2021-03-22 09:50 AM
Hello,
I am trying to get the UART to transmit some bytes with DMA. Nothing happens.
RCC->APB2ENR |= (uint32_t)((1<<14)|(1<<2)); // Bit 14 USART1 clock enable & Bit 2 I/O port A clock enable
GPIOA->BRR = (1<<10); // pull-down PA.10
GPIOA->CRH &= (uint32_t)~((0x0F<<4)|(0x0F<<8)); // Clear Pin Function PA.10 & PA.9
GPIOA->CRH |= (uint32_t)((2<<10)|(2<<6)|(3<<4)); // UART1_Rx pin PA.10 Input with pull-up / pull-down & UART1_Tx pin PA.9 Alternate function output Push-pull / max speed 50 MHz
uart_set_baudrate(460800,72000000);
USART1->CR1 = (uint16_t)(bit13|bit3|bit2); // Enable USART1 & USART RX Interrupt enable & USART TX & RX enable
USART1->SR = 0; // Reset SR
RCC->AHBENR |= (bit1|bit0); // enable DMA 1 and 2 clock
DMA1_Channel1->CCR &= ~bit0; // disable TX DMA1 Channel1
DMA1_Channel1->CCR = 0;
DMA1_Channel1->CPAR = (uint32_t)&USART1->DR;
DMA1_Channel1->CMAR = (uint32_t)&uart_tx_dma_buffer[0];
DMA1_Channel1->CCR = (bit12|bit4|bit7); // 12:DMA priority medium; 4: from memory to peripheral; 7:increment memory
DMA1_Channel1->CNDTR = 15;
USART1->CR3 = bit7; // enable UART DMA
DMA1_Channel1->CCR |= bit0;
while(1);
It is on a STM32F103 running at 72 MHz. Transmitting without DMA works. I don't get how to start the transmission and tried many variations of setting the register order. So what am I missing?
Thanks,
kind regards.
Solved! Go to Solution.
2021-03-22 11:12 AM
2021-03-22 11:12 AM
USART1_Tx is DMA1 Channel 4. See DMA1 request mapping in RM0008.
JW
2021-03-22 11:16 AM
Could'nt delete the post. The solution is I used the wrong DMA channel. Only channel 4 is connected to USART1.