FatFs errors on SD card when audio is enabled

The libdaisy SDMMC/FatFS implementation has a pretty substantial update incoming (I’ll be merging within the next hour or so).

And for anyone that wants to look at it: the PR

Details

The SDMMC Handle can now be configured for 1-bit, or 4-bit buswidth, and with configurable speed settings ranging from 400kHz up to an over-spec’d 100MHz.

Transfers are now done with the SDMMC1 peripheral’s dedicated IDMA bus. The current diskio setup is a slightly modified version of one of the example projects from an ST disco board. So there is probably still some room for improvement there, but the I/O functions are now interruptible and do not suffer the stability issues that were seen before while audio was running.

I’ve also added the beginnings of a few utility classes, one for Recording/Writing WAV files (WavWriter) and one for preloading files into RAM (mostly for wavetable purposes, but can be (ab)used for larger files (WaveTableLoader).

Changes

There are two “breaking” changes that will affect anyone’s projects that currently use the SD Card in any capacity:

  1. The project Makefile no longer needs any special attention when using the SD Card, and the Makefiles within these projects have been reduced to their simple forms. The necessary files are now included via the core/Makefile in libdaisy, but a custom FATFS implementation can be swapped out for the libdaisy one by using FATFS_DIR in the Makefile, though this has not been extensively tested.
  2. The daisy::SdmmcHandler class now has a configuration structure for setting bus-width and speed. There is a “Defaults” function available for easy adaptation.

Code change for new support is as follows:

// previous:
sdhandler.Init();
// new:
SdmmcHandler::Config sd_cfg;
sd_cfg.Defaults(); // 4-bit, 50MHz
sdhandler.Init(sd_cfg);

If anyone has any other issues or instabilities feel free to reach out or create github issues.

6 Likes