@@ -1089,6 +1089,12 @@ uint8_t tuh_descriptor_get_serial_string_sync(uint8_t daddr, uint16_t language_i
1089
1089
//
1090
1090
//--------------------------------------------------------------------+
1091
1091
1092
+ TU_ATTR_ALWAYS_INLINE
1093
+ static inline bool is_hub_addr (uint8_t daddr )
1094
+ {
1095
+ return (CFG_TUH_HUB > 0 ) && (daddr > CFG_TUH_DEVICE_MAX );
1096
+ }
1097
+
1092
1098
// a device unplugged from rhport:hub_addr:hub_port
1093
1099
static void process_device_unplugged (uint8_t rhport , uint8_t hub_addr , uint8_t hub_port )
1094
1100
{
@@ -1101,21 +1107,24 @@ static void process_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t h
1101
1107
1102
1108
// TODO Hub multiple level
1103
1109
if (dev -> rhport == rhport &&
1104
- (hub_addr == 0 || dev -> hub_addr == hub_addr ) && // hub_addr == 0 & hub_port == 0 means roothub
1105
- (hub_port == 0 || dev -> hub_port == hub_port ) &&
1110
+ (hub_addr == 0 || dev -> hub_addr == hub_addr ) && // hub_addr = 0 means roothub
1111
+ (hub_port == 0 || dev -> hub_port == hub_port ) && // hub_port = 0 means all devices of downstream hub
1106
1112
dev -> connected )
1107
1113
{
1108
1114
TU_LOG2 (" Address = %u\r\n" , dev_addr );
1109
1115
1110
- // If the device itself is a usb hub, unplug downstream devices.
1111
- if (dev_addr > CFG_TUH_DEVICE_MAX )
1116
+ if (is_hub_addr (dev_addr ))
1112
1117
{
1118
+ TU_LOG (USBH_DBG_LVL , "HUB address = %u is unmounted\r\n" , dev_addr );
1119
+ // If the device itself is a usb hub, unplug downstream devices.
1120
+ // FIXME un-roll recursive calls to prevent potential stack overflow
1113
1121
process_device_unplugged (rhport , dev_addr , 0 );
1122
+ }else
1123
+ {
1124
+ // Invoke callback before closing driver
1125
+ if (tuh_umount_cb ) tuh_umount_cb (dev_addr );
1114
1126
}
1115
1127
1116
- // Invoke callback before close driver
1117
- if (tuh_umount_cb ) tuh_umount_cb (dev_addr );
1118
-
1119
1128
// Close class driver
1120
1129
for (uint8_t drv_id = 0 ; drv_id < USBH_CLASS_DRIVER_COUNT ; drv_id ++ )
1121
1130
{
@@ -1395,12 +1404,6 @@ static bool enum_new_device(hcd_event_t* event)
1395
1404
return true;
1396
1405
}
1397
1406
1398
- TU_ATTR_ALWAYS_INLINE
1399
- static inline bool is_hub_addr (uint8_t daddr )
1400
- {
1401
- return daddr > CFG_TUH_DEVICE_MAX ;
1402
- }
1403
-
1404
1407
static uint8_t get_new_address (bool is_hub )
1405
1408
{
1406
1409
uint8_t start ;
@@ -1577,10 +1580,10 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
1577
1580
{
1578
1581
enum_full_complete ();
1579
1582
1580
- # if CFG_TUH_HUB
1581
- // skip device mount callback for hub
1582
- if ( ! is_hub_addr ( dev_addr ) )
1583
- #endif
1583
+ if ( is_hub_addr ( dev_addr ))
1584
+ {
1585
+ TU_LOG ( USBH_DBG_LVL , "HUB address = %u is mounted\r\n" , dev_addr );
1586
+ } else
1584
1587
{
1585
1588
// Invoke callback if available
1586
1589
if (tuh_mount_cb ) tuh_mount_cb (dev_addr );
0 commit comments