stm32/mboot: Pass initial_r0 to early-init and get-reset-mode funcs.
This allows a board to modify initial_r0 if needed. Also make default board behaviour functions always available, named as mboot_get_reset_mode_default and mboot_state_change_default. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
e64947dc90
commit
87fbceef26
|
@ -133,7 +133,7 @@ void board_mboot_led_state(int led, int state) {
|
|||
hub_display_update();
|
||||
}
|
||||
|
||||
int board_mboot_get_reset_mode(void) {
|
||||
int board_mboot_get_reset_mode(uint32_t *initial_r0) {
|
||||
board_button_init();
|
||||
int reset_mode = BOARDCTRL_RESET_MODE_NORMAL;
|
||||
if (board_button_state()) {
|
||||
|
|
|
@ -127,7 +127,7 @@ extern struct _spi_bdev_t spi_bdev;
|
|||
#define MBOOT_BOARD_LED_INIT board_mboot_led_init
|
||||
#define MBOOT_BOARD_LED_STATE board_mboot_led_state
|
||||
|
||||
#define MBOOT_BOARD_EARLY_INIT board_init
|
||||
#define MBOOT_BOARD_EARLY_INIT(initial_r0) board_init()
|
||||
#define MBOOT_BOARD_CLEANUP board_mboot_cleanup
|
||||
#define MBOOT_BOARD_GET_RESET_MODE board_mboot_get_reset_mode
|
||||
|
||||
|
@ -138,5 +138,5 @@ void board_init(void);
|
|||
void board_mboot_cleanup(int reset_mode);
|
||||
void board_mboot_led_init(void);
|
||||
void board_mboot_led_state(int led, int state);
|
||||
int board_mboot_get_reset_mode(void);
|
||||
int board_mboot_get_reset_mode(uint32_t *initial_r0);
|
||||
void *btstack_chipset_cc256x_instance(void);
|
||||
|
|
|
@ -221,5 +221,5 @@ extern struct _spi_bdev_t spi_bdev2;
|
|||
#define MBOOT_SPIFLASH2_SPIFLASH (&spi_bdev2.spiflash)
|
||||
#define MBOOT_SPIFLASH2_CONFIG (&spiflash2_config)
|
||||
|
||||
#define MBOOT_BOARD_EARLY_INIT mboot_board_early_init
|
||||
#define MBOOT_BOARD_EARLY_INIT(initial_r0) mboot_board_early_init()
|
||||
void mboot_board_early_init(void);
|
||||
|
|
|
@ -1346,9 +1346,7 @@ void stm32_main(uint32_t initial_r0) {
|
|||
SCB_EnableDCache();
|
||||
#endif
|
||||
|
||||
#if defined(MBOOT_BOARD_EARLY_INIT)
|
||||
MBOOT_BOARD_EARLY_INIT();
|
||||
#endif
|
||||
MBOOT_BOARD_EARLY_INIT(&initial_r0);
|
||||
|
||||
#ifdef MBOOT_BOOTPIN_PIN
|
||||
mp_hal_pin_config(MBOOT_BOOTPIN_PIN, MP_HAL_PIN_MODE_INPUT, MBOOT_BOOTPIN_PULL, 0);
|
||||
|
@ -1361,7 +1359,7 @@ void stm32_main(uint32_t initial_r0) {
|
|||
goto enter_bootloader;
|
||||
}
|
||||
|
||||
int reset_mode = mboot_get_reset_mode();
|
||||
int reset_mode = MBOOT_BOARD_GET_RESET_MODE(&initial_r0);
|
||||
if (reset_mode != BOARDCTRL_RESET_MODE_BOOTLOADER) {
|
||||
// Bootloader mode was not selected so try to enter the application,
|
||||
// passing through the reset_mode. This will return if the application
|
||||
|
|
|
@ -38,8 +38,20 @@
|
|||
#define NORETURN __attribute__((noreturn))
|
||||
#define MP_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
#ifndef MBOOT_BOARD_EARLY_INIT
|
||||
#define MBOOT_BOARD_EARLY_INIT(initial_r0)
|
||||
#endif
|
||||
|
||||
#ifndef MBOOT_BOARD_ENTRY_INIT
|
||||
#define MBOOT_BOARD_ENTRY_INIT mboot_entry_init
|
||||
#define MBOOT_BOARD_ENTRY_INIT(initial_r0) mboot_entry_init_default()
|
||||
#endif
|
||||
|
||||
#ifndef MBOOT_BOARD_GET_RESET_MODE
|
||||
#define MBOOT_BOARD_GET_RESET_MODE(initial_r0) mboot_get_reset_mode_default()
|
||||
#endif
|
||||
|
||||
#ifndef MBOOT_BOARD_STATE_CHANGE
|
||||
#define MBOOT_BOARD_STATE_CHANGE(state, arg) mboot_state_change_default((state), (arg))
|
||||
#endif
|
||||
|
||||
#ifndef MBOOT_ADDRESS_SPACE_64BIT
|
||||
|
@ -154,7 +166,7 @@ int do_write(uint32_t addr, const uint8_t *src8, size_t len, bool dry_run);
|
|||
const uint8_t *elem_search(const uint8_t *elem, uint8_t elem_id);
|
||||
int fsload_process(void);
|
||||
|
||||
static inline void mboot_entry_init(uint32_t *initial_r0) {
|
||||
static inline void mboot_entry_init_default(void) {
|
||||
// Init subsystems (mboot_get_reset_mode() may call these, calling them again is ok)
|
||||
led_init();
|
||||
|
||||
|
@ -167,20 +179,15 @@ static inline void mboot_entry_init(uint32_t *initial_r0) {
|
|||
#endif
|
||||
}
|
||||
|
||||
#if defined(MBOOT_BOARD_GET_RESET_MODE)
|
||||
static inline int mboot_get_reset_mode(void) {
|
||||
return MBOOT_BOARD_GET_RESET_MODE();
|
||||
}
|
||||
#else
|
||||
int mboot_get_reset_mode(void);
|
||||
#endif
|
||||
int mboot_get_reset_mode_default(void);
|
||||
void mboot_state_change_default(mboot_state_t state, uint32_t arg);
|
||||
|
||||
#if defined(MBOOT_BOARD_STATE_CHANGE)
|
||||
static inline void mboot_state_change(mboot_state_t state, uint32_t arg) {
|
||||
#if defined(MBOOT_BOARD_STATE_CHANGE)
|
||||
return MBOOT_BOARD_STATE_CHANGE(state, arg);
|
||||
#else
|
||||
return mboot_state_change_default(state, arg);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
void mboot_state_change(mboot_state_t state, uint32_t arg);
|
||||
#endif
|
||||
|
||||
#endif // MICROPY_INCLUDED_STM32_MBOOT_MBOOT_H
|
||||
|
|
|
@ -136,7 +136,7 @@ void led0_update(void) {
|
|||
/******************************************************************************/
|
||||
// User button
|
||||
|
||||
#if !defined(MBOOT_BOARD_GET_RESET_MODE)
|
||||
#ifdef MICROPY_HW_USRSW_PIN
|
||||
|
||||
#define RESET_MODE_NUM_STATES (4)
|
||||
#define RESET_MODE_TIMEOUT_CYCLES (8)
|
||||
|
@ -158,7 +158,7 @@ static int usrbtn_state(void) {
|
|||
return mp_hal_pin_read(MICROPY_HW_USRSW_PIN) == MICROPY_HW_USRSW_PRESSED;
|
||||
}
|
||||
|
||||
int mboot_get_reset_mode(void) {
|
||||
int mboot_get_reset_mode_default(void) {
|
||||
usrbtn_init();
|
||||
int reset_mode = BOARDCTRL_RESET_MODE_NORMAL;
|
||||
if (usrbtn_state()) {
|
||||
|
@ -198,9 +198,7 @@ int mboot_get_reset_mode(void) {
|
|||
/******************************************************************************/
|
||||
// State change
|
||||
|
||||
#if !defined(MBOOT_BOARD_STATE_CHANGE)
|
||||
|
||||
void mboot_state_change(mboot_state_t state, uint32_t arg) {
|
||||
void mboot_state_change_default(mboot_state_t state, uint32_t arg) {
|
||||
switch (state) {
|
||||
case MBOOT_STATE_DFU_START:
|
||||
led_state_all(0);
|
||||
|
@ -255,5 +253,3 @@ void mboot_state_change(mboot_state_t state, uint32_t arg) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue