summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Tomaszewski <kamil.tomaszewski@sony.com>2021-03-15 16:13:39 +0100
committerKamil Tomaszewski <kamil.tomaszewski@sony.com>2021-03-15 16:14:16 +0100
commited3f636be5aaaaebea8e44746ea88298c6d187df (patch)
tree9787ef63571b94cc2727766324146acb397d5c61
parent22ed0abf6c2966d11fc2bbbbaa14a2e9f8a48ac7 (diff)
spresense: empty rx uart fifo after initialization
-rw-r--r--ports/cxd56/common-hal/busio/UART.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/ports/cxd56/common-hal/busio/UART.c b/ports/cxd56/common-hal/busio/UART.c
index 52d2afc0c..30e1dad01 100644
--- a/ports/cxd56/common-hal/busio/UART.c
+++ b/ports/cxd56/common-hal/busio/UART.c
@@ -59,6 +59,9 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
uint32_t baudrate, uint8_t bits, busio_uart_parity_t parity, uint8_t stop,
mp_float_t timeout, uint16_t receiver_buffer_size, byte* receiver_buffer,
bool sigint_enabled) {
+ int i;
+ int count;
+ char tmp;
struct termios tio;
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) {
@@ -96,6 +99,14 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
if (busio_uart_dev[self->number].fd < 0) {
mp_raise_ValueError(translate("Could not initialize UART"));
}
+
+ // Wait to make sure the UART is ready
+ usleep(1000);
+ // Clear RX FIFO
+ ioctl(busio_uart_dev[self->number].fd, FIONREAD, (long unsigned int)&count);
+ for (i = 0; i < count; i++) {
+ read(busio_uart_dev[self->number].fd, &tmp, 1);
+ }
}
ioctl(busio_uart_dev[self->number].fd, TCGETS, (long unsigned int)&tio);