cancel
Showing results for 
Search instead for 
Did you mean: 

STM32cubef4 USB Virtual COM port

harinath
Associate III
Posted on April 15, 2014 at 04:12

Hello All,

I found a few samples for USB Virtual COM port for STM32F4-Discovery board, but they are pretty old & not based on STM32CubeF4

Could anyone please hint me or direct me to a sample which has Virtual COM port based on STM32CubeF4 ?

Thanks in advance.

#vcp-stm32f4 #stm32cubef4
9 REPLIES 9
schauer
Associate II
Posted on April 16, 2014 at 10:03

Hello kunnu,

within STM32Cube MX you could set the USB device class in the Configuration -> Middleware -> USB Device section.

In that case you should get a skeleton USB/CDC device receiving data that works mostly as expected.

Hope that helps, BS

harinath
Associate III
Posted on April 16, 2014 at 10:05

See the schematic of my board. I'm not using U_DET pin.

0690X00000605eZQAQ.png

STM32Cube firmware has an sample. The path is

C:\Users\Administrator\Downloads\STM32Cube_FW_F4_V1.1.0\Projects\STM324xG_EVAL\Applications\USB_Device\CDC_Standalone\Src They say:

This example is a part of the USB Device Library package using STM32Cube firmware. It describes how to use USB device application based on the Device Communication Class (CDC) following the PSTN subprotocol in the STM32F4xx devices using the OTG-USB and UART peripherals.

I have removed UART part of the sample as I need only VCP part. But still no luck. My board has 12MHz crystal, I modified HSE_VALUE to 12 MHz. Here is my clock configuration which was also correct.

static
void
SystemClock_Config(
void
)
{
RCC_OscInitTypeDef RCC_OscInit;
RCC_ClkInitTypeDef RCC_ClkInit;
/* Enable Power Control clock */
__PWR_CLK_ENABLE();
/* The voltage scaling allows optimizing the power consumption when the device is 
clocked below the maximum system frequency, to update the voltage scaling value 
regarding system frequency refer to product datasheet. */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/* Configure RCC Oscillators: All parameters can be changed according to user뭩 needs */
RCC_OscInit.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInit.HSEState = RCC_HSE_ON;
RCC_OscInit.PLL.PLLState = RCC_PLL_ON;
RCC_OscInit.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInit.PLL.PLLM = 8;
RCC_OscInit.PLL.PLLN = 224;
RCC_OscInit.PLL.PLLP = 2;
RCC_OscInit.PLL.PLLQ = 7;
HAL_RCC_OscConfig (&RCC_OscInit);
/* RCC Clocks: All parameters can be changed according to user뭩 needs */
RCC_ClkInit.ClockType = RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_HCLK |RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInit.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInit.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInit.APB1CLKDivider = RCC_HCLK_DIV4; 
RCC_ClkInit.APB2CLKDivider = RCC_HCLK_DIV2; 
HAL_RCC_ClockConfig (&RCC_ClkInit, FLASH_LATENCY_5);
}

I could be able to blink an on board LED too. @bs: I'm not using STM32CubeMX as it has some problems generating code. I just manually created my project in IAR EWARM and added Cube libraries. Any ideas please ?
schauer
Associate II
Posted on April 16, 2014 at 13:22

It might be good to know a few more things:

Do you use a custom or evaluation board?

What exactly is the issue?

If the device is not enumerating, you could check if

 - the USB is clocked (and enabled) accordingly

 - the USB input pins (incl. Vbus) are configured as USB AF

Additionally you could check what happens on the USB Bus. I use Wireshark for that - it is available for multiple operating systems and also capable of capturing/decoding USB packets.
richard239955
Associate II
Posted on April 16, 2014 at 14:47

Here's a VCP mirror for STM32F4 Discovery. The main skeleton was build with CubeMX. The included project is suited for Keil MDK. I described the minor code changes in another [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/USB%20CDC%20Bug%20in%20CubeMX%20firmware&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21]post

________________

Attachments :

Test_USB.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzSL&d=%2Fa%2F0X0000000bM5%2FqvphE6alol1mdGI8sQ19YRyA.9T3i4xIO8rehuXjgUM&asPdf=false
harinath
Associate III
Posted on April 17, 2014 at 03:41

Stm32Cube generated project for IAR works, pls find attachment. This means Hardware is fine.

But I still wonder why my code is not working !

see the

usbd_cdc_interface.c and

.h files for what I have modified from sample.

CDC_Itf_Init() and

CDC_Itf_Control()functions must be called, but are not being called. This could be problem.

________________

Attachments :

CubeMXproj.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzRw&d=%2Fa%2F0X0000000bM4%2F.Coa1hMxMYJk_UvVI5TIojS_WK1MbsWB5w10KeMvUmI&asPdf=false

usbd_cdc_interface.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzRm&d=%2Fa%2F0X0000000bM3%2FqIAfvbeNRXpvVMBL7kPl1NZ3QcMBqXoQenroN9w0Tgs&asPdf=false

usbd_cdc_interface.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzM5&d=%2Fa%2F0X0000000bM2%2FR41D4OIr1b_ytLEZiQSEQXpQbvOpAuQ2UNaYgLrWZtA&asPdf=false
harinath
Associate III
Posted on April 17, 2014 at 10:36

It is working. The problem was with VBUS pin initialization and sensing settings.

I removed VBUS pin initialization in  usbd_conf.c in the following function

void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)

also disabled sensing in USBD_StatusTypeDef  USBD_LL_Init (USBD_HandleTypeDef *pdev)

hpcd.Init.vbus_sensing_enable = 0; 

It means, I'm not using VBUS now.

Thanks for all the help.

stm32cube-t
Senior III
Posted on April 22, 2014 at 12:11

Hello Kunnu,

We do not encounter your problem.

To try to reproduce your issue could you please send us STM32CubeMX .ioc configuration file for your project?

Thank you.

arsalan_elec
Associate II
Posted on April 23, 2014 at 18:02

Hello,

this is my first post here! sorry for my bad english.

i had the same problem and i had to disable the vbus sensing even if i didn't set it to enable in CubeMX, but that was before i upgraded to firmware 1.1 and CubeMX 4.1 .

another problem is in the ''usbd_cdc.h''  in structure of ''USBD_CDC_HandleTypeDef''

uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE/4];      /* Force 32bits alignment */

the data size is depend on HS max packet even if you use device in FS mode and if the HS max is 512 the windows give the error ''This device cannot start. (Code 10)''; so i have to chage it to 256.

harinath
Associate III
Posted on April 24, 2014 at 02:17

@STM32Cube-T

The problem i described was not in the CubeMX project. It was in the CDC_Standalone sample in STM32CubeF4 firmware package. Also, the hardware is designed in our lab.