Skip to content

Commit 56c10d2

Browse files
committed
Fix bug: Start buffering where initial TX loading left off
1 parent 3855222 commit 56c10d2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cores/arduino/ard_sup/uart/ap3_uart.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ size_t Uart::write(const uint8_t data)
117117
size_t Uart::write(const uint8_t *buffer, size_t size)
118118
{
119119
uint32_t ui32BytesWritten = 0;
120+
uint32_t remaining = size;
120121

121122
//FIFO on Apollo3 is 32 bytes
122123

@@ -125,11 +126,11 @@ size_t Uart::write(const uint8_t *buffer, size_t size)
125126
am_hal_uart_flags_get(_handle, &uartFlags);
126127
if (uartFlags & AM_HAL_UART_FR_TX_EMPTY)
127128
{
128-
uint32_t amtToSend = size;
129+
uint32_t amtToSend = remaining;
129130
if (amtToSend > AM_HAL_UART_FIFO_MAX)
130131
amtToSend = AM_HAL_UART_FIFO_MAX;
131132

132-
size -= amtToSend;
133+
remaining -= amtToSend;
133134

134135
//Transfer to local buffer
135136
uint8_t tempTX[AM_HAL_UART_FIFO_MAX];
@@ -148,7 +149,7 @@ size_t Uart::write(const uint8_t *buffer, size_t size)
148149
}
149150

150151
//Transfer any remaining bytes into ring buffer
151-
for (int x = 0; x < size; x++)
152+
for (int x = size - remaining; x < size; x++)
152153
{
153154
//If TX ring buffer is full, begin blocking
154155
while (_tx_buffer.availableForStore() == 0)

0 commit comments

Comments
 (0)