Shop OBEX P1 Docs P2 Docs Learn Events
SD/MMC issue with FemtoBasic — Parallax Forums

SD/MMC issue with FemtoBasic

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2007-04-07 17:39 in Propeller 1
I've noticed an interesting issue with FemtoBASIC and the SD/MMC card.

{set the scene}
I've been developing with on a PC across the room from my Protoboard setup,
saving the new programs in binary format onto the SD card, (Under WindowsXP)
then moving the SD over to my project, bootng to Femto, and using SPIN "FILE
to boot the new item.

This works well, except I've spotted some sort of issue happening...

When I do a "FILES" from Femto, I see duplicated listings over and over again.
Seems that each time I save a file from the XP box to the SD card, the directory
table is replicated. This doesn't show on the Windows box, even a DOS dir looks
normal. This problem replicates as each time a file is saved from the Windows box.

On Femto, "files" starts to look something like this...

FILE 1 FILE 2 FILE 3
FILE 4 FILE 5
FILE 1 FILE 2 FILE 3
FILE 4 FILE 5
FILE 1 FILE 2 FILE 3
FILE 4 FILE 5


I've been reformatting the SD, and putting the files back on after a few duplications
occur, (Or whenever I get sick of seeing duplication.)

Which direction should I look on this? I wonder if Windows file/save is causing the issue.

Oldbitcollector

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-01 21:12
    I suspect it's some interaction between Window's FAT32 normal file system and the FAT16 file system used on the SD card. I don't see this happening on my Mac (under OS 10.4.9). See if you can come up with a minimal number of steps to reproduce the problem starting from an erased SD card and post the steps for Rokicki to look at.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-02 00:02
    Ok, this happens in two instances..

    1st..

    Format the SD/MMC in a dos window using:
    FORMAT X: /fs:fat /a:1024
    {no volume label}

    Then I copy my files to SD from a folder on
    my hard drive. (At least 5 files should do the trick)

    Now, checking the "FILES" in Femto reveals
    a perfect listing.

    Take the SD back to the PC, save a binary
    to the memory stick directly from the Propeller tool.

    Take the SD back to FemtoBASIC, and now
    you have two files listings, back to back.

    If you overwrite the binary file from the Propeller Tool,
    and go back to Femto, now you have three listings...

    The only fix has been to copy all the files off the
    SD, reformat the SD using the original format
    command and go agsin...

    ----

    I also noticed that tonight, after I had 30 files
    on the SD/MMC, it didn't seem to matter whether
    I reformatted the memory stick. Problem doesn't
    go away until reduce the number of files.
  • rokickirokicki Posts: 1,000
    edited 2007-04-02 18:13
    This is probably something my code is not dealing with properly. Can you replicate this on a small SD card,
    and then send me a full image of the SD card (the one that femtobasic claims has "duplicate" files)? You can
    snarf the image on a linux box using dd, and you can gzip it, and you can upload the file to
    http://tomas.rokicki.com/cgi-bin/upload.pl and let me know.

    BTW if you don't have a small SD card, that's fine; if you do a full format before running this test the image
    should compress to almost nothing anyway.

    If you don't have access to linux, or you can't do this for some reason, we can figure out a different way to
    debug things.

    (I'll try the steps you outline tonight when I get home, just in case I can reproduce them here.)

    Thanks for the bug report!
  • rokickirokicki Posts: 1,000
    edited 2007-04-03 04:10
    Okay, I can't duplicate it following your instructions on a 16MB card. What size card are you using?

    Are you inserting the SD card hot? (It really shouldn't matter, but . . . it's good to know anyway).

    It's really odd that you can get duplicated entries like that, especially if you can get three or more.

    Get me a dd of the SD card when it's showing that behavior on FB and I'll do two things:

    1. Verify the disk format/directory under linux (using a hex dump), and

    2. Make a direct duplicate of that card here and see if my femtobasic does the same thing.

    These will go a long way towards understanding the problem.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-03 06:47
    I'm using a 64MB card.

    I don't have a linux box setup to read SD media, so I may have to grab a copy of KNOPPIX and see I can DD it from there.

    Yes, I'm doing pulling/inserting it hot in both locations.
    (Shouldn't make a difference, but mileage may vary)

    Oldbit
  • rokickirokicki Posts: 1,000
    edited 2007-04-03 15:25
    If I understand things, you are not writing to the card at all on the propeller side. Is that correct?

    If you are pulling/inserting it hot, I would definitely add at least a pair of capacitors across the power
    supply to the SD card as close to the card as you can; the insertion current spike can be significant.
    The pair should be the usual suspects; perhaps a .1uF ceramic or tantalum, and a 10uF electrolytic.
    I doubt this is the problem, but you never know.

    If after seeing this multiple incarnations of a file, you power cycle the prop system, does it still persist?
    (This will tell us if the problem is on the card itself or in the propeller's memory.)

    Also, this is not related to your problem, but if you format with a 8K cluster instead of 1K, you'll get
    somewhat better performance.

    Finally, could you attach the full archive of the femtobasic you are using? I just want to make sure
    I debug against as close to what you are running as possible.

    Post Edited (rokicki) : 4/3/2007 3:34:30 PM GMT
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-03 15:49

    If I understand things, you are not writing to the card at all on the propeller side. Is that correct?


    :: Yes, the problem occures without writing to the card on the propeller side, although
    the card is written to from both places.


    If you are pulling/inserting it hot, I would definitely add at least a pair of capacitors across the power
    supply to the SD card as close to the card as you can; the insertion current spike can be significant.


    :: Point taken.. Will also test this tonight, inserting the card with power off.
    :: This should eliminate that as a factor.


    If after seeing this multiple incarnations of a file, you power cycle the prop system, does it still persist?


    :: IIRC, yes the problem persists after a reboot. So it's not the prop.


    Also, this is not related to your problem, but if you format with a 8K cluster instead of 1K, you'll get
    somewhat better performance.


    ::Yes, I was feeling wasteful because I figured there was no way
    ::I'd ever use 64MB on my Propeller. [noparse]:)[/noparse] Actually, I'm already close to 1/2 meg.


    Finally, could you attach the full archive of the femtobasic you are using? I just want to make sure
    I debug against as close to what you are running as possible.


    ::Will do tonight..

    Oldbitcollector

    Sorry if I've offended someone with my formatting...
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-04 03:24
    A souce copy of my current Femtobasic has been uploaded to that address you listed earlier.

    Successfully uploaded file.
    Got 47190 bytes.
    md5 sum is 756250f96b4a11ed54f9904e6a3d2a5f 11390-upload.tst .

    Oldbitcollector
  • rokickirokicki Posts: 1,000
    edited 2007-04-04 15:24
    Thanks! The real key thing here though is the dump of the SD card. That's what I'll need before I can make
    further progress. Booting into knoppix should do it.
  • rokickirokicki Posts: 1,000
    edited 2007-04-07 17:33
    With Oldbitcollector's excellent help, we were able to determine that this was a bug in nextfile() in the
    SecureDigital routines when working on a card with a lot of files and a small cluster size. The bug has
    been fixed, and there is a new version of fsrw-and-friends at http://tomas.rokicki.com/fat16work/

    Other than the version number change (from 1.4 to 1.5) and the date change, the only difference is
    this in nextfile:

    ***************
    *** 526,531 ****
    --- 528,535 ----
               t := pfillbuf
               if (t < 0)
                  return t
    +          if (((floc >> SECTORSHIFT) & ((1 << clustershift) - 1)) == 0)
    +             fclust++
            at := @buf + bufat
            if (byte[noparse][[/noparse]at] == 0)
               return -1
    
    



    This does mean of course that all the variations of femtobasic also need to be
    updated.

    While I'm here I will note that Paul Baker was successfully running the secure digital card at
    ESC with no pullup resistors at all---just four wires connected from the propeller to the SD
    card. While I don't recommend this for industrial designs, simply because I was taught to
    always pull up unconnected CMOS inputs, don't let the fact that you don't have the resistors
    keep you from experimenting with the SD card.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-07 17:39
    Fix appears to be flawless! Fixed in true wizard-like fashion!

    Oldbit
Sign In or Register to comment.