AnsweredAssumed Answered

STM32F0 DMA communication

Question asked by tunder.pinyin on Nov 16, 2015
Latest reply on Nov 17, 2015 by Clive One
Hi all,i want to STM32F0 DMA communication Peripheral to Perpheral.but when i debugging my codes,in my while loop code works one time and stops.What is my fault.My code is here;
/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx_gpio.h"
#include "stm32f0xx_usart.h"
#include "stm32f0xx_dma.h"
#include "stm32f0xx_misc.h"
#include <stdio.h>
uint32_t DMA_Array[8];
 
/**************************************************************************************/
 
                 
void RCC_Configuration(void)
{
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1ENR_USART2EN,ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
}
 
void GPIO_Configuration(void)
{
    GPIO_InitTypeDef GPIO_Struct;
    GPIO_InitTypeDef GPIO_Struct2;
    GPIO_InitTypeDef GPIO_Struct3;
    /*USART1 PA9-TX  PA10-RX*/
    GPIO_Struct.GPIO_Pin=((GPIO_Pin_9)|(GPIO_Pin_10));
    GPIO_Struct.GPIO_Mode=GPIO_Mode_AF;
    GPIO_Struct.GPIO_OType=GPIO_OType_PP;
    GPIO_Struct.GPIO_PuPd=GPIO_PuPd_NOPULL;
    GPIO_Struct.GPIO_Speed=GPIO_Speed_50MHz;
     
    GPIO_Init(GPIOA,&GPIO_Struct);
     
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
     
    /*USART2 PA2-TX  PA3-RX*/
    GPIO_Struct2.GPIO_Pin=(GPIO_Pin_2)|(GPIO_Pin_3);
    GPIO_Struct2.GPIO_Mode=GPIO_Mode_AF;
    GPIO_Struct2.GPIO_OType=GPIO_OType_PP;
    GPIO_Struct2.GPIO_PuPd=GPIO_PuPd_NOPULL;
    GPIO_Struct2.GPIO_Speed=GPIO_Speed_50MHz;
     
    GPIO_Init(GPIOA,&GPIO_Struct2);
     
    GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_1);
    GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_1);
 
}
void USARTs_Configuration(void)
{
    USART_InitTypeDef USART_Struct;
    USART_InitTypeDef USART_Struct2;
     
    USART_Struct.USART_BaudRate=9600;
    USART_Struct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
    USART_Struct.USART_Mode=(USART_Mode_Rx|USART_Mode_Tx);
    USART_Struct.USART_Parity=USART_Parity_No;
    USART_Struct.USART_StopBits=USART_StopBits_1;
    USART_Struct.USART_WordLength=USART_WordLength_8b;
     
    USART_Init(USART1,&USART_Struct);
     
    USART_Cmd(USART1,ENABLE);
     
    USART_Struct2.USART_BaudRate=9600;
    USART_Struct2.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
    USART_Struct2.USART_Mode=(USART_Mode_Rx|USART_Mode_Tx);
    USART_Struct2.USART_Parity=USART_Parity_No;
    USART_Struct2.USART_StopBits=USART_StopBits_1;
    USART_Struct2.USART_WordLength=USART_WordLength_8b;
     
    USART_Init(USART2,&USART_Struct2);
    USART_Cmd(USART2,ENABLE);
}
 
void DMA_Configuration(void)
{
    DMA_InitTypeDef DMA_Struct;
    NVIC_InitTypeDef NVIC_Struct;
 
     
    /***/
    DMA_Struct.DMA_BufferSize = 8; 
    DMA_Struct.DMA_DIR=DMA_DIR_PeripheralSRC;
    DMA_Struct.DMA_M2M = DMA_M2M_Enable;
  DMA_Struct.DMA_MemoryBaseAddr=(uint32_t)&USART2->TDR;
    DMA_Struct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_Struct.DMA_PeripheralInc =DMA_PeripheralInc_Enable;
    DMA_Struct.DMA_Mode = DMA_Mode_Circular;
  DMA_Struct.DMA_PeripheralBaseAddr=(uint32_t)&USART1->RDR;
    DMA_Struct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; 
  DMA_Struct.DMA_MemoryInc = DMA_MemoryInc_Disable;
    DMA_Struct.DMA_Priority = DMA_Priority_High ;
   
     
     
      
     
    DMA_ClearITPendingBit(DMA1_IT_TC3);
    DMA_ITConfig(DMA1_Channel3, DMA_IT_TC, ENABLE);
     
     
     
    NVIC_Struct.NVIC_IRQChannel = DMA1_Channel2_3_IRQn;
    NVIC_Struct.NVIC_IRQChannelPriority = 1;
    NVIC_Struct.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_Struct);
    DMA_Cmd(DMA1_Channel3, DISABLE);
 
    //Re-initialize channel
    DMA_Init(DMA1_Channel3, &DMA_Struct);
 
    //Enable the DMA channel
    DMA_Cmd(DMA1_Channel3, ENABLE);
}
void DMA1_Channel2_3_IRQnHandler(void){
    if(DMA_GetITStatus(DMA1_IT_TC3)){
        DMA_ClearITPendingBit(DMA1_IT_TC3);
         
    }
}
uint32_t i;
void delay()
{
    for(i=0;i<0x00010000;i++);
}
int main(void)
{
    RCC_Configuration();
    GPIO_Configuration();
    USARTs_Configuration();
    DMA_Configuration();
  while(1)
  {
        USART_SendData(USART1,'*');
        delay();
  }
}

Outcomes