tweak to dual host info device cdc to make it easier to pass hil test

This commit is contained in:
hathach
2025-11-13 14:34:17 +07:00
parent 1f8968f622
commit c9a9e94ae5
2 changed files with 20 additions and 6 deletions

View File

@ -69,7 +69,7 @@ enum {
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
static bool is_print[CFG_TUH_DEVICE_MAX+1] = { 0 };
static bool is_printable[CFG_TUH_DEVICE_MAX + 1] = {0};
static tusb_desc_device_t descriptor_device[CFG_TUH_DEVICE_MAX+1];
static void print_utf16(uint16_t *temp_buf, size_t buf_len);
@ -108,6 +108,7 @@ static void usb_device_init(void) {
tusb_init(BOARD_TUD_RHPORT, &dev_init);
tud_cdc_configure_t cdc_cfg = TUD_CDC_CONFIGURE_DEFAULT();
cdc_cfg.tx_persistent = true;
cdc_cfg.tx_overwritabe_if_not_connected = false;
tud_cdc_configure(&cdc_cfg);
board_init_after_tusb();
}
@ -209,10 +210,23 @@ void tud_resume_cb(void) {
}
void cdc_task(void) {
static uint32_t connected_ms = 0;
if (!tud_cdc_connected()) {
connected_ms = board_millis();
return;
}
// delay a bit otherwise we can outpace host's terminal. Linux will set LineState (DTR) then Line Coding.
// If we send data before Linux's terminal set Line Coding, it can be ignored --> missing data with hardware test loop
if (board_millis() - connected_ms < 100) {
return; // wait for stable connection
}
for (uint8_t daddr = 1; daddr <= CFG_TUH_DEVICE_MAX; daddr++) {
if (tuh_mounted(daddr)) {
if (is_print[daddr]) {
is_print[daddr] = false;
if (is_printable[daddr]) {
is_printable[daddr] = false;
print_device_info(daddr, &descriptor_device[daddr]);
tud_cdc_write_flush();
}
@ -279,13 +293,13 @@ void tuh_enum_descriptor_device_cb(uint8_t daddr, tusb_desc_device_t const* desc
void tuh_mount_cb(uint8_t daddr) {
cdc_printf("mounted device %u\r\n", daddr);
tud_cdc_write_flush();
is_print[daddr] = true;
is_printable[daddr] = true;
}
void tuh_umount_cb(uint8_t daddr) {
cdc_printf("unmounted device %u\r\n", daddr);
tud_cdc_write_flush();
is_print[daddr] = false;
is_printable[daddr] = false;
}
//--------------------------------------------------------------------+

View File

@ -112,7 +112,7 @@
// CDC FIFO size of TX and RX
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 256)
// CDC Endpoint transfer buffer size, more is faster
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)