diff options
author | Oxore <oxore@protonmail.com> | 2023-03-09 03:10:31 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2023-03-09 03:10:31 +0300 |
commit | 4c2caed73357c2173649d5a105cad5277eaa85f7 (patch) | |
tree | 74ce01d223c592d2fbadfc295761be2d74d5dab5 /app/platform/stm32f0-gcc/uart.cpp | |
parent | 7a0b96bf5c46521d6d8d2b527eb7099420a97aad (diff) |
Fix UART buffering, now it works
Diffstat (limited to 'app/platform/stm32f0-gcc/uart.cpp')
-rw-r--r-- | app/platform/stm32f0-gcc/uart.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
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<uint8_t>(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; } } |