summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriabdalkader <i.abdalkader@gmail.com>2023-04-09 19:20:09 +0200
committerDamien George <damien@micropython.org>2023-04-11 17:40:18 +1000
commitbde222ce849d3d247f588bc6db119b3d2f45faf8 (patch)
tree2a366c9a7efc1c20231bbfb4f0d9f13bdfab6cdf
parent8b72721b29b9454191b83353ca6895f32361abc5 (diff)
mimxrt/modmachine: Implement machine.bootloader().
If a board defines a custom bootloader entry function it will be called first, if not and the ROM API supports RUN bootloader API, then `machine.bootloader()` will jump to the ROM serial downloader in USB mode.
-rw-r--r--ports/mimxrt/Makefile1
-rw-r--r--ports/mimxrt/modmachine.c20
2 files changed, 21 insertions, 0 deletions
diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile
index 800370e0a..abde70f12 100644
--- a/ports/mimxrt/Makefile
+++ b/ports/mimxrt/Makefile
@@ -136,6 +136,7 @@ SRC_HAL_IMX_C += \
$(MCU_DIR)/drivers/fsl_lpuart.c \
$(MCU_DIR)/drivers/fsl_pit.c \
$(MCU_DIR)/drivers/fsl_pwm.c \
+ $(MCU_DIR)/drivers/fsl_romapi.c \
$(MCU_DIR)/drivers/fsl_sai.c \
$(MCU_DIR)/drivers/fsl_snvs_lp.c \
$(MCU_DIR)/drivers/fsl_wdog.c \
diff --git a/ports/mimxrt/modmachine.c b/ports/mimxrt/modmachine.c
index 9097289e7..5c897578d 100644
--- a/ports/mimxrt/modmachine.c
+++ b/ports/mimxrt/modmachine.c
@@ -38,6 +38,7 @@
#include "pin.h"
#include "modmachine.h"
#include "fsl_wdog.h"
+#include "fsl_romapi.h"
#if MICROPY_PY_MACHINE
@@ -108,6 +109,24 @@ STATIC mp_obj_t machine_enable_irq(mp_obj_t state_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq);
+NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
+ #if defined(MICROPY_BOARD_ENTER_BOOTLOADER)
+ // If a board has a custom bootloader, call it first.
+ MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
+ #elif FSL_ROM_HAS_RUNBOOTLOADER_API
+ // If not, enter ROM bootloader in serial downloader / USB mode.
+ uint32_t arg = 0xEB110000;
+ ROM_RunBootloader(&arg);
+ #else
+ // No custom bootloader, or run bootloader API, then just reset.
+ WDOG_TriggerSystemSoftwareReset(WDOG1);
+ #endif
+ while (1) {
+ ;
+ }
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);
+
STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) },
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) },
@@ -144,6 +163,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) },
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) },
+ { MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) },
#if MICROPY_PY_MACHINE_BITSTREAM
{ MP_ROM_QSTR(MP_QSTR_bitstream), MP_ROM_PTR(&machine_bitstream_obj) },