@@ -831,6 +831,12 @@ static hcd_port_event_t _intr_hdlr_hprt(port_t *port, usb_dwc_hal_port_event_t h
831831 port -> flags .conn_dev_ena = 0 ;
832832 break ;
833833 }
834+ case USB_DWC_HAL_PORT_EVENT_REMOTE_WAKEUP : {
835+ //ESP_EARLY_LOGI(HCD_DWC_TAG, "WAKE");
836+ //port->state = HCD_PORT_STATE_ENABLED;
837+ port_event = HCD_PORT_EVENT_REMOTE_WAKEUP ;
838+ break ;
839+ }
834840 default : {
835841 abort ();
836842 break ;
@@ -1231,6 +1237,8 @@ static esp_err_t _port_cmd_power_on(port_t *port)
12311237 } else {
12321238 ret = ESP_ERR_INVALID_STATE ;
12331239 }
1240+ //esp_rom_printf("power on: HPRT = %lx\n", usb_dwc_hal_port_get_hprt_val(port->hal));
1241+ //esp_rom_printf("power on: GINTSTS = %lx\n", usb_dwc_hal_port_get_gintsts_val(port->hal));
12341242 return ret ;
12351243}
12361244
@@ -1326,19 +1334,21 @@ static esp_err_t _port_cmd_bus_suspend(port_t *port)
13261334 // Port must have been previously enabled, and all pipes must already be halted
13271335 if (!(port -> state == HCD_PORT_STATE_ENABLED && _port_check_all_pipes_halted (port ))) {
13281336 ret = ESP_ERR_INVALID_STATE ;
1337+ esp_rom_printf ("ERR1\n" );
13291338 goto exit ;
13301339 }
13311340
13321341 usb_dwc_hal_port_suspend (port -> hal );
13331342 port -> state = HCD_PORT_STATE_SUSPENDING ;
13341343
13351344 HCD_EXIT_CRITICAL ();
1336- vTaskDelay (pdMS_TO_TICKS (SUSPEND_ENTRY_MS ));
1345+ vTaskDelay (pdMS_TO_TICKS (100 ));
13371346 HCD_ENTER_CRITICAL ();
13381347
13391348 if (port -> state != HCD_PORT_STATE_SUSPENDING ) {
13401349 // Port state unexpectedly changed
13411350 ret = ESP_ERR_INVALID_RESPONSE ;
1351+ esp_rom_printf ("ERR2\n" );
13421352 goto exit ;
13431353 }
13441354
@@ -1350,6 +1360,7 @@ static esp_err_t _port_cmd_bus_suspend(port_t *port)
13501360 // Sanity check, the root port should have entered the suspended state after the SUSPEND_ENTRY_MS delay
13511361 if (!usb_dwc_ll_hprt_get_port_suspend (port -> hal -> dev )) {
13521362 ret = ESP_ERR_NOT_FINISHED ;
1363+ esp_rom_printf ("ERR3\n" );
13531364 goto exit ;
13541365 }
13551366
@@ -1362,17 +1373,36 @@ static esp_err_t _port_cmd_bus_suspend(port_t *port)
13621373
13631374static esp_err_t _port_cmd_bus_resume (port_t * port )
13641375{
1376+ uint32_t hprt , gintsts , state ;
13651377 esp_err_t ret ;
13661378 // Port can only be resumed if it was previously suspended
13671379 if (port -> state != HCD_PORT_STATE_SUSPENDED ) {
13681380 ret = ESP_ERR_INVALID_STATE ;
13691381 goto exit ;
13701382 }
1383+ hprt = usb_dwc_hal_port_get_hprt_val (port -> hal );
1384+ gintsts = usb_dwc_hal_port_get_gintsts_val (port -> hal );
1385+ state = usb_dwc_hal_hprt_get_pwr_line_status (port -> hal );
1386+
1387+ // Res1 (Wkp1)
1388+ esp_rom_printf ("HPRT: %lx\n" , hprt );
1389+ esp_rom_printf ("GINTSTS: %lx\n" , gintsts );
1390+ esp_rom_printf ("State %lx\n" , state );
1391+
13711392 // Put and hold the bus in the K state.
13721393 usb_dwc_hal_port_toggle_resume (port -> hal , true);
13731394 port -> state = HCD_PORT_STATE_RESUMING ;
13741395 HCD_EXIT_CRITICAL ();
1375- vTaskDelay (pdMS_TO_TICKS (RESUME_HOLD_MS ));
1396+ vTaskDelay (pdMS_TO_TICKS (50 ));
1397+
1398+ // Res2 (Wkp2)
1399+ hprt = usb_dwc_hal_port_get_hprt_val (port -> hal );
1400+ gintsts = usb_dwc_hal_port_get_gintsts_val (port -> hal );
1401+ state = usb_dwc_hal_hprt_get_pwr_line_status (port -> hal );
1402+ esp_rom_printf ("HPRT: %lx\n" , hprt );
1403+ esp_rom_printf ("GINTSTS: %lx\n" , gintsts );
1404+ esp_rom_printf ("State %lx\n" , state );
1405+
13761406 HCD_ENTER_CRITICAL ();
13771407 // Return and hold the bus to the J state (as port of the LS EOP)
13781408 usb_dwc_hal_port_toggle_resume (port -> hal , false);
@@ -1382,7 +1412,15 @@ static esp_err_t _port_cmd_bus_resume(port_t *port)
13821412 goto exit ;
13831413 }
13841414 HCD_EXIT_CRITICAL ();
1385- vTaskDelay (pdMS_TO_TICKS (RESUME_RECOVERY_MS ));
1415+ vTaskDelay (pdMS_TO_TICKS (100 ));
1416+
1417+ // Res3 (Wkp3)
1418+ hprt = usb_dwc_hal_port_get_hprt_val (port -> hal );
1419+ gintsts = usb_dwc_hal_port_get_gintsts_val (port -> hal );
1420+ state = usb_dwc_hal_hprt_get_pwr_line_status (port -> hal );
1421+ esp_rom_printf ("HPRT: %lx\n" , hprt );
1422+ esp_rom_printf ("GINTSTS: %lx\n" , gintsts );
1423+ esp_rom_printf ("State %lx\n" , state );
13861424 HCD_ENTER_CRITICAL ();
13871425 if (port -> state != HCD_PORT_STATE_RESUMING || !port -> flags .conn_dev_ena ) {
13881426 // Port state unexpectedly changed
@@ -1485,8 +1523,11 @@ esp_err_t hcd_port_deinit(hcd_port_handle_t port_hdl)
14851523 return ESP_OK ;
14861524}
14871525
1526+ static port_t * s_port ;
1527+
14881528esp_err_t hcd_port_command (hcd_port_handle_t port_hdl , hcd_port_cmd_t command )
14891529{
1530+ s_port = (port_t * )port_hdl ;
14901531 esp_err_t ret = ESP_ERR_INVALID_STATE ;
14911532 port_t * port = (port_t * )port_hdl ;
14921533 xSemaphoreTake (port -> port_mux , portMAX_DELAY );
@@ -2688,6 +2729,8 @@ static inline bool _check_port_pipe_state(pipe_t *pipe, bool *submit_urb)
26882729
26892730esp_err_t hcd_urb_enqueue (hcd_pipe_handle_t pipe_hdl , urb_t * urb )
26902731{
2732+ //esp_rom_printf("HPRT: %lx\n", usb_dwc_hal_port_get_hprt_val(s_port->hal));
2733+ //esp_rom_printf("power on: GINTSTS = %lx\n", usb_dwc_hal_port_get_gintsts_val(s_port->hal));
26912734 // Check that URB has not already been enqueued
26922735 HCD_CHECK (urb -> hcd_ptr == NULL && urb -> hcd_var == URB_HCD_STATE_IDLE , ESP_ERR_INVALID_STATE );
26932736 pipe_t * pipe = (pipe_t * )pipe_hdl ;
0 commit comments