From 0adf0dd3d7108404fa2a62f0db637baaddaf0da9 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 27 Apr 2022 10:58:09 +0200 Subject: [PATCH] stm32/modmachine: Allow boards to provide custom bootloader code. And expose the machine_bootloader() C function so it can be used elsewhere. --- ports/stm32/boardctrl.h | 4 ++++ ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h | 2 +- ports/stm32/modmachine.c | 5 ++++- ports/stm32/modmachine.h | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ports/stm32/boardctrl.h b/ports/stm32/boardctrl.h index 0878a453b3..bc901f1c37 100644 --- a/ports/stm32/boardctrl.h +++ b/ports/stm32/boardctrl.h @@ -37,6 +37,10 @@ #define MICROPY_BOARD_STARTUP powerctrl_check_enter_bootloader #endif +#ifndef MICROPY_BOARD_ENTER_BOOTLOADER +#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) +#endif + #ifndef MICROPY_BOARD_EARLY_INIT #define MICROPY_BOARD_EARLY_INIT() #endif diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h index 30c909913c..31e19c9eb5 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h @@ -38,7 +38,7 @@ void PORTENTA_board_startup(void); #define MICROPY_BOARD_EARLY_INIT PORTENTA_board_early_init void PORTENTA_board_early_init(void); -#define MICROPY_BOARD_ENTER_BOOTLOADER PORTENTA_board_enter_bootloader +#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) PORTENTA_board_enter_bootloader() void PORTENTA_board_enter_bootloader(void); void PORTENTA_board_low_power(int mode); diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c index 5fca9b3e04..91061a3109 100644 --- a/ports/stm32/modmachine.c +++ b/ports/stm32/modmachine.c @@ -46,6 +46,7 @@ #include "gccollect.h" #include "irq.h" #include "powerctrl.h" +#include "boardctrl.h" #include "pybthread.h" #include "rng.h" #include "storage.h" @@ -270,7 +271,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(size_t n_args, const mp_obj_t *args) { +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 @@ -280,6 +281,8 @@ STATIC NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) __disable_irq(); + MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args); + #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) diff --git a/ports/stm32/modmachine.h b/ports/stm32/modmachine.h index 0e6c000a80..9fa7851582 100644 --- a/ports/stm32/modmachine.h +++ b/ports/stm32/modmachine.h @@ -36,6 +36,7 @@ extern const mp_obj_type_t machine_i2s_type; void machine_init(void); void machine_deinit(void); void machine_i2s_init0(); +NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args); MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj); MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj);