summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2025-11-06 20:29:23 +0700
committerGitHub <[email protected]>2025-11-06 20:29:23 +0700
commit6641550f58cd2f983ebb42a28dd881a72d72bc6f (patch)
tree4559b35dacfac6474ae31596325777a6c8c1994f
parent58b4104015ec10089e8790febe8b3b6cef8b4b09 (diff)
parent94c1e05a72b197fc0508d43e91deeb3fc63bb4d6 (diff)
Merge pull request #3333 from hathach/espressif-dual-mode
fix compile issue with enabled both device and host stack for dwc2
-rw-r--r--.PVS-Studio/.pvsconfig6
-rw-r--r--examples/device/video_capture/src/main.c18
-rw-r--r--examples/device/video_capture_2ch/src/main.c6
-rw-r--r--examples/dual/host_info_to_device_cdc/CMakeLists.txt7
-rw-r--r--examples/dual/host_info_to_device_cdc/only.txt1
-rw-r--r--examples/dual/host_info_to_device_cdc/src/CMakeLists.txt4
-rw-r--r--examples/dual/host_info_to_device_cdc/src/main.c126
-rw-r--r--examples/host/cdc_msc_hid_freertos/only.txt2
-rw-r--r--examples/host/device_info/only.txt4
-rw-r--r--hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt39
-rw-r--r--hw/bsp/family_support.cmake6
-rw-r--r--src/CMakeLists.txt13
-rw-r--r--src/portable/synopsys/dwc2/dcd_dwc2.c1
-rw-r--r--src/portable/synopsys/dwc2/dwc2_common.c10
-rw-r--r--src/portable/synopsys/dwc2/dwc2_common.h8
15 files changed, 174 insertions, 77 deletions
diff --git a/.PVS-Studio/.pvsconfig b/.PVS-Studio/.pvsconfig
index 2e231c939..2cc60722a 100644
--- a/.PVS-Studio/.pvsconfig
+++ b/.PVS-Studio/.pvsconfig
@@ -1,10 +1,14 @@
//V_EXCLUDE_PATH */iar/cxarm*
-//V_EXCLUDE_PATH */pico-sdk/*
+//V_EXCLUDE_PATH */pico-sdk/
+//V_EXCLUDE_PATH */esp-idf/
+//V_EXCLUDE_PATH */hw/bsp/espressif/components/
+//V_EXCLUDE_PATH */hw/mcu/
//-V::2506 MISRA. A function should have a single point of exit at the end.
//-V::2514 MISRA. Unions should not be used.
//-V:memcpy:2547 [MISRA-C-17.7] The return value of non-void function 'memcpy' should be used.
//-V:printf:2547 [MISRA-C-17.7] The return value of non-void function 'printf' should be used.
+//-V::2584::{gintsts} dwc2
//-V::2600 [MISRA-C-21.6] The function with the 'printf' name should not be used.
//+V2614 DISABLE_LENGHT_LIMIT_CHECK:YES
//-V:memcpy:2628 Pointer arguments to the 'memcpy' function should be pointers to qualified or unqualified versions of compatible types.
diff --git a/examples/device/video_capture/src/main.c b/examples/device/video_capture/src/main.c
index 29656e944..adcfb9f95 100644
--- a/examples/device/video_capture/src/main.c
+++ b/examples/device/video_capture/src/main.c
@@ -53,7 +53,7 @@ void usb_device_task(void *param);
void video_task(void* param);
#if CFG_TUSB_OS == OPT_OS_FREERTOS
-void freertos_init_task(void);
+void freertos_init(void);
#endif
@@ -65,7 +65,7 @@ int main(void) {
// If using FreeRTOS: create blinky, tinyusb device, video task
#if CFG_TUSB_OS == OPT_OS_FREERTOS
- freertos_init_task();
+ freertos_init();
#else
// init device stack on configured roothub port
tusb_rhport_init_t dev_init = {
@@ -211,8 +211,12 @@ static void video_send_frame(void) {
}
unsigned cur = board_millis();
- if (cur - start_ms < interval_ms) return; // not enough time
- if (tx_busy) return;
+ if (cur - start_ms < interval_ms) {
+ return; // not enough time
+ }
+ if (tx_busy) {
+ return;
+ }
start_ms += interval_ms;
tx_busy = 1;
@@ -273,7 +277,9 @@ void led_blinking_task(void* param) {
#if CFG_TUSB_OS == OPT_OS_FREERTOS
vTaskDelay(blink_interval_ms / portTICK_PERIOD_MS);
#else
- if (board_millis() - start_ms < blink_interval_ms) return; // not enough time
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
#endif
start_ms += blink_interval_ms;
@@ -336,7 +342,7 @@ void usb_device_task(void *param) {
}
}
-void freertos_init_task(void) {
+void freertos_init(void) {
#if configSUPPORT_STATIC_ALLOCATION
xTaskCreateStatic(led_blinking_task, "blinky", BLINKY_STACK_SIZE, NULL, 1, blinky_stack, &blinky_taskdef);
xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
diff --git a/examples/device/video_capture_2ch/src/main.c b/examples/device/video_capture_2ch/src/main.c
index a63efa82d..79b149f2b 100644
--- a/examples/device/video_capture_2ch/src/main.c
+++ b/examples/device/video_capture_2ch/src/main.c
@@ -53,7 +53,7 @@ void usb_device_task(void *param);
void video_task(void* param);
#if CFG_TUSB_OS == OPT_OS_FREERTOS
-void freertos_init_task(void);
+void freertos_init(void);
#endif
@@ -65,7 +65,7 @@ int main(void) {
// If using FreeRTOS: create blinky, tinyusb device, video task
#if CFG_TUSB_OS == OPT_OS_FREERTOS
- freertos_init_task();
+ freertos_init();
#else
// init device stack on configured roothub port
tusb_rhport_init_t dev_init = {
@@ -343,7 +343,7 @@ void usb_device_task(void *param) {
}
}
-void freertos_init_task(void) {
+void freertos_init(void) {
#if configSUPPORT_STATIC_ALLOCATION
xTaskCreateStatic(led_blinking_task, "blinky", BLINKY_STACK_SIZE, NULL, 1, blinky_stack, &blinky_taskdef);
xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
diff --git a/examples/dual/host_info_to_device_cdc/CMakeLists.txt b/examples/dual/host_info_to_device_cdc/CMakeLists.txt
index 6ae5b5766..ad3c5ddf0 100644
--- a/examples/dual/host_info_to_device_cdc/CMakeLists.txt
+++ b/examples/dual/host_info_to_device_cdc/CMakeLists.txt
@@ -10,6 +10,11 @@ project(${PROJECT} C CXX ASM)
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
+# Espressif has its own cmake build system
+if(FAMILY STREQUAL "espressif")
+ return()
+endif()
+
add_executable(${PROJECT})
# Example source
@@ -25,7 +30,7 @@ target_include_directories(${PROJECT} PUBLIC
# Configure compilation flags and libraries for the example without RTOS.
# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_dual_usb_example(${PROJECT} noos)
+family_configure_dual_usb_example(${PROJECT} ${RTOS})
# due to warnings from Pico-PIO-USB
if (FAMILY STREQUAL rp2040)
diff --git a/examples/dual/host_info_to_device_cdc/only.txt b/examples/dual/host_info_to_device_cdc/only.txt
index 35f896f1e..4431065ba 100644
--- a/examples/dual/host_info_to_device_cdc/only.txt
+++ b/examples/dual/host_info_to_device_cdc/only.txt
@@ -8,3 +8,4 @@ mcu:MAX3421
mcu:STM32F4
mcu:STM32F7
mcu:STM32H7
+mcu:ESP32P4
diff --git a/examples/dual/host_info_to_device_cdc/src/CMakeLists.txt b/examples/dual/host_info_to_device_cdc/src/CMakeLists.txt
new file mode 100644
index 000000000..cef2b46ee
--- /dev/null
+++ b/examples/dual/host_info_to_device_cdc/src/CMakeLists.txt
@@ -0,0 +1,4 @@
+# This file is for ESP-IDF only
+idf_component_register(SRCS "main.c" "usb_descriptors.c"
+ INCLUDE_DIRS "."
+ REQUIRES boards tinyusb_src)
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 5f3964196..03a1ac3d8 100644
--- a/examples/dual/host_info_to_device_cdc/src/main.c
+++ b/examples/dual/host_info_to_device_cdc/src/main.c
@@ -75,8 +75,12 @@ static tusb_desc_device_t descriptor_device[CFG_TUH_DEVICE_MAX+1];
static void print_utf16(uint16_t *temp_buf, size_t buf_len);
static void print_device_info(uint8_t daddr, const tusb_desc_device_t* desc_device);
-void led_blinking_task(void);
-void cdc_task(void);
+static void led_blinking_task(void);
+static void cdc_task(void);
+
+#if CFG_TUSB_OS == OPT_OS_FREERTOS
+static void freertos_init(void);
+#endif
#define cdc_printf(...) \
do { \
@@ -94,37 +98,86 @@ void cdc_task(void);
} \
} while(0)
-/*------------- MAIN -------------*/
-int main(void) {
- board_init();
-
- printf("TinyUSB Host Information -> Device CDC Example\r\n");
+static void usb_device_init(void) {
// init device and host stack on configured roothub port
tusb_rhport_init_t dev_init = {
.role = TUSB_ROLE_DEVICE,
.speed = TUSB_SPEED_AUTO
};
tusb_init(BOARD_TUD_RHPORT, &dev_init);
+ board_init_after_tusb();
+}
+static void usb_host_init(void) {
+ // init host stack on configured roothub port
tusb_rhport_init_t host_init = {
.role = TUSB_ROLE_HOST,
.speed = TUSB_SPEED_AUTO
};
tusb_init(BOARD_TUH_RHPORT, &host_init);
-
board_init_after_tusb();
+}
+
+//--------------------------------------------------------------------+
+// Main
+//--------------------------------------------------------------------+
+static void main_task(void* param) {
+ (void) param;
while (1) {
- tud_task(); // tinyusb device task
- tuh_task(); // tinyusb host task
cdc_task();
led_blinking_task();
+
+ // preempted RTOS run device/host stack in its own task
+#if CFG_TUSB_OS == OPT_OS_NONE || CFG_TUSB_OS == OPT_OS_PICO
+ tud_task(); // tinyusb device task
+ tuh_task(); // tinyusb host task
+#endif
}
+}
+
+int main(void) {
+ board_init();
+
+#if CFG_TUSB_OS == OPT_OS_NONE || CFG_TUSB_OS == OPT_OS_PICO
+ printf("TinyUSB Host Information -> Device CDC Example\r\n");
+
+ usb_device_init();
+ usb_host_init();
+
+ main_task(NULL);
+#elif CFG_TUSB_OS == OPT_OS_FREERTOS
+ freertos_init(); // create RTOS tasks for device, host stack and main_task()
+#else
+ #error RTOS not supported
+#endif
return 0;
}
+#if CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO
+// USB Device Driver task for RTOS
+static void usb_device_task(void *param) {
+ (void) param;
+ usb_device_init();
+ while (1) {
+ // put this thread to waiting state until there is new events
+ tud_task();
+ }
+}
+
+static void usb_host_task(void *param) {
+ (void) param;
+ usb_host_init();
+ while (1) {
+ // put this thread to waiting state until there is new events
+ tuh_task();
+ }
+}
+#endif
+
+
//--------------------------------------------------------------------+
// Device CDC
//--------------------------------------------------------------------+
@@ -156,7 +209,7 @@ void cdc_task(void) {
if (!tud_cdc_connected()) {
// delay a bit otherwise we can outpace host's terminal. Linux will set LineState (DTR) then Line Coding.
// If we send data before Linux's terminal set Line Coding, it can be ignored --> missing data with hardware test loop
- board_delay(20);
+ tusb_time_delay_ms_api(20);
return;
}
@@ -259,7 +312,6 @@ void led_blinking_task(void) {
//--------------------------------------------------------------------+
// String Descriptor Helper
//--------------------------------------------------------------------+
-
static void _convert_utf16le_to_utf8(const uint16_t *utf16, size_t utf16_len, uint8_t *utf8, size_t utf8_len) {
// TODO: Check for runover.
(void)utf8_len;
@@ -310,3 +362,53 @@ static void print_utf16(uint16_t *temp_buf, size_t buf_len) {
cdc_printf("%s", (char*) temp_buf);
}
+
+//--------------------------------------------------------------------+
+// FreeRTOS
+//--------------------------------------------------------------------+
+#if CFG_TUSB_OS == OPT_OS_FREERTOS
+
+#ifdef ESP_PLATFORM
+ #define USBD_STACK_SIZE 4096
+ #define USBH_STACK_SIZE 4096
+ void app_main(void) {
+ main();
+ }
+#else
+ // Increase stack size when debug log is enabled
+ #define USBD_STACK_SIZE (configMINIMAL_STACK_SIZE * (CFG_TUSB_DEBUG ? 4 : 2))
+ #define USBH_STACK_SIZE (configMINIMAL_STACK_SIZE * (CFG_TUSB_DEBUG ? 4 : 2))
+#endif
+
+#define MAIN_STACK_SIZE (configMINIMAL_STACK_SIZE*4)
+
+// static task
+#if configSUPPORT_STATIC_ALLOCATION
+StackType_t main_stack[MAIN_STACK_SIZE];
+StaticTask_t main_taskdef;
+
+StackType_t usb_device_stack[USBD_STACK_SIZE];
+StaticTask_t usb_device_taskdef;
+
+StackType_t usb_host_stack[USBH_STACK_SIZE];
+StaticTask_t usb_host_taskdef;
+#endif
+
+void freertos_init(void) {
+ #if configSUPPORT_STATIC_ALLOCATION
+ xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
+ xTaskCreateStatic(usb_host_task, "usbh", USBH_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_host_stack, &usb_host_taskdef);
+ xTaskCreateStatic(main_task, "main", MAIN_STACK_SIZE, NULL, configMAX_PRIORITIES - 2, main_stack, &main_taskdef);
+ #else
+ xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
+ xTaskCreate(usb_host_task, "usbh", USBH_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
+ xTaskCreate(main_task, "main", MAIN_STACK_SIZE, NULL, configMAX_PRIORITIES - 2, NULL);
+ #endif
+
+ // only start scheduler for non-espressif mcu
+ #ifndef ESP_PLATFORM
+ vTaskStartScheduler();
+ #endif
+}
+
+#endif
diff --git a/examples/host/cdc_msc_hid_freertos/only.txt b/examples/host/cdc_msc_hid_freertos/only.txt
index 576271aff..ef0a1ac96 100644
--- a/examples/host/cdc_msc_hid_freertos/only.txt
+++ b/examples/host/cdc_msc_hid_freertos/only.txt
@@ -1,4 +1,3 @@
-mcu:ESP32P4
mcu:LPC175X_6X
mcu:LPC177X_8X
mcu:LPC18XX
@@ -15,5 +14,6 @@ mcu:STM32F7
mcu:STM32H7
mcu:STM32H7RS
mcu:STM32N6
+family:espressif
family:samd21
family:samd5x_e5x
diff --git a/examples/host/device_info/only.txt b/examples/host/device_info/only.txt
index 133a7c9a0..61a08f68d 100644
--- a/examples/host/device_info/only.txt
+++ b/examples/host/device_info/only.txt
@@ -1,7 +1,4 @@
mcu:CH32V20X
-mcu:ESP32S2
-mcu:ESP32S3
-mcu:ESP32P4
mcu:KINETIS_KL
mcu:LPC175X_6X
mcu:LPC177X_8X
@@ -21,5 +18,6 @@ mcu:STM32F7
mcu:STM32H7
mcu:STM32H7RS
mcu:STM32N6
+family:espressif
family:samd21
family:samd5x_e5x
diff --git a/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt b/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt
index beabcad9c..2f529dd68 100644
--- a/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt
+++ b/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt
@@ -1,12 +1,12 @@
idf_build_get_property(target IDF_TARGET)
+include(CMakePrintHelpers)
-set(srcs)
-set(includes_public)
-set(compile_options)
-set(tusb_src "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src")
+set(tusb_src ${CMAKE_CURRENT_LIST_DIR}/../../../../../src)
+get_filename_component(tusb_src ${tusb_src} ABSOLUTE)
+include(${tusb_src}/CMakeLists.txt)
string(TOUPPER OPT_MCU_${target} tusb_mcu)
-list(APPEND compile_definitions
+set(compile_definitions
CFG_TUSB_MCU=${tusb_mcu}
CFG_TUSB_OS=OPT_OS_FREERTOS
BOARD_TUD_RHPORT=${RHPORT_DEVICE}
@@ -23,36 +23,11 @@ if (target STREQUAL esp32p4)
)
endif ()
+tinyusb_sources_get(srcs)
list(APPEND srcs
- # common
- ${tusb_src}/tusb.c
- ${tusb_src}/common/tusb_fifo.c
- # device
- ${tusb_src}/device/usbd.c
- ${tusb_src}/device/usbd_control.c
- ${tusb_src}/class/audio/audio_device.c
- ${tusb_src}/class/cdc/cdc_device.c
- ${tusb_src}/class/dfu/dfu_device.c
- ${tusb_src}/class/dfu/dfu_rt_device.c
- ${tusb_src}/class/hid/hid_device.c
- ${tusb_src}/class/midi/midi_device.c
- ${tusb_src}/class/msc/msc_device.c
- ${tusb_src}/class/mtp/mtp_device.c
- ${tusb_src}/class/net/ecm_rndis_device.c
- ${tusb_src}/class/net/ncm_device.c
- ${tusb_src}/class/usbtmc/usbtmc_device.c
- ${tusb_src}/class/vendor/vendor_device.c
- ${tusb_src}/class/video/video_device.c
${tusb_src}/portable/synopsys/dwc2/dcd_dwc2.c
${tusb_src}/portable/synopsys/dwc2/hcd_dwc2.c
${tusb_src}/portable/synopsys/dwc2/dwc2_common.c
- # host
- ${tusb_src}/host/usbh.c
- ${tusb_src}/host/hub.c
- ${tusb_src}/class/cdc/cdc_host.c
- ${tusb_src}/class/hid/hid_host.c
- ${tusb_src}/class/msc/msc_host.c
- ${tusb_src}/class/vendor/vendor_host.c
)
# use max3421 as host controller
@@ -74,7 +49,6 @@ if(DEFINED CFLAGS_CLI)
list(APPEND compile_definitions ${CFLAGS_CLI})
endif()
-
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${tusb_src}
REQUIRES src
@@ -82,4 +56,3 @@ idf_component_register(SRCS ${srcs}
)
target_compile_definitions(${COMPONENT_LIB} PUBLIC ${compile_definitions})
-target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=format)
diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake
index c2e7bf8f2..ad68957df 100644
--- a/hw/bsp/family_support.cmake
+++ b/hw/bsp/family_support.cmake
@@ -12,7 +12,7 @@ set(UF2CONV_PY ${TOP}/tools/uf2/utils/uf2conv.py)
#-------------------------------------------------------------
# Toolchain
-# Can be changed via -DTOOLCHAIN=gcc|iar or -DCMAKE_C_COMPILER=
+# Can be changed via -DTOOLCHAIN=gcc|iar or -DCMAKE_C_COMPILER= or ENV{CC}=
#-------------------------------------------------------------
function(detect_compiler COMPILER_PATH RESULT)
string(FIND ${COMPILER_PATH} "iccarm" IS_IAR)
@@ -319,8 +319,8 @@ endfunction()
# Add tinyusb to target
function(family_add_tinyusb TARGET OPT_MCU)
- # tinyusb's CMakeList.txt
- add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
+ # tinyusb's CMakeLists.txt
+ include(${TOP}/src/CMakeLists.txt)
# Add TinyUSB sources, include and common define
tinyusb_target_add(${TARGET})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 951683104..48dc75e50 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.20)
-# Add tinyusb to a existing target, DCD and HCD drivers are not included
-function(tinyusb_target_add TARGET)
- target_sources(${TARGET} PRIVATE
+# Get TinyUSB sources. Note: DCD and HCD drivers are not included
+function(tinyusb_sources_get OUTPUT_VAR)
+ set(${OUTPUT_VAR}
# common
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/tusb.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/common/tusb_fifo.c
@@ -32,7 +32,14 @@ function(tinyusb_target_add TARGET)
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/class/vendor/vendor_host.c
# typec
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/typec/usbc.c
+ PARENT_SCOPE
)
+endfunction()
+
+# Add tinyusb to a existing target
+function(tinyusb_target_add TARGET)
+ tinyusb_sources_get(TINYUSB_SRC)
+ target_sources(${TARGET} PRIVATE ${TINYUSB_SRC})
target_include_directories(${TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
# TODO for net driver, should be removed/changed
diff --git a/src/portable/synopsys/dwc2/dcd_dwc2.c b/src/portable/synopsys/dwc2/dcd_dwc2.c
index b2531426a..06579fbb3 100644
--- a/src/portable/synopsys/dwc2/dcd_dwc2.c
+++ b/src/portable/synopsys/dwc2/dcd_dwc2.c
@@ -1050,7 +1050,6 @@ static void handle_ep_irq(uint8_t rhport, uint8_t dir) {
Note: when OTG_MULTI_PROC_INTRPT = 1, Device Each endpoint interrupt deachint/deachmsk/diepeachmsk/doepeachmsk
are combined to generate dedicated interrupt line for each endpoint.
*/
-//-V::2584::{gintsts} PVS-Studio suppression
void dcd_int_handler(uint8_t rhport) {
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
const uint32_t gintmask = dwc2->gintmsk;
diff --git a/src/portable/synopsys/dwc2/dwc2_common.c b/src/portable/synopsys/dwc2/dwc2_common.c
index 5ff18ab94..980574e12 100644
--- a/src/portable/synopsys/dwc2/dwc2_common.c
+++ b/src/portable/synopsys/dwc2/dwc2_common.c
@@ -29,16 +29,6 @@
#define DWC2_COMMON_DEBUG 2
#if defined(TUP_USBIP_DWC2) && (CFG_TUH_ENABLED || CFG_TUD_ENABLED)
-
-#if CFG_TUD_ENABLED
-#include "device/dcd.h"
-#endif
-
-#if CFG_TUH_ENABLED
-#include "host/hcd.h"
-#include "host/usbh.h"
-#endif
-
#include "dwc2_common.h"
//--------------------------------------------------------------------
diff --git a/src/portable/synopsys/dwc2/dwc2_common.h b/src/portable/synopsys/dwc2/dwc2_common.h
index 0166b0261..dc204f578 100644
--- a/src/portable/synopsys/dwc2/dwc2_common.h
+++ b/src/portable/synopsys/dwc2/dwc2_common.h
@@ -30,6 +30,14 @@
#include "common/tusb_common.h"
#include "dwc2_type.h"
+#if CFG_TUD_ENABLED
+#include "device/dcd.h"
+#endif
+
+#if CFG_TUH_ENABLED
+#include "host/hcd.h"
+#endif
+
// Following symbols must be defined by port header
// - _dwc2_controller[]: array of controllers
// - DWC2_EP_MAX: largest EP counts of all controllers