File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed
ports/espressif/supervisor Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -98,14 +98,23 @@ bool usb_serial_jtag_bytes_available(void) {
98
98
}
99
99
100
100
void usb_serial_jtag_write (const char * text , uint32_t length ) {
101
- if (USB_SERIAL_JTAG .fram_num .sof_frame_index > 0 ) {
102
- size_t total_written = 0 ;
101
+ if (!usb_serial_jtag_connected ()) {
102
+ return ;
103
+ }
104
+ size_t total_written = 0 ;
105
+ while (total_written < length ) {
103
106
uint32_t start_time = supervisor_ticks_ms32 ();
104
- // Time out after 5 milliseconds in case usb isn't actually reading CDC.
105
- while (total_written < length && start_time - supervisor_ticks_ms32 () < 5 ) {
106
- total_written += usb_serial_jtag_ll_write_txfifo ((const uint8_t * )(text + total_written ), length - total_written );
107
- RUN_BACKGROUND_TASKS ;
107
+ // Wait until we can write to the FIFO again. If it takes too long, then
108
+ // assume we're disconnected.
109
+ while (!usb_serial_jtag_ll_txfifo_writable ()) {
110
+ uint32_t now = supervisor_ticks_ms32 ();
111
+ if (now - start_time > 200 ) {
112
+ connected = false;
113
+ return ;
114
+ }
108
115
}
109
- usb_serial_jtag_ll_txfifo_flush ();
116
+ total_written += usb_serial_jtag_ll_write_txfifo ((const uint8_t * )(text + total_written ), length - total_written );
117
+ RUN_BACKGROUND_TASKS ;
110
118
}
119
+ usb_serial_jtag_ll_txfifo_flush ();
111
120
}
You can’t perform that action at this time.
0 commit comments