Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change(dconn_test): Added esp32p4 to CI #112

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -22,8 +22,11 @@
#include "tinyusb.h"
#include "tusb_tasks.h"

#define DEVICE_DETACH_TEST_ROUNDS 10
#define DEVICE_DETACH_ROUND_DELAY_MS 1000
static const char *TAG = "dconn_detection";

#define DEVICE_DETACH_TEST_ROUNDS 10
#define DEVICE_DETACH_ROUND_DELAY_MS 10
#define TEARDOWN_DEVICE_ATTACH_TIMEOUT_MS 1000

#if (CONFIG_IDF_TARGET_ESP32P4)
#define USB_SRP_BVALID_IN_IDX USB_SRP_BVALID_PAD_IN_IDX
Expand All @@ -33,9 +36,11 @@
********************************************************************* */
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN)

SemaphoreHandle_t wait_dev_stage_change = NULL;
static unsigned int dev_mounted = 0;
static unsigned int dev_umounted = 0;


static uint8_t const test_configuration_descriptor[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, 0, 0, TUSB_DESC_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_SELF_POWERED | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
Expand Down Expand Up @@ -82,15 +87,17 @@ void tud_mount_cb(void)
* However, Windows issues SetConfiguration only after a USB driver was assigned to the device.
* So in case you are implementing a Vendor Specific class, or your device has 0 interfaces, this callback is not issued on Windows host.
*/
printf("%s\n", __FUNCTION__);
ESP_LOGD(TAG, "%s", __FUNCTION__);
dev_mounted++;
xSemaphoreGive(wait_dev_stage_change);
}

// Invoked when device is unmounted
void tud_umount_cb(void)
{
printf("%s\n", __FUNCTION__);
ESP_LOGD(TAG, "%s", __FUNCTION__);
dev_umounted++;
xSemaphoreGive(wait_dev_stage_change);
}

/**
Expand All @@ -114,7 +121,7 @@ void tud_umount_cb(void)
*/
TEST_CASE("dconn_detection", "[esp_tinyusb][dconn]")
{
unsigned int rounds = DEVICE_DETACH_TEST_ROUNDS;
wait_dev_stage_change = xSemaphoreCreateBinary();

// Install TinyUSB driver
const tinyusb_config_t tusb_cfg = {
Expand All @@ -129,27 +136,35 @@ TEST_CASE("dconn_detection", "[esp_tinyusb][dconn]")
#else
.configuration_descriptor = test_configuration_descriptor,
#endif // TUD_OPT_HIGH_SPEED
.self_powered = true,
.vbus_monitor_io = 0, // Doesn't matter in the current test scenario, as the connection and disconnection events are emulated by multiplexing bvalid signal
};

TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));
TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreTake(wait_dev_stage_change, pdMS_TO_TICKS(TEARDOWN_DEVICE_ATTACH_TIMEOUT_MS)));

//

unsigned int rounds = DEVICE_DETACH_TEST_ROUNDS;
dev_mounted = 0;
dev_umounted = 0;

while (rounds--) {
// LOW to emulate disconnect USB device
// HIGH to emulate disconnect USB device
ESP_LOGD(TAG, "bvalid(0)");
esp_rom_gpio_connect_in_signal(GPIO_MATRIX_CONST_ZERO_INPUT, USB_SRP_BVALID_IN_IDX, false);
vTaskDelay(pdMS_TO_TICKS(DEVICE_DETACH_ROUND_DELAY_MS));
TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreTake(wait_dev_stage_change, pdMS_TO_TICKS(TEARDOWN_DEVICE_ATTACH_TIMEOUT_MS)));
// HIGH to emulate connect USB device
ESP_LOGD(TAG, "bvalid(1)");
esp_rom_gpio_connect_in_signal(GPIO_MATRIX_CONST_ONE_INPUT, USB_SRP_BVALID_IN_IDX, false);
vTaskDelay(pdMS_TO_TICKS(DEVICE_DETACH_ROUND_DELAY_MS));
TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreTake(wait_dev_stage_change, pdMS_TO_TICKS(TEARDOWN_DEVICE_ATTACH_TIMEOUT_MS)));
}
// Cleanup
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());

// Verify
// Verify test results
TEST_ASSERT_EQUAL(dev_umounted, dev_mounted);
TEST_ASSERT_EQUAL(DEVICE_DETACH_TEST_ROUNDS, dev_mounted);

// Cleanup
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());
}
#endif // SOC_USB_OTG_SUPPORTED
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.esp32p4
#@pytest.mark.usb_device Disable in CI: unavailable teardown for P4
@pytest.mark.esp32p4
@pytest.mark.temp_skip_ci(targets=['esp32p4'], reason='P4 conn/dconn emulation has not been implmented')
@pytest.mark.usb_device
def test_usb_device_dconn_detection(dut: IdfDut) -> None:
dut.run_all_single_board_cases(group='dconn')
Loading