Merge branch 'refactor/usb_host_test_ext_hub_prereq' into 'master'

refactor(test_apps): Moved usb phy and hcd  to common folder

See merge request espressif/esp-idf!37551
This commit is contained in:
Roman Leonov
2025-03-27 18:22:25 +08:00
19 changed files with 79 additions and 138 deletions

View File

@@ -2,5 +2,9 @@ idf_component_register(SRCS "dev_hid.c"
"dev_isoc.c"
"dev_msc.c"
"mock_msc.c"
INCLUDE_DIRS "."
"phy_common.c"
"hcd_common.c"
INCLUDE_DIRS
"../../private_include" # hcd and urb
"."
REQUIRES usb unity)

View File

@@ -0,0 +1,26 @@
menu "USB PHY Test"
depends on IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps"
config USB_PHY_TEST_OTG_DRVVBUS_ENABLE
bool "Enable driving VBUS by an internal DRVVBUS signal"
default n
help
USB-OTG peripheral features a DRVVBUS signal, which controls the VBUS voltage. The DRVVBUS signal can be
either internally connected to a PHY (if a PHY supports it), in such a case the PHY would be controlling
the VBUS voltage by itself. Or the DRVVBUS can be handled by an external logic (a transistor switch).
Our PHY does not support the DRVVBUS signal, thus we must use an external logic to control the VBUS
voltage. The DRVVBUS signal is controlled via HCD_PORT_CMD_POWER_OFF and HCD_PORT_CMD_POWER_ON
config USB_PHY_TEST_OTG_DRVVBUS_GPIO
depends on USB_PHY_TEST_OTG_DRVVBUS_ENABLE
int "Connect a GPIO to the internal DRVVBUS signal"
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
default 1
help
GPIO number, that will be internally connected to the DRVVBUS signal.
USB Host CI target runners feature an external power switch controlled by this GPIO, to control the VBUS
voltage of USB devices during test.
endmenu

View File

@@ -14,12 +14,12 @@
#include "esp_err.h"
#include "esp_attr.h"
#include "esp_rom_gpio.h"
#include "hcd.h"
#include "usb_private.h"
#include "usb/usb_types_ch9.h"
#include "esp_private/usb_phy.h"
#include "test_hcd_common.h"
#include "hcd_common.h"
#include "mock_msc.h"
#include "phy_common.h"
#include "unity.h"
#include "sdkconfig.h"
@@ -28,11 +28,6 @@
#define ENUM_ADDR 1 // Device address to use for tests that enumerate the device
#define ENUM_CONFIG 1 // Device configuration number to use for tests that enumerate the device
#ifdef CONFIG_USB_HCD_TEST_OTG_DRVVBUS_ENABLE
#define OTG_DRVVBUS_ENABLE
#define OTG_DRVVBUS_GPIO CONFIG_USB_HCD_TEST_OTG_DRVVBUS_GPIO
#endif
typedef struct {
hcd_port_handle_t port_hdl;
hcd_port_event_t port_event;
@@ -44,7 +39,6 @@ typedef struct {
} pipe_event_msg_t;
hcd_port_handle_t port_hdl = NULL;
static usb_phy_handle_t phy_hdl = NULL;
// ---------------------------------------------------- Private --------------------------------------------------------
@@ -151,43 +145,8 @@ int test_hcd_get_num_pipe_events(hcd_pipe_handle_t pipe_hdl)
hcd_port_handle_t test_hcd_setup(void)
{
// Deinitialize PHY from previous failed test
if (phy_hdl != NULL) {
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, usb_del_phy(phy_hdl), "Failed to delete PHY");
phy_hdl = NULL;
}
// Initialize the internal USB PHY to connect to the USB OTG peripheral
usb_phy_config_t phy_config = {
.controller = USB_PHY_CTRL_OTG,
#if CONFIG_IDF_TARGET_ESP32P4 // ESP32-P4 has 2 USB-DWC peripherals, each with its dedicated PHY. We support HS+UTMI only ATM.
.target = USB_PHY_TARGET_UTMI,
#else
.target = USB_PHY_TARGET_INT,
#endif
.otg_mode = USB_OTG_MODE_HOST,
.otg_speed = USB_PHY_SPEED_UNDEFINED, // In Host mode, the speed is determined by the connected device
.ext_io_conf = NULL,
.otg_io_conf = NULL,
};
test_setup_usb_phy();
#ifdef OTG_DRVVBUS_ENABLE
const usb_phy_otg_io_conf_t otg_io_conf = {
.iddig_io_num = -1,
.avalid_io_num = -1,
.vbusvalid_io_num = -1,
.idpullup_io_num = -1,
.dppulldown_io_num = -1,
.dmpulldown_io_num = -1,
.drvvbus_io_num = OTG_DRVVBUS_GPIO,
.bvalid_io_num = -1,
.sessend_io_num = -1,
.chrgvbus_io_num = -1,
.dischrgvbus_io_num = -1
};
phy_config.otg_io_conf = &otg_io_conf;
#endif // OTG_DRVVBUS_ENABLE
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, usb_new_phy(&phy_config, &phy_hdl), "Failed to init USB PHY");
// Create a queue for port callback to queue up port events
QueueHandle_t port_evt_queue = xQueueCreate(EVENT_QUEUE_LEN, sizeof(port_event_msg_t));
TEST_ASSERT_NOT_NULL(port_evt_queue);
@@ -223,8 +182,7 @@ void test_hcd_teardown(hcd_port_handle_t port_hdl)
TEST_ASSERT_EQUAL(ESP_OK, hcd_uninstall());
vQueueDelete(port_evt_queue);
// Deinitialize the internal USB PHY
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, usb_del_phy(phy_hdl), "Failed to delete PHY");
phy_hdl = NULL;
test_delete_usb_phy();
}
usb_speed_t test_hcd_wait_for_conn(hcd_port_handle_t port_hdl)

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

View File

@@ -9,18 +9,18 @@
#include "esp_err.h"
#include "usb/usb_types_ch9.h"
#include "esp_private/usb_phy.h"
#include "test_usb_host_common.h"
#include "phy_common.h"
#include "unity.h"
#include "sdkconfig.h"
#ifdef CONFIG_USB_HOST_TEST_OTG_DRVVBUS_ENABLE
#ifdef CONFIG_USB_PHY_TEST_OTG_DRVVBUS_ENABLE
#define OTG_DRVVBUS_ENABLE
#define OTG_DRVVBUS_GPIO CONFIG_USB_HOST_TEST_OTG_DRVVBUS_GPIO
#define OTG_DRVVBUS_GPIO CONFIG_USB_PHY_TEST_OTG_DRVVBUS_GPIO
#endif
static usb_phy_handle_t phy_hdl = NULL;
void test_usb_host_setup_phy(void)
void test_setup_usb_phy(void)
{
// Deinitialize PHY from previous failed test
if (phy_hdl != NULL) {
@@ -62,7 +62,7 @@ void test_usb_host_setup_phy(void)
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, usb_new_phy(&phy_config, &phy_hdl), "Failed to init USB PHY");
}
void test_usb_host_delete_phy(void)
void test_delete_usb_phy(void)
{
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, usb_del_phy(phy_hdl), "Failed to delete PHY");
phy_hdl = NULL;

View File

@@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @brief Install USB PHY separately from the usb_host_install()
*/
void test_setup_usb_phy(void);
/**
* @brief Uninstall PHY
*/
void test_delete_usb_phy(void);

View File

@@ -1,6 +1,6 @@
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
# the component can be registered as WHOLE_ARCHIVE
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "../../../private_include" "."
PRIV_INCLUDE_DIRS "."
REQUIRES usb unity common esp_mm
WHOLE_ARCHIVE)

View File

@@ -1,26 +1 @@
menu "USB HCD Test"
orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps"
config USB_HCD_TEST_OTG_DRVVBUS_ENABLE
depends on IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
bool "Enable driving VBUS by an internal DRVVBUS signal from USB-OTG peripheral"
default n
help
USB-OTG peripheral features a DRVVBUS signal, which controls the VBUS voltage. The DRVVBUS signal can be
either internally connected to a PHY (if a PHY supports it), in such a case the PHY would be controlling
the VBUS voltage by itself. Or the DRVVBUS can be handled by an external logic (a transistor switch).
Our PHY does not support the DRVVBUS signal, thus we must use an external logic to control the VBUS
voltage. The DRVVBUS signal is controlled via HCD_PORT_CMD_POWER_OFF and HCD_PORT_CMD_POWER_ON
config USB_HCD_TEST_OTG_DRVVBUS_GPIO
depends on USB_HCD_TEST_OTG_DRVVBUS_ENABLE
int "Connect a GPIO to the internal DRVVBUS signal"
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
default 1
help
GPIO number, that will be internally connected to the DRVVBUS signal.
USB Host CI target runners feature an external power switch controlled by this GPIO, to control the VBUS
voltage of USB devices during test.
endmenu
source "$IDF_PATH/components/usb/test_apps/common/Kconfig.common"

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
@@ -11,7 +11,7 @@
#include "freertos/task.h"
#include "dev_msc.h"
#include "dev_hid.h"
#include "test_hcd_common.h"
#include "hcd_common.h"
void setUp(void)
{

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -11,7 +11,7 @@
#include "unity.h"
#include "mock_msc.h"
#include "dev_msc.h"
#include "test_hcd_common.h"
#include "hcd_common.h"
// --------------------------------------------------- Test Cases ------------------------------------------------------

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -8,7 +8,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "unity.h"
#include "test_hcd_common.h"
#include "hcd_common.h"
#define TEST_DEV_ADDR 0
#define NUM_URBS 3

View File

@@ -9,7 +9,7 @@
#include "freertos/semphr.h"
#include "unity.h"
#include "dev_hid.h"
#include "test_hcd_common.h"
#include "hcd_common.h"
// --------------------------------------------------- Test Cases ------------------------------------------------------

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -12,7 +12,7 @@
#include "unity.h"
#include "dev_isoc.h"
#include "usb/usb_types_ch9.h"
#include "test_hcd_common.h"
#include "hcd_common.h"
#define NUM_URBS 3
#define NUM_PACKETS_PER_URB 3

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -9,7 +9,7 @@
#include "freertos/semphr.h"
#include "unity.h"
#include "esp_rom_sys.h"
#include "test_hcd_common.h"
#include "hcd_common.h"
#define TEST_DEV_ADDR 0
#define NUM_URBS 3

View File

@@ -1,5 +1,5 @@
# Use external power switch to control USB device's power
# switch is controlled by GPIO 21
CONFIG_USB_HCD_TEST_OTG_DRVVBUS_ENABLE=y
CONFIG_USB_HCD_TEST_OTG_DRVVBUS_GPIO=21
CONFIG_USB_PHY_TEST_OTG_DRVVBUS_ENABLE=y
CONFIG_USB_PHY_TEST_OTG_DRVVBUS_GPIO=21

View File

@@ -1,7 +1,6 @@
source "$IDF_PATH/components/usb/test_apps/common/Kconfig.common"
menu "USB Host Library Test"
orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps"
config USB_HOST_TEST_CHECK_MANU_STR
bool "Check manufacturer string descriptor"
default y
@@ -23,25 +22,4 @@ menu "USB Host Library Test"
USB Host tests that check string descriptors will check the serial string descriptor
of the connected device.
config USB_HOST_TEST_OTG_DRVVBUS_ENABLE
depends on IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
bool "Enable driving VBUS by an internal DRVVBUS signal from USB-OTG peripheral"
default n
help
USB-OTG peripheral features a DRVVBUS signal, which controls the VBUS voltage. The DRVVBUS signal can be
either internally connected to a PHY (if a PHY supports it), in such a case the PHY would be controlling
the VBUS voltage by itself. Or the DRVVBUS can be handled by an external logic (a transistor switch).
Our PHY does not support the DRVVBUS signal, thus we must use an external logic to control the VBUS
voltage. The DRVVBUS signal is controlled via HCD_PORT_CMD_POWER_OFF and HCD_PORT_CMD_POWER_ON
config USB_HOST_TEST_OTG_DRVVBUS_GPIO
depends on USB_HOST_TEST_OTG_DRVVBUS_ENABLE
int "Connect a GPIO to the internal DRVVBUS signal"
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
default 1
help
GPIO number, that will be internally connected to the DRVVBUS signal.
USB Host CI target runners feature an external power switch controlled by this GPIO, to control the VBUS
voltage of USB devices during test.
endmenu

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
@@ -10,7 +10,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "dev_msc.h"
#include "test_usb_host_common.h"
#include "phy_common.h"
#include "usb/usb_host.h"
void setUp(void)
@@ -18,7 +18,7 @@ void setUp(void)
unity_utils_record_free_mem();
dev_msc_init();
// Install PHY separately
test_usb_host_setup_phy();
test_setup_usb_phy();
// Install USB Host
usb_host_config_t host_config = {
.skip_phy_setup = true,
@@ -36,7 +36,7 @@ void tearDown(void)
// Clean up USB Host
printf("USB Host uninstall\n");
ESP_ERROR_CHECK(usb_host_uninstall());
test_usb_host_delete_phy();
test_delete_usb_phy();
// Short delay to allow task to be cleaned up after client uninstall
vTaskDelay(10);
unity_utils_evaluate_leaks();

View File

@@ -1,15 +0,0 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @brief Install PHY separately from the usb_host_install()
*/
void test_usb_host_setup_phy(void);
/**
* @brief Uninstall PHY
*/
void test_usb_host_delete_phy(void);

View File

@@ -1,5 +1,5 @@
# Use external power switch to control USB device's power
# switch is controlled by GPIO 21
CONFIG_USB_HOST_TEST_OTG_DRVVBUS_ENABLE=y
CONFIG_USB_HOST_TEST_OTG_DRVVBUS_GPIO=21
CONFIG_USB_PHY_TEST_OTG_DRVVBUS_ENABLE=y
CONFIG_USB_PHY_TEST_OTG_DRVVBUS_GPIO=21