2022-03-11 05:51 PM
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?
Solved! Go to Solution.
2022-04-25 05:00 AM
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.
2022-04-25 05:00 AM
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.
2022-04-25 05:18 AM
...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
2022-04-25 06:03 AM
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:
Kind Regards.