Search code examples
stm32uartdma

STM32 UART RX using DMA: DMA not starting


I have some working interrupt-based UART receive code, and want to convert it to use DMA. The UART is receiving characters, but the DMA is not processing them.

The processor is an STM32F030K6, using UART1 and DMA1_channel5. Here is the DMA setup code:

__HAL_RCC_DMA1_CLK_ENABLE();

DMA_CHANNEL->CCR &= ~(1 << DMA_CCR_EN_Pos);

// Set up the DMA configuration
// MEM2MEM 0 - disabled
// PINC = disabled
// TC interrupt disabled
// TE interrupt disbled
DMA_CHANNEL->CCR =
         (1 << DMA_CCR_PL_Pos)          // Medium priority
        | (0 << DMA_CCR_MSIZE_Pos)      // 8 bits
        | (0 << DMA_CCR_PSIZE_Pos)      // 8 bits
        | (1 << DMA_CCR_MINC_Pos)       // Memory increment
        | (0 << DMA_CCR_DIR_Pos)        // Peripheral to memory
        | (1 << DMA_CCR_CIRC_Pos);      // Circular buffer

  // Start the DMA
  DMA_CHANNEL->CCR &= ~(1 << DMA_CCR_EN_Pos); 
  DMA_CHANNEL->CPAR = (uint32_t) (&USART1->RDR);
  DMA_CHANNEL->CMAR = (uint32_t) (ring);
  DMA_CHANNEL->CNDTR = RING_BUFFER_SIZE;
  DMA_CHANNEL->CCR |= (1 << DMA_CCR_EN_Pos);

  // Route UART receive to DMA
  USART1->CR3 |= USART_CR3_DMAR;

The UART receives characters- RDR contains the character and RXNE is set- but the DMA is not accepting the received characters- CNDTR is not decremented.

What do I need to add or change to make the DMA process the characters?


Solution

  • You have to set SYSCFG_CFGR1.USART1_RX_DMA_RMP for the USART1_RX DMA to trigger DMA1_Channel5, see description of that pin in RM, and also footnotes under the DMA request mapping pictures and tables in the DMA chapter.

    JW