altos/stm32f04x: Smite the OPL_LAUNCH bit to reset boot config
authorKeith Packard <keithp@keithp.com>
Sun, 16 Apr 2023 04:53:28 +0000 (21:53 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 16 Apr 2023 04:53:28 +0000 (21:53 -0700)
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 <keithp@keithp.com>
src/stmf0/ao_arch.h

index 47ac72787aa1801bbd3f56dc891efa0c8402ce44..1450545a10c015d9d33fd2c75f95d5f68eb57f07 100644 (file)
 #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")