F_mount and opening a sub directory off of the root path

Hi all,

I am using the WavPlayer and I’m looking to open a directory called “count.” To do this I am modifying this line from the seed wavplayer example:

From this:

f_mount(&fsi.GetSDFileSystem(), "/", 1);

to this:

f_mount(&fsi.GetSDFileSystem(), "/count", 1);

I’ve tried a few other variants as well but none of them seem to open the sub directory but instead it keeps opening the root directory on the files system.

Any thoughts on how I can open a sub directory off of the root path?

Thank you for your time and help,
Brett

IIRC, that path is used to specify logical drive path, not arbitrary directory on it. You should have a look at FATFS docs for explanation and examples for opening directories, reading files, etc.

1 Like

@antisvin,

Thank you, that is exactly what I was looking for. I assume I can call a change directory and then use the changed path for the WavPlayer.

Overall - thank you very much for the pointer to the docs.

Brett

@antisvin,

I went to use f_chdir(“/path”); I am getting an undefined reference compile error.

I have the USE_FATFS = 1 in the Makefile.
I have the “fatfs.h” in my cpp file.

Any pointers here would be appreciated.

Thank you for your help with this.
Brett

Just checking back as I am not sure if I am missing something in the Makefle to allow f_chdir to work.

Any help or pointers here would be greatly appreciated.

Thanks,
Brett

Was USE_FATFS set when libdaisy was built?

@tele_player,

No, it was not set in the libdaisy Makefile.
It is set in my local Makefile.

Where should I add this in the libdaisy Makefile?

Thanks,
Brett

@tele_player , @antisvin ,

I went into the libdaisy Makefile and added USE_FATFS = 1 just under the OPT flags after the sources. I ran the rebuild_all script, then went to my prject and bild it again, but no joy. I am still having issues with f_chdir not working.

Any other thoughts here?

Maybe I need to update all of my Daisy sources?

Thanks,
Brett

If you want to ask people to review your project, the first step would be uploading it to github or somewhere similar.

@antisvin,
I will do two things today: 1) re sync the Daisy project and 2) just upload a basic sample that reproduces the problem.

I do understand the value of code, I wasn’t sure if this problem has come up for others in the past and, as such, I thought i’d check here.

The reason I have not posted all of my current system code right now simply is because the code isn’t ready to be fully posted for the world. Hopefully coming soon.

I’ll do the above two this morning (for me here) and post back if the sync fixed it or the code sample.

Thank you for the help,
Brett

Hello @antisvin, @tele_player,

I went in and used Git Dektop to ensure my Daisy repro was in sync and yes, it was other than my local files.

Here is a very stripped-down version of my main CPP file:

#include "SEQ16_RevA.h"
#include "daisysp.h"
#include <string.h>
#include <stdio.h>
#include "daisy_seed.h"
#include "fatfs.h"

// Use the daisy namespace to prevent having to type
// daisy:: before all libdaisy functions
using namespace daisysp;
using namespace daisy;

// Declare a DaisySeed object called hardware
seq_16_rev_a hw;

// Setup audio descritption playback from SDCard
static SdmmcHandler   sdcard;
static FatFSInterface fsi;
static WavPlayer      sampler;
static FIL            file;

static void AudioCallback(AudioHandle::InterleavingInputBuffer  in,
                          AudioHandle::InterleavingOutputBuffer out,
                          size_t                    size)
{
 
    for(size_t i = 0; i < size; i += 2)
    {
        out[i] = out[i + 1] = s162f(sampler.Stream()) * 0.5f;
    }
   
}

int main(void)
{
        
    // Configure and Initialize the Daisy Seed
    // These are separate to allow reconfiguration of any of the internal
    // components before initialization.
    hw.Init(true);
    
    // start up the SD Card 
    SdmmcHandler::Config sd_cfg;
    sd_cfg.Defaults();
    sdcard.Init(sd_cfg);
    fsi.Init(FatFSInterface::Config::MEDIA_SD);
    f_mount(&fsi.GetSDFileSystem(), "/", 1);
//    f_open(&fsi, "/count", 1);
   int fs_ok = f_chdir("/count");

    // seupt the smapler 
    sampler.Init(fsi.GetSDPath());
    sampler.SetLooping(true);
    
    size_t curfile;
    curfile = sampler.GetCurrentFile();
    sampler.Open(curfile);

    for(;;)
    {
        // make sure the audio is flowing from the file ssystem
        sampler.Prepare();

    }
}

Here is my makefile

# Project Name
TARGET = MIDILEDs

# Sources
CPP_SOURCES =   OSCSqr.cpp \
                MIDILEDs.cpp 

# Includes FatFS source files within project.
USE_FATFS = 1

# set optimization so my code fits on the flash :)
OPT = -Os

# Library Locations
LIBDAISY_DIR = ../../libDaisy
DAISYSP_DIR = ../../DaisySP

# Core location, and generic Makefile.
SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core
include $(SYSTEM_FILES_DIR)/Makefile

# Library Locations
LIBDAISY_DIR = ../../libDaisy
DAISYSP_DIR = ../../DaisySP

Here is the error I get when compiling:

in function `main':
C:\Users\direc\Documents\GitHub\Daisy\DaisyExamples\ElectronDrift\Failure/MIDILEDs.cpp:52: undefined reference to `f_chdir'

Thank you for your time and help with this.
Brett

It looks like you’d have to set this to 1 or 2 in order to use f_chdir:

@antisvin,

Thank you, sorry I missed that and I greatly appreciate the help. I’m going to go give that a try right now. :smiley:

Brett

1 Like

@antisvin,

Thank you for the help, I was able to get everything working for the SD card. Much appreciated.

May you have a good rest of your day.
Brett

Does that means that your problem was just that you need a function that wasn’t compiled by default or anything else? IIRC, f_chdir is one way to open the directories with FATFS, but you also have an option of using f_open and building exact paths with C strings instead.

@antisvin,

Great question.

By adding the flag and recompiling libDaisy, I was able to access the f_chdir function and it worked great.

I also, looked at a different way to use the file system for what I am doing so I may not need the f_chdir function, but it does work successfully.

Thank you for the help, it is much appreciated.
Brett