How to trigger DMA from external input

felixcollins
Posts: 123
Joined: Fri May 24, 2019 2:02 am

How to trigger DMA from external input

Postby felixcollins » Fri May 13, 2022 12:50 am

I'm looking for information on programming the DMA controller on the ESP32 (beyond what is in the Tech. Ref.). Specifically I want to understand how to trigger a DMA burst using a GPIO (not mediated using an interrupt on the CPU).

The scenario is this: I have an SPI connected ADC. The ADC provides a pin that signals a conversion is ready. Every time that happens I want the SPI to read from the ADC and DMA to transfer the read data into a circular buffer. It seems like that it is possible to make a circular buffer using a circular dma config linked list with a single entry. But where do I configure a trigger? Is this even possible with ESP32?

Regards,
Felix

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: How to trigger DMA from external input

Postby ESP_Sprite » Fri May 13, 2022 1:40 am

You can't on current ESP chips, you'll need to have an interrupt on that GPIO that manually triggers the SPI transfer.

felixcollins
Posts: 123
Joined: Fri May 24, 2019 2:02 am

Re: How to trigger DMA from external input

Postby felixcollins » Tue May 17, 2022 2:05 am

ESP_Sprite wrote:
Fri May 13, 2022 1:40 am
You can't on current ESP chips, you'll need to have an interrupt on that GPIO that manually triggers the SPI transfer.
Thanks for that. It is as I suspected. Now I have a problem.

I need to read 8bytes from ADC over SPI when an interrupt fires every ~60uS. This is too fast to get a freertos task to do the read with a task notify fired from the interrupt. But I can not do SPI read from the interrupt itself. How would this be done on ESP32?

I could poll the ADC on the SPI until I get the valid data. But this seems wasteful and I have a lot to fit into this firmware...

felixcollins
Posts: 123
Joined: Fri May 24, 2019 2:02 am

Re: How to trigger DMA from external input

Postby felixcollins » Tue May 17, 2022 2:13 am

Is it possible to start a DMA SPI transaction from a gpio interrupt and then handle the transaction finished interrupt to copy the data to a buffer?

felixcollins
Posts: 123
Joined: Fri May 24, 2019 2:02 am

Re: How to trigger DMA from external input

Postby felixcollins » Tue May 17, 2022 2:31 am

Looking at the code in spi_device_queue_trans() It looks like I could duplicate that and use xQueueSendFromISR to make it ISR compatible. Any IDF developers care to comment?

felixcollins
Posts: 123
Joined: Fri May 24, 2019 2:02 am

Re: How to trigger DMA from external input

Postby felixcollins » Mon May 30, 2022 1:06 am

I tried that solution, queue spi transaction from isr. It knocks quite a bit of overhead off but there is still around 20uS of task switching and queue overhead.

Who is online

Users browsing this forum: No registered users and 123 guests