What is the correct way to use the SDCard on the Daisy Patch?

Hi,
I’m struggling with the Daisy Patch SD-Card (with a SanDisk Extreme micro SDHC 32GB formatted in FAT32); I don’t find any documentation, only snippets of code.

On some pages/code I find

SdmmcHandler::Config sd_cfg;
sd_cfg.Defaults();
sdcard.Init(sd_cfg);
...

on others:

dsy_fatfs_init();
// Mount SD Card
f_mount(&SDFatFS, SDPath, 1);
hw.DelayMs( 1000 );

On others I found that a USE_FATFS = 1 should be added to the Makefile

I tried the latter combination but:

f_mount(&SDFatFS, SDPath, 1)

returns error 3 FR_NOT_READY ?!?

What are the correct APIs (and Makefile configuration/defines) to

  1. initialize the SD-card hardware and prepare to read/write it (FAT32)
  2. open a file
  3. read some bytes from it
  4. close the file

?

Thank you in advance!

(I’ll put the info on the cheatsheet :wink: )

@algoritmarte This recently changed in v3.0.0

The reason for the change was to support USB drives as well as SD cards, and simultaneous mounting of both SD and USB media.

In order to setup SD card usage now, you can follow the following steps:

  1. Initialize the SD Card hardware using SdmmcHandler and SdmmcHandler::Config as shown in your first code block
  2. Link the FatFS filesystem to the desired hardware using FatFSInterface
  3. Use FatFS API directly as expected – (mount, read, write, etc.)
// . . . Global variables, or part of hardware class
SdmmcHandler sdcard;
FatFSInterface fsi;

// . . . in main() {

// Init the hardware
SdmmcHandler::Config sd_cfg;
sd_cfg.Defaults();
sdcard.Init(sd_cfg);

// Link hardware and FatFS
fsi.Init(FatFSInterface::Config::MEDIA_SD);

// Get a reference to the SD card file system
FATFS& fs = fsi.GetSDFileSystem();

// Mount using fatfs:
f_mount(&fs, "/", 1);

// you can now use FatFS as expected to read/write, etc.

hope that helps!

Thank you very much!

I still have some doubts: before reading your answer, I was able to read a file using the old combo sdcard.Configure/Init + dsy_fatfs_init() + f_mount; then I tried the new version; but the FatFSInterface is not present in the libDaisy that I’m using.

Then I found that the libDaisy linked to the DaisyExamples + submodules repository doesn’t contain any FatFSInterface definition/implementation .

Is it ok ?

ah, your repo may be a little bit out of date.

you should be able to git pull on DaisyExamples to get any updates, and if you’ve never manually changed your libDaisy files then it should update to the most recent.

Otherwise, you can either git submodule update and you should see libDaisy update to commit f99ff47, or you can manually do this by navigating to libDaisy and running git checkout f99ff47

Once you’ve done that you can rebuild the libraries, and you should be good to go with the above advice.

The seed/SDMMC should be able to be compiled and run. You can use that example as a reference as well.

Odd, because I redownloaded it from scratch using SmartGit and the repository link https://github.com/electro-smith/DaisyExamples.git . Tomorrow I’ll try again.

@shensley is the STM firmware for daisy seed deployed when updating a program binary? For some daisy seeds that I have, HAL_SD_ERROR_INVALID_VOLTRANGE is returned by SD_PowerON in DaisyExamples/libdaisy/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sd.c when following your above instructions.

For other daisy seeds, which I think are older. SD_PowerOn completes without error.

Is there a way to check daisy seed firmware versions? Does anyone know if there was a regression or change that may be causing this behavior?