From 4c2caed73357c2173649d5a105cad5277eaa85f7 Mon Sep 17 00:00:00 2001 From: Oxore Date: Thu, 9 Mar 2023 03:10:31 +0300 Subject: Fix UART buffering, now it works --- app/platform/stm32f0-gcc/uart.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'app/platform/stm32f0-gcc/uart.cpp') diff --git a/app/platform/stm32f0-gcc/uart.cpp b/app/platform/stm32f0-gcc/uart.cpp index 4d9bf5f..89472ee 100644 --- a/app/platform/stm32f0-gcc/uart.cpp +++ b/app/platform/stm32f0-gcc/uart.cpp @@ -42,7 +42,7 @@ UART g_uart4{ RingBuffer(g_uart4_tx_buffer, kUART4TxBufferSize), }; -static constexpr Min(size_t a, size_t b) { return (a >= b) ? a : b; } +static constexpr Min(size_t a, size_t b) { return (a <= b) ? a : b; } size_t UARTWrite(UART* uart, const void *buf, size_t nbytes) { @@ -96,19 +96,20 @@ void UARTHandleInterrupt(UART* uart) return; for (int _ = 0; _ < 256; _++) { const uint32_t isr = usart_regs->ISR; - const bool rxne = isr & USART_ISR_RXNE; - const bool txe = isr & USART_ISR_TXE; - if (!rxne && !txe) - break; - if (rxne) { + bool done = true; + if (isr & USART_ISR_RXNE) { uart->rx_buffer.Push(usart_regs->RDR); + done = false; } - if (txe) { + if (isr & USART_ISR_TXE) { if (!uart->tx_buffer.IsEmpty()) { usart_regs->TDR = uart->tx_buffer.Pop(); + done = false; } else { usart_regs->CR1 &= ~USART_CR1_TXEIE; } } + if (done) + break; } } -- cgit v1.2.3