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.
pull/4343/head
Damien George 2018-12-10 13:08:31 +11:00
rodzic 61ef031687
commit dc23978dde
4 zmienionych plików z 9 dodań i 6 usunięć

Wyświetl plik

@ -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;

Wyświetl plik

@ -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

Wyświetl plik

@ -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;
}
}
}

Wyświetl plik

@ -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