pbdrv/uart: implement flush for STM32L4
On STM32L4, pbdrv_uart_read_begin kept returning PBIO_ERROR_AGAIN indefinitely due to the rx buffer not being reset.
This partly addresses the longstanding hotplugging issue In particular, this fixes hotplugging of UART sensors/motors on Technic Hub.
@@ -324,6 +324,12 @@ pbio_error_t pbdrv_uart_set_baud_rate(pbdrv_uart_dev_t *uart_dev, uint32_t baud)
}
void pbdrv_uart_flush(pbdrv_uart_dev_t *uart_dev) {
+ pbdrv_uart_write_cancel(uart_dev);
+ pbdrv_uart_read_cancel(uart_dev);
+
+ pbdrv_uart_t *uart = PBIO_CONTAINER_OF(uart_dev, pbdrv_uart_t, uart_dev);
+ uart->read_buf = NULL;
+ uart->read_length = 0;
}
void pbdrv_uart_stm32l4_ll_dma_handle_tx_dma_irq(uint8_t id) {
