|
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); |
@@ -106,6 +106,10 @@ static void usb_device_init(void) { |
106 | 106 | .speed = TUSB_SPEED_AUTO |
107 | 107 | }; |
108 | 108 | tusb_init(BOARD_TUD_RHPORT, &dev_init); |
| 109 | + tud_cdc_configure_t cdc_cfg = TUD_CDC_CONFIGURE_DEFAULT(); |
| 110 | + cdc_cfg.tx_persistent = true; |
| 111 | + cdc_cfg.tx_overwritabe_if_not_connected = false; |
| 112 | + tud_cdc_configure(&cdc_cfg); |
109 | 113 | board_init_after_tusb(); |
110 | 114 | } |
111 | 115 |
|
@@ -206,17 +210,23 @@ void tud_resume_cb(void) { |
206 | 210 | } |
207 | 211 |
|
208 | 212 | void cdc_task(void) { |
| 213 | + static uint32_t connected_ms = 0; |
| 214 | + |
209 | 215 | if (!tud_cdc_connected()) { |
210 | | - // delay a bit otherwise we can outpace host's terminal. Linux will set LineState (DTR) then Line Coding. |
211 | | - // If we send data before Linux's terminal set Line Coding, it can be ignored --> missing data with hardware test loop |
212 | | - tusb_time_delay_ms_api(20); |
| 216 | + connected_ms = board_millis(); |
213 | 217 | return; |
214 | 218 | } |
215 | 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 | + |
216 | 226 | for (uint8_t daddr = 1; daddr <= CFG_TUH_DEVICE_MAX; daddr++) { |
217 | 227 | if (tuh_mounted(daddr)) { |
218 | | - if (is_print[daddr]) { |
219 | | - is_print[daddr] = false; |
| 228 | + if (is_printable[daddr]) { |
| 229 | + is_printable[daddr] = false; |
220 | 230 | print_device_info(daddr, &descriptor_device[daddr]); |
221 | 231 | tud_cdc_write_flush(); |
222 | 232 | } |
@@ -283,13 +293,13 @@ void tuh_enum_descriptor_device_cb(uint8_t daddr, tusb_desc_device_t const* desc |
283 | 293 | void tuh_mount_cb(uint8_t daddr) { |
284 | 294 | cdc_printf("mounted device %u\r\n", daddr); |
285 | 295 | tud_cdc_write_flush(); |
286 | | - is_print[daddr] = true; |
| 296 | + is_printable[daddr] = true; |
287 | 297 | } |
288 | 298 |
|
289 | 299 | void tuh_umount_cb(uint8_t daddr) { |
290 | 300 | cdc_printf("unmounted device %u\r\n", daddr); |
291 | 301 | tud_cdc_write_flush(); |
292 | | - is_print[daddr] = false; |
| 302 | + is_printable[daddr] = false; |
293 | 303 | } |
294 | 304 |
|
295 | 305 | //--------------------------------------------------------------------+ |
|
0 commit comments