Is it possible to run SPI communication in ISR of GPIO?

Valerii
Posts: 16
Joined: Wed Dec 27, 2017 4:20 pm

Is it possible to run SPI communication in ISR of GPIO?

Postby Valerii » Tue Apr 03, 2018 5:54 pm

Hi, I'm porting a peripheral library that sends SPI data in GPIO's interrupt routine. The panic occurring when firmware running.

Code: Select all

Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU0)
Core 0 register dump:
PC      : 0x400874ee  PS      : 0x00060234  A0      : 0x80086836  A1      : 0x3ffc0630  
0x400874ee: vListInsert at .../esp-idf/components/freertos/./list.c:188 (discriminator 1)

A2      : 0x3ffc6438  A3      : 0x3ffc7ba8  A4      : 0x00060221  A5      : 0x00000001  
A6      : 0x00060221  A7      : 0x3ffc64a0  A8      : 0x3ffc7ba8  A9      : 0x3ffc7ba8  
A10     : 0x00000019  A11     : 0x00000019  A12     : 0x00000004  A13     : 0x00000001  
A14     : 0x00060223  A15     : 0x00000000  SAR     : 0x0000001e  EXCCAUSE: 0x00000005  
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff  
Core 0 was running in ISR context:
EPC1    : 0x40085e43  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x400874ee
...
0x400ecb25: spi_device_get_trans_result at .../esp-idf/components/driver/./spi_master.c:772

0x400ecba6: spi_device_transmit at .../esp-idf/components/driver/./spi_master.c:807
So I think that

Code: Select all

spi_device_transmit()
can't be ran in ISR. Can it?
Is there any solution for this?

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

Re: Is it possible to run SPI communication in ISR of GPIO?

Postby ESP_Sprite » Wed Apr 04, 2018 1:38 am

There are very few things you can safely call in an ISR, as it runs outside of the task context. Most notably, FreeRTOS functions ending in FromISR can be called, and the standard way of dealing with this is to have a semaphore or queue plus a thread blocking on that. The ISR can then put something in the queue or give the semaphore and the task gets unblocked and can do the actual work (sending some SPI data, for example.)

Valerii
Posts: 16
Joined: Wed Dec 27, 2017 4:20 pm

Re: Is it possible to run SPI communication in ISR of GPIO?

Postby Valerii » Wed Apr 04, 2018 1:17 pm

Ok, thanks. It's clear now.

themindfactory
Posts: 55
Joined: Mon Mar 26, 2018 7:57 pm

Re: Is it possible to run SPI communication in ISR of GPIO?

Postby themindfactory » Sat May 05, 2018 10:08 pm

ESP_Sprite wrote:There are very few things you can safely call in an ISR, as it runs outside of the task context. Most notably, FreeRTOS functions ending in FromISR can be called, and the standard way of dealing with this is to have a semaphore or queue plus a thread blocking on that. The ISR can then put something in the queue or give the semaphore and the task gets unblocked and can do the actual work (sending some SPI data, for example.)
Hmm... I need to run a SPI peripheral in interrupt mode to be able to send a bitstream uninterrupted, as I find now I send data to SPI and it always has a gap between each 8 bit send....

Do you know if you can send 16 or 32 at once? and if interrupt is not avaiable how to send it in a tight loop and not get any gaps??

RichardS

Franklin.e
Posts: 1
Joined: Sat Jan 16, 2021 11:21 am

Re: Is it possible to run SPI communication in ISR of GPIO?

Postby Franklin.e » Fri Feb 19, 2021 9:26 am

themindfactory wrote:
Sat May 05, 2018 10:08 pm
ESP_Sprite wrote:There are very few things you can safely call in an ISR, as it runs outside of the task context. Most notably, FreeRTOS functions ending in FromISR can be called, and the standard way of dealing with this is to have a semaphore or queue plus a thread blocking on that. The ISR can then put something in the queue or give the semaphore and the task gets unblocked and can do the actual work (sending some SPI data, for example.)
Hmm... I need to run a SPI peripheral in interrupt mode to be able to send a bitstream uninterrupted, as I find now I send data to SPI and it always has a gap between each 8 bit send....

Do you know if you can send 16 or 32 at once? and if interrupt is not avaiable how to send it in a tight loop and not get any gaps??

RichardS
Hi,
I'm currently on a project with kind of that issue (POV display with SPI LED driver). And yes, if you didn't knew that a SPI transaction take quite a long time (see https://docs.espressif.com/projects/esp ... iderations ) to be started, that could be project-killer (almost true in my case).
What I did was to use a big DMA that include all the bytes (Adresse, R/W, Data) made-by-hand with polling transactions. With that, I had a ~7[μs] delay between every 6[μs] of transaction (20 bytes at 26[MHz]).
Here is the main part of my SPI-writing fuction, hope it can help:
Note: Really not a good programmer, take it as an algorithm, note as good code, sry for that <3

Code: Select all

// Made to use PCA9745B, see datasheet for more infos
// Loop for every chip
for (unsigned char c = 0; c < TX_CHIPS; c++){
	// Adresse + R/~W
	// Take the adress (say 0x08, 7 bits), bitshift by 1 (<<1), add the R/~W bit (& ~0x01) => first byte of one chip-sending
	*(data + (c*2)) = ((SPI_DEVICE_LED_ADDR+r)<<1) & ~0x01;
	// Data
	// Just take the data on 8 bits (with pointer-things) => second byte of one chip-sending
	*(data + (c*2) + 1) = *(table_angle_point + (c*TX_REGISTER));
 }
 // Have all my transaction on the DMA, can do the polling-transaction (gain of time)
spi_device_polling_transmit(spi_device_handle, &conf_transaction_tx);

Who is online

Users browsing this forum: No registered users and 66 guests