cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 all GPIO pin capture with DMA and Timer

JBond.1
Senior

Hi, I am trying to capture all GPIO pin values when timer pin goes LOW. I cant understand which timer I need to choose? Which peripheral stands for GPIO port?

How do I need to set Timer "Copy from" input source?

I have STM32F091RC

1 ACCEPTED SOLUTION

Accepted Solutions

>>I cant understand which timer I need to choose?

It is not complicated, but does require logical deduction and reading of the technical documentation.

There's a chain of associativity in the Reference Manual. Pick a TIM on APB2 (DMA2) for parts where that is required for Mem-to-Mem DMA

Find a TIMx_CHx pin you can use for Input Capture, and that same TIMx_CHx appears in the DMA channel/stream Trigger sources.

Use DMA in Mem-to-Mem, with GPIOx->IDR as the SOURCE, read as a word or halfword, and have the memory array / pattern buffer as the DESTINATION

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

View solution in original post

7 REPLIES 7

I cant understand which timer I need to choose?

Whichever, which has its capture/compare unit brought out to pins (i.e. not TIM6/TIM7), and which can trigger DMA operations (read DMA chapter in RM for your STM32 model).

You did not tell us your STM32 model, but in 'F2/'F4/'F7 you need to use timer which can trigger DMA2 streams (and 'H7 has some additional bonus levels of complexity).

> How do I need to set Timer "Copy from" input source?

There's no such, unless you talk about some Cube/CubeMX gibberish.

Read AN4666.

JW

>>I cant understand which timer I need to choose?

It is not complicated, but does require logical deduction and reading of the technical documentation.

There's a chain of associativity in the Reference Manual. Pick a TIM on APB2 (DMA2) for parts where that is required for Mem-to-Mem DMA

Find a TIMx_CHx pin you can use for Input Capture, and that same TIMx_CHx appears in the DMA channel/stream Trigger sources.

Use DMA in Mem-to-Mem, with GPIOx->IDR as the SOURCE, read as a word or halfword, and have the memory array / pattern buffer as the DESTINATION

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
JBond.1
Senior

Ok, so as I understood Timer itself does not have some kind of "copy and pass GPIO state to DMA input" logic correct?

I need to wait for half or full complete interupt of the timer and implement copy of GPIOx->IDR Mem-to-Mem myself correct?

Ok, so as I understood Timer itself does not have some kind of "copy and pass GPIO state to DMA input" logic correct?

I need to wait for half or full complete interupt of the timer and implement copy of GPIOx->IDR Mem-to-Mem myself correct?

Moving data is not the Timer's task, it's DMA's task. Timer in this context just provides a means to trigger the DMA.

Read AN4666.

JW

I cant set CCR1 but basicaly what I need it this:

htim2.Instance->CCR1 = (uint32_t)&GPIOC->IDR;

How do I achieve that?

Yes I am trying to use CubeMX, I cant choose MemToMem DMA operation with timer there

I can choose only Peripheral to Memory or Memory to Pheripheral, so not sure how to copy GPIO values.

Basicaly what I do is this:

HAL_TIM_IC_Start_DMA(
		&htim2,
		TIM_CHANNEL_1,
		(uint32_t *)&BUFFER_DATA[0],
		BufferSize);

but the problem here is that I cant add source from where to copy. It copies data from

htim2.Instance->CCR1

 And It seems that I cant simply set it

htim2.Instance->CCR1 = (uint32_t)&GPIOC->IDR;