After BLE disconnect SPI device read hangs on __WFE()

SDK V17.1, nRF52840 SOC, s140_nrf52_7.2.0_softdevice.hex

I am attempting to configure a spi device from a ble gap disconnect event handler. Before the disconnect event communication with the spi device is good.

When the disconnect event happens I try to read the device status register. The nRF52840 spi driver starts a read with nrf_drv_spi_transfer(..).

Then this code waits for the transfer to complete:

while((!spi_xfer_done) && --timeout)
__WFE();

if(!timeout)
{
NRF_LOG_DEBUG("SPI timeout!");
NRF_LOG_FLUSH();
return NRF_ERROR_TIMEOUT;
}

The timeout message is not seen and the code hangs waiting for an event. Could this be a soft device issue?

After BT reconnection event spi access once again works. config is attached.

1325.sdk_config.h

  • Hi davidb,

    My best guess is that the busy wait takes too long in the handler and causes issues. Even if that is right, I cannot say where the issues would be without having a somewhat similar setup in front of me and start digging.

    Therefore, instead, may I suggest that you don't perform the SPI operation in the event handler? You could set up a flag variable. In the event handler, raise the flag. In the main while loop, if the flag is raised, perform the action, and lower the flag.

    Generally busy waiting in interrupt and event handling context is not good. Please try that and let me know if you still have the problem.

    Best regards,

    Hieu.

  • Implemented your suggestion and the issue is fixed.

    Thank you.

Related