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
Has thanked: 10 times
Been thanked: 5 times

Reset reason

Post 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
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 »

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
Has thanked: 10 times
Been thanked: 5 times

Re: Reset reason

Post 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.
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 »

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
Has thanked: 10 times
Been thanked: 5 times

Re: Reset reason

Post 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.
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 »

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
Has thanked: 10 times
Been thanked: 5 times

Re: Reset reason

Post by neums »

What are further steps? Add it as feature request?
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 »

No need, I queued it already.

Giovanni
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 »

did support for this get added ?
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 »

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
Post Reply