mimxrt/machine_uart: Add uart.deinit method and machine_uart_deinit_all.
The call to machine_uart_deinit_all() is needed to avoid a crash after soft reset, if a UART had been used and data arrives before it is instantiated again. Signed-off-by: robert-hh <robert@hammelrath.com>
This commit is contained in:
parent
a9a219d8bf
commit
e43c669b4a
@ -288,6 +288,14 @@ STATIC mp_obj_t machine_uart_init(size_t n_args, const mp_obj_t *args, mp_map_t
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(machine_uart_init_obj, 1, machine_uart_init);
|
||||
|
||||
// uart.deinit()
|
||||
STATIC mp_obj_t machine_uart_deinit(mp_obj_t self_in) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
LPUART_Deinit(self->lpuart);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_deinit_obj, machine_uart_deinit);
|
||||
|
||||
STATIC mp_obj_t machine_uart_any(mp_obj_t self_in) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
size_t count = LPUART_TransferGetRxRingBufferLength(self->lpuart, &self->handle);
|
||||
@ -314,8 +322,18 @@ STATIC mp_obj_t machine_uart_txdone(mp_obj_t self_in) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_txdone_obj, machine_uart_txdone);
|
||||
|
||||
// Deinitialize all defined UARTs
|
||||
void machine_uart_deinit_all(void) {
|
||||
for (int i = 0; i < sizeof(uart_index_table); i++) {
|
||||
if (uart_index_table[i] != 0) {
|
||||
LPUART_Deinit(uart_base_ptr_table[uart_index_table[i]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t machine_uart_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_uart_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_uart_deinit_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_any), MP_ROM_PTR(&machine_uart_any_obj) },
|
||||
|
||||
|
@ -124,6 +124,7 @@ int main(void) {
|
||||
#if MICROPY_PY_NETWORK
|
||||
mod_network_deinit();
|
||||
#endif
|
||||
machine_uart_deinit_all();
|
||||
machine_pwm_deinit_all();
|
||||
soft_timer_deinit();
|
||||
gc_sweep_all();
|
||||
|
@ -43,6 +43,7 @@ extern const mp_obj_type_t machine_wdt_type;
|
||||
void machine_adc_init(void);
|
||||
void machine_pin_irq_deinit(void);
|
||||
void machine_pwm_deinit_all(void);
|
||||
void machine_uart_deinit_all(void);
|
||||
void machine_timer_init_PIT(void);
|
||||
void machine_sdcard_init0(void);
|
||||
void mimxrt_sdram_init(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user