How do I cancel a call to spi_transceive_cb()? Or, how do I safely change the MISO data when the nRF54LM20A is a SPI slave?

Hi,

As the subject says, I have an nRF54LM20A acting as a SPI slave. When I perform a call to spi_transceive_cb(), I don't have any data for TX (i.e. MISO). This runs until another chip acting as SPI master performs a SPI operation, at the end of which, the given callback passed to spi_transceieve_cb() is called. At that point, I can restart the call to spi_transceieve_cb() with any data that I want.

However, the problem is that I periodically need to update the TX data, and I need to do this safely. I am fine with the CPU taking and holding the SPI semaphore, which results in sending a bunch of DEF characters on MISO, but I have tried modifying the underlying tx buffer, and this doesn't seem to work.

When I want to add data periodically to the TX buf (for MISO), is it possible to do the following? 

  1. Cancel the current spi_transceieve_cb() operation.
  2. Write the tx_buf
  3. Restart the spi_transceieve_cb() operation.

If so, how would I do this?

Regards,
Tyler

Parents
  • Not possible. 

    If you hold the CPU semaphore, the SPIS won't send anything else than the DEF character until CS is pulled high again.

    Read the SPIS chapter in the datasheet - HW semaphore can only be aquired by SPIS when its free during the CS high-to-low edge.

    The whole internal buffering is undocumented, thus you also don't have any idea how many bytes the hardware would pre-fetch once a transaction has started. Even if you knew, its a bad race that you will loose a soon as there was a competing BT radio event.

    The only proper solution is for the SPI master to re-try the transaction once it reads DEF instead of expected answer.

  • This is not what I was asking. When calling spi_transceieve_cb() as SPI slave, we are waiting on a transaction by the SPI master.

    I have read the SPIS chapter in the datasheet, and what I need is possible by the hardware, but I don't see how you can stop a call to spi_transceieve_cb() once you started it in Nordic's SPIS driver.

Reply Children
Related