Dear readers,
I’m developing a SW project with KEIL MDK Plus (V5.25) and the STM32CubeMX (V6.5) tool. The target processor is the STM32F303VCTx and everything goes well until I added a USB device to the project.
Before I describe the issue I’d like to ask some basic questions for a better comprehension:
When I generate the code with CubeMX a new KEIL project is generated in the path
…\RTE\Device\STM32F303VCTx\STCubeGenerated\MDK-ARM
and the original KEIL project is going to be updated by CubeMX. May I understand the two KEIL projects as a generated output which shares some common resources ?
The problem appears when I added a USB device and the Middleware class USB_DEVICE with HID. After generating code and compiling the project I received the following message:
./RTE/Device/STM32F303VCTx/STCubeGenerated/Inc\usb_device.h(33): error: 'usbd_def.h' file not found
In principle, it’s possible to fix this by adding manually some groups from the generated cubeMX code and with some include path from my local STM32Cube repository but I’m not sure whether this is the right way?
I guess I have to add the USB port to the run time environment. Is this correct:
CubeMX looks like this:
and the KEIL project folder looks like this:
Any suggesting how to solve the missing groups, paths and entries in the KEIL project ?
Thanks in advance.
Best regards
Norbert
Hello Norbert, a first quick reply
- the integration of a Middleware component (like USB) requires a registered version of Keil MDK:
http://www2.keil.com/mdk5/selector
http://www.keil.com/distis/
- see also:
Using Keil MDK with STM32CubeIDE
USB Component: USB Component (keil.com)
Hello,
Thanks for your response!
We have a registered MDK Plus version V5.35 (flex) which should be working with the Middleware component. There are some limitations when I want to use the USB debug functions with source code but I'm using the release implementation. The release package is compile able with the Plus version.
As a registered user, please open a new Support Ticket with this and coming technical requests:
https://www.arm.com/support/contact-support
There are two different USBD stack options if you are using those tools (unless I'm very much mistaken). There is the Keil Middleware and there is the (free) STM stack. Perhaps you are caught in a mix of the two?
Personally, after evaluating several stacks, I went with libusb_stm32 from Dmitry on github. I felt it was lean enough yet complete enough to get my objectives done. There are many other 3rd party stacks as well, such as no-longer-tiny TinyUSB.
Hello Grant,
The two USBD options are a little confusing because sometimes I have to add the component in the Keil Runtime environment and sometimes it is enough to add it in STM32CubeMX only. Previously I tested both options without success. On the other hand when I want to use STM32CubeMX and I activate "Connectivity" with USB and "Middleware" with USB_Device I would expect that the existing folder are connected to my working project but no groups are added.
This is one of my starting questions: When I use STM32CubeMX and generate the code I'll find two projects (*.uvprojx), my working project and a new generated (STCubeGenerated.uvprojx) which contains the folder for the usb device. Should I merge these project or what is the typical way to manage this ?
When I merge both project and add some include paths it is possible to fix this issue and the project is compilable. Is this the intended way to do this ? (I'm not sure because when changing anything in CubeMX this could cause further manual actions)
Thanks in advance
Hello Norbert, as discussed in the support case, I repeat my answer also here for completeness.
First, you should ignore the STM32CubeMX generated MDK project. When after code generation the Cube asks to open it, just click "Close" in this dialog and change back to the actual µVision project from within you did start the STM32CubeMX from the RTE dialog.Then I think you need to decide, if you want to use USB HID from Cube or the Keil Middleware. If you want to use the Keil Middleware, deselect USB_DEVICE HID in Cube. Having enabled both potentially will not work.You can also check some example project and how that is configured, like the Middleware USB Device HID for STM32303E-EVAL example, which you can find in the Pack Installer Example tab.
Hello Andreas ,
Thanks for your message and the copy to the open support case.
I copied the configuration from the STM32303E-EVAL example project and the project is compileable now! I think you are right that I have to decide between the USB HID from Cube and KEIL middleware. I changed the device class from HID to the CDC class but in principle the config of the run time environment looks like this:
and with Cube I have to enable the USB device only without the middleware component.
Unfortunately the host can't connect and read the descriptor of the USB device and I'm still searching for other bugs. Maybe there is something wrong with the hardware - I have to find out ...