summaryrefslogtreecommitdiff
path: root/app/platform/stm32f0-gcc/uart.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'app/platform/stm32f0-gcc/uart.cpp')
-rw-r--r--app/platform/stm32f0-gcc/uart.cpp15
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;
}
}