I have a problem with STM32F0 DMA receiving data from UART. I use 2 DMA channels (for rx and tx) both in non-circular mode, rx channel has lower priority. Data from UART handles in Idle Line interrupt, where I read the number of DMA received bytes and process them. Everything works fine until the number of bytes in package is less than or equal to DMA buffer size. Otherwise DMA strangely turns off and following Idle Line interrupts give me the 1, 0, 0, ... number of DMA received bytes. Here is part of the code, where I check if the DMA buffers fills and try to reset DMA counter to buffer size:
#define S_M_INPUT_CMD_SIZE 20
static char s_m_uart_dma_in_buff[S_M_INPUT_CMD_SIZE + 1];
void USART1_IRQHandler(void)
{
ITStatus reception_status = USART_GetITStatus(USART1, USART_IT_IDLE);
if(reception_status != RESET)
{
int32_t bytes_number = S_M_INPUT_CMD_SIZE - DMA_GetCurrDataCounter(DMA1_Channel3);
if (DMA_GetFlagStatus(DMA1_FLAG_TC3) != RESET)
{
USART_ITConfig(UART_, USART_IT_IDLE, DISABLE);
DMA_Cmd(DMA1_Channel3, DISABLE);
while (DMA1_Channel3->CCR & DMA_CCR_EN);
for (int i = 0; i < S_M_INPUT_CMD_SIZE; i++)
s_m_uart_dma_in_buff[i] = '\0';
DMA_SetCurrDataCounter(DMA1_Channel3, S_M_INPUT_CMD_SIZE);
DMA_Cmd(DMA1_Channel3, ENABLE);
DMA_ClearFlag(DMA1_FLAG_GL3);
}
USART_ClearITPendingBit(UART_, USART_IT_IDLE);
}
}
After the first "overflow" and DMA enabling comes "buffer size + 1" byte that was in rx register and later the number of received bytes is stable zero. What I'm doing wrong?