P1 SD Minimal Boot Test for P2 ROM - Please test :)
Cluso99
Posts: 18,069
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...
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
I ordered an SD card breakout board today, so that I can try SD code out, too.
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.
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.
Activity Board WX (P22 - DO; P23 - CLK; P24 - DI/CD; P25 - /CS) 5MHz version
3 - 2GB Generic SD cards (Made in China) (Purchased used from Ebay).
Found another card, card passed, but its data looks a little different than the others:
RiData 2GB MicroSD card.
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.
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)
Maybe you could add a linux format howto to prepare the disk before doing the test?
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.
Samsung 32GB, Patriot 32 GB, Sony 16GB, Patriot 16GB, all passed. :thumb:
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.
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.
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.
The cards that have a speed number have it in parentheses in the filename, otherwise its listed as "x".
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.
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
Rather than sector numbers I thought I'd just reference the card in MB, so sector = MB << (20-9)