aboutsummaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorDamien George2019-02-07 16:13:57 +1100
committerDamien George2019-02-07 16:13:57 +1100
commitb26046aca2f2abb357f454974f69bc4fa8e4afab (patch)
tree75d418978af85b03386dd3540e4322d56c2b8980 /ports
parentab423f29692b6fe9d1d7ae4c2a9ae1af81acfedb (diff)
stm32/modmachine: Make bootloader() enter custom loader if it's enabled.
If a custom bootloader is enabled (eg mboot) then machine.bootloader() will now enter that loader. To get the original ST DFU loader pass any argument to the function, like machine.bootloader(1).
Diffstat (limited to 'ports')
-rw-r--r--ports/stm32/modmachine.c16
-rw-r--r--ports/stm32/modmachine.h2
2 files changed, 15 insertions, 3 deletions
diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c
index e14753bfe..3c60378ff 100644
--- a/ports/stm32/modmachine.c
+++ b/ports/stm32/modmachine.c
@@ -247,7 +247,7 @@ STATIC mp_obj_t machine_soft_reset(void) {
MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset);
// Activate the bootloader without BOOT* pins.
-STATIC NORETURN mp_obj_t machine_bootloader(void) {
+STATIC NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
#if MICROPY_HW_ENABLE_USB
pyb_usb_dev_deinit();
#endif
@@ -263,6 +263,18 @@ STATIC NORETURN mp_obj_t machine_bootloader(void) {
HAL_MPU_Disable();
#endif
+ #if MICROPY_HW_USES_BOOTLOADER
+ if (n_args == 0 || !mp_obj_is_true(args[0])) {
+ // By default, with no args given, we enter the custom bootloader (mboot)
+ #if __DCACHE_PRESENT == 1
+ SCB_DisableICache();
+ SCB_DisableDCache();
+ #endif
+ __set_MSP(*(volatile uint32_t*)0x08000000);
+ ((void (*)(uint32_t)) *((volatile uint32_t*)(0x08000000 + 4)))(0x70ad0000);
+ }
+ #endif
+
#if defined(STM32F7) || defined(STM32H7)
// arm-none-eabi-gcc 4.9.0 does not correctly inline this
// MSP function, so we write it out explicitly here.
@@ -283,7 +295,7 @@ STATIC NORETURN mp_obj_t machine_bootloader(void) {
while (1);
}
-MP_DEFINE_CONST_FUN_OBJ_0(machine_bootloader_obj, machine_bootloader);
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);
// get or set the MCU frequencies
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
diff --git a/ports/stm32/modmachine.h b/ports/stm32/modmachine.h
index f105bbeec..414e5b37c 100644
--- a/ports/stm32/modmachine.h
+++ b/ports/stm32/modmachine.h
@@ -34,7 +34,7 @@ void machine_deinit(void);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj);
-MP_DECLARE_CONST_FUN_OBJ_0(machine_bootloader_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj);