FatFs with Fastspin and FlexC (Updated Wav Player example)
Rayman
Posts: 14,646
Think maybe I'm close to getting FatFs to work with FlexC...
Got it to compile at least. That seems like a minor miracle...
Now, need to add in stuff from FSRW to actually read from the uSD card.
But, am I on a good path? Not sure...
Update: Got it working! Ok, so I cheated and just used the version that comes with FastSpin.
But, I added long file names and relative paths and it all seems to work!
FatFs comes with several interactive examples for different microcontrollers. I took the AVR one and made it work in the attached. It also does some simple read and write tests first.
Update: I noticed a license I didn't like in the earlier version of the .wav player that used some Arduino code to read the wav header.
So, I started over with some .wav header reader code that I found in a blog and slapped the whole thing with MIT license.
I could have just used my existing .Spin2 code to read the wav header, but this is more fun.
Got it to compile at least. That seems like a minor miracle...
Now, need to add in stuff from FSRW to actually read from the uSD card.
But, am I on a good path? Not sure...
Update: Got it working! Ok, so I cheated and just used the version that comes with FastSpin.
But, I added long file names and relative paths and it all seems to work!
FatFs comes with several interactive examples for different microcontrollers. I took the AVR one and made it work in the attached. It also does some simple read and write tests first.
Update: I noticed a license I didn't like in the earlier version of the .wav player that used some Arduino code to read the wav header.
So, I started over with some .wav header reader code that I found in a blog and slapped the whole thing with MIT license.
I could have just used my existing .Spin2 code to read the wav header, but this is more fun.
Comments
Well, at least I can write to one file and read from another.
For some reason, I have to remount before writing to a file.
That's probably not right...
Update: Creating a separate file object for the file being written to fixes the above issue. Maybe just operator error?
Code attached.
I just tweaked a bit to add long file names and relative path in the config h file.
Posted project to top post that includes a test program.
With my board, the uSD is on different pins and everything works fine.
With Eval board, it works fine with my 2 GB, regular uSD card. But, my 8 GB SDHC won't mount unless I physically remove and reinsert between mount attempts.
I think was seeing something similar with FSRW too...
I don’t know how many times I have to say this
Maybe I'll look for an actual FastSpin example to try out and confirm what I'm seeing...
Guess I should test this uSD card out in other places too...
@Cluso99 Where can I find your code to try?
https://forums.parallax.com/discussion/comment/1499300
and
forums.parallax.com/discussion/171642/p2-sd-drivers-cog-pasm-version-v-223/p1?new=1
BTW: I tried enabling exFat, but it seems that QWORD won't compile for some reason. Seems we need C99 extensions to do this, is that right?
Going to try Cluso's code now...
Anyway, I'm going to put this issue aside and move on.
What I'd like to do next is added other drives to FatFs, such as the spare space on boot flash chip, an eMMC chip, HyperFlash and perhaps HyperRam.
Thanks,
Mike
My board has a DS1339 RTC on it. The I2C interface for these chips looks identical.
But, DS1339 has a trickle charger that needs enabling, only main difference code-wise.
The AVR code is quite small. I think I'll see about adapting it for P2.
That way the time functions in the FatFs demo program will work...
That was relatively easy.
Hard part was getting the main code's interactive part to correctly parse input parameters...
Had to fix implementation of xatoi().
My C skills were not sharp enough to realize at first that needed parenthesis here to get the correct operator precedent: Anyway, you can now see and optionally set the date and time with this code.
Want to move on, but the AVR example also includes the ability to play a sound file. Think I just have to implement that
Only ~50kB without. I'm thinking it's worth it though. May reconsider if start to bump up against 512kB limit...
I'm guessing the read-only option would drop these a lot, but that's no fun...
The project files are attached.
Wav file playback is done using Spin2 code to start up the PASM2 assembly driver.
FlexC is working out to be very convenient...
Also attached some test wav files.
Usage: When you get the prompt, enter in "fi 0" to mount.
Then, type "p test7.wav" to play the file...
Also, enter "?" to see help with commands
Note: This is currently set up for my custom board, but I'll fix that soon.
Can use DS1339 for timestamp if installed. Pin definitions are in PropPins.h
Now, with MIT license...
It also uses the built-in version of FatFs in a cleaner way.