nrf52840 ble+sd card

I’m developing a project on the nRF52840 that uses BLE + RTC + an SD card. It’s based on a previous project that only used BLE + RTC, and I’ve added the ability to store data on the SD card. However, a problem has appeared. In the BLE + RTC + SD card project, when I write data to the SD card, it succeeds a few times at the beginning, but most of the time it just waits for the block_dev interrupt, and that interrupt doesn’t seem to occur. Is there anything I should check in this situation? After merging everything into the BLE + RTC + SD card project, I confirmed that the basic SD card write operation itself works. The issue only happens when BLE is running, the RTC is running, and I also perform SD card write operations at the same time.

  • Hi there,

    So I get this...When BLE + RTC + SD all run together and your SD writes start hanging waiting for the block_dev interrupt, it usually means the SD interrupt is either never firing or can’t preempt the context that’s doing the wait. On nRF52840 with BLE, you really need to:

    1. Make sure all SD writes run from normal thread/main context, never directly from BLE or RTC callbacks or ISRs.

    2. Check that the SPIM/SD interrupt priorities are compatible with the SoftDevice/BLE stack – if they’re too high or misconfigured, the interrupt either won’t fire or will be masked.

    3. Ensure only one “owner” task is using the SD card to avoid reentrancy issues.

    4. Temporarily disable aggressive power-saving / clock gating to rule out HFCLK/SD bus being turned off mid-transfer.

    A good next step is to add logging/toggling inside the block_dev ISR and compare your IRQ priority and sdk_config.h / prj.conf against a minimal SD-only project that works reliably. I run BLE + RTC + SD together on the Xiao nRF52840 Dev Expansion board without problems, so the combo is workable – the bug is most likely in the integration and timing.

    Post up the code if you can, We can look and give it a compile.

    HTH

    GL :-) PJ V

  • hello PjGlasso 

    In my project, the SD write function only runs inside the main function. It doesn’t run continuously; the RTC handler slowly fills a buffer, and when the data reaches a certain amount, the SD write function is called in main. Also, when I look at the spi_init function in app_sdc.c, I see that irq_priority is set to 6.

Related