How to handle ESP32 concurrent SPI bus access?

Rrobinet
Posts: 29
Joined: Wed Aug 16, 2017 7:05 am

How to handle ESP32 concurrent SPI bus access?

Postby Rrobinet » Mon Jan 24, 2022 8:53 am

Hi,

I try to understand how the ESP32 SPI library manages concurrent SPI access on the same bus and more specifically when a transaction is initiated by an Interrupt.

For interrupts, the Arduino SPI library manages that type of conflict using the SPI_HAS_TRANSACTION flag allowing the use usingInterrupt() functions that saves the SREG (Status Register) and disable the Interrupts before any SPI transaction (and restore it after).

The architecture of the ESP32 is quite different, but I don't see a similar configuration in the SPI and esp-hal-spi libraries beside one flag , the _inTransaction, that I can't hardly see its purposes.

I note that the SPI_HAS_TRANSACTION is defined in the esp-hal-spi.c, but again I don't see its purposes, ... beside compatibility with the Arduino one.

So is it somewhere and clear explanation of how to handle concurrent SPI access on the same bus or alternatively, shall I state that to ensure no conflict with concurrent SPI access on the same bus (typically when one is initiated by interrupt), that a semaphore mechanism handling SPI transaction is to be implemented in the script ensuring synchronized access.

Thanks in advance
Robert

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

Re: How to handle ESP32 concurrent SPI bus access?

Postby ESP_Sprite » Tue Jan 25, 2022 1:06 am

Moving to the Arduino forum as the question you ask is specific to that.

Rrobinet
Posts: 29
Joined: Wed Aug 16, 2017 7:05 am

Re: How to handle ESP32 concurrent SPI bus access?

Postby Rrobinet » Tue Jan 25, 2022 7:45 am

Is it Arduino which is responsible to port the ESP32 library to the Arduino IDE ?
I read in the library header:
Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD

It doesn't matter which platform to use, explanations of this issue using the ESP-IDF libraries is also OK for me.

Robert

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

Re: How to handle ESP32 concurrent SPI bus access?

Postby ESP_Sprite » Tue Jan 25, 2022 2:09 pm

I can explain how the ESP-IDF one works, but note that to my knowledge the architecture is fairly different from the Arduino one.

The ESP-IDF SPI libraries handle concurrency generally by taking transaction descriptors and pushing them onto FreeRTOS queues, off the top of my head there's one for each device (=CS pin on a given SPI bus) you define. The drivers interrupt logic takes these descriptors from the queue, execute them, and push the result on a return queue.

Who is online

Users browsing this forum: No registered users and 36 guests