Skip to content

Commit c730bf7

Browse files
committed
delay first serial write by 50ms
1 parent fed8847 commit c730bf7

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

supervisor/shared/serial.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ byte console_uart_rx_buf[64];
6262
#endif
6363
#endif
6464

65+
#if CIRCUITPY_USB || CIRCUITPY_CONSOLE_UART
66+
// Flag to note whether this is the first write after connection.
67+
// Delay slightly on the first write to allow time for the host to set up things,
68+
// including turning off echo mode.
69+
static bool _first_write_done = false;
70+
#endif
71+
6572
#if CIRCUITPY_USB_VENDOR
6673
bool tud_vendor_connected(void);
6774
#endif
@@ -144,6 +151,10 @@ void serial_early_init(void) {
144151
}
145152

146153
void serial_init(void) {
154+
#if CIRCUITPY_USB || CIRCUITPY_CONSOLE_UART
155+
_first_write_done = false;
156+
#endif
157+
147158
port_serial_init();
148159
}
149160

@@ -301,8 +312,11 @@ void serial_write_substring(const char *text, uint32_t length) {
301312
#endif
302313

303314
#if CIRCUITPY_CONSOLE_UART
315+
if (!_first_write_done) {
316+
mp_hal_delay_ms(50);
317+
_first_write_done = true;
318+
}
304319
int uart_errcode;
305-
306320
common_hal_busio_uart_write(&console_uart, (const uint8_t *)text, length, &uart_errcode);
307321
#endif
308322

@@ -321,6 +335,11 @@ void serial_write_substring(const char *text, uint32_t length) {
321335
#endif
322336

323337
#if CIRCUITPY_USB
338+
// Delay the very first write
339+
if (tud_cdc_connected() && !_first_write_done) {
340+
mp_hal_delay_ms(50);
341+
_first_write_done = true;
342+
}
324343
uint32_t count = 0;
325344
if (tud_cdc_connected()) {
326345
while (count < length) {

0 commit comments

Comments
 (0)