SMFSW / HARMcksL

ARM HAL toolbox (yet STM32 oriented)
MIT License
2 stars 0 forks source link

Get_Reset_Source functio not perfect #1

Open ColinYip100 opened 4 years ago

ColinYip100 commented 4 years ago

sometimes __HAL_RCC_GET_FLAG return more than 1flag,take away else would be a better result.

eResetSource Get_Reset_Source(void) { eResetSource rst = RST_UNKNOWN;

#if defined(STM32L4)
    if (__HAL_RCC_GET_FLAG(RCC_FLAG_FWRST))                 { rst = RST_FW; }
#elif defined(STM32G0)
    if (__HAL_RCC_GET_FLAG(RCC_FLAG_PWRRST))                { rst = RST_POR; }
#else
    if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST))                { rst = RST_POR; xprintf("\nRST_POR");}
#endif

    if (__HAL_RCC_GET_FLAG(RCC_FLAG_BORRST))                { rst = RST_PIN; xprintf("\nBORRST");}
if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST))                { rst = RST_PIN; xprintf("\nRST_PIN");}
if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST))                { rst = RST_SW; xprintf("\nRST_SW");}
if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST))               { rst = RST_IWDG; xprintf("\nRST_IWDG");}
if (__HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST))               { rst = RST_WWDG; xprintf("\nRST_WWDG");}
if (__HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST))               { rst = RST_LPWR; xprintf("\nRST_LPWR");}
#if defined(STM32F3) || defined(STM32L4)
    else if (__HAL_RCC_GET_FLAG(RCC_FLAG_OBLRST))           { rst = RST_OBL; }
    #if defined(STM32F301x8) ||                                                 \
        defined(STM32F302x8) || defined(STM32F302xC) || defined(STM32F302xE) || \
        defined(STM32F303x8) || defined(STM32F303xC) || defined(STM32F303xE) || \
        defined(STM32F334x8) || defined(STM32F358xx) || defined(STM32F373xC)
        else if (__HAL_RCC_GET_FLAG(RCC_FLAG_V18PWRRST))    { rst = RST_V18PWR; }
    #endif
#endif

__HAL_RCC_CLEAR_RESET_FLAGS();  // Clear reset flags

return rst;

}

SMFSW commented 4 years ago

Thanks for your feedback!

Usually, I use this function return to know if it's a POR or WDG, so I wasn't able to test every case.

Your solution takes the opposite thinking but doesn't solve the issue I guess. My implementation always returns the 1st reset source encountered, and yours, last one encountered. I think keeping 'else if's might be a better solution if reset sources can be sorted in a better way...

My question, when you say multiple sources can be set at once, do you have an example? and the one that is more relevant to you?

Thanks in advance!