OBEX 619 (SD Card): File System Corrupted
DavidZemon
Posts: 2,973
I'm giving SD card reading a try for the first time. I downloaded object 619 (http://obex.parallax.com/objects/619) and have written the following code:
I noticed, however, that when an error occurs it doesn't actually return the error code - it kills the cog (via the abort command) so I changed "abort" to "return" in abortError() and set the the calling function that is failing (formatPartition) to return abortError() instead of just calling it.
Anyway, my questions is, how do I go about finding out what "File System Corrupted" means or other errors that I may run into later? The card is currently unformatted.
Of course, if there is a different object that you think I should be using, I'm open to suggestions. My requirements are very simple and very static - read from and write to a single file in the root directory.
{{ File: Tachometer.spin Author: David Zemon Project: Learn SD Description: Learn how to work with an SD card }} CON _CLKMODE = XTAL1 + PLL16X _CLKFREQ = 80_000_000 BAUD_RATE = 115_200 LED_PIN0 = 16 LED_PIN7 = 23 CS = 0 DO = 1 CLK = 2 DI = 3 OBJ pst : "Parallax Serial Terminal" sd : "SD-MMC_FATEngine" PUB Main | count, sdSuccess pst.start(BAUD_RATE) dira[LED_PIN0..LED_PIN7] := $ff waitcnt(CLKFREQ*5 + cnt) ' Wait for user to be ready outa[LED_PIN0] := 1 pst.Str(String("Hello world!", pst#NL)) pst.Str(String("Press enter when ready to start...", pst#NL)) pst.CharIn ' Connect to the SD card outa[LED_PIN0 + 1] := 1 sdSuccess := sd.FATEngineStart(DO, CLK, DI, CS, -1, -1, -1, -1, -1) outa[LED_PIN0 + 2] := 1 if (True == sdSuccess) pst.Str(String("Successfully started! Press enter to format...", pst#NL)) pst.CharIn else pst.Str(String("Failed to start. Aborting.", pst#NL)) abort ' Mount a partition outa[LED_PIN0 + 3] := 1 pst.Str(String("Formatting partition...", pst#NL)) sdSuccess := sd.formatPartition(0) outa[LED_PIN0 + 4] := 1 if (False == sdSuccess) pst.Str(String("Successfully formatted FAT32 partition!!! Press enter to continue", pst#NL)) pst.CharIn else pst.Str(String("Failed: ")) pst.Str(sdSuccess) pst.Str(String(pst#NL)) abort outa[LED_PIN0 + 5] := 1 ' Unmount and stop the SD card sd.unmountPartition sd.FATEngineStop
I noticed, however, that when an error occurs it doesn't actually return the error code - it kills the cog (via the abort command) so I changed "abort" to "return" in abortError() and set the the calling function that is failing (formatPartition) to return abortError() instead of just calling it.
Anyway, my questions is, how do I go about finding out what "File System Corrupted" means or other errors that I may run into later? The card is currently unformatted.
Of course, if there is a different object that you think I should be using, I'm open to suggestions. My requirements are very simple and very static - read from and write to a single file in the root directory.
Comments
sdSuccess := /sd.formatPartition(0)
I never formatted a SD card with the propeller. Just do it with your PC.
I always use a slash now when doing a "mount", otherwise it shuts down the cog on failure...
Personally, I don't use the "abort" features, so it's easy to get surprised by this behavior...
Do a low level reformat on the PC to fix the file system corrupted error. The FATEngine does not like it when there are any problems with the media. (If it gives you a file system corrupted error there is a problem with the media, other drivers just choose to ignore the problem).
Thanks,
@Kye
I'm not sure what you mean by "Do a low level reformat". I'm running both Ubuntu and Windows so I can use whatever tool you think would work. I tried partitioning with GParted by: delete existing partition, Create Partition Table, recreate FAT32 partition. there were no options for the partition table or FAT32 partition like block or cluster size.
Thanks for the help.
This is a problem having to do with the block driver not getting the correct responses from the SD card on time.
The two solutions for this are to use a different card then or use the FSRW driver also on the OBEX... it has a different block driver that may be suitable.
Thanks,
I'm using the 4GB version of this SD card http://www.kingston.com/us/flash/sd_cards#sd4 if that helps.
I tried fsrw as well and upon mount_explicit, -1 is returned. Attached is my updated code.
I also reformatted with FAT16 this time (didn't change anything with either library).
Thanks,
David
Are you sure you have the SD pins connected the way you define it in the CON section?:
Most boards (QuickStart HMI, PropellerPlatform for example) have the pins in this order:
Andy
### SD Card Profile ###
Disk Signature: 0x000B78B6
Partition 0 - 0xF0F27818
FAT16
512 - Bytes Per Sector
128 - Sectors Per Cluster
7623936 - Total Sectors
59562 - Total Clusters
256 - Used Sectors
7623680 - Free Sectors
32 KB Stride Speed Test:
writeByte - 3 KBs
writeShort - 6 KBs
writeLong - 11 KBs
writeData - 207 KBs
readByte - 3 KBs
readShort - 6 KBs
readLong - 12 KBs
readData - 263 KBs
MISO is Master-in-Slave-Out and MOSI is Master-Out-Slave-In.
I think it's pretty clear that the Propeller is the master in this case and the SD card is the slave.
This labelling makes things a lot more clear, IMHO.
Here's the wikipedia info on it:
http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus