UART/USART DMA IDLE Receive with unknow data
Hi,
I'm trying to build a software to retrieve data from an solar inverter.
After I success to send data, it was the time to receive the data. I choose the method with DMA IDLE to receive data in a circular buffer.
In this mode, after a lot of debugging, I notice some issues with HAL functions.
Function void USART2_IRQHandler(void) and void DMA1_Stream5_IRQHandler(void) are calling the same function void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size). Doesn't metter if is a DMA IRQ or UART/USART IRQ, this function is called anyway.
My STM32F411 triggers an IRQ for DMA buffer overflow / reset counter and another IRQ for UART/USART IDLE. Because of this I tried to find out a solution to separate these events to threat the overflow of the DMA buffer and keep a tracking of the receiving data.
I tried with UART flags, getting IRQ triggers for DMA. All of these failed and I couldn't find a way to separate the events.
The idea is that after the DMA buffer overflows and IRQ is triggered I got the UART/USART IRQ afterwards. In this way is impossible to figure out how to threat the event.
There is a way in the HAL drivers to check this and without adding additional codes in void DMA1_Stream5_IRQHandler(void) and void USART2_IRQHandler(void) functions, like creating a flag for each type of IRQ, and then clear the flags in void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) ?
Example of hack to distinguishing the events:
void DMA1_Stream5_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream5_IRQn 0 */
/*
* 0b01 means HAL_UARTEx_RxEventCallback is called from UART/USART DMA IRQ.
* 0b10 means HAL_UARTEx_RxEventCallback is called from UART/USART IRQ.
*/
PI30_dev.IRQ_flag = 0b01;
/* USER CODE END DMA1_Stream5_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_usart2_rx);
/* USER CODE BEGIN DMA1_Stream5_IRQn 1 */
/* USER CODE END DMA1_Stream5_IRQn 1 */
}
void USART2_IRQHandler(void)
{
/* USER CODE BEGIN USART2_IRQn 0 */
/*
* 0b01 means HAL_UARTEx_RxEventCallback is called from UART/USART DMA IRQ.
* 0b10 means HAL_UARTEx_RxEventCallback is called from UART/USART IRQ.
*/
PI30_dev.IRQ_flag = 0b10;
/* USER CODE END USART2_IRQn 0 */
HAL_UART_IRQHandler(&huart2);
/* USER CODE BEGIN USART2_IRQn 1 */
/* USER CODE END USART2_IRQn 1 */
}PI30_dev.IRQ_flag is an uint8_t, uint16_t, uint32_t global var like. In this way I know for sure which IRQ triggered HAL_UARTEx_RxEventCallback.
