Spark Logic

New SdFat library (with and without DMA)

***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 MiniMaple MiniОтладочные и вычислительные платы…8MHz petertumler Thu Sep 24, 2015 10:58 am Hi, I’m trying to underclock a STM32F103 ( Maple Mini ) to 48MHz (for energy efficiency reasons). According to the datasheet .. The full…Underclocking STM32F103 to 48MHz (the STM32F103STM32F103Микроконтроллеры и процессоры…19.html . ag123 Sat Apr 28, 2018 5:54 pm come to think of it blue pill / maple mini ( stm32f103 ) is an *ideal* keyboard controller, the scanning can be done with assistance of sh…[SOLVED] generic blue pill clone as USB keyboard 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 STM32STM32Микроконтроллеры и процессоры…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…[STM32GENERIC] F429i Discovery DMAC if nonzero */
#define USE_STM32F1STM32F1Микроконтроллеры и процессоры…w I am not able to compile. Error message: “C:\arduino-1.6.12\hardware\Arduino_STM32\ STM32F1 \cores\maple/boards.h:39:25: fatal error: board/board.h: No such file or directory” I…Value Line Discovery Board _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

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

Replies20

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!

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.

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 STM32F103STM32F103Микроконтроллеры и процессоры…19.html . ag123 Sat Apr 28, 2018 5:54 pm come to think of it blue pill / maple mini ( stm32f103 ) is an *ideal* keyboard controller, the scanning can be done with assistance of sh…[SOLVED] generic blue pill clone as USB keyboard RET6

Thanks,
Sky

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.

Thu Apr 30, 2015 7:44 pm

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

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.

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?

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?

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?

Tue May 12, 2015 11:34 am

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

Thu Jun 25, 2015 8:57 pm

Anyone who had luck with this library (Maple MiniMaple MiniОтладочные и вычислительные платы…8MHz petertumler Thu Sep 24, 2015 10:58 am Hi, I’m trying to underclock a STM32F103 ( Maple Mini ) to 48MHz (for energy efficiency reasons). According to the datasheet .. The full…Underclocking STM32F103 to 48MHz )?
I gave it another try and there is no chance to get it working, equal which settings I use (different SS pin (1,9,8, NOT 7..), different spi speeds, dma on/off…..) I always got in the quicktest example
SD initialization failed.
Do not reformat the card!
Is the card correctly inserted?
Is chipSelect set to the correct value?
Does another SPI device need to be disabled?
Is there a wiring/soldering problem?
errorCode: 0x1, errorData: 0x0

Thu Jun 25, 2015 9:15 pm

Matthias

Last time i downloaded it, about 2 weeks ago, SDFat would not even compile.

i think Victor send a Pull Request to the author, which only worked with the modified code that victor has on his machine.

I tried downloading Victors version from GitHub, but that did not work either ;-(

So I am currently using the old lib. The old lib seems mainly ok, but i do occasionally get a glitch when trying to play MP3 files from SD to VS1053VS1053Аналоговые, логические и силовые компоненты…inly ok, but i do occasionally get a glitch when trying to play MP3 files from SD to VS1053 . But i have not had time to find the cause, because sometimes it can run for many hour…New SdFat library (with and without DMA) .
But i have not had time to find the cause, because sometimes it can run for many hours without a problem

Thu Jun 25, 2015 9:33 pm

RogerClark wrote:Matthias

Last time i downloaded it, about 2 weeks ago, SDFat would not even compile.

i think Victor send a Pull Request to the author, which only worked with the modified code that victor has on his machine.

I tried downloading Victors version from GitHub, but that did not work either ;-(

So I am currently using the old lib. The old lib seems mainly ok, but i do occasionally get a glitch when trying to play MP3 files from SD to VS1053VS1053Аналоговые, логические и силовые компоненты…inly ok, but i do occasionally get a glitch when trying to play MP3 files from SD to VS1053 . But i have not had time to find the cause, because sometimes it can run for many hour…New SdFat library (with and without DMA) .
But i have not had time to find the cause, because sometimes it can run for many hours without a problem

Thu Jun 25, 2015 9:44 pm

Hi Victor,

i will clone your repo again and see if it works.

it could just have been that PA4 SS issue, but i cant really remember as it was some time ago (but i thought one of my test rigs used PB5 for SS)

Thu Jun 25, 2015 9:55 pm

Victor: I remember, I got your library working some months ago… Maybe the lib doesn’t like every sd-card adapter and/or SD-card. I’m going to search all of my modules and cards and try the combinations…

Thu Jun 25, 2015 10:09 pm

Bingo!
Working:
The old LC-soft adapter (big one) is working http://img.dxcdn.com/productimages/sku_142121_1.jpg

Not working (but with the SD-library)
The micro one for the UNO (with the 5V multi-converter chip) http://img.alibaba.com/img/pb/659/697/9 … 59_679.jpg

SD cards tested: Transcend 4GB microSD: not working, 2GB micro SD (no brand) working. Maybe a formatting problem?

Edit with the successful combination (LC soft adapter + 2GB) the quickstart example works even with SPI_CLOCK_DIV2 and DMA enabled.
Bench speed is like a turtle: 88kb/s even with DMA enabled (more things to try out….)

Thu Jun 25, 2015 10:36 pm

Matthias,

Which repo are you using for SDFat ? Victors one ?

Fri Jun 26, 2015 2:29 am

The old LC-soft adapter (big one) is working http://img.dxcdn.com/productimages/sku_142121_1.jpg

That’s the adaptor I’m using too, but with the old SD. (I’ve didn’t retried SdFat from Victor since when I tried it on Netduino2Plus, it wasn’t working at that time few weeks ago)

On MapleMini, the LC-soft works well with plain SPI, but I’ve struggled to make it run with SPI(2). I wish SPI.SelectDev() will become handy soon … ;)

Fri Jun 26, 2015 6:34 am

Which repo are you using for SDFat ? Victors one ?
Yes, the direct one from Victor’s github account.

Fri Jun 26, 2015 6:43 am

Thanks

I’ll try it again this weekend

Post a reply