@@ -62,6 +62,13 @@ byte console_uart_rx_buf[64];
62
62
#endif
63
63
#endif
64
64
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
+
65
72
#if CIRCUITPY_USB_VENDOR
66
73
bool tud_vendor_connected (void );
67
74
#endif
@@ -144,6 +151,10 @@ void serial_early_init(void) {
144
151
}
145
152
146
153
void serial_init (void ) {
154
+ #if CIRCUITPY_USB || CIRCUITPY_CONSOLE_UART
155
+ _first_write_done = false;
156
+ #endif
157
+
147
158
port_serial_init ();
148
159
}
149
160
@@ -301,8 +312,11 @@ void serial_write_substring(const char *text, uint32_t length) {
301
312
#endif
302
313
303
314
#if CIRCUITPY_CONSOLE_UART
315
+ if (!_first_write_done ) {
316
+ mp_hal_delay_ms (50 );
317
+ _first_write_done = true;
318
+ }
304
319
int uart_errcode ;
305
-
306
320
common_hal_busio_uart_write (& console_uart , (const uint8_t * )text , length , & uart_errcode );
307
321
#endif
308
322
@@ -321,6 +335,11 @@ void serial_write_substring(const char *text, uint32_t length) {
321
335
#endif
322
336
323
337
#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
+ }
324
343
uint32_t count = 0 ;
325
344
if (tud_cdc_connected ()) {
326
345
while (count < length ) {
0 commit comments