diff options
author | Damien George <damien.p.george@gmail.com> | 2018-02-05 15:48:28 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-02-05 15:52:36 +1100 |
commit | 4607be3768b0f6fd187fb7f17545ec3a7d28b94c (patch) | |
tree | 2ea5a22b9aa67d9e50e99d340b020dc6c1cab76a | |
parent | 12464f1bd2c63af012d1ce47c79f9afbfefd71e2 (diff) |
stm32/main: Reorder some init calls to put them before soft-reset loop.
The calls to rtc_init_start(), sdcard_init() and storage_init() are all
guarded by a check for first_soft_reset, so it's simpler to just put them
all before the soft-reset loop, without the check.
The call to machine_init() can also go before the soft-reset loop because
it is only needed to check the reset cause which can happen once at the
first boot. To allow this to work, the reset cause must be set to SOFT
upon a soft-reset, which is the role of the new function machine_deinit().
-rw-r--r-- | ports/stm32/main.c | 31 | ||||
-rw-r--r-- | ports/stm32/modmachine.c | 5 | ||||
-rw-r--r-- | ports/stm32/modmachine.h | 1 |
3 files changed, 17 insertions, 20 deletions
diff --git a/ports/stm32/main.c b/ports/stm32/main.c index 5617747e9..1f39b9b9c 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -454,13 +454,21 @@ int main(void) { #endif pendsv_init(); led_init(); -#if MICROPY_HW_HAS_SWITCH + #if MICROPY_HW_HAS_SWITCH switch_init0(); -#endif + #endif + machine_init(); + #if MICROPY_HW_ENABLE_RTC + rtc_init_start(false); + #endif spi_init0(); #if MICROPY_HW_ENABLE_HW_I2C i2c_init0(); #endif + #if MICROPY_HW_HAS_SDCARD + sdcard_init(); + #endif + storage_init(); #if defined(USE_DEVICE_MODE) // default to internal flash being the usb medium @@ -483,24 +491,6 @@ soft_reset: led_state(4, 0); uint reset_mode = update_reset_mode(1); - machine_init(); - -#if MICROPY_HW_ENABLE_RTC - if (first_soft_reset) { - rtc_init_start(false); - } -#endif - - // more sub-system init -#if MICROPY_HW_HAS_SDCARD - if (first_soft_reset) { - sdcard_init(); - } -#endif - if (first_soft_reset) { - storage_init(); - } - // Python threading init #if MICROPY_PY_THREAD mp_thread_init(); @@ -692,6 +682,7 @@ soft_reset_exit: #if MICROPY_HW_ENABLE_CAN can_deinit(); #endif + machine_deinit(); #if MICROPY_PY_THREAD pyb_thread_deinit(); diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c index fba27a3bb..3645fe60e 100644 --- a/ports/stm32/modmachine.c +++ b/ports/stm32/modmachine.c @@ -99,6 +99,11 @@ void machine_init(void) { RCC->CSR |= RCC_CSR_RMVF; } +void machine_deinit(void) { + // we are doing a soft-reset so change the reset_cause + reset_cause = PYB_RESET_SOFT; +} + // machine.info([dump_alloc_table]) // Print out lots of information about the board. STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) { diff --git a/ports/stm32/modmachine.h b/ports/stm32/modmachine.h index 77668695f..81c6375c7 100644 --- a/ports/stm32/modmachine.h +++ b/ports/stm32/modmachine.h @@ -29,6 +29,7 @@ #include "py/obj.h" void machine_init(void); +void machine_deinit(void); MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj); MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj); |