AnsweredAssumed Answered

Sample code and some possible errors for comunication between STM32F411 and PC

Question asked by mao on Oct 24, 2015

In the past couple days I was studying the communication between STM32 and PC via CDC/VCP over usb. The code seems simple and works on F4 discovery board, but it just didn\t work on my own board. After searching website, I found there are lots of people may have this kind of problem. Therefore I summarize the problem and put into a file.
The sample code can be download via the public repository.
You can download a free tool there too to monitor the data sent via the com.

I attached a complete introduction file in this post.

Development tools:

Keil 5.16a, FDP2.6 pack.
Cubemx  v1.8pack.
Chip: STM32F411RC 64pins.

(1). PC doesn't response at all when you plug in the usb cable.
This is the most headache you may face. There are lots of possibility. 
One of them is the missing pull-up resistor.  You may need to connect a 1.5kohm pull up resistor.
The idea is the device needs to be correctly identified.

(2). PC response, but it prompts "USB device not recognized"

The problem is that my own board uses self-powered usb. Doesn't use the VBUS.
Therefore it should be disabled.
hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
hpcd_USB_OTG_FS.Init.dev_endpoints = 7;
hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
hpcd_USB_OTG_FS.Init.ep0_mps = DEP0CTL_MPS_64;
hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;//changed to disable, since we don't use vbus
hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;

(3).USB is recognized by PC, but reported as unknown or "This device cannot start"
This problem was discussed in the forum as link:
This one is easy to correct. Go to startup file
and change stacksize and heap size from 400-> 4000, 200->2000.
Stack_Size      EQU     0x000004000
Stack_Mem       SPACE   Stack_Size
; <h> Heap Configuration
;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size       EQU     0x000002000