Skip to main content
Explorer
December 2, 2024
Question

STM32G4 BSP's virtual com port fails to print character when UART register callback is turned on.

  • December 2, 2024
  • 2 replies
  • 952 views

In a nutshell, as you turned on the UART register callback option as shown in the figure below, the virtual com port fails to print any items.

Screenshot 2024-12-02 at 2.32.23 PM.png

After further inspection, I believe it is a bug in `stm32g4xx_nucleo.c`, under function `BSP_COM_Init`. It seems like someone forget to index the `IsComMspCbValid` to find the validity of the given `COM`, as shown in code below. 

#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
static uint32_t IsComMspCbValid[COMn] = {0};
#endif

/**
 * @brief Configures COM port.
 * @PAram COM COM port to be configured.
 * This parameter can be COM1
 * @PAram COM_Init Pointer to a UART_HandleTypeDef structure that contains the
 * configuration information for the specified USART peripheral.
 * @retval BSP error code
 */
int32_t BSP_COM_Init(COM_TypeDef COM, COM_InitTypeDef *COM_Init)
{
 int32_t ret = BSP_ERROR_NONE;

 if(COM > COMn)
 {
 ret = BSP_ERROR_WRONG_PARAM;
 }
 else
 {
#if (USE_HAL_UART_REGISTER_CALLBACKS == 0)
 /* Init the UART Msp */
 COM1_MspInit(&hcom_uart[COM]);
#else
 if(IsComMspCbValid == 0U) // HERE
 {
 if(BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE)
 {
 return BSP_ERROR_MSP_FAILURE;
 }
 }
#endif

 if(MX_LPUART1_Init(&hcom_uart[COM], COM_Init) != HAL_OK)
 {
 return BSP_ERROR_PERIPH_FAILURE;
 }
 }

 return ret;
}

 This causes, `BSP_COM_RegisterDefaultMspCallbacks(COM)` never get called and the `COM` is never initialised. Thus the lack of response when using the `printf` function.

 

After adding indexing as shown in code below, the `printf` successfully work as intended.

 if (IsComMspCbValid[COM] == 0U)
 {
 if (BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE)
 {
 return BSP_ERROR_MSP_FAILURE;
 }
 }

 

Hopefully, the team could fix this small issue.

    This topic has been closed for replies.

    2 replies

    Technical Moderator
    December 10, 2024

    Hello @rechiekho and welcome to the community;

     

    Thank you for sharing this issue.

    To check the issue, could you share you project?

     

    Thank you.

    Kaouthar

    rechiekhoAuthor
    Explorer
    December 11, 2024

    I recreate the issue since I could not disclose the main project. Here is the Github repository: https://github.com/RechieKho/stm32g474_printf_error_on_uart_callback

    Technical Moderator
    December 11, 2024

    Hi @rechiekho;

     

    I reported this issue internally.

    Thank you for your contribution to the community.

    Internal ticket number: 198296 (This is an internal tracking number and is not accessible or usable by customers).

    Kaouthar