Asynchronous UART breaks SPI communication

I’m currently working on a project which implements the Gapuino development board with Mbed OS on the RISC-V GAP8 platform of PlatformIO.

In this project I have to sample at a constant rate without losses (by using a data ready interrupt) data coming from an SPI device (ADS1299). Batches of data has to be sent (with a much slower rate) to a computer via asynchronous UART using rosserial protocol.

The problem lies with the fact that I cannot know when the computer is gonna send messages (sync messages for example which are frequent) and thus this will cause a UART rx interrupt that will break the execution of SPI reads ending with the following error:

Assert failed: g_spiHandle[1], file: /home/gualor/.platformio/packages/framework-gap_sdk/mbed-os/targets/TARGET_GWT/TARGET_GAP8

I managed to reproduce this error without the presence of rosserial, by just having a thread which takes too long to complete (using wait) that will cause the data ready interrupt to overlap with the SPI reads (which normally does not happen) :

#include "mbed.h"
#include "ADS1299.h"
#include "Definitions.h"

InterruptIn DRDY(GPIO_A5_B40);  // Setup interrupt pin
ADS1299 ads;                    // SPI device
osThreadId id;

// Data ready interrupt
void dataReadyISR(void)
    osSignalSet(id, 0x05);  // Signal when data is ready

int main() 
    id = ThisThread::get_id();              // Thread ID
    DRDY.fall(callback(&dataReadyISR));     // Attach data ready ISR

        osSignalWait(0x05, osWaitForever);  // Wait for data ready interrupt
        ads.updateChannelData();            // Read data with SPI
        // Used to slow down thread and cause
        // interrupt to break SPI

To go straight to the point, my question is:
"is there a way of making SPI interrupt safe without disabling UART rx interrupts? (losing incoming messages will cause a lost connection).

Thank you in advance for the support, any help will be greatly appreciated!

Seems like you have found a bug in in the implementation of framework-gap_sdk written by GreenWaves Technologies. You have already opened an issue at Mbed SPI async transfer won't call callback · Issue #175 · GreenWaves-Technologies/gap_sdk · GitHub. This is correct.

Once the issue has been corrected, you can open an issue on Issues · platformio/platform-riscv_gap · GitHub for an update request.

1 Like

Thank you very much for the quick response!
Yes, I opened an issue regarding a bug of the SPI transfer function that would have solved the issue by allowing non-blocking SPI communication and hence avoid the risk of getting interrupted (I think).

I already had issues with the gap_sdk in which the drivers for the RawSerial::attach method were entirely missing, I had to use a workaround that didn’t make use of attach, so I’m not sure this bug will be fixed anytime soon as GreenWaves Technologies does not support Mbed OS anymore.

I was wondering if there could be a workaround to the issue I am facing by just using the tools that I currently have, or is it impossible given the requirements I mentioned?