-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slow read/write speed of microSD card via SPI and FatFS #22906
Comments
The fs_write function gives a nb of bytes to be written, then will the driver (SD card or SPI) convert this nb of bytes into a nb of blocks (based on a usual card block size of 512B). |
A closer look at the low-level write functions shows that the SDHC_WRITE_BLOCK (CMD24 for Single Block) is constantly used, even with large amounts of data. ...
err = sdhc_spi_cmd_r1(data, SDHC_WRITE_BLOCK, addr);
if (err < 0) {
goto error;
}
... Instead of sending CMD24 and looping on the expected size wouldn't it be better to write a handler, which manages the amount of data to be transferred and transmits it as CMD25. |
right, this is explicitly mentioned in the |
I have converted this to an Enhancement, let us know if you plan to work on this @FRASTM |
Hello. I did a pull request to improve the read/write speed on nrf52: #26319. I believe that the same issue affects the other platforms. Would you be able to test the changes and report your results in the PR? Thanks |
|
@EminYagmahan can you please share your full test application which measures the SD write speed. So that I can check if any improvement is possible. |
@FRASTM Thank you. I have just uploaded all the necessary test functions. They are located in the following repository: zephyr_spi_sdcard. It should be mentioned that the calculation of the time in milliseconds does not fully reflect the write/read time. The time for required fat fs operations is also included in the output. |
Testing the write speed on a SD card on nucleo F411 + SD card on SPI (through cishield) With PR #26319 : improving the SPI clock, |
Testing the write speed on a SD card on nucleo F411 + SD card on SPI (through cishield) |
@EminYagmahan can you please check if PR #26757 improves the results of write speed |
@FRASTM Many thanks for the implementation. Enclosed are the measurement results with PR #26757 . Each measurement series was repeated three times and the average was recorded. One MB is written and afterwards read. Since the Multiwrite command is only executed at >2 blocks, there are no differences in writing block sizes 512 Byte and 1024 Byte. The implementation has definitely helped. Since the write rate was almost doubled at quadruple block size. (For completeness I have added the reading rate anyway. Although there is no implementation for the multiread yet, there are improvements. I explain this by the fact that the Transmit function of SPI must be called less often by larger buffers to transfer the same amount of data.) Test setup:
Results:
|
@EminYagmahan "Although there is no implementation for the multiread yet" The |
@lowlander Correct, but this problem has already been addressed and solved in PR #26319. With this PR the maximum clock frequency is now taken from the definition in the Device Tree Layer |
Can this be considered resolved and can it be closed? |
Since PR #26319 had a big impact on performance and that is still open, my thought was to do a final test and close the issue after successful merge of the PR. But this can be closed also now. |
To determine the read and write speed on my SD card, I wrote a test function that writes 1 Megabyte of data to my SD card, then reads it and determines the required time and speed.
According to my measurement results I get the following speeds:
Read: 35 KByte/s
Write: 27 KByte/s
According to ELM CHAN's benchmarking tests, I get similar speeds with my 16GB SD card as he did with W:1 and R:1. According to the API reference from Zephyr, there is no possibility to do a Multi_Block_Write with the high level API. I guess every fs_write function calls a Single_Block_Write (CMD 24) command. How is it efficient to stream the data to the Micro SD card? An "fs_multiwrite(...)" does not exist in the API.
How can I still increase the speed?
Test environment:
Discovery Kit: Disco_L475_IOT
MicroSD Card via SPI at 20 MHz
Benchmarking Results from ELM CHAN:
My test function write x byte on sd card:
The text was updated successfully, but these errors were encountered: