cancel
Showing results for 
Search instead for 
Did you mean: 

Using DMA to read GPIOx_IDR on STM32F0xx

kilian2399
Associate II
Posted on March 03, 2015 at 15:13

Hi,

before I try myself I would like to ask you whether it is possible to use a timer to start a DMA that reads from the GPIOx_IDR register into a memory location and whether the source would be a peripheral or memory endpoint.

Any other suggestion on how to sample two input lines would be welcome, the maximum rate should be around 800kHz. The MCU would have to be an STM32F0xx.

I hope you can help,

Regards,

Kilian

2 REPLIES 2
Posted on March 03, 2015 at 16:04

It works on all STM32 platforms I've tried it on. Not technically a M2M operation, I don't think the F0 has the same APBx/DMAx issues the others do. Recommend you just try it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kilian2399
Associate II
Posted on March 05, 2015 at 13:29

Works! Here is the configuration:

...

    /* Enable DMA1 clock */

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

    DMA_DeInit(DMA1_Channel3);

    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(GPIOA->IDR);

    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)DMABuffer;

    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

    DMA_InitStructure.DMA_BufferSize = 1;

    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_Normal;

    DMA_InitStructure.DMA_Priority = DMA_Priority_High;

    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

    DMA_Init(DMA1_Channel3, &DMA_InitStructure);

    DMA_ITConfig(DMA1_Channel3,DMA_IT_TE|DMA_IT_TC,ENABLE);

    /* Enable DMA1 Channel3 */

   // enable later

    // enable clock

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE);

    TIM_Cmd(TIM16, DISABLE);

    /* TIM configuration */

    TIM_InitStructure.TIM_Period =_SAMPLING_TIMER_FREQ_DIV;

    TIM_InitStructure.TIM_Prescaler = SystemCoreClock/(_SAMPLING_TIMER_FREQ) - 1;

    TIM_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;

    TIM_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM16, &TIM_InitStructure);

    TIM_DMACmd(TIM16, TIM_DMA_Update, ENABLE);

   

    // TIM_Cmd(TIM16, DISABLE); // enable later

...

Thanks for your help,

Kilian