Skip to content
Snippets Groups Projects
Commit dc23978d authored by Damien George's avatar Damien George
Browse files

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.
parent 61ef0316
No related branches found
No related tags found
No related merge requests found
...@@ -161,6 +161,11 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const ...@@ -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_arg_parse_all(n_args, pos_args, kw_args,
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&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 // baudrate
uint32_t baudrate = args.baudrate.u_int; uint32_t baudrate = args.baudrate.u_int;
......
...@@ -518,6 +518,7 @@ void stm32_main(uint32_t reset_mode) { ...@@ -518,6 +518,7 @@ void stm32_main(uint32_t reset_mode) {
#if MICROPY_HW_ENABLE_RTC #if MICROPY_HW_ENABLE_RTC
rtc_init_start(false); rtc_init_start(false);
#endif #endif
uart_init0();
spi_init0(); spi_init0();
#if MICROPY_PY_PYB_LEGACY && MICROPY_HW_ENABLE_HW_I2C #if MICROPY_PY_PYB_LEGACY && MICROPY_HW_ENABLE_HW_I2C
i2c_init0(); i2c_init0();
...@@ -586,7 +587,6 @@ soft_reset: ...@@ -586,7 +587,6 @@ soft_reset:
pin_init0(); pin_init0();
extint_init0(); extint_init0();
timer_init0(); timer_init0();
uart_init0();
// Define MICROPY_HW_UART_REPL to be PYB_UART_6 and define // 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 // MICROPY_HW_UART_REPL_BAUD in your mpconfigboard.h file if you want a
......
...@@ -64,18 +64,15 @@ void uart_init0(void) { ...@@ -64,18 +64,15 @@ void uart_init0(void) {
__fatal_error("HAL_RCCEx_PeriphCLKConfig"); __fatal_error("HAL_RCCEx_PeriphCLKConfig");
} }
#endif #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 // unregister all interrupt sources
void uart_deinit_all(void) { void uart_deinit_all(void) {
for (int i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(pyb_uart_obj_all)); i++) { 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]; 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); uart_deinit(uart_obj);
MP_STATE_PORT(pyb_uart_obj_all)[i] = NULL;
} }
} }
} }
......
...@@ -46,6 +46,7 @@ typedef struct _pyb_uart_obj_t { ...@@ -46,6 +46,7 @@ typedef struct _pyb_uart_obj_t {
USART_TypeDef *uartx; USART_TypeDef *uartx;
IRQn_Type irqn; IRQn_Type irqn;
pyb_uart_t uart_id : 8; pyb_uart_t uart_id : 8;
bool is_static : 1;
bool is_enabled : 1; bool is_enabled : 1;
bool attached_to_repl; // whether the UART is attached to REPL 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 byte char_width; // 0 for 7,8 bit chars, 1 for 9 bit chars
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment