cancel
Showing results for 
Search instead for 
Did you mean: 

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

rechiekho
Associate

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.

3 REPLIES 3
KDJEM.1
ST Employee

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

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.

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

KDJEM.1
ST Employee

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

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.