Skip to content

Commit 3d5c54e

Browse files
committed
Make HardwareSerial.flush() compatible with Arduino 1.0 api
1 parent e3753df commit 3d5c54e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

STM32F1/cores/maple/HardwareSerial.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ size_t HardwareSerial::write(unsigned char ch) {
193193
return 1;
194194
}
195195

196+
/* edogaldo: Waits for the transmission of outgoing serial data to complete (Arduino 1.0 api specs) */
196197
void HardwareSerial::flush(void) {
197-
usart_reset_rx(this->usart_device);
198-
usart_reset_tx(this->usart_device);
198+
while(!rb_is_empty(this->usart_device->wb)); // wait for TX buffer empty
199+
while(!((this->usart_device->regs->SR) & (1<<USART_SR_TC_BIT))); // wait for TC (Transmission Complete) flag set
199200
}

STM32F1/system/libmaple/include/libmaple/ring_buffer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ extern "C"{
5252
* One byte is left free to distinguish empty from full. */
5353
typedef struct ring_buffer {
5454
volatile uint8 *buf; /**< Buffer items are stored into */
55-
uint16 head; /**< Index of the next item to remove */
56-
uint16 tail; /**< Index where the next item will get inserted */
57-
uint16 size; /**< Buffer capacity minus one */
55+
volatile uint16 head; /**< Index of the next item to remove */
56+
volatile uint16 tail; /**< Index where the next item will get inserted */
57+
volatile uint16 size; /**< Buffer capacity minus one */
5858
} ring_buffer;
5959

6060
/**

0 commit comments

Comments
 (0)