fix(uart): fix send_size calculation in uart_write_bytes

MIN() macro is only an expansion of a conditional operator.
xRingbufferGetCurFreeSize was called twice in the original code,
which may return different values in two calls, leading to incorrect
send_size calculation and eventually could trigger task watchdog.
This commit is contained in:
Song Ruo Jing
2025-11-11 17:31:23 +08:00
parent f4703a2629
commit 335273c53e
+2 -1
View File
@@ -1638,7 +1638,8 @@ static int uart_tx_all(uart_port_t uart_num, const char *src, size_t size, bool
}
xRingbufferSend(p_uart_obj[uart_num]->tx_ring_buf, (void *) &evt, sizeof(uart_tx_data_t), portMAX_DELAY);
while (size > 0) {
size_t send_size = MIN(size, xRingbufferGetCurFreeSize(p_uart_obj[uart_num]->tx_ring_buf));
size_t free_size = xRingbufferGetCurFreeSize(p_uart_obj[uart_num]->tx_ring_buf);
size_t send_size = MIN(size, free_size);
if (send_size > 0) {
xRingbufferSend(p_uart_obj[uart_num]->tx_ring_buf, (void *)(src + offset), send_size, portMAX_DELAY);
size -= send_size;