cancel
Showing results for 
Search instead for 
Did you mean: 

USB devices with 2 interfaces.

jdcowpland
Associate II
Posted on June 19, 2014 at 18:02

Hi guys, looking for some help with a USB device I have which has 2 interfaces. The first interface is HID, and the second is MSC. I've modified the USB Host library so that it doesn't it doesn't fail in the MSC Interface Init. It's originally setup just to look at interface 0 here so I added a line to get it to look at interface 1 as well so that it didn't fail. This allowed me to mount the device with chan's FATFS. I can read from the device but I can't write to it. Debugging my way through it, the ep descriptors for interface 1 never seem to be there and I'm guessing that might be an issue. Not completely sure. Has anyone encountered this kind of thing before?

4 REPLIES 4
tsuneo
Senior
Posted on June 20, 2014 at 19:56

> Debugging my way through it, the ep descriptors for interface 1 never seem to be there and I'm guessing that might be an issue.

Are you working on STM32_USB-Host-Device_Lib_V2.1.0? USBH_MSC_InterfaceInit() parses the interface descriptor set, and it opens pipes for the bulk IN/OUT EPs. The original code assumes that the MSC sits on interface 0. For other interface number, you have to modify this routine as follows - add ''if_num'' parameter for the target interface number. - in the routine, Itf_Desc[0] --> Itf_Desc[if_num] Ep_Desc[0] --> Ep_Desc[if_num]

usbh_msc_core.c
static USBH_Status USBH_MSC_InterfaceInit ( USB_OTG_CORE_HANDLE *pdev, void *phost, uint32_t if_num)
{ 
USBH_HOST *pphost = phost;
if((pphost->device_prop.Itf_Desc[if_num].bInterfaceClass == MSC_CLASS) && \
(pphost->device_prop.Itf_Desc[if_num].bInterfaceProtocol == MSC_PROTOCOL))
{
if(pphost->device_prop.Ep_Desc[if_num][0].bEndpointAddress & 0x80)
{
MSC_Machine.MSBulkInEp = (pphost->device_prop.Ep_Desc[if_num][0].bEndpointAddress);
MSC_Machine.MSBulkInEpSize = pphost->device_prop.Ep_Desc[if_num][0].wMaxPacketSize;
}
else
{
MSC_Machine.MSBulkOutEp = (pphost->device_prop.Ep_Desc[if_num][0].bEndpointAddress);
MSC_Machine.MSBulkOutEpSize = pphost->device_prop.Ep_Desc[if_num][0].wMaxPacketSize; 
}
if(pphost->device_prop.Ep_Desc[if_num][1].bEndpointAddress & 0x80)
{
MSC_Machine.MSBulkInEp = (pphost->device_prop.Ep_Desc[if_num][1].bEndpointAddress);
MSC_Machine.MSBulkInEpSize = pphost->device_prop.Ep_Desc[if_num][1].wMaxPacketSize; 
}
else
{
MSC_Machine.MSBulkOutEp = (pphost->device_prop.Ep_Desc[if_num][1].bEndpointAddress);
MSC_Machine.MSBulkOutEpSize = pphost->device_prop.Ep_Desc[if_num][1].wMaxPacketSize; 
}
...

Tsuneo
jdcowpland
Associate II
Posted on June 23, 2014 at 11:20

Hi Tsuneo,

No, I'm working with library v.2.0.0. Are there significant changes in 2.1.0 that would help me? I made the changes you had suggested ( I had done something similar but it wasn't as tidy as yours :P) but the End point descriptors for interface 1 are still blank,and I can't even get to the point of mounting FAT now. The only change I had made was to modify the USBH_MSC_InterfaceInit so that instead of the first if statement just asking about itfdesc[0], it also checked itfdesc[1] :

if((pphost->device_prop.Itf_Desc[0].bInterfaceClass == MSC_CLASS) && (pphost->device_prop.Itf_Desc[0].bInterfaceProtocol == MSC_PROTOCOL) \
|| (pphost->device_prop.Itf_Desc[1].bInterfaceClass == MSC_CLASS) && (pphost->device_prop.Itf_Desc[1].bInterfaceProtocol == MSC_PROTOCOL))

With that as the only modification, I can mount and read files. So I’m not quite sure why your mods won’t work. To call your modified function i modified usbh_core.c so that it was like this:

case HOST_USR_INPUT:
/*The function should return user response true to move to class state */
if ( phost->usr_cb->UserInput() == USBH_USR_RESP_OK)
{
if(phost->device_prop.Itf_Desc[0].bInterfaceClass == 0x08){
interface = 0;
}
else if(phost->device_prop.Itf_Desc[1].bInterfaceClass == 0x08){
interface = 1;
}
if((phost->class_cb->Init(pdev, phost, interface))== USBH_OK)
{
phost->gState = HOST_CLASS_REQUEST;
}
}
break;

Within the enumeration stuff, there's the switch statement that calls on the USBH_Get_Cfg_Desc function (approx line 479 of usbh_core.c) and then has the user callback for cofiguration descriptors which just inculdes end point 0. Should that be modified too? Cheers!
jdcowpland
Associate II
Posted on September 02, 2014 at 00:02

I've successfully now managed to get the library working with my dual interface device and fat seems to be mounting fine onto the second interface (MSC), but as previously, I only seem to be able to read from the device and not write to it. All the fatfs functions return a FR_OK though even when writing. Does anyone know what might be happening?

Cheers!

jdcowpland
Associate II
Posted on February 24, 2015 at 16:35

I had put this project to the side for the past year, but now back onto it. Latest update is that I've discovered that the interface I need uses the same endpoint address(0x81,0x01) for in and out. All other devices I've tried with my USB host seem to use different addresses (usually 0x81, 0x02). I'm starting to think this might be the issue. Has anyone else encountered anything similar or able to confirm my hypothesis?