Merge branch 'fix/run_esp_usb_pre_commit' into 'master'

Run pre-commit fom esp-usb on usb-related files

See merge request espressif/esp-idf!40864
This commit is contained in:
Peter Marcisovsky
2025-08-12 10:18:44 +02:00
28 changed files with 105 additions and 110 deletions

View File

@@ -145,7 +145,7 @@ typedef struct {
struct { struct {
ext_hub_cb_t proc_req_cb; /**< Process callback */ ext_hub_cb_t proc_req_cb; /**< Process callback */
void *proc_req_cb_arg; /**< Process callback argument */ void *proc_req_cb_arg; /**< Process callback argument */
const ext_port_driver_api_t* port_driver; /**< External Port Driver */ const ext_port_driver_api_t *port_driver; /**< External Port Driver */
} constant; /**< Constant members. Do not change after installation thus do not require a critical section or mutex */ } constant; /**< Constant members. Do not change after installation thus do not require a critical section or mutex */
} ext_hub_driver_t; } ext_hub_driver_t;
@@ -180,7 +180,7 @@ DEFINE_CRIT_SECTION_LOCK_STATIC(ext_hub_driver_lock);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static bool _device_set_actions(ext_hub_dev_t *ext_hub_dev, uint32_t action_flags); static bool _device_set_actions(ext_hub_dev_t *ext_hub_dev, uint32_t action_flags);
static void device_error(ext_hub_dev_t *ext_hub_dev); static void device_error(ext_hub_dev_t *ext_hub_dev);
static void device_status_change_handle(ext_hub_dev_t *ext_hub_dev, const uint8_t* data, const int length); static void device_status_change_handle(ext_hub_dev_t *ext_hub_dev, const uint8_t *data, const int length);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// ---------------------- Callbacks (implementation) --------------------------- // ---------------------- Callbacks (implementation) ---------------------------
@@ -361,7 +361,7 @@ static void device_has_changed(ext_hub_dev_t *ext_hub_dev)
// | ... // | ...
// +---------------------------- Port N change detected // +---------------------------- Port N change detected
// //
static void device_status_change_handle(ext_hub_dev_t *ext_hub_dev, const uint8_t* data, const int length) static void device_status_change_handle(ext_hub_dev_t *ext_hub_dev, const uint8_t *data, const int length)
{ {
uint32_t device_status = 0; uint32_t device_status = 0;
// Driver does not support Hubs with EP IN wMaxPacketSize > 4 // Driver does not support Hubs with EP IN wMaxPacketSize > 4
@@ -415,14 +415,14 @@ static void device_error(ext_hub_dev_t *ext_hub_dev)
static esp_err_t device_port_new(ext_hub_dev_t *ext_hub_dev, uint8_t port_idx) static esp_err_t device_port_new(ext_hub_dev_t *ext_hub_dev, uint8_t port_idx)
{ {
ext_port_config_t port_config = { ext_port_config_t port_config = {
.context = (void*) ext_hub_dev, .context = (void *) ext_hub_dev,
.parent_dev_hdl = ext_hub_dev->constant.dev_hdl, .parent_dev_hdl = ext_hub_dev->constant.dev_hdl,
.parent_port_num = port_idx + 1, .parent_port_num = port_idx + 1,
.port_power_delay_ms = ext_hub_dev->constant.hub_desc->bPwrOn2PwrGood * 2, .port_power_delay_ms = ext_hub_dev->constant.hub_desc->bPwrOn2PwrGood * 2,
}; };
assert(p_ext_hub_driver->constant.port_driver); assert(p_ext_hub_driver->constant.port_driver);
esp_err_t ret = p_ext_hub_driver->constant.port_driver->new (&port_config, (void**) &ext_hub_dev->constant.ports[port_idx]); esp_err_t ret = p_ext_hub_driver->constant.port_driver->new (&port_config, (void **) &ext_hub_dev->constant.ports[port_idx]);
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(EXT_HUB_TAG, "[%d:%d] Port allocation error: %s", ext_hub_dev->constant.dev_addr, port_idx + 1, esp_err_to_name(ret)); ESP_LOGE(EXT_HUB_TAG, "[%d:%d] Port allocation error: %s", ext_hub_dev->constant.dev_addr, port_idx + 1, esp_err_to_name(ret));
goto fail; goto fail;
@@ -1208,7 +1208,7 @@ void *ext_hub_get_client(void)
EXT_HUB_ENTER_CRITICAL(); EXT_HUB_ENTER_CRITICAL();
driver_installed = (p_ext_hub_driver != NULL); driver_installed = (p_ext_hub_driver != NULL);
EXT_HUB_EXIT_CRITICAL(); EXT_HUB_EXIT_CRITICAL();
return (driver_installed) ? (void*) p_ext_hub_driver : NULL; return (driver_installed) ? (void *) p_ext_hub_driver : NULL;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@@ -78,7 +78,7 @@ struct ext_port_s {
usb_device_handle_t parent_dev_hdl; /**< Ports' parent device handle */ usb_device_handle_t parent_dev_hdl; /**< Ports' parent device handle */
uint8_t parent_dev_addr; /**< Ports' parent device bus address */ uint8_t parent_dev_addr; /**< Ports' parent device bus address */
// Port related constant members // Port related constant members
void* context; /**< Ports' parent External Hub handle */ void *context; /**< Ports' parent External Hub handle */
uint8_t port_num; /**< Ports' parent External Hub Port number */ uint8_t port_num; /**< Ports' parent External Hub Port number */
int power_on_delay_ms; /**< Ports' Power on time to Power Good, ms */ int power_on_delay_ms; /**< Ports' Power on time to Power Good, ms */
} constant; /**< Constant members. Do not change after installation thus do not require a critical section or mutex */ } constant; /**< Constant members. Do not change after installation thus do not require a critical section or mutex */
@@ -181,7 +181,7 @@ static inline bool port_is_enabled(ext_port_t *ext_port)
* - true Port connection changed * - true Port connection changed
* - false Port connection not changed * - false Port connection not changed
*/ */
static inline bool port_has_changed_connection(ext_port_t * ext_port) static inline bool port_has_changed_connection(ext_port_t *ext_port)
{ {
return ext_port->status.wPortChange.C_PORT_CONNECTION ? true : false; return ext_port->status.wPortChange.C_PORT_CONNECTION ? true : false;
} }
@@ -230,7 +230,7 @@ static inline bool port_has_finished_reset(ext_port_t *ext_port)
* - ESP_ERR_NOT_SUPPORTED: The request type is not supported by the External Hub Driver * - ESP_ERR_NOT_SUPPORTED: The request type is not supported by the External Hub Driver
* - ESP_OK: Status has been requested * - ESP_OK: Status has been requested
*/ */
static esp_err_t port_request_status(ext_port_t* ext_port) static esp_err_t port_request_status(ext_port_t *ext_port)
{ {
ext_port_parent_request_data_t data = { ext_port_parent_request_data_t data = {
.type = EXT_PORT_PARENT_REQ_CONTROL, .type = EXT_PORT_PARENT_REQ_CONTROL,
@@ -469,7 +469,7 @@ static ext_port_t *get_port_from_pending_list(void)
* - ESP_ERR_NOT_FINISHED: Unable to allocate the port object: parent device is not available * - ESP_ERR_NOT_FINISHED: Unable to allocate the port object: parent device is not available
* - ESP_OK: Port object created successfully * - ESP_OK: Port object created successfully
*/ */
static esp_err_t port_alloc(void* context, usb_device_handle_t parent_dev_hdl, uint8_t parent_port_num, uint16_t port_delay_ms, ext_port_t **port_obj) static esp_err_t port_alloc(void *context, usb_device_handle_t parent_dev_hdl, uint8_t parent_port_num, uint16_t port_delay_ms, ext_port_t **port_obj)
{ {
uint8_t parent_dev_addr = 0; uint8_t parent_dev_addr = 0;
EXT_PORT_CHECK(context != NULL && parent_dev_hdl != NULL, ESP_ERR_INVALID_ARG); EXT_PORT_CHECK(context != NULL && parent_dev_hdl != NULL, ESP_ERR_INVALID_ARG);
@@ -1247,7 +1247,7 @@ static esp_err_t port_gone(void *port_hdl)
* - ESP_ERR_INVALID_ARG: The port handle can't be NULL * - ESP_ERR_INVALID_ARG: The port handle can't be NULL
* - ESP_OK: Port action was requested * - ESP_OK: Port action was requested
*/ */
static esp_err_t port_get_status(void* port_hdl) static esp_err_t port_get_status(void *port_hdl)
{ {
EXT_PORT_CHECK(p_ext_port_driver != NULL, ESP_ERR_NOT_ALLOWED); EXT_PORT_CHECK(p_ext_port_driver != NULL, ESP_ERR_NOT_ALLOWED);
EXT_PORT_CHECK(port_hdl != NULL, ESP_ERR_INVALID_ARG); EXT_PORT_CHECK(port_hdl != NULL, ESP_ERR_INVALID_ARG);
@@ -1269,7 +1269,7 @@ static esp_err_t port_get_status(void* port_hdl)
* - ESP_ERR_INVALID_ARG: The port handle can't be NULL, the status data can't be NULL * - ESP_ERR_INVALID_ARG: The port handle can't be NULL, the status data can't be NULL
* - ESP_OK: Port action was requested * - ESP_OK: Port action was requested
*/ */
static esp_err_t port_set_status(void* port_hdl, const usb_port_status_t *port_status) static esp_err_t port_set_status(void *port_hdl, const usb_port_status_t *port_status)
{ {
EXT_PORT_CHECK(p_ext_port_driver != NULL, ESP_ERR_NOT_ALLOWED); EXT_PORT_CHECK(p_ext_port_driver != NULL, ESP_ERR_NOT_ALLOWED);
EXT_PORT_CHECK(port_hdl != NULL && port_status != NULL, ESP_ERR_INVALID_ARG); EXT_PORT_CHECK(port_hdl != NULL && port_status != NULL, ESP_ERR_INVALID_ARG);
@@ -1298,7 +1298,7 @@ static esp_err_t port_set_status(void* port_hdl, const usb_port_status_t *port_s
* - ESP_ERR_INVALID_ARG: The port handle can't be NULL * - ESP_ERR_INVALID_ARG: The port handle can't be NULL
* - ESP_OK: Port action was requested * - ESP_OK: Port action was requested
*/ */
static esp_err_t port_req_process(void* port_hdl) static esp_err_t port_req_process(void *port_hdl)
{ {
EXT_PORT_CHECK(p_ext_port_driver != NULL, ESP_ERR_NOT_ALLOWED); EXT_PORT_CHECK(p_ext_port_driver != NULL, ESP_ERR_NOT_ALLOWED);
EXT_PORT_CHECK(port_hdl != NULL, ESP_ERR_INVALID_ARG); EXT_PORT_CHECK(port_hdl != NULL, ESP_ERR_INVALID_ARG);
@@ -1443,7 +1443,7 @@ const ext_port_driver_api_t *ext_port_get_driver(void)
return &ext_port_driver; return &ext_port_driver;
} }
void* ext_port_get_context(ext_port_hdl_t port_hdl) void *ext_port_get_context(ext_port_hdl_t port_hdl)
{ {
EXT_PORT_CHECK(p_ext_port_driver != NULL, NULL); EXT_PORT_CHECK(p_ext_port_driver != NULL, NULL);
ext_port_t *ext_port = (ext_port_t *)port_hdl; ext_port_t *ext_port = (ext_port_t *)port_hdl;

View File

@@ -1407,7 +1407,7 @@ esp_err_t hcd_port_init(int port_number, const hcd_port_config_t *port_config, h
// USB-HAL's size is dependent on its configuration, namely on number of channels in the configuration // USB-HAL's size is dependent on its configuration, namely on number of channels in the configuration
// We must first initialize the HAL, to get the number of channels and then allocate memory for the channels // We must first initialize the HAL, to get the number of channels and then allocate memory for the channels
usb_dwc_hal_init(port_obj->hal, port_number); usb_dwc_hal_init(port_obj->hal, port_number);
port_obj->hal->channels.hdls = calloc(port_obj->hal->constant_config.chan_num_total, sizeof(usb_dwc_hal_chan_t*)); port_obj->hal->channels.hdls = calloc(port_obj->hal->constant_config.chan_num_total, sizeof(usb_dwc_hal_chan_t *));
HCD_CHECK_FROM_CRIT(port_obj->hal->channels.hdls != NULL, ESP_ERR_NO_MEM); HCD_CHECK_FROM_CRIT(port_obj->hal->channels.hdls != NULL, ESP_ERR_NO_MEM);
port_obj->initialized = true; port_obj->initialized = true;
@@ -1669,7 +1669,7 @@ static bool pipe_args_usb_compliance_verification(const hcd_pipe_config_t *pipe_
return true; return true;
} }
static bool pipe_alloc_hcd_support_verification(usb_dwc_hal_context_t *hal, const usb_ep_desc_t * ep_desc) static bool pipe_alloc_hcd_support_verification(usb_dwc_hal_context_t *hal, const usb_ep_desc_t *ep_desc)
{ {
assert(hal != NULL); assert(hal != NULL);
assert(ep_desc != NULL); assert(ep_desc != NULL);

View File

@@ -34,4 +34,4 @@ or run the executable directly:
``` ```
./build/host_test_usb_host_layer.elf ./build/host_test_usb_host_layer.elf
``` ```

View File

@@ -13,7 +13,7 @@ This test directory uses freertos as a real component
# Build # Build
Tests build regularly like an idf project. Currently only working on Linux machines. Tests build regularly like an idf project. Currently only working on Linux machines.
``` ```
idf.py --preview set-target linux idf.py --preview set-target linux
@@ -34,4 +34,4 @@ or run the executable directly:
``` ```
./build/host_test_usbh_layer.elf ./build/host_test_usbh_layer.elf
``` ```

View File

@@ -128,7 +128,7 @@ In order to communicate events to the client of the HCD, the HCD does not attemp
There are two types callbacks that the HCD offers: There are two types callbacks that the HCD offers:
- Port callback will run whenever an event a port occurs. `hcd_port_handle_event()` should be called after a port event occurs. - Port callback will run whenever an event a port occurs. `hcd_port_handle_event()` should be called after a port event occurs.
- A pipe callback on each pipe, that will run when a event occurs on a pipe. - A pipe callback on each pipe, that will run when a event occurs on a pipe.
The client of the HCD can also forego callbacks entirely and simply poll for port and pipe events using the `hcd_port_handle_event()` and `hcd_pipe_get_event()` respectively. The client of the HCD can also forego callbacks entirely and simply poll for port and pipe events using the `hcd_port_handle_event()` and `hcd_pipe_get_event()` respectively.

View File

@@ -29,7 +29,7 @@ extern "C" {
/** /**
* @brief Handle of enumeration control object * @brief Handle of enumeration control object
*/ */
typedef struct enum_ctx_handle_s * enum_ctx_handle_t; typedef struct enum_ctx_handle_s *enum_ctx_handle_t;
// ------------------------------ Events --------------------------------------- // ------------------------------ Events ---------------------------------------

View File

@@ -37,7 +37,7 @@ typedef bool (*ext_hub_cb_t)(bool in_isr, void *user_arg);
typedef struct { typedef struct {
ext_hub_cb_t proc_req_cb; /**< External Hub process callback */ ext_hub_cb_t proc_req_cb; /**< External Hub process callback */
void *proc_req_cb_arg; /**< External Hub process callback argument */ void *proc_req_cb_arg; /**< External Hub process callback argument */
const ext_port_driver_api_t* port_driver; /**< External Port Driver */ const ext_port_driver_api_t *port_driver; /**< External Port Driver */
} ext_hub_config_t; } ext_hub_config_t;
// ------------------------------ Driver --------------------------------------- // ------------------------------ Driver ---------------------------------------
@@ -55,7 +55,7 @@ typedef struct {
* - ESP_ERR_NO_MEM: Insufficient memory * - ESP_ERR_NO_MEM: Insufficient memory
* - ESP_ERR_INVALID_STATE: External Hub driver already installed * - ESP_ERR_INVALID_STATE: External Hub driver already installed
*/ */
esp_err_t ext_hub_install(const ext_hub_config_t* config); esp_err_t ext_hub_install(const ext_hub_config_t *config);
/** /**
* @brief Uninstall External Hub Driver * @brief Uninstall External Hub Driver

View File

@@ -128,7 +128,7 @@ typedef struct {
* Structure is used to create new port * Structure is used to create new port
*/ */
typedef struct { typedef struct {
void* context; /**< Ports' parent external Hub handle */ void *context; /**< Ports' parent external Hub handle */
usb_device_handle_t parent_dev_hdl; /**< Ports' parent device handle */ usb_device_handle_t parent_dev_hdl; /**< Ports' parent device handle */
uint8_t parent_port_num; /**< Ports' parent port number */ uint8_t parent_port_num; /**< Ports' parent port number */
uint16_t port_power_delay_ms; /**< Ports' Power on time to Power Good, ms */ uint16_t port_power_delay_ms; /**< Ports' Power on time to Power Good, ms */
@@ -193,7 +193,7 @@ const ext_port_driver_api_t *ext_port_get_driver(void);
* @return * @return
* - Pointer to the External Port Driver context * - Pointer to the External Port Driver context
*/ */
void* ext_port_get_context(ext_port_hdl_t port_hdl); void *ext_port_get_context(ext_port_hdl_t port_hdl);
/** /**
* @brief Returns External Port's port number * @brief Returns External Port's port number

View File

@@ -87,7 +87,7 @@ bLength : 0x22 (34 bytes)
bDescriptorType : 0x03 (String Descriptor) bDescriptorType : 0x03 (String Descriptor)
wData : " SanDisk 3.2Gen1" wData : " SanDisk 3.2Gen1"
----------------------------- String Descriptor Ser ---------------------------- ----------------------------- String Descriptor Set ----------------------------
bLength : 0xF2 (242 bytes) bLength : 0xF2 (242 bytes)
bDescriptorType : 0x03 (String Descriptor) bDescriptorType : 0x03 (String Descriptor)
wData : "0101cdd1e856b427bbb796f870561a4b2b817af9da9872c8d75217cccdd5d5eccb3a0000000000000000000096abe1a3ff83610095558107aea948b4" wData : "0101cdd1e856b427bbb796f870561a4b2b817af9da9872c8d75217cccdd5d5eccb3a0000000000000000000096abe1a3ff83610095558107aea948b4"

View File

@@ -51,7 +51,7 @@ The Mocked Device has a Final State Machine (FSM), which could be configured to
FSM is described in the **mock_dev_stage_t** structure and could be found in [mock_dev.h](main/mock_dev.h). FSM is described in the **mock_dev_stage_t** structure and could be found in [mock_dev.h](main/mock_dev.h).
Available stages: Available stages:
- Request Short Device Descriptor - Request Short Device Descriptor
- Request Full Device Descriptor - Request Full Device Descriptor
- Request Short Configuration Descriptor - Request Short Configuration Descriptor
@@ -165,7 +165,7 @@ TEST_CASE("enum::complete", "[mock_enum_device]")
} }
}, },
}; };
// Test remained logic // Test remained logic
} }
``` ```
@@ -346,4 +346,3 @@ E (121120) USBH: Dev 33 EP 0 STALL
E (121120) ENUM: Bad transfer status 4: CHECK_CONFIG E (121120) ENUM: Bad transfer status 4: CHECK_CONFIG
E (121120) ENUM: [0:0] CHECK_CONFIG FAILED E (121120) ENUM: [0:0] CHECK_CONFIG FAILED
``` ```

View File

@@ -202,7 +202,7 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid)
} }
// Advanced // Advanced
uint8_t const * tud_descriptor_bos_cb(void) uint8_t const *tud_descriptor_bos_cb(void)
{ {
printf("\t <- BOS Descriptor request\n"); printf("\t <- BOS Descriptor request\n");
return NULL; return NULL;

View File

@@ -77,7 +77,7 @@ typedef struct {
ext_port_parent_request_data_t data; ext_port_parent_request_data_t data;
} ext_port_hub_request_msg_t; } ext_port_hub_request_msg_t;
static const ext_port_driver_api_t* port_api; static const ext_port_driver_api_t *port_api;
SemaphoreHandle_t _process_cd_req = NULL; SemaphoreHandle_t _process_cd_req = NULL;
QueueHandle_t _ext_port_hub_req_queue = NULL; QueueHandle_t _ext_port_hub_req_queue = NULL;
QueueHandle_t _ext_port_event_queue = NULL; QueueHandle_t _ext_port_event_queue = NULL;
@@ -180,11 +180,11 @@ void test_ext_port_setup(void)
// Install External Port driver // Install External Port driver
ext_port_driver_config_t ext_port_config = { ext_port_driver_config_t ext_port_config = {
.proc_req_cb = test_ext_port_callback, .proc_req_cb = test_ext_port_callback,
.proc_req_cb_arg = (void*)_process_cd_req, .proc_req_cb_arg = (void *)_process_cd_req,
.event_cb = test_ext_port_event_callback, .event_cb = test_ext_port_event_callback,
.event_cb_arg = (void*)_ext_port_event_queue, .event_cb_arg = (void *)_ext_port_event_queue,
.hub_request_cb = test_ext_port_hub_request, .hub_request_cb = test_ext_port_hub_request,
.hub_request_cb_arg = (void*)_ext_port_hub_req_queue, .hub_request_cb_arg = (void *)_ext_port_hub_req_queue,
}; };
TEST_ASSERT_EQUAL(ESP_OK, ext_port_install(&ext_port_config)); TEST_ASSERT_EQUAL(ESP_OK, ext_port_install(&ext_port_config));
port_api = ext_port_get_driver(); port_api = ext_port_get_driver();
@@ -203,7 +203,7 @@ void test_ext_port_teardown(void)
ext_port_hdl_t test_ext_port_new(ext_port_config_t *config) ext_port_hdl_t test_ext_port_new(ext_port_config_t *config)
{ {
ext_port_hdl_t port = NULL; ext_port_hdl_t port = NULL;
TEST_ASSERT_EQUAL(ESP_OK, port_api->new (config, (void**) &port)); TEST_ASSERT_EQUAL(ESP_OK, port_api->new (config, (void **) &port));
TEST_ASSERT_NOT_NULL(port); TEST_ASSERT_NOT_NULL(port);
// Adding the port should trigger the process request callback // Adding the port should trigger the process request callback
test_wait_ext_port_process_request(); test_wait_ext_port_process_request();

View File

@@ -199,9 +199,9 @@ void hub_detach(void)
test_hcd_wait_for_disconn(hub.root_port_hdl, true); test_hcd_wait_for_disconn(hub.root_port_hdl, true);
} }
void* hub_get_context(void) void *hub_get_context(void)
{ {
return (void*) &hub; return (void *) &hub;
} }
uint8_t hub_get_port_num(void) uint8_t hub_get_port_num(void)

View File

@@ -72,7 +72,7 @@ void hub_child_quick_enum(hcd_pipe_handle_t ctrl_pipe, uint8_t dev_addr, uint8_t
* *
* @return void* pointer to a Hub context * @return void* pointer to a Hub context
*/ */
void* hub_get_context(void); void *hub_get_context(void);
/** /**
* @brief Get number of ports * @brief Get number of ports

View File

@@ -92,8 +92,8 @@ TEST_CASE("Port: disconnected", "[low_speed][full_speed][high_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_EMPTY <= port_num); TEST_ASSERT_TRUE(TEST_PORT_NUM_EMPTY <= port_num);
// Create External Port // Create External Port
ext_port_config_t port_config = { ext_port_config_t port_config = {
.context = (void*) hub_get_context() /* use any before IDF-10023 */, .context = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */, .parent_dev_hdl = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_EMPTY, .parent_port_num = TEST_PORT_NUM_EMPTY,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(), .port_power_delay_ms = hub_get_port_poweron_delay_ms(),
}; };
@@ -136,8 +136,8 @@ TEST_CASE("Port: enumerate child device Low-speed", "[ext_port][low_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_LS <= port_num); TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_LS <= port_num);
// Create External Port // Create External Port
ext_port_config_t port_config = { ext_port_config_t port_config = {
.context = (void*) hub_get_context() /* use any before IDF-10023 */, .context = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */, .parent_dev_hdl = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_LS, .parent_port_num = TEST_PORT_NUM_DEVICE_LS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(), .port_power_delay_ms = hub_get_port_poweron_delay_ms(),
}; };
@@ -146,7 +146,7 @@ TEST_CASE("Port: enumerate child device Low-speed", "[ext_port][low_speed]")
test_ext_port_power_on(TEST_PORT_NUM_DEVICE_LS, port_hdl); test_ext_port_power_on(TEST_PORT_NUM_DEVICE_LS, port_hdl);
// Wait connection // Wait connection
usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_LS, port_hdl); usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_LS, port_hdl);
printf("Hub port: %s speed device \n", (char*[]) { printf("Hub port: %s speed device \n", (char *[]) {
"Low", "Full", "High" "Low", "Full", "High"
}[port_speed]); }[port_speed]);
// Check the device speed // Check the device speed
@@ -193,8 +193,8 @@ TEST_CASE("Port: enumerate child device Full-speed", "[ext_port][full_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num); TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port // Create External Port
ext_port_config_t port_config = { ext_port_config_t port_config = {
.context = (void*) hub_get_context() /* use any before IDF-10023 */, .context = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */, .parent_dev_hdl = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS, .parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(), .port_power_delay_ms = hub_get_port_poweron_delay_ms(),
}; };
@@ -203,7 +203,7 @@ TEST_CASE("Port: enumerate child device Full-speed", "[ext_port][full_speed]")
test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
// Wait connection // Wait connection
usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
printf("Hub port: %s speed device \n", (char*[]) { printf("Hub port: %s speed device \n", (char *[]) {
"Low", "Full", "High" "Low", "Full", "High"
}[port_speed]); }[port_speed]);
// Check the device speed // Check the device speed
@@ -250,8 +250,8 @@ TEST_CASE("Port: enumerate child device High-speed", "[ext_port][high_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num); TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port // Create External Port
ext_port_config_t port_config = { ext_port_config_t port_config = {
.context = (void*) hub_get_context() /* use any before IDF-10023 */, .context = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */, .parent_dev_hdl = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS, .parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(), .port_power_delay_ms = hub_get_port_poweron_delay_ms(),
}; };
@@ -260,7 +260,7 @@ TEST_CASE("Port: enumerate child device High-speed", "[ext_port][high_speed]")
test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
// Wait connection // Wait connection
usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
printf("Hub port: %s speed device \n", (char*[]) { printf("Hub port: %s speed device \n", (char *[]) {
"Low", "Full", "High" "Low", "Full", "High"
}[port_speed]); }[port_speed]);
// Check the device speed // Check the device speed
@@ -307,8 +307,8 @@ TEST_CASE("Port: recycle", "[ext_port][full_speed][high_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num); TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port // Create External Port
ext_port_config_t port_config = { ext_port_config_t port_config = {
.context = (void*) hub_get_context() /* use any before IDF-10023 */, .context = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */, .parent_dev_hdl = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS, .parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(), .port_power_delay_ms = hub_get_port_poweron_delay_ms(),
}; };
@@ -317,7 +317,7 @@ TEST_CASE("Port: recycle", "[ext_port][full_speed][high_speed]")
test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
// Wait connection // Wait connection
usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
printf("Hub port: %s speed device \n", (char*[]) { printf("Hub port: %s speed device \n", (char *[]) {
"Low", "Full", "High" "Low", "Full", "High"
}[port_speed]); }[port_speed]);
// Wait disconnection // Wait disconnection
@@ -331,7 +331,7 @@ TEST_CASE("Port: recycle", "[ext_port][full_speed][high_speed]")
// Verify that port still available // Verify that port still available
printf("Verify the port is still available...\n"); printf("Verify the port is still available...\n");
port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
printf("Hub port: %s speed device \n", (char*[]) { printf("Hub port: %s speed device \n", (char *[]) {
"Low", "Full", "High" "Low", "Full", "High"
}[port_speed]); }[port_speed]);
// Wait disconnection // Wait disconnection
@@ -352,8 +352,8 @@ TEST_CASE("Port: recycle when port is gone", "[ext_port][low_speed][full_speed][
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num); TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port // Create External Port
ext_port_config_t port_config = { ext_port_config_t port_config = {
.context = (void*) hub_get_context() /* use any before IDF-10023 */, .context = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */, .parent_dev_hdl = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS, .parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(), .port_power_delay_ms = hub_get_port_poweron_delay_ms(),
}; };
@@ -362,7 +362,7 @@ TEST_CASE("Port: recycle when port is gone", "[ext_port][low_speed][full_speed][
test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
// Wait connection // Wait connection
usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
printf("Hub port: %s speed device \n", (char*[]) { printf("Hub port: %s speed device \n", (char *[]) {
"Low", "Full", "High" "Low", "Full", "High"
}[port_speed]); }[port_speed]);
@@ -397,8 +397,8 @@ TEST_CASE("Port: disable", "[ext_port][full_speed][high_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num); TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port // Create External Port
ext_port_config_t port_config = { ext_port_config_t port_config = {
.context = (void*) hub_get_context() /* use any before IDF-10023 */, .context = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */, .parent_dev_hdl = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS, .parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(), .port_power_delay_ms = hub_get_port_poweron_delay_ms(),
}; };
@@ -407,7 +407,7 @@ TEST_CASE("Port: disable", "[ext_port][full_speed][high_speed]")
test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
// Wait connection // Wait connection
usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
printf("Hub port: %s speed device \n", (char*[]) { printf("Hub port: %s speed device \n", (char *[]) {
"Low", "Full", "High" "Low", "Full", "High"
}[port_speed]); }[port_speed]);
printf("Disable the port ...\n"); printf("Disable the port ...\n");
@@ -440,8 +440,8 @@ TEST_CASE("Port: gone in state - powered on", "[ext_port][full_speed][high_speed
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num); TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port // Create External Port
ext_port_config_t port_config = { ext_port_config_t port_config = {
.context = (void*) hub_get_context() /* use any before IDF-10023 */, .context = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */, .parent_dev_hdl = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS, .parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(), .port_power_delay_ms = hub_get_port_poweron_delay_ms(),
}; };
@@ -478,8 +478,8 @@ TEST_CASE("Port: gone in state - enabled", "[ext_port][full_speed][high_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num); TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port // Create External Port
ext_port_config_t port_config = { ext_port_config_t port_config = {
.context = (void*) hub_get_context() /* use any before IDF-10023 */, .context = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */, .parent_dev_hdl = (void *) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS, .parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(), .port_power_delay_ms = hub_get_port_poweron_delay_ms(),
}; };
@@ -488,7 +488,7 @@ TEST_CASE("Port: gone in state - enabled", "[ext_port][full_speed][high_speed]")
test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
// Wait connection // Wait connection
usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl); usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
printf("Hub port: %s speed device \n", (char*[]) { printf("Hub port: %s speed device \n", (char *[]) {
"Low", "Full", "High" "Low", "Full", "High"
}[port_speed]); }[port_speed]);
// //

View File

@@ -33,7 +33,7 @@ Procedure:
TEST_CASE("Test HCD port disconnect event, port enabled", "[port][low_speed][full_speed][high_speed]") TEST_CASE("Test HCD port disconnect event, port enabled", "[port][low_speed][full_speed][high_speed]")
{ {
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
printf("Connected %s speed device \n", (char*[]) { printf("Connected %s speed device \n", (char *[]) {
"Low", "Full", "High" "Low", "Full", "High"
}[port_speed]); }[port_speed]);
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS) vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)

View File

@@ -9,4 +9,3 @@ There are three sets of tests in this application:
3. High-speed: Expects high-speed USB flash disk with 2 bulk endpoints to be connected 3. High-speed: Expects high-speed USB flash disk with 2 bulk endpoints to be connected
For running these tests locally, you will have to update device definitions (VID, PID, ...) in [dev_msc.c](../common/dev_msc.c) and [dev_hid.c](../common/dev_hid.c). For running these tests locally, you will have to update device definitions (VID, PID, ...) in [dev_msc.c](../common/dev_msc.c) and [dev_hid.c](../common/dev_hid.c).

View File

@@ -327,7 +327,7 @@ TEST_CASE("Test USB Host multiconfig client (single client)", "[usb_host][full_s
.bConfigurationValue = B_CONFIGURATION_VALUE, .bConfigurationValue = B_CONFIGURATION_VALUE,
}; };
xTaskCreatePinnedToCore(multiconf_client_async_task, "async client", 4096, (void*)&multiconf_params, 2, &client_task, 0); xTaskCreatePinnedToCore(multiconf_client_async_task, "async client", 4096, (void *)&multiconf_params, 2, &client_task, 0);
TEST_ASSERT_NOT_NULL_MESSAGE(client_task, "Failed to create async client task"); TEST_ASSERT_NOT_NULL_MESSAGE(client_task, "Failed to create async client task");
// Start the task // Start the task
xTaskNotifyGive(client_task); xTaskNotifyGive(client_task);
@@ -335,7 +335,7 @@ TEST_CASE("Test USB Host multiconfig client (single client)", "[usb_host][full_s
TaskHandle_t host_lib_task_hdl; TaskHandle_t host_lib_task_hdl;
// Get Current task handle // Get Current task handle
TaskHandle_t pending_task = xTaskGetCurrentTaskHandle(); TaskHandle_t pending_task = xTaskGetCurrentTaskHandle();
xTaskCreatePinnedToCore(host_lib_task, "host lib", 4096, (void*)pending_task, 2, &host_lib_task_hdl, 0); xTaskCreatePinnedToCore(host_lib_task, "host lib", 4096, (void *)pending_task, 2, &host_lib_task_hdl, 0);
TEST_ASSERT_NOT_NULL_MESSAGE(host_lib_task_hdl, "Failed to create host lib task"); TEST_ASSERT_NOT_NULL_MESSAGE(host_lib_task_hdl, "Failed to create host lib task");
// Wait for the device to be open // Wait for the device to be open

View File

@@ -1235,7 +1235,7 @@ exit:
esp_err_t usb_host_free_config_desc(const usb_config_desc_t *config_desc) esp_err_t usb_host_free_config_desc(const usb_config_desc_t *config_desc)
{ {
HOST_CHECK(config_desc != NULL, ESP_ERR_INVALID_ARG); HOST_CHECK(config_desc != NULL, ESP_ERR_INVALID_ARG);
heap_caps_free((usb_config_desc_t*)config_desc); heap_caps_free((usb_config_desc_t *)config_desc);
return ESP_OK; return ESP_OK;
} }

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: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -33,7 +33,7 @@ const uint8_t hid_report_descriptor[] = {
/** /**
* @brief String descriptor * @brief String descriptor
*/ */
const char* hid_string_descriptor[5] = { const char *hid_string_descriptor[5] = {
// array of pointer to string descriptors // array of pointer to string descriptors
(char[]){0x09, 0x04}, // 0: is supported language is English (0x0409) (char[]){0x09, 0x04}, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer "TinyUSB", // 1: Manufacturer
@@ -68,7 +68,7 @@ uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance)
// Invoked when received GET_REPORT control request // Invoked when received GET_REPORT control request
// Application must fill buffer report's content and return its length. // Application must fill buffer report's content and return its length.
// Return zero will cause the stack to STALL request // Return zero will cause the stack to STALL request
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen)
{ {
(void) instance; (void) instance;
(void) report_id; (void) report_id;
@@ -81,7 +81,7 @@ uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_t
// Invoked when received SET_REPORT control request or // Invoked when received SET_REPORT control request or
// received data on OUT endpoint ( Report ID = 0, Type = 0 ) // received data on OUT endpoint ( Report ID = 0, Type = 0 )
void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize)
{ {
} }

View File

@@ -42,7 +42,7 @@ enum usb_endpoints {
/** /**
* @brief String descriptor * @brief String descriptor
*/ */
static const char* s_str_desc[5] = { static const char *s_str_desc[5] = {
// array of pointer to string descriptors // array of pointer to string descriptors
(char[]){0x09, 0x04}, // 0: is supported language is English (0x0409) (char[]){0x09, 0x04}, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer "TinyUSB", // 1: Manufacturer

View File

@@ -24,7 +24,7 @@ As a USB stack, a TinyUSB component is used.
1. USB which accesses the ESP MSC Partition is unplugged initially and the board is powered-on. 1. USB which accesses the ESP MSC Partition is unplugged initially and the board is powered-on.
- Result: Host PC can't access the partition over USB MSC. Application example can perform operations (read, write) on partition. - Result: Host PC can't access the partition over USB MSC. Application example can perform operations (read, write) on partition.
2. USB which accesses the ESP MSC Partition is already plugged-in at boot time. 2. USB which accesses the ESP MSC Partition is already plugged-in at boot time.
- Result: Host PC recongnize it as removable device and can access the partition over USB MSC. Application example can't perform any operation on partition. - Result: Host PC recognize it as removable device and can access the partition over USB MSC. Application example can't perform any operation on partition.
3. USB which accesses the ESP MSC Partition is plugged-in at boot-up. After boot-up, it is ejected on Host PC manually by user. 3. USB which accesses the ESP MSC Partition is plugged-in at boot-up. After boot-up, it is ejected on Host PC manually by user.
- Result: Host PC can't access the partition over USB MSC. Application example can perform operations (read, write) on partition. - Result: Host PC can't access the partition over USB MSC. Application example can perform operations (read, write) on partition.
4. USB which accesses the ESP MSC Partition is plugged-in at boot-up. It is then unplugged(removed) from Host PC manually by user. 4. USB which accesses the ESP MSC Partition is plugged-in at boot-up. It is then unplugged(removed) from Host PC manually by user.
@@ -145,30 +145,30 @@ Type 'help' to get the list of commands.
Use UP/DOWN arrows to navigate through command history. Use UP/DOWN arrows to navigate through command history.
Press TAB when typing command name to auto-complete. Press TAB when typing command name to auto-complete.
I (724) main_task: Returned from app_main() I (724) main_task: Returned from app_main()
esp32s3> esp32s3>
esp32s3> help esp32s3> help
help help
Print the list of registered commands Print the list of registered commands
read read
read BASE_PATH/README.MD and print its contents read BASE_PATH/README.MD and print its contents
write write
create file BASE_PATH/README.MD if it does not exist create file BASE_PATH/README.MD if it does not exist
size size
show storage size and sector size show storage size and sector size
expose expose
Expose Storage to Host Expose Storage to Host
status status
Status of storage exposure over USB Status of storage exposure over USB
exit exit
exit from application exit from application
esp32s3> esp32s3>
esp32s3> read esp32s3> read
E (80054) example_main: storage exposed over USB. Application can't read from storage. E (80054) example_main: storage exposed over USB. Application can't read from storage.
Command returned non-zero error code: 0xffffffff (ESP_FAIL) Command returned non-zero error code: 0xffffffff (ESP_FAIL)
@@ -183,8 +183,8 @@ storage exposed over USB: Yes
esp32s3> expose esp32s3> expose
E (108344) example_main: storage is already exposed E (108344) example_main: storage is already exposed
Command returned non-zero error code: 0xffffffff (ESP_FAIL) Command returned non-zero error code: 0xffffffff (ESP_FAIL)
esp32s3> esp32s3>
esp32s3> esp32s3>
esp32s3> read esp32s3> read
Mass Storage Devices are one of the most common USB devices. It use Mass Storage Class (MSC) that allow access to their internal data storage. Mass Storage Devices are one of the most common USB devices. It use Mass Storage Class (MSC) that allow access to their internal data storage.
In this example, ESP chip will be recognised by host (PC) as Mass Storage Device. In this example, ESP chip will be recognised by host (PC) as Mass Storage Device.
@@ -198,6 +198,6 @@ esp32s3> expose
I (181224) example_main: Unmount storage... I (181224) example_main: Unmount storage...
esp32s3> status esp32s3> status
storage exposed over USB: Yes storage exposed over USB: Yes
esp32s3> esp32s3>
esp32s3> esp32s3>
``` ```

View File

@@ -11,7 +11,7 @@ This example shows how to use the CDC-ACM Host Driver to allow an ESP chip to co
### Hardware Required ### Hardware Required
Two development boards with USB-OTG support. One will act as USB host and the other as USB device. Two development boards with USB-OTG support. One will act as USB host and the other as USB device.
#### Pin Assignment #### Pin Assignment

View File

@@ -37,25 +37,25 @@ Mouse
X: 000883 Y: 000058 | |o| X: 000883 Y: 000058 | |o|
``` ```
Where every keyboard key printed as char symbol if it is possible and a Hex value for any other key. Where every keyboard key printed as char symbol if it is possible and a Hex value for any other key.
#### Keyboard input data #### Keyboard input data
Keyboard input data starts with the word "Keyboard" and every pressed key is printed to the serial debug. Keyboard input data starts with the word "Keyboard" and every pressed key is printed to the serial debug.
Left or right Shift modifier is also supported. Left or right Shift modifier is also supported.
``` ```
Keyboard Keyboard
Hello, ESP32 USB HID Keyboard is here! Hello, ESP32 USB HID Keyboard is here!
``` ```
#### Mouse input data #### Mouse input data
Mouse input data starts with the word "Mouse" and has the following structure. Mouse input data starts with the word "Mouse" and has the following structure.
``` ```
Mouse Mouse
X: -00343 Y: 000183 | |o| X: -00343 Y: 000183 | |o|
| | | | | | | |
| | | +- Right mouse button pressed status ("o" - pressed, " " - not pressed) | | | +- Right mouse button pressed status ("o" - pressed, " " - not pressed)
| | +--- Left mouse button pressed status ("o" - pressed, " " - not pressed) | | +--- Left mouse button pressed status ("o" - pressed, " " - not pressed)
| +---------- Y relative coordinate of the cursor | +---------- Y relative coordinate of the cursor
+----------------------- X relative coordinate of the cursor +----------------------- X relative coordinate of the cursor
``` ```

View File

@@ -27,7 +27,7 @@ The example is run in a loop so that it can demonstrate USB connection and recon
### USB Host Limitations ### USB Host Limitations
#### ESP32-S2 & ESP32-S3 #### ESP32-S2 & ESP32-S3
The USB OTG peripheral on ESP32-S2 and ESP32-S3 in host mode supports **up to 8 bidirectional endpoints**. Each of these endpoints can be configured as either IN or OUT. The USB OTG peripheral on ESP32-S2 and ESP32-S3 in host mode supports **up to 8 bidirectional endpoints**. Each of these endpoints can be configured as either IN or OUT.
Since each USB Mass Storage Class (MSC) device typically requires **3 endpoints** (Control, BULK IN, and BULK OUT), and USB hubs also consume endpoints (Control, INTERRUPT IN), this limits the theoretical maximum number of connected MSC devices to **2**. Since each USB Mass Storage Class (MSC) device typically requires **3 endpoints** (Control, BULK IN, and BULK OUT), and USB hubs also consume endpoints (Control, INTERRUPT IN), this limits the theoretical maximum number of connected MSC devices to **2**.

View File

@@ -64,7 +64,7 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui
I (305) main_task: Started on CPU0 I (305) main_task: Started on CPU0
I (315) main_task: Calling app_main() I (315) main_task: Calling app_main()
I (315) USB host lib: USB host library example I (315) USB host lib: USB host library example
I (315) gpio: GPIO[0]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2 I (315) gpio: GPIO[0]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2
I (325) USB host lib: Installing USB Host Library I (325) USB host lib: Installing USB Host Library
I (365) CLASS: Registering Client I (365) CLASS: Registering Client
I (745) CLASS: Opening device at address 1 I (745) CLASS: Opening device at address 1

View File

@@ -14,7 +14,6 @@
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/semphr.h" #include "freertos/semphr.h"
#define MOCK_CHECK(cond, ret_val) ({ \ #define MOCK_CHECK(cond, ret_val) ({ \
if (!(cond)) { \ if (!(cond)) { \
return (ret_val); \ return (ret_val); \
@@ -32,7 +31,6 @@
#define IS_VALID_ADDRESS(address) ((address) != 0xFF) #define IS_VALID_ADDRESS(address) ((address) != 0xFF)
#define IS_EMPTY_ADDRESS(address) ((address) == 0xFF) #define IS_EMPTY_ADDRESS(address) ((address) == 0xFF)
const char *MOCK_TAG_CB = "USB MOCK CB"; // Tag for callback functions const char *MOCK_TAG_CB = "USB MOCK CB"; // Tag for callback functions
const char *MOCK_TAG = "USB MOCK"; // Tag for the rest of the functions const char *MOCK_TAG = "USB MOCK"; // Tag for the rest of the functions
@@ -56,10 +54,9 @@ typedef struct {
static device_list_t device_list[MAX_DEV_COUNT]; static device_list_t device_list[MAX_DEV_COUNT];
static unsigned mocked_devices_count = 0; static unsigned mocked_devices_count = 0;
void usb_host_mock_dev_list_init(void) void usb_host_mock_dev_list_init(void)
{ {
for(int index = 0; index < MAX_DEV_COUNT; index++) { for (int index = 0; index < MAX_DEV_COUNT; index++) {
device_list[index].address = 0xFF; device_list[index].address = 0xFF;
device_list[index].opened = 0; device_list[index].opened = 0;
device_list[index].dev_desc = NULL; device_list[index].dev_desc = NULL;
@@ -98,7 +95,7 @@ esp_err_t usb_host_mock_add_device(uint8_t dev_address, const usb_device_desc_t
*/ */
static void _print_mocked_device(int index) static void _print_mocked_device(int index)
{ {
ESP_LOGI(MOCK_TAG, "Device handle = %p", (void*)(&device_list[index])); ESP_LOGI(MOCK_TAG, "Device handle = %p", (void *)(&device_list[index]));
ESP_LOGI(MOCK_TAG, "Device address = %d", device_list[index].address); ESP_LOGI(MOCK_TAG, "Device address = %d", device_list[index].address);
ESP_LOGI(MOCK_TAG, "Device opened by = %d clients", device_list[index].opened); ESP_LOGI(MOCK_TAG, "Device opened by = %d clients", device_list[index].opened);
@@ -113,12 +110,12 @@ esp_err_t usb_host_mock_print_mocked_devices(uint8_t dev_address)
// dev_address is 0xFF, print all devices from device_list // dev_address is 0xFF, print all devices from device_list
if (IS_EMPTY_ADDRESS(dev_address)) { if (IS_EMPTY_ADDRESS(dev_address)) {
for(int index = 0; index < MAX_DEV_COUNT; index++) { for (int index = 0; index < MAX_DEV_COUNT; index++) {
if(IS_VALID_ADDRESS(device_list[index].address)) { if (IS_VALID_ADDRESS(device_list[index].address)) {
_print_mocked_device(index); _print_mocked_device(index);
} }
} }
// Print only device at dev_address // Print only device at dev_address
} else { } else {
if (IS_VALID_ADDRESS(device_list[dev_address].address)) { if (IS_VALID_ADDRESS(device_list[dev_address].address)) {
_print_mocked_device(dev_address); _print_mocked_device(dev_address);
@@ -194,7 +191,7 @@ esp_err_t usb_host_client_register_mock_callback(const usb_host_client_config_t
esp_err_t ret; esp_err_t ret;
// Create client object // Create client object
client_t *client_obj = (client_t*)calloc(1, sizeof(client_t)); client_t *client_obj = (client_t *)calloc(1, sizeof(client_t));
SemaphoreHandle_t event_sem = xSemaphoreCreateBinary(); SemaphoreHandle_t event_sem = xSemaphoreCreateBinary();
if (client_obj == NULL || event_sem == NULL) { if (client_obj == NULL || event_sem == NULL) {
ret = ESP_ERR_NO_MEM; ret = ESP_ERR_NO_MEM;
@@ -261,7 +258,7 @@ esp_err_t usb_host_device_open_mock_callback(usb_host_client_handle_t client_hdl
MOCK_CHECK(dev_address < MAX_DEV_COUNT && client_hdl != NULL && dev_hdl_ret != NULL, ESP_ERR_INVALID_ARG); MOCK_CHECK(dev_address < MAX_DEV_COUNT && client_hdl != NULL && dev_hdl_ret != NULL, ESP_ERR_INVALID_ARG);
// Find a device in dev_list by dev_address // Find a device in dev_list by dev_address
for (int index = 0; index < MAX_DEV_COUNT; index++) { for (int index = 0; index < MAX_DEV_COUNT; index++) {
if(device_list[index].address == dev_address) { if (device_list[index].address == dev_address) {
// We should check, if the device has not been opened by the same client // We should check, if the device has not been opened by the same client
// But we are keeping this mock implementation simple // But we are keeping this mock implementation simple
@@ -282,7 +279,7 @@ esp_err_t usb_host_device_open_mock_callback(usb_host_client_handle_t client_hdl
esp_err_t usb_host_device_close_mock_callback(usb_host_client_handle_t client_hdl, usb_device_handle_t dev_hdl, int call_count) esp_err_t usb_host_device_close_mock_callback(usb_host_client_handle_t client_hdl, usb_device_handle_t dev_hdl, int call_count)
{ {
MOCK_CHECK(dev_hdl != NULL && client_hdl != NULL, ESP_ERR_INVALID_ARG); MOCK_CHECK(dev_hdl != NULL && client_hdl != NULL, ESP_ERR_INVALID_ARG);
device_list_t* current_device = (device_list_t *) dev_hdl; device_list_t *current_device = (device_list_t *) dev_hdl;
if (current_device->opened == 0) { if (current_device->opened == 0) {
// Device was never opened // Device was never opened
@@ -305,7 +302,7 @@ esp_err_t usb_host_device_addr_list_fill_mock_callback(int list_len, uint8_t *de
int found_devices_count = 0; int found_devices_count = 0;
for (int index = 0; index < MAX_DEV_COUNT; index++) { for (int index = 0; index < MAX_DEV_COUNT; index++) {
if(IS_VALID_ADDRESS(device_list[index].address) && (found_devices_count < list_len)) { if (IS_VALID_ADDRESS(device_list[index].address) && (found_devices_count < list_len)) {
dev_addr_list[found_devices_count++] = device_list[index].address; dev_addr_list[found_devices_count++] = device_list[index].address;
} }
} }
@@ -325,7 +322,7 @@ esp_err_t usb_host_get_device_descriptor_mock_callback(usb_device_handle_t dev_h
MOCK_CHECK(dev_hdl != NULL && device_desc != NULL, ESP_ERR_INVALID_ARG); MOCK_CHECK(dev_hdl != NULL && device_desc != NULL, ESP_ERR_INVALID_ARG);
ESP_LOGD(MOCK_TAG_CB, "Get device descriptor"); ESP_LOGD(MOCK_TAG_CB, "Get device descriptor");
const device_list_t* current_device = (const device_list_t *) dev_hdl; const device_list_t *current_device = (const device_list_t *) dev_hdl;
*device_desc = current_device->dev_desc; *device_desc = current_device->dev_desc;
return ESP_OK; return ESP_OK;
} }
@@ -335,7 +332,7 @@ esp_err_t usb_host_get_active_config_descriptor_mock_callback(usb_device_handle_
MOCK_CHECK(dev_hdl != NULL && config_desc != NULL, ESP_ERR_INVALID_ARG); MOCK_CHECK(dev_hdl != NULL && config_desc != NULL, ESP_ERR_INVALID_ARG);
ESP_LOGD(MOCK_TAG_CB, "Get active config descriptor"); ESP_LOGD(MOCK_TAG_CB, "Get active config descriptor");
const device_list_t* current_device = (const device_list_t *) dev_hdl; const device_list_t *current_device = (const device_list_t *) dev_hdl;
*config_desc = current_device->config_desc; *config_desc = current_device->config_desc;
return ESP_OK; return ESP_OK;
} }