Go Down

Topic: Read GPIO to DMA by clock request (Read 814 times) previous topic - next topic



I am starting with arduino DUE, I switched from 328P and STM32. I would like to read 0/1 from one digital pin and store value to DMA, as request for each read I would like to use timer.

To one GPIO come bits, 0.3us for each bit, it is fixed time.

So my idea is

1) set any TIM to 3.33Mhz (one cycle of timer)
2) set DMA, address should be from GPIOX to MEM and set TIMX_UP as DMA request
3) DMA no cycle mode because I need handle reading start/stop manually
4) set interupt for DMA "writing done"

I know how it do for STM in cubeMX but I have no idea how to do it for ATSAM, One week I tried find any info about it, but I was able to find only information about reading from ADC or writting to SPI.

Even, I was not able to find DMA request mapping for ATSAM. I know I can use manual for ATSAM but it has more than 1000 pages I find anything there is almost impossible. :(


A  description of the big picture of your project would help.

What is the interest of using a DMA transfer in this project ? A timer handler could be used to transfer data from  GPIOs to a memory at the right pace.

A DMA from a GPIO to a memory is usually a freeruning process.


Thank you for answer.

Ok, core of my project are two interupts (on two GPIO) and capture signal on third GPIO pin.

Frequency of first interupt is 50Hz, frequency of second interupt is 12.750KHz. And each 1/50s (50hz) I need capture signal 50us length at least 170 samples. Sample rate is about 3.33MHz.

I wanted to use DMA because interupt waste lot of CPU cycles. On 328P I think it is about 16 cycles. For example on 328p I can capture 170 samples in 50us, but I must be written in assembler and I have only 6 cycles for one sample.

I thought that interupt with frequency 3.33Mhz is too much for ATSAM.


Although your explanation is still unclear, I see no real issue if you have to trigger samplings triggered by an input signal (input signal frequency = 50 Hz or 12750 Hz or both ?). This triggering can be done with a simple attachinterrupt.

The only complex point is that for a frequency of F = 333333Hz, there is no integer to divide the TC "Master" clock (42 MHz) with a good accuracy. You'll have to use the Timer Chained feature with an external input frequency equivalent to a multiple of F.

The input bits to sample are arriving every 0.3 us (= 3333333Hz). To record these bits, you can (e.g.) use a Timer Counter with the Timer chained feature to receive an external input frequency as close as 2*3333333 Hz. Then divide this external input frequency by 2, trigger the TC Handler at the end of each period, record the GPIO state with PIO_PDSR inside the Timer Handler.

Maybe there is an internal solution to provide F with an hack of I2S, but that remains to be studied ...

Go Up