Skip to content

Commit 86f222d

Browse files
committed
refactor(esp_tinyusb): runtime_config test applicaton
- Fixed concurrent access in the multitask access test - Added README.md
1 parent 63a4825 commit 86f222d

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
| Supported Targets | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2+
| ----------------- | -------- | -------- | -------- | -------- |
3+
4+
# Espressif's Additions to TinyUSB - Runtime Configuration Test Application
5+
6+
This directory contains Unity tests that validate Espressif-specific integration of TinyUSB.
7+
8+
The tests focus on:
9+
10+
- TinyUSB configuration helpers (default macros, per-port config).
11+
- USB Device descriptors (FS/HS, string descriptors, edge cases).
12+
- USB peripheral / PHY configuration for full-speed and high-speed.
13+
- TinyUSB task configuration (CPU pinning, invalid parameters).
14+
- Multitask access to the TinyUSB driver (concurrent installs).
15+
16+
The test prints a numbered menu, for example:
17+
18+
```
19+
(1) "Config: Default macros arguments" [runtime_config][default]
20+
(2) "Config: Full-speed (High-speed)" [runtime_config][full_speed]
21+
...
22+
```
23+
24+
You can run all tests by running `pytest` or select individual ones by name and number.
25+
26+
## Tags
27+
28+
Each test is tagged with categories and modes:
29+
30+
### Categories
31+
32+
- [runtime_config] – Tests focusing on `tinyusb_config_t` and runtime configuration.
33+
- [periph] – Tests that directly exercise the USB peripheral (USB OTG 1.1 or USB OTG 2.0).
34+
- [task] – Tests related to the dedicated TinyUSB task configuration.
35+
36+
### Speed / Mode
37+
38+
- [default] – Generic, target-agnostic.
39+
- [full_speed] – Tests specific to USB OTG 1.1 / Full-speed port.
40+
- [high_speed] – Tests specific to USB OTG 2.0 / High-speed port.
41+
42+
These tags can be used by test runners / CI to select or filter tests.

device/esp_tinyusb/test_apps/runtime_config/main/test_multitask_access.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
#define MULTIPLE_THREADS_TASKS_NUM 5
3131

32-
static int nb_of_success = 0;
32+
// Unlocked spinlock, ready to use
33+
static portMUX_TYPE _spinlock = portMUX_INITIALIZER_UNLOCKED;
34+
static volatile int nb_of_success = 0;
3335

3436
static void test_task_install(void *arg)
3537
{
@@ -42,7 +44,9 @@ static void test_task_install(void *arg)
4244
if (tinyusb_driver_install(&tusb_cfg) == ESP_OK) {
4345
test_device_wait();
4446
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());
47+
taskENTER_CRITICAL(&_spinlock);
4548
nb_of_success++;
49+
taskEXIT_CRITICAL(&_spinlock);
4650
}
4751

4852
// Notify the parent task that the task completed the job
@@ -70,19 +74,20 @@ TEST_CASE("Multitask: Install", "[runtime_config][full_speed][high_speed]")
7074
};
7175
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, usb_new_phy(&phy_conf, &phy_hdl), "Unable to install USB PHY ");
7276

77+
taskENTER_CRITICAL(&_spinlock);
7378
nb_of_success = 0;
79+
taskEXIT_CRITICAL(&_spinlock);
7480
// Create tasks that will start the driver
7581
for (int i = 0; i < MULTIPLE_THREADS_TASKS_NUM; i++) {
76-
TEST_ASSERT_EQUAL(pdTRUE, xTaskCreate(test_task_install,
82+
TEST_ASSERT_EQUAL(pdPASS, xTaskCreate(test_task_install,
7783
"InstallTask",
7884
4096,
7985
(void *) xTaskGetCurrentTaskHandle(),
8086
4 + i,
8187
NULL));
8288
}
83-
84-
// Wait until all tasks are finished
85-
vTaskDelay(pdMS_TO_TICKS(5000));
89+
// Wait some time for all tasks to complete
90+
vTaskDelay(pdMS_TO_TICKS(1000));
8691
// Check if all tasks finished, we should get all notification from the tasks
8792
TEST_ASSERT_EQUAL_MESSAGE(MULTIPLE_THREADS_TASKS_NUM, ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(5000)), "Not all tasks finished");
8893
// There should be only one task that was able to install the driver

0 commit comments

Comments
 (0)