2025-08-20 4:56 AM
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?
2025-08-20 5:34 AM
Use printf to send characters over the VCP once it's enabled by the BSP.
printf("Hello world!\n");
2025-08-20 5:49 AM
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.
2025-08-20 6:10 AM
The source code is available for inspection. It's all in the project.
2025-08-20 6:11 AM
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.