Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(tinyusb): Run tinyusb tests in CI for esp32p4
Browse files Browse the repository at this point in the history
peter-marcisovsky committed Dec 3, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 3979c8f commit 38a1d37
Showing 4 changed files with 82 additions and 12 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/build_and_run_test_app_usb.yml
Original file line number Diff line number Diff line change
@@ -62,10 +62,6 @@ jobs:
- idf_ver: "release-v5.3" # TODO: enable IDF 5.3 once the docker image is updated
idf_target: "esp32p4"

# Exclude esp32p4 for all versions when using the usb_device runner
- idf_target: "esp32p4" # TODO: esp32p4 usb_device runner not built yet
runner_tag: "usb_device"

runs-on: [self-hosted, linux, docker, "${{ matrix.idf_target }}", "${{ matrix.runner_tag }}"]
container:
image: python:3.11-bookworm
Original file line number Diff line number Diff line change
@@ -58,6 +58,18 @@ static const tusb_desc_device_t test_device_descriptor = {
.bNumConfigurations = 0x01
};

static const tusb_desc_device_qualifier_t device_qualifier = {
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = 0x0200,
.bDeviceClass = TUSB_CLASS_MISC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
.bNumConfigurations = 0x01,
.bReserved = 0
};

void test_bvalid_sig_mount_cb(void)
{
dev_mounted++;
@@ -72,12 +84,20 @@ TEST_CASE("bvalid_signal", "[esp_tinyusb][usb_device]")
{
unsigned int rounds = DEVICE_DETACH_TEST_ROUNDS;

// Install TinyUSB driver
const tinyusb_config_t tusb_cfg = {
.external_phy = false,
.device_descriptor = &test_device_descriptor,
.string_descriptor = NULL,
.string_descriptor_count = 0,
.external_phy = false,
#if (TUD_OPT_HIGH_SPEED)
.fs_configuration_descriptor = test_configuration_descriptor,
.hs_configuration_descriptor = test_configuration_descriptor,
.qualifier_descriptor = &device_qualifier,
#else
.configuration_descriptor = test_configuration_descriptor,
#endif // TUD_OPT_HIGH_SPEED
};

TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));

dev_mounted = 0;
37 changes: 34 additions & 3 deletions device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_cdc.c
Original file line number Diff line number Diff line change
@@ -42,8 +42,25 @@ static const tusb_desc_device_t cdc_device_descriptor = {
static const uint16_t cdc_desc_config_len = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN;
static const uint8_t cdc_desc_configuration[] = {
TUD_CONFIG_DESCRIPTOR(1, 4, 0, cdc_desc_config_len, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
#if (TUD_OPT_HIGH_SPEED)
TUD_CDC_DESCRIPTOR(0, 4, 0x81, 8, 0x02, 0x82, 512),
TUD_CDC_DESCRIPTOR(2, 4, 0x83, 8, 0x04, 0x84, 512),
#else
TUD_CDC_DESCRIPTOR(0, 4, 0x81, 8, 0x02, 0x82, 64),
TUD_CDC_DESCRIPTOR(2, 4, 0x83, 8, 0x04, 0x84, 64),
#endif
};

static const tusb_desc_device_qualifier_t device_qualifier = {
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = 0x0200,
.bDeviceClass = TUSB_CLASS_MISC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
.bNumConfigurations = 0x01,
.bReserved = 0
};

static void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event)
@@ -64,12 +81,26 @@ static void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event)
*/
TEST_CASE("tinyusb_cdc", "[esp_tinyusb][cdc]")
{
// Install TinyUSB driver
const tinyusb_config_t tusb_cfg = {
.external_phy = false,
.device_descriptor = &cdc_device_descriptor,
.configuration_descriptor = cdc_desc_configuration
.string_descriptor = NULL,
.string_descriptor_count = 0,
.external_phy = false,
#if (TUD_OPT_HIGH_SPEED)
.fs_configuration_descriptor = cdc_desc_configuration,
.hs_configuration_descriptor = cdc_desc_configuration,
.qualifier_descriptor = &device_qualifier,
#else
.configuration_descriptor = cdc_desc_configuration,
#endif // TUD_OPT_HIGH_SPEED
};

// // Install TinyUSB driver
// const tinyusb_config_t tusb_cfg = {
// .external_phy = false,
// .device_descriptor = &cdc_device_descriptor,
// .configuration_descriptor = cdc_desc_configuration
// };
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));

tinyusb_config_cdcacm_t acm_cfg = {
Original file line number Diff line number Diff line change
@@ -29,16 +29,34 @@
// ========================= TinyUSB descriptors ===============================
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN)

static uint8_t const test_fs_configuration_descriptor[] = {
static const uint16_t cdc_desc_config_len = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN;
static const uint8_t test_fs_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),
TUD_CDC_DESCRIPTOR(0, 4, 0x81, 8, 0x02, 0x82, 64),
TUD_CDC_DESCRIPTOR(2, 4, 0x83, 8, 0x04, 0x84, 64),
};

#if (TUD_OPT_HIGH_SPEED)
static uint8_t const test_hs_configuration_descriptor[] = {
static const uint8_t test_hs_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),
TUD_CONFIG_DESCRIPTOR(1, 4, 0, cdc_desc_config_len, TUSB_DESC_CONFIG_ATT_SELF_POWERED | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
TUD_CDC_DESCRIPTOR(0, 4, 0x81, 8, 0x02, 0x82, 512),
TUD_CDC_DESCRIPTOR(2, 4, 0x83, 8, 0x04, 0x84, 512),
};

static const tusb_desc_device_qualifier_t device_qualifier = {
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = 0x0200,
.bDeviceClass = TUSB_CLASS_MISC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
.bNumConfigurations = 0x01,
.bReserved = 0
};

#endif // TUD_OPT_HIGH_SPEED

static const tusb_desc_device_t test_device_descriptor = {
@@ -136,6 +154,7 @@ TEST_CASE("descriptors_config_device", "[esp_tinyusb][usb_device]")
.configuration_descriptor = NULL,
#if (TUD_OPT_HIGH_SPEED)
.hs_configuration_descriptor = NULL,
.qualifier_descriptor = &device_qualifier,
#endif // TUD_OPT_HIGH_SPEED
};
// Install
@@ -158,6 +177,7 @@ TEST_CASE("descriptors_config_device_and_config", "[esp_tinyusb][usb_device]")
.configuration_descriptor = test_fs_configuration_descriptor,
#if (TUD_OPT_HIGH_SPEED)
.hs_configuration_descriptor = NULL,
.qualifier_descriptor = &device_qualifier,
#endif // TUD_OPT_HIGH_SPEED
};
// Install
@@ -180,6 +200,7 @@ TEST_CASE("descriptors_config_device_and_fs_config_only", "[esp_tinyusb][usb_dev
.device_descriptor = &test_device_descriptor,
.configuration_descriptor = test_fs_configuration_descriptor,
.hs_configuration_descriptor = NULL,
.qualifier_descriptor = &device_qualifier,
};
// Install
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));
@@ -200,6 +221,7 @@ TEST_CASE("descriptors_config_device_and_hs_config_only", "[esp_tinyusb][usb_dev
.device_descriptor = &test_device_descriptor,
.configuration_descriptor = NULL,
.hs_configuration_descriptor = test_hs_configuration_descriptor,
.qualifier_descriptor = &device_qualifier,
};
// Install
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));
@@ -220,6 +242,7 @@ TEST_CASE("descriptors_config_all_configured", "[esp_tinyusb][usb_device]")
.device_descriptor = &test_device_descriptor,
.fs_configuration_descriptor = test_fs_configuration_descriptor,
.hs_configuration_descriptor = test_hs_configuration_descriptor,
.qualifier_descriptor = &device_qualifier,
};
// Install
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));

0 comments on commit 38a1d37

Please sign in to comment.