Skip to main content
karatepe101
Associate III
November 16, 2015
Question

STM32F0 DMA communication

  • November 16, 2015
  • 4 replies
  • 1090 views
Posted on November 16, 2015 at 16:22

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();
}
}

    This topic has been closed for replies.

    4 replies

    Tesla DeLorean
    Guru
    November 16, 2015
    Posted on November 16, 2015 at 17:11

    Does the DMA controller permit this type of peripheral-to-peripheral interaction?

    Does the IRQ Handler get called?

    You don't need to have unique initialization structures for each pin, usart, etc. It's a throw away structure that's used once and discarded.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    karatepe101
    Associate III
    November 17, 2015
    Posted on November 17, 2015 at 14:20

    Thanks clive for your answer,is there any example Usart to Peripheral or similar application

    jpeacock
    Associate
    November 17, 2015
    Posted on November 17, 2015 at 19:15

    The problem with peripheral to peripheral DMA is there is no channel/stream combination to support it.  That means the either the source or destination can't perform a DMA request.  Then there's the bus matrix, only one AHB to APB bridge.

    Yes the peripheral looks like a memory address but internally it isn't the same.  The data has to be routed to different places and there has to handshake signals for the DMA to start transfers.  And there's no way the DMA FIFO will work since only of the DMA handshakes (the stream) to either write to or read from the FIFO is missing.

      Jack Peacock
    Tesla DeLorean
    Guru
    November 17, 2015
    Posted on November 17, 2015 at 19:34

    is there any example Usart to Peripheral or similar application

    Not that I've written, I'm not using Cortex-M0 parts, so no business driver there. What I do is practice and experiment based on a review of the available documentation.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..