@@ -146,10 +146,12 @@ Test port suspend and resume with active pipes
146146 - Trigger a port connection
147147 - Create a default pipe
148148 - Test that port can't be suspended with an active pipe
149+ - Ping a device (send get configuration descriptor transfer)
149150 - Halt the default pipe after a short delay
150151 - Suspend the port
151152 - Resume the port
152153 - Check that all the pipe is still halted
154+ - Ping a device
153155 - Cleanup default pipe
154156 - Trigger disconnection and teardown
155157*/
@@ -161,6 +163,9 @@ TEST_CASE("Test HCD port suspend and resume", "[port][low_speed][full_speed][hig
161163 // Allocate some URBs and initialize their data buffers with control transfers
162164 hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc (port_hdl , NULL , TEST_DEV_ADDR , port_speed ); // Create a default pipe (using a NULL EP descriptor)
163165
166+ urb_t * urb = test_hcd_alloc_urb (0 , URB_DATA_BUFF_SIZE );
167+ test_hcd_ping_device (default_pipe , urb );
168+
164169 // Test that suspending the port now fails as there is an active pipe
165170 TEST_ASSERT_EQUAL (ESP_ERR_INVALID_STATE , hcd_port_command (port_hdl , HCD_PORT_CMD_SUSPEND ));
166171
@@ -185,6 +190,8 @@ TEST_CASE("Test HCD port suspend and resume", "[port][low_speed][full_speed][hig
185190 TEST_ASSERT_EQUAL (HCD_PIPE_STATE_ACTIVE , hcd_pipe_get_state (default_pipe ));
186191 vTaskDelay (pdMS_TO_TICKS (100 )); // Give some time for resumed URBs to complete
187192
193+ test_hcd_ping_device (default_pipe , urb );
194+ test_hcd_free_urb (urb );
188195 test_hcd_pipe_free (default_pipe );
189196 // Cleanup
190197 test_hcd_wait_for_disconn (port_hdl , false);
@@ -197,17 +204,22 @@ Test port suspend and resume sudden disconnect
197204 - Test port suspend and resume procedure with sudden disconnect
198205 - When suspended, the port must react to power off command by disconnecting a device
199206 - When no device is connected, the port must NOT allow to enter and exit the suspended state
207+ - Test exiting suspend state through device disconnect
200208
201209Procedure:
202210 - Setup the HCD and a port
203211 - Trigger a port connection
204212 - Create a default pipe
213+ - Ping a device (send get configuration descriptor transfer)
205214 - Halt the default pipe after a short delay
206215 - Suspend the port
207216 - Cleanup default pipe
208217 - Power off the port and recover the port
209218 - Try to Suspend and Resume the port with no devices connected
210219 - Trigger connection and disconnection again (to make sure the port works post recovery)
220+ - Trigger connection again (to make sure the port works post recovery)
221+ - Ping a device
222+ - Trigger disconnection and cleanup
211223 - Teardown port and HCD
212224*/
213225TEST_CASE ("Test HCD port suspend and resume sudden disconnect" , "[port][low_speed][full_speed][high_speed]" )
@@ -218,8 +230,8 @@ TEST_CASE("Test HCD port suspend and resume sudden disconnect", "[port][low_spee
218230 // Allocate some URBs and initialize their data buffers with control transfers
219231 hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc (port_hdl , NULL , TEST_DEV_ADDR , port_speed ); // Create a default pipe (using a NULL EP descriptor)
220232
221- // Test that suspending the port now fails as there is an active pipe
222- TEST_ASSERT_EQUAL ( ESP_ERR_INVALID_STATE , hcd_port_command ( port_hdl , HCD_PORT_CMD_SUSPEND ) );
233+ urb_t * urb = test_hcd_alloc_urb ( 0 , URB_DATA_BUFF_SIZE );
234+ test_hcd_ping_device ( default_pipe , urb );
223235
224236 // Halt the default pipe before suspending
225237 TEST_ASSERT_EQUAL (HCD_PIPE_STATE_ACTIVE , hcd_pipe_get_state (default_pipe ));
@@ -240,7 +252,8 @@ TEST_CASE("Test HCD port suspend and resume sudden disconnect", "[port][low_spee
240252 TEST_ASSERT_EQUAL (HCD_PORT_STATE_RECOVERY , hcd_port_get_state (port_hdl ));
241253 printf ("Sudden disconnect\n" );
242254
243- // Free the pipe, to be able to recover the port
255+ // Free the pipe and its urb, to be able to recover the port
256+ test_hcd_free_urb (urb );
244257 test_hcd_pipe_free (default_pipe );
245258 // Recover the port should return to the NOT POWERED state
246259 TEST_ASSERT_EQUAL (ESP_OK , hcd_port_recover (port_hdl ));
@@ -250,8 +263,76 @@ TEST_CASE("Test HCD port suspend and resume sudden disconnect", "[port][low_spee
250263 TEST_ASSERT_EQUAL (ESP_ERR_INVALID_STATE , hcd_port_command (port_hdl , HCD_PORT_CMD_SUSPEND ));
251264 TEST_ASSERT_EQUAL (ESP_ERR_INVALID_STATE , hcd_port_command (port_hdl , HCD_PORT_CMD_RESUME ));
252265
253- // Recovered port should be able to connect and disconnect again
254- test_hcd_wait_for_conn (port_hdl );
266+ // Recovered port should be able to connect again
267+ port_speed = test_hcd_wait_for_conn (port_hdl );
268+ vTaskDelay (pdMS_TO_TICKS (100 )); // Short delay send of SOF (for FS, HS) or EOPs (for LS)
269+
270+ // Allocate some URBs and initialize their data buffers with control transfers
271+ default_pipe = test_hcd_pipe_alloc (port_hdl , NULL , TEST_DEV_ADDR , port_speed ); // Create a default pipe (using a NULL EP descriptor)
272+ urb = test_hcd_alloc_urb (0 , URB_DATA_BUFF_SIZE );
273+ test_hcd_ping_device (default_pipe , urb );
274+
275+ test_hcd_free_urb (urb );
276+ test_hcd_pipe_free (default_pipe );
277+ test_hcd_wait_for_disconn (port_hdl , false);
278+ }
279+
280+ /*
281+ Test port suspend and resume with port reset
282+
283+ Purpose:
284+ - Test port suspend and resume procedure with port reset
285+ - When suspended, the port must react to reset command
286+ - Test exiting suspend state through port reset
287+
288+ Procedure:
289+ - Setup the HCD and a port
290+ - Trigger a port connection
291+ - Create a default pipe
292+ - Ping a device (send get configuration descriptor transfer)
293+ - Halt the default pipe
294+ - Suspend the port
295+ - Reset and recover the port
296+ - Ping a device
297+ - Trigger disconnection and cleanup
298+ - Teardown port and HCD
299+ */
300+ TEST_CASE ("Test HCD port suspend and resume port reset" , "[port][low_speed][full_speed][high_speed]" )
301+ {
302+ usb_speed_t port_speed = test_hcd_wait_for_conn (port_hdl ); // Trigger a connection
303+ vTaskDelay (pdMS_TO_TICKS (100 )); // Short delay send of SOF (for FS, HS) or EOPs (for LS)
304+
305+ // Allocate some URBs and initialize their data buffers with control transfers
306+ hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc (port_hdl , NULL , TEST_DEV_ADDR , port_speed ); // Create a default pipe (using a NULL EP descriptor)
307+ urb_t * urb = test_hcd_alloc_urb (0 , URB_DATA_BUFF_SIZE );
308+ test_hcd_ping_device (default_pipe , urb );
309+
310+ // Halt the default pipe before suspending
311+ TEST_ASSERT_EQUAL (HCD_PIPE_STATE_ACTIVE , hcd_pipe_get_state (default_pipe ));
312+ TEST_ASSERT_EQUAL (ESP_OK , hcd_pipe_command (default_pipe , HCD_PIPE_CMD_HALT ));
313+ TEST_ASSERT_EQUAL (HCD_PIPE_STATE_HALTED , hcd_pipe_get_state (default_pipe ));
314+
315+ // Suspend the port
316+ TEST_ASSERT_EQUAL (ESP_OK , hcd_port_command (port_hdl , HCD_PORT_CMD_SUSPEND ));
317+ TEST_ASSERT_EQUAL (HCD_PORT_STATE_SUSPENDED , hcd_port_get_state (port_hdl ));
318+ printf ("Suspended\n" );
319+ vTaskDelay (pdMS_TO_TICKS (100 )); // Give some time for bus to remain suspended
320+
321+ // Reset the port
322+ TEST_ASSERT_EQUAL (ESP_OK , hcd_port_command (port_hdl , HCD_PORT_CMD_RESET ));
323+ printf ("Port reset\n" );
324+
325+ // Port should be in enabled state, and the default pipe still halted
326+ TEST_ASSERT_EQUAL (HCD_PORT_STATE_ENABLED , hcd_port_get_state (port_hdl ));
327+ TEST_ASSERT_EQUAL (HCD_PIPE_STATE_HALTED , hcd_pipe_get_state (default_pipe ));
328+ // Clear the pipe
329+ TEST_ASSERT_EQUAL (ESP_OK , hcd_pipe_command (default_pipe , HCD_PIPE_CMD_CLEAR ));
330+ TEST_ASSERT_EQUAL (HCD_PIPE_STATE_ACTIVE , hcd_pipe_get_state (default_pipe ));
331+
332+ test_hcd_ping_device (default_pipe , urb );
333+
334+ test_hcd_free_urb (urb );
335+ test_hcd_pipe_free (default_pipe );
255336 test_hcd_wait_for_disconn (port_hdl , false);
256337}
257338
0 commit comments