AnsweredAssumed Answered

STM32F427 data transfer from GPIO 8port using DMA to other board

Question asked by song.duke on Feb 4, 2015
Latest reply on Feb 4, 2015 by Clive One
Hi

I try to transfer data 1byte to other board(same chip STM32F427) using GPIO 8 ports using DMA.

I can transfer data but I have problem.

I did not set up my GPIOE PIN_15. clock is output irregularly.(it should be output data I think)

here is my code

#include "stm32f4xx_conf.h"


#define BUFFER_SIZE     188


unsigned char buffer[BUFFER_SIZE] = {
    0x47, 0x40, 0x10, 0x1F, 0x00, 0x40, 0xF3, 0x8D, 0x30, 0x05, 0xCB, 0x00, 0x00, 0xF0, 0x10, 0x40,
    0x0E, 0x43, 0x72, 0x79, 0x73, 0x74, 0x61, 0x6C, 0x20, 0x50, 0x61, 0x6C, 0x61, 0x63, 0x65, 0xF3,
    0x70, 0x10, 0x04, 0x23, 0x3A, 0xF0, 0x50, 0x41, 0x12, 0x10, 0x44, 0x01, 0x10, 0x84, 0x01, 0x10,
    0xFF, 0x01, 0x11, 0x3F, 0x01, 0x11, 0x7F, 0x01, 0x12, 0x3F, 0x01, 0x5A, 0x0B, 0x03, 0x03, 0xD7,
    0x25, 0x1F, 0x42, 0x41, 0xFF, 0xFF, 0xFF, 0xFF, 0x62, 0x0D, 0xFF, 0x04, 0x28, 0xCF, 0x25, 0x04,
    0x1D, 0x1C, 0x5B, 0x03, 0x4D, 0x56, 0x40, 0x5F, 0x04, 0x00, 0x00, 0x23, 0x3A, 0x83, 0x18, 0x10,
    0x44, 0xFC, 0x01, 0x10, 0x84, 0xFC, 0x02, 0x10, 0xFF, 0xFC, 0x07, 0x11, 0x3F, 0xFC, 0x50, 0x11,
    0x7F, 0xFC, 0x69, 0x12, 0x3F, 0xFC, 0x46, 0x20, 0x05, 0x23, 0x3A, 0xF0, 0x7A, 0x41, 0x24, 0x20,
    0x66, 0x01, 0x20, 0x85, 0x01, 0x20, 0xA1, 0x01, 0x20, 0xC0, 0x01, 0x20, 0xFA, 0x01, 0x21, 0x00,
    0x01, 0x21, 0x04, 0x01, 0x21, 0x45, 0x0C, 0x21, 0xC3, 0x0C, 0x22, 0x40, 0x0C, 0x22, 0x44, 0x02,
    0x20, 0x45, 0x01, 0x5A, 0x0B, 0x02, 0xDF, 0x38, 0x25, 0x1F, 0x81, 0x01, 0xFF, 0xFF, 0xFF, 0xFF,
    0x62, 0x0D, 0xFF, 0x03, 0xEC, 0x48, 0x5B, 0x04, 0x72, 0x4E, 0x40, 0x02 };




int i = 0;


void RCC_Configuration(void);
void GPIOE_Configuration(void);
void TIM8_Configuration(void);
void DMA2_Configuration(void);
void NVIC_Configuration(void);
void initUSART(void);


int _write(int file, char *ptr, int len);


int main(void)
{
    RCC_Configuration();


    initUSART();
    GPIOE_Configuration();
    NVIC_Configuration();
    TIM8_Configuration();
    DMA2_Configuration();




    while(1)
    {


    }
}


void RCC_Configuration(void)
{
    //RCC System reset(for debug purpose
    RCC_DeInit();


    //Enable HSE
    RCC_HSEConfig(RCC_HSE_ON);


    if(RCC_WaitForHSEStartUp() == SUCCESS)
    {
        //Enable Prefetch Buffer
        FLASH_PrefetchBufferCmd(ENABLE);


        //Flash 2 wait state
        FLASH_SetLatency(FLASH_Latency_5);


        //HCLK = SYSCLK
        RCC_HCLKConfig(RCC_SYSCLK_Div1);


        //PCLK1 = HCLK/2
        RCC_PCLK1Config(RCC_HCLK_Div4);


        //PCLK2 = HCLK
        RCC_PCLK2Config(RCC_HCLK_Div2);


        //Set up PLL source = HSE, PLL_M = 8, PLL_N = 336, PLL_P = 2, PLL_Q = 7
        RCC_PLLConfig(RCC_PLLSource_HSE, 8, 336, 2, 7);


        //Enable PLL
        RCC_PLLCmd(ENABLE);


        //Wait still PLL is ready
        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);


        //Select PLL as system clock source
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);


        //PLL used as system clock
        while(RCC_GetSYSCLKSource() != 0x08);
    }
}


void GPIOE_Configuration(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;


    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);


    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_Init(GPIOE, &GPIO_InitStructure);


    GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14);
}




void TIM8_Configuration(void)
{
    //GPIO_InitTypeDef GPIO_InitStructure;
    TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
    //TIM_ICInitTypeDef TIM_ICInitStructure;


    //RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);


    TIM_TimeBaseInitStructure.TIM_Period = 4 - 1;     //42MHz
    TIM_TimeBaseInitStructure.TIM_Prescaler = 1 - 1;
    TIM_TimeBaseInitStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;


    TIM_TimeBaseInit(TIM8, &TIM_TimeBaseInitStructure);
    TIM_ARRPreloadConfig(TIM8, ENABLE);
    TIM_Cmd(TIM8, ENABLE);
    TIM_DMACmd(TIM8, TIM_DMA_Update, ENABLE);
}


void DMA2_Configuration(void)
{
    DMA_InitTypeDef DMA_InitStructure;


    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);


    DMA_Cmd(DMA2_Stream1, DISABLE);
    DMA_DeInit(DMA2_Stream1);


    DMA_InitStructure.DMA_Channel = DMA_Channel_7;
    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&buffer[0];
    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&GPIOE->ODR;
    DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
    DMA_InitStructure.DMA_BufferSize = BUFFER_SIZE;
    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_InitStructure.DMA_Priority = DMA_Priority_High;
    DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
    DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOStatus_HalfFull;
    DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
    DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
    DMA_Init(DMA2_Stream1, &DMA_InitStructure);


    DMA_ITConfig(DMA2_Stream1, DMA_IT_TC, ENABLE);


    DMA_Cmd(DMA2_Stream1, ENABLE);
}


void NVIC_Configuration(void)
{
    NVIC_InitTypeDef NVIC_InitStructure;


    NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
}


void DMA2_Stream1_IRQHandler(void)
{
    if(DMA_GetITStatus(DMA2_Stream1, DMA_IT_TCIF1))
    {
        if(i == BUFFER_SIZE)
        {
            i = 0;
        }
        printf("buffer[%d] = %x\r\n", i, buffer[i++]);      //just for test purpose


        DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_TCIF1);
    }

Outcomes