Skip to main content
Visitor II
August 30, 2018
Question

STM32F303 USB CDC tutorial

  • August 30, 2018
  • 11 replies
  • 4834 views

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.

    This topic has been closed for replies.

    11 replies

    Technical Moderator
    August 30, 2018

    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.

    Visitor II
    August 31, 2018

    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

    Visitor II
    September 3, 2018

    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.)

    Visitor II
    February 13, 2023

    It's impossible to find any f303ze USB resources. Struggling to even get it to receive setup packets. Initializing it with the HAL and it seems to only trigger the resume interrupt when plugged in. Then nothing. Wish there was actual documentation about how to use this thing

    Visitor II
    September 4, 2018

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

    Visitor II
    December 28, 2018

    hi Manoj

    i'm also facing same kind of issue inSTM32L452RE controller ,can u explain how u solved that issue

    Visitor II
    September 10, 2018

    @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,

    Technical Moderator
    September 18, 2018

    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.

    Visitor II
    September 20, 2018

    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

    Technical Moderator
    September 21, 2018

    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

    Visitor II
    September 21, 2018

    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

    Technical Moderator
    September 25, 2018

    Hello @Bench​ ,

    You are right, I confirm that using STM32CubeMx (version 4.27.0), the MspInit functions are empty and there is no GPIO Configuration for STM32F303 and STM32F302.

    This issue is raised internally to CubeMx team for fix.

    Thank you for bringing this issue to our attention.

    Kind Regards,

    Imen.