Shop OBEX P1 Docs P2 Docs Learn Events
SD2.0 Full FAT32/16 File Sytem Driver - You there! Yes you, viewing this forum. - Page 6 — Parallax Forums

SD2.0 Full FAT32/16 File Sytem Driver - You there! Yes you, viewing this forum.

1468910

Comments

  • RaymanRayman Posts: 14,879
    edited 2010-06-19 19:41
    Kye said...
    @BradC - Yeah, you're right. Sorry I was being cheeky there =). I'll have to use more I/O pins however to support WP features.
    Kye:· That circuit I posted doesn't require any extra pins to monitor the WP and CP switches...

    You just read the input state of two SD pins that are normally outputs...

    This feature is not important at all for most hobby work, but essential for "real world" apps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Apps:· http://www.rayslogic.com/propeller/Programming/Programming.htm

    My Prop Info: ·http://www.rayslogic.com/propeller/propeller.htm
    My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm
  • KyeKye Posts: 2,200
    edited 2010-06-19 20:49
    Okay, so this is what I will do. I'm going to post the current code in the obex. That will let people use my driver.

    Next, I'll update the block driver to support card detect mode so that it can see if the card is inserted.

    Card detect will work like this. When you start the driver you will need to pass it the card detect pin number. This pin number can overlap with another pin. The card detect feature will see no card is inserted when the pin is high and a card is inserted when the pin is low.

    This allows Rayman's circuit to work but also allows you to have the CD and WR pins on seperate prop pins if you want.

    I'll be doing the same thing for write protect but that has to be built into my driver more... I plan to implement a more generalized caching technique to make my code cleaner and faster.

    Thanks,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • RaymanRayman Posts: 14,879
    edited 2010-06-19 23:46
    I'd be very appreciative if you added support for my circuit. But, it's not totally necessary, because it's pretty trivial to just test those pins before starting up the SD card driver...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Apps:· http://www.rayslogic.com/propeller/Programming/Programming.htm

    My Prop Info: ·http://www.rayslogic.com/propeller/propeller.htm
    My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm
  • KyeKye Posts: 2,200
    edited 2010-06-20 02:30
    ... I will have support for your circuit. See the post above...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • KyeKye Posts: 2,200
    edited 2010-06-22 23:00
    Okay its in the obex.

    Thank you all.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • zappmanzappman Posts: 418
    edited 2010-07-20 23:52
    This is so neat!

    Here are the results for my 4GB PNY Card.

    Running command: test
    Creating test file "testfile" ... Success
    
    Wrote 131,072 bytes at 0000005170 bytes per second
    
    Running byte stride write test...
    Wrote 32,768 bytes at 0000002969 bytes per second
    
    Running byte stride read test...
    Read 32,768 bytes at 0000004262 bytes per second
    
    Running word stride write test...
    Wrote 65,5536 bytes at 0000004472 bytes per second
    
    Running word stride read test...
    Read 65,5536 bytes at 0000008350 bytes per second
    
    Running long stride write test...
    Wrote 131,072 bytes at 0000006009 bytes per second
    
    Running long stride read test...
    Read 131,072 bytes at 0000016350 bytes per second
    
    Running speed writing test (512 bytes at a time)...
    Wrote 131,072 bytes at 0000008944 bytes per second
    
    Running speed reading test (512 bytes at a time)...
    Read 131,072 bytes at 0000250432 bytes per second
    
    Running append test... Success
    
    Running seek test... Success
    
    Deleting test file "testfile" ... Success
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit Zappman's Blog at Savage Circuits
  • KyeKye Posts: 2,200
    edited 2010-07-21 13:47
    Holy $%*& its alive! Its alive again!!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-07-21 14:08
    It lives every day on my Propeller boards!

    The perfect system for rapidly switching between hardcore MPM network programming and games. (Not necessarily in that order *grin*).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-07-29 03:12
    Hi,
    I'm hoping to use Kye's SD code in my project but I'm still a newbie on SPIN so I think I used the openFile wrongly. I think anyone could catch my mistake.

    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      _SD_DOPin = 0 
      _SD_DIPin = 2
      _SD_CKPin = 1
      _SD_CSPin = 3
    
    OBJ
    
      FAT : "SD2.0_FATEngine"
      NUM : "Numbers"
      STR : "C300M_STREngine"
      COM : "RS232_COMEngine"
    
    PUB Main
    
      com.COMEngineStart(31, 30, 115_200)
      waitcnt(clkfreq + cnt)
    
      ifnot(fat.FATEngineStart(_SD_DOPin, _SD_CKPin, _SD_DIPin, _SD_CSPin, _clockDataPin, _clockClockPin))
        reboot
    
      com.transmitString(fat.mountPartition(str.decimalToInteger(str.tokenizeString(0)), byte[noparse][[/noparse]str.tokenizeString(0)]))
      com.transmitString(string("Disk 0x"))
      com.transmitString(str.integerToHexadecimal(fat.checkDiskSignature, 8))                                               
      com.transmitString(string(" with volume ID 0x"))
      com.transmitString(str.integerToHexadecimal(fat.checkVolumeIdentification, 8))
      com.transmitString(string(" a.k.a "))
      com.transmitString(str.trimString(fat.checkVolumeLabel))
      com.transmitString(string(" ready", _newLineCharacter))
      waitcnt(clkfreq + cnt)
      '-----------------
      'It Mounted OK.
      '-----------------
    
      'Trying to open file
      com.transmitString(fat.openFile(str.tokenizeString(string("test001.txt")),"R")) 
      '-----------------
      'com showed nothing. Seems to be wrong?
      '-----------------
    
    
    



    From the original program, the parameter for str.tokenizeString is always "0". Does this means it points to the first variable declared in VAR (which is charactersPointer)?

    Thanks in advance.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ken

    Post Edited (MacTuxLin) : 7/29/2010 3:18:50 AM GMT
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-07-29 03:31
    I'm not 100% sure of the tokenize bit, but this is my open file for a new file that does not yet exist

    fat.openFile(fat.newFile(string("testfile")), "W")

    and for a file that already exists

    fat.openFile(string("testFile"), "R")

    see if one of those helps?

    also I don't think it is related as you say it mounts, but my mount code is shorter

    fat.mountPartition(0,0) ' mount the sd card

    though I think yours still has the same effect of producing zeros

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-07-29 03:46
    Thank you Dr_Acula! I did removed the tokenize but initially it didn't work. But re-looking at your example, I removed the ".txt" extension & now it worked! I don't know why so the openFile cannot work files with .3 extensions?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ken
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-07-29 04:08
    That is odd as my code does work with extensions. Anyway, if you can create a file and open it and close it then you can start testing things more thoroughly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
  • KyeKye Posts: 2,200
    edited 2010-07-29 04:13
    The tokenize string function is a special version of the standard C strtok function that is used to break strings up into pieces. My tokenize string funtion looks for white space characters to break the string up on. Unless you have use input that needs to be toeknized don't use it.

    http://www.cplusplus.com/reference/clibrary/cstring/strtok/

    ...

    Open file should have no problems with the .txt extension. I've used this function all the time to play .wav files and read .txt files. Since opening "test001" worked and not "test001.txt" this means that your file was not named "test001.txt" but "test001". The exension matters and is part of the name of the file. "stuff' and stuff.txt" can be two completely different files in one directory.

    Also note that my functions abort when they cannot process a request and return an error string. That said, you have no way to catch those failures in your code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-07-29 04:38
    blush.gif I'm so sorry!!! I named the extension wrongly on the SD card. My bad. After changing it, it worked!!! Thank you Kye & Dr_Acula. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ken
  • Jorge PJorge P Posts: 385
    edited 2010-07-29 09:10
    I am using the PPDB that has the DS1302, what do I need to change in order to use this RTC as opposed to the DS1307?

    I checked the code and the DS1307 needs only two pins and the ds1302 needs 3.· Is it safe to leave out the extra pin o the 1302?

    Thanks for the replies in advance.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    http://WhatsAvailable.org Software and Gadgets for Windows 7.
  • KyeKye Posts: 2,200
    edited 2010-07-29 14:20
    I don't know what the DS1302 needs to operate. You will need to find a driver for that thing yourself. If you look through the FATEngine you'll find a function called "readClock". Just replace all the references to the DS1307 there.

    Also, you'll need to remove the references to the DS1307 code in "FATEngineStart" and FATEngineStop" functions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • jmspaggijmspaggi Posts: 629
    edited 2010-07-29 14:59
    Hi Nyamekye,

    When I look at my card, it says VFAT. Is VFAT the same thing as FAT32? Or should I format it un FAT32 if I want to use it with your driver?

    Thanks,

    JM

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Linux? There is worst, but it's more expensive.
  • KyeKye Posts: 2,200
    edited 2010-07-29 19:14
    Don't know what VFAT is. If its not FAT32 or FAT16 my driver will refuse to mount the SD card an throw and erorr about the file system not being supported.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2010-07-29 20:31
    re:Is VFAT the same thing as FAT32

    From Q/A Wiki:
    (Virtual File Allocation Table) The file system used in Windows for Workgroups and Windows 95/98. It provided 32-bit Protected Mode access for file manipulation. VFAT was faster than, but also compatible with, the DOS 16-bit File Allocation Table (FAT). In Windows for Workgroups, VFAT was called "32-bit file access." In Windows 95/98, it supported long file names up to 255 characters.
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2010-07-29 20:36
    @Kye

    Wow! what a fantastic job you did developing all of this. I look forward to using it in a project. I like the recording features you added as well. cool.gif

    Thanks!

    Bob
  • Jorge PJorge P Posts: 385
    edited 2010-07-29 20:40
    Thanks for the info Kye, I'll give it a try and post back later.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    http://WhatsAvailable.org Software and Gadgets for Windows 7.
  • jmspaggijmspaggi Posts: 629
    edited 2010-07-30 01:42
    @Kye and @Bob: I just found that VFAT and FAT32 are the same thing. So it should works [noparse];)[/noparse]

    @Kye:
    Also, is it possible to open 2 files at the same time? Or do I have to close the first one before opening the second one?

    I'm just waiting for the SD reader from Parallax [noparse];)[/noparse] I really hope it will arrive soon. I want to test that?

    Also, regarding performances, is that faster that an EEPROM? Or is an EEPROM faster than the SD?

    Thanks,

    JM
  • KyeKye Posts: 2,200
    edited 2010-07-30 02:17
    The SD card is WAYYYYYYYYYYY faster than eeprom.

    Right now opening two files is not supported seemlessly. Unless you understand what you are doing to have two files open at once you will corrupt your SD card file system if you try to have two files open at once.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • jmspaggijmspaggi Posts: 629
    edited 2010-07-30 02:23
    Way faster? Wow. I have some EEPROMs linked to my propeller to store Strings I want to display, so look like I'm beter to move them on the SD...

    Regading the 2 files, will I corrupt the system even if everything is only on READ-ONLY mode? I just want to read an OGG file, and at the same time the catalogue to display the directory (or any other directory) content. Anyway, since you made the option to move in a file, I still can close one the time I look at the other, but I was just trying [noparse];)[/noparse]

    JM
  • jmspaggijmspaggi Posts: 629
    edited 2010-08-09 09:28
    Hi Kye,

    I tried your driver and I have one small issu.

    When I use it on my main loop, it's working perfectly. But when I'm trying to use it from a cog, listName call is never returning.

    Here is my code:
    CON
      _cardDataOutPin = 7
      _cardClockPin = 6
      _cardDataInPin = 5
      _cardChipSelectPin = 4
    
      _clockDataPin = 25
      _clockClockPin = 24
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    VAR
      long sd_stack [64]
      long volumeLabel
    OBJ
      fs : "SD2.0_FATEngine"
      sx : "FullDuplexSingleton"
      rtc: "DS1307_RTCEngine.spin"
    
    PUB start (lf_number)
      sx.start(31,30,0,115200)
    
      ifnot(rtc.RTCEngineStart(_clockDataPin, _clockClockPin))
        sx.str(string($d,"Not able to start the RTCEngine",$d))
        reboot
    
      ifnot(fs.FATEngineStart(_cardDataOutPin, _cardClockPin, _cardDataInPin, _cardChipSelectPin, _clockDataPin, _clockClockPin))
        sx.str(string($d,"Not able to start the FATEngine",$d))
        reboot
    
      volumeLabel := fs.mountPartition (0, 0)
      sx.str(string("Volume label: "))
      sx.str(volumeLabel)
      sx.str(string($d))
    
      sx.str(string("Changing directory to : "))
      sx.str(fs.changeDirectory(string("\")))
      sx.str(string($d))
    
      cognew (process, @sd_stack) ' Comment to run outside of the cof
      'process ' Uncomment to run outside of the cog
    
    PUB process  | index, fileName
      sx.str(string("Listing files...", $d))
      index := 0
      fs.listName("T")
      repeat
        fileName := fs.listName(0)
        sx.str(string("Read "))
        sx.str(fileName)
        sx.str(string(" Index="))
        sx.dec(index)
        sx.str(string(" strsize="))
        sx.dec(strsize(fileName))
        sx.str(string($d))
      until fileName == 0
      repeat ' Comment to run outside of the cog
    

    When I run that from a cog, I get a respons from fs.listName("T") then the next listName call never return. If I run that from the main, it's working fine.

    So I think I'm doing something wrong, but I'm working on that for 3 hours now with no result :(

    Any clue?

    Thanks,

    JM
  • jmspaggijmspaggi Posts: 629
    edited 2010-08-09 09:43
    I'm replying to myself ;)

    I found a way to have it working.

    I moved all my code into the cog instead of initializing the objects outside of the cog.

    Don't ask me why it's working that way, and not the other way, because I don't understaing anything here ;)

    Do I have a way to size the stack correctly?

    JM
    CON
      _cardDataOutPin = 7
      _cardClockPin = 6
      _cardDataInPin = 5
      _cardChipSelectPin = 4
    
      _clockDataPin = 25
      _clockClockPin = 24
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    VAR
      long sd_stack [256]
      long volumeLabel
    OBJ
      fs : "SD2.0_FATEngine"
      sx : "FullDuplexSingleton"
      rtc: "DS1307_RTCEngine.spin"
    
    PUB start (lf_number)
      cognew (process, @sd_stack) ' Comment to run outside of the cog
      'process ' Uncomment to run outside of the cog
    
    PUB process | index, fileName
      sx.start(31,30,0,115200)
    
      ifnot(rtc.RTCEngineStart(_clockDataPin, _clockClockPin))
        sx.str(string($d,"Not able to start the RTCEngine",$d))
        reboot
    
      ifnot(fs.FATEngineStart(_cardDataOutPin, _cardClockPin, _cardDataInPin, _cardChipSelectPin, _clockDataPin, _clockClockPin))
        sx.str(string($d,"Not able to start the FATEngine",$d))
        reboot
    
      volumeLabel := fs.mountPartition (0, 0)
      sx.str(string("Volume label: "))
      sx.str(volumeLabel)
      sx.str(string($d))
    
      sx.str(string("Changing directory to : "))
      sx.str(fs.changeDirectory(string("\")))
      sx.str(string($d))
    
      sx.str(string("Listing files...", $d))
      index := 0
      sx.str(string("Moving to the first entry.", $d))
      fs.listName("T")
      repeat
        sx.str(string("Reading next entry.", $d))
        fileName := fs.listName(0)
        sx.str(string("Read "))
        sx.str(fileName)
        sx.str(string(" Index="))
        sx.dec(index)
        sx.str(string(" strsize="))
        sx.dec(strsize(fileName))
        sx.str(string($d))
      until fileName == 0
      repeat ' Comment to run outside of the cog
    
  • KyeKye Posts: 2,200
    edited 2010-08-09 17:29
    Its probably working now because you made the stack larger.

    My stack size estimates included in my code are only estimates on about how many longs each function call takes. I base these estimates off a question I asked Chip back in a video fourm chat thingy last year.

    With the file system driver the stack needed gets very large for all the function calls.

    Oh, and are you usign the code from the OBEX? Its slightly better in handling wierd stuff like this.
  • jmspaggijmspaggi Posts: 629
    edited 2010-08-09 17:39
    Hi Kye,

    I'm not sure it's coming from the stack. Because it was not working, then I move the engine start into the cog and it was working. I just retried and figured that the issue is coming from the serial output I'm using. If I put it on the start method, it's not working. If I put it on the cog, it's working. All you Engine can be put in the start or in the cog and easy working fine in both cases ;)

    Also, I will only use read functions from your object. Do you think it's easy for someone quite new in SPIN to do some clean-up to remove all what is write related to save some space?

    BTW, did I already thanked you for this object? ;)

    JM
  • KyeKye Posts: 2,200
    edited 2010-08-09 17:48
    Thanks,

    You can comment out any function that doesn't cause the object to complain about compiling. If you get a compile error after commenting out a function then put that function back in.

    So, I included locking in the lowest level detail of the driver so that two or more cores won't have problems reading and writing sectors off the SD card. However, this doesn't protect the file system.

    So... if all your doing is reading... Then just avoid closing two files in the same directory at the same time or calling the disk free and used space functions.

    A freak accident can happen where if you close two files at the same time that are in the same directory... one of the files will have its last access time stamp corrupted.

    So, reading isn't really that bad. But if you were writing... oh boy. Stuff can go really wrong.

    I'm working on a new release that will solve this problem.
  • jmspaggijmspaggi Posts: 629
    edited 2010-08-09 18:11
    Ok, thanks.

    I will try to make a "lite" version of it ;)

    Also, I don't need to time stamp for the file. I'm doing an OGG reader so this information is not required for me. I will probably comment that too.

    So if I remove the last access time stamp, and all the write methodes, does it mean I can keep 2 files opened at the same time?

    Because I need to open 2 files in the same directory. The catalogue where I have the translation ShortName <=> LongName, and the musique file itself... I will try, and see if it's working, else, I will wait for the V2 of the driver ;) anyway, I took me the whole day just to find how to send the list of files from one cog to another one, you will be at the V99 when I will be ready to open the musique file ;)

    JM
Sign In or Register to comment.