<?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>SD Card Issues after updating to SDK 2.1</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93470/sd-card-issues-after-updating-to-sdk-2-1</link><description>We have updated our firmware runnung on an nRF9160 from SDK 1.9 to SDK 2.1 using the now deprecated SPM (We will upgrade to TFM soon). 
 When booting our firmware, we initialize and mount our SD Card using FAT filesystem. The function disk_access_get_di</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 23 Nov 2022 15:28:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93470/sd-card-issues-after-updating-to-sdk-2-1" /><item><title>RE: SD Card Issues after updating to SDK 2.1</title><link>https://devzone.nordicsemi.com/thread/397238?ContentTypeID=1</link><pubDate>Wed, 23 Nov 2022 15:28:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbc1694e-aeaa-43ec-a38b-120996a36b0f</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;The issue has already been fixed and is now part of the main branch: &lt;a href="https://github.com/nrfconnect/sdk-zephyr/commit/2c2b8c342247ff767ee369169a74dbcf09b5edc6"&gt;https://github.com/nrfconnect/sdk-zephyr/commit/2c2b8c342247ff767ee369169a74dbcf09b5edc6&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure if it has made it into the next NCS tagged release, as it was merged after the commit pointed to by the development branch.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD Card Issues after updating to SDK 2.1</title><link>https://devzone.nordicsemi.com/thread/395827?ContentTypeID=1</link><pubDate>Tue, 15 Nov 2022 14:46:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0cdf0e12-ef96-4c3e-a065-5236d8ed07ed</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Hi, no problem! Not sure if there are any other ways of knowing if it has been fixed than checking the tagged release, when a new release is notified. Anyways, I will let you know through this ticket.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Stian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD Card Issues after updating to SDK 2.1</title><link>https://devzone.nordicsemi.com/thread/395468?ContentTypeID=1</link><pubDate>Mon, 14 Nov 2022 07:10:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:612856cd-b7ee-4df8-9dc9-ab676305d7d0</guid><dc:creator>maluJ</dc:creator><description>&lt;p&gt;Thanks for this elaborative answer Stian!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;We already adapted our application to run the sd card initialization at APPLICATION level, which work fine.&lt;/p&gt;
&lt;p&gt;But very helpful to understand that POST_KERNEL &amp;gt; 90 should be possible too.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regarding &amp;#39;fs_close()&amp;#39; --&amp;gt; We implemented the workaround on our own sdk-zephyr fork as you suggested and it works fine. Could you let me know once the fix&amp;nbsp;is backported to the NRF SDK zephyr fork&amp;nbsp;or whats the best way to know when it is fixed?&lt;/p&gt;
&lt;p&gt;Thanks alot for the help again.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD Card Issues after updating to SDK 2.1</title><link>https://devzone.nordicsemi.com/thread/395422?ContentTypeID=1</link><pubDate>Sat, 12 Nov 2022 15:32:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37d9b70a-8206-4a9b-9f15-e3d03e967429</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Hi Manuel,&lt;/p&gt;
&lt;p&gt;Looks like the problem with using POST_KERNEL initialization level is the&lt;code&gt; fatfs_init()&lt;/code&gt; in subsys/fs/fat_fs.c, which is initialized at APPLICATION priority 40: &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/86893246053c50d34618f09ec6722cae8ba19472/subsys/fs/fat_fs.c#L490"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/86893246053c50d34618f09ec6722cae8ba19472/subsys/fs/fat_fs.c#L490&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Not exactly sure what your application looks like, but if we assume that it is a copy of the samples/subsys/fs/fat_fs, and that you moved the SD card and FAT FS initialization steps out of &lt;code&gt;main()&lt;/code&gt; into a function&lt;code&gt;&amp;nbsp;initSdCard()&lt;/code&gt; which is registered during boot with &lt;code&gt;SYS_INIT(initSdCard, POST_KERNEL, CONFIG_SDHC_INIT_PRIORITY);&lt;/code&gt; then the init steps should work all the way until &lt;code&gt;fs_mount()&lt;/code&gt; because the fat_fs init has not started yet.&lt;/p&gt;
&lt;p&gt;The relevant drivers are initialized in this order:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/86893246053c50d34618f09ec6722cae8ba19472/drivers/spi/spi_nrfx_spim.c#L606"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/86893246053c50d34618f09ec6722cae8ba19472/drivers/spi/spi_nrfx_spim.c#L606&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/86893246053c50d34618f09ec6722cae8ba19472/drivers/sdhc/sdhc_spi.c#L756"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/86893246053c50d34618f09ec6722cae8ba19472/drivers/sdhc/sdhc_spi.c#L756&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/86893246053c50d34618f09ec6722cae8ba19472/drivers/disk/sdmmc_subsys.c#L137"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/86893246053c50d34618f09ec6722cae8ba19472/drivers/disk/sdmmc_subsys.c#L137&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Last one at POST_KERNEL 90. It could be a possibility to initialize FATFS POST_KERNEL &amp;gt; 90, and then your initSdCard funciton at POST_KERNEL after FATFS, but I&amp;#39;m not sure if this will brake compatibility with other modules. Anyways, I tested it here and it seems to work fine with at least the samples/subsys/fs/fat_fs sample. Not sure if this is concidered a bug or not, but I will report it internally.&lt;/p&gt;
&lt;p&gt;Regarding the fs_close() issue, it looks to me like an issue with how the filesystem synchronization is implemented in the FATFS module, which checks if there is&lt;a href="https://github.com/zephyrproject-rtos/fatfs/blob/a30531af3a95a9a3ea7d771ea8a578ebfed45514/ff.c#L1100"&gt; no pending write&lt;/a&gt;. It will return FR_DISK_ERR as long as the return error is not 0. The disk_ioctl call, however, &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/86893246053c50d34618f09ec6722cae8ba19472/include/zephyr/drivers/sdhc.h#L395"&gt;returns -ENOSYS (not implemented)&lt;/a&gt;. I believe this is because this feature is not &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/86893246053c50d34618f09ec6722cae8ba19472/drivers/sdhc/sdhc_spi.c#L729"&gt;relevant when using SD card with SPI interface&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is of course a bug, and I have reported it to the SDK team. A temporary workaround could be to just comment out the check in ff.c that I linked to above. Or let z_impl_sdhc_card_busy return 0 instead of -ENOSYS.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Stian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD Card Issues after updating to SDK 2.1</title><link>https://devzone.nordicsemi.com/thread/394454?ContentTypeID=1</link><pubDate>Mon, 07 Nov 2022 13:55:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bac37c29-9778-4ad5-8c64-cba6ff603763</guid><dc:creator>maluJ</dc:creator><description>&lt;p&gt;Hi Stian&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Once you handled this particular problem, could you also look into the following issue:&lt;/p&gt;
&lt;p&gt;When doing SD Card Initialization whilst in initialization level &amp;#39;APPLICATION&amp;#39;&amp;nbsp; we can mount the SD card successfully.&amp;nbsp;&lt;br /&gt;I can Open, read and close files successfully on my SD Card.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;However, when i open, WRITE and close file is get a &amp;#39;fs: file close error (-5)&amp;#39; error.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Debugging this I&amp;nbsp;see that the failure comes from a timeout in sdmmc_wait_ready, there i see that the card_busy ptr from sdhc_driver_api is NULL, hence the failure.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The screenshot should show everthing that is relevant:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1667829325673v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Writing the data actually WORKS,&amp;nbsp;(i see Hello World in the file), but the system is blocked 10 seconds, as we&amp;nbsp;k_busy_wait 10 seconds in&amp;nbsp;&amp;nbsp;&lt;span&gt;sdmmc_wait_ready.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I do base my code on&amp;nbsp;&lt;a id="" href="https://github.com/nrfconnect/sdk-zephyr/tree/v3.1.99-ncs1/samples/subsys/fs/fat_fs"&gt;https://github.com/nrfconnect/sdk-zephyr/tree/v3.1.99-ncs1/samples/subsys/fs/fat_fs&lt;/a&gt;&amp;nbsp;...&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD Card Issues after updating to SDK 2.1</title><link>https://devzone.nordicsemi.com/thread/394021?ContentTypeID=1</link><pubDate>Thu, 03 Nov 2022 21:43:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:986e91e0-1be2-4c0f-8c28-e7d20a994a61</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Hi Manuel,&lt;/p&gt;
&lt;p&gt;Just want to let you know that I am working on your case, and will get back to you tomorrow.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Stian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>