<?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>Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/100045/unable-to-initialize-hot-swap-sd-card-during-run-time</link><description>Hi 
 I have a system which needs to be run for 10days continuously. I have and SD card to log data during this period. 
 I need to verify the SD card data in between, so I send data from Bluetooth to alert my system that i am going to unmount and remove</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 21 Jul 2023 07:09:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/100045/unable-to-initialize-hot-swap-sd-card-during-run-time" /><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/437579?ContentTypeID=1</link><pubDate>Fri, 21 Jul 2023 07:09:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7872f988-135a-4903-8bdb-c22fa9f95ca4</guid><dc:creator>ShuMan</dc:creator><description>&lt;p&gt;A reference for someone facing similar issue, I found a ticket with a workaround here which worked for me:&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/96911/unable-to-remount-sd-card-after-physically-ejecting-without-rebooting"&gt;&amp;nbsp;https://devzone.nordicsemi.com/f/nordic-q-a/96911/unable-to-remount-sd-card-after-physically-ejecting-without-rebooting&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/429343?ContentTypeID=1</link><pubDate>Mon, 05 Jun 2023 13:58:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18224270-0120-4b6b-aa81-496625dbc9a1</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Reshma&lt;/p&gt;
&lt;p&gt;It should be fine using the Zephyr drivers functions to reinit SPIM.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After some&amp;nbsp;more digging I found this thread that seems to report a similar behavior as what you see here. There was a bug where this timeout was always set to 0, but that should have been fixed as of NCS 2.0.0 from what I can tell. Can you double check to see what the timeout is in your spi_context.h file, as that is the only place in the SDK on my end that prints &amp;quot;&lt;em&gt;Timeout waiting for transfer complete&lt;/em&gt;&amp;quot;.&lt;/p&gt;
&lt;p&gt;The timeout value should be 200ms by default I believe, so please make sure it&amp;#39;s not 0.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/428693?ContentTypeID=1</link><pubDate>Thu, 01 Jun 2023 11:04:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6816917-0274-4cf4-905b-343031466f47</guid><dc:creator>Reshma_tomy</dc:creator><description>&lt;p&gt;I tried your solution , but it still fails with the same error&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;[00:01:10.115,509] &amp;lt;inf&amp;gt; sfhl_logs: Mounting FS&lt;br /&gt;[00:01:10.320,892] &amp;lt;err&amp;gt; spi_nrfx_spim: Timeout waiting for transfer complete&lt;br /&gt;[00:01:10.529,174] &amp;lt;err&amp;gt; spi_nrfx_spim: Timeout waiting for transfer complete&lt;br /&gt;[00:01:10.737,365] &amp;lt;err&amp;gt; spi_nrfx_spim: Timeout waiting for transfer complete&lt;br /&gt;[00:01:10.945,587] &amp;lt;err&amp;gt; spi_nrfx_spim: Timeout waiting for transfer complete&lt;br /&gt;[00:01:10.953,704] &amp;lt;err&amp;gt; sd: Failed to read from SDMMC -116&lt;br /&gt;[00:01:10.960,174] &amp;lt;err&amp;gt; sd: Card read failed&lt;br /&gt;[00:01:10.965,423] &amp;lt;err&amp;gt; fs: fs mount error (-5)&lt;br /&gt;[00:01:10.970,916] &amp;lt;inf&amp;gt; sfhl_logs: Mount result -5&lt;br /&gt;[00:01:10.976,409] &amp;lt;inf&amp;gt; sfhl_logs: Error mounting disk.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/428623?ContentTypeID=1</link><pubDate>Thu, 01 Jun 2023 07:46:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:169dc39f-4886-400e-9a87-a494b5ce277e</guid><dc:creator>Reshma_tomy</dc:creator><description>&lt;p&gt;So when I reinitialize it , do I need to give the configurations again and call &lt;strong&gt;nrfx_spim_init()&lt;/strong&gt; function?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/428621?ContentTypeID=1</link><pubDate>Thu, 01 Jun 2023 07:40:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:658a2a36-9e9d-4796-bb00-5324411e1a02</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;It seems like the Zephyr API don&amp;#39;t have a dedicated wrapper around the &lt;strong&gt;nrfx_spim_uninit&lt;/strong&gt;() function, so I think you&amp;#39;ll have to call it directly in order to uninitialize the peripheral, then reinitialize when the SD card is put back in.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/428107?ContentTypeID=1</link><pubDate>Tue, 30 May 2023 09:18:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a15520a-3dbd-4491-bb18-85cdaa06007d</guid><dc:creator>Reshma_tomy</dc:creator><description>&lt;p&gt;I am using only zephyr APIs, my device is SPI master, hence it will be using nrfx_spim. I haven&amp;#39;t used these driver functions directly in my code, as I am using only zephyr device tree APIs&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/428070?ContentTypeID=1</link><pubDate>Tue, 30 May 2023 08:03:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c25eeeab-1487-45cb-b9aa-56c1da1f460e</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;What driver are you using for SPI in your project? In I.E. the nrfx_spim/nrfx_spis drivers in the nRF Connect SDK we have dedicated uninit functions for example. You need to unmount the SD card and uninit the SPI I believe, then reinit and mount the SD card again.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/427979?ContentTypeID=1</link><pubDate>Mon, 29 May 2023 09:21:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb352dbf-6c03-46c5-acb4-36170443d21b</guid><dc:creator>Reshma_tomy</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/simonr"&gt;Simonr&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Do you have any suggestion how to uninit SPI in zephyr?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/427730?ContentTypeID=1</link><pubDate>Fri, 26 May 2023 09:43:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3157639a-cbf3-4d85-b5cc-05ba7f23d000</guid><dc:creator>Reshma_tomy</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I couldn&amp;#39;t find any uninit function in sd.c or any associated c files. Are you suggesting to write a custom uninit function?. Do you have any examples of the same?.&amp;nbsp; &amp;nbsp;I don&amp;#39;t want to uninitialize SPI as I am using the same SPI lines for a pressure sensor.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/427725?ContentTypeID=1</link><pubDate>Fri, 26 May 2023 09:23:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4db95e1d-5ee6-4dc7-a88f-08919b471508</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;So it already finds the SD card initialized. In that case I think you need to call an &amp;quot;uninit&amp;quot; function first, so that the device knows that the SD card has been removed at one point and then can initialize again. You can either do this when the error you see occurs, or uninit the disk if/when the SPI interface isn&amp;#39;t able to communicate with the SD card anymore.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/427221?ContentTypeID=1</link><pubDate>Wed, 24 May 2023 12:12:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:394c4fe3-a1d6-4889-814c-9706ff90f3f6</guid><dc:creator>Reshma_tomy</dc:creator><description>&lt;p&gt;On further debugging, I could find that, it is getting timeout inside this function in sdmmc_subsys.c file.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;em&gt;static int disk_sdmmc_access_init(struct disk_info *disk)&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;{&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; const struct device *dev = disk-&amp;gt;dev;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; const struct sdmmc_config *cfg = dev-&amp;gt;config;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; struct sdmmc_data *data = dev-&amp;gt;data;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; int ret;&lt;/em&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;em&gt;&lt;span style="background-color:#ffff00;"&gt;&amp;nbsp; &amp;nbsp; if (data-&amp;gt;status == SD_OK) {&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&lt;span style="background-color:#ffff00;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Called twice, don&amp;#39;t reinit &lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&lt;span style="background-color:#ffff00;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0;&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&lt;span style="background-color:#ffff00;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; if (!sd_is_card_present(cfg-&amp;gt;host_controller)) {&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return DISK_STATUS_NOMEDIA;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; }&lt;/em&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; ret = sd_init(cfg-&amp;gt;host_controller, &amp;amp;data-&amp;gt;card);&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; if (ret) {&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; data-&amp;gt;status = SD_ERROR;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return ret;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; }&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; data-&amp;gt;status = SD_OK;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;}&lt;/em&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;em&gt;static int disk_sdmmc_access_status(struct disk_info *disk)&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;{&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; const struct device *dev = disk-&amp;gt;dev;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; const struct sdmmc_config *cfg = dev-&amp;gt;config;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; struct sdmmc_data *data = dev-&amp;gt;data;&lt;/em&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; if (!sd_is_card_present(cfg-&amp;gt;host_controller)) {&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return DISK_STATUS_NOMEDIA;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; }&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; if (data-&amp;gt;status == SD_OK) {&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return DISK_STATUS_OK;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; } else {&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return DISK_STATUS_UNINIT;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; }&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;}&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;The code returns at highlighted part when we try to mount again .How can reinitialize sd card again?.&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/427218?ContentTypeID=1</link><pubDate>Wed, 24 May 2023 12:03:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02c8d75b-39d0-4305-9491-35120bb5a24a</guid><dc:creator>Reshma_tomy</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;The SDK toolchain version is V2.2.0.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Below are the sd card logs I get on fs_mount() after hot swap:&lt;/p&gt;
&lt;p&gt;[00:00:32.266,052] &amp;lt;err&amp;gt; sd: Failed to read from SDMMC -116&lt;br /&gt;[00:00:32.272,583] &amp;lt;err&amp;gt; sd: Card read failed&lt;br /&gt;[00:00:32.277,893] &amp;lt;err&amp;gt; fs: fs mount error (-5).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The reader I am using is an sd card breakout board with spi interface. It doesn&amp;#39;t have any switch to indicate sd card is inserted.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to initialize / hot swap sd card during run time</title><link>https://devzone.nordicsemi.com/thread/427201?ContentTypeID=1</link><pubDate>Wed, 24 May 2023 11:29:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a695f2b3-e540-4230-b6c4-d8cadb27857c</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Does the fs_mount() fail after this hot swap as well, or does it mount correctly, but fail to read properly once mounted? Do you have a log so we can see exactly where this error is triggered? And what SDK version are you using for development exactly?&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not entirely certain on what is causing this error, but have a few theories as to what could cause this. It might be that you need to reinitialize the filesystem after the SD card is removed and put back in. A reason for you needing to reinit is that the address range isn&amp;#39;t reset or updated when you hot swap the SD card during runtime for example.&lt;/p&gt;
&lt;p&gt;Also, what kind of SD card reader are you using? Does it have a physical &amp;quot;switch&amp;quot; that lets you know if a SD card is inserted and does it report whether a card is mounted to the nRF SoC, or is the reader agnostic to whether a card is inserted?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>