AnsweredAssumed Answered

STM32F407 USART3 DMA Transmit problem

Question asked by ASSAAD on Dec 18, 2014
Latest reply on Dec 18, 2014 by Clive One
Hello Everyone
I am tryint to send data through usart3 by dma ; I can send data without DMA but when configure to use the DMA I could not send ;
Could you guide me to check my mistakes ;
the code is :
void init_usart(void){
      
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
      
    /* enable peripheral clock for USART2 */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
  
      
    /* GPIOA clock enable */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
        
    /* GPIOA Configuration:  USART2 TX on PA2 */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
    GPIO_Init(GPIOB, &GPIO_InitStructure); 
          
  
          
  
  
    /* Connect USART3 pins to AF2 */ 
    // TX = b10
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
          
    USART_InitStructure.USART_BaudRate = 115200;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
    USART_Init(USART3, &USART_InitStructure);
  
    USART_Cmd(USART3, ENABLE); // enable USART3
      
}
  
  
//---
  
void DMA_Configuration(void)
{
  DMA_InitTypeDef  DMA_InitStructure;
      
      
//  NVIC_InitTypeDef NVIC_InitStructure;
// 
//  /* Configure the Priority Group to 2 bits */
//  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
// 
//  /* Enable the UART4 RX DMA Interrupt */
//  NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream3_IRQn;
//  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
//  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
//  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//  NVIC_Init(&NVIC_InitStructure);
//  
      
  /* DMA1 clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
   
  DMA_DeInit(DMA1_Stream3);
   
  DMA_InitStructure.DMA_Channel = DMA_Channel_3;
  DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; // Transmit
  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Buffer_usart;
  DMA_InitStructure.DMA_BufferSize = (uint16_t)sizeof(Buffer_usart) - 1;
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(USART3->DR);
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA_Mode_Normal ;//
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
   
  DMA_Init(DMA1_Stream3, &DMA_InitStructure);
   
  /* Enable the USART Tx DMA request */
  USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);
   
 /* Clear the TC bit in the SR register by writing 0 to it */
    USART_ClearFlag(USART3, USART_FLAG_TC);
   
   
  /* Enable DMA Stream Transfer Complete interrupt */
 // DMA_ITConfig(DMA1_Stream3, DMA_IT_TC, ENABLE);
   
  /* Enable the DMA Tx Stream */
  DMA_Cmd(DMA1_Stream3, ENABLE);
}



Thank you in advanced ;
Hector

Outcomes