Photon 2 SPI DMA transfer deadlock - Take 2

Thanks for the answer - I’ll give it a try. Before, I want to ask a few clarifying questions:

The API use in my example is in line with the documentation / intented usage, right? I do understand that the busy wait underneath is not what I want, but I also would have expected that the DeviceOS uses a mutex internally to block.

In my actual code, I want to tell LVGL with lv_display_flush_ready that the transfer is done, so that would be perfect from within that callback (docs). However, I also would need to set the CS signal high, but the particle documentation explicitly says this is not allowed either

You should not set the CS pin high from the callback ISR. The callback is called when the DMA transaction is completed, which can be before the data is actually transmitted out of the SPI FIFO.

So, the documentation / use of the SPI API seems to have all the proper pieces, but I cannot use them easily:

  • If I use the null callback version (I did that on an extra thread), DeviceOS busy waits and seems to cause problems with the rest of the OS, and eventually hangs. This post from another user seems to hint at the same.
  • If I use a callback, I have no guarantee when the SPI transfer is actually complete - I woud have to delay for some unknown buffer amount to be transmitted before I can set CS high again.

Since I also need to do the endTransaction after the callback fired, but not from within the callback, do I understand correctly that the recommended implementation for the user is to start a thread AND use the callback? The thread's sole purpose would be to trigger the transfer, then call endTransaction when the done signal is received via a mutex from the callback.

I see if it actually fixes the issue, but I’m surprised that the API does not take away the burden from me. Is my understanding above correct?

Thanks,
MikeS