DMA USART not working as expected (MEM2MEM mode) STM32F303K8T6
Hi,
I am trying to get DMA to work with memory as source and peripheral as dest (UART) and i am not using HAL (this is a learning exercise), but only so far i have managed to get a single character out and the transmission reports as completed (Transfer complete status is set in ISR register and CNDTR from configured value becomes 0).
#define buff_size 6U
uint8_t source_buff[buff_size] = {'h', 'e', 'l', 'l', '0', '\n'};
void DMAInit(void) {
// Enable DMA1
RCC->AHBENR |= (1U << 0);
// Channel configuration
DMA1_Channel7->CCR &= ~(1U << 0); // disable
// wait for DMA to disable
while(DMA1_Channel7->CCR & (1U << 0));
// memory size set to 8 bits
DMA1_Channel7->CCR &= ~(1U << 10);
DMA1_Channel7->CCR &= ~(1U << 11);
// peripheral size set to 8 bits
DMA1_Channel7->CCR &= ~(1U << 8);
DMA1_Channel7->CCR &= ~(1U << 9);
// read from memory to peripheral, DIR = 1
DMA1_Channel7->CCR |= (1U << 4);
// mem inc
DMA1_Channel7->CCR |= (1U << 7);
// peipheral constant addr
DMA1_Channel7->CCR &= ~(1U << 6);
// CIRC circular buffer disable
DMA1_Channel7->CCR &= ~(1U << 5);
// MEM2MEM enable
DMA1_Channel7->CCR |= (1U << 14);
// dest address
DMA1_Channel7->CPAR = (uint32_t)&USART2->TDR;
// source buffer
DMA1_Channel7->CMAR = (uint32_t)source_buff;
// enable priority, very high
DMA1_Channel7->CCR |= (1U << 13);
DMA1_Channel7->CCR |= (1U << 12);
// size of transfer
DMA1_Channel7->CNDTR = buff_size; //buff_size;
// reset global interrupt flag.
DMA1->IFCR |= (1U << 24);
return;
}here is how i am triggering the DMA request
void startTransfer(void) {
// clear TC flag by setting TCCF bit in UART CR
USART2->ICR |= UART2_ICR_TCCF;
// Enable DMA
DMA1_Channel7->CCR |= (1U << 0);
// Monitor TC for entire block transfer complete notification
while(!(USART2->ISR & UART2_ICR_TC));
return;
}
any help or pointers is appreciated.
Thanks.
