2015-10-23 03:13 PM
Hello,
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.https://bitbucket.org/rwmao/cdc_onstm32f411rc/downloads
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.
http://www.usbmadesimple.co.uk/ums_3.htm
(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;
HAL_PCD_Init(&hpcd_USB_OTG_FS);
(3).USB is recognized by PC, but reported as unknown or ''This device cannot start''
This problem was discussed in the forum as
/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/USB%20CDC%20recognized%20by%20computer%2c%20but%20device%20manager%20says%20This%20device%20cannot%20start.%20%28Code%2010%29&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=744
: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
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (
in
Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x000002000
#stm32f4 #usb #cdc #vcp #stm32