From cb756983a26595a5d2f317a6693f9a670665c86a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 15 Apr 2023 21:53:28 -0700 Subject: [PATCH] altos/stm32f04x: Smite the OPL_LAUNCH bit to reset boot config When rebooting, make sure the option bytes are recomputed based upon the latest flash configuration, including whether there's a program loaded. This ensures that we don't end up re-starting the DFU loader and mangling our ao_boot values. Without this, our flash loader code wouldn't be able to see the signal to stay in the loader and we'd end up back in the application. Of course, this is only necessary if we want to reboot just after flashing the boot loader without power cycling. Once the chip is power cycled, it recomputes the option bytes automatically. Signed-off-by: Keith Packard --- src/stmf0/ao_arch.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/stmf0/ao_arch.h b/src/stmf0/ao_arch.h index 47ac7278..1450545a 100644 --- a/src/stmf0/ao_arch.h +++ b/src/stmf0/ao_arch.h @@ -41,9 +41,11 @@ #define __interrupt(n) #define __at(n) -#define ao_arch_reboot() \ - (stm_scb.aircr = ((STM_SCB_AIRCR_VECTKEY_KEY << STM_SCB_AIRCR_VECTKEY) | \ - (1 << STM_SCB_AIRCR_SYSRESETREQ))) +static inline void ao_arch_reboot(void) { + stm_flash.cr = (1 << STM_FLASH_CR_OBL_LAUNCH); + stm_scb.aircr = ((STM_SCB_AIRCR_VECTKEY_KEY << STM_SCB_AIRCR_VECTKEY) | + (1 << STM_SCB_AIRCR_SYSRESETREQ)); +} #define ao_arch_nop() asm("nop") -- 2.30.2