Shop OBEX P1 Docs P2 Docs Learn Events
How does the P2's SD card work? — Parallax Forums

How does the P2's SD card work?

Hello everyone,
I'm back to ask for your help with a rather complex problem.
I'm using Propeller 2.9.3 as my IDE and coding in Spin 2.
My problem is as follows:
I have built a system that reads sensors and records the values, which are pressure differentials. Using these differentials, I am able to calculate a total of three speed values (the operations and calculations are performed using the P2X8C4M64P EVAL board).
My specifications required me to transmit the data via UART, which I was able to do fairly easily, but there has been a new request that I am having trouble fulfilling. I am being asked to retrieve the calculated values via the SD card port located on the board.
Despite my research, I haven’t found any tools in the library to help me execute the SD functions, and while searching the forum, I only found code that doesn’t work with my IDE, so I’m currently unable to switch IDEs.
my actuel code is below . Oh and I'm French, so the comments in my code are in French

Comments

  • RaymanRayman Posts: 16,240
    edited 2026-04-07 12:44

    Well I’d probably recommend this new driver:
    https://forums.parallax.com/discussion/178033/p2-usd-card-driver-fat32-filesystem-spin2-pasm2/p1

    But you mentioned want to use prop tool as ide…. That might not work directly but you can code in prop tool and then use pnut for final compile and testing.

    The other option might be FSRW from OBEX . Get the latest version that has a bashed3 low level driver. Use that instead of bashed2 in the zip. That should work.

    https://obex.parallax.com/obex/frsw-and-fat32-for-p2/

    Was just thinking about posting an FSRW usage update…. Might be a good time, before new driver makes it obsolete…

  • RaymanRayman Posts: 16,240

    Think the new driver is based on this one
    https://obex.parallax.com/obex/fat32-sd-card-driver/

    That might be another option

  • JonnyMacJonnyMac Posts: 9,791
    edited 2026-04-07 15:10

    so I’m currently unable to switch IDEs.

    You're at a very big disadvantage using Propeller Tool -- Parallax stopped development on it long ago and its version of the P2 compiler is very old. When you can, switch to Spin Tools IDE which is compatible with the latest version of the PNut (P2) compiler, but in an environment that looks-and-feels like a nicer version of Propeller Tool. It will also allow you to link to external compilers like PNut and FlexProp.

    I use a Propeller Tool compatible version of FSRW that Ray and others updated to the P2. My need is raw speed, and other uSD driver are slower than the P2 update of FSWR (I don't need long file names or folders). I made a very small touch-up to the mount() method because the return value is being used to note the card type; I had to reset the return value back to 0 after this test to get the proper result from a good mount..

    The attached demo looks like this in Propeller Tool:

    And like this in Spin Tools:

    Since timing seems to be important, there are lots of little things you can do to claw back a few microseconds here and there. For example, these routines:

    PRI uart_u16_le(x)
      ' envoie d'un word 16 bits en little-endian (LSB puis MSB)
      uart.tx(x & $FF)
      uart.tx((x >> 8) & $FF)
    
    PRI uart_u32_le(x)
      ' envoie d'un long 32 bits en little-endian
      uart.tx(x & $FF)
      uart.tx((x >> 8) & $FF)
      uart.tx((x >> 16) & $FF)
      uart.tx((x >> 24) & $FF)
    
    PRI uart_s32_le(x)
      uart.tx(x & $FF)
      uart.tx((x >> 8) & $FF)
      uart.tx((x >> 16) & $FF)
      uart.tx((x >> 24) & $FF)
    
    PRI uart_rx_u32_le() : x | b0, b1, b2, b3
      b0 := uart.rx()
      b1 := uart.rx()
      b2 := uart.rx()
      b3 := uart.rx()
    
      x := b0 | (b1 << 8) | (b2 << 16) | (b3 << 24)
    

    ...will run a bit faster (and are easier to read) like this:

    pri uart_u16_le(x)
    
      uart.tx(x.byte[0]) 
      uart.tx(x.byte[1]) 
    
    
    pri uart_u32_le(x)
    
      uart.tx(x.byte[0]) 
      uart.tx(x.byte[1]) 
      uart.tx(x.byte[2]) 
      uart.tx(x.byte[3]) 
    
    
    pri uart_s32_le(x)                                              ' redundant
    
      uart.tx(x.byte[0]) 
      uart.tx(x.byte[1]) 
      uart.tx(x.byte[2]) 
      uart.tx(x.byte[3]) 
    
    
    PRI uart_rx_u32_le() : result
    
      result.byte[0] := uart.rx()
      result.byte[1] := uart.rx()
      result.byte[2] := uart.rx()
      result.byte[3] := uart.rx() 
    
  • RaymanRayman Posts: 16,240

    @JonnyMac Thanks. BTW: @evanh has found some issues with low level drivers and fixed sdspi_bashed2.spin2 with sdspi_bashed3.spin2.

    Could be that bashed2 was developed a very long time ago when everybody was using clock speed <200 MHz. Guess there was a busy check missing that caused issues with higher clock speeds...

    Don't think he fixed up spdsp_asm_mb2.spin though. Maybe because the speed advantage wasn't worth using a cog, not sure.

    Anyway, if there are issues with "sdspi_asm_mb2", then would highly recommend using "sdspi_bashed3" instead.

    obj  'low level SPI objects   'Note:  Pick one of these
    
        'sdspi: "sdspi_bashed2" 'doesn't use a cog (inline assembly) but not quite as fast.  Use this for drives 2GB or less.
        'sdspi: "sdspi_asm_mb2" 'this version uses a cog and is fastest,  now compatible with Kye code
        'sdspi: "sdspi_with_audio"  'adds audio output to "sdspi_asm_mb2"
        sdspi: "sdspi_bashed3" 'new fixes from @Evanh
    
  • Anyway, if there are issues with "sdspi_asm_mb2", then would highly recommend using "sdspi_bashed3" instead.

    Where can I find that? I've not had any issues thus far, but I'd rather user updated code if available -- especially as I'm close to a product release that uses ra_fsrw.spin2.

  • RaymanRayman Posts: 16,240
    edited 2026-04-07 15:53

    https://obex.parallax.com/obex/frsw-and-fat32-for-p2/

    It needs an update badly for some examples and how to also use low level driver with FAT32 for more features...

  • Sorry, I should have deleted that post -- I found it with a quick web search. Connected to it and edited per my style (a bit); seems to read a bit faster which is good. I will try it with audio today.

Sign In or Register to comment.