Shop OBEX P1 Docs P2 Docs Learn Events
Secure Digital Card/FAT16/Read — Parallax Forums

Secure Digital Card/FAT16/Read

rokickirokicki Posts: 1,000
edited 2007-12-15 17:23 in Propeller 1
Here's a pair of objects that provides secure-digital card reading on a FAT16-formatted
filesystem. Writing is next.

Total size of the objects is 478 longs (including all buffering). This could possibly be improved.

The code is very short, too.

There are probably some bugs and incompatibilities; so far I've only tested it on a
single card formatted by a single device.

It's slow because it's Spin-only, but it would be straightforward to recode the lowest level
routines in assembly. I need to think about this though; do I want to occupy a whole
cog even though most of the time reading/writing won't be going on? Or do I want to
cognew() and release the cog as necessary (I need to find out how long it takes to
cognew).

Slow means about 3KBytes/second.

sdintsm.jpg
«1

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-05-21 10:57
    Very impressive. Having the photo inspires me to get going on this as it shows how easy the build is.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • GadgetmanGadgetman Posts: 2,436
    edited 2006-05-21 13:31
    I believe the Cognew operation is reported as 512uS, which really isn't that long.

    As for speed...

    The C64 read its floppydrive at 1200bps(tape was an agonizing 300bps), and even with your 3KB/s, you'll fill all available RAM in 10 seconds.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
  • JavalinJavalin Posts: 892
    edited 2006-05-21 15:01
    rokicki,

    Nice. Where did you get the SD card from with the handy connector?!

    James
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-05-21 15:03
    3KB/s is better then 0KB/s!
    Impresive work...
    And I like the idea of starting / stopping as needed...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • ForrestForrest Posts: 1,341
    edited 2006-05-21 15:29
    That looks like the SD-MMC Breakout board from Sparkfun www.sparkfun.com/commerce/product_info.php?products_id=204
  • JavalinJavalin Posts: 892
    edited 2006-05-21 15:36
    Cool - thanks for the info.
  • GadgetmanGadgetman Posts: 2,436
    edited 2006-05-21 17:18
    Surfed by Sparkfun, planning to buy that adapter...

    Too much goodies...

    Found a 640x480 CMOS camera meant for cellphones there, too, and with a couple of other chips, I'll be eating soup or spaghetti for the next week or two...

    smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
  • pnppnp Posts: 3
    edited 2006-05-22 16:35
    Now, Thats what I'm talking about.

    you da man!!!

    So I have my Sd breakout board from sparkfun and I even have two SD sockets to solder to the sample board.

    Now if I can only get my hands on a Propeller!!!
  • pjvpjv Posts: 1,903
    edited 2006-05-22 17:15
    Hi Rokicki;

    Regarding Cog launching speeds...... here is a copy of an earlier post I made on the private forums in early March; I belive that these findings are still valid.

    Hi All;

    For those who care.....

    I've just done some speed tests at 80 MHz:

    Spin launching an assembler cog takes about 12 uSec.

    Spin launching a spin cog takes about 225 uSec.

    Now need to see about assembler launching assembler & spin.


    Post Edit...... Finally got and assembler to launch an assembler, and that procedure takes about 110 uSec

    Cheers,

    Peter (pjv)

    Post Edited (pjv) : 3/7/2006 12:49:42 AM GMT
  • rokickirokicki Posts: 1,000
    edited 2006-05-22 18:30
    That's odd. 12 us to launce a new cog spin->assembler seems *way* fast.
    I would expect spin->assembler to be at least a tiny bit slower than
    assembler->assembler, but you show it as about 9 times faster.

    In any case, all these numbers are low enough that launching cogs as
    needed for SD I/O seems like a reasonable proposition.

    I'm thinking about adding the write support, and it's a bit nastier than I
    originally hoped; every time you flush data you have to update the
    directory entry (so that's a read and a write if you don't keep the
    directory entry around all the time), and every time you need a new
    cluster you need to read/write both FAT tables on average. In this
    case, for writes, you may actually *want* to use a separate COG
    that is permanently allocated so it can update the directory and the
    FATs asynchronously while more data is being collected to be written.
    It also lets you perform efficiency tricks---only update the metadata
    after a quarter second of no writes, for instance, or some such, so
    if the top level program does a bunch of writes in a row, the metadata
    is only updated once.

    On the other hand, all I really need to do is do all the I/O in
    assembly, and then it won't matter that I'm reading and writing
    so many blocks because it will all be blindingly fast anyway.

    Maybe I'll have writing completed next weekend.
  • JavalinJavalin Posts: 892
    edited 2006-05-22 19:34
    rokicki,

    I see from some research that the SD/MMC cards support SPI - am I correct in assuming that you could write whatever you want to the card and make up your own formatting rules??

    Where did you get your spec from - I've looked arround and the "offical" one is $$$$$$

    Cheers,

    james
  • GadgetmanGadgetman Posts: 2,436
    edited 2006-05-22 20:19
    You may find something useful here:

    http://www.sandisk.com/Oem/Manuals/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
  • JavalinJavalin Posts: 892
    edited 2006-05-22 20:25
    Hi Gadgetman,

    yeah thats helpful.

    cheers,

    James
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-05-22 20:42
    Javalin..
    Yes, you can write most any rules for formatting as long as the device's hardware supports it.
    As for a "file system", heck 100% any way you can make it work... BUT, if you want something else (like a pc for example), you MUST matain one of the FAT systems as reconized by the target system. Example: for a PC, FAT 12/16/32 (or even NTFS). If you have to maintain a file system as readable by a PC, then you have very little options in the formatting options...

    BTW: The same "commands" use here are used in USB storage devices. Once I figure out how a divice is "addressed", then the USB mass storage push is on...
    and I'm looking foward to the 18G 1" USB drive...

    rokicki: I like your code... sweet and to the point... but some things are unclear to me. Some extra comments would be nice... [noparse];)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • rokickirokicki Posts: 1,000
    edited 2006-05-22 21:17
    Kaos: Let me know what's unclear, and I'll add comments to clarify.

    I will see if I can purchase an inexpensive MMC card and make the code work with that too.

    Specs? All over. My starting point was the Wikipedia article on Secure Digital.

    USB mass storage would be cool! Of course we'll want fat32 for big USB keys. That's
    really not that much of a change.

    At this point, code organization really becomes an issue, especially with the limited code
    space of the propeller; I can see some people wanting to only read, and others only
    wanting to write, and some want FAT16, and some want FAT32, and some want both,
    and there's no easy way for me to conditionally include or elide code, is there? This is
    especially critical as we flesh it all out to support mkdir, seek, rmdir, append, rm,
    and all the other standard filesystem commands that most people won't need.

    Indeed, it would be major cool if the IDE would automatically omit pub/pri blocks that
    are not referenced anywhere.

    I suppose I can just put the kitchen sink in there and let people edit it down by hand.
    But it would be so sweet if that didn't have to be done . . .
  • GadgetmanGadgetman Posts: 2,436
    edited 2006-05-22 22:45
    You're looking to code this in assembly later?

    If so, why not have one piece of code that scans the media for format(FAT12/16/32/whatever), then loads the appropriate assembly routines from EEPROM and into a predetermined block in System RAM. Then it's a small case of starting a COG with the routine you need later.
    The user switches to another card?
    Run the first snippet again, load the correct assembly routines again...
    (No, I haven't tried loading assembly routines, yet, so I can't offer any code)

    Just wish there was a way of dynamically loading Spin code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-05-23 03:35
    Gadgetman... Good idea...
    As far as the other things, according to Chris and all the best... the compilier is smart enough to only include the code that's called, so if it can be divided into Methods then there's the best answer.
    As far as the commands to support, well make them PUB methods, and if there needed, then the complier would keep them, if they aren't needed, then, as best as I can tell from Chris (please, someone correct me if I'm wrong), it wouldn't be included in the obj file thats sent to the propeller.
    And the comments... I'm having a hard time following how you build the file name stuff at the top of sdfat.spin The rest of the code is easy enough for me to follow...
    This is awesome stuff... BTW, a friend of mine is trying to get me the docs at how a USB client communicates to it's host, and in particular, how this one device works as a USB thumb drive. If I get my hands on that, then we have a whole lot of USB drives that can be supported (darn near all of them....) I'm workin on it... and when I get it, it will be here...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • rokickirokicki Posts: 1,000
    edited 2006-05-23 07:19
    Wow, that's so cool, that it just includes the stuff needed! I assumed it wasn't doing that because some
    things seemed kind of big even when I just used a small bit of them---but that's great news. All I need
    to do is make sure my subroutines are reasonably separable then and things will work automatically,
    even for FAT16/FAT32.

    Heh, documenting the filename stuff is a good idea. All that code just to convert "foobarbaz.bat"
    into "FOOBARBABAT" (when stored in the directory, just the 8 and the 3 characters are stored, and
    they are padded with spaces, so there's a whole bunch of code to deal with that). I'll document
    it.

    The only bits I really plan to recode into assembly are initialize(), writeblock(), and readblock(). All
    the rest I hope to leave in Spin.

    Thanks for all the support, and all the technical help; this is all very new stuff and I'm learning as I go.
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-05-23 13:21
    Rokicki...
    what ever I can do...
    BTW: The spi code is the exact code needed to interface with the sta013 (mp3 decoder chip)... the routines your working on here will work with other spi devices....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • cbmeekscbmeeks Posts: 634
    edited 2006-05-23 14:30
    man, that is freaking awesome.

    I can't wait to get a propeller.


    Also, how hard would it be to load code from the SD and execute it in the propeller? ie, ROM?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Metroid Classic:
    http://metroidclassic.com

    Metroid Forums:
    http://eblarg.com/bbs/mc

    =========
    DMCA Sucks
    RIAA Sucks
  • JavalinJavalin Posts: 892
    edited 2006-05-24 13:32
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-05-26 16:08
    Gadgetman...
    YOu thought you had it bad... my Sparkfun order exceeds my lunch and breakfast budget for the next week...
    I guess its Donutholes and Glasses of air for next week!
    [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • cocokiwicocokiwi Posts: 75
    edited 2006-05-29 00:07
    Gadgetman said...
    You're looking to code this in assembly later?

    If so, why not have one piece of code that scans the media for format(FAT12/16/32/whatever), then loads the appropriate assembly routines from EEPROM and into a predetermined block in System RAM. Then it's a small case of starting a COG with the routine you need later.
    The user switches to another card?
    Run the first snippet again, load the correct assembly routines again...
    (No, I haven't tried loading assembly routines, yet, so I can't offer any code)

    Just wish there was a way of dynamically loading Spin code.

    ····· I don't get it, a perfectly good unit with internal firmware and they have to do it from scratch??

    ····· the UAFat device has DIRECT·hooks to the internal firmware and there ARE libraries of source code for this!
    ····· So! why invent the wheel all over again?? the only thing one has to do is make the code compatible to the Prop

    ····· Dennis

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://people.delphiforums.com/cocokiwi/Image/picture.jpg
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-05-30 13:43
    CoCokiwi...
    LOL... Well, 1/4 of it is the fun of it, 1/4 is the "can I do it", 1/4 is the cost of it,
    and lastly, well, lets just say this: If you ever truely wanted to know how something works: Make it your self.

    And one other note: I plan on making a USB HOST single device stack for the Propeller; Just explicitly for mass storage. When I get the basics down, I will need a completly operational 12/16 FAT for it. Now, with the FAT that rokicki is coding, it will be true mass storage Object; with access to 100% of all the USB Mass Storage ( and only the Mass Storage class!) devices. And just to finilize that dream: There are inexpencive ($29.00) devices that will take any IDE, EIDE, ATA, SATA device (read that as bing: hard drive, cd rom drive, CD-RW drives, DVD Drive, ZIP drives, Jaz drives) and place them on the USB, giving my USB HOST Single Device Stack access to them; for anyone who needs any kind of storage! The host interface, usb mass storage devices, and the converters for IDE,EIDE, ATA, SATA (and I think SCSI as well, I remember reading that was included in the mix) are all inexpensve, and it will provide the developer with a means of storage and access if needed.

    Thats about it all, for me least. When the funds become available to me, I will be getting one of the ufat devices: Just to include it in the Mass Storage object I am making.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • cocokiwicocokiwi Posts: 75
    edited 2006-06-01 01:05
    Kaos Kidd said...
    CoCokiwi...
    LOL... Well, 1/4 of it is the fun of it, 1/4 is the "can I do it", 1/4 is the cost of it,
    and lastly, well, lets just say this: If you ever truely wanted to know how something works: Make it your self.

    And one other note: I plan on making a USB HOST single device stack for the Propeller; Just explicitly for mass storage. When I get the basics down, I will need a completly operational 12/16 FAT for it. Now, with the FAT that rokicki is coding, it will be true mass storage Object; with access to 100% of all the USB Mass Storage ( and only the Mass Storage class!) devices. And just to finilize that dream: There are inexpencive ($29.00) devices that will take any IDE, EIDE, ATA, SATA device (read that as bing: hard drive, cd rom drive, CD-RW drives, DVD Drive, ZIP drives, Jaz drives) and place them on the USB, giving my USB HOST Single Device Stack access to them; for anyone who needs any kind of storage! The host interface, usb mass storage devices, and the converters for IDE,EIDE, ATA, SATA (and I think SCSI as well, I remember reading that was included in the mix) are all inexpensve, and it will provide the developer with a means of storage and access if needed.

    Thats about it all, for me least. When the funds become available to me, I will be getting one of the ufat devices: Just to include it in the Mass Storage object I am making.


    ···· me! I like it easy, akin to puting gun too close to foot and loosing toe!

    ··· I blew mine to electronic heven! Darn it! I had checked it a bunch of times!
    ··· looking a little closer I found I had crossed the powersupply.nono.gif

    ··· Byebuy SB card and unit!· why is it so hard for them to put a diode in line with the power supply!(grin)

    ··· they KNOW it is for klutz's like me....freaked.gif

    ··· I recieved two of those Mini USB devices the other day! one without the plug and one with! nice!

    ··· there is enough power for a Prop chip 3.3 volt 100ma and 5v 500ma from the USB
    ··· The chip in the USBto SER· has 3.3v but is only a few MA and cannot be used this way!
    ··· One can plug one into a Development board and have power and USB right there!


    · Cheers Dennis

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://people.delphiforums.com/cocokiwi/Image/picture.jpg
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-06-01 13:49
    JFTR: I just ordered a USBwiz... 'Twill be here early next week... My research shows me this about USB Hosting... LOTS OF WORK, way too much for my limited abilities.

    Sorry to hear about your SB card and unit... I' have a short and very true story for you:

    Superbowl sunday... 2006....

    My son was holding my laptop, standing in the walkway between the Lazy boy and the big fish tank... Several of my friends and I are watching the game, when one of my friends gets up to get something from the fridge... at that moment, the first touchdown was scored... In the excitement, my buddy ran into my son, which caused the laptop to go up while he and my son fell across the room onto the dinning room floor. As I watched, with horror, my laptop, with all of my development work, some office work and all of the originals for my short stories that I write, the picture of my Jeep with all 4 tires in the air in mid jump on its 17" display, crash through the plastic tank cover, shattering the two high temp bulbs, and thus sinking to the bottom of the tank. In the time it took for me to arise from my chair, my eyes trans fixed on the display, as it showed the swirling colors of death, was mere seconds. As my hand shot to the bottom of the tank to retrieve the now dieing laptop, undaunted by the shattered glass, exposed electrical wires from the bulbs or the fish that enjoy nibbling on my hand, the colors of death faded to black on the true color LCD screen.

    After nearly 4 hours of futile attempts at reviving the laptop, it was pronounced dead on the seen by PC Doctor Kidd. Various organs were harvested for other projects; the data contained was lost forever. All the fish survived the attacking laptop; some with mental problems to date are in counseling. My son suffered minor injuries to his backside and pride. My buddy has recently concluded group counseling for the easily excitable, achieving top ranks in his class. Financial consecrations were handled by all parties to the owners satisfaction.

    NOTE: Above is true... I feel your pain Dennis... [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • GadgetmanGadgetman Posts: 2,436
    edited 2006-06-01 14:45
    You know... There are companies who could recover the data on that HDD...

    Unfortunately, their prices generally start at $1500 or so, and there's no real limit...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
  • mcstarmcstar Posts: 144
    edited 2006-06-01 14:55
    Oh man, the laptop story almost brings a tear to my eye!· Maybe next time you can save it. A few months ago I dropped my cell phone into the sink my wife had just loaded with soapy water.· I grabbed it out a few seconds later and immediately popped the battery off the back.· I·pulled what screws I could find and let it sit for a couple days·and dry.··Then, I·popped the battery back in and it still works to this day. (I did have some problems with battery contacts as they·had a bid of corrosion on them, but this was easy to remidy)·What kills electronics in H2O is, strangely enough the fact that they are on and the power makes things short out.··Anyway, maybe next time you'll be able save the hd at least.· But let's hope there is no next time, right!
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-06-02 15:17
    This whole story was in the sandbox, but to conclude it... Water entered the HD chamber, causing the heads to contact the platers. Water shorted out the drive, and as the auto park system moved the heads to the LZ, they scraped the platter, which was spinning down from 7200 rpm, causing a sprial of defected cylenders across 3 of the 4 platters. With 3 out of 5 cylenders waisted ( on the outside, the inside was better at 1 of 5), the % of retrieable data was averaged to 2/5's. Other considerations included corrosion. The recovery room was able to recover less then 10% of the data from the drive (40 Gig drive), and most was useless (ie meaningless) data. I was refunded the setup cost, only ended up paying a nominal amount in exchange for the hdd assembly for their systems development group. Lesson learned: Every day, my documents are syncronized to a network share. All important data is in my documents. Just for the record, My hand was in the water as the screen faded to black, if it was 10 seconds, it was a lot. I haddn't thought of removing the battery until afterwards, not that it really mattered, by this time, it was dead... Dell's insurance, and my Friend replaced it for a newer, and better one. And my son's doesn't ask to use my laptop anymore... (gee, I don't know why... ) I do laugh about it, with both of them..... it was truly a comical and horrifying site... just 2 inches either direction and it would have hit the glass... If I didn't see it happen, I wouldn't have believed anyone in the room telling me... And, now, the fish tank has a hard wood cover on it... Just to prevent laptops (or Cats) from ever going into the "drink" again..

    Back to the topic at hand... The SUBWis doesn't read CD or DVD formats. So, any device you can hang onto the USB that has Mass Storage class descripto in it will work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • Dakota99Dakota99 Posts: 24
    edited 2006-06-03 02:27
    rokicki said...
    Here's a pair of objects that provides secure-digital card reading on a FAT16-formatted
    filesystem. Writing is next.

    Total size of the objects is 478 longs (including all buffering). This could possibly be improved.

    The code is very short, too.

    There are probably some bugs and incompatibilities; so far I've only tested it on a
    single card formatted by a single device.

    It's slow because it's Spin-only, but it would be straightforward to recode the lowest level
    routines in assembly. I need to think about this though; do I want to occupy a whole
    cog even though most of the time reading/writing won't be going on? Or do I want to
    cognew() and release the cog as necessary (I need to find out how long it takes to
    cognew).

    Slow means about 3KBytes/second.

    sdintsm.jpg

    dont mean to interrupt ya'll, but can one suggest where i might find info on interfacing the SD card(or the transflash card) to bs2. thanks
Sign In or Register to comment.