[Solved] SdFat "BackwardCompatability.ino" only works with SD.h selected...

I thought I could figure this out... but since I am asking here, you know that I didn't :frowning:
I can't get SdFat to work.

Setup:
• STM32F103C8 BluePill clone
• Official ST Core
• Arduino IDE 1.8.13
• No bootloader installed
• Use Serial connection and STM32CubeProgrammer to program
• SD module wired to SPI1 (SS = PA4, SCK = PA5, MISO = PA6, and MOSI = PA7)
• SdFat v2.0.4

On the latest version of SdFat (v2.0.4) there is a example program that allow you to switch between SD.h and SdFat.h for SD card support using SPI.

Setting USE_SD_H to 1 uses SD.h. In this example, the SD card works without any issues:

Using SD.h. Set USE_SD_H zero to use SdFat.h.
Type any character to begin.

Initializing SD card...initialization done.
Writing to test.txt...done.
test.txt:
testing 1, 2, 3.
testing 1, 2, 3.
testing 1, 2, 3.
testing 1, 2, 3.

Then I set USE_SD_H to 0 to use SdFat and it doesn't work.

Using SdFat.h. Set USE_SD_H nonzero to use SD.h.

Type any character to begin.
Initializing SD card...initialization failed!

After much testing, any SD example program using SD.h works. Any example program that uses SdFat.h doesn't work.
I had the same issue when using SdFat v1.1.4 then I upgraded to v2.0.4 hoping it worked, but it didn't.

Am I doing something wrong? I have tripled checked the wiring and since it does work on SD.h, it must be something else.

(Yes, I could just use SD.h, but I am excited to use some of the new features in SdFat v2, like long file names :slight_smile: )

I am in the process of using an 8 channel logic analyzer to capture the SPI bus during program execution of both examples.
Screen shots will be uploaded shortly.

Bill Greiman (author of SdFat) has provided the fix:

Simply change:

if (!SD.begin(SD_CS_PIN)) {

to:

 if (!SD.begin(SD_CS_PIN, SD_SCK_MHZ(4) )) {

and now SdFat works on the STM32F103 using the ST core.

What is interesting, is that the actual SPI clock speed didn't change... the logic analyzer still measured it at ~2.28 Mhz before and after the above change. That's kind of odd, but it works :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.