STM32L152 UART code missing in driver
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) */
}
}
}
