cancel
Showing results for 
Search instead for 
Did you mean: 

VCP for STM32F3

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.
57 REPLIES 57
Posted on February 22, 2018 at 21:33

As I said earlier, some later discovery boards do offer vcp. 

The schematic for the f3 discovery board (rev d) showed a uart connection between the target and host, and the document said that vcp is available for stlink v2b on that board. V2 doesn't have vcp capabilities.

So you just need to find out which board you have and test it out with some code.

Cannot be more definitive than that.

I do think the earlier suggestion of going with a nucleo board is spot on.

Posted on February 22, 2018 at 21:47

I have all sorts of boards (supporting Virtual COM through ST-LINK and those without this capabilities).

Both kinds of board can work with the USB. In the latter case I simply use USB/CDC drivers based on HAL (I described earlier what kind of caveats needss to be addressed).

I think we considered all options here and spent more time than required to implement either options;)

Posted on February 22, 2018 at 22:01

Another route you may wish to explore, potentially riskier but feature richer, is jlink-ob. Jlink offers a utility to turn certain stlink into jlink-ob. And back if you so desire. In jlink-ob, you have swo and rtt, much richer tools than vcp.

They list f3discovery boards as eligible - not sure if it applies to all revisions of that board, thus the added risk.

Posted on February 22, 2018 at 22:15

I have not considered it yet.

Once converted the st-link to the jlink and it worked fine. Then switched to the standalone jlink. So it seems that segger approach to promote jlink features works:)

Posted on February 23, 2018 at 08:26

While I agree - having some Nucleo boards myself - it is still up to the OP to decide. Basically between coding effort and money.

He had not answered here for quite a long time, I guess you chased him away ... ;)

Posted on February 23, 2018 at 09:51

AvaTar wrote:

it is still up to the OP to decide.

Indeed.

But it remains unclear that the OP has actually understood the options.

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
Associate
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();

...

}

}