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

NRF_ERROR_BUSY when trying to interface with SDCard

Hi! I'm using the fatfs library to read/write data from/to an SD-card. I noticed the following behaviour:

When I try to write or read data directly after receiving a BLE-event, the nrf_blk_dev_init function in the FATFS library will return NRF_ERROR_BUSY, but whenever I move those read/write operations back into the infinite loop in my main(), right after the idle_state_handle(), it performs as expected. 

Currently, my workaround is queueing these operations/working with some buffers but I was curious as to why it was behaving like this. 

  • directly after receiving a BLE-event

    Is the inside the event handler? This runs in interrupt context by default, and thus cannot wait for the SPI interrupt to occur, since those run on the same (or lower) priority. Thus SPI just blocks forever (or at least does not properly wait for the SPI).

    Running SDcard functions in interrupt context is asking for trouble anyway - file system is not interrupt safe.

  • Correct, well it calls through some functions but it is triggered by the event handler. That actually makes a lot of sense. I'm assuming adjusting the SPI interrupt to a higher priority is going to mess up my BLE-communication?

  • No need to mess with interrupt prio.

    As I said, the FAT filesystem will also not work from interrupt context.

    Try looking at the scheduler application (app_scheduler) in order to trigger app events from interrupts.

  • Awesome, exactly what I needed. Thanks!