Skip to content

Commit 0c36498

Browse files
feat(usb_host): HCD tests ok
1 parent be92c27 commit 0c36498

File tree

12 files changed

+104
-71
lines changed

12 files changed

+104
-71
lines changed

.github/workflows/build_idf_examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ name: Build ESP-IDF USB examples
1616

1717
on:
1818
pull_request:
19-
types: [opened, reopened, synchronize]
19+
types: [opened, reopened]
2020

2121
jobs:
2222
build:

host/usb/src/hcd_dwc.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,6 @@ static hcd_port_event_t _intr_hdlr_hprt(port_t *port, usb_dwc_hal_port_event_t h
833833
}
834834
case USB_DWC_HAL_PORT_EVENT_REMOTE_WAKEUP: {
835835
esp_rom_printf("WAKE\n");
836-
//port->state = HCD_PORT_STATE_ENABLED;
837836
port_event = HCD_PORT_EVENT_REMOTE_WAKEUP;
838837
break;
839838
}
@@ -1259,9 +1258,9 @@ static esp_err_t _port_cmd_power_on(port_t *port)
12591258
// Port can only be powered on if it's currently unpowered
12601259
if (port->state == HCD_PORT_STATE_NOT_POWERED) {
12611260
port->state = HCD_PORT_STATE_DISCONNECTED;
1261+
//assert(_internal_clk_gate(port, false)); // Un-gate the phy clock TODO: Test this
12621262
usb_dwc_hal_port_init(port->hal);
12631263
usb_dwc_hal_port_toggle_power(port->hal, true);
1264-
//_internal_clk_gate(port, false); // Un-gate the phy clock TODO: Test this
12651264
ret = ESP_OK;
12661265
} else {
12671266
ret = ESP_ERR_INVALID_STATE;
@@ -1274,8 +1273,13 @@ static esp_err_t _port_cmd_power_off(port_t *port)
12741273
esp_err_t ret;
12751274
// Port can only be unpowered if already powered
12761275
if (port->state != HCD_PORT_STATE_NOT_POWERED) {
1276+
1277+
if (port->state == HCD_PORT_STATE_SUSPENDED) {
1278+
// un-gate internal clock, to be able to toggle power on the port
1279+
assert(_internal_clk_gate(port, false)); // Un-gate the phy clock
1280+
}
12771281
port->state = HCD_PORT_STATE_NOT_POWERED;
1278-
//_internal_clk_gate(port, false); // Un-gate the phy clock TODO: Test this
1282+
//assert(_internal_clk_gate(port, false)); // Gate the phy clock TODO: Test this
12791283
usb_dwc_hal_port_deinit(port->hal);
12801284
usb_dwc_hal_port_toggle_power(port->hal, false);
12811285
// If a device is currently connected, this should trigger a disconnect event
@@ -1568,7 +1572,6 @@ esp_err_t hcd_port_deinit(hcd_port_handle_t port_hdl)
15681572
return ESP_OK;
15691573
}
15701574

1571-
15721575
esp_err_t hcd_port_command(hcd_port_handle_t port_hdl, hcd_port_cmd_t command)
15731576
{
15741577
esp_err_t ret = ESP_ERR_INVALID_STATE;
@@ -1677,6 +1680,7 @@ esp_err_t hcd_port_recover(hcd_port_handle_t port_hdl)
16771680
ESP_ERR_INVALID_STATE);
16781681

16791682
// We are about to do a soft reset on the peripheral. Disable the peripheral throughout
1683+
//assert(_internal_clk_gate(port, false)); // Gate the phy clock
16801684
esp_intr_disable(port->isr_hdl);
16811685
usb_dwc_hal_core_soft_reset(port->hal);
16821686
port->state = HCD_PORT_STATE_NOT_POWERED;
@@ -1686,6 +1690,7 @@ esp_err_t hcd_port_recover(hcd_port_handle_t port_hdl)
16861690
// Clear the frame list. We set the frame list register and enable periodic scheduling after a successful reset
16871691
memset(port->frame_list, 0, FRAME_LIST_LEN * sizeof(uint32_t));
16881692
esp_intr_enable(port->isr_hdl);
1693+
//assert(_internal_clk_gate(port, true)); // Gate the phy clock
16891694
HCD_EXIT_CRITICAL();
16901695
return ESP_OK;
16911696
}

host/usb/src/hub.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,14 +456,7 @@ static void root_port_handle_events(hcd_port_handle_t root_port_hdl)
456456
break;
457457
}
458458
case HCD_PORT_EVENT_REMOTE_WAKEUP:
459-
// Root port, including all the connected devices were resumed (global resume)
460-
// Clear all EPs and propagate the resumed event to clients
461-
//usbh_devs_set_pm_actions_all(USBH_DEV_RESUME | USBH_DEV_RESUME_EVT);
462-
463-
// Change Port state
464-
//HUB_DRIVER_ENTER_CRITICAL();
465-
//p_hub_driver_obj->dynamic.root_port_state = ROOT_PORT_STATE_ENABLED;
466-
//HUB_DRIVER_EXIT_CRITICAL();
459+
// Mark root port as ready to be resumed
467460
hub_root_mark_resume();
468461
break;
469462
default:

host/usb/src/usb_host.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,9 +1340,7 @@ esp_err_t usb_host_get_active_config_descriptor(usb_device_handle_t dev_hdl, con
13401340
static usb_transfer_status_t wait_for_transmission_done(usb_transfer_t *transfer)
13411341
{
13421342
SemaphoreHandle_t transfer_done = (SemaphoreHandle_t)transfer->context;
1343-
esp_rom_printf("Transfer wait\n");
13441343
xSemaphoreTake(transfer_done, portMAX_DELAY);
1345-
esp_rom_printf("Transfer done\n");
13461344
usb_transfer_status_t status = transfer->status;
13471345

13481346
// EP0 halt->flush->clear is managed by USBH and lower layers

host/usb/test/target_test/common/hcd_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void test_hcd_expect_port_event(hcd_port_handle_t port_hdl, hcd_port_event_t exp
127127
TEST_ASSERT_EQUAL_MESSAGE(pdPASS, ret, "Port event not generated on time");
128128
// Check the contents of that event message
129129
TEST_ASSERT_EQUAL(port_hdl, msg.port_hdl);
130-
TEST_ASSERT_EQUAL_MESSAGE(expected_event, msg.port_event, "Unexpected event");
130+
TEST_ASSERT_EQUAL_MESSAGE(expected_event, msg.port_event, "Unexpected port event");
131131
printf("\t-> Port event\n");
132132
}
133133

@@ -142,7 +142,7 @@ void test_hcd_expect_pipe_event(hcd_pipe_handle_t pipe_hdl, hcd_pipe_event_t exp
142142
TEST_ASSERT_EQUAL_MESSAGE(pdPASS, ret, "Pipe event not generated on time");
143143
// Check the contents of that event message
144144
TEST_ASSERT_EQUAL(pipe_hdl, msg.pipe_hdl);
145-
TEST_ASSERT_EQUAL_MESSAGE(expected_event, msg.pipe_event, "Unexpected event");
145+
TEST_ASSERT_EQUAL_MESSAGE(expected_event, msg.pipe_event, "Unexpected pipe event");
146146
}
147147

148148
void test_hcd_expect_no_pipe_event(hcd_pipe_handle_t pipe_hdl)

host/usb/test/target_test/common/phy_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
#pragma once
8-
#include "hal/usb_phy_types.h"
8+
#include "esp_private/usb_phy.h"
99

1010
/**
1111
* @brief Install USB PHY separately from the usb_host_install()

host/usb/test/target_test/hcd/main/test_hcd_port.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ TEST_CASE("Test HCD port suspend and resume sudden disconnect", "[port][low_spee
242242

243243
// Power-off the port to trigger a disconnection
244244
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_command(port_hdl, HCD_PORT_CMD_POWER_OFF));
245+
printf("COmmand\n");
245246
// Disconnect event should have occurred. Handle the port event
246247
test_hcd_expect_port_event(port_hdl, HCD_PORT_EVENT_DISCONNECTION);
247248
TEST_ASSERT_EQUAL(HCD_PORT_EVENT_DISCONNECTION, hcd_port_handle_event(port_hdl));
@@ -505,8 +506,6 @@ TEST_CASE("Test HCD port remote wakeup", "[port][low_speed][full_speed][high_spe
505506
TEST_ASSERT_EQUAL(HCD_PORT_STATE_ENABLED, hcd_port_get_state(port_hdl));
506507
printf("Resumed\n");
507508

508-
//vTaskDelay(pdMS_TO_TICKS(5000));
509-
510509
// Clear the pipe after the port has been resumed
511510
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_HALTED, hcd_pipe_get_state(default_pipe));
512511
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(default_pipe, HCD_PIPE_CMD_CLEAR));

host/usb/test/target_test/hcd/pytest_usb_hcd.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
import pytest
55
from pytest_embedded_idf.dut import IdfDut
6+
from pytest_embedded_idf.utils import idf_parametrize
67

7-
@pytest.mark.esp32s2
8-
@pytest.mark.esp32s3
9-
@pytest.mark.esp32p4
8+
#@pytest.mark.esp32s2
9+
#@pytest.mark.esp32s3
10+
#@pytest.mark.esp32p4
1011
@pytest.mark.usb_host_flash_disk
1112

1213
# No build for different configs yet, leaving this commented out
@@ -15,10 +16,10 @@
1516
# [('default', 'esp32s2'), ('default', 'esp32s3'), ('default', 'esp32p4'), ('esp32p4_psram', 'esp32p4')],
1617
# indirect=['config', 'target'],
1718
#)
18-
#@idf_parametrize('target', ['esp32s2', 'esp32s3', 'esp32p4'], indirect=['target'])
19+
@idf_parametrize('target', ['esp32s2', 'esp32s3', 'esp32p4'], indirect=['target'])
1920

2021
def test_usb_hcd(dut: IdfDut) -> None:
2122
if dut.target == 'esp32p4':
22-
dut.run_all_single_board_cases(group='high_speed', reset=True)
23+
dut.run_all_single_board_cases(group='high_speed')
2324
else:
24-
dut.run_all_single_board_cases(group='full_speed', reset=True)
25+
dut.run_all_single_board_cases(group='full_speed')

host/usb/test/target_test/usb_host/main/Kconfig.projbuild

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@ menu "USB Host Library Test"
2222
USB Host tests that check string descriptors will check the serial string descriptor
2323
of the connected device.
2424

25+
config USB_HOST_TEST_DEVICE_HAS_REMOTE_WAKEUP
26+
bool "Connected device has remote wakeup feature"
27+
default n
28+
help
29+
Run the remote wakeup test with a device which has, or which does not have remote wakeup functionality
30+
2531
endmenu

host/usb/test/target_test/usb_host/main/remote_wake_client.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,32 @@ void test_remote_wake_finish(void)
178178
* Following functions must not be called from the usb host client task, because a control transfer is sent by those functions
179179
*/
180180

181-
void test_remote_wake_enable(void)
181+
void test_remote_wake_enable(bool has_remote_wake)
182182
{
183183
ESP_LOGI(REMOTE_WAKE_CLIENT_TAG, "Remote wake enable");
184-
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_remote_wakeup_enable(s_remote_wake_obj->client_hdl, s_remote_wake_obj->dev_hdl, true));
184+
185+
esp_err_t ret = usb_host_device_remote_wakeup_enable(s_remote_wake_obj->client_hdl, s_remote_wake_obj->dev_hdl, true);
186+
TEST_ASSERT_EQUAL(ret, ((has_remote_wake) ? (ESP_OK) : (ESP_ERR_NOT_ALLOWED)));
185187
xSemaphoreGive(s_remote_wake_obj->test_param.dev_ready_smp);
186188
}
187189

188-
void test_remote_wake_disable(void)
190+
void test_remote_wake_disable(bool has_remote_wake)
189191
{
190192
ESP_LOGI(REMOTE_WAKE_CLIENT_TAG, "Remote wake disable");
191-
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_remote_wakeup_enable(s_remote_wake_obj->client_hdl, s_remote_wake_obj->dev_hdl, false));
193+
194+
esp_err_t ret = usb_host_device_remote_wakeup_enable(s_remote_wake_obj->client_hdl, s_remote_wake_obj->dev_hdl, false);
195+
TEST_ASSERT_EQUAL(ret, ((has_remote_wake) ? (ESP_OK) : (ESP_ERR_NOT_ALLOWED)));
192196
xSemaphoreGive(s_remote_wake_obj->test_param.dev_ready_smp);
193197
}
194198

195-
void test_remote_wake_check(bool expected_remote_wake)
199+
void test_remote_wake_check(bool expected_current_remote_wake, bool has_remote_wake)
196200
{
197201
ESP_LOGI(REMOTE_WAKE_CLIENT_TAG, "Remote wake check");
202+
198203
bool remote_wake_enabled = false;
199-
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_remote_wakeup_check(s_remote_wake_obj->client_hdl, s_remote_wake_obj->dev_hdl, &remote_wake_enabled));
200-
TEST_ASSERT_EQUAL_MESSAGE(expected_remote_wake, remote_wake_enabled, "Expected remote wakeup status not equal to the current status");
204+
esp_err_t ret = usb_host_device_remote_wakeup_check(s_remote_wake_obj->client_hdl, s_remote_wake_obj->dev_hdl, &remote_wake_enabled);
205+
TEST_ASSERT_EQUAL_MESSAGE(ret, ((has_remote_wake) ? (ESP_OK) : (ESP_ERR_NOT_ALLOWED)),
206+
"Unexpected remote wakeup check result");
207+
TEST_ASSERT_EQUAL_MESSAGE(expected_current_remote_wake, remote_wake_enabled, "Expected remote wakeup status not equal to the current status");
201208
xSemaphoreGive(s_remote_wake_obj->test_param.dev_ready_smp);
202209
}

0 commit comments

Comments
 (0)