AnsweredAssumed Answered

External Trigger Parallel GPIO DMA with HAL

Question asked by stone.josh on Dec 2, 2014
Latest reply on Jan 16, 2015 by Clive One
OK, I'm interfacing with a parallel bus that gives me 8 bits on an external clock pulse.  I have working code with an interrupt and manually shuffling the data into memory, but I'd like to use a DMA approach, similar to this forum discussion here, where the code under discussion configures a timer to initiate DMA transfering from the GPIO IDR to a region of memory.

Here are snippets from that code:

void TIM1_Configuration(void)
{
    GPIO_InitTypeDef   GPIO_InitStructure;
    TIM_ICInitTypeDef  TIM_ICInitStructure;
  
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);  /* TIM1 clock enable */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  
  /* TIM1 channel 1 pin (PA8) configuration */
  GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_TIM1); // PB3 TIM1_CH1
  
  TIM_ICInitStructure.TIM_Channel     = TIM_Channel_1;
  TIM_ICInitStructure.TIM_ICPolarity  = TIM_ICPolarity_Rising;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter    = 0x0;
  TIM_ICInit(TIM1, &TIM_ICInitStructure);
  
    TIM_CtrlPWMOutputs(TIM1, ENABLE);               /* TIM Main Inputs/Output Enable    */
  TIM_Cmd(TIM1, ENABLE);                  /* TIM enable counter               */
  TIM_DMACmd(TIM1, TIM_DMA_CC1, ENABLE ); /* Enable TIM1_CC1 DMA Requests     */
}

void DMA2_Configuration(void)
{
    /***************************************************************************************************************************************/
    DMA_InitTypeDef  DMA_InitStructure;
  
    /* Enable the DMA clock */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
  
    /* Configure the DMA Stream */
    DMA_Cmd(DMA2_Stream6, DISABLE);
    DMA_DeInit(DMA2_Stream6);
  
  /* Set the parameters to be configured */
  DMA_InitStructure.DMA_Channel = DMA_Channel_0;
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&GPIOC->IDR;  /* Read fron GPIO input data register */
  DMA_InitStructure.DMA_Memory0BaseAddr    = (uint32_t)&GPIO_DATA[0]; /* Send the data to the  RAM buffer */
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
    DMA_InitStructure.DMA_BufferSize = BufferSize;
    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_Disable;
    DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
    DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
    DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
    DMA_Init(DMA2_Stream6, &DMA_InitStructure);
  
  /* Enable DMA Transfer Complete interrupt */
  DMA_ITConfig(DMA2_Stream6, DMA_IT_TC, ENABLE);
  
    DMA_Cmd(DMA2_Stream6, ENABLE);
  
    /***************************************************************************************************************************************/
}


The problem is, the above code doesn't use the HAL that I downloaded, so everything's completely different.  I'm really confused about how to do this with the HAL.

How do I associate the DMA with the GPIO port?  There's no "DMA_PeripheralBaseAddr" or "DMA_Memory0BaseAddr" when initializing the DMA. 

Then, how do I associate the timer with the DMA channel?  In the linked code from above, I'm not even quite sure where that connection is, but I don't see anything in UM1725 (Description of the HAL drivers) that connects the two.

I am new to the STM32s, so please be kind if I've just totally missed something.  Thanks!

Outcomes