@@ -411,6 +411,21 @@ void stm32_main(uint32_t reset_mode) {
411411 rtc_init_start (false);
412412 #endif
413413 uart_init0 ();
414+
415+ #if defined(MICROPY_HW_UART_REPL )
416+ // Set up a UART REPL using a statically allocated object
417+ pyb_uart_repl_obj .base .type = & pyb_uart_type ;
418+ pyb_uart_repl_obj .uart_id = MICROPY_HW_UART_REPL ;
419+ pyb_uart_repl_obj .is_static = true;
420+ pyb_uart_repl_obj .timeout = 0 ;
421+ pyb_uart_repl_obj .timeout_char = 2 ;
422+ uart_init (& pyb_uart_repl_obj , MICROPY_HW_UART_REPL_BAUD , UART_WORDLENGTH_8B , UART_PARITY_NONE , UART_STOPBITS_1 , 0 );
423+ uart_set_rxbuf (& pyb_uart_repl_obj , sizeof (pyb_uart_repl_rxbuf ), pyb_uart_repl_rxbuf );
424+ uart_attach_to_repl (& pyb_uart_repl_obj , true);
425+ MP_STATE_PORT (pyb_uart_obj_all )[MICROPY_HW_UART_REPL - 1 ] = & pyb_uart_repl_obj ;
426+ MP_STATE_PORT (pyb_stdio_uart ) = & pyb_uart_repl_obj ;
427+ #endif
428+
414429 spi_init0 ();
415430 #if MICROPY_PY_PYB_LEGACY && MICROPY_HW_ENABLE_HW_I2C
416431 i2c_init0 ();
@@ -446,19 +461,6 @@ void stm32_main(uint32_t reset_mode) {
446461 }
447462 #endif
448463
449- #if defined(MICROPY_HW_UART_REPL )
450- // Set up a UART REPL using a statically allocated object
451- pyb_uart_repl_obj .base .type = & pyb_uart_type ;
452- pyb_uart_repl_obj .uart_id = MICROPY_HW_UART_REPL ;
453- pyb_uart_repl_obj .is_static = true;
454- pyb_uart_repl_obj .timeout = 0 ;
455- pyb_uart_repl_obj .timeout_char = 2 ;
456- uart_init (& pyb_uart_repl_obj , MICROPY_HW_UART_REPL_BAUD , UART_WORDLENGTH_8B , UART_PARITY_NONE , UART_STOPBITS_1 , 0 );
457- uart_set_rxbuf (& pyb_uart_repl_obj , sizeof (pyb_uart_repl_rxbuf ), pyb_uart_repl_rxbuf );
458- uart_attach_to_repl (& pyb_uart_repl_obj , true);
459- MP_STATE_PORT (pyb_uart_obj_all )[MICROPY_HW_UART_REPL - 1 ] = & pyb_uart_repl_obj ;
460- #endif
461-
462464 boardctrl_state_t state ;
463465 state .reset_mode = reset_mode ;
464466 state .log_soft_reset = false;
@@ -496,12 +498,6 @@ void stm32_main(uint32_t reset_mode) {
496498 // we can run Python scripts (eg boot.py), but anything that is configurable
497499 // by boot.py must be set after boot.py is run.
498500
499- #if defined(MICROPY_HW_UART_REPL )
500- MP_STATE_PORT (pyb_stdio_uart ) = & pyb_uart_repl_obj ;
501- #else
502- MP_STATE_PORT (pyb_stdio_uart ) = NULL ;
503- #endif
504-
505501 readline_init0 ();
506502 pin_init0 ();
507503 extint_init0 ();
@@ -659,6 +655,12 @@ void stm32_main(uint32_t reset_mode) {
659655 pyb_thread_deinit ();
660656 #endif
661657
658+ #if defined(MICROPY_HW_UART_REPL )
659+ MP_STATE_PORT (pyb_stdio_uart ) = & pyb_uart_repl_obj ;
660+ #else
661+ MP_STATE_PORT (pyb_stdio_uart ) = NULL ;
662+ #endif
663+
662664 MICROPY_BOARD_END_SOFT_RESET (& state );
663665
664666 gc_sweep_all ();
0 commit comments