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

  • So you want to store 84*20 = 1680 bytes? What do you mean by DMA? How are you interfacing the nRF52 with the SD card?

  • Hi,

    As I am doing BLE transmission and writing to SD card in parallel, writing one packet to SD card each time(at 1ms interval) would affect the BLE transmission and my MCU would be busy doing these operations. Instead of this I m looking into the method, which can store each packet to memory, till the level of 40 packets reached.

    I am interfacing SD card with nrf52 using FATFS sample example given in SDK12.0. I have added basic interfacing code Here

    Using Direct memory Access (DMA) of SAADC or SPI Can I achieve these task?

  • How would using SPI (through FATFS) affect BLE transmission? Connection events in the SoftDevice has the highest priority. I'm not too familiar with this example, but it seems to me that it is already using DMA.

  • 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.

  • Hi Pawel,

    Thanks for your response. This is really helpful concept. But From your comment I have few queries,

    1. SD read/Write operation if taking 250 or 500 ms for operation, then It will affect my BLE streaming which is happening at 12ms interval. Presently I can not perform both BLE streaming and SD write operation as BLE stops working.How can I deal with this?

    2)As SAADC as already have 2 buffers of size 24 which uses DMA, how can I then again allocate 2 buffers for this operation? Are you talking about SPI DMA.

    1. As I am unaware about how to use DMA on SPI, Can you suggest me any sample example or process for it?
Related