stm32: Enter bootloader via a system reset.

Entering a bootloader (ST system bootloader, or custom mboot) from software
by directly branching to it is not reliable, and the reliability of it
working can depend on the peripherals that were enabled by the application
code.  It's also not possible to branch to a bootloader if the WDT is
enabled (unless the bootloader has specific provisions to feed the WDT).

This patch changes the way a bootloader is entered from software by first
doing a complete system reset, then branching to the desired bootloader
early on in the start-up process.  The top two words of RAM (of the stack)
are reserved to store flags indicating that the bootloader should be
entered after a reset.
This commit is contained in:
Damien George
2019-06-22 21:26:03 +10:00
parent 205c6d0dc9
commit 04c7cdb668
27 changed files with 91 additions and 51 deletions

View File

@@ -72,6 +72,7 @@
#include "stm32_it.h"
#include "pendsv.h"
#include "irq.h"
#include "powerctrl.h"
#include "pybthread.h"
#include "gccollect.h"
#include "extint.h"
@@ -144,7 +145,7 @@ int pyb_hard_fault_debug = 0;
void HardFault_C_Handler(ExceptionRegisters_t *regs) {
if (!pyb_hard_fault_debug) {
NVIC_SystemReset();
powerctrl_mcu_reset();
}
#if MICROPY_HW_ENABLE_USB