cancel
Showing results for 
Search instead for 
Did you mean: 

Send and receive serial port data from PC to the ST25DV Discovery EVK via St-Link virtual COM port.

EGall.1
Associate

We would like this to be done though the St-Link virtual COM port that we see appears in windows when the MINI USB cable is plugged in.

The code seems to have some of this in place but it does not work...

#define COMn               ((COM_TypeDef)1)

#define COM1_UART             USART6

Usart6 seems like its the correct uart to use on the STM32 part that connects to the St-Link HW.

How to we send and receive to the PC from the demo code?

1 ACCEPTED SOLUTION

Accepted Solutions
Rene Lenerve
ST Employee

Hi @EGall.1​,

Yes you are right the code is embedding functions to communicate through the ST-Link (Guessing you are using ST25DV-DISCOVERY board with latest STSW-ST25DV001 firmware v1.2.0).

You will need to initialize the COM driver in the firmware with BSP_COM_Init and then use the printf function to send data to VCOM via ST-Link (fputc/__io_putchar is re-targeted to use USART6).

For example:

COM_InitTypeDef comlog;
 
comlog.BaudRate = 115200;
comlog.WordLength = COM_WORDLENGTH_8B;
comlog.StopBits = COM_STOPBITS_1;
comlog.Parity = COM_PARITY_NONE;
comlog.HwFlowCtl = COM_HWCONTROL_NONE;
 
BSP_COM_Init(COM1, &comlog);
 
printf("Hello World!");

This should display on PC side with a Serial console "Hello World!"

Hope this will help you.

Kind Regards.

View solution in original post

3 REPLIES 3
Rene Lenerve
ST Employee

Hi @EGall.1​,

Yes you are right the code is embedding functions to communicate through the ST-Link (Guessing you are using ST25DV-DISCOVERY board with latest STSW-ST25DV001 firmware v1.2.0).

You will need to initialize the COM driver in the firmware with BSP_COM_Init and then use the printf function to send data to VCOM via ST-Link (fputc/__io_putchar is re-targeted to use USART6).

For example:

COM_InitTypeDef comlog;
 
comlog.BaudRate = 115200;
comlog.WordLength = COM_WORDLENGTH_8B;
comlog.StopBits = COM_STOPBITS_1;
comlog.Parity = COM_PARITY_NONE;
comlog.HwFlowCtl = COM_HWCONTROL_NONE;
 
BSP_COM_Init(COM1, &comlog);
 
printf("Hello World!");

This should display on PC side with a Serial console "Hello World!"

Hope this will help you.

Kind Regards.

...and please don't forget the \n at the end of the string, otherwise the print buffer waits to be flushed, i.e.:

printf("Hello World!\n");

 Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Rene Lenerve
ST Employee

Hi @Peter BENSCH​,

Yes thank you for your precision that's right, I may add some information about that because it depends on the destination stream (and OSes) and not on the firmware:

  • When a stream is unbuffered, characters are intended to appear from the source or at the destination as soon as possible. Otherwise characters may be accumulated and transmitted to or from the host environment as a block.
  • When a stream is fully buffered, characters are intended to be transmitted to or from the host environment as a block when a buffer is filled.
  • When a stream is line buffered, characters are intended to be transmitted to or from the host environment as a block when a new-line character is encountered.
  • Furthermore, characters are intended to be transmitted as a block to the host environment when a buffer is filled, when input is requested on an unbuffered stream, or when input is requested on a line buffered stream that requires the transmission of characters from the host environment.

Kind Regards.