Hi everybody,
I have a problem and hope recive support from everyone.
I am trying to do spi communication with external flash memory (MT25QL128) in interrupt, this leads to the system dump. I want to ask if this is possible? If possible please give me an instruction
Below is my spi communication function:
void spiTranfer(uint8_t *writeData , uint32_t length, uint8_t *readData)
{
//Transaction descriptors. Declared static so they're not allocated on the stack; we need this memory even when this
//function is finished because the SPI driver needs access to it even while we're already calculating the next line.
static spi_transaction_t trans;
//In theory, it's better to initialize trans and data only once and hang on to the initialized
//variables. We allocate them on the stack, so we need to re-init them each call.
memset(&trans, 0, sizeof(spi_transaction_t));
//Odd transfers are data
trans.length = length*8;
trans.user = (void *)1;
trans.tx_buffer = writeData; //finally send the line data
trans.rx_buffer = readData;
trans.flags = 0; //undo SPI_TRANS_USE_TXDATA flag
//Queue all transactions.
spi_device_queue_trans(g_spi, &trans, portMAX_DELAY);
}
Thank you for your time.
Communicating with spi with slave in interrupt, the system will be dumped
-
- Posts: 3
- Joined: Fri Jan 29, 2021 4:40 am
-
- Posts: 9746
- Joined: Thu Nov 26, 2015 4:08 am
Re: Communicating with spi with slave in interrupt, the system will be dumped
Does your readData and writeData actually exist as long as the SPI transfer is in progress?
-
- Posts: 3
- Joined: Fri Jan 29, 2021 4:40 am
Re: Communicating with spi with slave in interrupt, the system will be dumped
Yes yes, I have tried using spiTranfer () function with 1 external flash memory slave and it works normally, I get correct readData array. But if I call spiTranfer () in an interrupt my system gets dumpedESP_Sprite wrote: ↑Fri Jan 29, 2021 6:21 amDoes your readData and writeData actually exist as long as the SPI transfer is in progress?
-
- Posts: 9746
- Joined: Thu Nov 26, 2015 4:08 am
Re: Communicating with spi with slave in interrupt, the system will be dumped
Easy solution: Don't do that. You can't call routines from ISRs unless they're specifically marked (either because they have _from_isr in the name or otherwise) to be OK to call from an interrupt.thanhphuct wrote: ↑Fri Jan 29, 2021 6:32 amBut if I call spiTranfer () in an interrupt my system gets dumped
-
- Posts: 3
- Joined: Fri Jan 29, 2021 4:40 am
Re: Communicating with spi with slave in interrupt, the system will be dumped
[quote=Easy solution: Don't do that. You can't call routines from ISRs unless they're specifically marked (either because they have _from_isr in the name or otherwise) to be OK to call from an interrupt.
[/quote]
So is there a way to distinguish which process can be called in the interrupt or not?
[/quote]
So is there a way to distinguish which process can be called in the interrupt or not?
-
- Posts: 3
- Joined: Mon Jan 25, 2021 1:56 pm
Re: Communicating with spi with slave in interrupt, the system will be dumped
Hi ESP_Sprite, I have same problem with him. I have a sensor with SPI interfaces. My sensor will trigger a signal (GPIO) when complete convert data.ESP_Sprite wrote: ↑Fri Jan 29, 2021 7:10 amEasy solution: Don't do that. You can't call routines from ISRs unless they're specifically marked (either because they have _from_isr in the name or otherwise) to be OK to call from an interrupt.thanhphuct wrote: ↑Fri Jan 29, 2021 6:32 amBut if I call spiTranfer () in an interrupt my system gets dumped
I connect this signal of sensor into GPIO interrupt of ESP32, configure SPI with master mode and DMA function.
When I received a trigger signal, I will read convert data from sensor. To increase the performance of system, I put the code read data of sensor (spi_device_queue_trans) in ISRs function and system will be crashed. In spite of the ISRs function is mapped into IRAM_ATTR
So can you give me some advice about my case. ?.
Hope for your reply. Thank and best regards
-
- Posts: 9746
- Joined: Thu Nov 26, 2015 4:08 am
Re: Communicating with spi with slave in interrupt, the system will be dumped
thanhphuct: ...I answered that question in the text you quoted. Either the name contains something like _from_isr, or the ESP-IDF documentation indicate it's OK to call that function from an interrupt.
tam1111574: Exact same answer: do not do that in an interrupt. Instead, have a (high-priority) task waiting for e.g. a semaphore before queueing the transfer, then use the ISR to set the semaphore.
tam1111574: Exact same answer: do not do that in an interrupt. Instead, have a (high-priority) task waiting for e.g. a semaphore before queueing the transfer, then use the ISR to set the semaphore.
Who is online
Users browsing this forum: No registered users and 90 guests