diff options
author | Damien George <damien@micropython.org> | 2022-06-17 13:57:47 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-06-17 13:57:47 +1000 |
commit | d8e7ecd23123247a6fc6f7d28833351e5b9d1fb6 (patch) | |
tree | 6ef7d3e89fe6eb3c87043f1300ee9000fc9583a3 /ports/stm32/boardctrl.c | |
parent | c5d26ee5e72331edf3c3ece342a577cbfe114310 (diff) | |
download | micropython-d8e7ecd23123247a6fc6f7d28833351e5b9d1fb6.tar.gz micropython-d8e7ecd23123247a6fc6f7d28833351e5b9d1fb6.zip |
stm32/modmachine: Factor out mboot enter code to a function.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'ports/stm32/boardctrl.c')
-rw-r--r-- | ports/stm32/boardctrl.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ports/stm32/boardctrl.c b/ports/stm32/boardctrl.c index 922f218e92..02a3759991 100644 --- a/ports/stm32/boardctrl.c +++ b/ports/stm32/boardctrl.c @@ -25,9 +25,11 @@ */ #include "py/runtime.h" +#include "py/objstr.h" #include "py/mphal.h" #include "shared/runtime/pyexec.h" #include "boardctrl.h" +#include "powerctrl.h" #include "led.h" #include "usrsw.h" @@ -43,6 +45,26 @@ STATIC void flash_error(int n) { led_state(PYB_LED_GREEN, 0); } +#if MICROPY_HW_USES_BOOTLOADER +void boardctrl_maybe_enter_mboot(size_t n_args, const void *args_in) { + const mp_obj_t *args = args_in; + + if (n_args == 0 || !mp_obj_is_true(args[0])) { + // By default, with no args given, we enter the custom bootloader (mboot) + powerctrl_enter_bootloader(0x70ad0000, MBOOT_VTOR); + } + + if (n_args == 1 && mp_obj_is_str_or_bytes(args[0])) { + // With a string/bytes given, pass its data to the custom bootloader + size_t len; + const char *data = mp_obj_str_get_data(args[0], &len); + void *mboot_region = (void *)*((volatile uint32_t *)MBOOT_VTOR); + memmove(mboot_region, data, len); + powerctrl_enter_bootloader(0x70ad0080, MBOOT_VTOR); + } +} +#endif + #if !MICROPY_HW_USES_BOOTLOADER STATIC uint update_reset_mode(uint reset_mode) { #if MICROPY_HW_HAS_SWITCH |