FatFs with Fastspin and FlexC

RaymanRayman Posts: 11,247
edited 2020-09-04 - 21:13:18 in Propeller 2
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.


Comments

  • If it helps, you can look at the file driver I did for p2gcc. It is based on FSRW.
  • Maybe... I could use my own version of FSRW for P2. But, this adds things like directory support...
  • RaymanRayman Posts: 11,247
    edited 2020-09-02 - 14:06:01
    I think I have it actually working!
    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.
  • Got it working! Turns out Fastspin already had the files I needed.
    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.
  • I think there's something wrong with the Eval board's sharing of flash and uSD on same pins...

    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...
  • Cluso99Cluso99 Posts: 16,570
    edited 2020-09-04 - 21:33:34
    Rayman wrote: »
    I think there's something wrong with the Eval board's sharing of flash and uSD on same pins...

    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...
    This is most likely the SD card failing to release driving the MISO (DO) pin. I’ve fixed that in the ROM code and my SD driver. I have had to do this with every driver I’ve used when I share the pins. I share the pins on my P1 RamBlade with the SRAM - CPM wouldn’t work without it!

    I don’t know how many times I have to say this :(
  • yes, IIRC you got to clock the card a couple times after deselecting it to make it surely shut up
  • I'm using the driver from FastSpin and it does appear to be sending out dummy clocks...

    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?
  • I've posted a newer fastspin in the fastspin thread, along with some samples of using the built-in file systems (both FatFs for SD and 9pfs for host).
  • RaymanRayman Posts: 11,247
    edited 2020-09-05 - 18:09:58
    Tried it, works but same issue with SDHC card...

    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...
  • As noted in FastSpin thread, I think the issue of having to remove the uSD card to remount is a phenomena limited to a small subset of card types and only when shared with boot/flash pins (for some undetermined reason).
    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.
  • yes, this would be very useful.

    Thanks,

    Mike
  • RaymanRayman Posts: 11,247
    edited 2020-09-06 - 13:55:59
    The AVR example comes with code for a DS1338 RTC. I suppose that is useful here to timestamp files.
    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...
  • RaymanRayman Posts: 11,247
    edited 2020-09-06 - 21:05:27
    Got the RTC code working in the attached.
    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:
    (*str)++;
    
    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 :)
  • RaymanRayman Posts: 11,247
    edited 2020-09-07 - 01:55:51
    So it looks like the binary is coming in at about 100kB with long file names and relative path enabled.
    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...
  • RaymanRayman Posts: 11,247
    edited 2020-09-10 - 00:01:37
    I believe I've now completed adaptation of this AVR demo for FatFs to FlexC by adding in wav file playback.
    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.
  • This version works with the P2 Eval Board with A/V accessory on P8..P15 and can play .wav files out on the audio out jack.

    Can use DS1339 for timestamp if installed. Pin definitions are in PropPins.h
Sign In or Register to comment.