|
69 | 69 |
|
70 | 70 | static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED; |
71 | 71 |
|
72 | | -static bool is_print[CFG_TUH_DEVICE_MAX+1] = { 0 }; |
| 72 | +static bool is_printable[CFG_TUH_DEVICE_MAX + 1] = {0}; |
73 | 73 | static tusb_desc_device_t descriptor_device[CFG_TUH_DEVICE_MAX+1]; |
74 | 74 |
|
75 | 75 | static void print_utf16(uint16_t *temp_buf, size_t buf_len); |
@@ -108,6 +108,7 @@ static void usb_device_init(void) { |
108 | 108 | tusb_init(BOARD_TUD_RHPORT, &dev_init); |
109 | 109 | tud_cdc_configure_t cdc_cfg = TUD_CDC_CONFIGURE_DEFAULT(); |
110 | 110 | cdc_cfg.tx_persistent = true; |
| 111 | + cdc_cfg.tx_overwritabe_if_not_connected = false; |
111 | 112 | tud_cdc_configure(&cdc_cfg); |
112 | 113 | board_init_after_tusb(); |
113 | 114 | } |
@@ -209,10 +210,23 @@ void tud_resume_cb(void) { |
209 | 210 | } |
210 | 211 |
|
211 | 212 | void cdc_task(void) { |
| 213 | + static uint32_t connected_ms = 0; |
| 214 | + |
| 215 | + if (!tud_cdc_connected()) { |
| 216 | + connected_ms = board_millis(); |
| 217 | + return; |
| 218 | + } |
| 219 | + |
| 220 | + // delay a bit otherwise we can outpace host's terminal. Linux will set LineState (DTR) then Line Coding. |
| 221 | + // If we send data before Linux's terminal set Line Coding, it can be ignored --> missing data with hardware test loop |
| 222 | + if (board_millis() - connected_ms < 100) { |
| 223 | + return; // wait for stable connection |
| 224 | + } |
| 225 | + |
212 | 226 | for (uint8_t daddr = 1; daddr <= CFG_TUH_DEVICE_MAX; daddr++) { |
213 | 227 | if (tuh_mounted(daddr)) { |
214 | | - if (is_print[daddr]) { |
215 | | - is_print[daddr] = false; |
| 228 | + if (is_printable[daddr]) { |
| 229 | + is_printable[daddr] = false; |
216 | 230 | print_device_info(daddr, &descriptor_device[daddr]); |
217 | 231 | tud_cdc_write_flush(); |
218 | 232 | } |
@@ -279,13 +293,13 @@ void tuh_enum_descriptor_device_cb(uint8_t daddr, tusb_desc_device_t const* desc |
279 | 293 | void tuh_mount_cb(uint8_t daddr) { |
280 | 294 | cdc_printf("mounted device %u\r\n", daddr); |
281 | 295 | tud_cdc_write_flush(); |
282 | | - is_print[daddr] = true; |
| 296 | + is_printable[daddr] = true; |
283 | 297 | } |
284 | 298 |
|
285 | 299 | void tuh_umount_cb(uint8_t daddr) { |
286 | 300 | cdc_printf("unmounted device %u\r\n", daddr); |
287 | 301 | tud_cdc_write_flush(); |
288 | | - is_print[daddr] = false; |
| 302 | + is_printable[daddr] = false; |
289 | 303 | } |
290 | 304 |
|
291 | 305 | //--------------------------------------------------------------------+ |
|
0 commit comments