28
28
#include <string.h>
29
29
30
30
#include "py/mpconfig.h"
31
+ #include "py/mphal.h"
31
32
32
33
#include "supervisor/shared/cpu.h"
33
34
#include "supervisor/shared/display.h"
@@ -62,6 +63,13 @@ byte console_uart_rx_buf[64];
62
63
#endif
63
64
#endif
64
65
66
+ #if CIRCUITPY_USB || CIRCUITPY_CONSOLE_UART
67
+ // Flag to note whether this is the first write after connection.
68
+ // Delay slightly on the first write to allow time for the host to set up things,
69
+ // including turning off echo mode.
70
+ static bool _first_write_done = false;
71
+ #endif
72
+
65
73
#if CIRCUITPY_USB_VENDOR
66
74
bool tud_vendor_connected (void );
67
75
#endif
@@ -144,6 +152,10 @@ void serial_early_init(void) {
144
152
}
145
153
146
154
void serial_init (void ) {
155
+ #if CIRCUITPY_USB || CIRCUITPY_CONSOLE_UART
156
+ _first_write_done = false;
157
+ #endif
158
+
147
159
port_serial_init ();
148
160
}
149
161
@@ -301,8 +313,11 @@ void serial_write_substring(const char *text, uint32_t length) {
301
313
#endif
302
314
303
315
#if CIRCUITPY_CONSOLE_UART
316
+ if (!_first_write_done ) {
317
+ mp_hal_delay_ms (50 );
318
+ _first_write_done = true;
319
+ }
304
320
int uart_errcode ;
305
-
306
321
common_hal_busio_uart_write (& console_uart , (const uint8_t * )text , length , & uart_errcode );
307
322
#endif
308
323
@@ -321,6 +336,11 @@ void serial_write_substring(const char *text, uint32_t length) {
321
336
#endif
322
337
323
338
#if CIRCUITPY_USB
339
+ // Delay the very first write
340
+ if (tud_cdc_connected () && !_first_write_done ) {
341
+ mp_hal_delay_ms (50 );
342
+ _first_write_done = true;
343
+ }
324
344
uint32_t count = 0 ;
325
345
if (tud_cdc_connected ()) {
326
346
while (count < length ) {
0 commit comments