cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 USB CDC problem

pro100vald
Associate II
Posted on June 08, 2018 at 11:07

Hello everyone!

I`m trying to get CDC VCP working on STM2F407VET6 chip. I`ve created a project in STM32CubeMX (the latest version available), where I`ve set up clocks, enabled USB_FS_Device and USB CDC middleware. All the settings remained default, except for VBUS sensing, which was disabled.

After this, I`ve generated code for Atollic studio, compiled and run in without making any changes to code. When I plug my device into PC (Windows 10 Pro x64 with latest updates), device configures and enumerates correctly, no errors was reported, and COM4 port is assigned to device. However, if I try to open this port with any terminal software (like Putty or RealTerm), they are reporting connection error ('the parameter is incorrect' in RealTerm`s case). 

On the device side, in this moment hUsbDeviceFS.dev_state is equal to USBD_STATE_CONFIGURED, and if I try to call CDC_Transmit_FS, then it returns USBD_OK on first call and USBD_BUSY on all the next calls. However, I cannot recieve anything in terminal because of connection error.

I`ve already tried to increase heap and stack size, changing CDC buffers lengths and installing official STM CDC drivers. I`ve also defined

&sharpdefine USBD_DEBUG_LEVEL     3

and rerouted printf to UART, but I`m getting 0 debug messages.

So, what I`m doing wrong, how to troubleshoot USB connection and why STM32Cube generated code gives such error?

#atollic #stm32 #stm32f4 #usb #bug #cdc #stm32cube #connection-error
1 ACCEPTED SOLUTION

Accepted Solutions
pro100vald
Associate II
Posted on June 13, 2018 at 21:28

So, after long investigation and comparing my project with others, I finally found a solution.

1) Disable USB in STM32Cube.

2) Regenerate code.

3) Enable USB in STM32Cube, click 'Restore default' to any of available USB settings.

4) Generate code.

5) In TrueStudio, right-click project and 'refresh' it.

6) Compile and run.

After doing this, I finally got my CDC working. Hope it`ll help someone else.

By the way, I`m using STM32Cube 4.26.0, STM32F4 package 1.6.1, and TrueSTUDIO 9.0.1.

View solution in original post

5 REPLIES 5
Ant M
Associate II
Posted on June 08, 2018 at 15:22

I have a working USB CDC project for the F429 Disco board, with cubeMX project that may be a useful reference for you:

https://github.com/Ant1882/STM32F429-Tracealyzer-Demo

 

Ant

Posted on June 08, 2018 at 23:07

Thank you for your reply!

I've reviewed this project, and, unfortunately, my CDC configuration is the same, except for using FS port. Even more, half a year ago I've got an STM32F103C8T6 CDC up and running using exactly the same project creation procedure and toolchain.

I'm confused with the fact that enumeration and configuration stage is working just fine. Seems like USB stack is up and running. The only problem is that I'm getting error on port opening stage, but I have no idea how to debug this, because just watching at usb status variables via debugger gives nothing.

pro100vald
Associate II
Posted on June 13, 2018 at 21:28

So, after long investigation and comparing my project with others, I finally found a solution.

1) Disable USB in STM32Cube.

2) Regenerate code.

3) Enable USB in STM32Cube, click 'Restore default' to any of available USB settings.

4) Generate code.

5) In TrueStudio, right-click project and 'refresh' it.

6) Compile and run.

After doing this, I finally got my CDC working. Hope it`ll help someone else.

By the way, I`m using STM32Cube 4.26.0, STM32F4 package 1.6.1, and TrueSTUDIO 9.0.1.

P D Chauhan
Associate II

Hello,

I have also faced same problem and I searched and found the solution.

Do not know how you got solved your problem, but the actual reason is here:

The code generated by CubeMX has some fault. I came to know about this when I found below link:

https://community.st.com/s/question/0D50X00009XkfnjSAB/problem-solved-with-usb-cdc

This gives good reasoning and also the solution.

Regards.

so it does