cancel
Showing results for 
Search instead for 
Did you mean: 

Troubleshooting reset causes using RCC->CSR register

Aaron McNeil
Associate III

I am trying to determine the cause of resets happening in my application. It does not seem like the RCC->CSR register is working properly.

I tested this out by manually grounding the NRST pin and setting a break point in my code before main(). The CSR register has none of the reset bits set when I would expect to see PINRSTF set here. I also tried the same issuing a software reset and that does not seem to set the SFTRSTF bit. The ONLY time I see anything set here is when I do a reset using the debugger. When I do this I see both the PINRSTF and SFTRSTF set and then cleared after Hal_Init().

6 REPLIES 6
KnarfB
Principal III

What MCU? It generally works. More than one bit can be set. Usually PINRSTF is set in addition to others. I also see BORRST together with PORRST. Read early (before HAL...) and clear reset flags afterwards for next reset. Think those bits are sampled values of the reset circuit (see "Simplified diagram of reset circuit").

hth

KnarfB

Which STM32?

Try to read RCC_CSR without having debugger connected, e.g. outputting it to UART or similar.

JW

STM32L476. I have an array that holds the last 10 reset values and I can print them out in hex. Each reset is always a 0x600 unless I reset with the debugger and its a 0x1400600. This holds true with and without the debugger connected.

This is exactly what I'm trying to accomplish but none of the bits are ever set no matter what type of reset occurs UNLESS I reset it with my debugger. I do read the register before main does anything.

I've just tried on an 'L476 DISCO and it behaves as expected - after power on 0x0c00'0600, after pushbutton (NRST) reset 0x0400'0600.

> manually grounding the NRST pin

How exactly do you do this?

Can you write an absolute minimal program, i.e. NO function calls in the startup code, and only RCC_CSR readout in main(), storing to memory and then infinite loop?

JW

KnarfB
Principal III

Also hooked up my board. The following code works, i.e. separates between reconnecting power (BOR) and pressing the reset button (PIN).

int main(void)
{
  /* USER CODE BEGIN 1 */
	char *reset_cause = "unknown";
    if (__HAL_RCC_GET_FLAG(RCC_FLAG_BORRST))
    {
        reset_cause = "BOR";
    }
    else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST))
    {
        reset_cause = "PIN";
    }
    __HAL_RCC_CLEAR_RESET_FLAGS();