diff options
| author | Damien George <damien@micropython.org> | 2023-05-24 15:55:28 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-06-15 11:02:49 +1000 |
| commit | b839acc7d9231df049793bd32c672f72b705af3e (patch) | |
| tree | e2dc8d8e8444139d8682a6a2d84cd160a1e10e77 | |
| parent | fb1bdf0ff2d48fbc28ce89b5424fac07edd50e4b (diff) | |
stm32/main: Start UART REPL as early as possible.
For debugging purposes, to see output from other peripherals.
Also reset the pyb_stdio_uart state at the end of soft reset, in case it
points to a heap-allocated object.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | ports/stm32/main.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/ports/stm32/main.c b/ports/stm32/main.c index cc0367b82..15be21d48 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 @@ soft_reset: // 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 @@ soft_reset_exit: 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(); |
