Skip to content

Commit badb30a

Browse files
committed
correct cdc host app
1 parent 22b62f8 commit badb30a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

examples/host/cdc_msc_hid/src/cdc_app.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,31 @@ size_t get_console_inputs(uint8_t* buf, size_t bufsize)
5252
void cdc_app_task(void)
5353
{
5454
uint8_t buf[64+1]; // +1 for extra null character
55-
memset(buf, 0, sizeof(buf));
55+
uint32_t const bufsize = sizeof(buf)-1;
5656

57-
size_t count = get_console_inputs(buf, sizeof(buf)-1);
57+
uint32_t console_count = get_console_inputs(buf, bufsize);
58+
buf[console_count] = 0;
5859

5960
// loop over all mounted interfaces
60-
for(size_t idx=0; idx<CFG_TUH_CDC; idx++)
61+
for(uint8_t idx=0; idx<CFG_TUH_CDC; idx++)
6162
{
6263
if ( tuh_cdc_mounted(idx) )
6364
{
6465
// console --> cdc interfaces
65-
if (count)
66+
if (console_count)
6667
{
67-
tuh_cdc_write(idx, buf, count);
68+
tuh_cdc_write(idx, buf, console_count);
6869
tuh_cdc_write_flush(idx);
6970
}
7071

7172
// cdc interfaces -> console
7273
if ( tuh_cdc_read_available(idx) )
7374
{
74-
printf((char*) buf);
75+
uint8_t buf_cdc[64+1];
76+
uint32_t cdc_count = tuh_cdc_read(idx, buf_cdc, sizeof(buf_cdc)-1);
77+
buf_cdc[cdc_count] = 0;
78+
79+
printf((char*) buf_cdc);
7580
}
7681
}
7782
}

src/class/cdc/cdc_host.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
459459
}
460460
else if ( ep_addr == p_cdc->stream.rx.ep_addr )
461461
{
462-
tu_edpt_stream_read_xfer_complete(&p_cdc->stream.rx, xferred_bytes);
462+
// skip if ZLP
463+
if (xferred_bytes) tu_edpt_stream_read_xfer_complete(&p_cdc->stream.rx, xferred_bytes);
463464

464465
// invoke receive callback
465466

0 commit comments

Comments
 (0)