Skip to content

Commit 1fc6c63

Browse files
committed
Fix cli serial overflow
1 parent 6df8d0e commit 1fc6c63

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/config

src/main/cli/cli.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6896,7 +6896,7 @@ void cliEnter(serialPort_t *serialPort, bool interactive)
68966896
setPrintfSerialPort(cliPort);
68976897
}
68986898

6899-
bufWriterInit(&cliWriterDesc, cliWriteBuffer, sizeof(cliWriteBuffer), (bufWrite_t)serialWriteBufShim, serialPort);
6899+
bufWriterInit(&cliWriterDesc, cliWriteBuffer, sizeof(cliWriteBuffer), (bufWrite_t)serialWriteBufBlockingShim, serialPort);
69006900
cliErrorWriter = cliWriter = &cliWriterDesc;
69016901

69026902
if (interactive) {

src/main/drivers/serial.c

+10
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,18 @@ void serialWriteBuf(serialPort_t *instance, const uint8_t *data, int count)
129129
serialEndWrite(instance);
130130
}
131131

132+
void serialWriteBufBlocking(serialPort_t *instance, const uint8_t *data, int count)
133+
{
134+
while (serialTxBytesFree(instance) < (uint32_t)count) /* NOP */;
135+
serialWriteBuf(instance, data, count);
136+
}
137+
132138
void serialWriteBufShim(void *instance, const uint8_t *data, int count)
133139
{
134140
serialWriteBuf((serialPort_t *)instance, data, count);
135141
}
136142

143+
void serialWriteBufBlockingShim(void *instance, const uint8_t *data, int count)
144+
{
145+
serialWriteBufBlocking(instance, data, count);
146+
}

src/main/drivers/serial.h

+1
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,6 @@ uint32_t serialGetBaudRate(serialPort_t *instance);
150150

151151
// A shim that adapts the bufWriter API to the serialWriteBuf() API.
152152
void serialWriteBufShim(void *instance, const uint8_t *data, int count);
153+
void serialWriteBufBlockingShim(void *instance, const uint8_t *data, int count);
153154
void serialBeginWrite(serialPort_t *instance);
154155
void serialEndWrite(serialPort_t *instance);

0 commit comments

Comments
 (0)