summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-12-10 13:08:31 +1100
committerDamien George <damien.p.george@gmail.com>2018-12-10 16:21:50 +1100
commitdc23978ddeaf46f67f653a4653e07065aa7d6ad4 (patch)
treed116b6778190a6b88a0576f71295b876e90d5fe6
parent61ef0316879aea9b7a3b6d0538a6143043fba0d2 (diff)
stm32/uart: Add ability to have a static built-in UART object.
A static UART is useful for internal peripherals that require a UART and need to persist outside the soft-reset loop.
-rw-r--r--ports/stm32/machine_uart.c5
-rw-r--r--ports/stm32/main.c2
-rw-r--r--ports/stm32/uart.c7
-rw-r--r--ports/stm32/uart.h1
4 files changed, 9 insertions, 6 deletions
diff --git a/ports/stm32/machine_uart.c b/ports/stm32/machine_uart.c
index f5f56c703..1a21ff8f4 100644
--- a/ports/stm32/machine_uart.c
+++ b/ports/stm32/machine_uart.c
@@ -161,6 +161,11 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const
mp_arg_parse_all(n_args, pos_args, kw_args,
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&args);
+ // static UARTs are used for internal purposes and shouldn't be reconfigured
+ if (self->is_static) {
+ mp_raise_ValueError("UART is static and can't be init'd");
+ }
+
// baudrate
uint32_t baudrate = args.baudrate.u_int;
diff --git a/ports/stm32/main.c b/ports/stm32/main.c
index f14176efa..62cba5434 100644
--- a/ports/stm32/main.c
+++ b/ports/stm32/main.c
@@ -518,6 +518,7 @@ void stm32_main(uint32_t reset_mode) {
#if MICROPY_HW_ENABLE_RTC
rtc_init_start(false);
#endif
+ uart_init0();
spi_init0();
#if MICROPY_PY_PYB_LEGACY && MICROPY_HW_ENABLE_HW_I2C
i2c_init0();
@@ -586,7 +587,6 @@ soft_reset:
pin_init0();
extint_init0();
timer_init0();
- uart_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
diff --git a/ports/stm32/uart.c b/ports/stm32/uart.c
index 9d93bc1e5..ff1e86004 100644
--- a/ports/stm32/uart.c
+++ b/ports/stm32/uart.c
@@ -64,18 +64,15 @@ void uart_init0(void) {
__fatal_error("HAL_RCCEx_PeriphCLKConfig");
}
#endif
-
- for (int i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(pyb_uart_obj_all)); i++) {
- MP_STATE_PORT(pyb_uart_obj_all)[i] = NULL;
- }
}
// unregister all interrupt sources
void uart_deinit_all(void) {
for (int i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(pyb_uart_obj_all)); i++) {
pyb_uart_obj_t *uart_obj = MP_STATE_PORT(pyb_uart_obj_all)[i];
- if (uart_obj != NULL) {
+ if (uart_obj != NULL && !uart_obj->is_static) {
uart_deinit(uart_obj);
+ MP_STATE_PORT(pyb_uart_obj_all)[i] = NULL;
}
}
}
diff --git a/ports/stm32/uart.h b/ports/stm32/uart.h
index bc50248c1..285277515 100644
--- a/ports/stm32/uart.h
+++ b/ports/stm32/uart.h
@@ -46,6 +46,7 @@ typedef struct _pyb_uart_obj_t {
USART_TypeDef *uartx;
IRQn_Type irqn;
pyb_uart_t uart_id : 8;
+ bool is_static : 1;
bool is_enabled : 1;
bool attached_to_repl; // whether the UART is attached to REPL
byte char_width; // 0 for 7,8 bit chars, 1 for 9 bit chars