2025-01-10 01:44 AM - last edited on 2025-01-10 02:27 AM by Andrew Neil
Code formatting applied - please see here for future reference.
Hello everyone,
I'm currently working on an STM32 project using the NUCLEO-G431KB board. I've come across the BSP_COM API in the STM32Cube firmware, which seems to be an abstraction layer for handling USART/UART communication. I have successfully set up the following code to send data over a virtual COM port using "printf":
COM_InitTypeDef BspCOMInit;
BspCOMInit.BaudRate = 115200;
BspCOMInit.WordLength = COM_WORDLENGTH_8B;
BspCOMInit.StopBits = COM_STOPBITS_1;
BspCOMInit.Parity = COM_PARITY_NONE;
BspCOMInit.HwFlowCtl = COM_HWCONTROL_NONE;
if (BSP_COM_Init(COM1, &BspCOMInit) != BSP_ERROR_NONE) {
Error_Handler();
}
printf( "Hello, Virtual COM Port!\n" );
This works perfectly for transmitting data, but I'm struggling to figure out how to receive data using the BSP_COM interface. Is there a built-in function in BSP_COM for receiving data, or do I need to revert to using HAL_UART_RECEIVE or similar HAL functions for this purpose?
Thank you for your help.
2025-01-10 02:35 AM
@jin96 wrote:Is there a built-in function in BSP_COM for receiving data.
Have you tried scanf ?
2025-01-10 04:04 AM
Hello @jin96 and welcome to the community,
There is no BSP API for UART receive.
Need o use HAL functions and inspire from the examples provided in Cube G4 package.
Or use scanf as stated by @Andrew Neil see https://embedthreads.com/how-to-use-printf-and-scanf-on-stm32-using-uart/ (not tested)