Skip to main content
Visitor II
June 6, 2025
Solved

STM32L152 UART code missing in driver

  • June 6, 2025
  • 1 reply
  • 388 views

Good Day,

Recently I started working with a new MCU (STM32L152). I ported some UART code to handle received data from a different MCU, which worked fine. But as soon as I started testing edge cases I saw some weird things happen. I am using the DMA on the receive, and I rely on the Idle interrupt to send data to a different buffer for processing. It seemed like the Idle interrupt would trigger correctly for the following:
- data length < half buffer length

- data length = half buffer length

- half buffer length < data length < full buffer length

-  full buffer length < data length 

But it does not trigger for:

- data length = full buffer length
It turns out in HAL_UART_IRQHandler (in stm32l1xx_hal_uart.c) there is a missing piece of code that enables this to happen. This code existed in the previous MCU's UART driver. I checked that I had the newest library downloaded for STM32L152. The piece of missing code is attached.

 /*
 * NOTE: This else was manually put in to fix the Idle interrupt not firing on an EXACTLY full buffer
 * worth of data being received.
 */

 else
 {
 /* If DMA is in Circular mode, Idle event is to be reported to user
 even if occurring after a Transfer Complete event from DMA */
 if (nb_remaining_rx_data == huart->RxXferSize)
 {
 if (HAL_IS_BIT_SET(huart->hdmarx->Instance->CCR, DMA_CCR_CIRC))
 {
 /* Initialize type of RxEvent that correspond to RxEvent callback execution;
 In this case, Rx Event type is Idle Event */
 huart->RxEventType = HAL_UART_RXEVENT_IDLE;

#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
 /*Call registered Rx Event callback*/
 huart->RxEventCallback(huart, huart->RxXferSize);
#else
 /*Call legacy weak Rx Event callback*/
 HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize);
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
 }
 }
 }

 

    This topic has been closed for replies.
    Best answer by Veldbrand

    Thanks!


    I have removed the image and added the code.
    The MCU I copied the code from was the STM32L471.

    1 reply

    Super User
    June 6, 2025

    Welcome to the forum.

    Please see How to write your question to maximize your chances to find a solution for best results; in particular, How to insert source code - not as images.

     


    @Veldbrand wrote:

    a different MCU ... This code existed in the previous MCU's UART driver. 


    Which MCU was that?

    VeldbrandAuthorAnswer
    Visitor II
    June 6, 2025

    Thanks!


    I have removed the image and added the code.
    The MCU I copied the code from was the STM32L471.