How sharing SPI for ethernet w5500, lora sx1276 and sdcard
Posted: Tue Aug 31, 2021 6:57 pm
Good afternoon,
I have a firmware doubt that totally implies my hardware design. I'm designing a PCB and I wanted to share the same SPI for ethernet w5500, lora sx1276 and sdcard, since HSPI or VSPI make it possible to use 3 CS slaves.
However, looking at all the ESP-NETIF API for w5500 and the mqtt and tcp socket layers that I will use, it is not clear how I can implement a mutex in the call of these functions to protect shared access to this SPI by various tasks, since the SDCARD and LORA will make use of the same SPI, with the lib lora I built, I managed to insert the mutexes properly, however, in the case of the LIB of the sdcard and ethernet ESP-NETIF, I have no idea how to build this from a thread-safe way.
Since in the case of Ethernett mainly, I will receive external interrupts and I need to ensure that the lora and not sdcard will be consuming the bus at this time.
I saw in the documentation that there are functions spi_device_acquire_bus() and spi_device_release_bus(), which are a kind of mutex, but again, how will I ensure that the MQTT callback event loop at the time it happens is pulling data via ESP-NETIF , do not collide with my SPI when I am occupying bus with LORA ? It would be awesome to have this clear of how to properly insert the FreeRTOS mutexes into the ethernet API, so that you can share the SPI with as much confidence as possible.
Att. Maurício Alencar
I have a firmware doubt that totally implies my hardware design. I'm designing a PCB and I wanted to share the same SPI for ethernet w5500, lora sx1276 and sdcard, since HSPI or VSPI make it possible to use 3 CS slaves.
However, looking at all the ESP-NETIF API for w5500 and the mqtt and tcp socket layers that I will use, it is not clear how I can implement a mutex in the call of these functions to protect shared access to this SPI by various tasks, since the SDCARD and LORA will make use of the same SPI, with the lib lora I built, I managed to insert the mutexes properly, however, in the case of the LIB of the sdcard and ethernet ESP-NETIF, I have no idea how to build this from a thread-safe way.
Since in the case of Ethernett mainly, I will receive external interrupts and I need to ensure that the lora and not sdcard will be consuming the bus at this time.
I saw in the documentation that there are functions spi_device_acquire_bus() and spi_device_release_bus(), which are a kind of mutex, but again, how will I ensure that the MQTT callback event loop at the time it happens is pulling data via ESP-NETIF , do not collide with my SPI when I am occupying bus with LORA ? It would be awesome to have this clear of how to properly insert the FreeRTOS mutexes into the ethernet API, so that you can share the SPI with as much confidence as possible.
Att. Maurício Alencar