diff --git a/.github/workflows/build_and_run_test_app_usb.yml b/.github/workflows/build_and_run_test_app_usb.yml index 0d0629cc..b2bbdfa6 100644 --- a/.github/workflows/build_and_run_test_app_usb.yml +++ b/.github/workflows/build_and_run_test_app_usb.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - idf_ver: ["release-v5.0", "release-v5.1", "release-v5.2", "latest"] + idf_ver: ["release-v4.4", "release-v5.0", "release-v5.1", "release-v5.2", "latest"] runs-on: ubuntu-20.04 container: espressif/idf:${{ matrix.idf_ver }} steps: diff --git a/device/esp_tinyusb/test_app/CMakeLists.txt b/device/esp_tinyusb/test_app/CMakeLists.txt index 3ac869f1..2faba3ed 100644 --- a/device/esp_tinyusb/test_app/CMakeLists.txt +++ b/device/esp_tinyusb/test_app/CMakeLists.txt @@ -2,4 +2,14 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +# Set the components to include the tests for. +set(TEST_COMPONENTS) +set(EXTRA_COMPONENT_DIRS) + +if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") + list(APPEND EXTRA_COMPONENT_DIRS ../) + list(APPEND TEST_COMPONENTS "esp_tinyusb") +endif() + project(test_app_usb_device_esp_tinyusb) diff --git a/device/esp_tinyusb/test_app/main/CMakeLists.txt b/device/esp_tinyusb/test_app/main/CMakeLists.txt index 02fd48c9..caa61dd1 100644 --- a/device/esp_tinyusb/test_app/main/CMakeLists.txt +++ b/device/esp_tinyusb/test_app/main/CMakeLists.txt @@ -1,4 +1,26 @@ +include($ENV{IDF_PATH}/tools/cmake/version.cmake) +set (TINYUSB_LIB) +if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") + set(TINYUSB_LIB "esp_tinyusb") +else() + set(TINYUSB_LIB "tinyusb") +endif() + +# TODO: once IDF_v4.4 is at the EOL support, use WHOLE_ARCHIVE idf_component_register(SRCS "test_esp_tinyusb.c" "test_bvalid_sig.c" "test_app_main.c" INCLUDE_DIRS "." - REQUIRES unity esp_tinyusb - WHOLE_ARCHIVE) + REQUIRES unity ${TINYUSB_LIB}) + +# In order for the cases defined by `TEST_CASE` to be linked into the final elf, +# the component can be registered as WHOLE_ARCHIVE + +# Due to the backward compatibility to IDFv4.4 (in which WHOLE_ARCHIVE is not implemented) we use following approach: +# Any non-static function from test_app/main/*.c (apart from test_app_main.c) file is added as an undefined symbol +# because otherwise the linker will ignore test_app/main/*.c as it has no other files depending on any +# symbols in it. + +# force-link test_bvalid_sig.c +set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-u tud_mount_cb") +# force-link test_esp_tinyusb.c - void function linker_hook created because: +# no non-static function, no dependency to already force-linked test_bvalid_sig.c +set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-u linker_hook") diff --git a/device/esp_tinyusb/test_app/main/test_esp_tinyusb.c b/device/esp_tinyusb/test_app/main/test_esp_tinyusb.c index de8a7ea6..b71d4870 100644 --- a/device/esp_tinyusb/test_app/main/test_esp_tinyusb.c +++ b/device/esp_tinyusb/test_app/main/test_esp_tinyusb.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -22,6 +22,9 @@ #define VFS_PATH "/dev/usb-cdc1" +// idf_component_register(WHOLE_ARCHIVE) backward compatibility to IDF_v4.4 +void linker_hook(void) {}; + static const tusb_desc_device_t cdc_device_descriptor = { .bLength = sizeof(cdc_device_descriptor), .bDescriptorType = TUSB_DESC_DEVICE, diff --git a/host/class/cdc/usb_host_cdc_acm/test_app/main/CMakeLists.txt b/host/class/cdc/usb_host_cdc_acm/test_app/main/CMakeLists.txt index 1c29af0e..24599850 100644 --- a/host/class/cdc/usb_host_cdc_acm/test_app/main/CMakeLists.txt +++ b/host/class/cdc/usb_host_cdc_acm/test_app/main/CMakeLists.txt @@ -6,9 +6,18 @@ else() set(TINYUSB_LIB "tinyusb") endif() -# In order for the cases defined by `TEST_CASE` to be linked into the final elf, -# the component can be registered as WHOLE_ARCHIVE +# TODO: once IDF_v4.4 is at the EOL support, use WHOLE_ARCHIVE idf_component_register(SRCS "test_cdc_acm_host.c" "usb_device.c" "test_app_main.c" INCLUDE_DIRS "." - REQUIRES usb_host_cdc_acm unity ${TINYUSB_LIB} - WHOLE_ARCHIVE) + REQUIRES usb_host_cdc_acm unity ${TINYUSB_LIB}) + +# In order for the cases defined by `TEST_CASE` to be linked into the final elf, +# the component can be registered as WHOLE_ARCHIVE + +# Due to the backward compatibility to IDFv4.4 (in which WHOLE_ARCHIVE is not implemented) we use following approach: +# Any non-static function test_app/main/*.c (apart from test_app_main.c) file is added as an undefined symbol +# because otherwise the linker will ignore test_app/main/*.c as it has no other files depending on any +# symbols in it. + +# force-link test_cdc_acm_host.c +set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-u usb_lib_task") \ No newline at end of file diff --git a/host/class/hid/usb_host_hid/test_app/main/CMakeLists.txt b/host/class/hid/usb_host_hid/test_app/main/CMakeLists.txt index 3f90214f..00e10eca 100644 --- a/host/class/hid/usb_host_hid/test_app/main/CMakeLists.txt +++ b/host/class/hid/usb_host_hid/test_app/main/CMakeLists.txt @@ -6,9 +6,20 @@ else() set(TINYUSB_LIB "tinyusb") endif() -# In order for the cases defined by `TEST_CASE` to be linked into the final elf, -# the component can be registered as WHOLE_ARCHIVE +# TODO: once IDF_v4.4 is at the EOL support, use WHOLE_ARCHIVE idf_component_register(SRC_DIRS . INCLUDE_DIRS . - REQUIRES unity usb usb_host_hid ${TINYUSB_LIB} - WHOLE_ARCHIVE) + REQUIRES unity usb usb_host_hid ${TINYUSB_LIB}) + +# In order for the cases defined by `TEST_CASE` to be linked into the final elf, +# the component can be registered as WHOLE_ARCHIVE + +# Due to the backward compatibility to IDFv4.4 (in which WHOLE_ARCHIVE is not implemented) we use following approach: +# Any non-static function test_app/main/*.c (apart from test_app_main.c) file is added as an undefined symbol +# because otherwise the linker will ignore test_app/main/*.c as it has no other files depending on any +# symbols in it. + +# force-link test_hid_basic.c +set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-u test_hid_setup") +# force-link test_hid_err_handling.c +set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-u test_interface_callback_handler") diff --git a/host/class/msc/usb_host_msc/test_app/main/CMakeLists.txt b/host/class/msc/usb_host_msc/test_app/main/CMakeLists.txt index 5fabfc35..e1d5d55a 100644 --- a/host/class/msc/usb_host_msc/test_app/main/CMakeLists.txt +++ b/host/class/msc/usb_host_msc/test_app/main/CMakeLists.txt @@ -6,9 +6,19 @@ else() set(TINYUSB_LIB "tinyusb") endif() -# In order for the cases defined by `TEST_CASE` to be linked into the final elf, -# the component can be registered as WHOLE_ARCHIVE +# TODO: once IDF_v4.4 is at the EOL support, use WHOLE_ARCHIVE idf_component_register(SRC_DIRS . INCLUDE_DIRS . - REQUIRES unity usb usb_host_msc ${TINYUSB_LIB} - WHOLE_ARCHIVE) + REQUIRES unity usb usb_host_msc ${TINYUSB_LIB}) + +# In order for the cases defined by `TEST_CASE` to be linked into the final elf, +# the component can be registered as WHOLE_ARCHIVE + +# Due to the backward compatibility to IDFv4.4 (in which WHOLE_ARCHIVE is not implemented) we use following approach: +# Any non-static function test_app/main/*.c (apart from test_app_main.c) file is added as an undefined symbol +# because otherwise the linker will ignore test_app/main/*.c as it has no other files depending on any +# symbols in it. + +# force-link test_msc.c - void function linker_hook created because: +# no non-static function +set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-u linker_hook") \ No newline at end of file diff --git a/host/class/msc/usb_host_msc/test_app/main/test_msc.c b/host/class/msc/usb_host_msc/test_app/main/test_msc.c index bdf4048f..05f03f6e 100644 --- a/host/class/msc/usb_host_msc/test_app/main/test_msc.c +++ b/host/class/msc/usb_host_msc/test_app/main/test_msc.c @@ -1,6 +1,6 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -19,6 +19,9 @@ #if SOC_USB_OTG_SUPPORTED +// idf_component_register(WHOLE_ARCHIVE) backward compatibility to IDF_v4.4 +void linker_hook(void) {}; + static const char *TAG = "APP"; #define ESP_OK_ASSERT(exp) TEST_ASSERT_EQUAL(ESP_OK, exp) diff --git a/host/class/uvc/usb_host_uvc/test_app/main/CMakeLists.txt b/host/class/uvc/usb_host_uvc/test_app/main/CMakeLists.txt index 4707f6fc..bf85849f 100644 --- a/host/class/uvc/usb_host_uvc/test_app/main/CMakeLists.txt +++ b/host/class/uvc/usb_host_uvc/test_app/main/CMakeLists.txt @@ -6,9 +6,19 @@ else() set(TINYUSB_LIB "tinyusb") endif() -# In order for the cases defined by `TEST_CASE` to be linked into the final elf, -# the component can be registered as WHOLE_ARCHIVE +# TODO: once IDF_v4.4 is at the EOL support, use WHOLE_ARCHIVE idf_component_register(SRCS "test_uvc.c" "libusb_parse.c" "test_app_main.c" INCLUDE_DIRS "." "../../private_include" - REQUIRES usb_host_uvc usb unity - WHOLE_ARCHIVE) + REQUIRES usb_host_uvc usb unity) + +# In order for the cases defined by `TEST_CASE` to be linked into the final elf, +# the component can be registered as WHOLE_ARCHIVE + +# Due to the backward compatibility to IDFv4.4 (in which WHOLE_ARCHIVE is not implemented) we use following approach: +# Any non-static function from test_app/main/*.c (apart from test_app_main.c) file is added as an undefined symbol +# because otherwise the linker will ignore test_app/main/*.c as it has no other files depending on any +# symbols in it. + +# force-link test_uvc.c - void function linker_hook created because: +# no non-static function +set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-u linker_hook") diff --git a/host/class/uvc/usb_host_uvc/test_app/main/test_uvc.c b/host/class/uvc/usb_host_uvc/test_app/main/test_uvc.c index c8f4ccbe..fac6b014 100644 --- a/host/class/uvc/usb_host_uvc/test_app/main/test_uvc.c +++ b/host/class/uvc/usb_host_uvc/test_app/main/test_uvc.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -28,6 +28,9 @@ int libusb_parse_configuration(struct libusb_config_descriptor *config, const uint8_t *buffer, int size); void libusb_clear_config_descriptor(struct libusb_config_descriptor *config); +// idf_component_register(WHOLE_ARCHIVE) backward compatibility to IDF_v4.4 +void linker_hook(void) {}; + const uint8_t CANYON_CNE_CWC2[] = { 0x09, 0x02, 0x7d, 0x02, 0x04, 0x01, 0x00, 0x80, 0xfa, 0x08, 0x0b, 0x00, 0x02, 0x0e, 0x03, 0x00, 0x05, 0x09, 0x04, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x00, 0x05, 0x0d, 0x24, 0x01, 0x00, 0x01, 0x4d,