cancel
Showing results for 
Search instead for 
Did you mean: 

A patch for USB HOST Library Bug

dzuikov
Associate II
Posted on January 27, 2012 at 20:58


There is bug in USB Host library that causes to wrongbehavior if the attached device has more that one interface. EP properties for interface 0 is overriding by the values for next interfaces.
There is also a problem that if there are more interfaces that value ofUSBH_MAX_NUM_INTERFACESthen library will not work at all. For me there is no reason for suchbehavior, it's perfect if it will fork with firstUSBH_MAX_NUM_INTERFACES ignoring rest of them (there is no patch for this yet).

--- a/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_HOST_Library/Core/src/usbh_stdreq.c
+++ b/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_HOST_Library/Core/src/usbh_stdreq.c
@@ -77,7 +77,7 @@ 
static
void
USBH_ParseDevDesc (USBH_DevDesc_TypeDef* , uint8_t *buf, uint16_t le
static
void
USBH_ParseCfgDesc (USBH_CfgDesc_TypeDef* cfg_desc,
USBH_InterfaceDesc_TypeDef* itf_desc,
- USBH_EpDesc_TypeDef* ep_desc, 
+ USBH_EpDesc_TypeDef ep_desc[USBH_MAX_NUM_INTERFACES][USBH_MAX_NUM_ENDPOINTS], ^M
uint8_t *buf, 
uint16_t length);
static
USBH_DescHeader_t *USBH_GetNextDesc (uint8_t *pbuf, 
@@ -156,7 +156,7 @@ USBH_Status USBH_Get_CfgDesc(USB_OTG_CORE_HANDLE *pdev,
/* Commands successfully sent and Response Received */
USBH_ParseCfgDesc (&phost->device_prop.Cfg_Desc,
phost->device_prop.Itf_Desc,
- phost->device_prop.Ep_Desc[0], 
+ phost->device_prop.Ep_Desc, ^M
pdev->host.Rx_Buffer,
length); 
@@ -356,7 +356,7 @@ 
static
void
USBH_ParseDevDesc (USBH_DevDesc_TypeDef* dev_desc,
*/
static
void
USBH_ParseCfgDesc (USBH_CfgDesc_TypeDef* cfg_desc,
USBH_InterfaceDesc_TypeDef* itf_desc,
- USBH_EpDesc_TypeDef* ep_desc, 
+ USBH_EpDesc_TypeDef ep_desc[USBH_MAX_NUM_INTERFACES][USBH_MAX_NUM_ENDPOINTS], ^M
uint8_t *buf, 
uint16_t length)
{ 
@@ -409,7 +409,7 @@ 
static
void
USBH_ParseCfgDesc (USBH_CfgDesc_TypeDef* cfg_desc,
pdesc = USBH_GetNextDesc((
void
* )pdesc, &ptr);
if
(pdesc->bDescriptorType == USB_DESC_TYPE_ENDPOINT) 
{ 
- pep = &ep_desc[ep_ix];
+ pep = &(ep_desc[if_ix][ep_ix]);^M
USBH_ParseEPDesc (pep, (uint8_t *)pdesc);
ep_ix++;
}

2 REPLIES 2
Pm77
Associate II

I could recreate such/similar behaviour by setting follong defines to 1 (default set by CubeMX = 2)

#define USBH_MAX_NUM_ENDPOINTS    1
#define USBH_MAX_NUM_INTERFACES    1

Setting it to defaults =2 seems working(one parting per USB Drive)

I'm using

CubeMX Version 5.0

STM32Cube V1.0

With STM32F437 Micro

Hope it will be resolved soon.

Pm77
Associate II

Follow up:

CubeMX uses following defines even with use of RTOS enalbled

/** Alias for memory allocation. */
#define USBH_malloc         malloc
 
/** Alias for memory release. */
#define USBH_free           free

correct one should be following one

/** Alias for memory allocation. */
#define USBH_malloc         pvPortMalloc
 
/** Alias for memory release. */
#define USBH_free           vPortFree

For following allocate to succeed

phost->pActiveClass->pData = (MSC_HandleTypeDef *)USBH_malloc (sizeof(MSC_HandleTypeDef));