boardloader: check reset flags for production

This commit is contained in:
mcudev 2017-10-22 12:26:50 -04:00 committed by Pavol Rusnak
parent 3f58a771b4
commit 1f6edb448c
4 changed files with 22 additions and 5 deletions

View File

@ -76,7 +76,20 @@ void periph_init(void)
HAL_PWR_ConfigPVD(&pvd_config);
HAL_PWR_EnablePVD();
NVIC_EnableIRQ(PVD_IRQn);
// Clear the reset flags
RCC->CSR |= RCC_CSR_RMVF;
}
bool reset_flags_init(void)
{
#if PRODUCTION
// this is effective enough that it makes development painful, so only use it for production.
// check the reset flags to assure that we arrive here due to a regular full power-on event,
// and not as a result of a lesser reset.
if ((RCC->CSR & (RCC_CSR_LPWRRSTF | RCC_CSR_WWDGRSTF | RCC_CSR_IWDGRSTF | RCC_CSR_SFTRSTF | RCC_CSR_PORRSTF | RCC_CSR_PINRSTF | RCC_CSR_BORRSTF)) != (RCC_CSR_PORRSTF | RCC_CSR_PINRSTF | RCC_CSR_BORRSTF)) {
return false;
}
#endif
RCC->CSR |= RCC_CSR_RMVF; // clear the reset flags
return true;
}

View File

@ -6,5 +6,6 @@
void flash_set_option_bytes(void);
bool flash_check_option_bytes(void);
void periph_init(void);
bool reset_flags_init(void);
#endif

View File

@ -151,6 +151,10 @@ int main(void)
{
periph_init(); // need the systick timer running before the production flash (and many other HAL) operations
if (!reset_flags_init()) {
return 1;
}
#if PRODUCTION
flash_set_option_bytes();
if (!flash_check_option_bytes()) {

View File

@ -55,7 +55,6 @@ reset_handler:
// enter the application code
bl main
// loop forever if the application code returns
b .
b shutdown
.end