Shop OBEX P1 Docs P2 Docs Learn Events
P2 SD-Carte FAT32 — Parallax Forums

P2 SD-Carte FAT32

Hello,

is there actually already a FAT32 SD card driver.
On the github I have found nothing for the P2.

Comments

  • RaymanRayman Posts: 14,754

    For Spin2 there is a fsrw that works. Also, @Cluso99 posted a driver.

    FlexC has FatFs working and built in.

  • Cluso99Cluso99 Posts: 18,069

    If you're familiar with Kyes' FatEngine for FAT32, I converted it for P2.
    It works when using my SD Driver and the ROM serial, but when I added in external serial support it all broke and I haven't had the time to find the problem even tho I've tried on numerous attempts.
    You're welcome to try and find the bug(s) - prelim code is posted in my RetroBlade2 thread
    https://forums.parallax.com/discussion/comment/1512317/#Comment_1512317

    And there are some older versions in this thread
    https://forums.parallax.com/discussion/171600/propeller-2-os-its-alive-and-cpm2-2-is-running/p1

  • pic18f2550pic18f2550 Posts: 400
    edited 2021-03-08 12:01

    I have just downloaded the OS228c.spin2.

    If I see it correctly, it is made for a CP/M system?

    How do I get in and out of a subdirectory with the _FAT32.spin2?

  • pic18f2550pic18f2550 Posts: 400
    edited 2021-03-08 12:40
    VAR
      long  tmp
      long  data[512]
    
    OBJ
      fat0      : "_FAT32"
    
    PUB main()
    {}
        tmp := fat0.FATEngineStart()
        tmp := fat0.mountPartition(0)
    {Verzeichnis wechseln}
    
    {Datei öffnen}
        tmp := fat0.openFile(string("test0.spin2"),"R")
        tmp := fat0.fileSize()
    
    {Daten lesen}
        repeat (tmp/512)
          tmp := fat0.readData(@data,512)
    
    {alles wieder Schließen}
        tmp := fat0.closeFile()
        tmp := fat0.unmountPartition()
        tmp := fat0.FATEngineStop()
    
    DAT
    
    
  • Cluso99Cluso99 Posts: 18,069

    @pic18f2550 said:
    I have just downloaded the OS228c.spin2.

    If I see it correctly, it is made for a CP/M system?

    How do I get in and out of a subdirectory with the _FAT32.spin2?

    I don't recall all the routines provided by the FAT32 driver, but IIRC there is a call to change the directory.

    What you're looking at is a version that also can do the interfacing to the CPM files on the SD card. The DIR etc commands are in a terrible state :( I was just trying to get something working to start verifying the FAT32 was working correctly before I split the OS back into separate files.

    Sorry, I don't have the time to debug what's wrong just now. But I can answer questions if you want to give it a go. Once the FAT32 is running properly I will be able to get the whole OS running quite quickly with time permitting.

  • I don't need the listing of the directory (DIR).
    What I am looking for is the directory change.
    CD directory
    CD ..
    CD .
    Time is a fleeting element :)
    Hardly seen, it is already gone.

  • Cluso99Cluso99 Posts: 18,069

    @pic18f2550 said:
    I don't need the listing of the directory (DIR).
    What I am looking for is the directory change.
    CD directory
    CD ..
    CD .
    Time is a fleeting element :)
    Hardly seen, it is already gone.

    Surely you could look at the FAT32 source? Here it is

    PUB changeDirectory(directoryPathName) : result
    
  • Excuse me, I think I need new ashtrays. I think mine are a bit too cloudy.

    Do I have to call each subdirectory individually or can I specify them all at once.

    "Directory" or "Directory1/Directory2

    What about relative and absolute path specifications.

    CD directory next subdirectory
    CD /Directory Directory under main directory

  • das letztere, also der komplette pfad, so ".." does not work you need to track the current path by yourself

    Gruss,

    Mike

  • pic18f2550pic18f2550 Posts: 400
    edited 2021-07-14 10:53

    Which maximum transfer rates are possible in larger files when writing software-wise? > 1Mbyte -> 8MBit?

  • Way below for me. I would need 5MBit. Not by a far stretch possible. I get maybe a few 100KBit/s. This is not a driver issue (at least not superficially). The SD-Card enforces several 100ms long pauses. I guess that’s the wear leveling kicking in.

  • All the current P2 SD drivers use single block commands. Using multiblock commands is trickier (and less efficient when seeking a lot), but gets rid of the access latency, allowing approach of the theoretical 49 Mbit/s limit

  • The map should simply be written from sector 0. That is, without a file system.
    I just need to cache a lot of data.

  • Cluso99Cluso99 Posts: 18,069

    My SD Driver supports raw sector mode. It’s unravelled code so it’s fast (IIRC it’s 4 instructions per bit so 8 clocks) but currently does not support block mode (multi sector read/write).
    Note that SD Cards do slow things down significantly due to internal processing.

  • I think the best attempt with SD drivers was done by @lonesock in the SD-Spi-Block-driver used by FSRW on the P1.

    It does write-behind and read-ahead.

    Basically if you write a sector from HUB to SD the driver just gets it from HUB into COG and then clears its mailbox to signal success so that the main program (the caller) can continue wile the driver is writing the sector to SD. That uses the parallel processing power better then having the main program wait until the sector is actual written to SD.

    On reading it is even nicer, it checks if it already has the sector, if yes copies it from COG to HUB, if not reads it from SD, copies to the HUB, clears the mailbox to signal success and read the NEXT sector in case you might need it next.

    This decouples the SD access from the HUB<->COG transfer.

    On the P2 one could use the LUT to cache 4 sectors...

    Mike

  • Hello,

    I have looked at the connection of the SD card.
    Here only the SPI interface is used.

    Is there also an example where the SD interface is used?
    So where DAT0..DAT3, CMD and CLK is used.

    A clock diagram would also be useful.

  • As far as I know nobody did a NON SPI interface neither on P1 or P2.

    The problem seems to be that 4 pin connection requires CRC on all pins or something alike.

    In SPI mode you can switch off CRC calculations.

    And there is also a problem with 4 bit mode requiring a license and money to even get the description.

    So chances are slim for that.

    Enjoy!

    Mike

  • RaymanRayman Posts: 14,754

    Licensing requirement for 4-bit mode has always seemed a bit murky to me...

    But, it looks like (according to Wikipedia) that the simplified spec. now covers SDIO and is free.
    Or, you could base you driver off the Linux driver that is also free.

  • A while back with the P1V code base I tried adding a 4-bit SD mode interface for SD cards in Verilog attached as a peripheral for the P1 core. I found various snippets of information about 4 bit mode here and there online and had to do a lot of reverse engineering of drivers and other bits and pieces related to clock timing etc but in the end I was able to get CMD and DAT transfers working for reading, and could read SD card registers etc, and was about to start on the write side work but then moved over to the P2. There is probably more information out there these days but as to the licensing side I'm not sure (so don't ask me for my code).

    I think the P2 could probably do 4 bit SD mode with a little bit of effort, and hopefully in a single COG (two COGs would probably be a little wasteful IMO). It would be interesting to see how fast we could transfer to/from an SD card.

  • I believe from what i read that you could use the streamer for the transfer so it would boil down to doing the CRC as fast as possible so maybe ~ 300 Mbits/sec @200Mhz

  • RaymanRayman Posts: 14,754

    I think the crc that I did for eMMC should work for sdio too

Sign In or Register to comment.