Skip to main content
lamare
Associate II
Apr 23, 2025 7:39 AM UTC
Solved

Bug report: Incorrect validation in com port initalization of nucleo (G4) BSP

When using the register callbacks feature ( USE_HAL_UART_REGISTER_CALLBACKS = 1) , the BSP does not register the default callback, causing the serial port not to work. 

Fix:

 

 
diff --git a/Drivers/BSP/STM32G4xx_Nucleo/stm32g4xx_nucleo.c b/Drivers/BSP/STM32G4xx_Nucleo/stm32g4xx_nucleo.c
index 89b0837..bd2dd97 100644
--- a/Drivers/BSP/STM32G4xx_Nucleo/stm32g4xx_nucleo.c
+++ b/Drivers/BSP/STM32G4xx_Nucleo/stm32g4xx_nucleo.c
@@ -384,7 +384,7 @@ int32_t BSP_COM_Init(COM_TypeDef COM, COM_InitTypeDef *COM_Init)
 /* Init the UART Msp */
 COM1_MspInit(&hcom_uart[COM]);
 #else
- if(IsComMspCbValid == 0U)
+ if(IsComMspCbValid[COM] == 0U)
 {
 if(BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE)
 {
 
This topic has been closed for replies.
mƎALLEm
mƎALLEmBest answer
ST Technical Moderator
Apr 24, 2025 9:17 AM UTC

Hello @lamare ,

Issue reported. Internal Ticket 208444 (not accessible by community users).

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.

3 replies

ST Technical Moderator
Apr 23, 2025 10:07 AM UTC

Hi @lamare 

Do you configured the uart interrupt line and Nvic ?

lamare
lamareAuthor
Associate II
Apr 24, 2025 7:20 AM UTC

There's an obvious bug in the  stm32g4xx_nucleo.c file. At line 96 there's the declaration of the IsComMspCbValid array:

 

 
static uint32_t IsComMspCbValid[COMn] = {0};
 
At line 387 (BSP_COM_Init), it is supposed to check if the passed COM is valid, before attempting to register the callbacks, but the check is wrong:
#if (USE_HAL_UART_REGISTER_CALLBACKS == 0)
 /* Init the UART Msp */
 COM1_MspInit(&hcom_uart[COM]);
#else
 if(IsComMspCbValid == 0U)
 {
 if(BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE)
 {
 return BSP_ERROR_MSP_FAILURE;
 }
 }
#endif

Since IsComMspCbValid is a static array that has an address, this if statement:

if(IsComMspCbValid == 0U)

is *always* false, so BSP_COM_RegisterDefaultMspCallbacks is never called.

So, the if statement should be:

 if(IsComMspCbValid[COM] == 0U)

 

This way, it checks the value at offset COM in the array....

 

 

mƎALLEm
mƎALLEmBest answer
ST Technical Moderator
Apr 24, 2025 9:17 AM UTC

Hello @lamare ,

Issue reported. Internal Ticket 208444 (not accessible by community users).

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.