Skip to main content
HNguy.6
Associate
April 25, 2019
Solved

STM32F407VE USART DMA RECEIVE

  • April 25, 2019
  • 1 reply
  • 912 views

Hello everyone, I am a beginner on STM32F4. I want to using DMA for receiving data via USART. But it doesnot work, please help me to solve the problem. Here is my code:

void USART2_ConfigDMA(void)

{

  DMA_InitTypeDef DMA_InitStructure;

  RCC->AHB1ENR = RCC_AHB1ENR_DMA1EN;

  DMA_InitStructure.DMA_BufferSize = 10;

  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable ;

  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ;

  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ;

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

  DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t) (&(USART2->DR)) ;

  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;

  DMA_InitStructure.DMA_Channel = DMA_Channel_4 ;

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory ;

  DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)&data[0]; 

  DMA_Init(DMA1_Stream5,&DMA_InitStructure);

  USART_Cmd(USART2, ENABLE);

  USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE);

  DMA_Cmd(DMA1_Stream5, ENABLE);

}

Thanks for your support !

This topic has been closed for replies.
Best answer by Tesla DeLorean

Probably want to start by ORing clock enable bits, rather than blind writing..

RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN;

1 reply

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
April 25, 2019

Probably want to start by ORing clock enable bits, rather than blind writing..

RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN;

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
HNguy.6
HNguy.6Author
Associate
April 25, 2019

Thank you ! I have solved the problem.