<?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>FATFS/SD Card Write Stuck in wait_func when called from app_timer handler</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/46133/fatfs-sd-card-write-stuck-in-wait_func-when-called-from-app_timer-handler</link><description>I&amp;#39;m developing an application on an nRF52832 revAA that logs data coming from the app_uart module. It logs this data to an SD card using the fatfs library; the code is more-or-less exactly the same as the fatfs example in the SDK v15.2. The issue is,</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 12 Apr 2019 20:27:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/46133/fatfs-sd-card-write-stuck-in-wait_func-when-called-from-app_timer-handler" /><item><title>RE: FATFS/SD Card Write Stuck in wait_func when called from app_timer handler</title><link>https://devzone.nordicsemi.com/thread/181912?ContentTypeID=1</link><pubDate>Fri, 12 Apr 2019 20:27:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66b9062a-8218-4c62-92aa-f11276cc6c50</guid><dc:creator>fierst</dc:creator><description>&lt;p&gt;That was definitely the issue. I enabled app_scheduler for the application (including in sdk_config.h for the app_timer instance) so that the actual write would happen in the main context instead of the interrupt and it seems to be working just fine now. Thanks for the help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FATFS/SD Card Write Stuck in wait_func when called from app_timer handler</title><link>https://devzone.nordicsemi.com/thread/181906?ContentTypeID=1</link><pubDate>Fri, 12 Apr 2019 18:41:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:790820c5-89bf-47c8-97f3-cc6ad0b9a767</guid><dc:creator>wpaul</dc:creator><description>&lt;p&gt;If I understand your design correctly, I don&amp;#39;t think you can do things the way you&amp;#39;re trying to do them.&lt;/p&gt;
&lt;p&gt;If the timer callback works the way I think it does, then it&amp;#39;s essentially an interrupt service routine: when the timer interval expires, you get an interrupt, and you can use that to trigger other things. But there is a limit to what you can reasonably do in an interrupt handler.&lt;/p&gt;
&lt;p&gt;When you issue an f_write(), the underlying code will need to perform SPI transactions and it has to wait for the transactions to complete. You can detect completion either by waiting for an interrupt from the SPI controller or polling a status register. The problem is, these are both basically &amp;quot;blocking&amp;quot; operations, and you don&amp;#39;t want to perform a blocking operation inside an interrupt service routine. ISRs should be short and should complete in a well bounded amount of time.&lt;/p&gt;
&lt;p&gt;I think what you may need to do is to have the timer handler update a variable that indicates the timer has expired. You need to find a way to have your idle_state_handler() function wake up due to the interrupt and test the variable, and if it indicates the timer has fired, then check for data and write it to the SD card from the application context instead of from interrupt context.&lt;/p&gt;
&lt;p&gt;-Bill&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>