46
46
#define CFG_TUH_INTERFACE_MAX 8
47
47
#endif
48
48
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__)
51
53
52
54
//--------------------------------------------------------------------+
53
55
// USBH-HCD common data structure
@@ -324,11 +326,11 @@ bool tuh_init(uint8_t controller_id)
324
326
// skip if already initialized
325
327
if ( tuh_inited () ) return true;
326
328
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 ));
332
334
333
335
// Event queue
334
336
_usbh_q = osal_queue_create ( & _usbh_qdef );
@@ -353,7 +355,7 @@ bool tuh_init(uint8_t controller_id)
353
355
// Class drivers
354
356
for (uint8_t drv_id = 0 ; drv_id < USBH_CLASS_DRIVER_COUNT ; drv_id ++ )
355
357
{
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 );
357
359
usbh_class_drivers [drv_id ].init ();
358
360
}
359
361
@@ -401,12 +403,12 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
401
403
case HCD_EVENT_DEVICE_ATTACH :
402
404
// TODO due to the shared _usbh_ctrl_buf, we must complete enumerating
403
405
// 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 );
405
407
enum_new_device (& event );
406
408
break ;
407
409
408
410
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 );
410
412
process_device_unplugged (event .rhport , event .connection .hub_addr , event .connection .hub_port );
411
413
412
414
#if CFG_TUH_HUB
@@ -425,7 +427,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
425
427
uint8_t const epnum = tu_edpt_number (ep_addr );
426
428
uint8_t const ep_dir = tu_edpt_dir (ep_addr );
427
429
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 );
429
431
430
432
if (event .dev_addr == 0 )
431
433
{
@@ -449,7 +451,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
449
451
uint8_t drv_id = dev -> ep2drv [epnum ][ep_dir ];
450
452
if (drv_id < USBH_CLASS_DRIVER_COUNT )
451
453
{
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 );
453
455
usbh_class_drivers [drv_id ].xfer_cb (event .dev_addr , ep_addr , event .xfer_complete .result , event .xfer_complete .len );
454
456
}
455
457
else
@@ -539,9 +541,11 @@ bool tuh_control_xfer (tuh_xfer_t* xfer)
539
541
TU_VERIFY (is_idle );
540
542
const uint8_t rhport = usbh_get_rhport (daddr );
541
543
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" );
545
549
546
550
if (xfer -> complete_cb )
547
551
{
@@ -585,7 +589,7 @@ TU_ATTR_ALWAYS_INLINE static inline void _set_control_xfer_stage(uint8_t stage)
585
589
586
590
static void _xfer_complete (uint8_t daddr , xfer_result_t result )
587
591
{
588
- TU_LOG2 ("\r\n" );
592
+ TU_LOG_USBH ("\r\n" );
589
593
590
594
// duplicate xfer since user can execute control transfer within callback
591
595
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
643
647
case CONTROL_STAGE_DATA :
644
648
if (request -> wLength )
645
649
{
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 );
648
652
}
649
653
650
654
_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
760
764
uint8_t const dir = tu_edpt_dir (ep_addr );
761
765
tu_edpt_state_t * ep_state = & dev -> ep_status [epnum ][dir ];
762
766
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 );
764
768
765
769
// Attempt to transfer on a busy endpoint, sound like an race condition !
766
770
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
776
780
777
781
if ( hcd_edpt_xfer (dev -> rhport , dev_addr , ep_addr , buffer , total_bytes ) )
778
782
{
779
- TU_LOG2 ("OK\r\n" );
783
+ TU_LOG_USBH ("OK\r\n" );
780
784
return true;
781
785
}else
782
786
{
@@ -791,7 +795,7 @@ bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t * b
791
795
792
796
static bool usbh_edpt_control_open (uint8_t dev_addr , uint8_t max_packet_size )
793
797
{
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 );
795
799
796
800
tusb_desc_endpoint_t ep0_desc =
797
801
{
@@ -960,7 +964,7 @@ bool tuh_descriptor_get_serial_string(uint8_t daddr, uint16_t language_id, void*
960
964
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 ,
961
965
tuh_xfer_cb_t complete_cb , uintptr_t user_data )
962
966
{
963
- TU_LOG2 ("HID Get Report Descriptor\r\n" );
967
+ TU_LOG_USBH ("HID Get Report Descriptor\r\n" );
964
968
tusb_control_request_t const request =
965
969
{
966
970
.bmRequestType_bit =
@@ -999,7 +1003,7 @@ bool tuh_descriptor_get_hid_report(uint8_t daddr, uint8_t itf_num, uint8_t desc_
999
1003
bool tuh_configuration_set (uint8_t daddr , uint8_t config_num ,
1000
1004
tuh_xfer_cb_t complete_cb , uintptr_t user_data )
1001
1005
{
1002
- TU_LOG2 ("Set Configuration = %d\r\n" , config_num );
1006
+ TU_LOG_USBH ("Set Configuration = %d\r\n" , config_num );
1003
1007
1004
1008
tusb_control_request_t const request =
1005
1009
{
@@ -1103,11 +1107,11 @@ static void process_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t h
1103
1107
(hub_port == 0 || dev -> hub_port == hub_port ) && // hub_port = 0 means all devices of downstream hub
1104
1108
dev -> connected )
1105
1109
{
1106
- TU_LOG2 (" Address = %u\r\n" , dev_addr );
1110
+ TU_LOG_USBH (" Address = %u\r\n" , dev_addr );
1107
1111
1108
1112
if (is_hub_addr (dev_addr ))
1109
1113
{
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 );
1111
1115
// If the device itself is a usb hub, unplug downstream devices.
1112
1116
// FIXME un-roll recursive calls to prevent potential stack overflow
1113
1117
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
1120
1124
// Close class driver
1121
1125
for (uint8_t drv_id = 0 ; drv_id < USBH_CLASS_DRIVER_COUNT ; drv_id ++ )
1122
1126
{
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 );
1124
1128
usbh_class_drivers [drv_id ].close (dev_addr );
1125
1129
}
1126
1130
@@ -1245,7 +1249,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
1245
1249
TU_ASSERT ( usbh_edpt_control_open (addr0 , 8 ), );
1246
1250
1247
1251
// 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" );
1249
1253
TU_ASSERT (tuh_descriptor_get_device (addr0 , _usbh_ctrl_buf , 8 , process_enumeration , ENUM_SET_ADDR ), );
1250
1254
}
1251
1255
break ;
@@ -1254,7 +1258,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
1254
1258
case ENUM_RESET_2 :
1255
1259
// TODO not used by now, but may be needed for some devices !?
1256
1260
// Reset device again before Set Address
1257
- TU_LOG2 ("Port reset2 \r\n" );
1261
+ TU_LOG_USBH ("Port reset2 \r\n" );
1258
1262
if (_dev0 .hub_addr == 0 )
1259
1263
{
1260
1264
// connected directly to roothub
@@ -1294,7 +1298,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
1294
1298
TU_ASSERT ( usbh_edpt_control_open (new_addr , new_dev -> ep0_size ), );
1295
1299
1296
1300
// Get full device descriptor
1297
- TU_LOG2 ("Get Device Descriptor\r\n" );
1301
+ TU_LOG_USBH ("Get Device Descriptor\r\n" );
1298
1302
TU_ASSERT (tuh_descriptor_get_device (new_addr , _usbh_ctrl_buf , sizeof (tusb_desc_device_t ), process_enumeration , ENUM_GET_9BYTE_CONFIG_DESC ), );
1299
1303
}
1300
1304
break ;
@@ -1315,7 +1319,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
1315
1319
1316
1320
// Get 9-byte for total length
1317
1321
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" );
1319
1323
TU_ASSERT ( tuh_descriptor_get_configuration (daddr , config_idx , _usbh_ctrl_buf , 9 , process_enumeration , ENUM_GET_FULL_CONFIG_DESC ), );
1320
1324
}
1321
1325
break ;
@@ -1332,7 +1336,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
1332
1336
1333
1337
// Get full configuration descriptor
1334
1338
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" );
1336
1340
TU_ASSERT ( tuh_descriptor_get_configuration (daddr , config_idx , _usbh_ctrl_buf , total_len , process_enumeration , ENUM_SET_CONFIG ), );
1337
1341
}
1338
1342
break ;
@@ -1347,7 +1351,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
1347
1351
1348
1352
case ENUM_CONFIG_DRIVER :
1349
1353
{
1350
- TU_LOG2 ("Device configured\r\n" );
1354
+ TU_LOG_USBH ("Device configured\r\n" );
1351
1355
usbh_device_t * dev = get_device (daddr );
1352
1356
TU_ASSERT (dev , );
1353
1357
@@ -1387,7 +1391,7 @@ static bool enum_new_device(hcd_event_t* event)
1387
1391
if ( !hcd_port_connect_status (_dev0 .rhport ) ) return true;
1388
1392
1389
1393
_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 ]);
1391
1395
1392
1396
// fake transfer to kick-off the enumeration process
1393
1397
tuh_xfer_t xfer ;
@@ -1444,7 +1448,7 @@ static bool enum_request_set_addr(void)
1444
1448
uint8_t const new_addr = get_new_address (desc_device -> bDeviceClass == TUSB_CLASS_HUB );
1445
1449
TU_ASSERT (new_addr != 0 );
1446
1450
1447
- TU_LOG2 ("Set Address = %d\r\n" , new_addr );
1451
+ TU_LOG_USBH ("Set Address = %d\r\n" , new_addr );
1448
1452
1449
1453
usbh_device_t * new_dev = get_device (new_addr );
1450
1454
@@ -1488,9 +1492,12 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur
1488
1492
{
1489
1493
usbh_device_t * dev = get_device (dev_addr );
1490
1494
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 ;
1492
1497
uint8_t const * p_desc = tu_desc_next (desc_cfg );
1493
1498
1499
+ TU_LOG_USBH ("Parsing Configuration descriptor (wTotalLength = %u)\r\n" , total_len );
1500
+
1494
1501
// parse each interfaces
1495
1502
while ( p_desc < desc_end )
1496
1503
{
@@ -1535,7 +1542,7 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur
1535
1542
if ( driver -> open (dev -> rhport , dev_addr , desc_itf , drv_len ) )
1536
1543
{
1537
1544
// open successfully
1538
- TU_LOG2 (" %s opened\r\n" , driver -> name );
1545
+ TU_LOG_USBH (" %s opened\r\n" , driver -> name );
1539
1546
1540
1547
// bind (associated) interfaces to found driver
1541
1548
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
1555
1562
1556
1563
if ( drv_id >= USBH_CLASS_DRIVER_COUNT )
1557
1564
{
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" ,
1559
1566
desc_itf -> bInterfaceNumber , desc_itf -> bInterfaceClass , desc_itf -> bInterfaceSubClass , desc_itf -> bInterfaceProtocol );
1560
1567
}
1561
1568
}
@@ -1580,7 +1587,7 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
1580
1587
if (drv_id != DRVID_INVALID )
1581
1588
{
1582
1589
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 );
1584
1591
driver -> set_config (dev_addr , itf_num );
1585
1592
break ;
1586
1593
}
@@ -1593,7 +1600,7 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
1593
1600
1594
1601
if (is_hub_addr (dev_addr ))
1595
1602
{
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 );
1597
1604
}else
1598
1605
{
1599
1606
// Invoke callback if available
0 commit comments