Skip to main content
Explorer II
January 10, 2025
Solved

Help Understanding BSP_COM for Communication

  • January 10, 2025
  • 2 replies
  • 2623 views

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.

Best answer by mƎALLEm

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)

2 replies

Andrew Neil
Super User
January 10, 2025

@jin96 wrote:

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


Have you tried scanf ?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
mƎALLEm
mƎALLEmBest answer
Technical Moderator
January 10, 2025

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 "Best answer" on the reply which solved your issue or answered your question.