cancel
Showing results for 
Search instead for 
Did you mean: 

Reading data through DMA triggered by Input Capture Timer

D��ug
Associate II

Hi,

I am new to microcontrollers and this is my first big project. I want to receive data from other device through 8 data lines and 1 clock signal (similar to STM Application note AN4666 ''Parallel synchronous transmition using GPIO and DMA'')

I am using STM32F411 Discovery Board.

This is how it looks:

  • data lines are connected to PC0 - PC7 (already configured)
  • clock line is connected to PE9 (Timer 1 Channel 1)
  • DMA2 is configured to on Stream 1 Channel 6
  • DMA should be triggered by rising edge of clock signal
  • data should be transfered to frameBuffer table (Memory addres incrementation Enabled)
  • I need interrupt after 348 transfers

Here's my configuration for DMA and Timer:

volatile uint8_t frame_buffer[2*I174];
 
void TimerAndDMAConfigure(void){
 
	GPIO_InitTypeDef gpioPCLK;
	TIM_ICInitTypeDef icTIM1;
	DMA_InitTypeDef dmaPerToMem;
 
	NVIC_InitTypeDef nvic;
	
	//GPIOE for timer config - PE9
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
	
	gpioPCLK.GPIO_Mode = GPIO_Mode_AF;
	gpioPCLK.GPIO_OType = GPIO_OType_OD;
	gpioPCLK.GPIO_Pin = GPIO_Pin_9;
	gpioPCLK.GPIO_PuPd = GPIO_PuPd_NOPULL;
	gpioPCLK.GPIO_Speed = GPIO_High_Speed;
	GPIO_Init(GPIOE, &gpioPCLK);
	GPIO_PinAFConfig(GPIOE, GPIO_PinSource9, GPIO_AF_TIM1);
 
 
	//Timer config
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
 
	icTIM1.TIM_Channel = TIM_Channel_1;
	icTIM1.TIM_ICPolarity = TIM_ICPolarity_Rising;
	icTIM1.TIM_ICSelection = TIM_ICSelection_DirectTI;
	icTIM1.TIM_ICPrescaler = TIM_ICPSC_DIV1;
	icTIM1.TIM_ICFilter = 0;
	TIM_ICInit(TIM1, &icTIM1);
 
	TIM_CtrlPWMOutputs(TIM1, ENABLE);
	TIM_SelectOutputTrigger(TIM8 , TIM_TRGOSource_Reset);
	TIM_Cmd(TIM1, ENABLE);
	TIM_DMAConfig(TIM1, TIM_DMABase_CCR1, TIM_DMABurstLength_1Transfer);
	TIM_DMACmd(TIM1, TIM_DMA_CC1, ENABLE);
 
 
	//DMA config - peripheral to memory
	//DMA2 Stream 1 Channel 6
 
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
 
	DMA_DeInit(DMA2_Stream1);
 
	dmaPerToMem.DMA_BufferSize = 174*2;
	dmaPerToMem.DMA_Channel = DMA_Channel_6;
	dmaPerToMem.DMA_DIR=DMA_DIR_PeripheralToMemory;
	dmaPerToMem.DMA_FIFOMode = DMA_FIFOMode_Disable;
	dmaPerToMem.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
	dmaPerToMem.DMA_Memory0BaseAddr = (uint32_t) frame_buffer;
	dmaPerToMem.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	dmaPerToMem.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
	dmaPerToMem.DMA_MemoryInc = DMA_MemoryInc_Enable;
	dmaPerToMem.DMA_Mode = DMA_Mode_Normal;
	dmaPerToMem.DMA_PeripheralBaseAddr = (uint32_t) (&GPIOC->IDR);
	dmaPerToMem.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	dmaPerToMem.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
	dmaPerToMem.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	dmaPerToMem.DMA_Priority = DMA_Priority_Medium;
	DMA_Init(DMA2_Stream1, &dmaPerToMem);
 
	DMA_ITConfig(DMA2_Stream1, DMA_IT_TC, ENABLE);
	DMA_Cmd(DMA2_Stream1, 174);
 
	//DMA2 - Interrupt
	nvic.NVIC_IRQChannel = DMA2_Stream1_IRQn;
	nvic.NVIC_IRQChannelCmd = ENABLE;
	nvic.NVIC_IRQChannelPreemptionPriority = 0;
	nvic.NVIC_IRQChannelSubPriority = 0;
	NVIC_Init(&nvic);
 
}

I am not sure about GPIOE and Timer configuration. Could anybody review if what I wrote is correct? I am total newbie in programming microcontrollers (and don't have faith in my code). That would be very helpful

Yes, I am aware of very similar topic (https://community.st.com/s/question/0D50X00009XkXKJSA3/dma-triggering-via-timerinput-capture-mode) and I took inspiration from that, but mine differs a little and Timer confiruration doesn't seem to work

Thank You in advance

2 REPLIES 2
S.Ma
Principal

I guess you also need to configure the timer. Here only the input capture portion. Timer clock frequency, mode, behaviour, overflow, etc... needs to be defined as well.

D��ug
Associate II

Alright, suprisingly it works - but only once. I must have messed something with the flags after finishing the transfer. Everybody feel free to use this configuration