Secure Digital Card/FAT16/Read
rokicki
Posts: 1,000
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.
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.
zip
30K
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
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...
Nice. Where did you get the SD card from with the handy connector?!
James
Impresive work...
And I like the idea of starting / stopping as needed...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
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...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't visit my new website...
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!!!
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
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.
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
http://www.sandisk.com/Oem/Manuals/
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't visit my new website...
yeah thats helpful.
cheers,
James
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
·
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 . . .
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...
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
·
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.
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
·
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
http://www.mmca.org/compliance/buy_spec/MMCA_System_SummaryV41.pdf
James
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
·
····· 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
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
·
···· 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.
··· 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....
··· 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
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
·
Unfortunately, their prices generally start at $1500 or so, and there's no real limit...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't visit my new website...
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
·
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