diff options
| author | hathach <[email protected]> | 2020-09-01 19:16:50 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2020-09-01 19:16:50 +0700 |
| commit | 84425c50b3bb5c892bfab9d094cc3da6a9c04da5 (patch) | |
| tree | 6e8a46cb5259ea57078381ea8c64c4c3e4b348ca /src | |
| parent | f4e3c6fd8ee125123e2cfa704d61dab34be576c5 (diff) | |
add more logging to host stack
tested host with lpc4357, don't use fpu with lpc m4 since it seems to
cause hardfault (stack does not make use of fpu anyway).
Diffstat (limited to 'src')
| -rw-r--r-- | src/class/msc/msc_host.c | 1 | ||||
| -rw-r--r-- | src/host/usbh.c | 44 | ||||
| -rw-r--r-- | src/host/usbh.h | 4 | ||||
| -rw-r--r-- | src/osal/osal.h | 4 |
4 files changed, 41 insertions, 12 deletions
diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 98c71eb70..3aa697b17 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -310,6 +310,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it (*p_length) += sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); //------------- Get Max Lun -------------// + TU_LOG2("MSC Get Max Lun\r\n"); tusb_control_request_t request = { .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_INTERFACE, .type = TUSB_REQ_TYPE_CLASS, .direction = TUSB_DIR_IN }, .bRequest = MSC_REQ_GET_MAX_LUN, diff --git a/src/host/usbh.c b/src/host/usbh.c index 8536cec0a..c5f28cf0e 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -42,10 +42,17 @@ //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ +#if CFG_TUSB_DEBUG >= 2 + #define DRIVER_NAME(_name) .name = _name, +#else + #define DRIVER_NAME(_name) +#endif + static host_class_driver_t const usbh_class_drivers[] = { #if CFG_TUH_CDC { + DRIVER_NAME("CDC") .class_code = TUSB_CLASS_CDC, .init = cdch_init, .open = cdch_open, @@ -56,6 +63,7 @@ static host_class_driver_t const usbh_class_drivers[] = #if CFG_TUH_MSC { + DRIVER_NAME("MSC") .class_code = TUSB_CLASS_MSC, .init = msch_init, .open = msch_open, @@ -66,6 +74,7 @@ static host_class_driver_t const usbh_class_drivers[] = #if HOST_CLASS_HID { + DRIVER_NAME("HID") .class_code = TUSB_CLASS_HID, .init = hidh_init, .open = hidh_open_subtask, @@ -76,6 +85,7 @@ static host_class_driver_t const usbh_class_drivers[] = #if CFG_TUH_HUB { + DRIVER_NAME("HUB") .class_code = TUSB_CLASS_HUB, .init = hub_init, .open = hub_open, @@ -86,6 +96,7 @@ static host_class_driver_t const usbh_class_drivers[] = #if CFG_TUH_VENDOR { + DRIVER_NAME("VENDOR") .class_code = TUSB_CLASS_VENDOR_SPECIFIC, .init = cush_init, .open = cush_open_subtask, @@ -131,7 +142,7 @@ static inline void osal_task_delay(uint32_t msec) { (void) msec; - uint32_t start = hcd_frame_number(TUH_OPT_RHPORT); + const uint32_t start = hcd_frame_number(TUH_OPT_RHPORT); while ( ( hcd_frame_number(TUH_OPT_RHPORT) - start ) < msec ) {} } @@ -162,7 +173,11 @@ bool usbh_init(void) } // Class drivers init - for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++) usbh_class_drivers[drv_id].init(); + for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++) + { + TU_LOG2("%s init\r\n", usbh_class_drivers[drv_id].name); + usbh_class_drivers[drv_id].init(); + } TU_ASSERT(hcd_init()); hcd_int_enable(TUH_OPT_RHPORT); @@ -269,6 +284,7 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev if (usbh_class_drivers[drv_id].isr) { + TU_LOG2("%s isr\r\n", usbh_class_drivers[drv_id].name); usbh_class_drivers[drv_id].isr(dev_addr, ep_addr, event, xferred_bytes); } else @@ -336,7 +352,11 @@ static void usbh_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t hub_ if (tuh_umount_cb) tuh_umount_cb(dev_addr); // Close class driver - for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++) usbh_class_drivers[drv_id].close(dev_addr); + for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++) + { + TU_LOG2("%s close\r\n", usbh_class_drivers[drv_id].name); + usbh_class_drivers[drv_id].close(dev_addr); + } memset(dev->itf2drv, 0xff, sizeof(dev->itf2drv)); // invalid mapping memset(dev->ep2drv , 0xff, sizeof(dev->ep2drv )); // invalid mapping @@ -381,7 +401,7 @@ bool enum_task(hcd_event_t* event) { if( hcd_port_connect_status(dev0->rhport) ) { - TU_LOG2("Connect \r\n"); + TU_LOG2("Device connect \r\n"); // connection event osal_task_delay(POWER_STABLE_DELAY); // wait until device is stable. Increase this if the first 8 bytes is failed to get @@ -396,7 +416,7 @@ bool enum_task(hcd_event_t* event) } else { - TU_LOG2("Disconnect \r\n"); + TU_LOG2("Device disconnect \r\n"); // disconnection event usbh_device_unplugged(dev0->rhport, 0, 0); @@ -451,7 +471,7 @@ bool enum_task(hcd_event_t* event) TU_ASSERT_ERR( usbh_pipe_control_open(0, 8) ); //------------- Get first 8 bytes of device descriptor to get Control Endpoint Size -------------// - TU_LOG2("Get 8 byte of Device Descriptor \r\n"); + TU_LOG2("Get 8 byte of Device Descriptor\r\n"); request = (tusb_control_request_t ) { .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_IN }, .bRequest = TUSB_REQ_GET_DESCRIPTOR, @@ -536,7 +556,7 @@ bool enum_task(hcd_event_t* event) TU_ASSERT(configure_selected <= new_dev->configure_count); // TODO notify application when invalid configuration //------------- Get 9 bytes of configuration descriptor -------------// - TU_LOG2("Get 9 bytes of Configuration Descriptor \r\n"); + TU_LOG2("Get 9 bytes of Configuration Descriptor\r\n"); request = (tusb_control_request_t ) { .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_IN }, .bRequest = TUSB_REQ_GET_DESCRIPTOR, @@ -550,7 +570,7 @@ bool enum_task(hcd_event_t* event) TU_ASSERT( CFG_TUSB_HOST_ENUM_BUFFER_SIZE >= ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength ); //------------- Get full configuration descriptor -------------// - TU_LOG2("Get full Configuration Descriptor \r\n"); + TU_LOG2("Get full Configuration Descriptor\r\n"); request.wLength = ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength; // full length TU_ASSERT( usbh_control_xfer( new_addr, &request, _usbh_ctrl_buf ) ); @@ -558,7 +578,7 @@ bool enum_task(hcd_event_t* event) new_dev->interface_count = ((tusb_desc_configuration_t*) _usbh_ctrl_buf)->bNumInterfaces; //------------- Set Configure -------------// - TU_LOG2("Set Configuration Descriptor \r\n"); + TU_LOG2("Set Configuration Descriptor\r\n"); request = (tusb_control_request_t ) { .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_OUT }, .bRequest = TUSB_REQ_SET_CONFIGURATION, @@ -568,6 +588,7 @@ bool enum_task(hcd_event_t* event) }; TU_ASSERT(usbh_control_xfer( new_addr, &request, NULL )); + TU_LOG2("Device configured\r\n"); new_dev->state = TUSB_DEVICE_STATE_CONFIGURED; //------------- TODO Get String Descriptors -------------// @@ -575,6 +596,8 @@ bool enum_task(hcd_event_t* event) //------------- parse configuration & install drivers -------------// uint8_t const* p_desc = _usbh_ctrl_buf + sizeof(tusb_desc_configuration_t); + TU_LOG2_MEM(_usbh_ctrl_buf, ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength, 0); + // parse each interfaces while( p_desc < _usbh_ctrl_buf + ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength ) { @@ -584,7 +607,7 @@ bool enum_task(hcd_event_t* event) p_desc = tu_desc_next(p_desc); // skip the descriptor, increase by the descriptor's length }else { - tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) p_desc; + tusb_desc_interface_t const* desc_itf = (tusb_desc_interface_t const*) p_desc; // Check if class is supported uint8_t drv_id; @@ -614,6 +637,7 @@ bool enum_task(hcd_event_t* event) { uint16_t itf_len = 0; + TU_LOG2("%s open\r\n", usbh_class_drivers[drv_id].name); TU_ASSERT( usbh_class_drivers[drv_id].open(new_dev->rhport, new_addr, desc_itf, &itf_len) ); TU_ASSERT( itf_len >= sizeof(tusb_desc_interface_t) ); p_desc += itf_len; diff --git a/src/host/usbh.h b/src/host/usbh.h index cc112d756..39e7a4e0d 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -52,6 +52,10 @@ typedef enum tusb_interface_status_{ } tusb_interface_status_t; typedef struct { + #if CFG_TUSB_DEBUG >= 2 + char const* name; + #endif + uint8_t class_code; void (* const init) (void); diff --git a/src/osal/osal.h b/src/osal/osal.h index c61f0c912..b5057ff4c 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -37,9 +37,9 @@ #include "common/tusb_common.h" // Return immediately -#define OSAL_TIMEOUT_NOTIMEOUT (0) +#define OSAL_TIMEOUT_NOTIMEOUT (0) // Default timeout -#define OSAL_TIMEOUT_NORMAL (10) +#define OSAL_TIMEOUT_NORMAL (10) // Wait forever #define OSAL_TIMEOUT_WAIT_FOREVER (UINT32_MAX) |
