ErichStyger / mcuoneclipse

McuOnEclipse Processor Expert components and example projects
Other
731 stars 1.29k forks source link

FATFsMemSDHC throughput issue #14

Closed dfukumori closed 9 years ago

dfukumori commented 10 years ago

Hi Erich,

http://mcuoneclipse.com/2012/07/30/fatfs-with-kinetis/#comment-16199

In the above comment, you mentioned that you weren't seeing any performance benefits using more data pins during SDHC communication. I believe this is due to the way that FATFsMemSDHC implements the disk_read and disk_write functions. Both of these functions use the following block of code to handle transferring multiple blocks to/from the SD card:

do { if (SD_TransferBlock(&SD, FALSE, sector_FATM1_BLOCK_SIZE, (uint8t)buff, 1)) { break; } sector++; buff += FATM1_BLOCK_SIZE; } while(--count);

Rather than performing one multi-block I/O operation, the component performs a number of single-block I/O operations. This incurs the SD card's read (or write) access time for each block transferred. A multi-block transfer would only incur this cost once.

I tested using 4-pin communication at 24MHz. A single 512-byte block read takes about 660us -- about 40us for the data transfer and 620us for the card-specific read access time. With the original disk readfunction, reading n blocks takes n(620us + 40us). I made some minor changes to disk_read and SD_TransferBlock so that they attempt to make a single multi-block read. Using the modified function, I saw times much closer to the ideal value of 620us + n_40us for n blocks.

ErichStyger commented 10 years ago

Hi dfukumori, that indeed could be the reason for the transfer time needed. I admit that most of my projects are not using SDHC (because the micrcontroller does not have it), and is using SPI instead, and performance was ok for me. I'm happy to incorporate and test your change if you can share it? You simply can make a pull request on GitHub.

hanwannian commented 9 years ago

if you use bigger block sizes and larger transfers you’ll get speed increases…. 10MB or 100MB files will run faster.

hanwannian commented 9 years ago

if you use bigger block sizes and larger transfers you’ll get speed increases…. 10MB or 100MB files will run faster.

hanwannian commented 9 years ago

I use the component more in SPI mode, and not much with SDHC. However, sometimes I have seen strange issues with SDHC, which appeard and then disappeared. I was never able to track it down :-(. looks like what you report could be the issue?

ErichStyger commented 9 years ago

As for SDHC, I even believe this could be some kind of silicon bug. I had sometimes issues too, not working it properly, but never found out why.