8000 mimxrt/modmachine: Implement machine.bootloader(). · micropython/micropython@bde222c · GitHub
[go: up one dir, main page]

Skip to content

Commit bde222c

Browse files
iabdalkaderdpgeorge
authored andcommitted
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.
1 parent 8b72721 commit bde222c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ports/mimxrt/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ SRC_HAL_IMX_C += \
136136
$(MCU_DIR)/drivers/fsl_lpuart.c \
137137
$(MCU_DIR)/drivers/fsl_pit.c \
138138
$(MCU_DIR)/drivers/fsl_pwm.c \
139+
$(MCU_DIR)/drivers/fsl_romapi.c \
139140
$(MCU_DIR)/drivers/fsl_sai.c \
140141
$(MCU_DIR)/drivers/fsl_snvs_lp.c \
141142
$(MCU_DIR)/drivers/fsl_wdog.c \

ports/mimxrt/modmachine.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "pin.h"
3939
#include "modmachine.h"
4040
#include "fsl_wdog.h"
41+
#include "fsl_romapi.h"
4142

4243
#if MICROPY_PY_MACHINE
4344

@@ -108,6 +109,24 @@ STATIC mp_obj_t machine_enable_irq(mp_obj_t state_in) {
108109
}
109110
MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq);
110111

112+
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
113+
#if defined(MICROPY_BOARD_ENTER_BOOTLOADER)
114+
// If a board has a custom bootloader, call it first.
115+
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
116+
#elif FSL_ROM_HAS_RUNBOOTLOADER_API
117+
// If not, enter ROM bootloader in serial downloader / USB mode.
118+
uint32_t arg = 0xEB110000;
119+
ROM_RunBootloader(&arg);
120 AF6D +
#else
121+
// No custom bootloader, or run bootloader API, then just reset.
122+
WDOG_TriggerSystemSoftwareReset(WDOG1);
123+
#endif
124+
while (1) {
125+
;
126+
}
127+
}
128+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);
129+
111130
STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
112131
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) },
113132
{ 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[] = {
144163

145164
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) },
146165
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) },
166+
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) },
147167

148168
#if MICROPY_PY_MACHINE_BITSTREAM
149169
{ MP_ROM_QSTR(MP_QSTR_bitstream), MP_ROM_PTR(&machine_bitstream_obj) },

0 commit comments

Comments
 (0)
0