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

How to use DMA in NRF52 while writing on SD card, while BLE is also operating?

Hi,

In my application of interfacing SD card with nrf52, I am using SAADC to sample the input signal at 1000 samples per seconds. These samples I am combining in 84 packets each consisting 12 samples and 20 bytes. In one second I am sending 84 packets over BLE to remote tablet device.

So, I want to write these packets in SD card. Writing one packet at a time is not a good practice. So I want to write 40 packets at a time in SD card. For this I need DMA. As I am never used DMA before, I want to understand what is the correct steps to use DMA for my application.

Does any one has any idea about this?

SDC+BLE.c

Parents
  • FATFS port present in SDK 12 is using the asynchronous SD card driver (which uses SPI master driver in EasyDMA mode on nRF52). Unfortunately FATFS API is synchronous, so if it's not modiffied and used without preemptive OS, CPU has to wait for SD card operations to complete on every synchronous API call. However, when there is a serial data transfer in the background (card read/write operation), higher priority interrupts should not affect SD communication (except the possible delay), as far as SPI driver interrupts are being handled.

    I'd suggest the following scenario:

    • allocate 2 buffers,
    • set current buffer to #1,
    • start ADC sampling (N=12 samples appended into the current buffer)
    • send the samples over BLE and trigger the next sampling,
    • if current buffer is ful then switch current buffer to #2, start the ADC sampling into #2 and trigger the write of #1 into SD; while writing the data, you can still send the packets over BLE and trigger ADC sampling in interrupts
    • ...and so on...

    Note that the worst case scenario for SD write operation (according to SD specifications) is 250 or 500ms, depending on card type.

  • Scheduler would be the recommended way of doing this if you want to extend the application in future. In this simple case, a single flag is good enough. (btw. it should be defined as volatile bool, not bool as it's being modiffed from different context). The general idea is OK - SD card operations from main context only. You might also want to increase the priority of SAADC interrupt in from _LOWEST (default) to APP_IRQ_PRIORITY_LOW (to be above SD/SPI).

    Do you have an environment set up for debugging to see where it stops? To find the caouse, try to run the blocks separately - sampling/sending, then sampling/writing or periodic writing (or sending) some random data.

    In the attached code, adc is initialized (and started) at the beginning, before the initialization of BLE / SD card - that could also be a source of problems.

Reply
  • Scheduler would be the recommended way of doing this if you want to extend the application in future. In this simple case, a single flag is good enough. (btw. it should be defined as volatile bool, not bool as it's being modiffed from different context). The general idea is OK - SD card operations from main context only. You might also want to increase the priority of SAADC interrupt in from _LOWEST (default) to APP_IRQ_PRIORITY_LOW (to be above SD/SPI).

    Do you have an environment set up for debugging to see where it stops? To find the caouse, try to run the blocks separately - sampling/sending, then sampling/writing or periodic writing (or sending) some random data.

    In the attached code, adc is initialized (and started) at the beginning, before the initialization of BLE / SD card - that could also be a source of problems.

Children
No Data
Related