AnsweredAssumed Answered

When reading USART, DMA instantaneously completes

Question asked by Misha K on May 15, 2018
Latest reply on May 15, 2018 by Misha K

Please see code below. 

I'm trying to read from USART using DMA. 

Please see the last line DMA1_Channel3->CCR |= DMA_CCR_EN;

When I step over that line,  CNDTR instantaneously resets to zero like it has finished reading, also destination buffer is populated by multiple instances of the same char that was in USART1->RDR.

It looks like DMA believes that the same char is constantly arriving into RDR and available for transfer.

I don't expect any actual USART transmission at that time.

What am I doing wrong please?

 

void ScheduleUsartDmaRead(){
USART1->CR1 &= ~USART_CR1_TE;
USART1->CR1 |= USART_CR1_RE;
USART1->CR1 |= USART_CR1_UE; // enable usart


DMA1_Channel3->CCR &= ~DMA_CCR_EN; // disable DMA to set registers
DMA1_Channel3->CCR &= ~DMA_CCR_DIR; // peripheral to memory

DMA1->IFCR = DMA_FLAG_GL3; // clear flags
DMA1_Channel3->CNDTR = usartBufferSize; // set buffer size
DMA1_Channel3->CPAR = (uint32_t)(&(USART1->RDR)); // USART register address
DMA1_Channel3->CMAR = (uint32_t)(usartInBuffer); // memory address
DMA1_Channel3->CCR |= DMA_CCR_EN; // start DMA
}

Outcomes