Search code examples
carmembeddedresetstm32

STM32 how to get last reset status


I'm working with STM32F427 and I'd like to get cause of last reset. There is RCC clock control & status register RCC_CSR with many reset flags, but I'm not able to get any meaningful value.

By reading the value of that register, I get only 0x03, which means LSI ready and LSI ON, but no flags about reset are set if I try power on, software reset, low voltage etc. I found snippet of code for getting reset flags like below, but all the flags are still 0.

if (RCC_GetFlagStatus(RCC_FLAG_SFTRST)) ...

Do you have any suggestions how to get better results? Is there some needed configuration before reading these reset flags?

Thanks


Solution

  • Read RCC_CSR as soon as possible after startup, before initializing any other peripheral. It is safe to initialize your system clocks first (which is done in SystemInit() if you use ST's libraries).