New SdFat library (with and without DMA)

Please do not post requests
Post Reply
victor_pv
Posts: 1745
Joined: Mon Apr 27, 2015 12:12 pm

New SdFat library (with and without DMA)

Post by victor_pv » Mon Apr 27, 2015 7:11 pm

***Latest Update 04/10/2017***
The code in the official repo from Bill Greyman has now the support for the libmaple based core (stm32duino) integrated in it. So no need to download it from my repo any more.

Official SD-Fat library repository:
https://github.com/greiman/SdFat

===============================================================

UPDATE TO THIS WARNING. SHOULD BE SOLVED IN THE LATEST REPO. If you have problems using pin 7 for CS, make sure you are in sync with Roger's master STM32Duino repo.
WARNING!!
I was just testing an SD card with one of the sketches, and noticed that you CAN NOT use pin 7 in the maple mini (the stm32f103 native SS pin for spi1) for CS. I have not looked at how the library manages CS and how that pin is setup in out SPI library, but I guess there is a conflict in the pin mode. So the work around at the moment is to use a different pin for CS.
- Updated 06/04/2015-

- New update on 07/10/2015 - Small code changes to the library and specially to the SPI library, which should go to Roger's master repo soon.

So as I posted before in the forum, I modified the latest SdFat library from Greiman.
I had submitted him changes for a previous version, but had issues. Now all the issues seem to be corrected in my latest version.
It is available here:
https://github.com/victorpv/SdFat

It seems to work fine for me for the few examples I have tested.
If you want the best performance for large transfers, can use DMA mode.

DMA would be advantageous for large transfers, but doesn't help at all, and may even have a penalty, if you are just reading a few bytes to a log and things like that. Now if you transfer images or mp3 files from the sdcard, DMA can improve performance greatly, anything involving big blocks at once.

DMA can be enabled or disabled editing SdSpiSTM32F1.cpp, there is one #define line:
/** Use STM32 DMAC if nonzero */
#define USE_STM32F1_DMAC 1

Comment that line or change the 1 for 0, and DMA transfers will not be used.

RECOMMENDATIONS FOR SPEED:
Use DMA mode.
Set a bigger buffer, ideally 4KB

Read speeds without DMA, 4KB buffer:
read speed and latency

Code: Select all

speed,max,min,avg
KB/Sec,usec,usec,usec
676.29,8189,5927,6056
676.38,7467,5927,6054
676.38,7468,5927,6054
676.38,7469,5926,6054
676.38,7472,5926,6054
Same card, same settings with DMA:

Code: Select all

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
1793.65,4362,2154,2282
1794.30,3227,2155,2281
1794.30,3224,2157,2281
1793.65,3225,2155,2282
1793.65,3224,2154,2282
-KNOWN PROBLEMS:
  • -Some cards do not work fine with the default speed. Always give the speed parameter to the driver, such as:
    sd.begin(SD_ChipSelectPin, SPI_CLOCK_DIV2);
    -Some sdcard adapters work better than others (LC Soft one seems to work for everyone).
    -CS pin. Besides the possible issue with the hardware SS pin (7 in the maple mini) some people had trouble with others. If you have trouble detecting the card, change to a different pin in a different port. Pin 8 works for me. Pins 1 and 2 have worked for other people.
    -SDCards. Not all sdcards work fine. The SPI mode is not the normal one SdCards use, they use SDIO, the library-card compatibility may not be perfect. Try a different card.
    -Level converters. Sdcards work at 3.3V, STM32F1 works at 3.3V. Level converters are not needed and may affect reliability. Avoid them if possible.
    -Voltage regulators. Some cards include a 5 to 3.3V voltage regulator. Normally that's a 1117 regulator with a fairly high dropout voltage. If you power the card with 3.3 you don't need a regulator. If you are having problems avoid the regulator. DO NOT POWER WITH 5V. Neither sdcards or STM32F1 can work at 5V and will most likely get damaged. If you modify a reader to avoid the regulator, be careful to not power it with an Arduino 5V later.
    -SdCard speed. Most cards work fine at DIV2 spi speed. If you have trouble, reduce the speed to DIV4 or even lower. At DIV4 there is very little performance impact because the SPI port is still faster than most cards.
Last edited by victor_pv on Mon Apr 10, 2017 8:49 pm, edited 11 times in total.

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: New SdFat library (with and without DMA)

Post by madias » Mon Apr 27, 2015 8:16 pm

Dear Victor,
does it matter, if you post some examples written by you? It would be easier for us...
thanks!

victor_pv
Posts: 1745
Joined: Mon Apr 27, 2015 12:12 pm

Re: New SdFat library (with and without DMA)

Post by victor_pv » Tue Apr 28, 2015 2:35 am

Madias, I have not written any example for that library, basically because I have not use for it at the moment.
I ported it mostly just to test the sdcard connector in the back of my display, in case I needed it in the future.

From the examples included in the library I have tested:
ReadWriteSdfat
Bench
Sdinfo
Printbenchmark

The only thing I may use it for, will be to hold small images for the display, but have not tested it for that yet.

skyng22003
Posts: 9
Joined: Wed Apr 29, 2015 9:49 pm

Re: New SdFat library (with and without DMA)

Post by skyng22003 » Thu Apr 30, 2015 7:10 pm

Hi Victor,

I updated the SPI library (with DMA off) to the one you posted and the new SdFat library you posted cannot detect my card?

Says SD card initialisation failed with the quick start example, even though I've tried different CS pin values.

However, It works fine with the SD card library bundled with the Arduino IDE, I can see the text file written to the card, any ideas?

Using STM32F103 RET6

Thanks,
Sky

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: New SdFat library (with and without DMA)

Post by madias » Thu Apr 30, 2015 7:32 pm

skyng/victor: is the SPI clock div still at 128? This was my problem with the library and nothing worked.

skyng22003
Posts: 9
Joined: Wed Apr 29, 2015 9:49 pm

Re: New SdFat library (with and without DMA)

Post by skyng22003 » Thu Apr 30, 2015 7:44 pm

madias: Is that in the SPI library or in the SdFat library?

victor_pv
Posts: 1745
Joined: Mon Apr 27, 2015 12:12 pm

Re: New SdFat library (with and without DMA)

Post by victor_pv » Fri May 01, 2015 3:35 pm

Skyng I thought I had corrected the issues with the DIV values in the latest version in my repo, but perhaps there is still an issue with it.
in the quick start example the SPI speed is set on this line:
const uint8_t spiSpeed = SPI_HALF_SPEED;

Change that to:
const uint8_t spiSpeed = SPI_CLOCK_DIV4;

Make sure you set the SPI to DIV2 to DIV8, they work pretty good for most sdcards.
Some slower cards may have problems with the fastest speed, but DIV4 pr DIV8 should for for most.

Let me know if you still have problems.

Phono
Posts: 92
Joined: Tue May 05, 2015 6:08 am
Location: Ermont, France

Re: New SdFat library (with and without DMA)

Post by Phono » Fri May 08, 2015 4:21 pm

I have tested the library from the repository which link is in an earlier post.
I have failed for SPI.h was missing.
I haved included SPI, and then I get the following compile error :

In file included from sketch_may08a.ino:11:0:
C:\Users\Jean-Marc\Documents\Arduino\libraries\SdFat/SdVolume.h:25:2: error: #error SdVolume is deperacated. Remove this line to continue using this class.
#error SdVolume is deperacated. Remove this line to continue using this class.

What should I do?

User avatar
mrburnette
Posts: 1884
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: New SdFat library (with and without DMA)

Post by mrburnette » Sat May 09, 2015 5:57 pm

Phono wrote:I have tested the library from the repository which link is in an earlier post.
I have failed for SPI.h was missing.
I haved included SPI, and then I get the following compile error :

In file included from sketch_may08a.ino:11:0:
C:\Users\Jean-Marc\Documents\Arduino\libraries\SdFat/SdVolume.h:25:2: error: #error SdVolume is deperacated. Remove this line to continue using this class.
#error SdVolume is deperacated. Remove this line to continue using this class.

What should I do?

Now, look closely at this line:
C:\Users\Jean-Marc\Documents\Arduino\libraries\SdFat/SdVolume.h

See the problem? Hint, wrong library location. You must link to the STM32 library under the hardware directory.

Ray

Phono
Posts: 92
Joined: Tue May 05, 2015 6:08 am
Location: Ermont, France

Re: New SdFat library (with and without DMA)

Post by Phono » Mon May 11, 2015 9:01 pm

Ok, but this came by default. How can I make by default the compiler seek the libraries in the hardware section?

Post Reply