Skip to content

Commit fab1c8b

Browse files
committed
Prevent custom task blocking tud_task for 5s every time
1 parent 6a9478b commit fab1c8b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

usb/device/dev_multi_cdc/main.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99
#include <tusb.h>
1010

1111
#include <pico/stdio.h>
12+
#include <pico/stdlib.h>
1213

1314
void custom_cdc_task(void);
1415

16+
bool tud_task_callback(__unused struct repeating_timer *t) {
17+
tud_task();
18+
return true;
19+
}
20+
1521
int main(void)
1622
{
1723
// Initialize TinyUSB stack
@@ -26,15 +32,18 @@ int main(void)
2632
// let pico sdk use the first cdc interface for std io
2733
stdio_init_all();
2834

35+
// TinyUSB device task must be called regularly, so we use a repeating timer
36+
struct repeating_timer timer;
37+
add_repeating_timer_ms(1, tud_task_callback, NULL, &timer);
38+
2939
// main run loop
3040
while (1) {
31-
// TinyUSB device task | must be called regurlarly
32-
tud_task();
33-
34-
// custom tasks
41+
// custom tasks can run in the main loop without blocking the TinyUSB task
3542
custom_cdc_task();
3643
}
3744

45+
cancel_repeating_timer(&timer);
46+
3847
// indicate no error
3948
return 0;
4049
}

usb/device/dev_multi_cdc/usb_descriptors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define CDC_EXAMPLE_VID 0xCafe
1616
// use _PID_MAP to generate unique PID for each interface
1717
#define CDC_EXAMPLE_PID (0x4000 | _PID_MAP(CDC, 0))
18-
// set USB 2.0
18+
// set to 2.10 so the MS_OS_20_DESCRIPTOR works
1919
#define CDC_EXAMPLE_BCD 0x0210
2020

2121
// String descriptors referenced with .i... in the descriptor tables

0 commit comments

Comments
 (0)