Skip to content

Commit c9a9e94

Browse files
committed
tweak to dual host info device cdc to make it easier to pass hil test
1 parent 1f8968f commit c9a9e94

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

examples/dual/host_info_to_device_cdc/src/main.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ enum {
6969

7070
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
7171

72-
static bool is_print[CFG_TUH_DEVICE_MAX+1] = { 0 };
72+
static bool is_printable[CFG_TUH_DEVICE_MAX + 1] = {0};
7373
static tusb_desc_device_t descriptor_device[CFG_TUH_DEVICE_MAX+1];
7474

7575
static void print_utf16(uint16_t *temp_buf, size_t buf_len);
@@ -108,6 +108,7 @@ static void usb_device_init(void) {
108108
tusb_init(BOARD_TUD_RHPORT, &dev_init);
109109
tud_cdc_configure_t cdc_cfg = TUD_CDC_CONFIGURE_DEFAULT();
110110
cdc_cfg.tx_persistent = true;
111+
cdc_cfg.tx_overwritabe_if_not_connected = false;
111112
tud_cdc_configure(&cdc_cfg);
112113
board_init_after_tusb();
113114
}
@@ -209,10 +210,23 @@ void tud_resume_cb(void) {
209210
}
210211

211212
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+
212226
for (uint8_t daddr = 1; daddr <= CFG_TUH_DEVICE_MAX; daddr++) {
213227
if (tuh_mounted(daddr)) {
214-
if (is_print[daddr]) {
215-
is_print[daddr] = false;
228+
if (is_printable[daddr]) {
229+
is_printable[daddr] = false;
216230
print_device_info(daddr, &descriptor_device[daddr]);
217231
tud_cdc_write_flush();
218232
}
@@ -279,13 +293,13 @@ void tuh_enum_descriptor_device_cb(uint8_t daddr, tusb_desc_device_t const* desc
279293
void tuh_mount_cb(uint8_t daddr) {
280294
cdc_printf("mounted device %u\r\n", daddr);
281295
tud_cdc_write_flush();
282-
is_print[daddr] = true;
296+
is_printable[daddr] = true;
283297
}
284298

285299
void tuh_umount_cb(uint8_t daddr) {
286300
cdc_printf("unmounted device %u\r\n", daddr);
287301
tud_cdc_write_flush();
288-
is_print[daddr] = false;
302+
is_printable[daddr] = false;
289303
}
290304

291305
//--------------------------------------------------------------------+

examples/dual/host_info_to_device_cdc/src/tusb_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112

113113
// CDC FIFO size of TX and RX
114114
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
115-
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
115+
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 256)
116116

117117
// CDC Endpoint transfer buffer size, more is faster
118118
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

0 commit comments

Comments
 (0)