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.

  • Hi Pawel,

    I have implemented the SAADC DMA buffer using the function nrf_drv_saadc_buffer_convert(). I am attaching my complete code with this thread, at top. I have kept the SAADC buffer size as 24 and SAADC is running in scan mode. So every 12ms Event done interrupt will occur. Now I am performing SD write operation after 120 ms. But Still I am starting streaming data at 1000 sps entire code stops.

    I am calling the SD write operation in main function by checking the SD write flag which is activated after 120ms .

    Does App scheduler will really solve this issue as I have not worked on scheduler till now?

Reply
  • Hi Pawel,

    I have implemented the SAADC DMA buffer using the function nrf_drv_saadc_buffer_convert(). I am attaching my complete code with this thread, at top. I have kept the SAADC buffer size as 24 and SAADC is running in scan mode. So every 12ms Event done interrupt will occur. Now I am performing SD write operation after 120 ms. But Still I am starting streaming data at 1000 sps entire code stops.

    I am calling the SD write operation in main function by checking the SD write flag which is activated after 120ms .

    Does App scheduler will really solve this issue as I have not worked on scheduler till now?

Children
No Data
Related