Skip to content

Commit

Permalink
mimxrt/modmachine: Implement machine.bootloader().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iabdalkader authored and dpgeorge committed Apr 11, 2023
1 parent 8b72721 commit bde222c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions ports/mimxrt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
20 changes: 20 additions & 0 deletions ports/mimxrt/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "pin.h"
#include "modmachine.h"
#include "fsl_wdog.h"
#include "fsl_romapi.h"

#if MICROPY_PY_MACHINE

Expand Down Expand Up @@ -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) },
Expand Down Expand Up @@ -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) },
Expand Down

0 comments on commit bde222c

Please sign in to comment.