Unreset GPIO Pins While System Resetting

Viewed 36

Is it possible to unreset some GPIO pins while using NVIC_SystemReset function at STM32 ? Thanks in advance for your answers

Best Regards

I try to reach NVIC_SystemReset function. But not clear inside of this function. Also this project is running on KEIL

1 Answers

Looks like it is not possible, NVIC_SystemReset issues a general reset of all subsystems.

But probably, instead of system reset, you can just reset all peripheral expect one you need keep working, using peripheral reset registers in Reset and Clock Control module (RCC): RCC_AHB1RSTR, RCC_AHB2RSTR, RCC_APB1RSTR, RCC_APB1RSTR.

Example:

   // Issue reset of SPI2, SPI3, I2C1, I2C2, I2C3 on APB1 bus
   RCC->APB1RSTR = RCC_APB1RSTR_I2C3RST | RCC_APB1RSTR_I2C2RST | RCC_APB1RSTR_I2C1RST 
                 | RCC_APB1RSTR_SPI3RST | RCC_APB1RSTR_SPI2RST;
   __DMB(); // Data memory barrier
   RCC->APB1RSTR = 0; // deassert all reset signals

See detailed information in RCC registers description in Reference Manual for your MCU.

You may also need to disable all interrupts in NVIC:

  for (int i = 0 ; i < 8 ; i++) NVIC->ICER[i] = 0xFFFFFFFFUL; // disable all interrupts 
  for (int i = 0 ; i < 8 ; i++) NVIC->ICPR[i] = 0xFFFFFFFFUL; // clear all pending flags

if you want to restart the program, you can reload stack pointer to its top value, located at offset 0 of the flash memory and jump to the start address which is stored at offset 4. Note: flash memory is addressed starting from 0x08000000 address in the address space.

  uint32_t stack_top = *((volatile uint32_t*)FLASH_BASE);
  uint32_t entry_point = *((volatile uint32_t*)(FLASH_BASE + 4));

  __set_MSP(stack_top); // set stack top
  __ASM volatile ("BX %0" : : "r" (entry_point | 1) ); // jump to the entry point with bit 1 set
Related