Skip to content

Commit a5cbbe4

Browse files
committed
USBHost: enumerate devices once at a time
1 parent 4652de4 commit a5cbbe4

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

libraries/USBHOST/src/USBHost.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ uint32_t USBHost::Init(uint8_t id, const tusbh_class_reg_t class_table[]) {
1414
root_fs.support_classes = class_table;
1515
tusb_host_init(_fs, &root_fs);
1616
tusb_open_host(_fs);
17-
1817
start_hub();
1918
}
2019

libraries/USBHOST/src/class/host/tusbh_hub.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,10 @@ static int hub_data_xfered(tusbh_ep_info_t* ep)
298298
goto error;
299299
}
300300
TUSB_HUB_INFO("HUB port state = %02x\n", port_state);
301-
for(;port_state; port_state>>=1, port++) {
302-
if( (port_state & 1) == 0 ) continue;
301+
while (port_state != 0) {
302+
if( (port_state & 1) == 0 ) {
303+
goto next_port;
304+
}
303305
usb_hub_port_status_t status;
304306
TUSB_HUB_INFO("HUB get port %d status\n", port);
305307
res = tusbh_get_hub_port_staus(dev, port, &status);
@@ -342,7 +344,7 @@ static int hub_data_xfered(tusbh_ep_info_t* ep)
342344
if(status.wPortStatus.PORT_LOW_SPEED){
343345
child->speed = PORT_SPEED_LOW;
344346
}
345-
tusb_delay_ms(200);
347+
//tusb_delay_ms(200);
346348

347349
if(dev->ctrl_in>=0){
348350
tusbh_close_pipe(dev, dev->ctrl_in);
@@ -360,7 +362,8 @@ static int hub_data_xfered(tusbh_ep_info_t* ep)
360362
}
361363
if(dev->ctrl_out<0){
362364
TUSB_HUB_INFO("Fail to re-allocate hub ctrl out\n");
363-
}
365+
}
366+
goto next_port;
364367
}else{
365368
TUSB_HUB_INFO("Connect\n");
366369
tusbh_device_t* child = dev->children[port-1];
@@ -373,6 +376,8 @@ static int hub_data_xfered(tusbh_ep_info_t* ep)
373376
child->hub_port = port;
374377
dev->children[port-1] = child;
375378
tusbh_set_hub_port_feature(dev, port, HUB_FEATURE_SEL_PORT_RESET);
379+
tusb_delay_ms(info->hub_desc.bPowerOnToPowerGood);
380+
continue;
376381
}
377382
}else{
378383
TUSB_HUB_INFO("Disconnect\n");
@@ -384,8 +389,11 @@ static int hub_data_xfered(tusbh_ep_info_t* ep)
384389
dev->children[port-1] = 0;
385390
}
386391
}
392+
next_port:
393+
port_state>>=1;
394+
port++;
387395
}
388-
396+
389397
error:
390398
if(dev->ctrl_in>=0){ tusbh_close_pipe(dev, dev->ctrl_in); }
391399
if(dev->ctrl_out>=0){ tusbh_close_pipe(dev, dev->ctrl_out); }

libraries/USBHOST/src/teeny_usb_stm32_otg_host.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ uint32_t tusb_otg_host_xfer_data_split(tusb_host_t* host, uint8_t hc_num, uint8_
11571157
tusb_otg_host_submit(host, hc_num);
11581158
} while (0);
11591159

1160-
delayMicroseconds(300);
1160+
delayMicroseconds(200);
11611161

11621162
HC->HCSPLT = 0;
11631163

@@ -1202,13 +1202,17 @@ uint32_t tusb_otg_host_xfer_data_normal(tusb_host_t* host, uint8_t hc_num, uint8
12021202
#endif
12031203
}
12041204

1205+
if ((USBx == USB_OTG_FS) && (hc->speed == PORT_SPEED_LOW)) {
1206+
//delayMicroseconds(200);
1207+
}
1208+
12051209
tusb_otg_host_submit(host, hc_num);
12061210
return 0;
12071211
}
12081212

12091213
uint32_t tusb_otg_host_xfer_data(tusb_host_t* host, uint8_t hc_num, uint8_t is_data, uint8_t* data, uint32_t len, uint8_t port)
12101214
{
1211-
if (port == 0 || GetUSB(host) == USB_OTG_FS) {
1215+
if ((port == 0) || (GetUSB(host) == USB_OTG_FS)) {
12121216
return tusb_otg_host_xfer_data_normal(host, hc_num, is_data, data, len);
12131217
} else {
12141218
return tusb_otg_host_xfer_data_split(host, hc_num, is_data, data, len, port);

0 commit comments

Comments
 (0)