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.
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Location: Dresden, Germany
Has thanked: 10 times
Been thanked: 5 times

Reset reason

Postby neums » Wed Mar 02, 2016 9:53 am

Hi,
how about a reset reason getter and resetter in the stm32_rcc.h files? Anybody here who needs that too?
At the moment i do this direct via CMSIS register access.

Maybe something like this:

Code: Select all

#define rccClearResetReason(){  \
    RCC->CSR |= RCC_CSR_RMVF \
}

#define rccGetResetReason() RCC->CSR & ( RCC_CSR_LPWRRSTF | RCC_CSR_WWDGRSTF | RCC_CSR_IWDGRSTF | RCC_CSR_SFTRSTF | RCC_CSR_PORRSTF | RCC_CSR_PINRSTF) 


Thanks

User avatar
Giovanni
Site Admin
Posts: 12017
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 543 times
Been thanked: 454 times
Contact:

Re: Reset reason

Postby Giovanni » Wed Mar 02, 2016 10:48 pm

It would not abstract much, you would have to check the reason bits using the mask constants anyway.

Giovanni

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

Re: Reset reason

Postby neums » Thu Mar 03, 2016 11:19 am

For the STM32F4 maybe somthing like this:

Code: Select all

typedef enum{
  RESET_REASON_LOW_POWER,
  RESET_REASON_WINDOW_WATCHDOG,
  RESET_REASON_INDEPENDENT_WATCHDOG,
  RESET_REASON_SOFTWARE,
  RESET_REASON_POWER_ON,
  RESET_REASON_PIN,
  RESET_REASON_UNKNOWN,
}rccResetReason_t;

rccResetReason_t rccGetResetReason(void) {
    if(RCC->CSR & RCC_CSR_LPWRRSTF)
      return RESET_REASON_LOW_POWER;
    else if(RCC->CSR & RCC_CSR_WWDGRSTF)
      return RESET_REASON_WINDOW_WATCHDOG;
    else if(RCC->CSR & RCC_CSR_WDGRSTF)
      return RESET_REASON_INDEPENDENT_WATCHDOG;
    else if(RCC->CSR & RCC_CSR_SFTRSTF)
      return RESET_REASON_SOFTWARE;
    else if(RCC->CSR & RCC_CSR_PORRSTF)
      return RESET_REASON_POWER_ON;
    else if(RCC->CSR & RCC_CSR_PADRSTF)
      return RESET_REASON_PIN;
    else
      return RESET_REASON_UNKNOWN;
}

where the type rccResetReason_t is standardized platform independent and the interpretation is done in this platform dependent functions? Then the interface between application and HAL is standardized.

User avatar
Giovanni
Site Admin
Posts: 12017
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 543 times
Been thanked: 454 times
Contact:

Re: Reset reason

Postby Giovanni » Thu Mar 03, 2016 1:15 pm

It could be added to the HAL driver. A standard API halGetResetReason() could be added. The enum would be defined in the low layer. A couple of values could be "standard": cold reset, watchdog.

It makes sense and it is a common feature.

Giovanni

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

Re: Reset reason

Postby neums » Thu Mar 03, 2016 2:00 pm

Then we have to define an intersection of the possible reset causes, e.g. an high level part of the enum and a low level part which is platform dependent.
Common might be POWER_ON, RESET_PIN, SOFTWARE and WATCHDOG, isn't it? Some other proposals?

Also a rccClearResetCause() is mandatory because the "reset" register of some platforms need to be explicitly cleared by the application e.g. STM32.

User avatar
Giovanni
Site Admin
Posts: 12017
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 543 times
Been thanked: 454 times
Contact:

Re: Reset reason

Postby Giovanni » Thu Mar 03, 2016 2:11 pm

The reset would be implicit in reading, cannot put an STM32-specific thing to API level.

Giovanni

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

Re: Reset reason

Postby neums » Fri Mar 04, 2016 8:51 am

What are further steps? Add it as feature request?

User avatar
Giovanni
Site Admin
Posts: 12017
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 543 times
Been thanked: 454 times
Contact:

Re: Reset reason

Postby Giovanni » Fri Mar 04, 2016 12:16 pm

No need, I queued it already.

Giovanni

Tabulous
Posts: 453
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 1 time
Been thanked: 13 times

Re: Reset reason

Postby Tabulous » Tue Jan 17, 2017 12:34 pm

did support for this get added ?

User avatar
Giovanni
Site Admin
Posts: 12017
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 543 times
Been thanked: 454 times
Contact:

Re: Reset reason

Postby Giovanni » Tue Jan 17, 2017 2:11 pm

Hi,

No, not yet, for some reason the STM32 can have multiple reset reasons at the same time (it is a mask of bits), I couldn't define a portable API for this, it varies too much among MCUs.

Doing it an enum as proposed would not work.

Giovanni


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 1 guest