cancel
Showing results for 
Search instead for 
Did you mean: 

UART transmit DMA not working (bare metal, no HAL)

Nickelgrass
Senior

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.

1 ACCEPTED SOLUTION

Accepted Solutions

USART1_Tx is DMA1 Channel 4. See DMA1 request mapping in RM0008.

JW

View solution in original post

2 REPLIES 2

USART1_Tx is DMA1 Channel 4. See DMA1 request mapping in RM0008.

JW

Nickelgrass
Senior

Could'nt delete the post. The solution is I used the wrong DMA channel. Only channel 4 is connected to USART1.