From 92602b9de3675c2d3e240bcd0838082e1a07b13b Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 11 Oct 2024 12:58:18 +0700 Subject: [PATCH 1/6] change tusb_init(), tusb_rhport_init() to use init struct for expandability --- .../device/audio_4_channel_mic/src/main.c | 7 +++- .../audio_4_channel_mic_freertos/src/main.c | 7 +++- examples/device/audio_test/src/main.c | 7 +++- .../device/audio_test_freertos/src/main.c | 7 +++- .../device/audio_test_multi_rate/src/main.c | 7 +++- examples/device/cdc_dual_ports/src/main.c | 7 +++- examples/device/cdc_msc/src/main.c | 7 +++- examples/device/cdc_msc_freertos/src/main.c | 7 +++- examples/device/cdc_uac2/src/main.c | 7 +++- examples/device/dfu/src/main.c | 7 +++- examples/device/dfu_runtime/src/main.c | 7 +++- .../device/dynamic_configuration/src/main.c | 7 +++- examples/device/hid_boot_interface/src/main.c | 7 +++- examples/device/hid_composite/src/main.c | 7 +++- .../device/hid_composite_freertos/src/main.c | 7 +++- examples/device/hid_generic_inout/src/main.c | 7 +++- .../device/hid_multiple_interface/src/main.c | 7 +++- examples/device/midi_test/src/main.c | 7 +++- examples/device/msc_dual_lun/src/main.c | 7 +++- examples/device/net_lwip_webserver/src/main.c | 7 +++- examples/device/uac2_headset/src/main.c | 7 +++- examples/device/uac2_speaker_fb/src/main.c | 7 +++- examples/device/usbtmc/src/main.c | 7 +++- examples/device/video_capture/src/main.c | 14 ++++++-- examples/device/video_capture_2ch/src/main.c | 14 ++++++-- examples/device/webusb_serial/src/main.c | 7 +++- .../dual/host_hid_to_device_cdc/src/main.c | 15 ++++++-- .../dual/host_info_to_device_cdc/src/main.c | 15 ++++++-- examples/host/bare_api/src/main.c | 7 +++- examples/host/cdc_msc_hid/src/main.c | 7 +++- examples/host/cdc_msc_hid_freertos/src/main.c | 8 ++++- examples/host/device_info/src/main.c | 7 +++- examples/host/hid_controller/src/main.c | 7 +++- examples/host/msc_file_explorer/src/main.c | 7 +++- src/common/tusb_common.h | 2 +- src/common/tusb_compiler.h | 8 +++++ src/common/tusb_types.h | 10 ++++++ src/common/tusb_verify.h | 3 -- src/device/usbd.c | 17 ++++++---- src/device/usbd.h | 15 +++++++- src/host/usbh.c | 16 +++++---- src/host/usbh.h | 22 +++++++++--- src/tusb.c | 34 ++++++++++++------- src/tusb.h | 16 ++++++--- .../test/device/msc/test_msc_device.c | 8 ++++- test/unit-test/test/device/usbd/test_usbd.c | 8 ++++- 46 files changed, 348 insertions(+), 80 deletions(-) diff --git a/examples/device/audio_4_channel_mic/src/main.c b/examples/device/audio_4_channel_mic/src/main.c index 6c75d95bfe..ca0e67faea 100644 --- a/examples/device/audio_4_channel_mic/src/main.c +++ b/examples/device/audio_4_channel_mic/src/main.c @@ -86,7 +86,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/audio_4_channel_mic_freertos/src/main.c b/examples/device/audio_4_channel_mic_freertos/src/main.c index d24113df60..c1ebc48993 100644 --- a/examples/device/audio_4_channel_mic_freertos/src/main.c +++ b/examples/device/audio_4_channel_mic_freertos/src/main.c @@ -209,7 +209,12 @@ void usb_device_task(void* param) // init device stack on configured roothub port // This should be called after scheduler/kernel is started. // Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API. - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/audio_test/src/main.c b/examples/device/audio_test/src/main.c index 9702060e0a..f4c1bf95fc 100644 --- a/examples/device/audio_test/src/main.c +++ b/examples/device/audio_test/src/main.c @@ -79,7 +79,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/audio_test_freertos/src/main.c b/examples/device/audio_test_freertos/src/main.c index 3d9166263e..b7d7dc0426 100644 --- a/examples/device/audio_test_freertos/src/main.c +++ b/examples/device/audio_test_freertos/src/main.c @@ -156,7 +156,12 @@ void usb_device_task(void* param) // init device stack on configured roothub port // This should be called after scheduler/kernel is started. // Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API. - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/audio_test_multi_rate/src/main.c b/examples/device/audio_test_multi_rate/src/main.c index 99b81f74df..a1c4d32dbe 100644 --- a/examples/device/audio_test_multi_rate/src/main.c +++ b/examples/device/audio_test_multi_rate/src/main.c @@ -97,7 +97,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/cdc_dual_ports/src/main.c b/examples/device/cdc_dual_ports/src/main.c index 07f41371a2..b446bca0b3 100644 --- a/examples/device/cdc_dual_ports/src/main.c +++ b/examples/device/cdc_dual_ports/src/main.c @@ -52,7 +52,12 @@ int main(void) { board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c index a1f178e2a4..47ba5a8878 100644 --- a/examples/device/cdc_msc/src/main.c +++ b/examples/device/cdc_msc/src/main.c @@ -51,7 +51,12 @@ int main(void) { board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c index b84b33a8cb..a08e063ac1 100644 --- a/examples/device/cdc_msc_freertos/src/main.c +++ b/examples/device/cdc_msc_freertos/src/main.c @@ -132,7 +132,12 @@ static void usb_device_task(void *param) { // init device stack on configured roothub port // This should be called after scheduler/kernel is started. // Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API. - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/cdc_uac2/src/main.c b/examples/device/cdc_uac2/src/main.c index a75ec14270..384d910ec0 100644 --- a/examples/device/cdc_uac2/src/main.c +++ b/examples/device/cdc_uac2/src/main.c @@ -46,7 +46,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); #if (CFG_TUSB_MCU == OPT_MCU_RP2040) stdio_init_all(); diff --git a/examples/device/dfu/src/main.c b/examples/device/dfu/src/main.c index 5efec9d322..f2aea7cfc7 100644 --- a/examples/device/dfu/src/main.c +++ b/examples/device/dfu/src/main.c @@ -75,7 +75,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/dfu_runtime/src/main.c b/examples/device/dfu_runtime/src/main.c index c21034fc1f..5d6b907b7a 100644 --- a/examples/device/dfu_runtime/src/main.c +++ b/examples/device/dfu_runtime/src/main.c @@ -70,7 +70,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/dynamic_configuration/src/main.c b/examples/device/dynamic_configuration/src/main.c index bc9ab0b2ba..143570c5c0 100644 --- a/examples/device/dynamic_configuration/src/main.c +++ b/examples/device/dynamic_configuration/src/main.c @@ -57,7 +57,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/hid_boot_interface/src/main.c b/examples/device/hid_boot_interface/src/main.c index 351a60854b..dfee7421d4 100644 --- a/examples/device/hid_boot_interface/src/main.c +++ b/examples/device/hid_boot_interface/src/main.c @@ -57,7 +57,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c index 8f7873ee30..56c485982a 100644 --- a/examples/device/hid_composite/src/main.c +++ b/examples/device/hid_composite/src/main.c @@ -58,7 +58,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/hid_composite_freertos/src/main.c b/examples/device/hid_composite_freertos/src/main.c index d1842368ba..fc07a1a39f 100644 --- a/examples/device/hid_composite_freertos/src/main.c +++ b/examples/device/hid_composite_freertos/src/main.c @@ -136,7 +136,12 @@ void usb_device_task(void* param) // init device stack on configured roothub port // This should be called after scheduler/kernel is started. // Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API. - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/hid_generic_inout/src/main.c b/examples/device/hid_generic_inout/src/main.c index 03de8bfee2..1bbcbf7a46 100644 --- a/examples/device/hid_generic_inout/src/main.c +++ b/examples/device/hid_generic_inout/src/main.c @@ -81,7 +81,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/hid_multiple_interface/src/main.c b/examples/device/hid_multiple_interface/src/main.c index 0b7544fe05..edcedd3caf 100644 --- a/examples/device/hid_multiple_interface/src/main.c +++ b/examples/device/hid_multiple_interface/src/main.c @@ -62,7 +62,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/midi_test/src/main.c b/examples/device/midi_test/src/main.c index 84ca1d9445..b05307d1b0 100644 --- a/examples/device/midi_test/src/main.c +++ b/examples/device/midi_test/src/main.c @@ -63,7 +63,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/msc_dual_lun/src/main.c b/examples/device/msc_dual_lun/src/main.c index 9b0930ce08..fe3896ca7b 100644 --- a/examples/device/msc_dual_lun/src/main.c +++ b/examples/device/msc_dual_lun/src/main.c @@ -54,7 +54,12 @@ int main(void) { board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/net_lwip_webserver/src/main.c b/examples/device/net_lwip_webserver/src/main.c index dbd7746b0b..6041b56e27 100644 --- a/examples/device/net_lwip_webserver/src/main.c +++ b/examples/device/net_lwip_webserver/src/main.c @@ -216,7 +216,12 @@ int main(void) { board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/uac2_headset/src/main.c b/examples/device/uac2_headset/src/main.c index 73616109fc..4d28f73a4c 100644 --- a/examples/device/uac2_headset/src/main.c +++ b/examples/device/uac2_headset/src/main.c @@ -100,7 +100,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/uac2_speaker_fb/src/main.c b/examples/device/uac2_speaker_fb/src/main.c index 21c2ac24ae..1250b041d1 100644 --- a/examples/device/uac2_speaker_fb/src/main.c +++ b/examples/device/uac2_speaker_fb/src/main.c @@ -106,7 +106,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/usbtmc/src/main.c b/examples/device/usbtmc/src/main.c index 8dbded6322..2af581bc18 100644 --- a/examples/device/usbtmc/src/main.c +++ b/examples/device/usbtmc/src/main.c @@ -55,7 +55,12 @@ int main(void) board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/video_capture/src/main.c b/examples/device/video_capture/src/main.c index 4b8877a2fe..c5d87c660a 100644 --- a/examples/device/video_capture/src/main.c +++ b/examples/device/video_capture/src/main.c @@ -68,7 +68,12 @@ int main(void) { freertos_init_task(); #else // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); @@ -319,7 +324,12 @@ void usb_device_task(void *param) { // init device stack on configured roothub port // This should be called after scheduler/kernel is started. // Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API. - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/video_capture_2ch/src/main.c b/examples/device/video_capture_2ch/src/main.c index 118ee669d9..a45e62ab0d 100644 --- a/examples/device/video_capture_2ch/src/main.c +++ b/examples/device/video_capture_2ch/src/main.c @@ -68,7 +68,12 @@ int main(void) { freertos_init_task(); #else // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); @@ -327,7 +332,12 @@ void usb_device_task(void *param) { // init device stack on configured roothub port // This should be called after scheduler/kernel is started. // Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API. - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/webusb_serial/src/main.c b/examples/device/webusb_serial/src/main.c index e809c6319f..46215ec138 100644 --- a/examples/device/webusb_serial/src/main.c +++ b/examples/device/webusb_serial/src/main.c @@ -91,7 +91,12 @@ int main(void) { board_init(); // init device stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/dual/host_hid_to_device_cdc/src/main.c b/examples/dual/host_hid_to_device_cdc/src/main.c index ce586201c1..061958aae9 100644 --- a/examples/dual/host_hid_to_device_cdc/src/main.c +++ b/examples/dual/host_hid_to_device_cdc/src/main.c @@ -79,8 +79,19 @@ int main(void) { printf("TinyUSB Host HID <-> Device CDC Example\r\n"); // init device and host stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); - tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); + + tusb_rhport_init_t host_init = { + .rhport = BOARD_TUH_RHPORT, + .role = TUSB_ROLE_HOST, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/dual/host_info_to_device_cdc/src/main.c b/examples/dual/host_info_to_device_cdc/src/main.c index 7a862f5ada..e4d802a0cc 100644 --- a/examples/dual/host_info_to_device_cdc/src/main.c +++ b/examples/dual/host_info_to_device_cdc/src/main.c @@ -82,8 +82,19 @@ int main(void) { printf("TinyUSB Host Information -> Device CDC Example\r\n"); // init device and host stack on configured roothub port - tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE); - tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST); + tusb_rhport_init_t dev_init = { + .rhport = BOARD_TUD_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); + + tusb_rhport_init_t host_init = { + .rhport = BOARD_TUH_RHPORT, + .role = TUSB_ROLE_HOST, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/host/bare_api/src/main.c b/examples/host/bare_api/src/main.c index f248dd28d4..e710e3caab 100644 --- a/examples/host/bare_api/src/main.c +++ b/examples/host/bare_api/src/main.c @@ -62,7 +62,12 @@ int main(void) printf("TinyUSB Bare API Example\r\n"); // init host stack on configured roothub port - tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST); + tusb_rhport_init_t host_init = { + .rhport = BOARD_TUH_RHPORT, + .role = TUSB_ROLE_HOST, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c index 65f7b5201d..3a6e762b7c 100644 --- a/examples/host/cdc_msc_hid/src/main.c +++ b/examples/host/cdc_msc_hid/src/main.c @@ -50,7 +50,12 @@ int main(void) { printf("TinyUSB Host CDC MSC HID Example\r\n"); // init host stack on configured roothub port - tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST); + tusb_rhport_init_t host_init = { + .rhport = BOARD_TUH_RHPORT, + .role = TUSB_ROLE_HOST, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/host/cdc_msc_hid_freertos/src/main.c b/examples/host/cdc_msc_hid_freertos/src/main.c index 2116e6dcf7..9d2f347c39 100644 --- a/examples/host/cdc_msc_hid_freertos/src/main.c +++ b/examples/host/cdc_msc_hid_freertos/src/main.c @@ -126,7 +126,13 @@ static void usb_host_task(void *param) { (void) param; // init host stack on configured roothub port - if (!tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST)) { + tusb_rhport_init_t host_init = { + .rhport = BOARD_TUH_RHPORT, + .role = TUSB_ROLE_HOST, + .speed = TUSB_SPEED_AUTO + }; + + if (!tusb_init(&host_init)) { printf("Failed to init USB Host Stack\r\n"); vTaskSuspend(NULL); } diff --git a/examples/host/device_info/src/main.c b/examples/host/device_info/src/main.c index 55d685a5d6..8ca3d8a3a5 100644 --- a/examples/host/device_info/src/main.c +++ b/examples/host/device_info/src/main.c @@ -66,7 +66,12 @@ int main(void) { printf("TinyUSB Device Info Example\r\n"); // init host stack on configured roothub port - tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST); + tusb_rhport_init_t host_init = { + .rhport = BOARD_TUH_RHPORT, + .role = TUSB_ROLE_HOST, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/host/hid_controller/src/main.c b/examples/host/hid_controller/src/main.c index 76b6866837..6db47792ca 100644 --- a/examples/host/hid_controller/src/main.c +++ b/examples/host/hid_controller/src/main.c @@ -52,7 +52,12 @@ int main(void) printf("Note: Events only displayed for explicit supported controllers\r\n"); // init host stack on configured roothub port - tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST); + tusb_rhport_init_t host_init = { + .rhport = BOARD_TUH_RHPORT, + .role = TUSB_ROLE_HOST, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/host/msc_file_explorer/src/main.c b/examples/host/msc_file_explorer/src/main.c index 3af079b0ee..11512ab65e 100644 --- a/examples/host/msc_file_explorer/src/main.c +++ b/examples/host/msc_file_explorer/src/main.c @@ -78,7 +78,12 @@ int main(void) { printf("TinyUSB Host MassStorage Explorer Example\r\n"); // init host stack on configured roothub port - tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST); + tusb_rhport_init_t host_init = { + .rhport = BOARD_TUH_RHPORT, + .role = TUSB_ROLE_HOST, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 0d4082c031..d3e0cf888b 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -79,7 +79,7 @@ //--------------------------------------------------------------------+ // Optional API implemented by application if needed -// TODO move to a more ovious place/file +// TODO move to a more obvious place/file //--------------------------------------------------------------------+ // flush data cache diff --git a/src/common/tusb_compiler.h b/src/common/tusb_compiler.h index ce5566ffe3..646c22b295 100644 --- a/src/common/tusb_compiler.h +++ b/src/common/tusb_compiler.h @@ -118,6 +118,14 @@ #define _TU_ARGS_APPLY_7(_X, _s, _a1, _a2, _a3, _a4, _a5, _a6, _a7) _X(_a1) _s _TU_ARGS_APPLY_6(_X, _s, _a2, _a3, _a4, _a5, _a6, _a7) #define _TU_ARGS_APPLY_8(_X, _s, _a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8) _X(_a1) _s _TU_ARGS_APPLY_7(_X, _s, _a2, _a3, _a4, _a5, _a6, _a7, _a8) +//--------------------------------------------------------------------+ +// Macro for function default arguments +//--------------------------------------------------------------------+ +#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...) arg3 + +// function expand with number of arguments +#define TU_FUNC_OPTIONAL_ARG(func, ...) TU_XSTRCAT(func##_arg, TU_ARGS_NUM(__VA_ARGS__))(__VA_ARGS__) + //--------------------------------------------------------------------+ // Compiler porting with Attribute and Endian //--------------------------------------------------------------------+ diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index adf4b57204..5dfe3ff98c 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -50,6 +50,7 @@ typedef enum { TUSB_SPEED_FULL = 0, TUSB_SPEED_LOW = 1, TUSB_SPEED_HIGH = 2, + TUSB_SPEED_AUTO = 0xaa, TUSB_SPEED_INVALID = 0xff, } tusb_speed_t; @@ -273,6 +274,15 @@ enum { TUSB_INDEX_INVALID_8 = 0xFFu }; +//--------------------------------------------------------------------+ +// +//--------------------------------------------------------------------+ +typedef struct { + uint8_t rhport; + tusb_role_t role; + tusb_speed_t speed; +} tusb_rhport_init_t; + //--------------------------------------------------------------------+ // USB Descriptors //--------------------------------------------------------------------+ diff --git a/src/common/tusb_verify.h b/src/common/tusb_verify.h index 8ad218b033..3e0f1f1068 100644 --- a/src/common/tusb_verify.h +++ b/src/common/tusb_verify.h @@ -93,9 +93,6 @@ #define TU_BREAKPOINT() do {} while (0) #endif -// Helper to implement optional parameter for TU_VERIFY Macro family -#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...) arg3 - /*------------------------------------------------------------------*/ /* TU_VERIFY * - TU_VERIFY_1ARGS : return false if failed diff --git a/src/device/usbd.c b/src/device/usbd.c index 6fe7e416e7..7e35c976c0 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -448,11 +448,14 @@ bool tud_inited(void) { return _usbd_rhport != RHPORT_INVALID; } -bool tud_init(uint8_t rhport) { - // skip if already initialized - if (tud_inited()) return true; +bool tud_rhport_init(const tusb_rhport_init_t* rh_init) { + if (tud_inited()) { + return true; // skip if already initialized + } + TU_ASSERT(rh_init); - TU_LOG_USBD("USBD init on controller %u, Highspeed = %u\r\n", rhport, TUD_OPT_HIGH_SPEED); + TU_LOG_USBD("USBD init on controller %u, speed = %s\r\n", rh_init->rhport, + rh_init->speed == TUSB_SPEED_HIGH ? "High" : "Full"); TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(usbd_device_t)); TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(dcd_event_t)); TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(tu_fifo_t)); @@ -484,11 +487,11 @@ bool tud_init(uint8_t rhport) { driver->init(); } - _usbd_rhport = rhport; + _usbd_rhport = rh_init->rhport; // Init device controller driver - dcd_init(rhport); - dcd_int_enable(rhport); + dcd_init(rh_init->rhport); + dcd_int_enable(rh_init->rhport); return true; } diff --git a/src/device/usbd.h b/src/device/usbd.h index 7913096e39..05eb0173f6 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -37,8 +37,21 @@ extern "C" { // Application API //--------------------------------------------------------------------+ +// New API to replace tud_init() to init device stack on specific roothub port +bool tud_rhport_init(const tusb_rhport_init_t* rh_init); + // Init device stack on roothub port -bool tud_init (uint8_t rhport); +#if TUSB_VERSION_NUMBER > 2000 // 0.20.0 +TU_ATTR_DEPRECATED("Please use tusb_init(tusb_rhport_init_t*) instead") +#endif +TU_ATTR_ALWAYS_INLINE static inline bool tud_init (uint8_t rhport) { + const tusb_rhport_init_t rh_init = { + .rhport = rhport, + .role = TUSB_ROLE_DEVICE, + .speed = TUD_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL + }; + return tud_rhport_init(&rh_init); +} // Deinit device stack on roothub port bool tud_deinit(uint8_t rhport); diff --git a/src/host/usbh.c b/src/host/usbh.c index ed253ffcc4..39bc8d63a7 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -352,11 +352,13 @@ bool tuh_inited(void) { return _usbh_controller != TUSB_INDEX_INVALID_8; } -bool tuh_init(uint8_t rhport) { - // skip if already initialized - if (tuh_rhport_is_active(rhport)) return true; +bool tuh_rhport_init(const tusb_rhport_init_t* rh_init) { + if (tuh_rhport_is_active(rh_init->rhport)) { + return true; // skip if already initialized + } - TU_LOG_USBH("USBH init on controller %u\r\n", rhport); + TU_LOG_USBH("USBH init on controller %u, speed = %s\r\n", rhport, + rh_init->speed == TUSB_SPEED_HIGH ? "High" : "Full"); // Init host stack if not already if (!tuh_inited()) { @@ -402,9 +404,9 @@ bool tuh_init(uint8_t rhport) { } // Init host controller - _usbh_controller = rhport;; - TU_ASSERT(hcd_init(rhport)); - hcd_int_enable(rhport); + _usbh_controller = rh_init->rhport; + TU_ASSERT(hcd_init(rh_init->rhport)); + hcd_int_enable(rh_init->rhport); return true; } diff --git a/src/host/usbh.h b/src/host/usbh.h index 217cb1a9c6..9b865ac1b5 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -120,8 +120,21 @@ void tuh_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr); // - cfg_param: configure data, structure depends on the ID bool tuh_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param); +// New API to replace tuh_init() to init host stack on specific roothub port +bool tuh_rhport_init(const tusb_rhport_init_t* rh_init); + // Init host stack -bool tuh_init(uint8_t rhport); +#if TUSB_VERSION_NUMBER > 2000 // 0.20.0 +TU_ATTR_DEPRECATED("Please use tusb_init(tusb_rhport_init_t*) instead") +#endif +TU_ATTR_ALWAYS_INLINE static inline bool tuh_init(uint8_t rhport) { + const tusb_rhport_init_t rh_init = { + .rhport = rhport, + .role = TUSB_ROLE_HOST, + .speed = TUH_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL, + }; + return tuh_rhport_init(&rh_init); +} // Deinit host stack on rhport bool tuh_deinit(uint8_t rhport); @@ -149,9 +162,10 @@ extern void hcd_int_handler(uint8_t rhport, bool in_isr); #endif // Interrupt handler alias to HCD with in_isr as optional parameter -#define _tuh_int_handler_1arg(_rhport) hcd_int_handler(_rhport, true) -#define _tuh_int_hanlder_2arg(_rhport, _in_isr) hcd_int_handler(_rhport, _in_isr) -#define tuh_int_handler(...) TU_GET_3RD_ARG(__VA_ARGS__, _tuh_int_hanlder_2arg, _tuh_int_handler_1arg, _dummy)(__VA_ARGS__) +#define _tuh_int_handler_arg0() TU_VERIFY_STATIC(false, "tuh_int_handler() must have 1 or 2 arguments") +#define _tuh_int_handler_arg1(_rhport) hcd_int_handler(_rhport, true) +#define _tuh_int_handler_arg2(_rhport, _in_isr) hcd_int_handler(_rhport, _in_isr) +#define tuh_int_handler(...) TU_FUNC_OPTIONAL_ARG(_tuh_int_handler, __VA_ARGS__) // Check if roothub port is initialized and active as a host bool tuh_rhport_is_active(uint8_t rhport); diff --git a/src/tusb.c b/src/tusb.c index 9f0e45fef9..3eb299dff4 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -47,19 +47,29 @@ static tusb_role_t _rhport_role[TUP_USBIP_CONTROLLER_NUM] = { 0 }; // Public API //--------------------------------------------------------------------+ -bool _tusb_rhport_init(uint8_t rhport, tusb_role_t role) { +bool tusb_rhport_init(const tusb_rhport_init_t* rh_init) { // backward compatible called with tusb_init(void) #if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT) - if (rhport == 0xff || role == TUSB_ROLE_INVALID) { + if (rh_init == NULL) { #if CFG_TUD_ENABLED && defined(TUD_OPT_RHPORT) // init device stack CFG_TUSB_RHPORTx_MODE must be defined - TU_ASSERT ( tud_init(TUD_OPT_RHPORT) ); + const tusb_rhport_init_t dev_init = { + .rhport = TUD_OPT_RHPORT, + .role = TUSB_ROLE_DEVICE, + .speed = TUD_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL + }; + TU_ASSERT ( tud_rhport_init(&dev_init) ); _rhport_role[TUD_OPT_RHPORT] = TUSB_ROLE_DEVICE; #endif #if CFG_TUH_ENABLED && defined(TUH_OPT_RHPORT) // init host stack CFG_TUSB_RHPORTx_MODE must be defined - TU_ASSERT( tuh_init(TUH_OPT_RHPORT) ); + const tusb_rhport_init_t host_init = { + .rhport = TUH_OPT_RHPORT, + .role = TUSB_ROLE_HOST, + .speed = TUH_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL + }; + TU_ASSERT( tuh_rhport_init(&host_init) ); _rhport_role[TUH_OPT_RHPORT] = TUSB_ROLE_HOST; #endif @@ -68,21 +78,21 @@ bool _tusb_rhport_init(uint8_t rhport, tusb_role_t role) { #endif // new API with explicit rhport and role - TU_ASSERT(rhport < TUP_USBIP_CONTROLLER_NUM && role != TUSB_ROLE_INVALID); + TU_ASSERT(rh_init->rhport < TUP_USBIP_CONTROLLER_NUM && rh_init->role != TUSB_ROLE_INVALID); #if CFG_TUD_ENABLED - if (role == TUSB_ROLE_DEVICE) { - TU_ASSERT( tud_init(rhport) ); + if (rh_init->role == TUSB_ROLE_DEVICE) { + TU_ASSERT( tud_rhport_init(rh_init) ); } #endif #if CFG_TUH_ENABLED - if (role == TUSB_ROLE_HOST) { - TU_ASSERT( tuh_init(rhport) ); + if (rh_init->role == TUSB_ROLE_HOST) { + TU_ASSERT( tuh_rhport_init(rh_init) ); } #endif - _rhport_role[rhport] = role; + _rhport_role[rh_init->rhport] = rh_init->role; return true; } @@ -106,13 +116,13 @@ void tusb_int_handler(uint8_t rhport, bool in_isr) { #if CFG_TUD_ENABLED if (_rhport_role[rhport] == TUSB_ROLE_DEVICE) { (void) in_isr; - tud_int_handler(rhport); + dcd_int_handler(rhport); } #endif #if CFG_TUH_ENABLED if (_rhport_role[rhport] == TUSB_ROLE_HOST) { - tuh_int_handler(rhport, in_isr); + hcd_int_handler(rhport, in_isr); } #endif } diff --git a/src/tusb.h b/src/tusb.h index 911d1bae02..c12abba8b8 100644 --- a/src/tusb.h +++ b/src/tusb.h @@ -129,19 +129,25 @@ //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ + + #if CFG_TUH_ENABLED || CFG_TUD_ENABLED // Internal helper for backward compatible with tusb_init(void) -bool _tusb_rhport_init(uint8_t rhport, tusb_role_t role); +bool tusb_rhport_init(const tusb_rhport_init_t* rh_init); // Initialize roothub port with device/host role // Note: when using with RTOS, this should be called after scheduler/kernel is started. // Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API. // Note2: defined as macro for backward compatible with tusb_init(void), can be changed to function in the future. -#define _tusb_init_0arg() _tusb_rhport_init(0xff, TUSB_ROLE_INVALID) -#define _tusb_init_1arg(_rhport) _tusb_rhport_init(_rhport, TUSB_ROLE_INVALID) -#define _tusb_init_2arg(_rhport, _role) _tusb_rhport_init(_rhport, _role) -#define tusb_init(...) TU_GET_3RD_ARG(__VA_ARGS__, _tusb_init_2arg, _tusb_init_1arg, _tusb_init_0arg)(__VA_ARGS__) +#if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT) +#define _tusb_init_arg0() tusb_rhport_init(NULL) +#else +#define _tusb_init_arg0() TU_VERIFY_STATIC(false, "CFG_TUSB_RHPORT0_MODE/CFG_TUSB_RHPORT1_MODE must be defined") +#endif + +#define _tusb_init_arg1(_rh_init) tusb_rhport_init(_rh_init) +#define tusb_init(...) TU_FUNC_OPTIONAL_ARG(_tusb_init, __VA_ARGS__) // Check if stack is initialized bool tusb_inited(void); diff --git a/test/unit-test/test/device/msc/test_msc_device.c b/test/unit-test/test/device/msc/test_msc_device.c index 28216af107..3444d81c5b 100644 --- a/test/unit-test/test/device/msc/test_msc_device.c +++ b/test/unit-test/test/device/msc/test_msc_device.c @@ -200,7 +200,13 @@ void setUp(void) if ( !tud_inited() ) { dcd_init_Expect(rhport); - tusb_init(0, TUSB_ROLE_DEVICE); + + tusb_rhport_init_t dev_init = { + .rhport = 0, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); } dcd_event_bus_reset(rhport, TUSB_SPEED_HIGH, false); diff --git a/test/unit-test/test/device/usbd/test_usbd.c b/test/unit-test/test/device/usbd/test_usbd.c index 43722d1759..faa6b159ee 100644 --- a/test/unit-test/test/device/usbd/test_usbd.c +++ b/test/unit-test/test/device/usbd/test_usbd.c @@ -128,7 +128,13 @@ void setUp(void) { mscd_init_Expect(); dcd_init_Expect(rhport); - tusb_init(0, TUSB_ROLE_DEVICE); + + tusb_rhport_init_t dev_init = { + .rhport = 0, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(&dev_init); } } From d997f0071ea5d2d07e340d183fffb97e09526773 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 11 Oct 2024 15:21:32 +0700 Subject: [PATCH 2/6] change dcd_init() to take rhport struct --- .pre-commit-config.yaml | 15 +++++++++++++++ src/device/dcd.h | 2 +- src/device/usbd.c | 2 +- src/portable/bridgetek/ft9xx/dcd_ft9xx.c | 4 ++-- src/portable/chipidea/ci_fs/dcd_ci_fs.c | 4 ++-- src/portable/chipidea/ci_hs/dcd_ci_hs.c | 4 ++-- src/portable/dialog/da146xx/dcd_da146xx.c | 4 ++-- src/portable/espressif/esp32sx/dcd_esp32sx.c | 4 ++-- src/portable/mentor/musb/dcd_musb.c | 3 ++- src/portable/microchip/pic/dcd_pic.c | 4 ++-- src/portable/microchip/pic32mz/dcd_pic32mz.c | 4 ++-- src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c | 4 ++-- src/portable/nordic/nrf5x/dcd_nrf5x.c | 3 ++- src/portable/nuvoton/nuc120/dcd_nuc120.c | 4 ++-- src/portable/nuvoton/nuc121/dcd_nuc121.c | 4 ++-- src/portable/nuvoton/nuc505/dcd_nuc505.c | 4 ++-- src/portable/nxp/khci/dcd_khci.c | 4 ++-- src/portable/nxp/lpc17_40/dcd_lpc17_40.c | 4 ++-- src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c | 4 ++-- src/portable/raspberrypi/rp2040/dcd_rp2040.c | 3 ++- src/portable/renesas/rusb2/dcd_rusb2.c | 4 ++-- src/portable/sony/cxd56/dcd_cxd56.c | 4 ++-- src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 3 ++- src/portable/sunxi/dcd_sunxi_musb.c | 4 ++-- src/portable/synopsys/dwc2/dcd_dwc2.c | 3 ++- src/portable/ti/msp430x5xx/dcd_msp430x5xx.c | 12 ++++++++---- src/portable/valentyusb/eptri/dcd_eptri.c | 4 ++-- src/portable/wch/dcd_ch32_usbfs.c | 3 ++- src/portable/wch/dcd_ch32_usbhs.c | 3 ++- test/unit-test/test/device/msc/test_msc_device.c | 7 +++---- test/unit-test/test/device/usbd/test_usbd.c | 10 +++++----- 31 files changed, 83 insertions(+), 58 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bba217cc99..21da285c1f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -42,3 +42,18 @@ repos: pass_filenames: false types_or: [c, header] language: system + + - id: build-fuzzer + name: build-fuzzer + files: ^(src/|test/fuzz/) + language: system + types_or: [c, header] + entry: | + export CC=clang + export CXX=clang++ + fuzz_harness=$(ls -d test/fuzz/device/*/) + for h in $fuzz_harness + do + make -C $h get-deps + make -C $h all + done diff --git a/src/device/dcd.h b/src/device/dcd.h index 3ef5188fc7..8fa7b8bc18 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -108,7 +108,7 @@ void dcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) TU_ATTR_W //--------------------------------------------------------------------+ // Initialize controller to device mode -void dcd_init(uint8_t rhport); +void dcd_init(const tusb_rhport_init_t* rh_init); // Deinitialize controller, unset device mode. bool dcd_deinit(uint8_t rhport); diff --git a/src/device/usbd.c b/src/device/usbd.c index 7e35c976c0..12f95ab400 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -490,7 +490,7 @@ bool tud_rhport_init(const tusb_rhport_init_t* rh_init) { _usbd_rhport = rh_init->rhport; // Init device controller driver - dcd_init(rh_init->rhport); + dcd_init(rh_init); dcd_int_enable(rh_init->rhport); return true; diff --git a/src/portable/bridgetek/ft9xx/dcd_ft9xx.c b/src/portable/bridgetek/ft9xx/dcd_ft9xx.c index f02415904f..f4b236da67 100644 --- a/src/portable/bridgetek/ft9xx/dcd_ft9xx.c +++ b/src/portable/bridgetek/ft9xx/dcd_ft9xx.c @@ -517,8 +517,8 @@ static uint16_t _ft9xx_dusb_out(uint8_t ep_number, uint8_t *buffer, uint16_t len *------------------------------------------------------------------*/ // Initialize controller to device mode -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; TU_LOG2("FT9xx initialisation\r\n"); _dcd_ft9xx_attach(); diff --git a/src/portable/chipidea/ci_fs/dcd_ci_fs.c b/src/portable/chipidea/ci_fs/dcd_ci_fs.c index 02f813ab5b..315e9a86d3 100644 --- a/src/portable/chipidea/ci_fs/dcd_ci_fs.c +++ b/src/portable/chipidea/ci_fs/dcd_ci_fs.c @@ -267,8 +267,8 @@ static void process_bus_resume(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; // save crystal-less setting (if available) diff --git a/src/portable/chipidea/ci_hs/dcd_ci_hs.c b/src/portable/chipidea/ci_hs/dcd_ci_hs.c index 93e1d78dd2..bdb7abe41a 100644 --- a/src/portable/chipidea/ci_hs/dcd_ci_hs.c +++ b/src/portable/chipidea/ci_hs/dcd_ci_hs.c @@ -234,8 +234,8 @@ static void bus_reset(uint8_t rhport) dcd_dcache_clean_invalidate(&_dcd_data, sizeof(dcd_data_t)); } -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; tu_memclr(&_dcd_data, sizeof(dcd_data_t)); ci_hs_regs_t* dcd_reg = CI_HS_REG(rhport); diff --git a/src/portable/dialog/da146xx/dcd_da146xx.c b/src/portable/dialog/da146xx/dcd_da146xx.c index d1e85c2df1..05cebea0bd 100644 --- a/src/portable/dialog/da146xx/dcd_da146xx.c +++ b/src/portable/dialog/da146xx/dcd_da146xx.c @@ -804,8 +804,8 @@ static void handle_ep0_nak(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; _dcd.init_called = true; diff --git a/src/portable/espressif/esp32sx/dcd_esp32sx.c b/src/portable/espressif/esp32sx/dcd_esp32sx.c index 61911ab4c8..3d4757f035 100644 --- a/src/portable/espressif/esp32sx/dcd_esp32sx.c +++ b/src/portable/espressif/esp32sx/dcd_esp32sx.c @@ -172,8 +172,8 @@ static void enum_done_processing(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; ESP_LOGV(TAG, "DCD init - Start"); // A. Disconnect diff --git a/src/portable/mentor/musb/dcd_musb.c b/src/portable/mentor/musb/dcd_musb.c index a40b3dc079..a8437ad5bf 100644 --- a/src/portable/mentor/musb/dcd_musb.c +++ b/src/portable/mentor/musb/dcd_musb.c @@ -582,7 +582,8 @@ void print_musb_info(musb_regs_t* musb_regs) { } #endif -void dcd_init(uint8_t rhport) { +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; musb_regs_t* musb_regs = MUSB_REGS(rhport); #if CFG_TUSB_DEBUG >= MUSB_DEBUG diff --git a/src/portable/microchip/pic/dcd_pic.c b/src/portable/microchip/pic/dcd_pic.c index ccc27c3c9e..3ee0ab6d5e 100644 --- a/src/portable/microchip/pic/dcd_pic.c +++ b/src/portable/microchip/pic/dcd_pic.c @@ -470,8 +470,8 @@ static void process_bus_resume(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; intr_disable(rhport); intr_clear(rhport); diff --git a/src/portable/microchip/pic32mz/dcd_pic32mz.c b/src/portable/microchip/pic32mz/dcd_pic32mz.c index 9ad755670f..0049900462 100644 --- a/src/portable/microchip/pic32mz/dcd_pic32mz.c +++ b/src/portable/microchip/pic32mz/dcd_pic32mz.c @@ -120,8 +120,8 @@ static ep0_stage_t ep0_get_stage(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; // Disable endpoint interrupts for now USB_REGS->INTRRXEbits.w = 0; USB_REGS->INTRTXEbits.w = 0; diff --git a/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c b/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c index d5c0daaeb5..4117ab45f2 100644 --- a/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c +++ b/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c @@ -245,8 +245,8 @@ static void process_bus_active(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; tu_memclr(&_dcd, sizeof(_dcd)); diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index a63e442f3e..c1084c20c9 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -230,7 +230,8 @@ static void xact_in_dma(uint8_t epnum) { //--------------------------------------------------------------------+ // Controller API //--------------------------------------------------------------------+ -void dcd_init(uint8_t rhport) { +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; TU_LOG2("dcd init\r\n"); (void) rhport; } diff --git a/src/portable/nuvoton/nuc120/dcd_nuc120.c b/src/portable/nuvoton/nuc120/dcd_nuc120.c index fb12122e01..c9e8d86fdd 100644 --- a/src/portable/nuvoton/nuc120/dcd_nuc120.c +++ b/src/portable/nuvoton/nuc120/dcd_nuc120.c @@ -201,8 +201,8 @@ static const uint32_t enabled_irqs = USBD_INTSTS_FLDET_STS_Msk | USBD_INTSTS_BUS NUC100/NUC120 TinyUSB API driver implementation */ -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; USBD->ATTR = 0x7D0; diff --git a/src/portable/nuvoton/nuc121/dcd_nuc121.c b/src/portable/nuvoton/nuc121/dcd_nuc121.c index 873b1b7efa..78c65a91c7 100644 --- a/src/portable/nuvoton/nuc121/dcd_nuc121.c +++ b/src/portable/nuvoton/nuc121/dcd_nuc121.c @@ -209,8 +209,8 @@ enum { NUC121/NUC125/NUC126 TinyUSB API driver implementation */ -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; #ifdef SUPPORT_LPM diff --git a/src/portable/nuvoton/nuc505/dcd_nuc505.c b/src/portable/nuvoton/nuc505/dcd_nuc505.c index 3a92c97946..caeb89a0ac 100644 --- a/src/portable/nuvoton/nuc505/dcd_nuc505.c +++ b/src/portable/nuvoton/nuc505/dcd_nuc505.c @@ -279,8 +279,8 @@ static const uint32_t enabled_irqs = USBD_GINTEN_USBIEN_Msk | \ NUC505 TinyUSB API driver implementation */ -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; /* configure interrupts in their initial state; BUSINTEN and CEPINTEN will be subsequently and dynamically re-written as needed */ diff --git a/src/portable/nxp/khci/dcd_khci.c b/src/portable/nxp/khci/dcd_khci.c index ef61146aaa..2d08e84a50 100644 --- a/src/portable/nxp/khci/dcd_khci.c +++ b/src/portable/nxp/khci/dcd_khci.c @@ -265,8 +265,8 @@ static void process_bus_resume(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; // save crystal-less setting (if available) diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index 75b29faf37..e28b279192 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -167,8 +167,8 @@ static void bus_reset(void) tu_memclr(&_dcd, sizeof(dcd_data_t)); } -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; //------------- user manual 11.13 usb device controller initialization -------------// diff --git a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c index cc18cf59bb..06a82c4e7d 100644 --- a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c +++ b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c @@ -289,8 +289,8 @@ static void edpt_reset_all(uint8_t rhport) } prepare_setup_packet(rhport); } -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; edpt_reset_all(rhport); dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs; diff --git a/src/portable/raspberrypi/rp2040/dcd_rp2040.c b/src/portable/raspberrypi/rp2040/dcd_rp2040.c index bc0deee328..9473d3bd85 100644 --- a/src/portable/raspberrypi/rp2040/dcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/dcd_rp2040.c @@ -369,7 +369,8 @@ static void __tusb_irq_path_func(dcd_rp2040_irq)(void) { #define PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY 0xff #endif -void dcd_init(uint8_t rhport) { +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; assert(rhport == 0); TU_LOG(2, "Chip Version B%u\r\n", rp2040_chip_version()); diff --git a/src/portable/renesas/rusb2/dcd_rusb2.c b/src/portable/renesas/rusb2/dcd_rusb2.c index 7c6044ca03..e8e1bf041b 100644 --- a/src/portable/renesas/rusb2/dcd_rusb2.c +++ b/src/portable/renesas/rusb2/dcd_rusb2.c @@ -657,8 +657,8 @@ static void enable_interrupt(uint32_t pswi) } #endif -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; rusb2_reg_t* rusb = RUSB2_REG(rhport); rusb2_module_start(rhport, true); diff --git a/src/portable/sony/cxd56/dcd_cxd56.c b/src/portable/sony/cxd56/dcd_cxd56.c index 41814370ea..fe1c422492 100644 --- a/src/portable/sony/cxd56/dcd_cxd56.c +++ b/src/portable/sony/cxd56/dcd_cxd56.c @@ -201,8 +201,8 @@ static void _dcd_resume(FAR struct usbdevclass_driver_s *driver, FAR struct usbd dcd_event_bus_signal(0, DCD_EVENT_RESUME, true); } -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; usbdcd_driver.usbdevclass_driver.speed = USB_SPEED_HIGH; diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c index 6eea1ab32b..8e9bb0b30a 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c @@ -184,7 +184,8 @@ TU_ATTR_ALWAYS_INLINE static inline xfer_ctl_t *xfer_ctl_ptr(uint8_t epnum, uint //--------------------------------------------------------------------+ // Controller API //--------------------------------------------------------------------+ -void dcd_init(uint8_t rhport) { +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; // Follow the RM mentions to use a special ordering of PDWN and FRES for (volatile uint32_t i = 0; i < 200; i++) { // should be a few us asm("NOP"); diff --git a/src/portable/sunxi/dcd_sunxi_musb.c b/src/portable/sunxi/dcd_sunxi_musb.c index 6f36ad4419..d7bf1068ad 100644 --- a/src/portable/sunxi/dcd_sunxi_musb.c +++ b/src/portable/sunxi/dcd_sunxi_musb.c @@ -867,8 +867,8 @@ static void usb_isr_handler(void) { dcd_int_handler(0); } -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; dcd_disconnect(rhport); USBC_HardwareReset(); USBC_PhyConfig(); diff --git a/src/portable/synopsys/dwc2/dcd_dwc2.c b/src/portable/synopsys/dwc2/dcd_dwc2.c index 1ba3507ef5..580960e24d 100644 --- a/src/portable/synopsys/dwc2/dcd_dwc2.c +++ b/src/portable/synopsys/dwc2/dcd_dwc2.c @@ -650,9 +650,10 @@ static bool check_dwc2(dwc2_regs_t* dwc2) { return true; } -void dcd_init(uint8_t rhport) { +void dcd_init(const tusb_rhport_init_t* rh_init) { // Programming model begins in the last section of the chapter on the USB // peripheral in each Reference Manual. + const uint8_t rhport = rh_init->rhport; dwc2_regs_t* dwc2 = DWC2_REG(rhport); // Check Synopsys ID register, failed if controller clock/power is not enabled diff --git a/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c b/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c index 6b60bc657c..120d5c4b9b 100644 --- a/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c +++ b/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c @@ -130,9 +130,8 @@ static void enable_functional_reset(const bool enable) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init (uint8_t rhport) -{ - (void) rhport; +void dcd_init(const tusb_rhport_init_t* rh_init) { + (void) rh_init; USBKEYPID = USBKEY; @@ -699,7 +698,12 @@ static void handle_bus_power_event(void *param) { // A successful lock is indicated by all PLL-related interrupt flags being cleared. if(!USBPLLIR) { - dcd_init(0); // Re-initialize the USB module. + const tusb_rhport_init_t rhport_init = { + .rhport = 0, + .role = TUSB_ROLE_DEVICE, + .speed = TUSB_SPEED_FULL + }; + dcd_init(&rhport_init); // Re-initialize the USB module. } } else { // Event caused by removal of bus power. USBPWRCTL |= VBONIE; // Enable bus-power-applied interrupt. diff --git a/src/portable/valentyusb/eptri/dcd_eptri.c b/src/portable/valentyusb/eptri/dcd_eptri.c index 8f40e33493..da7a5a81a2 100644 --- a/src/portable/valentyusb/eptri/dcd_eptri.c +++ b/src/portable/valentyusb/eptri/dcd_eptri.c @@ -336,8 +336,8 @@ static void dcd_reset(void) } // Initializes the USB peripheral for device mode and enables it. -void dcd_init(uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; usb_pullup_out_write(0); diff --git a/src/portable/wch/dcd_ch32_usbfs.c b/src/portable/wch/dcd_ch32_usbfs.c index 9ed370b40a..4a7ad704b4 100644 --- a/src/portable/wch/dcd_ch32_usbfs.c +++ b/src/portable/wch/dcd_ch32_usbfs.c @@ -123,7 +123,8 @@ static void update_out(uint8_t rhport, uint8_t ep, size_t rx_len) { } /* public functions */ -void dcd_init(uint8_t rhport) { +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; // init registers USBOTG_FS->BASE_CTRL = USBFS_CTRL_SYS_CTRL | USBFS_CTRL_INT_BUSY | USBFS_CTRL_DMA_EN; USBOTG_FS->UDEV_CTRL = USBFS_UDEV_CTRL_PD_DIS | USBFS_UDEV_CTRL_PORT_EN; diff --git a/src/portable/wch/dcd_ch32_usbhs.c b/src/portable/wch/dcd_ch32_usbhs.c index 622f9c5084..77ebc378cf 100644 --- a/src/portable/wch/dcd_ch32_usbhs.c +++ b/src/portable/wch/dcd_ch32_usbhs.c @@ -131,7 +131,8 @@ static void xfer_data_packet(uint8_t ep_num, tusb_dir_t ep_dir, xfer_ctl_t* xfer ep_set_response_and_toggle(ep_num, ep_dir, USBHS_EP_R_RES_ACK); } -void dcd_init(uint8_t rhport) { +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; memset(&xfer_status, 0, sizeof(xfer_status)); diff --git a/test/unit-test/test/device/msc/test_msc_device.c b/test/unit-test/test/device/msc/test_msc_device.c index 3444d81c5b..4033bf1586 100644 --- a/test/unit-test/test/device/msc/test_msc_device.c +++ b/test/unit-test/test/device/msc/test_msc_device.c @@ -197,15 +197,14 @@ void setUp(void) dcd_int_disable_Ignore(); dcd_int_enable_Ignore(); - if ( !tud_inited() ) - { - dcd_init_Expect(rhport); - + if ( !tud_inited() ) { tusb_rhport_init_t dev_init = { .rhport = 0, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; + + dcd_init_Expect(&dev_init); tusb_init(&dev_init); } diff --git a/test/unit-test/test/device/usbd/test_usbd.c b/test/unit-test/test/device/usbd/test_usbd.c index faa6b159ee..8f900f6561 100644 --- a/test/unit-test/test/device/usbd/test_usbd.c +++ b/test/unit-test/test/device/usbd/test_usbd.c @@ -124,16 +124,16 @@ void setUp(void) dcd_int_disable_Ignore(); dcd_int_enable_Ignore(); - if ( !tud_inited() ) - { - mscd_init_Expect(); - dcd_init_Expect(rhport); - + if ( !tud_inited() ) { tusb_rhport_init_t dev_init = { .rhport = 0, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; + + mscd_init_Expect(); + dcd_init_Expect(&dev_init); + tusb_init(&dev_init); } } From f3b7d7515e9cae834013dc9ee3a67d87111090eb Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 11 Oct 2024 16:00:51 +0700 Subject: [PATCH 3/6] fix fuzzing build --- .pre-commit-config.yaml | 28 +++++------ src/device/dcd.h | 23 +++++---- src/portable/microchip/samd/dcd_samd.c | 5 +- src/portable/microchip/samg/dcd_samg.c | 4 +- src/portable/microchip/samx7x/dcd_samx7x.c | 4 +- .../raspberrypi/pio_usb/dcd_pio_usb.c | 6 +-- src/portable/template/dcd_template.c | 48 ++++++------------- test/fuzz/dcd_fuzz.cc | 4 +- 8 files changed, 54 insertions(+), 68 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 21da285c1f..9cd4a5ed1c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,17 +43,17 @@ repos: types_or: [c, header] language: system - - id: build-fuzzer - name: build-fuzzer - files: ^(src/|test/fuzz/) - language: system - types_or: [c, header] - entry: | - export CC=clang - export CXX=clang++ - fuzz_harness=$(ls -d test/fuzz/device/*/) - for h in $fuzz_harness - do - make -C $h get-deps - make -C $h all - done +# - id: build-fuzzer +# name: build-fuzzer +# files: ^(src/|test/fuzz/) +# language: system +# types_or: [c, header] +# entry: | +# bash -c 'export CC=clang +# export CXX=clang++ +# fuzz_harness=$(ls -d test/fuzz/device/*/) +# for h in $fuzz_harness +# do +# make -C $h get-deps +# make -C $h all +# done' diff --git a/src/device/dcd.h b/src/device/dcd.h index 8fa7b8bc18..02f3847ff3 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -194,38 +194,45 @@ extern void dcd_event_handler(dcd_event_t const * event, bool in_isr); // helper to send bus signal event TU_ATTR_ALWAYS_INLINE static inline void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr) { - dcd_event_t event = { .rhport = rhport, .event_id = eid }; + dcd_event_t event; + event.rhport = rhport; + event.event_id = eid; dcd_event_handler(&event, in_isr); } // helper to send bus reset event TU_ATTR_ALWAYS_INLINE static inline void dcd_event_bus_reset (uint8_t rhport, tusb_speed_t speed, bool in_isr) { - dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_BUS_RESET }; + dcd_event_t event; + event.rhport = rhport; + event.event_id = DCD_EVENT_BUS_RESET; event.bus_reset.speed = speed; dcd_event_handler(&event, in_isr); } // helper to send setup received TU_ATTR_ALWAYS_INLINE static inline void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr) { - dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_SETUP_RECEIVED }; + dcd_event_t event; + event.rhport = rhport; + event.event_id = DCD_EVENT_SETUP_RECEIVED; memcpy(&event.setup_received, setup, sizeof(tusb_control_request_t)); - dcd_event_handler(&event, in_isr); } // helper to send transfer complete event TU_ATTR_ALWAYS_INLINE static inline void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr) { - dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_XFER_COMPLETE }; - + dcd_event_t event; + event.rhport = rhport; + event.event_id = DCD_EVENT_XFER_COMPLETE; event.xfer_complete.ep_addr = ep_addr; event.xfer_complete.len = xferred_bytes; event.xfer_complete.result = result; - dcd_event_handler(&event, in_isr); } TU_ATTR_ALWAYS_INLINE static inline void dcd_event_sof(uint8_t rhport, uint32_t frame_count, bool in_isr) { - dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_SOF }; + dcd_event_t event; + event.rhport = rhport; + event.event_id = DCD_EVENT_SOF; event.sof.frame_count = frame_count; dcd_event_handler(&event, in_isr); } diff --git a/src/portable/microchip/samd/dcd_samd.c b/src/portable/microchip/samd/dcd_samd.c index 005b63faf6..c3a74ad0fd 100644 --- a/src/portable/microchip/samd/dcd_samd.c +++ b/src/portable/microchip/samd/dcd_samd.c @@ -78,9 +78,8 @@ static void bus_reset(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init (uint8_t rhport) -{ - (void) rhport; +void dcd_init(const tusb_rhport_init_t* rh_init) { + (void) rh_init; // Reset to get in a clean state. USB->DEVICE.CTRLA.bit.SWRST = true; diff --git a/src/portable/microchip/samg/dcd_samg.c b/src/portable/microchip/samg/dcd_samg.c index a154319378..2242d3336b 100644 --- a/src/portable/microchip/samg/dcd_samg.c +++ b/src/portable/microchip/samg/dcd_samg.c @@ -155,8 +155,8 @@ static void bus_reset(void) } // Initialize controller to device mode -void dcd_init (uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; tu_memclr(_dcd_xfer, sizeof(_dcd_xfer)); dcd_connect(rhport); } diff --git a/src/portable/microchip/samx7x/dcd_samx7x.c b/src/portable/microchip/samx7x/dcd_samx7x.c index 9586df84d9..d57db6e555 100644 --- a/src/portable/microchip/samx7x/dcd_samx7x.c +++ b/src/portable/microchip/samx7x/dcd_samx7x.c @@ -104,8 +104,8 @@ TU_ATTR_ALWAYS_INLINE static inline void CleanInValidateCache(uint32_t *addr, in //------------------------------------------------------------------ // Initialize controller to device mode -void dcd_init (uint8_t rhport) -{ +void dcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; dcd_connect(rhport); } diff --git a/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c b/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c index e6daf68272..83589efa01 100644 --- a/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c +++ b/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c @@ -50,10 +50,8 @@ static usb_descriptor_buffers_t desc; *------------------------------------------------------------------*/ // Initialize controller to device mode -void dcd_init (uint8_t rhport) -{ - (void) rhport; - +void dcd_init(const tusb_rhport_init_t* rh_init) { + (void) rh_init; static pio_usb_configuration_t config = PIO_USB_DEFAULT_CONFIG; usb_device = pio_usb_device_init(&config, &desc); } diff --git a/src/portable/template/dcd_template.c b/src/portable/template/dcd_template.c index 25ee507c1b..56a89e89af 100644 --- a/src/portable/template/dcd_template.c +++ b/src/portable/template/dcd_template.c @@ -40,54 +40,44 @@ *------------------------------------------------------------------*/ // Initialize controller to device mode -void dcd_init (uint8_t rhport) -{ - (void) rhport; +void dcd_init(const tusb_rhport_init_t* rh_init) { + (void) rh_init; } // Enable device interrupt -void dcd_int_enable (uint8_t rhport) -{ +void dcd_int_enable (uint8_t rhport) { (void) rhport; } // Disable device interrupt -void dcd_int_disable (uint8_t rhport) -{ +void dcd_int_disable (uint8_t rhport) { (void) rhport; } // Receive Set Address request, mcu port must also include status IN response -void dcd_set_address (uint8_t rhport, uint8_t dev_addr) -{ +void dcd_set_address (uint8_t rhport, uint8_t dev_addr) { (void) rhport; (void) dev_addr; } // Wake up host -void dcd_remote_wakeup (uint8_t rhport) -{ +void dcd_remote_wakeup (uint8_t rhport) { (void) rhport; } // Connect by enabling internal pull-up resistor on D+/D- -void dcd_connect(uint8_t rhport) -{ +void dcd_connect(uint8_t rhport) { (void) rhport; } // Disconnect by disabling internal pull-up resistor on D+/D- -void dcd_disconnect(uint8_t rhport) -{ +void dcd_disconnect(uint8_t rhport) { (void) rhport; } -void dcd_sof_enable(uint8_t rhport, bool en) -{ +void dcd_sof_enable(uint8_t rhport, bool en) { (void) rhport; (void) en; - - // TODO implement later } //--------------------------------------------------------------------+ @@ -95,8 +85,7 @@ void dcd_sof_enable(uint8_t rhport, bool en) //--------------------------------------------------------------------+ // Configure endpoint's registers according to descriptor -bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * ep_desc) -{ +bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * ep_desc) { (void) rhport; (void) ep_desc; return false; @@ -118,14 +107,12 @@ bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep) return false; } -void dcd_edpt_close_all (uint8_t rhport) -{ +void dcd_edpt_close_all (uint8_t rhport) { (void) rhport; } // Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack -bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes) -{ +bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes) { (void) rhport; (void) ep_addr; (void) buffer; @@ -134,8 +121,7 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t } // Submit a transfer where is managed by FIFO, When complete dcd_event_xfer_complete() is invoked to notify the stack - optional, however, must be listed in usbd.c -bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes) -{ +bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes) { (void) rhport; (void) ep_addr; (void) ff; @@ -144,19 +130,15 @@ bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16 } // Stall endpoint -void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr) -{ +void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; (void) ep_addr; } // clear stall, data toggle is also reset to DATA0 -void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr) -{ +void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; (void) ep_addr; } - - #endif diff --git a/test/fuzz/dcd_fuzz.cc b/test/fuzz/dcd_fuzz.cc index 06ddddc4a2..7ef0c74468 100644 --- a/test/fuzz/dcd_fuzz.cc +++ b/test/fuzz/dcd_fuzz.cc @@ -46,8 +46,8 @@ tu_static State state = {false, 0, 0}; // All no-ops as we are fuzzing. //--------------------------------------------------------------------+ extern "C" { -void dcd_init(uint8_t rhport) { - UNUSED(rhport); +void dcd_init(const tusb_rhport_init_t* rh_init) { + UNUSED(rh_init); return; } From 1587d48e89cbaa8d0d1c870809bc40c3c8d1056f Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 11 Oct 2024 17:53:39 +0700 Subject: [PATCH 4/6] hcd_init() take init struct --- src/host/hcd.h | 19 ++++++------------- src/host/usbh.c | 2 +- src/portable/analog/max3421/hcd_max3421.c | 4 ++-- src/portable/chipidea/ci_hs/hcd_ci_hs.c | 3 ++- src/portable/mentor/musb/hcd_musb.c | 5 ++--- src/portable/nxp/khci/hcd_khci.c | 6 ++---- src/portable/ohci/ohci.c | 4 ++-- .../raspberrypi/pio_usb/hcd_pio_usb.c | 4 ++-- src/portable/raspberrypi/rp2040/hcd_rp2040.c | 5 ++--- src/portable/renesas/rusb2/hcd_rusb2.c | 4 ++-- src/portable/template/hcd_template.c | 5 ++--- 11 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/host/hcd.h b/src/host/hcd.h index 5547c7cc5c..97cb017547 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -53,26 +53,21 @@ //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ -typedef enum -{ +typedef enum { HCD_EVENT_DEVICE_ATTACH, HCD_EVENT_DEVICE_REMOVE, HCD_EVENT_XFER_COMPLETE, - // Not an HCD event, just a convenient way to defer ISR function - USBH_EVENT_FUNC_CALL, - + USBH_EVENT_FUNC_CALL, // Not an HCD event HCD_EVENT_COUNT } hcd_eventid_t; -typedef struct -{ +typedef struct { uint8_t rhport; uint8_t event_id; uint8_t dev_addr; - union - { + union { // Attach, Remove struct { uint8_t hub_addr; @@ -93,11 +88,9 @@ typedef struct void* param; }func_call; }; - } hcd_event_t; -typedef struct -{ +typedef struct { uint8_t rhport; uint8_t hub_addr; uint8_t hub_port; @@ -128,7 +121,7 @@ bool hcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) TU_ATTR_W bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param); // Initialize controller to host mode -bool hcd_init(uint8_t rhport); +bool hcd_init(const tusb_rhport_init_t* rh_init); // De-initialize controller bool hcd_deinit(uint8_t rhport); diff --git a/src/host/usbh.c b/src/host/usbh.c index 39bc8d63a7..f9e6c4e974 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -405,7 +405,7 @@ bool tuh_rhport_init(const tusb_rhport_init_t* rh_init) { // Init host controller _usbh_controller = rh_init->rhport; - TU_ASSERT(hcd_init(rh_init->rhport)); + TU_ASSERT(hcd_init(rh_init)); hcd_int_enable(rh_init->rhport); return true; diff --git a/src/portable/analog/max3421/hcd_max3421.c b/src/portable/analog/max3421/hcd_max3421.c index 215feb4816..30d822c3b2 100644 --- a/src/portable/analog/max3421/hcd_max3421.c +++ b/src/portable/analog/max3421/hcd_max3421.c @@ -494,8 +494,8 @@ bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) { } // Initialize controller to host mode -bool hcd_init(uint8_t rhport) { - (void) rhport; +bool hcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; tuh_max3421_int_api(rhport, false); diff --git a/src/portable/chipidea/ci_hs/hcd_ci_hs.c b/src/portable/chipidea/ci_hs/hcd_ci_hs.c index 462cbd3013..fbc51f6df8 100644 --- a/src/portable/chipidea/ci_hs/hcd_ci_hs.c +++ b/src/portable/chipidea/ci_hs/hcd_ci_hs.c @@ -70,7 +70,8 @@ bool hcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) { // Controller API //--------------------------------------------------------------------+ -bool hcd_init(uint8_t rhport) { +bool hcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; ci_hs_regs_t *hcd_reg = CI_HS_REG(rhport); // Reset controller diff --git a/src/portable/mentor/musb/hcd_musb.c b/src/portable/mentor/musb/hcd_musb.c index 8fc2256768..9324c6a34e 100644 --- a/src/portable/mentor/musb/hcd_musb.c +++ b/src/portable/mentor/musb/hcd_musb.c @@ -556,9 +556,8 @@ static void process_pipe_rx(uint8_t rhport, uint_fast8_t pipenum) * Host API *------------------------------------------------------------------*/ -bool hcd_init(uint8_t rhport) -{ - (void)rhport; +bool hcd_init(const tusb_rhport_init_t* rh_init) { + (void) rh_init; NVIC_ClearPendingIRQ(USB0_IRQn); _hcd.bmRequestType = REQUEST_TYPE_INVALID; diff --git a/src/portable/nxp/khci/hcd_khci.c b/src/portable/nxp/khci/hcd_khci.c index 57684b2594..e9c00b8f94 100644 --- a/src/portable/nxp/khci/hcd_khci.c +++ b/src/portable/nxp/khci/hcd_khci.c @@ -368,10 +368,8 @@ static void process_bus_reset(uint8_t rhport) /*------------------------------------------------------------------*/ /* Host API *------------------------------------------------------------------*/ -bool hcd_init(uint8_t rhport) -{ - (void)rhport; - +bool hcd_init(const tusb_rhport_init_t* rh_init) { + (void) rh_init; KHCI->USBTRC0 |= USB_USBTRC0_USBRESET_MASK; while (KHCI->USBTRC0 & USB_USBTRC0_USBRESET_MASK); diff --git a/src/portable/ohci/ohci.c b/src/portable/ohci/ohci.c index c59d4755ed..fbaa5208e5 100644 --- a/src/portable/ohci/ohci.c +++ b/src/portable/ohci/ohci.c @@ -178,8 +178,8 @@ TU_ATTR_ALWAYS_INLINE static inline void *_virt_addr(void *physical_address) } // Initialization according to 5.1.1.4 -bool hcd_init(uint8_t rhport) -{ +bool hcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; (void) rhport; //------------- Data Structure init -------------// diff --git a/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c b/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c index f4de3c51da..4386bbce47 100644 --- a/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c +++ b/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c @@ -55,8 +55,8 @@ bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void *cfg_param) { return true; } -bool hcd_init(uint8_t rhport) { - (void) rhport; +bool hcd_init(const tusb_rhport_init_t* rh_init) { + (void) rh_init; // To run USB SOF interrupt in core1, call this init in core1 pio_usb_host_init(&pio_host_cfg); diff --git a/src/portable/raspberrypi/rp2040/hcd_rp2040.c b/src/portable/raspberrypi/rp2040/hcd_rp2040.c index 222dbbbf03..a870418a8a 100644 --- a/src/portable/raspberrypi/rp2040/hcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/hcd_rp2040.c @@ -375,9 +375,8 @@ static void _hw_endpoint_init(struct hw_endpoint *ep, uint8_t dev_addr, uint8_t //--------------------------------------------------------------------+ // HCD API //--------------------------------------------------------------------+ -bool hcd_init(uint8_t rhport) -{ - (void) rhport; +bool hcd_init(const tusb_rhport_init_t* rh_init) { + (void) rh_init; pico_trace("hcd_init %d\n", rhport); assert(rhport == 0); diff --git a/src/portable/renesas/rusb2/hcd_rusb2.c b/src/portable/renesas/rusb2/hcd_rusb2.c index f140da6909..35e85a3b0c 100644 --- a/src/portable/renesas/rusb2/hcd_rusb2.c +++ b/src/portable/renesas/rusb2/hcd_rusb2.c @@ -466,8 +466,8 @@ static void enable_interrupt(uint32_t pswi) } #endif -bool hcd_init(uint8_t rhport) -{ +bool hcd_init(const tusb_rhport_init_t* rh_init) { + const uint8_t rhport = rh_init->rhport; rusb2_reg_t* rusb = RUSB2_REG(rhport); rusb2_module_start(rhport, true); diff --git a/src/portable/template/hcd_template.c b/src/portable/template/hcd_template.c index b073d60570..9386e95cc0 100644 --- a/src/portable/template/hcd_template.c +++ b/src/portable/template/hcd_template.c @@ -44,9 +44,8 @@ bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) { } // Initialize controller to host mode -bool hcd_init(uint8_t rhport) { - (void) rhport; - +bool hcd_init(const tusb_rhport_init_t* rh_init) { + (void) rh_init; return false; } From 1f18be93db39dbc57bbf34f982dbe07e209a2ae3 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 14 Oct 2024 18:27:52 +0700 Subject: [PATCH 5/6] change the tusb_rhport_init_t struct, exclude the rhport to make API more consistent --- .github/workflows/pre-commit.yml | 2 +- .idea/cmake.xml | 13 ++++++------ .../device/audio_4_channel_mic/src/main.c | 3 +-- .../audio_4_channel_mic_freertos/src/main.c | 3 +-- examples/device/audio_test/src/main.c | 3 +-- .../device/audio_test_freertos/src/main.c | 3 +-- .../device/audio_test_multi_rate/src/main.c | 3 +-- examples/device/cdc_dual_ports/src/main.c | 3 +-- examples/device/cdc_msc/src/main.c | 3 +-- examples/device/cdc_msc_freertos/src/main.c | 3 +-- examples/device/cdc_uac2/src/main.c | 3 +-- examples/device/dfu/src/main.c | 3 +-- examples/device/dfu_runtime/src/main.c | 3 +-- .../device/dynamic_configuration/src/main.c | 3 +-- examples/device/hid_boot_interface/src/main.c | 3 +-- examples/device/hid_composite/src/main.c | 3 +-- .../device/hid_composite_freertos/src/main.c | 3 +-- examples/device/hid_generic_inout/src/main.c | 3 +-- .../device/hid_multiple_interface/src/main.c | 3 +-- examples/device/midi_test/src/main.c | 3 +-- examples/device/msc_dual_lun/src/main.c | 3 +-- examples/device/net_lwip_webserver/src/main.c | 3 +-- examples/device/uac2_headset/src/main.c | 3 +-- examples/device/uac2_speaker_fb/src/main.c | 3 +-- examples/device/usbtmc/src/main.c | 3 +-- examples/device/video_capture/src/main.c | 6 ++---- examples/device/video_capture_2ch/src/main.c | 6 ++---- examples/device/webusb_serial/src/main.c | 3 +-- .../dual/host_hid_to_device_cdc/src/main.c | 6 ++---- .../dual/host_info_to_device_cdc/src/main.c | 6 ++---- examples/host/bare_api/src/main.c | 3 +-- examples/host/cdc_msc_hid/src/main.c | 3 +-- examples/host/cdc_msc_hid_freertos/src/main.c | 3 +-- examples/host/device_info/src/main.c | 3 +-- examples/host/hid_controller/src/main.c | 3 +-- examples/host/msc_file_explorer/src/main.c | 3 +-- src/class/video/video_device.c | 2 +- src/common/tusb_types.h | 1 - src/device/dcd.h | 2 +- src/device/usbd.c | 8 ++++---- src/device/usbd.h | 7 +++---- src/host/hcd.h | 2 +- src/host/usbh.c | 10 +++++----- src/host/usbh.h | 7 +++---- src/portable/analog/max3421/hcd_max3421.c | 4 ++-- src/portable/bridgetek/ft9xx/dcd_ft9xx.c | 4 ++-- src/portable/chipidea/ci_fs/dcd_ci_fs.c | 4 ++-- src/portable/chipidea/ci_hs/dcd_ci_hs.c | 4 ++-- src/portable/chipidea/ci_hs/hcd_ci_hs.c | 8 +++++--- src/portable/dialog/da146xx/dcd_da146xx.c | 4 ++-- src/portable/espressif/esp32sx/dcd_esp32sx.c | 4 ++-- src/portable/mentor/musb/dcd_musb.c | 4 ++-- src/portable/mentor/musb/hcd_musb.c | 3 ++- src/portable/microchip/pic/dcd_pic.c | 4 ++-- src/portable/microchip/pic32mz/dcd_pic32mz.c | 4 ++-- src/portable/microchip/samd/dcd_samd.c | 4 ++-- src/portable/microchip/samg/dcd_samg.c | 5 +++-- src/portable/microchip/samx7x/dcd_samx7x.c | 4 ++-- .../mindmotion/mm32/dcd_mm32f327x_otg.c | 4 ++-- src/portable/nordic/nrf5x/dcd_nrf5x.c | 6 +++--- src/portable/nuvoton/nuc120/dcd_nuc120.c | 4 ++-- src/portable/nuvoton/nuc121/dcd_nuc121.c | 4 ++-- src/portable/nuvoton/nuc505/dcd_nuc505.c | 4 ++-- src/portable/nxp/khci/dcd_khci.c | 4 ++-- src/portable/nxp/khci/hcd_khci.c | 3 ++- src/portable/nxp/lpc17_40/dcd_lpc17_40.c | 4 ++-- src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c | 4 ++-- src/portable/ohci/ohci.c | 4 ++-- .../raspberrypi/pio_usb/dcd_pio_usb.c | 3 ++- .../raspberrypi/pio_usb/hcd_pio_usb.c | 3 ++- src/portable/raspberrypi/rp2040/dcd_rp2040.c | 4 ++-- src/portable/raspberrypi/rp2040/hcd_rp2040.c | 3 ++- src/portable/renesas/rusb2/dcd_rusb2.c | 4 ++-- src/portable/renesas/rusb2/hcd_rusb2.c | 4 ++-- src/portable/sony/cxd56/dcd_cxd56.c | 4 ++-- src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 4 ++-- src/portable/sunxi/dcd_sunxi_musb.c | 4 ++-- src/portable/synopsys/dwc2/dcd_dwc2.c | 4 ++-- src/portable/template/dcd_template.c | 4 ++-- src/portable/template/hcd_template.c | 3 ++- src/portable/ti/msp430x5xx/dcd_msp430x5xx.c | 7 +++---- src/portable/valentyusb/eptri/dcd_eptri.c | 4 ++-- src/portable/wch/dcd_ch32_usbfs.c | 4 ++-- src/portable/wch/dcd_ch32_usbhs.c | 4 ++-- src/tusb.c | 16 +++++++-------- src/tusb.h | 11 +++++----- test/fuzz/dcd_fuzz.cc | 3 ++- .../test/device/msc/test_msc_device.c | 5 ++--- test/unit-test/test/device/usbd/test_usbd.c | 20 +++++++------------ 89 files changed, 174 insertions(+), 213 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 379a22ee2b..530484079e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -29,7 +29,7 @@ jobs: #ceedling test:all - name: Run pre-commit - uses: pre-commit/action@v3.0.0 + uses: pre-commit/action@v3.0.1 - name: Build Fuzzer run: | diff --git a/.idea/cmake.xml b/.idea/cmake.xml index c0b55a82e5..05dceda5a5 100644 --- a/.idea/cmake.xml +++ b/.idea/cmake.xml @@ -2,6 +2,9 @@ + + + @@ -80,7 +83,7 @@ - + @@ -94,11 +97,11 @@ - + - + @@ -109,9 +112,6 @@ - - - @@ -148,6 +148,7 @@ + \ No newline at end of file diff --git a/examples/device/audio_4_channel_mic/src/main.c b/examples/device/audio_4_channel_mic/src/main.c index ca0e67faea..e8c40309ed 100644 --- a/examples/device/audio_4_channel_mic/src/main.c +++ b/examples/device/audio_4_channel_mic/src/main.c @@ -87,11 +87,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/audio_4_channel_mic_freertos/src/main.c b/examples/device/audio_4_channel_mic_freertos/src/main.c index c1ebc48993..2ac7516cdf 100644 --- a/examples/device/audio_4_channel_mic_freertos/src/main.c +++ b/examples/device/audio_4_channel_mic_freertos/src/main.c @@ -210,11 +210,10 @@ void usb_device_task(void* param) // This should be called after scheduler/kernel is started. // Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API. tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/audio_test/src/main.c b/examples/device/audio_test/src/main.c index f4c1bf95fc..018c48994d 100644 --- a/examples/device/audio_test/src/main.c +++ b/examples/device/audio_test/src/main.c @@ -80,11 +80,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/audio_test_freertos/src/main.c b/examples/device/audio_test_freertos/src/main.c index b7d7dc0426..4e2264b5d4 100644 --- a/examples/device/audio_test_freertos/src/main.c +++ b/examples/device/audio_test_freertos/src/main.c @@ -157,11 +157,10 @@ void usb_device_task(void* param) // This should be called after scheduler/kernel is started. // Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API. tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/audio_test_multi_rate/src/main.c b/examples/device/audio_test_multi_rate/src/main.c index a1c4d32dbe..f9dcd1b8a4 100644 --- a/examples/device/audio_test_multi_rate/src/main.c +++ b/examples/device/audio_test_multi_rate/src/main.c @@ -98,11 +98,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/cdc_dual_ports/src/main.c b/examples/device/cdc_dual_ports/src/main.c index b446bca0b3..63ae8a8c9c 100644 --- a/examples/device/cdc_dual_ports/src/main.c +++ b/examples/device/cdc_dual_ports/src/main.c @@ -53,11 +53,10 @@ int main(void) { // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c index 47ba5a8878..f36c910d7a 100644 --- a/examples/device/cdc_msc/src/main.c +++ b/examples/device/cdc_msc/src/main.c @@ -52,11 +52,10 @@ int main(void) { // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c index a08e063ac1..f70267e335 100644 --- a/examples/device/cdc_msc_freertos/src/main.c +++ b/examples/device/cdc_msc_freertos/src/main.c @@ -133,11 +133,10 @@ static void usb_device_task(void *param) { // This should be called after scheduler/kernel is started. // Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API. tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/cdc_uac2/src/main.c b/examples/device/cdc_uac2/src/main.c index 384d910ec0..b148593dab 100644 --- a/examples/device/cdc_uac2/src/main.c +++ b/examples/device/cdc_uac2/src/main.c @@ -47,11 +47,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); #if (CFG_TUSB_MCU == OPT_MCU_RP2040) stdio_init_all(); diff --git a/examples/device/dfu/src/main.c b/examples/device/dfu/src/main.c index f2aea7cfc7..af9e998579 100644 --- a/examples/device/dfu/src/main.c +++ b/examples/device/dfu/src/main.c @@ -76,11 +76,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/dfu_runtime/src/main.c b/examples/device/dfu_runtime/src/main.c index 5d6b907b7a..4740c18c42 100644 --- a/examples/device/dfu_runtime/src/main.c +++ b/examples/device/dfu_runtime/src/main.c @@ -71,11 +71,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/dynamic_configuration/src/main.c b/examples/device/dynamic_configuration/src/main.c index 143570c5c0..32ff58232d 100644 --- a/examples/device/dynamic_configuration/src/main.c +++ b/examples/device/dynamic_configuration/src/main.c @@ -58,11 +58,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/hid_boot_interface/src/main.c b/examples/device/hid_boot_interface/src/main.c index dfee7421d4..570e4e8010 100644 --- a/examples/device/hid_boot_interface/src/main.c +++ b/examples/device/hid_boot_interface/src/main.c @@ -58,11 +58,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c index 56c485982a..5302af3b8c 100644 --- a/examples/device/hid_composite/src/main.c +++ b/examples/device/hid_composite/src/main.c @@ -59,11 +59,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/hid_composite_freertos/src/main.c b/examples/device/hid_composite_freertos/src/main.c index fc07a1a39f..ae091571e0 100644 --- a/examples/device/hid_composite_freertos/src/main.c +++ b/examples/device/hid_composite_freertos/src/main.c @@ -137,11 +137,10 @@ void usb_device_task(void* param) // This should be called after scheduler/kernel is started. // Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API. tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/hid_generic_inout/src/main.c b/examples/device/hid_generic_inout/src/main.c index 1bbcbf7a46..73f51002d8 100644 --- a/examples/device/hid_generic_inout/src/main.c +++ b/examples/device/hid_generic_inout/src/main.c @@ -82,11 +82,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/hid_multiple_interface/src/main.c b/examples/device/hid_multiple_interface/src/main.c index edcedd3caf..92c7e8332c 100644 --- a/examples/device/hid_multiple_interface/src/main.c +++ b/examples/device/hid_multiple_interface/src/main.c @@ -63,11 +63,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/midi_test/src/main.c b/examples/device/midi_test/src/main.c index b05307d1b0..d7849a2c4b 100644 --- a/examples/device/midi_test/src/main.c +++ b/examples/device/midi_test/src/main.c @@ -64,11 +64,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/msc_dual_lun/src/main.c b/examples/device/msc_dual_lun/src/main.c index fe3896ca7b..012095dcaa 100644 --- a/examples/device/msc_dual_lun/src/main.c +++ b/examples/device/msc_dual_lun/src/main.c @@ -55,11 +55,10 @@ int main(void) { // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/net_lwip_webserver/src/main.c b/examples/device/net_lwip_webserver/src/main.c index 6041b56e27..8af7a9de6a 100644 --- a/examples/device/net_lwip_webserver/src/main.c +++ b/examples/device/net_lwip_webserver/src/main.c @@ -217,11 +217,10 @@ int main(void) { // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/uac2_headset/src/main.c b/examples/device/uac2_headset/src/main.c index 4d28f73a4c..6b2ab09738 100644 --- a/examples/device/uac2_headset/src/main.c +++ b/examples/device/uac2_headset/src/main.c @@ -101,11 +101,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/uac2_speaker_fb/src/main.c b/examples/device/uac2_speaker_fb/src/main.c index 1250b041d1..53bbec9b60 100644 --- a/examples/device/uac2_speaker_fb/src/main.c +++ b/examples/device/uac2_speaker_fb/src/main.c @@ -107,11 +107,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/usbtmc/src/main.c b/examples/device/usbtmc/src/main.c index 2af581bc18..aa7902a15a 100644 --- a/examples/device/usbtmc/src/main.c +++ b/examples/device/usbtmc/src/main.c @@ -56,11 +56,10 @@ int main(void) // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/video_capture/src/main.c b/examples/device/video_capture/src/main.c index c5d87c660a..aeeeb89308 100644 --- a/examples/device/video_capture/src/main.c +++ b/examples/device/video_capture/src/main.c @@ -69,11 +69,10 @@ int main(void) { #else // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); @@ -325,11 +324,10 @@ void usb_device_task(void *param) { // This should be called after scheduler/kernel is started. // Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API. tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/video_capture_2ch/src/main.c b/examples/device/video_capture_2ch/src/main.c index a45e62ab0d..dd69837666 100644 --- a/examples/device/video_capture_2ch/src/main.c +++ b/examples/device/video_capture_2ch/src/main.c @@ -69,11 +69,10 @@ int main(void) { #else // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); @@ -333,11 +332,10 @@ void usb_device_task(void *param) { // This should be called after scheduler/kernel is started. // Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API. tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/device/webusb_serial/src/main.c b/examples/device/webusb_serial/src/main.c index 46215ec138..d189af91fb 100644 --- a/examples/device/webusb_serial/src/main.c +++ b/examples/device/webusb_serial/src/main.c @@ -92,11 +92,10 @@ int main(void) { // init device stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/dual/host_hid_to_device_cdc/src/main.c b/examples/dual/host_hid_to_device_cdc/src/main.c index 061958aae9..633f7a6acf 100644 --- a/examples/dual/host_hid_to_device_cdc/src/main.c +++ b/examples/dual/host_hid_to_device_cdc/src/main.c @@ -80,18 +80,16 @@ int main(void) { // init device and host stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); tusb_rhport_init_t host_init = { - .rhport = BOARD_TUH_RHPORT, .role = TUSB_ROLE_HOST, .speed = TUSB_SPEED_AUTO }; - tusb_init(&host_init); + tusb_init(BOARD_TUH_RHPORT, &host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/dual/host_info_to_device_cdc/src/main.c b/examples/dual/host_info_to_device_cdc/src/main.c index e4d802a0cc..668808db25 100644 --- a/examples/dual/host_info_to_device_cdc/src/main.c +++ b/examples/dual/host_info_to_device_cdc/src/main.c @@ -83,18 +83,16 @@ int main(void) { // init device and host stack on configured roothub port tusb_rhport_init_t dev_init = { - .rhport = BOARD_TUD_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - tusb_init(&dev_init); + tusb_init(BOARD_TUD_RHPORT, &dev_init); tusb_rhport_init_t host_init = { - .rhport = BOARD_TUH_RHPORT, .role = TUSB_ROLE_HOST, .speed = TUSB_SPEED_AUTO }; - tusb_init(&host_init); + tusb_init(BOARD_TUH_RHPORT, &host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/host/bare_api/src/main.c b/examples/host/bare_api/src/main.c index e710e3caab..f582f4f5ae 100644 --- a/examples/host/bare_api/src/main.c +++ b/examples/host/bare_api/src/main.c @@ -63,11 +63,10 @@ int main(void) // init host stack on configured roothub port tusb_rhport_init_t host_init = { - .rhport = BOARD_TUH_RHPORT, .role = TUSB_ROLE_HOST, .speed = TUSB_SPEED_AUTO }; - tusb_init(&host_init); + tusb_init(BOARD_TUH_RHPORT, &host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c index 3a6e762b7c..71257c0fed 100644 --- a/examples/host/cdc_msc_hid/src/main.c +++ b/examples/host/cdc_msc_hid/src/main.c @@ -51,11 +51,10 @@ int main(void) { // init host stack on configured roothub port tusb_rhport_init_t host_init = { - .rhport = BOARD_TUH_RHPORT, .role = TUSB_ROLE_HOST, .speed = TUSB_SPEED_AUTO }; - tusb_init(&host_init); + tusb_init(BOARD_TUH_RHPORT, &host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/host/cdc_msc_hid_freertos/src/main.c b/examples/host/cdc_msc_hid_freertos/src/main.c index 9d2f347c39..7fb84a40f2 100644 --- a/examples/host/cdc_msc_hid_freertos/src/main.c +++ b/examples/host/cdc_msc_hid_freertos/src/main.c @@ -127,12 +127,11 @@ static void usb_host_task(void *param) { // init host stack on configured roothub port tusb_rhport_init_t host_init = { - .rhport = BOARD_TUH_RHPORT, .role = TUSB_ROLE_HOST, .speed = TUSB_SPEED_AUTO }; - if (!tusb_init(&host_init)) { + if (!tusb_init(BOARD_TUH_RHPORT, &host_init)) { printf("Failed to init USB Host Stack\r\n"); vTaskSuspend(NULL); } diff --git a/examples/host/device_info/src/main.c b/examples/host/device_info/src/main.c index 8ca3d8a3a5..0ff4f32e99 100644 --- a/examples/host/device_info/src/main.c +++ b/examples/host/device_info/src/main.c @@ -67,11 +67,10 @@ int main(void) { // init host stack on configured roothub port tusb_rhport_init_t host_init = { - .rhport = BOARD_TUH_RHPORT, .role = TUSB_ROLE_HOST, .speed = TUSB_SPEED_AUTO }; - tusb_init(&host_init); + tusb_init(BOARD_TUH_RHPORT, &host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/host/hid_controller/src/main.c b/examples/host/hid_controller/src/main.c index 6db47792ca..ba12774bdc 100644 --- a/examples/host/hid_controller/src/main.c +++ b/examples/host/hid_controller/src/main.c @@ -53,11 +53,10 @@ int main(void) // init host stack on configured roothub port tusb_rhport_init_t host_init = { - .rhport = BOARD_TUH_RHPORT, .role = TUSB_ROLE_HOST, .speed = TUSB_SPEED_AUTO }; - tusb_init(&host_init); + tusb_init(BOARD_TUH_RHPORT, &host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/examples/host/msc_file_explorer/src/main.c b/examples/host/msc_file_explorer/src/main.c index 11512ab65e..9509035b4a 100644 --- a/examples/host/msc_file_explorer/src/main.c +++ b/examples/host/msc_file_explorer/src/main.c @@ -79,11 +79,10 @@ int main(void) { // init host stack on configured roothub port tusb_rhport_init_t host_init = { - .rhport = BOARD_TUH_RHPORT, .role = TUSB_ROLE_HOST, .speed = TUSB_SPEED_AUTO }; - tusb_init(&host_init); + tusb_init(BOARD_TUH_RHPORT, &host_init); if (board_init_after_tusb) { board_init_after_tusb(); diff --git a/src/class/video/video_device.c b/src/class/video/video_device.c index c544a09fee..70dbb5b9e9 100644 --- a/src/class/video/video_device.c +++ b/src/class/video/video_device.c @@ -707,7 +707,7 @@ static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t /* The first descriptor is a video control interface descriptor. */ uint8_t const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum); - TU_LOG_DRV(" cur %d\r\n", cur - beg); + TU_LOG_DRV(" cur %" PRId32 "\r\n", (int32_t) (cur - beg)); TU_VERIFY(cur < end); tusb_desc_vc_itf_t const *vc = (tusb_desc_vc_itf_t const *)cur; diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index 5dfe3ff98c..53bb367cb1 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -278,7 +278,6 @@ enum { // //--------------------------------------------------------------------+ typedef struct { - uint8_t rhport; tusb_role_t role; tusb_speed_t speed; } tusb_rhport_init_t; diff --git a/src/device/dcd.h b/src/device/dcd.h index 02f3847ff3..64dffbaefb 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -108,7 +108,7 @@ void dcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) TU_ATTR_W //--------------------------------------------------------------------+ // Initialize controller to device mode -void dcd_init(const tusb_rhport_init_t* rh_init); +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init); // Deinitialize controller, unset device mode. bool dcd_deinit(uint8_t rhport); diff --git a/src/device/usbd.c b/src/device/usbd.c index 12f95ab400..4b6600eb26 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -448,7 +448,7 @@ bool tud_inited(void) { return _usbd_rhport != RHPORT_INVALID; } -bool tud_rhport_init(const tusb_rhport_init_t* rh_init) { +bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { if (tud_inited()) { return true; // skip if already initialized } @@ -487,11 +487,11 @@ bool tud_rhport_init(const tusb_rhport_init_t* rh_init) { driver->init(); } - _usbd_rhport = rh_init->rhport; + _usbd_rhport = rhport; // Init device controller driver - dcd_init(rh_init); - dcd_int_enable(rh_init->rhport); + dcd_init(rhport, rh_init); + dcd_int_enable(rhport); return true; } diff --git a/src/device/usbd.h b/src/device/usbd.h index 05eb0173f6..de6007fb39 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -38,19 +38,18 @@ extern "C" { //--------------------------------------------------------------------+ // New API to replace tud_init() to init device stack on specific roothub port -bool tud_rhport_init(const tusb_rhport_init_t* rh_init); +bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init); // Init device stack on roothub port #if TUSB_VERSION_NUMBER > 2000 // 0.20.0 -TU_ATTR_DEPRECATED("Please use tusb_init(tusb_rhport_init_t*) instead") +TU_ATTR_DEPRECATED("Please use tusb_init(rhport, rh_init) instead") #endif TU_ATTR_ALWAYS_INLINE static inline bool tud_init (uint8_t rhport) { const tusb_rhport_init_t rh_init = { - .rhport = rhport, .role = TUSB_ROLE_DEVICE, .speed = TUD_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL }; - return tud_rhport_init(&rh_init); + return tud_rhport_init(rhport, &rh_init); } // Deinit device stack on roothub port diff --git a/src/host/hcd.h b/src/host/hcd.h index 97cb017547..6518e6fd29 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -121,7 +121,7 @@ bool hcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) TU_ATTR_W bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param); // Initialize controller to host mode -bool hcd_init(const tusb_rhport_init_t* rh_init); +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init); // De-initialize controller bool hcd_deinit(uint8_t rhport); diff --git a/src/host/usbh.c b/src/host/usbh.c index f9e6c4e974..b5df29f501 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -352,8 +352,8 @@ bool tuh_inited(void) { return _usbh_controller != TUSB_INDEX_INVALID_8; } -bool tuh_rhport_init(const tusb_rhport_init_t* rh_init) { - if (tuh_rhport_is_active(rh_init->rhport)) { +bool tuh_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + if (tuh_rhport_is_active(rhport)) { return true; // skip if already initialized } @@ -404,9 +404,9 @@ bool tuh_rhport_init(const tusb_rhport_init_t* rh_init) { } // Init host controller - _usbh_controller = rh_init->rhport; - TU_ASSERT(hcd_init(rh_init)); - hcd_int_enable(rh_init->rhport); + _usbh_controller = rhport; + TU_ASSERT(hcd_init(rhport, rh_init)); + hcd_int_enable(rhport); return true; } diff --git a/src/host/usbh.h b/src/host/usbh.h index 9b865ac1b5..20fad284ee 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -121,19 +121,18 @@ void tuh_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr); bool tuh_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param); // New API to replace tuh_init() to init host stack on specific roothub port -bool tuh_rhport_init(const tusb_rhport_init_t* rh_init); +bool tuh_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init); // Init host stack #if TUSB_VERSION_NUMBER > 2000 // 0.20.0 -TU_ATTR_DEPRECATED("Please use tusb_init(tusb_rhport_init_t*) instead") +TU_ATTR_DEPRECATED("Please use tusb_init(rhport, rh_init) instead") #endif TU_ATTR_ALWAYS_INLINE static inline bool tuh_init(uint8_t rhport) { const tusb_rhport_init_t rh_init = { - .rhport = rhport, .role = TUSB_ROLE_HOST, .speed = TUH_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL, }; - return tuh_rhport_init(&rh_init); + return tuh_rhport_init(rhport, &rh_init); } // Deinit host stack on rhport diff --git a/src/portable/analog/max3421/hcd_max3421.c b/src/portable/analog/max3421/hcd_max3421.c index 30d822c3b2..c5e9242668 100644 --- a/src/portable/analog/max3421/hcd_max3421.c +++ b/src/portable/analog/max3421/hcd_max3421.c @@ -494,8 +494,8 @@ bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) { } // Initialize controller to host mode -bool hcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; tuh_max3421_int_api(rhport, false); diff --git a/src/portable/bridgetek/ft9xx/dcd_ft9xx.c b/src/portable/bridgetek/ft9xx/dcd_ft9xx.c index f4b236da67..4e7b288251 100644 --- a/src/portable/bridgetek/ft9xx/dcd_ft9xx.c +++ b/src/portable/bridgetek/ft9xx/dcd_ft9xx.c @@ -517,8 +517,8 @@ static uint16_t _ft9xx_dusb_out(uint8_t ep_number, uint8_t *buffer, uint16_t len *------------------------------------------------------------------*/ // Initialize controller to device mode -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; TU_LOG2("FT9xx initialisation\r\n"); _dcd_ft9xx_attach(); diff --git a/src/portable/chipidea/ci_fs/dcd_ci_fs.c b/src/portable/chipidea/ci_fs/dcd_ci_fs.c index 315e9a86d3..6038160cfc 100644 --- a/src/portable/chipidea/ci_fs/dcd_ci_fs.c +++ b/src/portable/chipidea/ci_fs/dcd_ci_fs.c @@ -267,9 +267,9 @@ static void process_bus_resume(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; // save crystal-less setting (if available) #if defined(FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED) && FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED == 1 diff --git a/src/portable/chipidea/ci_hs/dcd_ci_hs.c b/src/portable/chipidea/ci_hs/dcd_ci_hs.c index bdb7abe41a..5204dee66d 100644 --- a/src/portable/chipidea/ci_hs/dcd_ci_hs.c +++ b/src/portable/chipidea/ci_hs/dcd_ci_hs.c @@ -234,8 +234,8 @@ static void bus_reset(uint8_t rhport) dcd_dcache_clean_invalidate(&_dcd_data, sizeof(dcd_data_t)); } -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; tu_memclr(&_dcd_data, sizeof(dcd_data_t)); ci_hs_regs_t* dcd_reg = CI_HS_REG(rhport); diff --git a/src/portable/chipidea/ci_hs/hcd_ci_hs.c b/src/portable/chipidea/ci_hs/hcd_ci_hs.c index fbc51f6df8..14f8acb45e 100644 --- a/src/portable/chipidea/ci_hs/hcd_ci_hs.c +++ b/src/portable/chipidea/ci_hs/hcd_ci_hs.c @@ -70,8 +70,8 @@ bool hcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) { // Controller API //--------------------------------------------------------------------+ -bool hcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; ci_hs_regs_t *hcd_reg = CI_HS_REG(rhport); // Reset controller @@ -83,7 +83,9 @@ bool hcd_init(const tusb_rhport_init_t* rh_init) { // LPC18XX/43XX need to set VBUS Power Select to HIGH // RHPORT1 is fullspeed only (need external PHY for Highspeed) hcd_reg->USBMODE = USBMODE_CM_HOST | USBMODE_VBUS_POWER_SELECT; - if ( rhport == 1 ) hcd_reg->PORTSC1 |= PORTSC1_FORCE_FULL_SPEED; + if (rhport == 1) { + hcd_reg->PORTSC1 |= PORTSC1_FORCE_FULL_SPEED; + } #else hcd_reg->USBMODE = USBMODE_CM_HOST; #endif diff --git a/src/portable/dialog/da146xx/dcd_da146xx.c b/src/portable/dialog/da146xx/dcd_da146xx.c index 05cebea0bd..558e1269a9 100644 --- a/src/portable/dialog/da146xx/dcd_da146xx.c +++ b/src/portable/dialog/da146xx/dcd_da146xx.c @@ -804,9 +804,9 @@ static void handle_ep0_nak(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; _dcd.init_called = true; if (_dcd.vbus_present) diff --git a/src/portable/espressif/esp32sx/dcd_esp32sx.c b/src/portable/espressif/esp32sx/dcd_esp32sx.c index 3d4757f035..d233813d41 100644 --- a/src/portable/espressif/esp32sx/dcd_esp32sx.c +++ b/src/portable/espressif/esp32sx/dcd_esp32sx.c @@ -172,8 +172,8 @@ static void enum_done_processing(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; ESP_LOGV(TAG, "DCD init - Start"); // A. Disconnect diff --git a/src/portable/mentor/musb/dcd_musb.c b/src/portable/mentor/musb/dcd_musb.c index a8437ad5bf..02c8da1e06 100644 --- a/src/portable/mentor/musb/dcd_musb.c +++ b/src/portable/mentor/musb/dcd_musb.c @@ -582,8 +582,8 @@ void print_musb_info(musb_regs_t* musb_regs) { } #endif -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; musb_regs_t* musb_regs = MUSB_REGS(rhport); #if CFG_TUSB_DEBUG >= MUSB_DEBUG diff --git a/src/portable/mentor/musb/hcd_musb.c b/src/portable/mentor/musb/hcd_musb.c index 9324c6a34e..1c0740193a 100644 --- a/src/portable/mentor/musb/hcd_musb.c +++ b/src/portable/mentor/musb/hcd_musb.c @@ -556,7 +556,8 @@ static void process_pipe_rx(uint8_t rhport, uint_fast8_t pipenum) * Host API *------------------------------------------------------------------*/ -bool hcd_init(const tusb_rhport_init_t* rh_init) { +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; (void) rh_init; NVIC_ClearPendingIRQ(USB0_IRQn); diff --git a/src/portable/microchip/pic/dcd_pic.c b/src/portable/microchip/pic/dcd_pic.c index 3ee0ab6d5e..089d3f5200 100644 --- a/src/portable/microchip/pic/dcd_pic.c +++ b/src/portable/microchip/pic/dcd_pic.c @@ -470,8 +470,8 @@ static void process_bus_resume(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; intr_disable(rhport); intr_clear(rhport); diff --git a/src/portable/microchip/pic32mz/dcd_pic32mz.c b/src/portable/microchip/pic32mz/dcd_pic32mz.c index 0049900462..f1614f30c1 100644 --- a/src/portable/microchip/pic32mz/dcd_pic32mz.c +++ b/src/portable/microchip/pic32mz/dcd_pic32mz.c @@ -120,8 +120,8 @@ static ep0_stage_t ep0_get_stage(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; // Disable endpoint interrupts for now USB_REGS->INTRRXEbits.w = 0; USB_REGS->INTRTXEbits.w = 0; diff --git a/src/portable/microchip/samd/dcd_samd.c b/src/portable/microchip/samd/dcd_samd.c index c3a74ad0fd..8120681a7f 100644 --- a/src/portable/microchip/samd/dcd_samd.c +++ b/src/portable/microchip/samd/dcd_samd.c @@ -78,8 +78,8 @@ static void bus_reset(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(const tusb_rhport_init_t* rh_init) { - (void) rh_init; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; (void) rh_init; // Reset to get in a clean state. USB->DEVICE.CTRLA.bit.SWRST = true; diff --git a/src/portable/microchip/samg/dcd_samg.c b/src/portable/microchip/samg/dcd_samg.c index 2242d3336b..b02889b244 100644 --- a/src/portable/microchip/samg/dcd_samg.c +++ b/src/portable/microchip/samg/dcd_samg.c @@ -155,8 +155,9 @@ static void bus_reset(void) } // Initialize controller to device mode -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; + (void) rh_init; tu_memclr(_dcd_xfer, sizeof(_dcd_xfer)); dcd_connect(rhport); } diff --git a/src/portable/microchip/samx7x/dcd_samx7x.c b/src/portable/microchip/samx7x/dcd_samx7x.c index d57db6e555..a85d2306ed 100644 --- a/src/portable/microchip/samx7x/dcd_samx7x.c +++ b/src/portable/microchip/samx7x/dcd_samx7x.c @@ -104,8 +104,8 @@ TU_ATTR_ALWAYS_INLINE static inline void CleanInValidateCache(uint32_t *addr, in //------------------------------------------------------------------ // Initialize controller to device mode -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; dcd_connect(rhport); } diff --git a/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c b/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c index 4117ab45f2..b74ca847a9 100644 --- a/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c +++ b/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c @@ -245,9 +245,9 @@ static void process_bus_active(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; tu_memclr(&_dcd, sizeof(_dcd)); USB_OTG_FS->BDT_PAGE_01 = (uint8_t)((uintptr_t)_dcd.bdt >> 8); diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index c1084c20c9..06474e65d7 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -230,10 +230,10 @@ static void xact_in_dma(uint8_t epnum) { //--------------------------------------------------------------------+ // Controller API //--------------------------------------------------------------------+ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; - TU_LOG2("dcd init\r\n"); +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; + TU_LOG2("dcd init\r\n"); } void dcd_int_enable(uint8_t rhport) { diff --git a/src/portable/nuvoton/nuc120/dcd_nuc120.c b/src/portable/nuvoton/nuc120/dcd_nuc120.c index c9e8d86fdd..89fca021fd 100644 --- a/src/portable/nuvoton/nuc120/dcd_nuc120.c +++ b/src/portable/nuvoton/nuc120/dcd_nuc120.c @@ -201,9 +201,9 @@ static const uint32_t enabled_irqs = USBD_INTSTS_FLDET_STS_Msk | USBD_INTSTS_BUS NUC100/NUC120 TinyUSB API driver implementation */ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; USBD->ATTR = 0x7D0; diff --git a/src/portable/nuvoton/nuc121/dcd_nuc121.c b/src/portable/nuvoton/nuc121/dcd_nuc121.c index 78c65a91c7..b813eea772 100644 --- a/src/portable/nuvoton/nuc121/dcd_nuc121.c +++ b/src/portable/nuvoton/nuc121/dcd_nuc121.c @@ -209,9 +209,9 @@ enum { NUC121/NUC125/NUC126 TinyUSB API driver implementation */ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; #ifdef SUPPORT_LPM USBD->ATTR = 0x7D0 | USBD_LPMACK; diff --git a/src/portable/nuvoton/nuc505/dcd_nuc505.c b/src/portable/nuvoton/nuc505/dcd_nuc505.c index caeb89a0ac..3821b6ec8a 100644 --- a/src/portable/nuvoton/nuc505/dcd_nuc505.c +++ b/src/portable/nuvoton/nuc505/dcd_nuc505.c @@ -279,9 +279,9 @@ static const uint32_t enabled_irqs = USBD_GINTEN_USBIEN_Msk | \ NUC505 TinyUSB API driver implementation */ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; /* configure interrupts in their initial state; BUSINTEN and CEPINTEN will be subsequently and dynamically re-written as needed */ USBD->GINTEN = enabled_irqs; diff --git a/src/portable/nxp/khci/dcd_khci.c b/src/portable/nxp/khci/dcd_khci.c index 2d08e84a50..1b7f56e8c4 100644 --- a/src/portable/nxp/khci/dcd_khci.c +++ b/src/portable/nxp/khci/dcd_khci.c @@ -265,9 +265,9 @@ static void process_bus_resume(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; // save crystal-less setting (if available) #if defined(FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED) && FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED == 1 diff --git a/src/portable/nxp/khci/hcd_khci.c b/src/portable/nxp/khci/hcd_khci.c index e9c00b8f94..f5ca73c18e 100644 --- a/src/portable/nxp/khci/hcd_khci.c +++ b/src/portable/nxp/khci/hcd_khci.c @@ -368,7 +368,8 @@ static void process_bus_reset(uint8_t rhport) /*------------------------------------------------------------------*/ /* Host API *------------------------------------------------------------------*/ -bool hcd_init(const tusb_rhport_init_t* rh_init) { +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; (void) rh_init; KHCI->USBTRC0 |= USB_USBTRC0_USBRESET_MASK; while (KHCI->USBTRC0 & USB_USBTRC0_USBRESET_MASK); diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index e28b279192..22b4500c57 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -167,9 +167,9 @@ static void bus_reset(void) tu_memclr(&_dcd, sizeof(dcd_data_t)); } -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; //------------- user manual 11.13 usb device controller initialization -------------// // step 6 : set up control endpoint diff --git a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c index 06a82c4e7d..e59a0f5261 100644 --- a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c +++ b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c @@ -289,8 +289,8 @@ static void edpt_reset_all(uint8_t rhport) } prepare_setup_packet(rhport); } -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; edpt_reset_all(rhport); dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs; diff --git a/src/portable/ohci/ohci.c b/src/portable/ohci/ohci.c index fbaa5208e5..ce35eab706 100644 --- a/src/portable/ohci/ohci.c +++ b/src/portable/ohci/ohci.c @@ -178,9 +178,9 @@ TU_ATTR_ALWAYS_INLINE static inline void *_virt_addr(void *physical_address) } // Initialization according to 5.1.1.4 -bool hcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; //------------- Data Structure init -------------// tu_memclr(&ohci_data, sizeof(ohci_data_t)); diff --git a/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c b/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c index 83589efa01..89d60a21e8 100644 --- a/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c +++ b/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c @@ -50,7 +50,8 @@ static usb_descriptor_buffers_t desc; *------------------------------------------------------------------*/ // Initialize controller to device mode -void dcd_init(const tusb_rhport_init_t* rh_init) { +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; (void) rh_init; static pio_usb_configuration_t config = PIO_USB_DEFAULT_CONFIG; usb_device = pio_usb_device_init(&config, &desc); diff --git a/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c b/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c index 4386bbce47..6422afff1a 100644 --- a/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c +++ b/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c @@ -55,7 +55,8 @@ bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void *cfg_param) { return true; } -bool hcd_init(const tusb_rhport_init_t* rh_init) { +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; (void) rh_init; // To run USB SOF interrupt in core1, call this init in core1 diff --git a/src/portable/raspberrypi/rp2040/dcd_rp2040.c b/src/portable/raspberrypi/rp2040/dcd_rp2040.c index 9473d3bd85..9a945caf86 100644 --- a/src/portable/raspberrypi/rp2040/dcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/dcd_rp2040.c @@ -369,8 +369,8 @@ static void __tusb_irq_path_func(dcd_rp2040_irq)(void) { #define PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY 0xff #endif -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; assert(rhport == 0); TU_LOG(2, "Chip Version B%u\r\n", rp2040_chip_version()); diff --git a/src/portable/raspberrypi/rp2040/hcd_rp2040.c b/src/portable/raspberrypi/rp2040/hcd_rp2040.c index a870418a8a..2c0a3fd49e 100644 --- a/src/portable/raspberrypi/rp2040/hcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/hcd_rp2040.c @@ -375,7 +375,8 @@ static void _hw_endpoint_init(struct hw_endpoint *ep, uint8_t dev_addr, uint8_t //--------------------------------------------------------------------+ // HCD API //--------------------------------------------------------------------+ -bool hcd_init(const tusb_rhport_init_t* rh_init) { +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; (void) rh_init; pico_trace("hcd_init %d\n", rhport); assert(rhport == 0); diff --git a/src/portable/renesas/rusb2/dcd_rusb2.c b/src/portable/renesas/rusb2/dcd_rusb2.c index e8e1bf041b..3da4ef50b5 100644 --- a/src/portable/renesas/rusb2/dcd_rusb2.c +++ b/src/portable/renesas/rusb2/dcd_rusb2.c @@ -657,8 +657,8 @@ static void enable_interrupt(uint32_t pswi) } #endif -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; rusb2_reg_t* rusb = RUSB2_REG(rhport); rusb2_module_start(rhport, true); diff --git a/src/portable/renesas/rusb2/hcd_rusb2.c b/src/portable/renesas/rusb2/hcd_rusb2.c index 35e85a3b0c..4c81b05be8 100644 --- a/src/portable/renesas/rusb2/hcd_rusb2.c +++ b/src/portable/renesas/rusb2/hcd_rusb2.c @@ -466,8 +466,8 @@ static void enable_interrupt(uint32_t pswi) } #endif -bool hcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; rusb2_reg_t* rusb = RUSB2_REG(rhport); rusb2_module_start(rhport, true); diff --git a/src/portable/sony/cxd56/dcd_cxd56.c b/src/portable/sony/cxd56/dcd_cxd56.c index fe1c422492..93eb8674e5 100644 --- a/src/portable/sony/cxd56/dcd_cxd56.c +++ b/src/portable/sony/cxd56/dcd_cxd56.c @@ -201,9 +201,9 @@ static void _dcd_resume(FAR struct usbdevclass_driver_s *driver, FAR struct usbd dcd_event_bus_signal(0, DCD_EVENT_RESUME, true); } -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; usbdcd_driver.usbdevclass_driver.speed = USB_SPEED_HIGH; usbdcd_driver.usbdevclass_driver.ops = &g_driverops; diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c index 8e9bb0b30a..a4bd2da10c 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c @@ -184,8 +184,8 @@ TU_ATTR_ALWAYS_INLINE static inline xfer_ctl_t *xfer_ctl_ptr(uint8_t epnum, uint //--------------------------------------------------------------------+ // Controller API //--------------------------------------------------------------------+ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; // Follow the RM mentions to use a special ordering of PDWN and FRES for (volatile uint32_t i = 0; i < 200; i++) { // should be a few us asm("NOP"); diff --git a/src/portable/sunxi/dcd_sunxi_musb.c b/src/portable/sunxi/dcd_sunxi_musb.c index d7bf1068ad..85c7bef5dd 100644 --- a/src/portable/sunxi/dcd_sunxi_musb.c +++ b/src/portable/sunxi/dcd_sunxi_musb.c @@ -867,8 +867,8 @@ static void usb_isr_handler(void) { dcd_int_handler(0); } -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; dcd_disconnect(rhport); USBC_HardwareReset(); USBC_PhyConfig(); diff --git a/src/portable/synopsys/dwc2/dcd_dwc2.c b/src/portable/synopsys/dwc2/dcd_dwc2.c index 580960e24d..e44ca96d15 100644 --- a/src/portable/synopsys/dwc2/dcd_dwc2.c +++ b/src/portable/synopsys/dwc2/dcd_dwc2.c @@ -650,10 +650,10 @@ static bool check_dwc2(dwc2_regs_t* dwc2) { return true; } -void dcd_init(const tusb_rhport_init_t* rh_init) { +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; (void) rh_init; // Programming model begins in the last section of the chapter on the USB // peripheral in each Reference Manual. - const uint8_t rhport = rh_init->rhport; dwc2_regs_t* dwc2 = DWC2_REG(rhport); // Check Synopsys ID register, failed if controller clock/power is not enabled diff --git a/src/portable/template/dcd_template.c b/src/portable/template/dcd_template.c index 56a89e89af..5ce650844c 100644 --- a/src/portable/template/dcd_template.c +++ b/src/portable/template/dcd_template.c @@ -40,8 +40,8 @@ *------------------------------------------------------------------*/ // Initialize controller to device mode -void dcd_init(const tusb_rhport_init_t* rh_init) { - (void) rh_init; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; (void) rh_init; } // Enable device interrupt diff --git a/src/portable/template/hcd_template.c b/src/portable/template/hcd_template.c index 9386e95cc0..d8bca196f5 100644 --- a/src/portable/template/hcd_template.c +++ b/src/portable/template/hcd_template.c @@ -44,7 +44,8 @@ bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) { } // Initialize controller to host mode -bool hcd_init(const tusb_rhport_init_t* rh_init) { +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; (void) rh_init; return false; } diff --git a/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c b/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c index 120d5c4b9b..6150c254f2 100644 --- a/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c +++ b/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c @@ -130,8 +130,8 @@ static void enable_functional_reset(const bool enable) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(const tusb_rhport_init_t* rh_init) { - (void) rh_init; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; (void) rh_init; USBKEYPID = USBKEY; @@ -699,11 +699,10 @@ static void handle_bus_power_event(void *param) { // A successful lock is indicated by all PLL-related interrupt flags being cleared. if(!USBPLLIR) { const tusb_rhport_init_t rhport_init = { - .rhport = 0, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_FULL }; - dcd_init(&rhport_init); // Re-initialize the USB module. + dcd_init(0, &rhport_init); // Re-initialize the USB module. } } else { // Event caused by removal of bus power. USBPWRCTL |= VBONIE; // Enable bus-power-applied interrupt. diff --git a/src/portable/valentyusb/eptri/dcd_eptri.c b/src/portable/valentyusb/eptri/dcd_eptri.c index da7a5a81a2..8287230a48 100644 --- a/src/portable/valentyusb/eptri/dcd_eptri.c +++ b/src/portable/valentyusb/eptri/dcd_eptri.c @@ -336,9 +336,9 @@ static void dcd_reset(void) } // Initializes the USB peripheral for device mode and enables it. -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; usb_pullup_out_write(0); diff --git a/src/portable/wch/dcd_ch32_usbfs.c b/src/portable/wch/dcd_ch32_usbfs.c index 4a7ad704b4..9af3a1acbb 100644 --- a/src/portable/wch/dcd_ch32_usbfs.c +++ b/src/portable/wch/dcd_ch32_usbfs.c @@ -123,8 +123,8 @@ static void update_out(uint8_t rhport, uint8_t ep, size_t rx_len) { } /* public functions */ -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; // init registers USBOTG_FS->BASE_CTRL = USBFS_CTRL_SYS_CTRL | USBFS_CTRL_INT_BUSY | USBFS_CTRL_DMA_EN; USBOTG_FS->UDEV_CTRL = USBFS_UDEV_CTRL_PD_DIS | USBFS_UDEV_CTRL_PORT_EN; diff --git a/src/portable/wch/dcd_ch32_usbhs.c b/src/portable/wch/dcd_ch32_usbhs.c index 77ebc378cf..64a88914f1 100644 --- a/src/portable/wch/dcd_ch32_usbhs.c +++ b/src/portable/wch/dcd_ch32_usbhs.c @@ -131,9 +131,9 @@ static void xfer_data_packet(uint8_t ep_num, tusb_dir_t ep_dir, xfer_ctl_t* xfer ep_set_response_and_toggle(ep_num, ep_dir, USBHS_EP_R_RES_ACK); } -void dcd_init(const tusb_rhport_init_t* rh_init) { - const uint8_t rhport = rh_init->rhport; +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; + (void) rh_init; memset(&xfer_status, 0, sizeof(xfer_status)); diff --git a/src/tusb.c b/src/tusb.c index 3eb299dff4..e6f8055b7b 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -47,29 +47,27 @@ static tusb_role_t _rhport_role[TUP_USBIP_CONTROLLER_NUM] = { 0 }; // Public API //--------------------------------------------------------------------+ -bool tusb_rhport_init(const tusb_rhport_init_t* rh_init) { +bool tusb_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { // backward compatible called with tusb_init(void) #if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT) if (rh_init == NULL) { #if CFG_TUD_ENABLED && defined(TUD_OPT_RHPORT) // init device stack CFG_TUSB_RHPORTx_MODE must be defined const tusb_rhport_init_t dev_init = { - .rhport = TUD_OPT_RHPORT, .role = TUSB_ROLE_DEVICE, .speed = TUD_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL }; - TU_ASSERT ( tud_rhport_init(&dev_init) ); + TU_ASSERT ( tud_rhport_init(rhport, &dev_init) ); _rhport_role[TUD_OPT_RHPORT] = TUSB_ROLE_DEVICE; #endif #if CFG_TUH_ENABLED && defined(TUH_OPT_RHPORT) // init host stack CFG_TUSB_RHPORTx_MODE must be defined const tusb_rhport_init_t host_init = { - .rhport = TUH_OPT_RHPORT, .role = TUSB_ROLE_HOST, .speed = TUH_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL }; - TU_ASSERT( tuh_rhport_init(&host_init) ); + TU_ASSERT( tuh_rhport_init(TUH_OPT_RHPORT, &host_init) ); _rhport_role[TUH_OPT_RHPORT] = TUSB_ROLE_HOST; #endif @@ -78,21 +76,21 @@ bool tusb_rhport_init(const tusb_rhport_init_t* rh_init) { #endif // new API with explicit rhport and role - TU_ASSERT(rh_init->rhport < TUP_USBIP_CONTROLLER_NUM && rh_init->role != TUSB_ROLE_INVALID); + TU_ASSERT(rhport < TUP_USBIP_CONTROLLER_NUM && rh_init->role != TUSB_ROLE_INVALID); #if CFG_TUD_ENABLED if (rh_init->role == TUSB_ROLE_DEVICE) { - TU_ASSERT( tud_rhport_init(rh_init) ); + TU_ASSERT(tud_rhport_init(rhport, rh_init)); } #endif #if CFG_TUH_ENABLED if (rh_init->role == TUSB_ROLE_HOST) { - TU_ASSERT( tuh_rhport_init(rh_init) ); + TU_ASSERT(tuh_rhport_init(rhport, rh_init)); } #endif - _rhport_role[rh_init->rhport] = rh_init->role; + _rhport_role[rhport] = rh_init->role; return true; } diff --git a/src/tusb.h b/src/tusb.h index c12abba8b8..2f30a57394 100644 --- a/src/tusb.h +++ b/src/tusb.h @@ -134,20 +134,21 @@ #if CFG_TUH_ENABLED || CFG_TUD_ENABLED // Internal helper for backward compatible with tusb_init(void) -bool tusb_rhport_init(const tusb_rhport_init_t* rh_init); +bool tusb_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init); // Initialize roothub port with device/host role // Note: when using with RTOS, this should be called after scheduler/kernel is started. // Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API. // Note2: defined as macro for backward compatible with tusb_init(void), can be changed to function in the future. #if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT) -#define _tusb_init_arg0() tusb_rhport_init(NULL) + #define _tusb_init_arg0() tusb_rhport_init(0, NULL) #else -#define _tusb_init_arg0() TU_VERIFY_STATIC(false, "CFG_TUSB_RHPORT0_MODE/CFG_TUSB_RHPORT1_MODE must be defined") + #define _tusb_init_arg0() TU_VERIFY_STATIC(false, "CFG_TUSB_RHPORT0_MODE/CFG_TUSB_RHPORT1_MODE must be defined") #endif -#define _tusb_init_arg1(_rh_init) tusb_rhport_init(_rh_init) -#define tusb_init(...) TU_FUNC_OPTIONAL_ARG(_tusb_init, __VA_ARGS__) +#define _tusb_init_arg1(_rhport) _tusb_init_arg0() +#define _tusb_init_arg2(_rhport, _rh_init) tusb_rhport_init(_rhport, _rh_init) +#define tusb_init(...) TU_FUNC_OPTIONAL_ARG(_tusb_init, __VA_ARGS__) // Check if stack is initialized bool tusb_inited(void); diff --git a/test/fuzz/dcd_fuzz.cc b/test/fuzz/dcd_fuzz.cc index 7ef0c74468..e76ae5087f 100644 --- a/test/fuzz/dcd_fuzz.cc +++ b/test/fuzz/dcd_fuzz.cc @@ -46,7 +46,8 @@ tu_static State state = {false, 0, 0}; // All no-ops as we are fuzzing. //--------------------------------------------------------------------+ extern "C" { -void dcd_init(const tusb_rhport_init_t* rh_init) { +void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + UNUSED(rhport); UNUSED(rh_init); return; } diff --git a/test/unit-test/test/device/msc/test_msc_device.c b/test/unit-test/test/device/msc/test_msc_device.c index 4033bf1586..60fcdb41cf 100644 --- a/test/unit-test/test/device/msc/test_msc_device.c +++ b/test/unit-test/test/device/msc/test_msc_device.c @@ -199,13 +199,12 @@ void setUp(void) if ( !tud_inited() ) { tusb_rhport_init_t dev_init = { - .rhport = 0, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; - dcd_init_Expect(&dev_init); - tusb_init(&dev_init); + dcd_init_Expect(0, &dev_init); + tusb_init(0, &dev_init); } dcd_event_bus_reset(rhport, TUSB_SPEED_HIGH, false); diff --git a/test/unit-test/test/device/usbd/test_usbd.c b/test/unit-test/test/device/usbd/test_usbd.c index 8f900f6561..598dac641d 100644 --- a/test/unit-test/test/device/usbd/test_usbd.c +++ b/test/unit-test/test/device/usbd/test_usbd.c @@ -102,44 +102,38 @@ uint8_t const* desc_configuration; //--------------------------------------------------------------------+ // //--------------------------------------------------------------------+ -uint8_t const * tud_descriptor_device_cb(void) -{ +uint8_t const * tud_descriptor_device_cb(void) { return desc_device; } -uint8_t const * tud_descriptor_configuration_cb(uint8_t index) -{ +uint8_t const * tud_descriptor_configuration_cb(uint8_t index) { return desc_configuration; } -uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) -{ +uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) { (void) langid; return NULL; } -void setUp(void) -{ +void setUp(void) { dcd_int_disable_Ignore(); dcd_int_enable_Ignore(); if ( !tud_inited() ) { tusb_rhport_init_t dev_init = { - .rhport = 0, .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO }; mscd_init_Expect(); - dcd_init_Expect(&dev_init); + dcd_init_Expect(0, &dev_init); - tusb_init(&dev_init); + tusb_init(0, &dev_init); } } -void tearDown(void) -{ +void tearDown(void) { } //--------------------------------------------------------------------+ From e83e08343afca86b2bacf26822ef9032571e6f56 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 14 Oct 2024 19:42:22 +0700 Subject: [PATCH 6/6] change dcd_init() return from void to bool --- src/device/dcd.h | 2 +- src/device/usbd.c | 9 +++++---- src/portable/bridgetek/ft9xx/dcd_ft9xx.c | 3 ++- src/portable/chipidea/ci_fs/dcd_ci_fs.c | 3 ++- src/portable/chipidea/ci_hs/dcd_ci_hs.c | 6 ++++-- src/portable/dialog/da146xx/dcd_da146xx.c | 7 ++++--- src/portable/espressif/esp32sx/dcd_esp32sx.c | 3 ++- src/portable/mentor/musb/dcd_musb.c | 3 ++- src/portable/microchip/pic/dcd_pic.c | 3 ++- src/portable/microchip/pic32mz/dcd_pic32mz.c | 3 ++- src/portable/microchip/samd/dcd_samd.c | 7 +++++-- src/portable/microchip/samg/dcd_samg.c | 4 +++- src/portable/microchip/samx7x/dcd_samx7x.c | 3 ++- src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c | 3 ++- src/portable/nordic/nrf5x/dcd_nrf5x.c | 3 ++- src/portable/nuvoton/nuc120/dcd_nuc120.c | 4 +++- src/portable/nuvoton/nuc121/dcd_nuc121.c | 4 +++- src/portable/nuvoton/nuc505/dcd_nuc505.c | 4 +++- src/portable/nxp/khci/dcd_khci.c | 4 +++- src/portable/nxp/lpc17_40/dcd_lpc17_40.c | 4 +++- src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c | 4 +++- src/portable/raspberrypi/pio_usb/dcd_pio_usb.c | 4 +++- src/portable/raspberrypi/rp2040/dcd_rp2040.c | 3 ++- src/portable/renesas/rusb2/dcd_rusb2.c | 10 ++++++---- src/portable/sony/cxd56/dcd_cxd56.c | 4 +++- src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 4 +++- src/portable/sunxi/dcd_sunxi_musb.c | 5 ++++- src/portable/synopsys/dwc2/dcd_dwc2.c | 9 ++++++--- src/portable/template/dcd_template.c | 3 ++- src/portable/ti/msp430x5xx/dcd_msp430x5xx.c | 4 +++- src/portable/valentyusb/eptri/dcd_eptri.c | 4 +++- src/portable/wch/dcd_ch32_usbfs.c | 4 +++- src/portable/wch/dcd_ch32_usbhs.c | 4 +++- test/fuzz/dcd_fuzz.cc | 4 ++-- test/unit-test/test/device/msc/test_msc_device.c | 2 +- test/unit-test/test/device/usbd/test_usbd.c | 2 +- 36 files changed, 103 insertions(+), 49 deletions(-) diff --git a/src/device/dcd.h b/src/device/dcd.h index 64dffbaefb..d01f82e01c 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -108,7 +108,7 @@ void dcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) TU_ATTR_W //--------------------------------------------------------------------+ // Initialize controller to device mode -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init); +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init); // Deinitialize controller, unset device mode. bool dcd_deinit(uint8_t rhport); diff --git a/src/device/usbd.c b/src/device/usbd.c index 4b6600eb26..a730b745b8 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -454,7 +454,7 @@ bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { } TU_ASSERT(rh_init); - TU_LOG_USBD("USBD init on controller %u, speed = %s\r\n", rh_init->rhport, + TU_LOG_USBD("USBD init on controller %u, speed = %s\r\n", rhport, rh_init->speed == TUSB_SPEED_HIGH ? "High" : "Full"); TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(usbd_device_t)); TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(dcd_event_t)); @@ -490,15 +490,16 @@ bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { _usbd_rhport = rhport; // Init device controller driver - dcd_init(rhport, rh_init); + TU_ASSERT(dcd_init(rhport, rh_init)); dcd_int_enable(rhport); return true; } bool tud_deinit(uint8_t rhport) { - // skip if not initialized - if (!tud_inited()) return true; + if (!tud_inited()) { + return true; // skip if not initialized + } TU_LOG_USBD("USBD deinit on controller %u\r\n", rhport); diff --git a/src/portable/bridgetek/ft9xx/dcd_ft9xx.c b/src/portable/bridgetek/ft9xx/dcd_ft9xx.c index 4e7b288251..34a8be3b66 100644 --- a/src/portable/bridgetek/ft9xx/dcd_ft9xx.c +++ b/src/portable/bridgetek/ft9xx/dcd_ft9xx.c @@ -517,7 +517,7 @@ static uint16_t _ft9xx_dusb_out(uint8_t ep_number, uint8_t *buffer, uint16_t len *------------------------------------------------------------------*/ // Initialize controller to device mode -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; TU_LOG2("FT9xx initialisation\r\n"); @@ -526,6 +526,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { interrupt_attach(interrupt_usb_device, (int8_t)interrupt_usb_device, _ft9xx_usbd_ISR); dcd_connect(rhport); + return true; } // Enable device interrupt diff --git a/src/portable/chipidea/ci_fs/dcd_ci_fs.c b/src/portable/chipidea/ci_fs/dcd_ci_fs.c index 6038160cfc..11ddb683f3 100644 --- a/src/portable/chipidea/ci_fs/dcd_ci_fs.c +++ b/src/portable/chipidea/ci_fs/dcd_ci_fs.c @@ -267,7 +267,7 @@ static void process_bus_resume(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; @@ -296,6 +296,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { dcd_connect(rhport); // NVIC_ClearPendingIRQ(CIFS_IRQN); + return true; } void dcd_set_address(uint8_t rhport, uint8_t dev_addr) diff --git a/src/portable/chipidea/ci_hs/dcd_ci_hs.c b/src/portable/chipidea/ci_hs/dcd_ci_hs.c index 5204dee66d..430a0aad10 100644 --- a/src/portable/chipidea/ci_hs/dcd_ci_hs.c +++ b/src/portable/chipidea/ci_hs/dcd_ci_hs.c @@ -234,13 +234,13 @@ static void bus_reset(uint8_t rhport) dcd_dcache_clean_invalidate(&_dcd_data, sizeof(dcd_data_t)); } -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; tu_memclr(&_dcd_data, sizeof(dcd_data_t)); ci_hs_regs_t* dcd_reg = CI_HS_REG(rhport); - TU_ASSERT(ci_ep_count(dcd_reg) <= TUP_DCD_ENDPOINT_MAX, ); + TU_ASSERT(ci_ep_count(dcd_reg) <= TUP_DCD_ENDPOINT_MAX); // Reset controller dcd_reg->USBCMD |= USBCMD_RESET; @@ -268,6 +268,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { usbcmd |= USBCMD_RUN_STOP; // run dcd_reg->USBCMD = usbcmd; + + return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/dialog/da146xx/dcd_da146xx.c b/src/portable/dialog/da146xx/dcd_da146xx.c index 558e1269a9..887f59588d 100644 --- a/src/portable/dialog/da146xx/dcd_da146xx.c +++ b/src/portable/dialog/da146xx/dcd_da146xx.c @@ -804,15 +804,16 @@ static void handle_ep0_nak(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; _dcd.init_called = true; - if (_dcd.vbus_present) - { + if (_dcd.vbus_present) { dcd_connect(rhport); } + + return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/espressif/esp32sx/dcd_esp32sx.c b/src/portable/espressif/esp32sx/dcd_esp32sx.c index d233813d41..1b6aae026b 100644 --- a/src/portable/espressif/esp32sx/dcd_esp32sx.c +++ b/src/portable/espressif/esp32sx/dcd_esp32sx.c @@ -172,7 +172,7 @@ static void enum_done_processing(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; ESP_LOGV(TAG, "DCD init - Start"); @@ -211,6 +211,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { USB_DISCONNINTMSK_M; // host most only dcd_connect(rhport); + return true; } void dcd_set_address(uint8_t rhport, uint8_t dev_addr) diff --git a/src/portable/mentor/musb/dcd_musb.c b/src/portable/mentor/musb/dcd_musb.c index 02c8da1e06..4fce08dd9a 100644 --- a/src/portable/mentor/musb/dcd_musb.c +++ b/src/portable/mentor/musb/dcd_musb.c @@ -582,7 +582,7 @@ void print_musb_info(musb_regs_t* musb_regs) { } #endif -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; musb_regs_t* musb_regs = MUSB_REGS(rhport); @@ -594,6 +594,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { musb_dcd_int_clear(rhport); musb_dcd_phy_init(rhport); dcd_connect(rhport); + return true; } void dcd_int_enable(uint8_t rhport) { diff --git a/src/portable/microchip/pic/dcd_pic.c b/src/portable/microchip/pic/dcd_pic.c index 089d3f5200..d40c4794a8 100644 --- a/src/portable/microchip/pic/dcd_pic.c +++ b/src/portable/microchip/pic/dcd_pic.c @@ -470,7 +470,7 @@ static void process_bus_resume(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; intr_disable(rhport); intr_clear(rhport); @@ -502,6 +502,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { U1IE = _U1IE_URSTIE_MASK; dcd_connect(rhport); + return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/microchip/pic32mz/dcd_pic32mz.c b/src/portable/microchip/pic32mz/dcd_pic32mz.c index f1614f30c1..8709baf671 100644 --- a/src/portable/microchip/pic32mz/dcd_pic32mz.c +++ b/src/portable/microchip/pic32mz/dcd_pic32mz.c @@ -120,7 +120,7 @@ static ep0_stage_t ep0_get_stage(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; // Disable endpoint interrupts for now USB_REGS->INTRRXEbits.w = 0; @@ -129,6 +129,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { USB_REGS->INTRUSBEbits.w = 7; dcd_connect(rhport); + return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/microchip/samd/dcd_samd.c b/src/portable/microchip/samd/dcd_samd.c index 8120681a7f..0c96f6ac42 100644 --- a/src/portable/microchip/samd/dcd_samd.c +++ b/src/portable/microchip/samd/dcd_samd.c @@ -78,8 +78,9 @@ static void bus_reset(void) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { - (void) rhport; (void) rh_init; +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; + (void) rh_init; // Reset to get in a clean state. USB->DEVICE.CTRLA.bit.SWRST = true; @@ -101,6 +102,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { USB->DEVICE.INTFLAG.reg |= USB->DEVICE.INTFLAG.reg; // clear pending USB->DEVICE.INTENSET.reg = /* USB_DEVICE_INTENSET_SOF | */ USB_DEVICE_INTENSET_EORST; + + return true; } #if CFG_TUSB_MCU == OPT_MCU_SAMD51 || CFG_TUSB_MCU == OPT_MCU_SAME5X diff --git a/src/portable/microchip/samg/dcd_samg.c b/src/portable/microchip/samg/dcd_samg.c index b02889b244..c88b315144 100644 --- a/src/portable/microchip/samg/dcd_samg.c +++ b/src/portable/microchip/samg/dcd_samg.c @@ -155,11 +155,13 @@ static void bus_reset(void) } // Initialize controller to device mode -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; + tu_memclr(_dcd_xfer, sizeof(_dcd_xfer)); dcd_connect(rhport); + return true; } // Enable device interrupt diff --git a/src/portable/microchip/samx7x/dcd_samx7x.c b/src/portable/microchip/samx7x/dcd_samx7x.c index a85d2306ed..8aec1568d0 100644 --- a/src/portable/microchip/samx7x/dcd_samx7x.c +++ b/src/portable/microchip/samx7x/dcd_samx7x.c @@ -104,9 +104,10 @@ TU_ATTR_ALWAYS_INLINE static inline void CleanInValidateCache(uint32_t *addr, in //------------------------------------------------------------------ // Initialize controller to device mode -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; dcd_connect(rhport); + return true; } // Enable device interrupt diff --git a/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c b/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c index b74ca847a9..1ce3da27ee 100644 --- a/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c +++ b/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c @@ -245,7 +245,7 @@ static void process_bus_active(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; @@ -256,6 +256,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { dcd_connect(rhport); NVIC_ClearPendingIRQ(USB_FS_IRQn); + return true; } #define USB_DEVICE_INTERRUPT_PRIORITY (3U) void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 06474e65d7..3f53ee26e5 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -230,10 +230,11 @@ static void xact_in_dma(uint8_t epnum) { //--------------------------------------------------------------------+ // Controller API //--------------------------------------------------------------------+ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; TU_LOG2("dcd init\r\n"); + return true; } void dcd_int_enable(uint8_t rhport) { diff --git a/src/portable/nuvoton/nuc120/dcd_nuc120.c b/src/portable/nuvoton/nuc120/dcd_nuc120.c index 89fca021fd..b0b6fe8576 100644 --- a/src/portable/nuvoton/nuc120/dcd_nuc120.c +++ b/src/portable/nuvoton/nuc120/dcd_nuc120.c @@ -201,7 +201,7 @@ static const uint32_t enabled_irqs = USBD_INTSTS_FLDET_STS_Msk | USBD_INTSTS_BUS NUC100/NUC120 TinyUSB API driver implementation */ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; @@ -215,6 +215,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { USBD->INTSTS = enabled_irqs; USBD->INTEN = enabled_irqs; + + return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/nuvoton/nuc121/dcd_nuc121.c b/src/portable/nuvoton/nuc121/dcd_nuc121.c index b813eea772..f4af97ca75 100644 --- a/src/portable/nuvoton/nuc121/dcd_nuc121.c +++ b/src/portable/nuvoton/nuc121/dcd_nuc121.c @@ -209,7 +209,7 @@ enum { NUC121/NUC125/NUC126 TinyUSB API driver implementation */ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; @@ -227,6 +227,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { USBD->INTSTS = ENABLED_IRQS; USBD->INTEN = ENABLED_IRQS; + + return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/nuvoton/nuc505/dcd_nuc505.c b/src/portable/nuvoton/nuc505/dcd_nuc505.c index 3821b6ec8a..1c98a0a493 100644 --- a/src/portable/nuvoton/nuc505/dcd_nuc505.c +++ b/src/portable/nuvoton/nuc505/dcd_nuc505.c @@ -279,7 +279,7 @@ static const uint32_t enabled_irqs = USBD_GINTEN_USBIEN_Msk | \ NUC505 TinyUSB API driver implementation */ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; @@ -291,6 +291,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { bus_reset(); usb_attach(); + + return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/nxp/khci/dcd_khci.c b/src/portable/nxp/khci/dcd_khci.c index 1b7f56e8c4..8398b09bf8 100644 --- a/src/portable/nxp/khci/dcd_khci.c +++ b/src/portable/nxp/khci/dcd_khci.c @@ -265,7 +265,7 @@ static void process_bus_resume(uint8_t rhport) /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; @@ -294,6 +294,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { dcd_connect(rhport); NVIC_ClearPendingIRQ(USB0_IRQn); + + return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index 22b4500c57..855c59cd1c 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -167,7 +167,7 @@ static void bus_reset(void) tu_memclr(&_dcd, sizeof(dcd_data_t)); } -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; @@ -186,6 +186,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { // Clear pending IRQ NVIC_ClearPendingIRQ(USB_IRQn); + + return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c index e59a0f5261..7d5cfb5b0f 100644 --- a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c +++ b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c @@ -289,7 +289,7 @@ static void edpt_reset_all(uint8_t rhport) } prepare_setup_packet(rhport); } -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; edpt_reset_all(rhport); @@ -303,6 +303,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { DEVCMDSTAT_RESET_CHANGE_MASK | DEVCMDSTAT_CONNECT_CHANGE_MASK | DEVCMDSTAT_SUSPEND_CHANGE_MASK; NVIC_ClearPendingIRQ(_dcd_controller[rhport].irqnum); + + return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c b/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c index 89d60a21e8..60afbd4352 100644 --- a/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c +++ b/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c @@ -50,11 +50,13 @@ static usb_descriptor_buffers_t desc; *------------------------------------------------------------------*/ // Initialize controller to device mode -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; static pio_usb_configuration_t config = PIO_USB_DEFAULT_CONFIG; usb_device = pio_usb_device_init(&config, &desc); + + return true; } // Enable device interrupt diff --git a/src/portable/raspberrypi/rp2040/dcd_rp2040.c b/src/portable/raspberrypi/rp2040/dcd_rp2040.c index 9a945caf86..2e177d5cbf 100644 --- a/src/portable/raspberrypi/rp2040/dcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/dcd_rp2040.c @@ -369,7 +369,7 @@ static void __tusb_irq_path_func(dcd_rp2040_irq)(void) { #define PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY 0xff #endif -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; assert(rhport == 0); @@ -406,6 +406,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (FORCE_VBUS_DETECT ? 0 : USB_INTS_DEV_CONN_DIS_BITS); dcd_connect(rhport); + return true; } bool dcd_deinit(uint8_t rhport) { diff --git a/src/portable/renesas/rusb2/dcd_rusb2.c b/src/portable/renesas/rusb2/dcd_rusb2.c index 3da4ef50b5..ecd28973c7 100644 --- a/src/portable/renesas/rusb2/dcd_rusb2.c +++ b/src/portable/renesas/rusb2/dcd_rusb2.c @@ -657,14 +657,14 @@ static void enable_interrupt(uint32_t pswi) } #endif -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; rusb2_reg_t* rusb = RUSB2_REG(rhport); rusb2_module_start(rhport, true); -// We disable SOF for now until needed later on. -// Since TinyUSB doesn't use SOF for now, and this interrupt often (1ms interval) -_dcd.sof_enabled = false; + // We disable SOF for now until needed later on. + // Since TinyUSB doesn't use SOF for now, and this interrupt often (1ms interval) + _dcd.sof_enabled = false; #ifdef RUSB2_SUPPORT_HIGHSPEED if ( rusb2_is_highspeed_rhport(rhport) ) { @@ -719,6 +719,8 @@ _dcd.sof_enabled = false; if (rusb->INTSTS0_b.VBSTS) { dcd_connect(rhport); } + + return true; } void dcd_int_enable(uint8_t rhport) { diff --git a/src/portable/sony/cxd56/dcd_cxd56.c b/src/portable/sony/cxd56/dcd_cxd56.c index 93eb8674e5..b16509c6fb 100644 --- a/src/portable/sony/cxd56/dcd_cxd56.c +++ b/src/portable/sony/cxd56/dcd_cxd56.c @@ -201,7 +201,7 @@ static void _dcd_resume(FAR struct usbdevclass_driver_s *driver, FAR struct usbd dcd_event_bus_signal(0, DCD_EVENT_RESUME, true); } -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; @@ -211,6 +211,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { usbdcd_driver.setup_queue = osal_queue_create(&_setup_queue_def); usbdev_register(&usbdcd_driver.usbdevclass_driver); + + return true; } // Enable device interrupt diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c index a4bd2da10c..d921429e29 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c @@ -184,7 +184,7 @@ TU_ATTR_ALWAYS_INLINE static inline xfer_ctl_t *xfer_ctl_ptr(uint8_t epnum, uint //--------------------------------------------------------------------+ // Controller API //--------------------------------------------------------------------+ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; // Follow the RM mentions to use a special ordering of PDWN and FRES for (volatile uint32_t i = 0; i < 200; i++) { // should be a few us @@ -224,6 +224,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { // Enable pull-up if supported dcd_connect(rhport); + + return true; } void dcd_sof_enable(uint8_t rhport, bool en) { diff --git a/src/portable/sunxi/dcd_sunxi_musb.c b/src/portable/sunxi/dcd_sunxi_musb.c index 85c7bef5dd..21f13b279d 100644 --- a/src/portable/sunxi/dcd_sunxi_musb.c +++ b/src/portable/sunxi/dcd_sunxi_musb.c @@ -867,8 +867,9 @@ static void usb_isr_handler(void) { dcd_int_handler(0); } -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; + dcd_disconnect(rhport); USBC_HardwareReset(); USBC_PhyConfig(); @@ -895,6 +896,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { f1c100s_intc_set_isr(F1C100S_IRQ_USBOTG, usb_isr_handler); dcd_connect(rhport); + + return true; } // Connect by enabling internal pull-up resistor on D+/D- diff --git a/src/portable/synopsys/dwc2/dcd_dwc2.c b/src/portable/synopsys/dwc2/dcd_dwc2.c index e44ca96d15..f30ec5ee39 100644 --- a/src/portable/synopsys/dwc2/dcd_dwc2.c +++ b/src/portable/synopsys/dwc2/dcd_dwc2.c @@ -650,14 +650,15 @@ static bool check_dwc2(dwc2_regs_t* dwc2) { return true; } -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { - (void) rhport; (void) rh_init; +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rhport; + (void) rh_init; // Programming model begins in the last section of the chapter on the USB // peripheral in each Reference Manual. dwc2_regs_t* dwc2 = DWC2_REG(rhport); // Check Synopsys ID register, failed if controller clock/power is not enabled - TU_ASSERT(check_dwc2(dwc2), ); + TU_ASSERT(check_dwc2(dwc2)); dcd_disconnect(rhport); if (phy_hs_supported(dwc2)) { @@ -726,6 +727,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { // TU_LOG_HEX(DWC2_DEBUG, dwc2->gahbcfg); dcd_connect(rhport); + + return true; } void dcd_int_enable(uint8_t rhport) { diff --git a/src/portable/template/dcd_template.c b/src/portable/template/dcd_template.c index 5ce650844c..3738ac0cb9 100644 --- a/src/portable/template/dcd_template.c +++ b/src/portable/template/dcd_template.c @@ -40,8 +40,9 @@ *------------------------------------------------------------------*/ // Initialize controller to device mode -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; + return true; } // Enable device interrupt diff --git a/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c b/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c index 6150c254f2..3752ae2519 100644 --- a/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c +++ b/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c @@ -130,7 +130,7 @@ static void enable_functional_reset(const bool enable) /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; USBKEYPID = USBKEY; @@ -163,6 +163,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { } USBKEYPID = 0; + + return true; } // There is no "USB peripheral interrupt disable" bit on MSP430, so we have diff --git a/src/portable/valentyusb/eptri/dcd_eptri.c b/src/portable/valentyusb/eptri/dcd_eptri.c index 8287230a48..a03c945589 100644 --- a/src/portable/valentyusb/eptri/dcd_eptri.c +++ b/src/portable/valentyusb/eptri/dcd_eptri.c @@ -336,7 +336,7 @@ static void dcd_reset(void) } // Initializes the USB peripheral for device mode and enables it. -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; @@ -352,6 +352,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { // Turn on the external pullup usb_pullup_out_write(1); + + return true; } // Enables or disables the USB device interrupt(s). May be used to diff --git a/src/portable/wch/dcd_ch32_usbfs.c b/src/portable/wch/dcd_ch32_usbfs.c index 9af3a1acbb..4e8e25a001 100644 --- a/src/portable/wch/dcd_ch32_usbfs.c +++ b/src/portable/wch/dcd_ch32_usbfs.c @@ -123,7 +123,7 @@ static void update_out(uint8_t rhport, uint8_t ep, size_t rx_len) { } /* public functions */ -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; // init registers USBOTG_FS->BASE_CTRL = USBFS_CTRL_SYS_CTRL | USBFS_CTRL_INT_BUSY | USBFS_CTRL_DMA_EN; @@ -154,6 +154,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { EP_DMA(3) = (uint32_t) &data.ep3_buffer.out[0]; dcd_connect(rhport); + + return true; } void dcd_int_handler(uint8_t rhport) { diff --git a/src/portable/wch/dcd_ch32_usbhs.c b/src/portable/wch/dcd_ch32_usbhs.c index 64a88914f1..f8bf3c8896 100644 --- a/src/portable/wch/dcd_ch32_usbhs.c +++ b/src/portable/wch/dcd_ch32_usbhs.c @@ -131,7 +131,7 @@ static void xfer_data_packet(uint8_t ep_num, tusb_dir_t ep_dir, xfer_ctl_t* xfer ep_set_response_and_toggle(ep_num, ep_dir, USBHS_EP_R_RES_ACK); } -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rhport; (void) rh_init; @@ -171,6 +171,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { USBHSD->DEV_AD = 0; USBHSD->CONTROL |= USBHS_DEV_PU_EN; + + return true; } void dcd_int_enable(uint8_t rhport) { diff --git a/test/fuzz/dcd_fuzz.cc b/test/fuzz/dcd_fuzz.cc index e76ae5087f..046a90555b 100644 --- a/test/fuzz/dcd_fuzz.cc +++ b/test/fuzz/dcd_fuzz.cc @@ -46,10 +46,10 @@ tu_static State state = {false, 0, 0}; // All no-ops as we are fuzzing. //--------------------------------------------------------------------+ extern "C" { -void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { UNUSED(rhport); UNUSED(rh_init); - return; + return true; } void dcd_int_handler(uint8_t rhport) { diff --git a/test/unit-test/test/device/msc/test_msc_device.c b/test/unit-test/test/device/msc/test_msc_device.c index 60fcdb41cf..f2a4fa2958 100644 --- a/test/unit-test/test/device/msc/test_msc_device.c +++ b/test/unit-test/test/device/msc/test_msc_device.c @@ -203,7 +203,7 @@ void setUp(void) .speed = TUSB_SPEED_AUTO }; - dcd_init_Expect(0, &dev_init); + dcd_init_ExpectAndReturn(0, &dev_init, true); tusb_init(0, &dev_init); } diff --git a/test/unit-test/test/device/usbd/test_usbd.c b/test/unit-test/test/device/usbd/test_usbd.c index 598dac641d..9879cd4ba8 100644 --- a/test/unit-test/test/device/usbd/test_usbd.c +++ b/test/unit-test/test/device/usbd/test_usbd.c @@ -127,7 +127,7 @@ void setUp(void) { }; mscd_init_Expect(); - dcd_init_Expect(0, &dev_init); + dcd_init_ExpectAndReturn(0, &dev_init, true); tusb_init(0, &dev_init); }