diff --git a/ports/stm32/main.c b/ports/stm32/main.c index cc0367b824e0..15be21d48132 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -411,6 +411,21 @@ void stm32_main(uint32_t reset_mode) { rtc_init_start(false); #endif uart_init0(); + + #if defined(MICROPY_HW_UART_REPL) + // Set up a UART REPL using a statically allocated object + pyb_uart_repl_obj.base.type = &pyb_uart_type; + pyb_uart_repl_obj.uart_id = MICROPY_HW_UART_REPL; + pyb_uart_repl_obj.is_static = true; + pyb_uart_repl_obj.timeout = 0; + pyb_uart_repl_obj.timeout_char = 2; + uart_init(&pyb_uart_repl_obj, MICROPY_HW_UART_REPL_BAUD, UART_WORDLENGTH_8B, UART_PARITY_NONE, UART_STOPBITS_1, 0); + uart_set_rxbuf(&pyb_uart_repl_obj, sizeof(pyb_uart_repl_rxbuf), pyb_uart_repl_rxbuf); + uart_attach_to_repl(&pyb_uart_repl_obj, true); + MP_STATE_PORT(pyb_uart_obj_all)[MICROPY_HW_UART_REPL - 1] = &pyb_uart_repl_obj; + MP_STATE_PORT(pyb_stdio_uart) = &pyb_uart_repl_obj; + #endif + spi_init0(); #if MICROPY_PY_PYB_LEGACY && MICROPY_HW_ENABLE_HW_I2C i2c_init0(); @@ -446,19 +461,6 @@ void stm32_main(uint32_t reset_mode) { } #endif - #if defined(MICROPY_HW_UART_REPL) - // Set up a UART REPL using a statically allocated object - pyb_uart_repl_obj.base.type = &pyb_uart_type; - pyb_uart_repl_obj.uart_id = MICROPY_HW_UART_REPL; - pyb_uart_repl_obj.is_static = true; - pyb_uart_repl_obj.timeout = 0; - pyb_uart_repl_obj.timeout_char = 2; - uart_init(&pyb_uart_repl_obj, MICROPY_HW_UART_REPL_BAUD, UART_WORDLENGTH_8B, UART_PARITY_NONE, UART_STOPBITS_1, 0); - uart_set_rxbuf(&pyb_uart_repl_obj, sizeof(pyb_uart_repl_rxbuf), pyb_uart_repl_rxbuf); - uart_attach_to_repl(&pyb_uart_repl_obj, true); - MP_STATE_PORT(pyb_uart_obj_all)[MICROPY_HW_UART_REPL - 1] = &pyb_uart_repl_obj; - #endif - boardctrl_state_t state; state.reset_mode = reset_mode; state.log_soft_reset = false; @@ -496,12 +498,6 @@ void stm32_main(uint32_t reset_mode) { // we can run Python scripts (eg boot.py), but anything that is configurable // by boot.py must be set after boot.py is run. - #if defined(MICROPY_HW_UART_REPL) - MP_STATE_PORT(pyb_stdio_uart) = &pyb_uart_repl_obj; - #else - MP_STATE_PORT(pyb_stdio_uart) = NULL; - #endif - readline_init0(); pin_init0(); extint_init0(); @@ -659,6 +655,12 @@ void stm32_main(uint32_t reset_mode) { pyb_thread_deinit(); #endif + #if defined(MICROPY_HW_UART_REPL) + MP_STATE_PORT(pyb_stdio_uart) = &pyb_uart_repl_obj; + #else + MP_STATE_PORT(pyb_stdio_uart) = NULL; + #endif + MICROPY_BOARD_END_SOFT_RESET(&state); gc_sweep_all();