Shop OBEX P1 Docs P2 Docs Learn Events
P2 SD card code test... — Parallax Forums

P2 SD card code test...

Cluso99Cluso99 Posts: 18,069
edited 2020-01-03 04:17 in Propeller 2
Attached is a test program for SD Cards. I would appreciate testing this on your SDHC cards formatted as FAT32.

I compiled it with FlexGUI v4.0.6 and downloaded it with LoadP2 v4.0.6 using the windoze command prompt window/program.

It runs on the P2-EVAL Rev B with Rev B silicon and RevA with RevA silicon. (All switches OFF)
It should run on the P2D2 Rev A provided a 10K pullup resistor is connected to pin 25 as it self-identifies the P2-EVAL and P2D2.

It runs at 160MHz.

Below is a sample of the expected output. There is a further debug that can be enabled for SD cards that fail the test (see line 497 of the spin code).

I am particularly interested that SDHC cards are detected (the program will error is you use an old card that uses byte mode addressing), and
That the SD-DO pin reports as being Hi.

Your dump of the sector will be different!
The checkpoints are just prior to that command being sent to the SD card.

SD204%20test.jpg
675 x 835 - 156K

Comments

  • Cluso99Cluso99 Posts: 18,069
    The routines...
    Initialise
    ReadCSDCID
    ReadSector
    WriteSector
    are all callable. At the end of each of these, the pins are tristated, and a successful result is NC and Z.

    I have these routines almost ready to replace the PASM code drivers that we used in P1 where it ran in its own cog. Kye’s spin code will need converting tho.
  • blew the dust of my P2A and download the flexgui code. Compiled and ran the code. Got nothing.

    Mike
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-01-03 11:34
    Did the download work?

    Once loaded and running the first thing it does is initialise the serial port and output the P2-EVAL or P2D2 message and this occurs before the SD card code runs.

    I presume you don’t have anything connected to P25?

    I just power my board from the USB port (the serial port) as my PC supplies power just fine.

    I’ll post the little bat file i use to compile and load and run tomorrow.
  • I think the key is to make sure to use the -SINGLE option when loading this binary (-CHIP was not successful in providing output)...
    Results from my P2-EVAL Rev B:
    SD204Output.png

    My python load script does this:
    return_code = subprocess.call("loadp2 -p /dev/cu.usbserial-DN43WMDD -b 115200 -l 115200 -t -SINGLE " + fn, she$
    

    dgately
    602 x 620 - 487K
  • Cluso99Cluso99 Posts: 18,069
    Thanks.

    Yes, you need the -SINGLE option.

    What may not have been obvious from my screenshot is that f406 is flexgui v4.0.6 renamed and similarly l406 is loadp2.
  • Your test program seems to run fine here on my Rev B board with two different SDHC cards (an 8 GB Sony and a 16 GB nextech).

    BTW, the reason that loadp2 -CHIP doesn't work is that there's a typo in the loadp2 fast loader code which causes all of memory to be erased at load time, including the debug area (it was not supposed to touch memory above $7c000, but it does). You can avoid this by passing -NOZERO to loadp2, or, obviously, -SINGLE.

    I hadn't realized that -SINGLE doesn't clear RAM but apparently it doesn't -- in the course of testing this I wrote a little program to poke data into HUB and it persists across loads with -SINGLE.
  • evanhevanh Posts: 15,916
    Oh, I think I'd prefer -CHIP to not clear hubRAM by default, same as -SINGLE. If a program wants hubRAM cleared then it can do so itself.
  • I tried this from FlexGui 4.0.6 but there is something weird going on

    Without an SD card loaded, it runs with passes various checkpoints, null data
    ( Entering terminal mode.  Press Ctrl-] to exit. )
       Auto Detected P2EVAL
    Initialise
    Checkpoint 0
    Checkpoint 0
    Checkpoint 0
    Checkpoint 0
    Checkpoint 0
    Checkpoint 0
    Checkpoint 0
    Checkpoint 0
    Checkpoint 0
    Checkpoint 0
    ***error*** 00000040
    *
    


    When I put a Sandisk Ultra 16GB card in the slot, it doesn't run.
    SD204.binary failed to load
    Error response was ""
    Press enter to continue...
    

    There may be a .bix on the card that takes it down a different path?? Should that matter?
  • I later tried a 64 G samsung that seemed to work, so maybe its just that card or something on it.
    Note I have formatted some of my cards with non default cluster sizes
  • Tubular wrote: »

    When I put a Sandisk Ultra 16GB card in the slot, it doesn't run.
    SD204.binary failed to load
    Error response was ""
    Press enter to continue...
    

    There may be a .bix on the card that takes it down a different path?? Should that matter?

    I would think that if it boots from the card then it won't be possible to load anything via serial, which would explain the "binary failed to load" message.
  • Yeah I think you're right. I'll dig deeper but it might be on Monday
  • Cluso99Cluso99 Posts: 18,069
    It will not work if there is a boot program on the SD (_BOOT_P2.BIX or .BIY or in the boot sector 0 or VOL).

    Checkpoint is not a "PASS" but rather that will now be tested, Your card failed the very first command (checkpoint 0 = command 0).
    Of course, since there is no SD card, it will fail command 0. Perhaps I need to check for pullup on SD_CS (from the card). I don't need to do this in the ROM because when I get passed control from Chip's booter he has already confirmed that there is a pullup (ie a card).

    Different cluster sizes should be fine.
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-01-04 14:52
    This is my F.BAT file for assembling P2 code
    F406.exe is fastspin.exe v4.0.6 renamed
    L406.exe is loadp2.exe v4.0.6 renamed
    f406 %1.spin -2 -l
    l406 %1.binary -b115200 -t -SINGLE
    
    Note that I call my .spin2 files .spin as I still edit with PropTool.
  • Flexgui still does not work. I type: flexgui SD204.spin -2 -1

    I get "Error in startup scrip".

    To load the binary I used bin\loadp2 SD204.binary -b115200 -t -SINGLE

    program completes normally and works just fine.
       Auto Detected P2EVAL
    Initialise
    Checkpoint 0
    Checkpoint 8
    Checkpoint 55
    Checkpoint 41
    Checkpoint 55
    Checkpoint 41
    Checkpoint 55
    Checkpoint 41
    Checkpoint 55
    Checkpoint 41
    Checkpoint 55
    Checkpoint 41
    Checkpoint 55
    Checkpoint 41
    Checkpoint 58
    Checkpoint 16
    SD-DO pin high
    Success
    SDHC card
    Read CSD+CID
    Checkpoint 9
    Checkpoint 10
    SD-DO pin high
    Success
    Read sector
    Checkpoint 17
    SD-DO pin high
    

    Mike
  • iseries wrote: »
    Flexgui still does not work. I type: flexgui SD204.spin -2 -1

    I get "Error in startup scrip".

    I think @Cluso99 mistyped; he meant "fastspin" rather than "flexgui". flexgui is the graphical interface; fastspin is the actual compiler. Also, that second argument is probably a lower case L rather than the digit 1 (not sure from the font which you typed). It's the fastspin flag to produce a listing file and is optional anyway, only the "-2" (for P2 output) really matters.
  • Cluso99Cluso99 Posts: 18,069
    Sorry, yes it’s fastspin :(
  • Great, just trying to get this to work for those that may want to try it on there own.

    Mike
  • Cluso99Cluso99 Posts: 18,069
    You will also notice the autodetection of P2-EVAL vs P2D2 which must have a pullup on P25 (and nothing on P2-EVAL P25)
  • Cluso99 wrote: »
    You will also notice the autodetection of P2-EVAL vs P2D2 which must have a pullup on P25 (and nothing on P2-EVAL P25)

    The P2D2 doesn't have any pull-ups on any ports under P56 where P56,57 are I2C. There must be a better way to check for hardware and so detecting pullups on these two pins might help.
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-01-05 01:48
    Peter,
    I added the pullup on P25 because it was easy to plug a pullup resistor into my P2D2 as i have female pins on my board. IIRC 3V3 is 0.3 or 0.4” away from P25 making it easy to plug in a pullup.
    I couldnt see any other easy way to do an auto test.
Sign In or Register to comment.