<?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>DMA buffers switching with SPI and TIMERS via PPI</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119959/dma-buffers-switching-with-spi-and-timers-via-ppi</link><description>While collecting 2-byte samples via SPI4 (with a 32 MHz clock) using PPI and timers—one triggering transfers at 400 kHz and another handling an interrupt every 512 samples (counter mode incrementing every SPI transfer end via PPI) to switch the SPI DMA</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 Apr 2025 05:38:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119959/dma-buffers-switching-with-spi-and-timers-via-ppi" /><item><title>RE: DMA buffers switching with SPI and TIMERS via PPI</title><link>https://devzone.nordicsemi.com/thread/530117?ContentTypeID=1</link><pubDate>Wed, 02 Apr 2025 05:38:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5045d3bb-7449-4c1a-948e-e41b1d6c8aa3</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;If you&amp;#39;re already chaining with SUSPEND and RESUME and still seeing corrupted samples, then it does sound like a buffer ownership race.&lt;/p&gt;
&lt;p&gt;Even if the time between switches is enough, it&amp;#39;s possible that the SPI is still writing when the pointer is updated or handed off. I&amp;#39;d suggest making absolutely sure that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You only update the buffer address after SPI has fully suspended.&lt;/li&gt;
&lt;li&gt;No part of your queue processing thread (or the queue itself) touches the active buffer before the handoff is done.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Also worth checking if the DMA buffers are aligned and marked as non-cached&amp;nbsp;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If all that looks clean, I would next look into logging when each buffer switch and SPI transfer actually happens (timestamps) to catch any overlaps.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA buffers switching with SPI and TIMERS via PPI</title><link>https://devzone.nordicsemi.com/thread/529523?ContentTypeID=1</link><pubDate>Fri, 28 Mar 2025 13:10:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52b25b92-8a21-4941-a2f8-05f909543427</guid><dc:creator>Michal Mrowiec</dc:creator><description>&lt;p&gt;Yes, I tried this also. Unfortunately, the problem still persists. After switching buffers, in the interrupt handler for the sample block, the pointer to the previous part of the buffer is placed into the queue using &lt;code data-start="193" data-end="204"&gt;k_msg_put&lt;/code&gt;. The message is then processed by the memory write thread. The number of data buffers and the time between switches are sufficient to prevent data block overlap. However, could pointer transfer errors still occur in this configuration? Where else can I look for the source of the issue?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA buffers switching with SPI and TIMERS via PPI</title><link>https://devzone.nordicsemi.com/thread/528602?ContentTypeID=1</link><pubDate>Mon, 24 Mar 2025 12:25:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df0a0bba-cb45-412e-a7a8-e200dd787d98</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user=""]I) to switch the SPI DMA buffer address—[/quote]
&lt;p&gt;I missed the obvious point, didn&amp;#39;t I?&lt;/p&gt;
&lt;p&gt;This is a classic race condition between DMA buffer update and the next DPPI triggered SPI transfer which normally should be solved using software enabled methods.&lt;/p&gt;
&lt;p&gt;Maybe it helps to chain this using suspend and resume tasks&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Chain Timer A → SPI.TASKS_RESUME via PPI.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After every 512 samples: Use TASKS_SUSPEND to pause SPI.Change the DMA buffer address.Then trigger TASKS_RESUME again via DPPI/PPI.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I can not think of anything else right now apart form this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA buffers switching with SPI and TIMERS via PPI</title><link>https://devzone.nordicsemi.com/thread/528357?ContentTypeID=1</link><pubDate>Fri, 21 Mar 2025 09:27:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c85aef65-160a-45f8-9947-0a715e1c3b26</guid><dc:creator>Michal Mrowiec</dc:creator><description>&lt;p&gt;Sounds good, how can I use mutex for sampling timer (2,5 us), while it&amp;#39;s running without irq handler?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA buffers switching with SPI and TIMERS via PPI</title><link>https://devzone.nordicsemi.com/thread/528354?ContentTypeID=1</link><pubDate>Fri, 21 Mar 2025 09:21:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b33bc24b-0417-46fa-824f-1b3ef88ea5b5</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Michal,&lt;/p&gt;
&lt;p&gt;What you are running seems a bit tight. You are running one timer that is triggering the SPI samples every 2.5us and then the other timer is slow enough to trigger only when you have 512 samples. The issue is to find a safe spot to change the buffers when the other timer is not trying to access it&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I would use a mutual exclusion (mutex ) while accessing these SPI DMA buffers so that the DMA pointers are not changed while they are being used.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA buffers switching with SPI and TIMERS via PPI</title><link>https://devzone.nordicsemi.com/thread/528229?ContentTypeID=1</link><pubDate>Thu, 20 Mar 2025 13:23:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:707aa3a3-10a4-42dc-8ed0-55c3ac132c5e</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Michal,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I took over this thread. I want to analyze this a bit more and give you a proper reply, please expect that I will reply to you on or before Monday. Thanks for your patience in advance.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA buffers switching with SPI and TIMERS via PPI</title><link>https://devzone.nordicsemi.com/thread/528051?ContentTypeID=1</link><pubDate>Wed, 19 Mar 2025 15:22:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bacdfc61-e942-44b7-962e-49ea497397e1</guid><dc:creator>Michal Mrowiec</dc:creator><description>&lt;p&gt;The nRF SDK version is 2.6.1.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>