Skip to content

Instantly share code, notes, and snippets.

@brbrr
Created February 21, 2024 23:08
Show Gist options
  • Save brbrr/98a3c8a9d77b6eeb7d5ce8ba607d987b to your computer and use it in GitHub Desktop.
Save brbrr/98a3c8a9d77b6eeb7d5ce8ba607d987b to your computer and use it in GitHub Desktop.
fatfs_read_corruption.cpp
#include <stdio.h>
#include <string.h>
#include "daisy_pod.h"
#include "fatfs.h"
#define TEST_FILE_NAME "/output.bin"
// #define TEST_FILE_NAME "/samples/100_A_PrismSynth_01_850.wav"
// #define TEST_FILE_NAME "/samples/125_FirefightDrums_850.wav"
using namespace daisy;
static DaisyPod hw;
SdmmcHandler sd;
FatFSInterface fsi;
FIL SDFile;
static DSY_SDRAM_BSS char inbuff[2048];
int main(void)
{
// Vars and buffs.
size_t byteswritten;
// auto f_offset = 654;
auto f_offset = 843;
auto length = 1321; // 881 is the last size without corruption.
// Init hardware
hw.Init();
hw.seed.StartLog(true);
// Init SD Card
SdmmcHandler::Config sd_cfg;
sd_cfg.Defaults();
sd.Init(sd_cfg);
fsi.Init(FatFSInterface::Config::MEDIA_SD);
f_mount(&fsi.GetSDFileSystem(), "/", 1);
if(f_open(&SDFile, TEST_FILE_NAME, FA_READ) == FR_OK)
{
f_lseek(&SDFile, f_offset);
f_read(&SDFile, inbuff, length, &byteswritten);
f_close(&SDFile);
}
hw.seed.PrintLine("Starting from offset: %d", f_offset);
for(size_t i = 0; i < byteswritten; i++)
{
hw.seed.Print("%x ", inbuff[i]);
}
while(1)
{
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment