[SPI] how to stop using DMA

michprev
Posts: 88
Joined: Fri Aug 04, 2017 8:57 pm

[SPI] how to stop using DMA

Postby michprev » Wed Dec 12, 2018 10:37 pm

Hi,
let's say that I want to use SPI with DMA channel and then without DMA channel.
To use DMA I set channel in DPORT_SPI_DMA_CHAN_SEL_REG register. I set DPORT_SPI3_DMA_CHAN_SEL to either 1 or 2.
SPI DMA transmission is successful but how to stop using DMA now? When I set DPORT_SPI3_DMA_CHAN_SEL to 0 SPI still keeps reading wrong data (= still somehow uses DMA).

How can i stop using DMA once it has been configured? I am using my custom SPI driver, not ESP-IDF one.
periph_module_disable() & periph_module_enable() seems to work but isn't there any other better way?

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

Re: [SPI] how to stop using DMA

Postby ESP_Sprite » Thu Dec 13, 2018 4:32 am

If you don't set dma_out_link.start and dma_in_link.start at the beginning of a transaction, DMA should automatically be inhibited. No need to enable/disable/deselect/... DMA on a peripheral level.

Also, out of curiosity, is there a reason you're writing your own driver, foregoing the one in esp-idf?

michprev
Posts: 88
Joined: Fri Aug 04, 2017 8:57 pm

Re: [SPI] how to stop using DMA

Postby michprev » Thu Dec 13, 2018 5:07 pm

Found the issue, it is not even DMA related. If you set SPI_FASTRD_MODE to 0 and SPI_FREAD_QIO to 1 hardware will still perform QIO transmission. It has been fixed in TRM from 07/12/2018.
Also, out of curiosity, is there a reason you're writing your own driver, foregoing the one in esp-idf?
In the past I complained about state of ESP-IDF drivers so I decided to write my own to blame only myself :D It works without FreeRTOS so I can use it on the second core when only the first core uses FreeRTOS. There are also a few other advantages and the biggest disadvantage is missing queue.

This way I also discovered bugs in ESP-IDF driver. Some of them are fixed now.

squonk11
Posts: 52
Joined: Wed Mar 01, 2017 6:53 pm
Location: Germany

Re: [SPI] how to stop using DMA

Postby squonk11 » Fri Jan 11, 2019 2:44 pm

@michprev : are you willing to share your code of your spi driver? I am currently stuck with the problem that the spi slave driver from Espressif has the problem that in DMA mode for certain telegrams some of the received bytes are missing. So I am searching for another solution.
"Wer glaubt etwas zu sein hat aufgehört etwas zu werden"
Sokrates

michprev
Posts: 88
Joined: Fri Aug 04, 2017 8:57 pm

Re: [SPI] how to stop using DMA

Postby michprev » Fri Jan 11, 2019 7:12 pm

Unfortunately I have written driver only for SPI master. As I am no longer working with ESP32 I do not plan to extend it also for SPI slave.

There is a hardware bug in SPI DMA https://github.com/espressif/esp-idf/bl ... #L382-L438, https://github.com/espressif/esp-idf/bl ... ave.c#L387. It may be related to your issue. AFAIK these issues are not decribed anywhere.

I am attaching my code for anyone who wants to use it.
Attachments
spi_master.zip
(7.49 KiB) Downloaded 12 times

squonk11
Posts: 52
Joined: Wed Mar 01, 2017 6:53 pm
Location: Germany

Re: [SPI] how to stop using DMA

Postby squonk11 » Fri Jan 11, 2019 9:44 pm

Thank you for providing your source code!
But for master mode now the problem seems to be fixed also in the esp-idf sources. For the slave mode the problem still exists and unfortunalely I urgently need a solution.
Currently I am working on a totally stupid solution:
I am trying to emulate an SPI slave interface completely by polling port pins via software. My masters clock frequency is "only" 1MHz. So I am on the limit with the sampling of the SPI input clock signal. In order to make it work I had to redefine the "gpio_get_level()" and "gpio_set_level()" functions to be much simpler.
Amuch better solution would be to have the SPI slave interface generate an interrupt after every received byte. But I don't know how to achieve that because the documentation of the chip is VERY poor.
"Wer glaubt etwas zu sein hat aufgehört etwas zu werden"
Sokrates

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 26 guests