From c5d26ee5e72331edf3c3ece342a577cbfe114310 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 7 Jun 2022 19:13:08 +0200 Subject: [PATCH] renesas-ra/modmachine: Allow boards to provide custom bootloader code. And expose the machine_bootloader() C function so it can be used elsewhere. --- ports/renesas-ra/boardctrl.h | 4 ++++ ports/renesas-ra/modmachine.c | 5 ++++- ports/renesas-ra/modmachine.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ports/renesas-ra/boardctrl.h b/ports/renesas-ra/boardctrl.h index cc7918c35f..1fc572a34e 100644 --- a/ports/renesas-ra/boardctrl.h +++ b/ports/renesas-ra/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/renesas-ra/modmachine.c b/ports/renesas-ra/modmachine.c index cd6e750340..e6f78747fd 100644 --- a/ports/renesas-ra/modmachine.c +++ b/ports/renesas-ra/modmachine.c @@ -47,6 +47,7 @@ #include "gccollect.h" #include "irq.h" #include "powerctrl.h" +#include "boardctrl.h" #include "pybthread.h" #include "storage.h" #include "pin.h" @@ -182,13 +183,15 @@ 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_STORAGE storage_flush(); #endif __disable_irq(); + MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args); + #if MICROPY_HW_USES_BOOTLOADER // ToDo: need to review how to implement diff --git a/ports/renesas-ra/modmachine.h b/ports/renesas-ra/modmachine.h index 65077220df..de421c5db8 100644 --- a/ports/renesas-ra/modmachine.h +++ b/ports/renesas-ra/modmachine.h @@ -49,6 +49,7 @@ void machine_deinit(void); void machine_pin_init(void); void machine_pin_deinit(void); void machine_i2s_init0(void); +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);