<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to use DMA in NRF52 while writing on SD card, while BLE is also operating?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/18769/how-to-use-dma-in-nrf52-while-writing-on-sd-card-while-ble-is-also-operating</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 10 Jan 2017 15:22:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/18769/how-to-use-dma-in-nrf52-while-writing-on-sd-card-while-ble-is-also-operating" /><item><title>RE: How to use DMA in NRF52 while writing on SD card, while BLE is also operating?</title><link>https://devzone.nordicsemi.com/thread/72495?ContentTypeID=1</link><pubDate>Tue, 10 Jan 2017 15:22:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3783f889-64a6-4483-bfa3-597c13a5b34c</guid><dc:creator>Ankush</dc:creator><description>&lt;p&gt;Hi Pawel,&lt;/p&gt;
&lt;p&gt;Thanks for your suggestion in mentioned attached code above.I will change it volatile bool .  Actually I am initializing SAADC before SD card and BLE but not starting it to sample the input signal.After every thing has been initialized properly, then using Nordic UART service I am sending some values(1 or 2) to start sampling the SAADC. (This happens after BLE starts advertising ). So AS sson as received any value from master control panel ADC samples the signal and after 12 samples it generates EVENT DONE event in Callback.&lt;/p&gt;
&lt;p&gt;I am using IAR for developing my code and using MCP to get the values over APP. AS soon as I sent any value 1 or 2 , entire code gets stopped and over MCP I received GATT error :133(0x85). In IAR it is not showing the cause of sopping the code.&lt;/p&gt;
&lt;p&gt;In SAADC initialization I have set priority as &lt;code&gt;APP_IRQ_PRIORITY_LOW&lt;/code&gt; from default value of lowest.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use DMA in NRF52 while writing on SD card, while BLE is also operating?</title><link>https://devzone.nordicsemi.com/thread/72493?ContentTypeID=1</link><pubDate>Tue, 10 Jan 2017 12:11:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d9766c2-d29b-47a5-aeb5-692df999ba3d</guid><dc:creator>Pawel Zadrozniak</dc:creator><description>&lt;p&gt;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&amp;#39;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).&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use DMA in NRF52 while writing on SD card, while BLE is also operating?</title><link>https://devzone.nordicsemi.com/thread/72494?ContentTypeID=1</link><pubDate>Tue, 10 Jan 2017 07:43:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86e02b4e-962b-488d-aa46-94b751dabbf2</guid><dc:creator>Ankush</dc:creator><description>&lt;p&gt;Hi Pawel,&lt;/p&gt;
&lt;p&gt;I have implemented the SAADC DMA buffer using the function &lt;code&gt;nrf_drv_saadc_buffer_convert()&lt;/code&gt;. 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.&lt;/p&gt;
&lt;p&gt;I am calling the SD write operation in main function by checking the SD write flag which is activated after 120ms .&lt;/p&gt;
&lt;p&gt;Does App scheduler will really solve this issue as I have not worked on scheduler till now?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use DMA in NRF52 while writing on SD card, while BLE is also operating?</title><link>https://devzone.nordicsemi.com/thread/72491?ContentTypeID=1</link><pubDate>Mon, 09 Jan 2017 15:18:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0e926c4-7b5a-4d74-930a-823d572065ed</guid><dc:creator>Pawel Zadrozniak</dc:creator><description>&lt;p&gt;I&amp;#39;ll start from #3:
3) SD card library uses SPI in DMA mode if SPIn_USE_EASY_DMA is enabled in sdk_config.h (where n is the SPI instance number used by app_sdcard, defined by APP_SDCARD_SPI_INSTANCE; by default (in fatfs example): instance 0, dma enabled).&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Call FATFS API functions from the main context (not an interrupt handler) and BLE functions from interrupts (which will preempt the fatfs call). BLE communication is time sensitive, so it&amp;#39;s a good idea to keep the SPI priority lower than the priority from which wireless transmission is triggered (eg. SAADC, timer). By default SPI priority is set to lowest (SPI_DEFAULT_CONFIG_IRQ_PRIORITY (sdk_config.h) equal to APP_IRQ_PRIORITY_LOWEST (app_util_platform.h) = 7 on nRF52/Cortex M4).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I&amp;#39;d also recomment using app_scheduler. If you will be able to implement ADC sampling / BLE transmission in interrupt driven way then all you need to do is schedule the SD write in one of the interrupts (then it will be executed from main cotext) and make sure that there is enough time to write the data on SD (in the worst case scenario) between filling the buffers.&lt;/p&gt;
&lt;ol start="2"&gt;
&lt;li&gt;Take a look at nrf_drv_saadc_buffer_convert(). It takes a pointer to the buffer and buffer size as an argument. My concept is something like this:
uint16_t buf[2][12&lt;em&gt;N];
call _convert() with: &amp;amp;buf[0][0], size 12; then [0][12], then [0][24], [0][36], and so on until it&amp;#39;s filled. When it&amp;#39;s full (last conversion to buf[0][&lt;/em&gt;] finished) call _convert with( &amp;amp;buf[1][0]. trigger SD write of buffer 0, then convert to [1][12]. [1][24]...
nrf_drv_saadc_buffer_convert() will result in interrupt and calling the handler, so you can trigger the next sampling / wireless data transmission there.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use DMA in NRF52 while writing on SD card, while BLE is also operating?</title><link>https://devzone.nordicsemi.com/thread/72492?ContentTypeID=1</link><pubDate>Mon, 09 Jan 2017 14:23:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2e40485-b9fe-434a-838e-ab694bf9967a</guid><dc:creator>Ankush</dc:creator><description>&lt;p&gt;Hi Pawel,&lt;/p&gt;
&lt;p&gt;Thanks for your response. This is really helpful concept. But From your comment I have few queries,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;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?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;ol start="3"&gt;
&lt;li&gt;As I am unaware about how to use DMA on SPI, Can you suggest me any sample example or process for it?&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use DMA in NRF52 while writing on SD card, while BLE is also operating?</title><link>https://devzone.nordicsemi.com/thread/72490?ContentTypeID=1</link><pubDate>Mon, 09 Jan 2017 08:23:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ebdf707-5bb6-4961-b6f2-e23a2bc4cf29</guid><dc:creator>Pawel Zadrozniak</dc:creator><description>&lt;p&gt;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&amp;#39;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.&lt;/p&gt;
&lt;p&gt;I&amp;#39;d suggest the following scenario:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;allocate 2 buffers,&lt;/li&gt;
&lt;li&gt;set current buffer to #1,&lt;/li&gt;
&lt;li&gt;start ADC sampling (N=12 samples appended into the current buffer)&lt;/li&gt;
&lt;li&gt;send the samples over BLE and trigger the next sampling,&lt;/li&gt;
&lt;li&gt;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&lt;/li&gt;
&lt;li&gt;...and so on...&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that the worst case scenario for SD write operation (according to SD specifications) is 250 or 500ms, depending on card type.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use DMA in NRF52 while writing on SD card, while BLE is also operating?</title><link>https://devzone.nordicsemi.com/thread/72488?ContentTypeID=1</link><pubDate>Thu, 05 Jan 2017 09:53:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f87d5000-ffac-4541-80cb-f8841b4553c1</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;How would using SPI (through FATFS) affect BLE transmission? Connection events in the SoftDevice has the highest priority. I&amp;#39;m not too familiar with this example, but it seems to me that it is already using DMA.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use DMA in NRF52 while writing on SD card, while BLE is also operating?</title><link>https://devzone.nordicsemi.com/thread/72487?ContentTypeID=1</link><pubDate>Thu, 05 Jan 2017 09:09:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de523169-c8d9-450b-895b-4a75f11f4011</guid><dc:creator>Ankush</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;I am interfacing SD card with nrf52 using FATFS sample example given in SDK12.0. I have added basic interfacing code &lt;a href="https://devzone.nordicsemi.com/question/109173/how-to-open-and-access-files-in-directory-other-than-root-directory-in-fatfs/"&gt;Here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Using Direct memory Access (DMA) of SAADC or SPI Can I achieve these task?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use DMA in NRF52 while writing on SD card, while BLE is also operating?</title><link>https://devzone.nordicsemi.com/thread/72489?ContentTypeID=1</link><pubDate>Thu, 05 Jan 2017 08:03:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f34dc5b0-2fb3-452e-81e3-48ddd8e30185</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;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?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>