Shop OBEX P1 Docs P2 Docs Learn Events
P1 SD Minimal Boot Test for P2 ROM - Please test :) — Parallax Forums

P1 SD Minimal Boot Test for P2 ROM - Please test :)

Cluso99Cluso99 Posts: 18,069
edited 2017-11-10 21:15 in Propeller 1
SD Boot Test for P1 v111

I would be really pleased if any of you can test the attached code on any SD/microSD cards that you may have.
SanDisk cards seem to work the best, although I have tried all sorts of cards.

The code is compiled for 5MHz*PLL16 (80MHz) and uses P0=DI, P1=CLK, P2=DO, P3=/CS. PST is used as a terminal on the PC.
Let me know if you require any other builds (crystal or SD pins).

Output is logged to the PST terminal screen and may be copied by CTL-C and pasted into Notepad or the forum.

Would you mind trying any cards you have and post the results to this thread. I am particularly interested in any failures. There is quite a complete diagnostic for me to see where it failed.

We are trying to validate the code for inclusion into the P2 ROM so that we can boot directly to SD Card if the user/designer wishes.

Here is a sample of the output...
SD testing v111
SD card type: 3 = SDHC/SD V2(block)  (passed)
4404: CS1 CLK0 ;
4408: CS1 CLK0  0 00000040 00000000 00000095 000000FF (1) 00000001 ;
4430: CS1 CLK0  8 00000048 000001AA 00000087 000000FF (1) 00000001 000001AA ;
445C: CS1 CLK0 55 00000077 00000000 00000087 000000FF (1) 00000001 ;
4484: CS0 CLK0 41 00000069 40000000 00000087 000000FF (1) 00000000 (7) (43736 clocks) 0ms ;
44BC: CS1 CLK0 58 0000007A 00000000 00000087 000000FF (1) 00000000 C0FF8000 ;
44E8: CS1 CLK0 16 00000050 00000200 00000087 000000FF (1) 00000000 ;
4510: CS1 CLK0  9 00000049 00000000 00000087 000000FF (1) 00000000 000000FF (1) 000000FE ;
4548:      (16 bytes) CRC: 0000008B 0000008F ;
4558: CS1 CLK0 10 0000004A 00000000 00000087 000000FF (1) 00000000 000000FF (1) 000000FE ;
4590:      (16 bytes) CRC: 00000062 000000D1 ;
45A0: CS1 CLK0 17 00000051 00000000 00000087 000000FF (1) 00000000 000000FF (348) 000000FE ;
45D8:     (512 bytes) CRC: 0000003B 00000084 ;
45E8: CS1 CLK0 17 00000051 00000001 00000087 000000FF (1) 00000000 000000FF (166) 000000FE ;
4620:     (512 bytes) CRC: 00000000 00000000 ;
4630: <eof>      (815700 clocks) 8ms
CSD register...
0000: 40 0E 00 32 5B 59 00 00 3B 7F 7F 80 0A 40 00 09  @..2[Y..;....@..
CID register...
0000: 12 56 78 41 53 54 43 00 34 00 00 14 6C 01 03 5B  .VxASTC.4...l..[
MBR/VBR sector 0 ...
0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 82  ................
01C0: 03 00 0B E6 DC CA 00 20 00 00 00 E0 ED 00 00 00  ....... ........
01D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA  ..............U.
Valid MBR
proposed use--> 01AE: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
PTN 0: Typ=$0B  01BE: 00 82 03 00 0B E6 DC CA 00 20 00 00 00 E0 ED 00  ......... ......
PTN 1: Typ=$00  01CE: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
PTN 2: Typ=$00  01DE: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
PTN 3: Typ=$00  01EE: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
VOL sector 1 ...
0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................

Comments

  • cgraceycgracey Posts: 14,153
    Great, Cluso99!

    I ordered an SD card breakout board today, so that I can try SD code out, too.
  • Cluso99Cluso99 Posts: 18,069
    In my reading on SD cards, one of the articles says that a pullup is required on DO for some cards. I haven't ever used this and don't recall a card requiring it. Just mentioning here so we don't forget if we find cards that we cannot read.

    The code has a very complete set of routines for SPI read/write of commands and data sector/registers. I have been careful not to drive this at full speed as it's a boot loader we want to guarantee to work. We can load a better/faster one subsequently if desired.

    BTW Chip, I realised my cards have been booting faster the first time, because my board has an eeprom sd booter in it that attempts to initialise the card before I can get in to do it by download. I will have to enable the eeprom to overwrite it. Note some SD cards can take 100's of ms to initialise.
  • Cluso99Cluso99 Posts: 18,069
    Chip,
    FWIW code size without sector buffer...
    Code initialisation ~100 longs
    Subroutines ~100 longs
    Pre-initialised working registers ~25
    Un-initialised working registers ~30
    This includes some debug instructions and registers which will come out.
  • I need a build for the Activity Board WX (P22 - DO; P23 - CLK; P24 - DI/CD; P25 - /CS)
  • Cluso99Cluso99 Posts: 18,069
    Mike,
    Activity Board WX (P22 - DO; P23 - CLK; P24 - DI/CD; P25 - /CS) 5MHz version
  • Activity Board WX Rev A with generic 2GB (MicroCenter) card:
  • Propeller Board of Education with 8GB SanDisk card
  • Propeller Board of Education with 64GB SanDiskUltra card

  • Activity Board (Not WX) Rev A.

    3 - 2GB Generic SD cards (Made in China) (Purchased used from Ebay).
  • Activity Board (Not WX) Rev A.

    Found another card, card passed, but its data looks a little different than the others:

    RiData 2GB MicroSD card.
  • Cluso99Cluso99 Posts: 18,069
    Thanks guys :)

    I am out so cannot check the data right now. As long as they pass, it's all good.
    The different sector data will depend on whether boot code was written or not, even though the boot is not used much any more.
  • Cluso99Cluso99 Posts: 18,069
    Here is a quick summary so far...
    All 15 cards passed
    Only 6 are SanDisk
    9 are #3 (V2 block mode), 5 are #2 (V2 byte mode), 1 unknown( 1GB SanDisk missing top log section)
    All contain Partition data in the MBR/Sector 0
    12 contain 00's in the rest of the MBR, except 2 with pre-partition block $1AE with data, 3 contain some form of boot data
    13 contain 00's in sector 1, and 2 contain FF's
    1 is 1GB is unknown version
    5 are 2GB and V2(byte mode)
    9 are 4-32GB and V2(block mode)
  • I'd like to be of assistance But I did not try anything yet. Do the sdcards have to be formatted in a special way or does the test format the card itself?
    Maybe you could add a linux format howto to prepare the disk before doing the test?
  • Cluso99Cluso99 Posts: 18,069
    edited 2017-11-12 23:04
    The test program only initialises the SD Card, reads the CSD and CID registers, and reads sectors 0 & 1.
    No writes are done.

    Do not do anything to prepare the SD card. I am interested in whether it works (initialises and reads), and what data is on sectors 0 & 1.

    Just download the binary into the P1 propeller and run as you would normally do on whatever OS you use (Windoze, Linux, MacOS). You will need to run a terminal program immediately to catch the output.
    eg Ctl-F10 followed by F12 in PropTool/Windows.

    Thanks.
  • Cluso99Cluso99 Posts: 18,069
    Finally had a chance to re-test all my microSD cards. Results attached.

  • Cluso99Cluso99 Posts: 18,069
    Here is a summary of the cards tested...
    SD%20Cards%20V111.jpg
    688 x 453 - 117K
  • These are from the Prop BOE, same pinout as the Activity Board WX program you made Mike: (P22 - DO; P23 - CLK; P24 - DI/CD; P25 - /CS).
    Samsung 32GB, Patriot 32 GB, Sony 16GB, Patriot 16GB, all passed. :thumb:
  • Cluso99Cluso99 Posts: 18,069
    Thanks DrProp.
    I am interested to know for these larger cards, whether they are marked SDHC or SDXC and if they have a Class "Cnn" and/or "Un" speed, please.
  • DrPopDrPop Posts: 227
    edited 2017-11-14 16:19
    Cluso99 wrote: »
    Thanks DrProp.
    I am interested to know for these larger cards, whether they are marked SDHC or SDXC and if they have a Class "Cnn" and/or "Un" speed, please.

    They are all Class 10; Micro SD HC I, with the little symbol of a U with a 1 inside.
    The Sony 16GB card says 40MB/s; the others don't list a speed on them, but the Samsung 32GB is the EVO version and even faster.
    Hope that helps a little! If you want smaller cards tested, I can dig up them up if I still have them. :smile:
  • Cluso99Cluso99 Posts: 18,069
    I am going to bump this thread as I would love to see more test results.

    What I am seeing is that the MBR (sector 0) is rarely used, other than for the Partition Blocks.
    Similarly, sector 1 is rarely used either.
    This is confirmed by some manufacturers card specs too.
  • Cluso99 wrote: »
    I am going to bump this thread as I would love to see more test results.

    What I am seeing is that the MBR (sector 0) is rarely used, other than for the Partition Blocks.
    Similarly, sector 1 is rarely used either.
    This is confirmed by some manufacturers card specs too.

    I can confirm that just from experience, in fact a properly formatted card always has a few meg totally unused (and inaccessible to the PC) before the start of the FAT32 partition, and I do mean unused, except for mandatory MBR partition information in sector 0. Cameras should format a card correctly, just as Panasonic's SD formatter software does too, but WIndows nor Linux does not AFAIK as it does not leave this SD optimizing gap. An SD card after all is not just serial Flash, it has a controller that tries to manage it as best as it can.

    BTW, any pre-SDHC card such as 2GB cards etc should be lumped in with the floppies, they are irrelevant for any new design and work differently anyway since SDHC addresses blocks, not bytes.

  • Cluso99Cluso99 Posts: 18,069
    Peter,
    I detect SD & SDHC cards V2.0 in byte or block mode correctly, so there are no problems here. It is simple enough to support both, and the extra code is minimal.

    There were no old V1.0 SD cards tested. I did find a bug in my code although it has not caused any problems so far. I had been trying to minimise the code as far as possible, and make the subroutines as usable as possible to make the commands as simple to use as possible, with generic calling methods.
  • Here are results for 8 cards in the 64M to 32G range with their info in the file name. (The 64M is an older card I had lying around; all the others are 1G or larger).

    The cards that have a speed number have it in parentheses in the filename, otherwise its listed as "x".
  • Cluso99Cluso99 Posts: 18,069
    Thanks David. I will check when I get home later.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2017-11-22 04:54
    Here is a cluster map of the first 40 or so megabytes of a 64G SD card, just to give you an idea. Each character in the dump represents 32KB so each line is 2MB. A * indicates non-zero data present. Of the first 32kB there is only the partition table in sector 0.
    TAQOZ$ 0 $20000 SDMAP2
     $00.0000: *...............................................................
     $00.1000: ................................................................
     $00.2000: ................................................................
     $00.3000: ................................................................
     $00.4000: ................................................................
     $00.5000: ................................................................
     $00.6000: ................................................................
     $00.7000: ................................................................
     $00.8000: *...............................................................
     $00.9000: ................................................................
     $00.A000: ................................................................
     $00.B000: ................................................................
     $00.C000: *...............................................................
     $00.D000: ................................................................
     $00.E000: ................................................................
     $00.F000: ................................................................
     $01.0000: *...*...*...*.......*...*...*...*...****........................
     $01.1000: ........................*.......................................
     $01.2000: ............*****...*******.*...********************************
     $01.3000: ****************************************************************
     $01.4000: ****************************************************************
     $01.5000: ****************************************************************
     $01.6000: *********...*...............*...*...*...*...********************
     $01.7000: ****************************************************************
     $01.8000: ****************************************************************
     $01.9000: **********************************..*...*.......................
     $00.0000: *...............................................................
     $00.1000: ................................................................
     $00.2000: ................................................................
     $00.3000: ................................................................
     $00.4000: ................................................................
     $00.5000: ................................................................
     $00.6000: ................................................................
     $00.7000: ................................................................
     $00.8000: *...............................................................
     $00.9000: ................................................................
     $00.A000: ................................................................
     $00.B000: ................................................................
     $00.C000: *...............................................................
     $00.D000: ................................................................
     $00.E000: ................................................................
     $00.F000: ................................................................
     $01.0000: *...*...*...*.......*...*...*...*...****........................
     $01.1000: ........................*.......................................
     $01.2000: ............*****...*******.*...********************************
     $01.3000: ****************************************************************
     $01.4000: ****************************************************************
     $01.5000: ****************************************************************
     $01.6000: *********...*...............*...*...*...*...********************
     $01.7000: ****************************************************************
     $01.8000: ****************************************************************
     $01.9000: **********************************..*...*.......................
    
  • Cluso99Cluso99 Posts: 18,069
    Yes Peter. That's precisely my expectations.

    With ~256B (~64 instructions) we can get enough to determine where to load more code from, by utilising the ROM subroutines already loaded in the boot code.

    With this method, we will not care what format the SD card has. And we can cover any future standard.

    I am hoping I might be able to have the MBR code workable for both P2 and P1 :)

    FWIW FAT32 will work to 1TB cards, and they are probably 5 years out. So that means they should be readily available (new) for +10 years after that.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2017-11-23 01:17
    In regards to the "free space" do take into account that it is common for SD cards to be optimized for FAT file systems and that free space comes with a price, namely acces time. Take a look at some sector timings just to give you an idea. While the first random sector may take a little longer it usually means that the next sequential sector normally in the same cluster is available sooner.

    Here I create a simple sector timing word S and then pass sector numbers to it interactively to discover sector timings. The read data is at 10MHz rate so it only accounts for around 500us, the rest of the time is the latency for the SD controller to have that sector ready. Notice too that I calculate the sector number for 2MB and 4MB boundaries and the difference in timings is huge. Attempting sequential sector reads in the 4000 range does not improve the poor timings. The 5.5us time is simply reflecting the fact that the sector has already been buffered which must be the same as the FAT boot sector (not MBR).

    EDIT: It gets worse in other sections too, have a look at the bottom of the post
    TAQOZ# : S LAP SECTOR LAP .ms ;  ok
    TAQOZ# 0 S 921.0us ok
    TAQOZ# 1 S 921.0us ok
    TAQOZ# 4000 S 4.523ms  ok
    TAQOZ# 4001 S 4.527ms  ok
    TAQOZ# 4002 S 4.195ms  ok
    TAQOZ# 8000 S 1.181ms  ok
    TAQOZ# 8001 S 986.800us ok
    TAQOZ# 2000 S 4.724ms  ok
    TAQOZ# 2001 S 4.531ms  ok
    TAQOZ# 2 mb 9 >> . 4096 ok
    TAQOZ# .FAT
    Mounted 7803.AA00-F84E.1690          NO NAME     FAT32   4,119MB (32,768/cluster)
     ok
    TAQOZ# 4 MB 9 >> . 8192 ok
    TAQOZ# 8192 S 5.500us ok
    TAQOZ# 8193 S 936.400us ok
    TAQOZ# 8194 S 958.800us ok
    

    TAQOZ# 8192 SECTOR SDBUF $80 DUMP
    00.F200: EB 3C 90 20 20 20 20 20 20 20 20 00 02 40 54 18    .<.        ..@T.
    00.F210: 02 00 00 00 00 F8 00 00 3F 00 80 00 00 20 00 00    ........?.... ..
    00.F220: 00 C8 7A 00 D6 03 00 00 00 00 00 00 02 00 00 00    ..z.............
    00.F230: 01 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00.F240: 80 01 29 90 16 4E F8 4E 4F 20 4E 41 4D 45 20 20    ..)..N.NO NAME
    00.F250: 20 20 46 41 54 33 32 20 20 20 00 00 00 00 00 00      FAT32   ......
    00.F260: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00.F270: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................ ok
    


    Rather than sector numbers I thought I'd just reference the card in MB, so sector = MB << (20-9)
    TAQOZ# : M  11 << S ;  ok
    TAQOZ# 16 M 922.400us ok
    TAQOZ# 32 M 5.734ms  ok
    TAQOZ# 64 m 790.800us ok
    TAQOZ# 128 M 4.136ms  ok
    TAQOZ# 256 M 790.800us ok
    TAQOZ# 512 M 790.800us ok
    TAQOZ# 1024 M 989.600us ok
    TAQOZ# 2048 M 989.600us ok
    TAQOZ# 2048 M 5.500us ok
    TAQOZ# 3800 M 989.600us ok
    TAQOZ# : S++   @sector @ 1+ S ;  ok
    TAQOZ# S++ 789.400us ok
    TAQOZ# S++ 789.400us ok
    TAQOZ# S++ 789.400us ok
    TAQOZ# 32 M 5.538ms  ok
    TAQOZ# S++ 5.536ms  ok
    TAQOZ# S++ 5.203ms  ok
    TAQOZ#
    
Sign In or Register to comment.