Skip to content

Commit 5c4e10e

Browse files
committed
SerialX.flush() - now wait until TC Complete
SerialX.flush() - now waits until the TX completes... Looks at the TC flag of the uart to know when it has completed the transfer. Moved the flush() function to .cpp file as it now uses the device header file which is only included in the .cpp file
1 parent a64ced3 commit 5c4e10e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Diff for: cores/arduino/zephyrSerial.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ size_t arduino::ZephyrSerial::write(const uint8_t *buffer, size_t size)
189189
return size;
190190
}
191191

192+
void arduino::ZephyrSerial::flush() {
193+
while (ring_buf_size_get(&tx.ringbuf) > 0) {
194+
k_yield();
195+
}
196+
while (uart_irq_tx_complete(uart) == 0){
197+
k_yield();
198+
}
199+
}
200+
201+
192202
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), serials)
193203
#if !DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm)
194204
// If CDC USB, use that object as Serial (and SerialUSB)

Diff for: cores/arduino/zephyrSerial.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ class ZephyrSerial : public HardwareSerial
5151
ZephyrSerial(const struct device *dev) : uart(dev) { }
5252
void begin(unsigned long baudrate, uint16_t config);
5353
void begin(unsigned long baudrate) { begin(baudrate, SERIAL_8N1); }
54-
void flush() {
55-
while (ring_buf_size_get(&tx.ringbuf) > 0) {
56-
k_yield();
57-
}
58-
}
54+
void flush();
5955
void end() { }
6056
size_t write(const uint8_t *buffer, size_t size);
6157
size_t write(const uint8_t data) { return write(&data, 1); }

0 commit comments

Comments
 (0)