diff --git a/demos/host/host_os_none/host_os_none.uvopt b/demos/host/host_os_none/host_os_none.uvopt index 2cf7205a..83c42778 100644 --- a/demos/host/host_os_none/host_os_none.uvopt +++ b/demos/host/host_os_none/host_os_none.uvopt @@ -460,7 +460,7 @@ 0 25 0 - 151 + 152 160 0 ..\src\main.c @@ -492,7 +492,7 @@ 0 0 0 - 127 + 128 135 0 ..\src\keyboard_app.c @@ -524,7 +524,7 @@ 0 1 0 - 53 + 66 86 0 ..\src\rndis_app.c @@ -556,7 +556,7 @@ 0 33 0 - 73 + 74 77 0 ..\src\cli.c @@ -612,7 +612,7 @@ 0 44 0 - 82 + 95 106 0 ..\..\bsp\boards\printf_retarget.c @@ -794,10 +794,10 @@ 1 0 0 - 24 + 0 0 1 - 11 + 1 0 ..\..\..\tinyusb\host\hub.c hub.c @@ -810,10 +810,10 @@ 1 0 0 - 0 + 19 0 1 - 1 + 18 0 ..\..\..\tinyusb\host\usbh.c usbh.c @@ -826,10 +826,10 @@ 1 0 0 - 56 + 0 0 - 562 - 578 + 1 + 1 0 ..\..\..\tinyusb\host\ehci\ehci.c ehci.c @@ -988,7 +988,7 @@ 0 0 0 - 240 + 241 249 0 ..\..\..\tinyusb\class\msc_host.c @@ -1060,7 +1060,7 @@ 0 3 0 - 572 + 573 580 0 ..\..\bsp\lpc43xx\CMSIS_LPC43xx_DriverLib\src\lpc43xx_cgu.c @@ -1116,7 +1116,7 @@ 0 0 0 - 145 + 146 151 0 ..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s @@ -1138,9 +1138,9 @@ 1 0 0 - 51 + 52 0 - 111 + 107 108 0 ..\..\..\vendor\fatfs\diskio.c diff --git a/demos/host/src/cdc_serial_app.c b/demos/host/src/cdc_serial_app.c index a6616964..a83c27ab 100644 --- a/demos/host/src/cdc_serial_app.c +++ b/demos/host/src/cdc_serial_app.c @@ -62,15 +62,16 @@ void tusbh_cdc_mounted_cb(uint8_t dev_addr) { // application set-up - printf("a CDC device is mounted\n"); + printf("\na CDC device is mounted\n"); osal_queue_flush(queue_hdl); tusbh_cdc_receive(dev_addr, buffer_in, sizeof(buffer_in), true); // first report } -void tusbh_cdc_unmounted_isr(uint8_t dev_addr) +void tusbh_cdc_unmounted_cb(uint8_t dev_addr) { // application tear-down + printf("\na CDC device is unmounted\n"); } void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes) diff --git a/demos/host/src/keyboard_app.c b/demos/host/src/keyboard_app.c index b0f92a2c..77cc0d63 100644 --- a/demos/host/src/keyboard_app.c +++ b/demos/host/src/keyboard_app.c @@ -71,15 +71,16 @@ void tusbh_hid_keyboard_mounted_cb(uint8_t dev_addr) { // application set-up - printf("a keyboard device is mounted\n"); + puts("\na Keyboard device is mounted"); osal_queue_flush(queue_kbd_hdl); tusbh_hid_keyboard_get_report(dev_addr, (uint8_t*) &usb_keyboard_report); // first report } -void tusbh_hid_keyboard_unmounted_isr(uint8_t dev_addr) +void tusbh_hid_keyboard_unmounted_cb(uint8_t dev_addr) { // application tear-down + puts("\na Keyboard device is unmounted"); } void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event) diff --git a/demos/host/src/mouse_app.c b/demos/host/src/mouse_app.c index af0dfc83..e3709091 100644 --- a/demos/host/src/mouse_app.c +++ b/demos/host/src/mouse_app.c @@ -71,15 +71,16 @@ void tusbh_hid_mouse_mounted_cb(uint8_t dev_addr) { // application set-up - printf("a mouse device is mounted\n"); + puts("\na Mouse device is mounted"); osal_queue_flush(queue_mouse_hdl); (void) tusbh_hid_mouse_get_report(dev_addr, (uint8_t*) &usb_mouse_report); // first report } -void tusbh_hid_mouse_unmounted_isr(uint8_t dev_addr) +void tusbh_hid_mouse_unmounted_cb(uint8_t dev_addr) { // application tear-down + puts("\na Mouse device is unmounted\n"); } void tusbh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event) diff --git a/demos/host/src/msc_app.c b/demos/host/src/msc_app.c index e5101caf..99b41814 100644 --- a/demos/host/src/msc_app.c +++ b/demos/host/src/msc_app.c @@ -65,7 +65,7 @@ static FATFS fatfs[TUSB_CFG_HOST_DEVICE_MAX] TUSB_CFG_ATTR_USBRAM; //--------------------------------------------------------------------+ void tusbh_msc_mounted_cb(uint8_t dev_addr) { - printf("an msc device is mounted\n"); + puts("\na MassStorage device is mounted"); //------------- Disk Information -------------// // SCSI VendorID[8] & ProductID[16] from Inquiry Command @@ -110,11 +110,11 @@ void tusbh_msc_mounted_cb(uint8_t dev_addr) } } -void tusbh_msc_unmounted_isr(uint8_t dev_addr) +void tusbh_msc_unmounted_cb(uint8_t dev_addr) { // unmount disk disk_state[dev_addr-1] = STA_NOINIT; - puts("--"); + puts("\na MassStorage device is unmounted"); } void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes) diff --git a/demos/host/src/rndis_app.c b/demos/host/src/rndis_app.c index d0027ea9..9b75a3c3 100644 --- a/demos/host/src/rndis_app.c +++ b/demos/host/src/rndis_app.c @@ -51,7 +51,7 @@ void tusbh_cdc_rndis_mounted_cb(uint8_t dev_addr) { // application set-up uint8_t mac_address[6]; - printf("a RNDIS device is mounted\n"); + printf("\nan RNDIS device is mounted\n"); tusbh_cdc_rndis_get_mac_addr(dev_addr, mac_address); printf("MAC Address "); @@ -59,9 +59,10 @@ void tusbh_cdc_rndis_mounted_cb(uint8_t dev_addr) printf("\n"); } -void tusbh_cdc_rndis_unmounted_isr(uint8_t dev_addr) +void tusbh_cdc_rndis_unmounted_cb(uint8_t dev_addr) { // application tear-down + printf("\nan RNDIS device is unmounted\n"); } void rndis_app_init(void) diff --git a/tests/lpc18xx_43xx/test/host/usbh/test_usbh.c b/tests/lpc18xx_43xx/test/host/usbh/test_usbh.c index 961d836d..3b93742c 100644 --- a/tests/lpc18xx_43xx/test/host/usbh/test_usbh.c +++ b/tests/lpc18xx_43xx/test/host/usbh/test_usbh.c @@ -149,7 +149,7 @@ void test_usbh_device_unplugged_isr_device_not_previously_mounted(void) usbh_devices[dev_addr].hub_addr = 0; usbh_devices[dev_addr].hub_port = 0; - usbh_device_unplugged_isr(0); + usbh_hcd_rhport_unplugged_isr(0); } void test_usbh_device_unplugged_isr(void) @@ -166,7 +166,7 @@ void test_usbh_device_unplugged_isr(void) hcd_pipe_control_close_ExpectAndReturn(dev_addr, TUSB_ERROR_NONE); //------------- Code Under Test -------------// - usbh_device_unplugged_isr(0); + usbh_hcd_rhport_unplugged_isr(0); TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, usbh_devices[dev_addr].state); } @@ -188,7 +188,7 @@ void test_usbh_device_unplugged_multple_class(void) hcd_pipe_control_close_ExpectAndReturn(dev_addr, TUSB_ERROR_NONE); //------------- Code Under Test -------------// - usbh_device_unplugged_isr(0); + usbh_hcd_rhport_unplugged_isr(0); TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, usbh_devices[dev_addr].state); diff --git a/tinyusb/class/cdc_host.c b/tinyusb/class/cdc_host.c index 1fae8d66..f5488948 100644 --- a/tinyusb/class/cdc_host.c +++ b/tinyusb/class/cdc_host.c @@ -266,7 +266,7 @@ void cdch_close(uint8_t dev_addr) memclr_(p_cdc, sizeof(cdch_data_t)); - tusbh_cdc_unmounted_isr(dev_addr); + tusbh_cdc_unmounted_cb(dev_addr); } diff --git a/tinyusb/class/cdc_host.h b/tinyusb/class/cdc_host.h index dfc1eba7..f5add34d 100644 --- a/tinyusb/class/cdc_host.h +++ b/tinyusb/class/cdc_host.h @@ -71,7 +71,7 @@ tusb_error_t tusbh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t lengt //------------- CDC Application Callback -------------// void tusbh_cdc_mounted_cb(uint8_t dev_addr); -void tusbh_cdc_unmounted_isr(uint8_t dev_addr); +void tusbh_cdc_unmounted_cb(uint8_t dev_addr); void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes); @@ -84,7 +84,7 @@ tusb_error_t tusbh_cdc_rndis_get_mac_addr(uint8_t dev_addr, uint8_t mac_address[ //------------- RNDIS Application Callback (overshadow CDC callbacks) -------------// void tusbh_cdc_rndis_mounted_cb(uint8_t dev_addr); -void tusbh_cdc_rndis_unmounted_isr(uint8_t dev_addr); +void tusbh_cdc_rndis_unmounted_cb(uint8_t dev_addr); void tusbh_cdc_rndis_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes); diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c index b968c445..0c7d4dc0 100644 --- a/tinyusb/class/hid_host.c +++ b/tinyusb/class/hid_host.c @@ -282,7 +282,7 @@ void hidh_close(uint8_t dev_addr) if ( pipehandle_is_valid( keyboardh_data[dev_addr-1].pipe_hdl ) ) { hidh_interface_close(dev_addr, &keyboardh_data[dev_addr-1]); - tusbh_hid_keyboard_unmounted_isr(dev_addr); + tusbh_hid_keyboard_unmounted_cb(dev_addr); } #endif @@ -290,7 +290,7 @@ void hidh_close(uint8_t dev_addr) if( pipehandle_is_valid( mouseh_data[dev_addr-1].pipe_hdl ) ) { hidh_interface_close(dev_addr, &mouseh_data[dev_addr-1]); - tusbh_hid_mouse_unmounted_isr( dev_addr ); + tusbh_hid_mouse_unmounted_cb( dev_addr ); } #endif diff --git a/tinyusb/class/hid_host.h b/tinyusb/class/hid_host.h index d0179a9b..0c84bfbc 100644 --- a/tinyusb/class/hid_host.h +++ b/tinyusb/class/hid_host.h @@ -66,7 +66,7 @@ tusb_error_t tusbh_hid_keyboard_get_report(uint8_t dev_addr, void * report) /*A //------------- Application Callback -------------// void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event); void tusbh_hid_keyboard_mounted_cb(uint8_t dev_addr); -void tusbh_hid_keyboard_unmounted_isr(uint8_t dev_addr); +void tusbh_hid_keyboard_unmounted_cb(uint8_t dev_addr); //--------------------------------------------------------------------+ // MOUSE Application API @@ -78,7 +78,7 @@ tusb_error_t tusbh_hid_mouse_get_report(uint8_t dev_addr, void* report) /*ATTR_ //------------- Application Callback -------------// void tusbh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event); void tusbh_hid_mouse_mounted_cb(uint8_t dev_addr); -void tusbh_hid_mouse_unmounted_isr(uint8_t dev_addr); +void tusbh_hid_mouse_unmounted_cb(uint8_t dev_addr); //--------------------------------------------------------------------+ // GENERIC Application API diff --git a/tinyusb/class/msc_host.c b/tinyusb/class/msc_host.c index 14c6bb5e..df41a599 100644 --- a/tinyusb/class/msc_host.c +++ b/tinyusb/class/msc_host.c @@ -427,7 +427,7 @@ void msch_close(uint8_t dev_addr) memclr_(&msch_data[dev_addr-1], sizeof(msch_interface_t)); osal_semaphore_reset(msch_sem_hdl); - tusbh_msc_unmounted_isr(dev_addr); // invoke Application Callback + tusbh_msc_unmounted_cb(dev_addr); // invoke Application Callback } //--------------------------------------------------------------------+ diff --git a/tinyusb/class/msc_host.h b/tinyusb/class/msc_host.h index 83409f85..4dbb3ef6 100644 --- a/tinyusb/class/msc_host.h +++ b/tinyusb/class/msc_host.h @@ -80,7 +80,7 @@ tusb_error_t tusbh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, msc_cmd_st //------------- Application Callback -------------// void tusbh_msc_mounted_cb(uint8_t dev_addr); -void tusbh_msc_unmounted_isr(uint8_t dev_addr); +void tusbh_msc_unmounted_cb(uint8_t dev_addr); void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes); diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index 9cebff79..756c7dcb 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -564,11 +564,11 @@ static void port_connect_status_change_isr(uint8_t hostid) // NOTE There is an sequence plug->unplug->…..-> plug if device is powering with pre-plugged device if (regs->portsc_bit.current_connect_status) { - usbh_device_plugged_isr(hostid, 0, 0); + usbh_hcd_rhport_plugged_isr(hostid, 0, 0); }else // device unplugged { usbh_hcd_rhport_unplugged_isr(hostid); - regs->usb_cmd_bit.advacne_async = 1; // Async doorbell check EHCI 4.8.2 for operational details +// regs->usb_cmd_bit.advacne_async = 1; // Async doorbell check EHCI 4.8.2 for operational details } } diff --git a/tinyusb/host/hub.c b/tinyusb/host/hub.c index b4f1baf0..e72a0ac5 100644 --- a/tinyusb/host/hub.c +++ b/tinyusb/host/hub.c @@ -210,7 +210,7 @@ void hub_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes) if ( BIT_TEST_(p_hub->status_change, port) ) { // TODO HUB connection/disconnection will be determined in enum task --> connect change - usbh_device_plugged_isr(usbh_devices[pipe_hdl.dev_addr].core_id, pipe_hdl.dev_addr, port); + usbh_hcd_rhport_plugged_isr(usbh_devices[pipe_hdl.dev_addr].core_id, pipe_hdl.dev_addr, port); } } diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index 929c87b0..dcb4e73a 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -273,16 +273,21 @@ void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t even } } -void usbh_device_plugged_isr(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port) +void usbh_hcd_rhport_plugged_isr(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port) { osal_queue_send(enum_queue_hdl, - &(usbh_enumerate_t){ .core_id = hostid, .hub_addr = hub_addr, .hub_port = hub_port} ); + &(usbh_enumerate_t){ + .core_id = hostid, + .hub_addr = hub_addr, + .hub_port = hub_port} + ); } // a device unplugged on hostid, hub_addr, hub_port // return true if found and unmounted device, false if cannot find -bool usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port) +void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port) { + bool is_found = false; //------------- find the all devices (star-network) under port that is unplugged -------------// for (uint8_t dev_addr = 0; dev_addr <= TUSB_CFG_HOST_DEVICE_MAX; dev_addr ++) { @@ -306,15 +311,24 @@ bool usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port) // HCD must set this device's state to TUSB_DEVICE_STATE_UNPLUG when done usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_REMOVING; usbh_devices[dev_addr].flag_supported_class = 0; + + is_found = true; } } - return true; + if (is_found) hcd_hub_advance_asyn(usbh_devices[0].core_id); // TODO hack + } void usbh_hcd_rhport_unplugged_isr(uint8_t hostid) { - (void) usbh_device_unplugged(hostid, 0, 0); + osal_queue_send(enum_queue_hdl, + &(usbh_enumerate_t) + { + .core_id = hostid, + .hub_addr = 0, + .hub_port = 0 + } ); } //--------------------------------------------------------------------+ @@ -353,8 +367,23 @@ tusb_error_t enumeration_body_subtask(void) usbh_devices[0].hub_port = enum_entry.hub_port; usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG; - if ( usbh_devices[0].hub_addr != 0) // connected/disconnected via hub - { + if ( usbh_devices[0].hub_addr == 0) + { // connected/disconnected directly with roothub + if( hcd_port_connect_status(usbh_devices[0].core_id) ) + { // connection event + osal_task_delay(200); // wait for device is stable + hcd_port_reset( usbh_devices[0].core_id ); // port must be reset to have correct speed operation + // osal_task_delay(50); // TODO reset is recommended to last 50 ms (NXP EHCI passes this) + usbh_devices[0].speed = hcd_port_speed_get( usbh_devices[0].core_id ); + } + else + { // disconnection event + usbh_device_unplugged(usbh_devices[0].core_id, 0, 0); + SUBTASK_EXIT(TUSB_ERROR_NONE); // restart task + } + } + else + { // connected/disconnected via hub //------------- Get Port Status -------------// OSAL_SUBTASK_INVOKED_AND_WAIT( usbh_control_xfer_subtask( usbh_devices[0].hub_addr, bm_request_type(TUSB_DIR_DEV_TO_HOST, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_OTHER), @@ -370,17 +399,14 @@ tusb_error_t enumeration_body_subtask(void) if ( ! ((hub_port_status_response_t *) enum_data_buffer)->status_change.connect_status ) SUBTASK_EXIT(TUSB_ERROR_NONE); // only handle connection change if ( ! ((hub_port_status_response_t *) enum_data_buffer)->status_current.connect_status ) - { // Device is disconnected via Hub - if ( usbh_device_unplugged(usbh_devices[0].core_id, usbh_devices[0].hub_addr, usbh_devices[0].hub_port) ) - { - hcd_hub_advance_asyn(usbh_devices[0].core_id); // TODO hack - } + { // Disconnection event + usbh_device_unplugged(usbh_devices[0].core_id, usbh_devices[0].hub_addr, usbh_devices[0].hub_port); (void) hub_status_pipe_queue( usbh_devices[0].hub_addr ); // done with hub, waiting for next data on status pipe SUBTASK_EXIT(TUSB_ERROR_NONE); // restart task } else - { // Device is connected via Hub + { // Connection Event OSAL_SUBTASK_INVOKED_AND_WAIT ( hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port), error ); SUBTASK_ASSERT_STATUS( error ); @@ -390,14 +416,6 @@ tusb_error_t enumeration_body_subtask(void) OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE), error ); } } - else - { - SUBTASK_ASSERT( hcd_port_connect_status(usbh_devices[0].core_id) ); // ensure device is still plugged - osal_task_delay(200); // wait for device is stable - hcd_port_reset( usbh_devices[0].core_id ); // port must be reset to have correct speed operation - // osal_task_delay(50); // TODO reset is recommended to last 50 ms (NXP EHCI passes this) - usbh_devices[0].speed = hcd_port_speed_get( usbh_devices[0].core_id ); - } SUBTASK_ASSERT_STATUS( usbh_pipe_control_open(0, 8) ); usbh_devices[0].state = TUSB_DEVICE_STATE_ADDRESSED; diff --git a/tinyusb/host/usbh_hcd.h b/tinyusb/host/usbh_hcd.h index d364dac0..f4e7c7a8 100644 --- a/tinyusb/host/usbh_hcd.h +++ b/tinyusb/host/usbh_hcd.h @@ -115,7 +115,7 @@ extern usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; // including // callback from HCD ISR //--------------------------------------------------------------------+ void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t event, uint32_t xferred_bytes); -void usbh_device_plugged_isr(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port); +void usbh_hcd_rhport_plugged_isr(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port); void usbh_hcd_rhport_unplugged_isr(uint8_t hostid); #ifdef __cplusplus