Shop OBEX P1 Docs P2 Docs Learn Events
Can't use a SD when booted from flash [solved in driver v. 2.71] — Parallax Forums

Can't use a SD when booted from flash [solved in driver v. 2.71]

pik33pik33 Posts: 2,350
edited 2021-02-28 07:14 in Propeller 2

I try to init a SD card using Cluso's driver v. 2.70

If a program boots from the serial port, it works
If it boots from the flash, it doesn't work ("I" command fails)
If I use "write flash" command in Propeller Tool, it writes the flash and then starts OK, and inits the SD (=works)

Do I have to do something after booting from the flash and before starting a SD driver (pin dirs, levels, tell the flash (how?) to switch off, etc?) to get the access to the SD card?

DIP switches on the board are set at 1100 (reset on, flash on, P59 up off, P59 down off)

Comments

  • In your flash program, add some more flash clock cycles, as per this info

    https://forums.parallax.com/discussion/comment/1465384/#Comment_1465384

    Various cards need 0, +1, +2 extra clock cycles in order to have the flash release its SO line, allowing subsequent card boot. One card I tested wouldn't release no matter how many extra clocks I gave it

  • Cluso99Cluso99 Posts: 18,069
    edited 2021-02-28 04:00

    Try this v271.
    I don't expect any differences, but I've...

    • FLTH #SD_DO (pin 58)
    • I = Initialise twice so lots of clocks

    If this doesn't work I could try sending some clocks to the Flash chip with its' CS=1.

    Or before you call the SD Driver you can do this yourself. Just use the Flash pins instead

    '+-----------------------------------------------------------------------------+
    '+      Send >74 clocks with /CS=1 & DI=1 starting & ending with CLK=0         +
    '+-----------------------------------------------------------------------------+
    _SDInit         call    #_enable_pins                   ' outputs:/CS=1 CLK=0 DI=1
                    rep     @.rep,#(96*2)                   '                                          
                    outnot  #sdx_ck                         '\ CLK=0-->1-->0                           
                    waitx   ##delay5us                      '/ 5us @20MHz 100KHz (20MHz/100KHz/2-2=98)
    .rep                                                    ' /CS=1 & CLK=0 (idle)        
    '>>>>>> insert   RET   here             
    '+-----------------------------------------------------------------------------+                     
    '+      Enable SD I/O Pins                                                     +                      
    '+-----------------------------------------------------------------------------+                    
    _enable_pins    drvh    #sdx_cs                         ' /CS=1 & output
                    drvl    #sdx_ck                         ' CLK=0 & output
                    drvh    #sdx_di                         ' DI =1 & output
                    flth    #sdx_do                         ' DO =1 & input
                    mov     SDX_bitout,      #0             ' OUTB: /CS=0 CLK=0 DI=0 
                    waitx   #20                             ' delay 20 clocks (was 5us)
                    RET
    '+-----------------------------------------------------------------------------+                    
    
  • Cluso99Cluso99 Posts: 18,069

    FWIW The P2 boot protocol will (depending on pullup settings) try out the flash first (it reads the flash looking for an checksum equiv) and if it's not found the boot code then passes control to my ROM SD driver which will boot correctly.

    Therefore, there is something being left incorrectly, or not cleared down correctly, as Flash and SD can co-exist on the shared pins. So this is solvable!

  • pik33pik33 Posts: 2,350
    edited 2021-02-28 09:00

    2.71 works.


    Edit: Booting from flash always works - tested on 2 different cards.

    A side effect occurs while booted from serial and using 32 GB Sandisk card: if, after mounting, I read something from the card, it mounts every second reboot (mounted at the first reboot after inserting the card, then not mounted-mounted-not mounted-mounted...
    I don't know yet if it really doesn't mount or it mounts, and returns the error code: to be tested.

    A cheaper 32 GB card mounts every time, so this behavior depends on the card,

  • Cluso99Cluso99 Posts: 18,069

    Thanks.
    OK we need to find out if the changes I did to v271 is fixing an SD problem, or as a consequence, fixing a flash problem.

    I'm curious to know which of the two changes I did to 271 fixed the problem.

    These are the two changes I did (both 1 liners)
    I added a second line
    call #_SDInit

    '+-----------------------------------------------------------------------------+
    cmd_I       call    #_SDInit                    ' initialise sd card
                call    #_SDInit                    ' initialise sd card (twice)
                jmp     #done
    '+-----------------------------------------------------------------------------+
    

    And I added an extra line
    flth #sdx_do

    '+-----------------------------------------------------------------------------+                    
    _enable_pins    drvh    #sdx_cs                         ' /CS=1 & output
                    drvl    #sdx_ck                         ' CLK=0 & output
                    drvh    #sdx_di                         ' DI =1 & output
                    flth    #sdx_do                         ' DO =1 & input
                    mov     SDX_bitout,      #0             ' OUTB: /CS=0 CLK=0 DI=0 
                    waitx   #20                             ' delay 20 clocks (was 5us)
                    RET
    '+-----------------------------------------------------------------------------+                    
    

    Perhaps you could try both by disabling each line?

  • Cluso99Cluso99 Posts: 18,069
    edited 2021-02-28 12:36

    Please note I have not verified the “X” command. It will cause a problem if the mailbox location gets overwritten with the loaded code/data because at the conclusion of the X it will clear parts of the mailbox which effectively overwrites the loaded code/data.

    This is why I need to be able to place the mailbox at the top of hub ram.
    Or, change my code to stop after an X. I can see that I’ll require two different commands, a “L” to load and “X” to load and execute. In P1 I prevented loading over the top of hub where the OS interface mailboxes were.

  • pik33pik33 Posts: 2,350

    I used "I", "R" and "W" only so far.

    2.70 never worked for me after booting from the flash, simply changing the file to 2.71 made it work.

    I tried to comment out double init and flth, in 2.71 and it still works. Maybe I am too tired now and I am doing something wrong.

Sign In or Register to comment.