cancel
Showing results for 
Search instead for 
Did you mean: 

nucleo STM32G474RE UART communication

enee
Visitor

Hello,

I just created a default project with the nucleo board template and with VCP initialized, how can I transmit data via UART using the VCP?

4 REPLIES 4
TDK
Super User

Use printf to send characters over the VCP once it's enabled by the BSP.

 

printf("Hello world!\n");

 

 

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for the answer, but I know that I can do it like this. I would like to learn more about the abstraction implemented by the BSP on the VCP over the redirection of printf.

The source code is available for inspection. It's all in the project.

If you feel a post has answered your question, please click "Accept as Solution".
mfgkw
Associate III

The VCP is simply one (LP)U(S)ARTx routed to the ST-Link, which in turn appears as an USB device at the PC.

In case of your NUCLEO-STM32G474RE it is LPUART1 used for this by default. It can be changed to USART1 by changing solder bridges, see UM2505 chapter 6.6.5 "Virtual COM port (VCP): LPUART and USART".

The prinf() in turn function calls

     int _write( int file, char *ptr, int len );


which must be implemented to transfer characters to the UART. If you need no other files and file handles the  function might ignore its first argument and print everything to the same UART.