From e4574fa3bfb1a80218292b5f3b76778bf76cae84 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Mon, 21 Oct 2019 13:17:51 +0200 Subject: [PATCH] Clean UART on reset --- ports/cxd56/common-hal/busio/UART.c | 9 +++++++++ ports/cxd56/common-hal/busio/UART.h | 2 ++ ports/cxd56/supervisor/port.c | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/ports/cxd56/common-hal/busio/UART.c b/ports/cxd56/common-hal/busio/UART.c index 6c59c8f283..4a1376f19a 100644 --- a/ports/cxd56/common-hal/busio/UART.c +++ b/ports/cxd56/common-hal/busio/UART.c @@ -187,3 +187,12 @@ bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) { ioctl(busio_uart_dev[self->number].fd, TCFLSH, (long unsigned int)NULL); return true; } + +void busio_uart_reset(void) { + for (int i = 0; i < MP_ARRAY_SIZE(busio_uart_dev); i++) { + if (busio_uart_dev[i].fd >= 0) { + close(busio_uart_dev[i].fd); + busio_uart_dev[i].fd = -1; + } + } +} diff --git a/ports/cxd56/common-hal/busio/UART.h b/ports/cxd56/common-hal/busio/UART.h index c1f6fff533..e1d8161491 100644 --- a/ports/cxd56/common-hal/busio/UART.h +++ b/ports/cxd56/common-hal/busio/UART.h @@ -40,4 +40,6 @@ typedef struct { uint32_t timeout; } busio_uart_obj_t; +void busio_uart_reset(void); + #endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_UART_H diff --git a/ports/cxd56/supervisor/port.c b/ports/cxd56/supervisor/port.c index 3fddfe52c6..c7ed4b232e 100644 --- a/ports/cxd56/supervisor/port.c +++ b/ports/cxd56/supervisor/port.c @@ -35,6 +35,7 @@ #include "common-hal/analogio/AnalogIn.h" #include "common-hal/pulseio/PulseOut.h" #include "common-hal/pulseio/PWMOut.h" +#include "common-hal/busio/UART.h" safe_mode_t port_init(void) { boardctl(BOARDIOC_INIT, 0); @@ -60,6 +61,9 @@ void reset_port(void) { pulseout_reset(); pwmout_reset(); #endif +#if CIRCUITPY_BUSIO + busio_uart_reset(); +#endif reset_all_pins(); }