<?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 writing speed issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/69544/sd-card-writing-speed-issue</link><description>Hi, 
 I am new to nrf9160 and zephyr. I was using the SD card and a breakout board on SPI bus to write the raw data coming from the PDM interface on nrf9160 Feather. Before that I want to do a SD write test to see how the speed is, so I wrote a simple</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Apr 2021 03:04:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/69544/sd-card-writing-speed-issue" /><item><title>RE: SD card writing speed issue</title><link>https://devzone.nordicsemi.com/thread/307348?ContentTypeID=1</link><pubDate>Thu, 29 Apr 2021 03:04:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:807bb007-05b3-4a3c-9de2-76d0ae3b8e60</guid><dc:creator>liteyear</dc:creator><description>&lt;p&gt;I hit this obstacle recently too. SD Card reads capped at about 27kB/s. My my, what a mission to get to the bottom of it. After a long battle, the issue is now resolved for me. I ended up using&amp;nbsp;a few&amp;nbsp;fixes that&amp;nbsp;have&amp;nbsp;been applied to the Zephyr upstream project, and back-porting them to the now very out of date nRF Connect SDK downstream project. I&amp;#39;ve summarised the changes in these three diffs:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/sdhc_2D00_speed_2D00_fix.patch"&gt;devzone.nordicsemi.com/.../sdhc_2D00_speed_2D00_fix.patch&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/spi_2D00_devicetree_2D00_fix_2D00_part1.patch"&gt;devzone.nordicsemi.com/.../spi_2D00_devicetree_2D00_fix_2D00_part1.patch&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/spi_2D00_devicetree_2D00_fix_2D00_part2.patch"&gt;devzone.nordicsemi.com/.../spi_2D00_devicetree_2D00_fix_2D00_part2.patch&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;My next issue is that SD Card reading disrupts I2S comms... and so the saga continues.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD card writing speed issue</title><link>https://devzone.nordicsemi.com/thread/287327?ContentTypeID=1</link><pubDate>Mon, 04 Jan 2021 17:21:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ddde8759-7061-4586-8114-421fe0c5f12d</guid><dc:creator>Z.Hong</dc:creator><description>&lt;p&gt;Thank you so much for the help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD card writing speed issue</title><link>https://devzone.nordicsemi.com/thread/287204?ContentTypeID=1</link><pubDate>Mon, 04 Jan 2021 11:44:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32125d57-7365-4319-982d-af5cfbf1857e</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Z.Hong"]From my observation, the only way that the speed changed is changing the &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/subsys/disk/disk_access_spi_sdhc.c#L19"&gt;SDHC_SPI_INITIAL_SPEED&lt;/a&gt; to a different value, which is a hard coding define value. Additionally, this is the initial value, the speed should change to another value (&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/subsys/disk/disk_access_spi_sdhc.c#L21"&gt;SDHC_SPI_SPEED&lt;/a&gt;) after &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/subsys/disk/disk_access_spi_sdhc.c#L642"&gt;initialization&amp;nbsp;here&lt;/a&gt;, but it doesn&amp;#39;t.&amp;nbsp;&amp;nbsp;[/quote][quote user="Z.Hong"]- What is the correct way to change/define the&amp;nbsp;SPI frequency in my case?[/quote][quote user="Z.Hong"]- Why the hard coding value SDHC_SPI_SPEED doesn&amp;#39;t affect the actual read/write speed?[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As the frequency in the SDHC library is hard-coded, a change to the zephyr project is needed to allow other frequencies at initial speed and &amp;quot;normal speed&amp;quot;.&lt;/p&gt;
&lt;p&gt;By looking at the driver port, spi_nrfx_spim.c, it looks like a weakness there (or a intentional implementation),&amp;nbsp;where you can only configure the device once:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/drivers/spi/spi_nrfx_spim.c#L112-L114"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/master/drivers/spi/spi_nrfx_spim.c#L112-L114&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I would recommend that you either remove this check, or set the SDHC_SPI_INITIAL_SPEED equal to SDHC_SPI_SPEED, ie. up to 8 MHz.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD card writing speed issue</title><link>https://devzone.nordicsemi.com/thread/286135?ContentTypeID=1</link><pubDate>Mon, 21 Dec 2020 17:50:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b460e0c-078e-42a8-bc13-904fded5da50</guid><dc:creator>Z.Hong</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I understand what you mentioned in the answer. However, I just wonder why changing the SPI speed doesn&amp;#39;t work, at least different frequency(or speed) will give you a different frequency in the scope, not matter what the value is. Or maybe I defined it in the wrong way.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;From my observation, the only way that the speed changed is changing the &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/subsys/disk/disk_access_spi_sdhc.c#L19"&gt;SDHC_SPI_INITIAL_SPEED&lt;/a&gt; to a different value, which is a hard coding define value. Additionally, this is the initial value, the speed should change to another value (&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/subsys/disk/disk_access_spi_sdhc.c#L21"&gt;SDHC_SPI_SPEED&lt;/a&gt;) after &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/subsys/disk/disk_access_spi_sdhc.c#L642"&gt;initialization&amp;nbsp;here&lt;/a&gt;, but it doesn&amp;#39;t.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So my question is:&lt;/p&gt;
&lt;p&gt;- What is the correct way to change/define the&amp;nbsp;SPI frequency in my case?&lt;/p&gt;
&lt;p&gt;- Why the hard coding value SDHC_SPI_SPEED doesn&amp;#39;t affect the actual read/write speed?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;My apology if my expression makes you confused.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Zirun&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD card writing speed issue</title><link>https://devzone.nordicsemi.com/thread/286068?ContentTypeID=1</link><pubDate>Mon, 21 Dec 2020 14:07:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f59a162-824e-473b-822e-8dadf1a6d683</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The speeds you&amp;#39;re getting (just below 30kB/s) seems to correspond with the numbers provided in this zephyr PR:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/pull/26319"&gt;https://github.com/zephyrproject-rtos/zephyr/pull/26319&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It looks like you are writing at 4MHz SPI speed, given the speed results you&amp;#39;re seeing. As you can see from the comparison with 250k/4M, its not a linear speed difference, which indicates that it takes quite some processing to conform to the specific filesystem.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD card writing speed issue</title><link>https://devzone.nordicsemi.com/thread/285707?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 17:29:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7d7e332-84b4-4b7f-8c00-3f0b618d2b82</guid><dc:creator>Z.Hong</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I do probe the CLK line when transmitting the file, and it doesn&amp;#39;t change to 4MHz. It remains at 250KHz for some reason.&lt;/p&gt;
&lt;p&gt;So, I manually change the &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/subsys/disk/disk_access_spi_sdhc.c#L19"&gt;SDHC_SPI_INITIAL_SPEED&lt;/a&gt;&amp;nbsp;to 4MHZ, not sure if it is correct to do so, but it initially at 4MHZ and remains at 4MHz when doing file writing. I guess it doesn&amp;#39;t change the speed &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/subsys/disk/disk_access_spi_sdhc.c#L642"&gt;here &lt;/a&gt;when it finish initialization. Also I notice the speed is not changed/updated to new value in disk_access_spi_sdhc.c, maybe it is defined somewhere?&lt;/p&gt;
&lt;p&gt;Zirun&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD card writing speed issue</title><link>https://devzone.nordicsemi.com/thread/285544?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 09:14:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2e3cc7c-1395-46c4-bbec-0f94133c8ef7</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My apologies, the spi_nrfx_spim port reconfigures the SPI frequency after the application calls the first spi_transceive function, as explained in the comment here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.4.0-ncs2/drivers/spi/spi_nrfx_spim.c#L309-L311"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v2.4.0-ncs2/drivers/spi/spi_nrfx_spim.c#L309-L311&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Z.Hong"]&amp;nbsp; &amp;nbsp;Also I probe the CLK line and find that it is at 250KHz.[/quote]
&lt;p&gt;It looks like the initial communication is at 250 kHz, and it switches to 4M after successful init:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/subsys/disk/disk_access_spi_sdhc.c#L18-L21"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/master/subsys/disk/disk_access_spi_sdhc.c#L18-L21&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Did you scope the communication when transferring a file?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD card writing speed issue</title><link>https://devzone.nordicsemi.com/thread/285462?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2020 21:34:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dde9fa11-15cd-4f43-a9db-dab3dcafbe2f</guid><dc:creator>Z.Hong</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for your reply.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The driver sets the frequency configuration to 4MHz:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;- So can I set it a different value by setting&amp;nbsp;spi-max-frequency in the overlay file?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;Or maybe, in another approach, setting&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;spi_nrfx_config.frequency =&amp;#160;NRF_SPIM_FREQ_8M&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;You can try to change this to a higher value, lets say 64, and see if this affects the transfer speed &amp;amp;&amp;nbsp;Could you also try to store a larger file to see if this speed is the same then as well?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;- I try in both approach, the result is still the same, even worse when I store a larger file with a speed ~ 24KB/sec.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;Also I probe the CLK line and find that it is at 250KHz.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Zirun&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SD card writing speed issue</title><link>https://devzone.nordicsemi.com/thread/285287?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2020 11:26:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:237273d2-1f4a-4db5-a7b4-44608a9ba0e0</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The driver sets the frequency configuration to 4MHz:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.4.0-ncs2/drivers/spi/spi_nrfx_spim.c#L431"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v2.4.0-ncs2/drivers/spi/spi_nrfx_spim.c#L431&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The DMA length is 12 bit, meaning that you have 2047 bytes max per transaction:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf9160/spim.html?cp=2_0_0_5_12_5_27#register.RXD.MAXCNT"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf9160/spim.html?cp=2_0_0_5_12_5_27#register.RXD.MAXCNT&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The configuration &amp;quot;CONFIG_SPI_NRFX_RAM_BUFFER_SIZE=8&amp;quot; gives a chunk size of 8 bytes, as the DMA can only transfer from a RAM buffer. You can try to change this to a higher value, lets say 64, and see if this affects the transfer speed. That being said; you&amp;#39;re using a filesystem on your SDHC card, which requires handling as well. Changing the SPI speed can reduce the physical delay between the nRF and SD-card, but you still have to conform to the fatfs filesystem.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you also try to store a larger file to see if this speed is the same then as well?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>