Skip to content

Commit cb2af4c

Browse files
committed
minor debug log
1 parent d1ea384 commit cb2af4c

File tree

3 files changed

+63
-43
lines changed

3 files changed

+63
-43
lines changed

src/class/cdc/cdc_host.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333

3434
#include "cdc_host.h"
3535

36+
37+
// Debug level, TUSB_CFG_DEBUG must be at least this level for debug message
38+
#define CDCH_DEBUG 2
39+
40+
#define TU_LOG_CDCH(...) TU_LOG(CDCH_DEBUG, __VA_ARGS__)
41+
3642
//--------------------------------------------------------------------+
3743
// MACRO CONSTANT TYPEDEF
3844
//--------------------------------------------------------------------+
@@ -348,6 +354,8 @@ bool tuh_cdc_set_control_line_state(uint8_t idx, uint16_t line_state, tuh_xfer_c
348354
cdch_interface_t* p_cdc = get_itf(idx);
349355
TU_VERIFY(p_cdc && p_cdc->acm_capability.support_line_request);
350356

357+
TU_LOG_CDCH("CDC Set Control Line State\r\n");
358+
351359
tusb_control_request_t const request =
352360
{
353361
.bmRequestType_bit =

src/class/msc/msc_host.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333

3434
#include "msc_host.h"
3535

36+
// Debug level, TUSB_CFG_DEBUG must be at least this level for debug message
37+
#define MSCH_DEBUG 2
38+
39+
#define TU_LOG_MSCH(...) TU_LOG(MSCH_DEBUG, __VA_ARGS__)
40+
3641
//--------------------------------------------------------------------+
3742
// MACRO CONSTANT TYPEDEF
3843
//--------------------------------------------------------------------+
@@ -417,7 +422,7 @@ bool msch_set_config(uint8_t dev_addr, uint8_t itf_num)
417422
p_msc->configured = true;
418423

419424
//------------- Get Max Lun -------------//
420-
TU_LOG2("MSC Get Max Lun\r\n");
425+
TU_LOG_MSCH("MSC Get Max Lun\r\n");
421426
tusb_control_request_t const request =
422427
{
423428
.bmRequestType_bit =
@@ -456,7 +461,7 @@ static void config_get_maxlun_complete (tuh_xfer_t* xfer)
456461
p_msc->max_lun++; // MAX LUN is minus 1 by specs
457462

458463
// TODO multiple LUN support
459-
TU_LOG2("SCSI Test Unit Ready\r\n");
464+
TU_LOG_MSCH("SCSI Test Unit Ready\r\n");
460465
uint8_t const lun = 0;
461466
tuh_msc_test_unit_ready(daddr, lun, config_test_unit_ready_complete, 0);
462467
}
@@ -469,14 +474,14 @@ static bool config_test_unit_ready_complete(uint8_t dev_addr, tuh_msc_complete_d
469474
if (csw->status == 0)
470475
{
471476
// Unit is ready, read its capacity
472-
TU_LOG2("SCSI Read Capacity\r\n");
477+
TU_LOG_MSCH("SCSI Read Capacity\r\n");
473478
tuh_msc_read_capacity(dev_addr, cbw->lun, (scsi_read_capacity10_resp_t*) ((void*) _msch_buffer), config_read_capacity_complete, 0);
474479
}else
475480
{
476481
// Note: During enumeration, some device fails Test Unit Ready and require a few retries
477482
// with Request Sense to start working !!
478483
// TODO limit number of retries
479-
TU_LOG2("SCSI Request Sense\r\n");
484+
TU_LOG_MSCH("SCSI Request Sense\r\n");
480485
TU_ASSERT(tuh_msc_request_sense(dev_addr, cbw->lun, _msch_buffer, config_request_sense_complete, 0));
481486
}
482487

src/host/usbh.c

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@
4646
#define CFG_TUH_INTERFACE_MAX 8
4747
#endif
4848

49-
// Debug level of USBD
50-
#define USBH_DBG_LVL 2
49+
// Debug level, TUSB_CFG_DEBUG must be at least this level for debug message
50+
#define USBH_DEBUG 2
51+
52+
#define TU_LOG_USBH(...) TU_LOG(USBH_DEBUG, __VA_ARGS__)
5153

5254
//--------------------------------------------------------------------+
5355
// USBH-HCD common data structure
@@ -324,11 +326,11 @@ bool tuh_init(uint8_t controller_id)
324326
// skip if already initialized
325327
if ( tuh_inited() ) return true;
326328

327-
TU_LOG2("USBH init on controller %u\r\n", controller_id);
328-
TU_LOG2_INT(sizeof(usbh_device_t));
329-
TU_LOG2_INT(sizeof(hcd_event_t));
330-
TU_LOG2_INT(sizeof(_ctrl_xfer));
331-
TU_LOG2_INT(sizeof(tuh_xfer_t));
329+
TU_LOG_USBH("USBH init on controller %u\r\n", controller_id);
330+
TU_LOG_INT(USBH_DEBUG, sizeof(usbh_device_t));
331+
TU_LOG_INT(USBH_DEBUG, sizeof(hcd_event_t));
332+
TU_LOG_INT(USBH_DEBUG, sizeof(_ctrl_xfer));
333+
TU_LOG_INT(USBH_DEBUG, sizeof(tuh_xfer_t));
332334

333335
// Event queue
334336
_usbh_q = osal_queue_create( &_usbh_qdef );
@@ -353,7 +355,7 @@ bool tuh_init(uint8_t controller_id)
353355
// Class drivers
354356
for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++)
355357
{
356-
TU_LOG2("%s init\r\n", usbh_class_drivers[drv_id].name);
358+
TU_LOG_USBH("%s init\r\n", usbh_class_drivers[drv_id].name);
357359
usbh_class_drivers[drv_id].init();
358360
}
359361

@@ -401,12 +403,12 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
401403
case HCD_EVENT_DEVICE_ATTACH:
402404
// TODO due to the shared _usbh_ctrl_buf, we must complete enumerating
403405
// one device before enumerating another one.
404-
TU_LOG2("[%u:] USBH DEVICE ATTACH\r\n", event.rhport);
406+
TU_LOG_USBH("[%u:] USBH DEVICE ATTACH\r\n", event.rhport);
405407
enum_new_device(&event);
406408
break;
407409

408410
case HCD_EVENT_DEVICE_REMOVE:
409-
TU_LOG2("[%u:%u:%u] USBH DEVICE REMOVED\r\n", event.rhport, event.connection.hub_addr, event.connection.hub_port);
411+
TU_LOG_USBH("[%u:%u:%u] USBH DEVICE REMOVED\r\n", event.rhport, event.connection.hub_addr, event.connection.hub_port);
410412
process_device_unplugged(event.rhport, event.connection.hub_addr, event.connection.hub_port);
411413

412414
#if CFG_TUH_HUB
@@ -425,7 +427,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
425427
uint8_t const epnum = tu_edpt_number(ep_addr);
426428
uint8_t const ep_dir = tu_edpt_dir(ep_addr);
427429

428-
TU_LOG2("on EP %02X with %u bytes\r\n", ep_addr, (unsigned int) event.xfer_complete.len);
430+
TU_LOG_USBH("on EP %02X with %u bytes\r\n", ep_addr, (unsigned int) event.xfer_complete.len);
429431

430432
if (event.dev_addr == 0)
431433
{
@@ -449,7 +451,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
449451
uint8_t drv_id = dev->ep2drv[epnum][ep_dir];
450452
if(drv_id < USBH_CLASS_DRIVER_COUNT)
451453
{
452-
TU_LOG2("%s xfer callback\r\n", usbh_class_drivers[drv_id].name);
454+
TU_LOG_USBH("%s xfer callback\r\n", usbh_class_drivers[drv_id].name);
453455
usbh_class_drivers[drv_id].xfer_cb(event.dev_addr, ep_addr, event.xfer_complete.result, event.xfer_complete.len);
454456
}
455457
else
@@ -539,9 +541,11 @@ bool tuh_control_xfer (tuh_xfer_t* xfer)
539541
TU_VERIFY(is_idle);
540542
const uint8_t rhport = usbh_get_rhport(daddr);
541543

542-
TU_LOG2("[%u:%u] %s: ", rhport, daddr, xfer->setup->bRequest <= TUSB_REQ_SYNCH_FRAME ? tu_str_std_request[xfer->setup->bRequest] : "Unknown Request");
543-
TU_LOG2_PTR(xfer->setup);
544-
TU_LOG2("\r\n");
544+
TU_LOG_USBH("[%u:%u] %s: ", rhport, daddr,
545+
(xfer->setup->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD && xfer->setup->bRequest <= TUSB_REQ_SYNCH_FRAME) ?
546+
tu_str_std_request[xfer->setup->bRequest] : "Class Request");
547+
TU_LOG_PTR(USBH_DEBUG, xfer->setup);
548+
TU_LOG_USBH("\r\n");
545549

546550
if (xfer->complete_cb)
547551
{
@@ -585,7 +589,7 @@ TU_ATTR_ALWAYS_INLINE static inline void _set_control_xfer_stage(uint8_t stage)
585589

586590
static void _xfer_complete(uint8_t daddr, xfer_result_t result)
587591
{
588-
TU_LOG2("\r\n");
592+
TU_LOG_USBH("\r\n");
589593

590594
// duplicate xfer since user can execute control transfer within callback
591595
tusb_control_request_t const request = _ctrl_xfer.request;
@@ -643,8 +647,8 @@ static bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result
643647
case CONTROL_STAGE_DATA:
644648
if (request->wLength)
645649
{
646-
TU_LOG2("[%u:%u] Control data:\r\n", rhport, dev_addr);
647-
TU_LOG2_MEM(_ctrl_xfer.buffer, xferred_bytes, 2);
650+
TU_LOG_USBH("[%u:%u] Control data:\r\n", rhport, dev_addr);
651+
TU_LOG_MEM(USBH_DEBUG, _ctrl_xfer.buffer, xferred_bytes, 2);
648652
}
649653

650654
_ctrl_xfer.actual_len = (uint16_t) xferred_bytes;
@@ -760,7 +764,7 @@ bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t * b
760764
uint8_t const dir = tu_edpt_dir(ep_addr);
761765
tu_edpt_state_t* ep_state = &dev->ep_status[epnum][dir];
762766

763-
TU_LOG2(" Queue EP %02X with %u bytes ... ", ep_addr, total_bytes);
767+
TU_LOG_USBH(" Queue EP %02X with %u bytes ... ", ep_addr, total_bytes);
764768

765769
// Attempt to transfer on a busy endpoint, sound like an race condition !
766770
TU_ASSERT(ep_state->busy == 0);
@@ -776,7 +780,7 @@ bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t * b
776780

777781
if ( hcd_edpt_xfer(dev->rhport, dev_addr, ep_addr, buffer, total_bytes) )
778782
{
779-
TU_LOG2("OK\r\n");
783+
TU_LOG_USBH("OK\r\n");
780784
return true;
781785
}else
782786
{
@@ -791,7 +795,7 @@ bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t * b
791795

792796
static bool usbh_edpt_control_open(uint8_t dev_addr, uint8_t max_packet_size)
793797
{
794-
TU_LOG2("[%u:%u] Open EP0 with Size = %u\r\n", usbh_get_rhport(dev_addr), dev_addr, max_packet_size);
798+
TU_LOG_USBH("[%u:%u] Open EP0 with Size = %u\r\n", usbh_get_rhport(dev_addr), dev_addr, max_packet_size);
795799

796800
tusb_desc_endpoint_t ep0_desc =
797801
{
@@ -960,7 +964,7 @@ bool tuh_descriptor_get_serial_string(uint8_t daddr, uint16_t language_id, void*
960964
bool tuh_descriptor_get_hid_report(uint8_t daddr, uint8_t itf_num, uint8_t desc_type, uint8_t index, void* buffer, uint16_t len,
961965
tuh_xfer_cb_t complete_cb, uintptr_t user_data)
962966
{
963-
TU_LOG2("HID Get Report Descriptor\r\n");
967+
TU_LOG_USBH("HID Get Report Descriptor\r\n");
964968
tusb_control_request_t const request =
965969
{
966970
.bmRequestType_bit =
@@ -999,7 +1003,7 @@ bool tuh_descriptor_get_hid_report(uint8_t daddr, uint8_t itf_num, uint8_t desc_
9991003
bool tuh_configuration_set(uint8_t daddr, uint8_t config_num,
10001004
tuh_xfer_cb_t complete_cb, uintptr_t user_data)
10011005
{
1002-
TU_LOG2("Set Configuration = %d\r\n", config_num);
1006+
TU_LOG_USBH("Set Configuration = %d\r\n", config_num);
10031007

10041008
tusb_control_request_t const request =
10051009
{
@@ -1103,11 +1107,11 @@ static void process_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t h
11031107
(hub_port == 0 || dev->hub_port == hub_port) && // hub_port = 0 means all devices of downstream hub
11041108
dev->connected)
11051109
{
1106-
TU_LOG2(" Address = %u\r\n", dev_addr);
1110+
TU_LOG_USBH(" Address = %u\r\n", dev_addr);
11071111

11081112
if (is_hub_addr(dev_addr))
11091113
{
1110-
TU_LOG(USBH_DBG_LVL, "HUB address = %u is unmounted\r\n", dev_addr);
1114+
TU_LOG(USBH_DEBUG, "HUB address = %u is unmounted\r\n", dev_addr);
11111115
// If the device itself is a usb hub, unplug downstream devices.
11121116
// FIXME un-roll recursive calls to prevent potential stack overflow
11131117
process_device_unplugged(rhport, dev_addr, 0);
@@ -1120,7 +1124,7 @@ static void process_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t h
11201124
// Close class driver
11211125
for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++)
11221126
{
1123-
TU_LOG2("%s close\r\n", usbh_class_drivers[drv_id].name);
1127+
TU_LOG_USBH("%s close\r\n", usbh_class_drivers[drv_id].name);
11241128
usbh_class_drivers[drv_id].close(dev_addr);
11251129
}
11261130

@@ -1245,7 +1249,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
12451249
TU_ASSERT( usbh_edpt_control_open(addr0, 8), );
12461250

12471251
// Get first 8 bytes of device descriptor for Control Endpoint size
1248-
TU_LOG2("Get 8 byte of Device Descriptor\r\n");
1252+
TU_LOG_USBH("Get 8 byte of Device Descriptor\r\n");
12491253
TU_ASSERT(tuh_descriptor_get_device(addr0, _usbh_ctrl_buf, 8, process_enumeration, ENUM_SET_ADDR), );
12501254
}
12511255
break;
@@ -1254,7 +1258,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
12541258
case ENUM_RESET_2:
12551259
// TODO not used by now, but may be needed for some devices !?
12561260
// Reset device again before Set Address
1257-
TU_LOG2("Port reset2 \r\n");
1261+
TU_LOG_USBH("Port reset2 \r\n");
12581262
if (_dev0.hub_addr == 0)
12591263
{
12601264
// connected directly to roothub
@@ -1294,7 +1298,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
12941298
TU_ASSERT( usbh_edpt_control_open(new_addr, new_dev->ep0_size), );
12951299

12961300
// Get full device descriptor
1297-
TU_LOG2("Get Device Descriptor\r\n");
1301+
TU_LOG_USBH("Get Device Descriptor\r\n");
12981302
TU_ASSERT(tuh_descriptor_get_device(new_addr, _usbh_ctrl_buf, sizeof(tusb_desc_device_t), process_enumeration, ENUM_GET_9BYTE_CONFIG_DESC), );
12991303
}
13001304
break;
@@ -1315,7 +1319,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
13151319

13161320
// Get 9-byte for total length
13171321
uint8_t const config_idx = CONFIG_NUM - 1;
1318-
TU_LOG2("Get Configuration[0] Descriptor (9 bytes)\r\n");
1322+
TU_LOG_USBH("Get Configuration[0] Descriptor (9 bytes)\r\n");
13191323
TU_ASSERT( tuh_descriptor_get_configuration(daddr, config_idx, _usbh_ctrl_buf, 9, process_enumeration, ENUM_GET_FULL_CONFIG_DESC), );
13201324
}
13211325
break;
@@ -1332,7 +1336,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
13321336

13331337
// Get full configuration descriptor
13341338
uint8_t const config_idx = CONFIG_NUM - 1;
1335-
TU_LOG2("Get Configuration[0] Descriptor\r\n");
1339+
TU_LOG_USBH("Get Configuration[0] Descriptor\r\n");
13361340
TU_ASSERT( tuh_descriptor_get_configuration(daddr, config_idx, _usbh_ctrl_buf, total_len, process_enumeration, ENUM_SET_CONFIG), );
13371341
}
13381342
break;
@@ -1347,7 +1351,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
13471351

13481352
case ENUM_CONFIG_DRIVER:
13491353
{
1350-
TU_LOG2("Device configured\r\n");
1354+
TU_LOG_USBH("Device configured\r\n");
13511355
usbh_device_t* dev = get_device(daddr);
13521356
TU_ASSERT(dev, );
13531357

@@ -1387,7 +1391,7 @@ static bool enum_new_device(hcd_event_t* event)
13871391
if ( !hcd_port_connect_status(_dev0.rhport) ) return true;
13881392

13891393
_dev0.speed = hcd_port_speed_get(_dev0.rhport );
1390-
TU_LOG2("%s Speed\r\n", tu_str_speed[_dev0.speed]);
1394+
TU_LOG_USBH("%s Speed\r\n", tu_str_speed[_dev0.speed]);
13911395

13921396
// fake transfer to kick-off the enumeration process
13931397
tuh_xfer_t xfer;
@@ -1444,7 +1448,7 @@ static bool enum_request_set_addr(void)
14441448
uint8_t const new_addr = get_new_address(desc_device->bDeviceClass == TUSB_CLASS_HUB);
14451449
TU_ASSERT(new_addr != 0);
14461450

1447-
TU_LOG2("Set Address = %d\r\n", new_addr);
1451+
TU_LOG_USBH("Set Address = %d\r\n", new_addr);
14481452

14491453
usbh_device_t* new_dev = get_device(new_addr);
14501454

@@ -1488,9 +1492,12 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur
14881492
{
14891493
usbh_device_t* dev = get_device(dev_addr);
14901494

1491-
uint8_t const* desc_end = ((uint8_t const*) desc_cfg) + tu_le16toh(desc_cfg->wTotalLength);
1495+
uint16_t const total_len = tu_le16toh(desc_cfg->wTotalLength);
1496+
uint8_t const* desc_end = ((uint8_t const*) desc_cfg) + total_len;
14921497
uint8_t const* p_desc = tu_desc_next(desc_cfg);
14931498

1499+
TU_LOG_USBH("Parsing Configuration descriptor (wTotalLength = %u)\r\n", total_len);
1500+
14941501
// parse each interfaces
14951502
while( p_desc < desc_end )
14961503
{
@@ -1535,7 +1542,7 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur
15351542
if ( driver->open(dev->rhport, dev_addr, desc_itf, drv_len) )
15361543
{
15371544
// open successfully
1538-
TU_LOG2(" %s opened\r\n", driver->name);
1545+
TU_LOG_USBH(" %s opened\r\n", driver->name);
15391546

15401547
// bind (associated) interfaces to found driver
15411548
for(uint8_t i=0; i<assoc_itf_count; i++)
@@ -1555,7 +1562,7 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur
15551562

15561563
if( drv_id >= USBH_CLASS_DRIVER_COUNT )
15571564
{
1558-
TU_LOG(USBH_DBG_LVL, "Interface %u: class = %u subclass = %u protocol = %u is not supported\r\n",
1565+
TU_LOG(USBH_DEBUG, "Interface %u: class = %u subclass = %u protocol = %u is not supported\r\n",
15591566
desc_itf->bInterfaceNumber, desc_itf->bInterfaceClass, desc_itf->bInterfaceSubClass, desc_itf->bInterfaceProtocol);
15601567
}
15611568
}
@@ -1580,7 +1587,7 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
15801587
if (drv_id != DRVID_INVALID)
15811588
{
15821589
usbh_class_driver_t const * driver = &usbh_class_drivers[drv_id];
1583-
TU_LOG2("%s set config: itf = %u\r\n", driver->name, itf_num);
1590+
TU_LOG_USBH("%s set config: itf = %u\r\n", driver->name, itf_num);
15841591
driver->set_config(dev_addr, itf_num);
15851592
break;
15861593
}
@@ -1593,7 +1600,7 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
15931600

15941601
if (is_hub_addr(dev_addr))
15951602
{
1596-
TU_LOG(USBH_DBG_LVL, "HUB address = %u is mounted\r\n", dev_addr);
1603+
TU_LOG(USBH_DEBUG, "HUB address = %u is mounted\r\n", dev_addr);
15971604
}else
15981605
{
15991606
// Invoke callback if available

0 commit comments

Comments
 (0)