Spark Logic

New SdFat library (with and without DMA)

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
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

Replies

Tiago Sun Jun 28, 2015 8:17 pm

To enable DMA in mini maple generates this error:

/home//Arduino/libraries/SdFat/SdSpiSTM32F1.cpp: In member function 'uint8_t SdSpi::receive(uint8_t*, size_t)':
/home//Arduino/libraries/SdFat/SdSpiSTM32F1.cpp:172:7: error: 'class SPIClass' has no member named 'dmaTransfer'
SPI.dmaTransfer(0, const_cast<uint8*>(buf), n);
^
/home//Arduino/libraries/SdFat/SdSpiSTM32F1.cpp: In member function 'void SdSpi::send(const uint8_t*, size_t)':
/home//Arduino/libraries/SdFat/SdSpiSTM32F1.cpp:208:7: error: 'class SPIClass' has no member named 'dmaSend'
SPI.dmaSend(const_cast<uint8*>(buf), n);
^

madias Mon Jun 29, 2015 9:06 am

Your repo isn’t up to date.
see SPI.h —-> https://github.com/rogerclarkmelbourne/ … maTransfer
At least you must update the SPI library, but it’s better to update everything, because many innovations are linked together.

The whole dma stuff (like ‘dmaTransfer’) is for a some weeks within the SPI.h/.cpp itself and not in the individual libraries.

tj_style Wed Jul 01, 2015 1:08 pm

I think some problem is related on level converter on sdcard module/shield.
I have test using sdcard module without using leevel converter, and it work fine.
but it not work when using sd card module that have level converter.

mrburnette Thu Jul 02, 2015 12:39 pm

tj_style wrote:I think some problem is related on level converter on sdcard module/shield.
I have test using sdcard module without using leevel converter, and it work fine.
but it not work when using sd card module that have level converter.

victor_pv Thu Jul 02, 2015 1:33 pm

mrburnette wrote:tj_style wrote:I think some problem is related on level converter on sdcard module/shield.
I have test using sdcard module without using leevel converter, and it work fine.
but it not work when using sd card module that have level converter.

mrburnette Thu Jul 02, 2015 1:51 pm

victor_pv wrote:
I haven’t been using an extra capacitor for SDCards, but it makes much sense, I’ll start using it from now on anytime I see any problem.

ahull Thu Jul 02, 2015 9:26 pm

victor_pv wrote:
EDIT: Just to add that personally I have used the SDCard slot in the back of an ili9341 board, which seems to work “mostly” fine, and also the adapter Madias linked before: http://img.dxcdn.com/productimages/sku_142121_1.jpg
That one works great all the time so far.

victor_pv Thu Jul 02, 2015 11:15 pm

I have used all of them separately, but never tried all 3 at the same time.
I also used the screen+touch at the same time, but never a combination of the 3 of them.

tj_style Sat Jul 04, 2015 10:24 pm

Strange result,
I was try to using CS pin in different pin.
using pin 8 and 9 is not working but when i use pin 1 and oin 2 is working
Using example Sketch.

Micro SD Sandisk 2GB, some test using DMA:
write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
1052.47,106079,2898,3888
1071.19,19437,2900,3820
1073.50,22139,2901,3813
1068.67,33005,2902,3829
1067.76,34606,2901,3833
1063.90,36557,2902,3845
1070.51,38904,2901,3823
1070.28,42891,2899,3824
1065.94,59471,2900,3838
1061.64,44357,2900,3855

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
1562.09,4049,2607,2621
1563.07,3180,2606,2619
1562.58,3183,2606,2620
1562.58,3183,2605,2619
1562.58,3183,2607,2619

victor_pv Fri Jul 10, 2015 1:17 pm

tj_style wrote:Strange result,
I was try to using CS pin in different pin.
using pin 8 and 9 is not working but when i use pin 1 and oin 2 is working

victor_pv Sun Jul 26, 2015 4:28 pm

Quick update. I have noticed that if I “begin” the sdcard without the speed, just the chip select pin, it fails some times, such as:
sd.begin(SD_ChipSelectPin);

But if I add the parameter for the speed, it works fine:
sd.begin(SD_ChipSelectPin, SPI_CLOCK_DIV2)

Maybe the card, may be the default speed, I don’t have time to check it out right now, just wanted to post it in case it helps someone.

e-dredon Sun Aug 30, 2015 9:13 am

Hello
I’m getting an error during compiling any of the exemples
‘SPI_DMAC_TX_CH’ was not declared in this scope

I’m working with a bluepill STM32F103C8T6 board.

I tried with both the stable branch on the github and the beta repository.

I had a quick look at the SdSpiSTM31F1.cpp and i’ve found definition for SPI1_DMAC_TX_CH but not for SPI_DMAC_TX_CH

#define SPI1_DMAC_RX_CH DMA_CH2
/** DMAC transmit channel */
#define SPI1_DMAC_TX_CH DMA_CH3

Is it possible to fix it ?

Regards,

\%user%\Documents\Arduino\libraries\SdFat\src\SdSpiCard\SdSpiSTM32F1.cpp: In function 'void SPI_DMA_TX_Event()':
\%user%\Documents\Arduino\libraries\SdFat\src\SdSpiCard\SdSpiSTM32F1.cpp:40:21: error: 'SPI_DMAC_TX_CH' was not declared in this scope
dma_disable(DMA1, SPI_DMAC_TX_CH);
^
\%user%\Documents\Arduino\libraries\SdFat\src\SdSpiCard\SdSpiSTM32F1.cpp: In member function 'uint8_t SdSpi::receive(uint8_t*, size_t)':
\%user%\Documents\Arduino\libraries\SdFat\src\SdSpiCard\SdSpiSTM32F1.cpp:148:28: error: 'SPI_DMAC_RX_CH' was not declared in this scope
dmac_channel_disable(SPI_DMAC_RX_CH);
^
\%user%\Documents\Arduino\libraries\SdFat\src\SdSpiCard\SdSpiSTM32F1.cpp:149:28: error: 'SPI_DMAC_TX_CH' was not declared in this scope
dmac_channel_disable(SPI_DMAC_TX_CH);

RogerClark Sun Aug 30, 2015 10:30 am

What version of SD lib are you using?

e-dredon Sun Aug 30, 2015 2:37 pm

Oops… I just saw the first post at the same time you answered. I thought greiman repo was up to date. Thank for the super fast answer. The 2 variables are defined in your version. Obviously It now compiles nicely. Now i can focus on making a demo for the ILI9341 TFT display, with PicoJPEG and your lib. Thank you. I’m using SPI1 for the ILI9341. Do i need to set a dedicated SPI (MISO/MOSI) for the SDcard reader or shall I just use a dedicated CS pin ?

victor_pv Sun Aug 30, 2015 5:32 pm

e-dredon wrote:Oops… I just saw the first post at the same time you answered. I thought greiman repo was up to date. Thank for the super fast answer. The 2 variables are defined in your version. Obviously It now compiles nicely. Now i can focus on making a demo for the ILI9341 TFT display, with PicoJPEG and your lib. Thank you. I’m using SPI1 for the ILI9341. Do i need to set a dedicated SPI (MISO/MOSI) for the SDcard reader or shall I just use a dedicated CS pin ?

e-dredon Sat Sep 05, 2015 6:15 am

Thanks for your answer.

I’m now having issues to get the SDreader module working. Even I connect it alone for now on any of the 3 SPIs, SdFat won’t find it. My ILI9341 board comes with a 5 pins connector for the SDcard (F_CS, SD_SCK, SD_MISO, SD_MOSI, SD_CS). If I’m not mistaken, F_CS should be left unconnected as I don’t have the U3 SPI flash populated. I tried with a microSD module made for 5V VCC (just bypassing the 3.3 voltage regulator) and it works. Well I’ll put it on hold for now as i have other issues to address first with the bootloader.

Best regards,

bubulindo Wed Sep 16, 2015 10:10 am

Hello,

I have an Olimexino board with an SD card attached and I find that the SD libraries assume that there is only one SPI peripheral when in fact we have two (on the olimexino, it’s on SPI2 that the SD card is connected).

Do you think this could be changed in the library?

martinayotte Wed Sep 16, 2015 2:46 pm

The SdFat can be configured into different flavours in libraries/SdFat/SdFatConfig.h.
SD_SPI_CONFIGURATION is the define that let you choose if you rely on Hardware or Software SPI, or even a custom one.
In my case, for Netduino2Plus, a F405, the SDCard is hooked up on SPI3 and is working marvellously. ;)

Sign in to reply