Skip to content

Commit a36e77d

Browse files
authored
Merge pull request #108 from balanceTWK/usb_host
[update] usb/usbhost Component
2 parents a0b76a2 + a391428 commit a36e77d

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

rt-thread/components/drivers/usb/usbhost/class/udisk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ rt_err_t rt_udisk_run(struct uhintf* intf)
186186
{
187187
int i = 0;
188188
rt_err_t ret;
189-
char dname[4];
189+
char dname[8];
190190
char sname[8];
191191
rt_uint8_t max_lun, *sector, sense[18], inquiry[36];
192192
struct dfs_partition part[MAX_PARTITION_COUNT];

rt-thread/components/drivers/usb/usbhost/core/hub.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,13 @@ static rt_err_t rt_usbh_hub_port_change(uhub_t hub)
417417

418418
if(reconnect)
419419
{
420-
if(hub->child[i] != RT_NULL && hub->child[i]->status != DEV_STATUS_IDLE)
420+
if(hub->child[i] != RT_NULL && hub->child[i]->status != DEV_STATUS_IDLE)
421+
{
421422
rt_usbh_detach_instance(hub->child[i]);
423+
424+
/* Child device have been detach. Set hub->child[i] to NULL. */
425+
hub->child[i] = RT_NULL;
426+
}
422427

423428
ret = rt_usbh_hub_port_debounce(hub, i + 1);
424429
if(ret != RT_EOK) continue;
@@ -532,7 +537,12 @@ static rt_err_t rt_usbh_hub_enable(void *arg)
532537
}
533538

534539
/* get hub ports number */
535-
hub->num_ports = hub->hub_desc.num_ports;
540+
/* If hub device supported ports over USB_HUB_PORT_NUM(Ex: 8 port hub). Set hub->num_ports to USB_HUB_PORT_NUM */
541+
if(hub->hub_desc.num_ports > USB_HUB_PORT_NUM)
542+
hub->num_ports = USB_HUB_PORT_NUM;
543+
else
544+
hub->num_ports = hub->hub_desc.num_ports;
545+
536546
hub->hcd = device->hcd;
537547
hub->self = device;
538548

@@ -607,7 +617,6 @@ static rt_err_t rt_usbh_hub_disable(void* arg)
607617
}
608618

609619
if(hub != RT_NULL) rt_free(hub);
610-
if(intf != RT_NULL) rt_free(intf);
611620

612621
return RT_EOK;
613622
}

rt-thread/components/drivers/usb/usbhost/core/usbhost_core.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ rt_err_t rt_usbh_attatch_instance(uinst_t device)
162162

163163
/* alloc memory for configuration descriptor */
164164
device->cfg_desc = (ucfg_desc_t)rt_malloc(cfg_desc.wTotalLength);
165+
if(device->cfg_desc == RT_NULL)
166+
{
167+
return RT_ENOMEM;
168+
}
165169
rt_memset(device->cfg_desc, 0, cfg_desc.wTotalLength);
166170

167171
/* get full configuration descriptor */
@@ -219,6 +223,10 @@ rt_err_t rt_usbh_attatch_instance(uinst_t device)
219223
{
220224
/* allocate memory for interface device */
221225
device->intf[i] = (struct uhintf*)rt_malloc(sizeof(struct uhintf));
226+
if(device->intf[i] == RT_NULL)
227+
{
228+
return RT_ENOMEM;
229+
}
222230
device->intf[i]->drv = drv;
223231
device->intf[i]->device = device;
224232
device->intf[i]->intf_desc = intf_desc;

0 commit comments

Comments
 (0)