diff --git a/mongoose.c b/mongoose.c index 410d0d97..9fe222ac 100644 --- a/mongoose.c +++ b/mongoose.c @@ -12048,9 +12048,11 @@ bool mg_ota_write(const void *buf, size_t len) { } bool mg_ota_end(void) { - mg_ota_flash_end(&s_mg_flash_stm32h5); - return false; + if (!mg_ota_flash_end(&s_mg_flash_stm32h5)) return false; + *(volatile uint32_t *) 0xe000ed0c = 0x5fa0004U; // NVIC_SystemReset() + return true; } + struct mg_flash *mg_flash = &s_mg_flash_stm32h5; #endif diff --git a/mongoose.h b/mongoose.h index 2657738f..86d875d9 100644 --- a/mongoose.h +++ b/mongoose.h @@ -240,10 +240,11 @@ extern "C" { #endif #if defined(TAMP) -#define MG_OTA_STATE_GET() (TAMP->BKP0R) +#define MG_OTA_STATE_GET() \ + (RCC->APB3ENR |= RCC_APB3ENR_RTCAPBEN, TAMP->BKP0R) #define MG_OTA_STATE_SET(v) \ (RCC->APB3ENR |= RCC_APB3ENR_RTCAPBEN, MG_OTA_DBP_ENABLE(), \ - (TAMP->BKP0R = (uint32_t) (v))) + (TAMP->BKP0R = (uint32_t) (v)), TAMP->BKP0R) #elif defined(RCC_APB4ENR_RTCAPBEN) #define MG_OTA_STATE_GET() (RTC->BKP0R) #define MG_OTA_STATE_SET(v) \ diff --git a/src/arch_cube.h b/src/arch_cube.h index 13126d47..5b9f9250 100644 --- a/src/arch_cube.h +++ b/src/arch_cube.h @@ -108,10 +108,11 @@ #endif #if defined(TAMP) -#define MG_OTA_STATE_GET() (TAMP->BKP0R) +#define MG_OTA_STATE_GET() \ + (RCC->APB3ENR |= RCC_APB3ENR_RTCAPBEN, TAMP->BKP0R) #define MG_OTA_STATE_SET(v) \ (RCC->APB3ENR |= RCC_APB3ENR_RTCAPBEN, MG_OTA_DBP_ENABLE(), \ - (TAMP->BKP0R = (uint32_t) (v))) + (TAMP->BKP0R = (uint32_t) (v)), TAMP->BKP0R) #elif defined(RCC_APB4ENR_RTCAPBEN) #define MG_OTA_STATE_GET() (RTC->BKP0R) #define MG_OTA_STATE_SET(v) \ diff --git a/src/ota_stm32h5.c b/src/ota_stm32h5.c index e6ebc204..59835109 100644 --- a/src/ota_stm32h5.c +++ b/src/ota_stm32h5.c @@ -159,8 +159,10 @@ bool mg_ota_write(const void *buf, size_t len) { } bool mg_ota_end(void) { - mg_ota_flash_end(&s_mg_flash_stm32h5); - return false; + if (!mg_ota_flash_end(&s_mg_flash_stm32h5)) return false; + *(volatile uint32_t *) 0xe000ed0c = 0x5fa0004U; // NVIC_SystemReset() + return true; } + struct mg_flash *mg_flash = &s_mg_flash_stm32h5; #endif diff --git a/tutorials/stm32/nucleo-h563zi/minimal/mongoose/mongoose_config.h b/tutorials/stm32/nucleo-h563zi/minimal/mongoose/mongoose_config.h index 9479936f..061fce03 100644 --- a/tutorials/stm32/nucleo-h563zi/minimal/mongoose/mongoose_config.h +++ b/tutorials/stm32/nucleo-h563zi/minimal/mongoose/mongoose_config.h @@ -41,8 +41,10 @@ // OTA state in TAMP backup register 0 (survives all resets, clears on POR). // Requires hal_backup_domain_init() (called from hal_clock_init) to have run. -#define MG_OTA_STATE_GET() (TAMP->BKP0R) -#define MG_OTA_STATE_SET(v) (TAMP->BKP0R = (uint32_t) (v)) +#define MG_OTA_STATE_GET() (RCC->APB3ENR |= RCC_APB3ENR_RTCAPBEN, TAMP->BKP0R) +#define MG_OTA_STATE_SET(v) \ + (RCC->APB3ENR |= RCC_APB3ENR_RTCAPBEN, PWR->DBPCR |= PWR_DBPCR_DBP, \ + (TAMP->BKP0R = (uint32_t) (v)), TAMP->BKP0R) // #define MG_DRIVER_MDC_CR 4 // RMII MDC clock divider, from 0 to 4 // #define MG_TCPIP_PHY_ADDR 0 // PHY address