cancel
Showing results for 
Search instead for 
Did you mean: 

Help Understanding BSP_COM for Communication

jin96
Associate

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.

1 ACCEPTED SOLUTION

Accepted Solutions
mƎALLEm
ST Employee

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)

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.

View solution in original post

2 REPLIES 2

@jin96 wrote:

 Is there a built-in function in BSP_COM for receiving data.


Have you tried scanf ?

mƎALLEm
ST Employee

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)

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.