cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F303 USB CDC tutorial

Manoj Hiwarkar
Associate III

Hello,

I am trying the USB Communication stm32f303 with android phone usins CDC USB TERMINAL app . I am able transmit all the string. But while reception I am receiving only the first character.

13 REPLIES 13
Imen.D
ST Employee

Hello @Manoj Hiwarkar​ ,

I recommend you the CDC example available in the STM32CubeF3 package at this path:

STM32Cube_FW_F3_V1.10.0\Projects\STM32303C_EVAL\Applications\USB_Device\CDC_Standalone

You can follow the instructions on the readme file to make a basic USB CDC project.

With Regards,

Imen.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Bench
Associate III

Hi Imen,

Thank you for the example. Do you have a similar one for the F3030ZE Nucleo board? I am trying hard to get the CDC usb interface running but it doesnt work so far. The device just even doen't appear in the device manager. Is there maybe a configuration problem in CubeMX? I attached the cubeMx file.

I would be very thankful if you could help me!

Thank you a lot in advance.

Best regards

Ben K
Senior III

ST should be really ashamed of itself at this point, in the Cube Repository there are no HAL MSP source files in any of the USB application projects. These would really be necessary to show how the interrupts and the GPIOs should be set up for the USB. Specifically the part where (at least for F3 and earlier series) a GPIO in output mode is tied to USB_DP line with 1K5 to control the attached state of the USB device. This is pin PG6 for this Nucleo board in question, which I could only find out from the schematics, as when opening the board in CubeMX the pin shows up as "USB PowerSwitchOn" (that functionality is not present on this Nucleo at all).

Long story short, don't count on out-of-the-box solutions. To solve your problem just set up PG6 as PP output, and paste this code in a source file of your choosing:

#include "stm32f3xx_hal.h"

void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)

{

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6, state);

}

(I would link to the post from half a year ago where I explained the same, but I can't recover it from the old forum engine.)

Manoj Hiwarkar
Associate III

Ok my problem is solved. I am getting the whole string now

Bench
Associate III

@Imen DAHMEN​ : I still have the problem that I cannot connect my nucleo board stm32f303ZE with with the PC via USB by using the CUbeMX generated Code. Do You have an example also for this nucleo board?

I would be very thankful!

Best regards,

Imen.D
ST Employee

Hello @Bench​ ,

I recommend you to increase heap and stack sizes in the CubeMx setting.

There is no USB CDC example available in the STM32CubeF3 for STM32F303ZE. You can get inspired from other CDC examples to develop your own project.

With Regards,

Imen.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Bench
Associate III

Hi @Imen DAHMEN​ 

thank you for the recommendation. I already did that. Unfortunately it still doesnt work. Above is the Cube file I use and the generated code doesnt include the GPIO Config for the pins. So I think there might be a bug in Cube. The Code looks also different if I generate an USB project for the L4 for example. There the Pins are configured and the functions are not empty as in the COde for F303ze. Could that be?

Thanks a lot and best regards

Imen.D
ST Employee

Hi @Bench​,

Is this issue encountered using latest version of STM32CubeMx V4.27.0?

If you are using previous version of CubeMX, please update it to use the last one (V4.27.0) and check if this resolve your issue.

With Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Bench
Associate III

Hi @Imen DAHMEN​ ,

thank you for the advice, that there is a new version of Cube. However, I get the same problem and the MSP_init functions are still empty and the initialization of the Pins is still missing as you can see in the attached file.

I am thankful for any kind of help!

Best regards