aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George2019-01-28 22:56:55 +1100
committerDamien George2019-01-28 22:56:55 +1100
commit38022ddb2c44a14b24150f221e63459405531fac (patch)
tree6dc5d83490d2514a65dc8a585d319599f3d5cbe6
parentf431795caf99ef49a5a1010063146ba25f524548 (diff)
stm32/main: Make board-defined UART REPL use a static object and buffer.
This way the UART REPL does not need the MicroPython heap and exists outside the MicroPython runtime, allowing characters to still be received during a soft reset.
-rw-r--r--ports/stm32/main.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/ports/stm32/main.c b/ports/stm32/main.c
index 5d6cbf236..33cfe84ee 100644
--- a/ports/stm32/main.c
+++ b/ports/stm32/main.c
@@ -73,6 +73,14 @@ STATIC pyb_thread_t pyb_thread_main;
STATIC fs_user_mount_t fs_user_mount_flash;
#endif
+#if defined(MICROPY_HW_UART_REPL)
+#ifndef MICROPY_HW_UART_REPL_RXBUF
+#define MICROPY_HW_UART_REPL_RXBUF (64)
+#endif
+STATIC pyb_uart_obj_t pyb_uart_repl_obj;
+STATIC uint8_t pyb_uart_repl_rxbuf[MICROPY_HW_UART_REPL_RXBUF];
+#endif
+
void flash_error(int n) {
for (int i = 0; i < n; i++) {
led_state(PYB_LED_RED, 1);
@@ -541,6 +549,19 @@ void stm32_main(uint32_t reset_mode) {
lwip_init();
#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
+
soft_reset:
#if defined(MICROPY_HW_LED2)
@@ -588,27 +609,17 @@ 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.
- readline_init0();
- pin_init0();
- extint_init0();
- timer_init0();
-
- // Define MICROPY_HW_UART_REPL to be PYB_UART_6 and define
- // MICROPY_HW_UART_REPL_BAUD in your mpconfigboard.h file if you want a
- // REPL on a hardware UART as well as on USB VCP
#if defined(MICROPY_HW_UART_REPL)
- {
- mp_obj_t args[2] = {
- MP_OBJ_NEW_SMALL_INT(MICROPY_HW_UART_REPL),
- MP_OBJ_NEW_SMALL_INT(MICROPY_HW_UART_REPL_BAUD),
- };
- MP_STATE_PORT(pyb_stdio_uart) = pyb_uart_type.make_new((mp_obj_t)&pyb_uart_type, MP_ARRAY_SIZE(args), 0, args);
- uart_attach_to_repl(MP_STATE_PORT(pyb_stdio_uart), true);
- }
+ 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();
+ timer_init0();
+
#if MICROPY_HW_ENABLE_CAN
can_init0();
#endif