Skip to main content
Erenburg.Evgeny
Associate III
February 21, 2018
Question

VCP for STM32F3

  • February 21, 2018
  • 57 replies
  • 6543 views
Posted on February 21, 2018 at 14:09

I'm trying to implement Virtual Com Port on STM32F3. I use IAR.

I've included all files from a demo project.

0690X00000609h4QAA.png

However I have numerous errors while compiling the project. Struggling for hours I came to this question

Is there any compiled project with VCP for STM32F3?

Note: this post was migrated and contained many threaded conversations, some content may be missing.
    This topic has been closed for replies.

    57 replies

    Bogdan Golab
    Lead
    February 21, 2018
    Posted on February 21, 2018 at 14:55

    Discovery board? What model? Some come in two flavors - with and w/o VCOM supported. It's a matter of st-link version (2-1 and 2B support VCOM). See the documentation of the particular board

    Erenburg.Evgeny
    Associate III
    February 21, 2018
    Posted on February 21, 2018 at 14:58

    Can you advice what board come with VCP? I didn't find any.

    I need it as a demo project for a user connectivity, not to program/debug with ST-LINK.

    henry.dick
    Associate II
    February 21, 2018
    Posted on February 21, 2018 at 15:08

    The list of boards with vcp is practically limitless, most of them of no use to you.

    So you can help others help you by narrowing that down a little.

    Andrew Neil
    Super User
    February 21, 2018
    Posted on February 21, 2018 at 15:14

    I have numerous errors while compiling the project

    You're referring to this:

    https://community.st.com/0D50X00009XkfBRSAZ

    ?

    As noted there, you probably just have one actualmistake - but that results in a whole load of similar error reports.

    This is quite common - one mistake causes resultant errors in everything else that depends upon it.

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Erenburg.Evgeny
    Associate III
    February 21, 2018
    Posted on February 21, 2018 at 15:18

    Well - I invented a shortcut - to take an example and to see what's going wrong.

    Erenburg.Evgeny
    Associate III
    February 22, 2018
    Posted on February 22, 2018 at 07:33

    I think I have to clarify things. I want to connect my PC's USB to USB on a board  and use it as UART terminal.

    Bogdan Golab
    Lead
    February 22, 2018
    Posted on February 22, 2018 at 07:50

    So select the Discovery or Nucleo model:

    http://www.st.com/en/evaluation-tools/stm32-mcu-nucleo.html?querycriteria=productId=LN1847

     

    http://www.st.com/en/evaluation-tools/stm32-mcu-discovery-kits.html?querycriteria=productId=LN1848

     

    Look at price, sensors, displays, arduino connectors (can add extra HW  - arduino shields). All new boards supports VCP - Virtual COM emulated by the ST-LINK programmer / debugger.

    Also boards equipped with the second USB port (Some if not all Discovery boards)  can use USB CDC  - direct connection from the MCU to the PC without ST-LINK.

    Erenburg.Evgeny
    Associate III
    February 22, 2018
    Posted on February 22, 2018 at 08:55

    Hi Bogdan,

    I perfectly understand that all boards supports VCP. I have no problem with the hardware. The problem I didn't found any compiled VCP  example.

    My English too bad? It's hard to understand what I want? I start to panic.

    Andrew Neil
    Super User
    February 22, 2018
    Posted on February 22, 2018 at 10:17

    Perhaps this helps to distinguish the USB connection via the on-board ST-Link from the Target microcontroller's USB connection:

    0690X00000609knQAA.png
    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Andrew Neil
    Super User
    February 22, 2018
    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Erenburg.Evgeny
    Associate III
    February 22, 2018
    Posted on February 22, 2018 at 11:45

    MY DEAR LORD!!!

    IS THERE ANY ADEQUATE PERSON ON THE FORUM UNDERSTANDING ME???

    Andrew Neil
    Super User
    February 22, 2018
    Posted on February 22, 2018 at 11:47

    You seem to be the one failing to understand.

    As has been explained a number of times, there are two possible ways to have a 'VCP' on a Nucleo or Discovery board. 

    You have not yet clarified which particular 'VCP' option you require.

    So, please answer the simple question: Is using the VCP provided by the ST-Link sufficient for you?

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Erenburg.Evgeny
    Associate III
    February 22, 2018
    Posted on February 22, 2018 at 12:01

    Provided by the ST-LINK??? How ST-LINK involved here?

    I have STM32F3DISCOVERY BOARD (MB1035B)

    I debug/program on USB-LINK connector. And VCP communication I what to run on USB USER connector.

    A piece of the demo code

    while ( 1 ) {

            if (bDeviceState == CONFIGURED)

            {

                STM_EVAL_LEDOn(LED6);

                CDC_Receive_DATA();

                /* Check to see if we have data yet */

                if (Receive_length  != 0)

                {

                    STM_EVAL_LEDOn(LED4);

                    int i;

                    for (i = 0; i < Receive_length; i++) {

                        localBuffer[i] = Receive_Buffer[i];

                    }

                    CDC_Send_DATA(localBuffer, Receive_length);

                    Receive_length = 0;

                }

            }

        }

    The problem I can not compile the demo so I want to see compiled example for IAR.

    Jesus Christ

    ! What I'm asking? NASA project?
    henry.dick
    Associate II
    February 22, 2018
    Posted on February 22, 2018 at 17:25

    It is not difficult to tell if your board supports vcp. Take a look at the schematic of your board. There should be a connection between the debuggers uart and the targets uart pins.

    If there is, there is a chance you board supports vcp. Otherwise, no chance and you have to move on.

    Later jtag support swo and jscope ... So that's another option.

    Andrew Neil
    Super User
    February 22, 2018
    Posted on February 22, 2018 at 17:50

    dhenry wrote:

    It is not difficult to tell if your board supports vcp.

    I think you need to be clear that you're talking here about VCP via the ST-Link.

    It's still not clear that the OP has understood that there are two possible ways to do 'VCP'; viz,

    1. via the ST-Link;
    2. by implementing USB/CDC on the target microcontroller.
    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    AvaTar
    Senior III
    February 22, 2018
    Posted on February 22, 2018 at 18:29

    Just to mention it - the F3 Discovery firmware package has an USB example project, too.

    I guess it's not VCP specific code, though.

    I think what the OP was trying to tell us as well - his F3 discovery has no ST-Link with VCP (V2, like mine).

    So option 1 drops out.

    Andrew Neil
    Super User
    February 22, 2018
    Posted on February 22, 2018 at 18:38

    AvaTar wrote:

    I think what the OP was trying to tell us as well - his F3 discovery has no ST-Link with VCP (V2, like mine).

    So option 1 drops out.

    But I think that this thread, and the previous thread, demonstrate that it would be far simpler to just get a board with the VCP-equipped ST-Link ?

    See:

    https://community.st.com/0D50X00009XkfBTSAZ

    The cost of the time spent on this so far would have bought several dozen Nucleo and/or discovery boards - with premium delivery!!

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Bogdan Golab
    Lead
    February 22, 2018
    Posted on February 22, 2018 at 18:51

    For hobbyist like me more fun is to develop the VCP w/o st-link.

    You are (unfortunately) professionals and 'time is money' is your every day mantra:)

    Erenburg.Evgeny
    Associate III
    February 25, 2018
    Posted on February 25, 2018 at 09:14

    Why I love professionals? - they resolve problems in a second.

    Go to ST -> download STM32_USB-FS-Device_Lib_V4.1.0 -> have a demo for F3 in IAR.

    Ivan Elkin
    Visitor II
    March 1, 2018
    Posted on March 01, 2018 at 09:48

    Hi 

    erenburg.evgeny.002

    I've check the code on stm32F103RE, STM32F4DISCOVERY, STM32F417

    I use the CubeMX. And I'm sorry for long letter...

    I setup CDC project for USB FS, set heap=stack=0x2000

    usbd_cdc_if.c:

    /* USER CODE BEGIN INCLUDE */

    #include 'Device.h'

    /* USER CODE END INCLUDE */

    ...

    /* USER CODE BEGIN PRIVATE_TYPES */

    //EXCLUDE_THIS_BEGIN

    #if 0

    /* USER CODE END PRIVATE_TYPES */

    ...

    /* USER CODE BEGIN PRIVATE_VARIABLES */

    #endif

    //EXCLUDE_THIS_END

    /* USER CODE END PRIVATE_VARIABLES */

    ...

    static int8_t CDC_Control_FS  (uint8_t cmd, uint8_t* pbuf, uint16_t length)

    {

    ...

    case CDC_SET_LINE_CODING:

    SetLineCoding((const SLineCoding*) pbuf);

    break;

    case CDC_GET_LINE_CODING:

    GetLineCoding((SLineCoding*) pbuf);

    break;

    ...

    }

    static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)

    {

    /* USER CODE BEGIN 6 */

    // USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);

    // USBD_CDC_ReceivePacket(&hUsbDeviceFS);

    SeveUsbIncomingMessage(*Len);

    return (USBD_OK);

    /* USER CODE END 6 */

    }

    Now I create 2 files: Device(c|cpp,h)

    Device.h:

    #ifdef __cplusplus

    extern 'C' {

    #endif

    typedef struct LineCoding

    {

    uint32_t bitRate;

    uint8_t stopBits;

    uint8_t parityType;

    uint8_t dataBits;

    } SLineCoding;

    #define APP_RX_DATA_SIZE 64

    #define APP_TX_DATA_SIZE 64

    typedef uint8_t TRxBuffer[APP_RX_DATA_SIZE];

    typedef uint8_t TTxBuffer[APP_TX_DATA_SIZE];

    extern uint8_t* UserRxBufferFS;

    extern uint8_t* UserTxBufferFS;

    void SeveUsbIncomingMessage(uint32_t msgSize);

    void SetLineCoding(const SLineCoding *lc);

    void GetLineCoding(SLineCoding *lc);

    void HandleMessage(void);

    Device.c(pp):

    void SeveUsbIncomingMessage(uint32_t msgSize)

    {

    gsUsbMsgSize = msgSize;

    }

    void HandleMessage(void)

    {

    ShowAlive();

    if(0 > gsUsbMsgSize) {

    return;

    }

    //Do some useful here

    USBD_CDC_ReceivePacket(&hUsbDeviceFS);

    }

    static SLineCoding 

    gsLineCoding;

    void SetLineCoding(const SLineCoding *lc)

    {

    memcpy(reinterpret_cast<void *> (&gsLineCoding), reinterpret_cast<const void *> (lc),sizeof(gsLineCoding));

    }

    void GetLineCoding(SLineCoding *lc)

    {

    memcpy(reinterpret_cast<void *> (lc), reinterpret_cast<void *> (&gsLineCoding), sizeof(gsLineCoding));

    }

    main.c:

    #include 'Device.h'

    ...

    int main(...)

    {

    ...

    while(1)

    {

    ...

    HandleMessage();

    ...

    }

    }