Reset reason

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Reset reason

Post by Tabulous »

yeah the RCC->CSR Reg has about 6 bits for reset reasons, but if cleared by RMVF bit on startup, the next reset should have the correct reason for reset.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Reset reason

Post by Giovanni »

Is it guaranteed that you find only one bit raised? Couldn't find this info.

Giovanni
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Has thanked: 10 times
Been thanked: 5 times

Re: Reset reason

Post by neums »

I've asked it there:

https://community.st.com/thread/35979-r ... on-stm32fx

waiting for response...
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Has thanked: 10 times
Been thanked: 5 times

Re: Reset reason

Post by neums »

Hi,
ST answered:
"It's possible in case of internal reset to have 2 Flag set in the same time."
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Reset reason

Post by Giovanni »

So this API could just report "external reset" or "other reset" and a mask of platform-dependent flags, the RCC_CSR register in the STM32 case.

Giovanni
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Has thanked: 10 times
Been thanked: 5 times

Re: Reset reason

Post by neums »

May we wait for other replies at STMs page for some days.
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Reset reason

Post by Tabulous »

if you poll the CRS register in this order, you will know you reason for reset. Yes NRST is always set as every reset work by pulling NRST low for afew micro seconds, but it should be the last bit you poll.

Code: Select all

    if( RCC->CSR & ( 1 << 31 ))
    {
        TGL_DEBUG( DBG_MASK_APP, "$ APP - RESET(PLWR)\r\n" );
    }
    else if( RCC->CSR & ( 1 << 30 ))
    {
        TGL_DEBUG( DBG_MASK_APP, "$ APP - RESET(WWDG)\r\n" );
    }
    else if( RCC->CSR & ( 1 << 29 ))
    {
        TGL_DEBUG( DBG_MASK_APP, "$ APP - RESET(IWDG)\r\n" );
    }
    else if( RCC->CSR & ( 1 << 28 ))
    {
        TGL_DEBUG( DBG_MASK_APP, "$ APP - RESET(SOFT)\r\n" );
    }
    else if( RCC->CSR & ( 1 << 27 ))
    {
        TGL_DEBUG( DBG_MASK_APP, "$ APP - RESET(POR)\r\n" );
    }
    else if( RCC->CSR & ( 1 << 26 ))
    {
        TGL_DEBUG( DBG_MASK_APP, "$ APP - RESET(NRST)\r\n" );
    }



Tested this and seems to work.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Reset reason

Post by Giovanni »

Moving topic.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Reset reason

Post by Giovanni »

bump

It will go in next HAL in a specific driver.
electronic_eel
Posts: 95
Joined: Sat Mar 19, 2016 8:07 pm
Has thanked: 8 times
Been thanked: 23 times

Re: Reset reason

Post by electronic_eel »

Is there already any HAL code for this available that I could test?

I'm just working on a project where I need to check if the watchdog triggered a reset and alert the user that something went wrong.

Thanks.
Post Reply