Page 1 of 3

Reset reason

Posted: Wed Mar 02, 2016 9:53 am
by neums
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

Re: Reset reason

Posted: Wed Mar 02, 2016 10:48 pm
by Giovanni
It would not abstract much, you would have to check the reason bits using the mask constants anyway.

Giovanni

Re: Reset reason

Posted: Thu Mar 03, 2016 11:19 am
by neums
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.

Re: Reset reason

Posted: Thu Mar 03, 2016 1:15 pm
by Giovanni
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

Re: Reset reason

Posted: Thu Mar 03, 2016 2:00 pm
by neums
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.

Re: Reset reason

Posted: Thu Mar 03, 2016 2:11 pm
by Giovanni
The reset would be implicit in reading, cannot put an STM32-specific thing to API level.

Giovanni

Re: Reset reason

Posted: Fri Mar 04, 2016 8:51 am
by neums
What are further steps? Add it as feature request?

Re: Reset reason

Posted: Fri Mar 04, 2016 12:16 pm
by Giovanni
No need, I queued it already.

Giovanni

Re: Reset reason

Posted: Tue Jan 17, 2017 12:34 pm
by Tabulous
did support for this get added ?

Re: Reset reason

Posted: Tue Jan 17, 2017 2:11 pm
by Giovanni
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