This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52840 SPI init hangs after event loop starts

Hi,

My project uses nRF52840 with SD 140, SDK 17.0.2 and SES.  My hardware has SD Card SPI and LCD SPI sharing bus pins, using CS pins to switch devices.  Because of this each device needs to be uninitialized before starting comms with the other.  Essentially my code flow goes:

Initialize SD card -> Read bmp file from SD -> Uninitialize SD -> Initialize LCD -> Display bmp on screen -> Uninitialize LCD

This all works fine when called from my main() function.  I can display as many bmp images in a row as I desire.  The problem occurs once the event loop has started.   Both the SD card and LCD will not initialize from an event handler function.  The SD card hangs at m_drives[drv].config.wait_func(); in diskio_blkdev.c or the LCD hangs at while(!m_spi_xfer_done)  after calling nrfx_spim_xfer();.  I have tried using a bsp event (pressing board button) and also a ble write event (writing to custom characteristic).  I have tried using SPI Instances 0, 1, and 2 with same results.

I don't understand how it can initialize and unitialize 10 times in a row with no issues before any event handlers run but it seems deadlocked afterwards?  It seems to me there could be an issue with the soft device causing interference with the spi bus?

EDIT: It appears I might have an interrupt issue?  But if I set NRFX_SPIM and SPI_ENABLED irq priority to 3 or 5 I get hard fault when event handler routine is called

Parents Reply Children
  • Hello,

    poolshark021 said:
    I think I solved my interrupt issue with info from this topic:

    I am happy to hear that you have resolved your issue!

    poolshark021 said:
    I decided to only use the event handler to set a flag and then let the interrupt return.  Then I circle back and handle the flag and data transfer afterwards. 

    This is a good way of implementing this, especially if it is not paramount that the flag event is processed immediately(since the main context has the lowest priority). Good choice!

    poolshark021 said:
    I have DEBUG and DEBUG_NRF defined.  No info is displayed in the log (using RTT backend).

    By this, do you mean that you are not seeing anything at all written out to your RTT backend, or only that you are not seeing any error messages despite having DEBUG defined?

    poolshark021 said:
    I am currently stepping through code leading to the hard faults.  If I can pinpoint where its happening I will update this thread

    Be advised that you can not step through the code when the SoftDevice is active, as this will halt the CPU - causing the SoftDevice to miss its timing-critical tasks, and thus crash. If you are debugging a peripheral I recommend disabling the BLE parts of the application before stepping through the code.

    Best regards,
    Karl

Related