cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with the STM32_USB_HOST_LIBRARY generated by CubeMX

Antoine Wajntraub
Associate II
Posted on January 12, 2017 at 10:59

Hi !

First, I use the version 4.18.0 STM32Cube V1.0, and Atollic True Studio 7.0.1, so both are (normally) the last ones.

I try to generate, with CubeMX, a project on STM32F417VG, using several libraries, the STM32_USB_HOST_LIBRARY for MSC being one of them. My problem is that I cannot use this project !

I generate the project -> I compile -> Works !

I generate the project -> I add these lines in the main.h :

&sharpinclude ''usbh_def.h''

USBH_HandleTypeDef hUSBHost;

I doesn't change anything else, and I don't write anything else but it doesn't compile, I have some strange errors.

Four of them are about four different macros (USBH_MAX_DATA_BUFFER, USBH_MAX_NUM_ENDPOINTS, USBH_MAX_NUM_INTERFACES, USBH_MAX_NUM_SUPPORTED_CLASS) in the file ''usbh_def.h'' with this message :

Macro undeclared here (not in a function)

But those macros are declared in usbh_conf.h which is directly included in usbh_def.h.

Another error is :

USBH_DeviceTypeDef has no member name 'CfgDesc_Raw'

in this line :

0690X000006061iQAA.png

And when I go to the definition of USBH_DeviceTypeDef, I have this :

0690X000006061nQAA.png

So if we want CfgDesc_Raw, it's because USBH_KEEP_CFG_DESCRIPTOR == 1 (and I checked, it's true), but if we don't have it in the structure, it's because the same macro != 1...

What happened ? Why can't I use this library properly ? Do you have any solution I can try, please ?

Thanks !

Regards,

Antoine

#cubemx
1 ACCEPTED SOLUTION

Accepted Solutions
Jocelyn RICARD
ST Employee
Posted on January 12, 2017 at 18:36

Hello Antoine,

I could reproduce a compilation issue with Attollic, IAR and Keil but looks a bit different.

What is failing is the compilation of usbh_conf.c after adding the 2 lines in main.h

This seems to be linked to a recent change in code generation:

In generated stm32f4xx_hal_conf.h there is the line

#include 'main.h'

In older version of Cube there was instead 

#include 'mxconstants.h'

If I remove this include main.h, compilation of usbh_conf.c is ok.

The error I get is:

In file included from ../Inc/main.h:49:0,

from ../Inc/stm32f4xx_hal_conf.h:43,

from ../Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h:48,

from ../Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:245,

from ../Inc/usbh_conf.h:55,

from ../Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h:37,

from ../Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc.h:37,

from ..\Middlewares\ST\STM32_USB_Host_Library\Class\MSC\Src\usbh_msc.c:42:

../Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h:281:44: error: 'USBH_MAX_NUM_ENDPOINTS' undeclared here (not in a function)

USBH_EpDescTypeDef Ep_Desc[USBH_MAX_NUM_ENDPOINTS];

Actually usbh_conf.h which defines the 

USBH_MAX_NUM_ENDPOINTS is itself including stm32f4xx.h which leads to include main.h. So in main.h you include a header file 

As a workaround I would suggest adding your lines in the main.c file if possible or create another header file if you need to share this with another source file.

Jocelyn

View solution in original post

2 REPLIES 2
Amel NASRI
ST Employee
Posted on January 12, 2017 at 17:21

Hi

WAJNTRAUB.Antoine

‌,

I tried the same using Keil and didn't got any compilation issue.

In order to be in the same configuration conditions, please share your IOC file. I'll give it a try using TrueStudio.

Then as general recommendation to generate Host example, please refer to UM1718:

  • subsection '6.6.5 Configuring the middleware'
  • Appendix 'B.3STM32CubeMX design choices and limitations for middleware initialization'

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Jocelyn RICARD
ST Employee
Posted on January 12, 2017 at 18:36

Hello Antoine,

I could reproduce a compilation issue with Attollic, IAR and Keil but looks a bit different.

What is failing is the compilation of usbh_conf.c after adding the 2 lines in main.h

This seems to be linked to a recent change in code generation:

In generated stm32f4xx_hal_conf.h there is the line

#include 'main.h'

In older version of Cube there was instead 

#include 'mxconstants.h'

If I remove this include main.h, compilation of usbh_conf.c is ok.

The error I get is:

In file included from ../Inc/main.h:49:0,

from ../Inc/stm32f4xx_hal_conf.h:43,

from ../Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h:48,

from ../Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:245,

from ../Inc/usbh_conf.h:55,

from ../Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h:37,

from ../Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc.h:37,

from ..\Middlewares\ST\STM32_USB_Host_Library\Class\MSC\Src\usbh_msc.c:42:

../Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h:281:44: error: 'USBH_MAX_NUM_ENDPOINTS' undeclared here (not in a function)

USBH_EpDescTypeDef Ep_Desc[USBH_MAX_NUM_ENDPOINTS];

Actually usbh_conf.h which defines the 

USBH_MAX_NUM_ENDPOINTS is itself including stm32f4xx.h which leads to include main.h. So in main.h you include a header file 

As a workaround I would suggest adding your lines in the main.c file if possible or create another header file if you need to share this with another source file.

Jocelyn