File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -99,14 +99,16 @@ int HardwareSerial::available(void)
99
99
100
100
void HardwareSerial::flush ()
101
101
{
102
+ uint8_t bit_length = 0 ;
102
103
if (!_uart || !uart_tx_enabled (_uart)) {
103
104
return ;
104
105
}
105
106
107
+ bit_length = uart_get_bit_length (_uart_nr); // data width, parity and stop
106
108
uart_wait_tx_empty (_uart);
107
109
// Workaround for a bug in serial not actually being finished yet
108
110
// Wait for 8 data bits, 1 parity and 2 stop bits, just in case
109
- delayMicroseconds (11000000 / uart_get_baudrate (_uart) + 1 );
111
+ delayMicroseconds (bit_length * 1000000 / uart_get_baudrate (_uart) + 1 );
110
112
}
111
113
112
114
void HardwareSerial::startDetectBaudrate ()
Original file line number Diff line number Diff line change 48
48
#include " user_interface.h"
49
49
#include " uart_register.h"
50
50
51
+ #define MODE2WIDTH (mode ) (((mode%16 )>>2 )+5 )
52
+ #define MODE2STOP (mode ) (((mode)>>5 )+1 )
53
+ #define MODE2PARITY (mode ) (mode%4 )
54
+
51
55
/*
52
56
Some general architecture for GDB integration with the UART to enable
53
57
serial debugging.
@@ -204,6 +208,13 @@ uart_read_char_unsafe(uart_t* uart)
204
208
return -1 ;
205
209
}
206
210
211
+ uint8_t
212
+ uart_get_bit_length (const int uart_nr)
213
+ {
214
+ // return bit length from uart mode, +1 for the start bit which is always there.
215
+ return MODE2WIDTH (USC0 (uart_nr)) + MODE2PARITY (USC0 (uart_nr)) + MODE2STOP (USC0 (uart_nr)) + 1 ;
216
+ }
217
+
207
218
size_t
208
219
uart_rx_available (uart_t * uart)
209
220
{
Original file line number Diff line number Diff line change @@ -147,6 +147,7 @@ int uart_get_debug();
147
147
void uart_start_detect_baudrate (int uart_nr );
148
148
int uart_detect_baudrate (int uart_nr );
149
149
150
+ uint8_t uart_get_bit_length (const int uart_nr );
150
151
151
152
#if defined (__cplusplus )
152
153
} // extern "C"
You can’t perform that action at this time.
0 commit comments