Shop OBEX P1 Docs P2 Docs Learn Events
New SD mode P2 accessory board - Page 18 — Parallax Forums

New SD mode P2 accessory board

1151618202130

Comments

  • evanhevanh Posts: 16,023
    edited 2024-10-13 03:14

    I guess I should fix that before looking at A2 extensions. EDIT: Not that I can test it. I think even my oldest full sized SD card was HC from the start. It'll be theoretical support until someone else can test it.
    EDIT2: Ah, no, I have one 2GB miniSD card in an adaptor, that was pushed on me at the time. It would have been my second flash card purchased after the rather expensive 2GB Compact Flash in the DSO.

  • evanhevanh Posts: 16,023
    edited 2024-10-18 23:43

    Here's the untested support for SDSC (up to 2 GB capacity) cards.
    Install instructions - https://forums.parallax.com/discussion/comment/1562218/#Comment_1562218
    PS: Make sure you put this in the sdfatfs directory. Not the fatfs directory.
    EDIT: I can see this as an accident waiting to happen. Maybe a new file name is in order ...
    EDIT2: Okay, renamed and a couple of comment clean ups. Also improved the tester program to perform mounting steps before first fopen().
    EDIT3: Added a 500 ms timeout to power-down step of power cycling.
    EDIT4: Separated init debug messages from performance debug messages
    EDIT5: for()-loop compiler bug workaround
    EDIT6: Fixed a bug in speedtester's file verify routine

  • evanhevanh Posts: 16,023
    edited 2024-10-13 07:38

    Huh, there's quite a generational style difference in the extensions in the SDv6 spec. All the documentation up to SDv3 is big-endian oriented, but that flips to little-endian thinking with the extensions. Clearly, new blood arrived in between.

    EDIT: The cache setting bits aren't very well documented. It doesn't mention what command or register names are being worked with. It's just these etherial bit and byte numbers.

    EDIT2: Looks like everything is via commands 48 and 49:

  • RaymanRayman Posts: 14,744

    @evanh does your code work with dat0 on P40?

  • evanhevanh Posts: 16,023

    @Rayman said:
    @evanh does your code work with dat0 on P40?

    Yep. Tested now with bases P16, P32, P40 and P48. All four runs behaved the same.
    Eg:

       clkfreq = 360000000   clkmode = 0x10011fb
    Filesystem = fatfs,  Driver = sdsdcard
     Clock divider for SD card is 3 (120 MHz)
    mount: OK
     Buffer = 2 kB,  Written 2048 kB at 1018 kB/s,  Verified,  Read 2048 kB at 8767 kB/s
     Buffer = 2 kB,  Written 2048 kB at 602 kB/s,  Verified,  Read 2048 kB at 8484 kB/s
     Buffer = 2 kB,  Written 2048 kB at 881 kB/s,  Verified,  Read 2048 kB at 8792 kB/s
     Buffer = 2 kB,  Written 2048 kB at 1026 kB/s,  Verified,  Read 2048 kB at 8795 kB/s
    
     Buffer = 4 kB,  Written 2048 kB at 1260 kB/s,  Verified,  Read 2048 kB at 14006 kB/s
     Buffer = 4 kB,  Written 2048 kB at 773 kB/s,  Verified,  Read 2048 kB at 14675 kB/s
     Buffer = 4 kB,  Written 2048 kB at 1671 kB/s,  Verified,  Read 2048 kB at 14637 kB/s
     Buffer = 4 kB,  Written 2048 kB at 1691 kB/s,  Verified,  Read 2048 kB at 14605 kB/s
    
     Buffer = 8 kB,  Written 4096 kB at 2496 kB/s,  Verified,  Read 4096 kB at 22331 kB/s
     Buffer = 8 kB,  Written 4096 kB at 1709 kB/s,  Verified,  Read 4096 kB at 21591 kB/s
     Buffer = 8 kB,  Written 4096 kB at 1646 kB/s,  Verified,  Read 4096 kB at 22253 kB/s
     Buffer = 8 kB,  Written 4096 kB at 2546 kB/s,  Verified,  Read 4096 kB at 22349 kB/s
    
     Buffer = 16 kB,  Written 4096 kB at 3833 kB/s,  Verified,  Read 4096 kB at 31268 kB/s
     Buffer = 16 kB,  Written 4096 kB at 3794 kB/s,  Verified,  Read 4096 kB at 31143 kB/s
     Buffer = 16 kB,  Written 4096 kB at 3838 kB/s,  Verified,  Read 4096 kB at 31125 kB/s
     Buffer = 16 kB,  Written 4096 kB at 3827 kB/s,  Verified,  Read 4096 kB at 31144 kB/s
    
     Buffer = 32 kB,  Written 8192 kB at 2535 kB/s,  Verified,  Read 8192 kB at 34186 kB/s
     Buffer = 32 kB,  Written 8192 kB at 4693 kB/s,  Verified,  Read 8192 kB at 34237 kB/s
     Buffer = 32 kB,  Written 8192 kB at 4908 kB/s,  Verified,  Read 8192 kB at 34109 kB/s
     Buffer = 32 kB,  Written 8192 kB at 4942 kB/s,  Verified,  Read 8192 kB at 34030 kB/s
    
     Buffer = 64 kB,  Written 8192 kB at 8186 kB/s,  Verified,  Read 8192 kB at 34223 kB/s
     Buffer = 64 kB,  Written 8192 kB at 8366 kB/s,  Verified,  Read 8192 kB at 34325 kB/s
     Buffer = 64 kB,  Written 8192 kB at 8385 kB/s,  Verified,  Read 8192 kB at 34206 kB/s
     Buffer = 64 kB,  Written 8192 kB at 8351 kB/s,  Verified,  Read 8192 kB at 34111 kB/s
    
     Buffer = 128 kB,  Written 16384 kB at 5140 kB/s,  Verified,  Read 16384 kB at 33851 kB/s
     Buffer = 128 kB,  Written 16384 kB at 6512 kB/s,  Verified,  Read 16384 kB at 34109 kB/s
     Buffer = 128 kB,  Written 16384 kB at 12764 kB/s,  Verified,  Read 16384 kB at 34181 kB/s
     Buffer = 128 kB,  Written 16384 kB at 12851 kB/s,  Verified,  Read 16384 kB at 34127 kB/s
    
     Buffer = 256 kB,  Written 16384 kB at 17342 kB/s,  Verified,  Read 16384 kB at 34209 kB/s
     Buffer = 256 kB,  Written 16384 kB at 15338 kB/s,  Verified,  Read 16384 kB at 34169 kB/s
     Buffer = 256 kB,  Written 16384 kB at 6697 kB/s,  Verified,  Read 16384 kB at 33920 kB/s
     Buffer = 256 kB,  Written 16384 kB at 17022 kB/s,  Verified,  Read 16384 kB at 34175 kB/s
    
    exit
    

    And with debugging:

       clkfreq = 360000000   clkmode = 0x10011fb
    Filesystem = fatfs,  Driver = sdsdcard
     Clock divider for SD card is 3 (120 MHz)
     Set pins: CLK_PIN=45 CMD_PIN=44 DAT_PIN=40 POW_PIN=47 LED_PIN=46
    mount: OK
     Card detected ... power cycle of SD card
      power-down threshold = 37   pin state = 1
      power-down slope = 27030 us   pin state = 0
      power-up threshold = 209   pin state = 0
      power-up slope = 1095 us   pin state = 1
     SD clock divider set to sysclock/900.  'rxlag' compensation is 0
    Card idle OK
     OCR register c0ff8000  - SDHC/SDXC Card
    Data Transfer Mode entered - Published RCA 00010000
    4-bit data interface engaged
     BlockReadError:  blocks=1  err=0  crc=0000bc83  CRC failed! Cache (A2 extension) supported = no
     BlockReadError:  blocks=1  err=0  crc=0000bc83  CRC failed! High-Speed access mode engaged
    CID register backed up
     SD clock divider set to sysclock/3.  'rxlag' compensation is 0
    . CMD10 error! 
    . CMD10 error! 
    .
    .
    .
    ................................................................................
    ................................................................................
    ................................................................................
    . CMD10 error!   rxlag=7 selected  Lowest=6 Highest=8
      SD clock divider 3 (120 MHz)
    CID decode:  ManID=1D   OEMID=AD  Name=USD
      Ver=2.0   Serial=000003A0   Date=2024-1
    SD Card Init Successful
     RD0 138022  RD800 138723  RD801 138990  RD7cc0 139290  WR7cc0 139578 ...
    
  • @evanh said:
    Huh, there's quite a generational style difference in the extensions in the SDv6 spec. All the documentation up to SDv3 is big-endian oriented, but that flips to little-endian thinking with the extensions. Clearly, new blood arrived in between.

    EDIT: The cache setting bits aren't very well documented. It doesn't mention what command or register names are being worked with. It's just these etherial bit and byte numbers.

    EDIT2: Looks like everything is via commands 48 and 49:

    Yes, all CMD49. Kind of funny that you need to send 511 dummy bytes to set one bit.

    Also, fun fact about the SD spec: You can get rid of the watermark by disabling it in the "Layers" menu (at least in Okular)

  • evanhevanh Posts: 16,023
    edited 2024-10-13 12:03

    Yeah, Okular doesn't remember the setting though. It doesn't bug me anyway.
    And it doesn't work for secured PDFs either, so useless on the whole. EDIT: Or maybe its lacking layers or something. Whatever it is it doesn't always work.

  • Yeah, some watermarks are just not broken like that. Also note the "Obey DRM limitations" checkbox in settings, gets around any "security" without futzing.

  • RaymanRayman Posts: 14,744

    Seems my setup is failing to read the first block in 4 bit mode, no matter clock speed. Only thing I can think of is the series resistor, but that seems like a stretch…

    Also, guess I have all pull-ups in fet side were you have one on the rail. Could that matter?

  • evanhevanh Posts: 16,023
    edited 2024-10-13 13:45

    I've updated the files at top of this page.

    @Rayman said:
    Seems my setup is failing to read the first block in 4 bit mode, no matter clock speed. Only thing I can think of is the series resistor, but that seems like a stretch…

    It's a lock-up too isn't it? That's not supposed to be possible there. The SE2 wait has a timeout so it can't be that one. That means it's somehow getting stuck on a WAITSE1. Which is the smartpin complete event of clocking.

    Also, guess I have all pull-ups in fet side were you have one on the rail. Could that matter?

    The red activity LED doesn't matter at all. It's purely for visuals.

  • roglohrogloh Posts: 5,837

    @Rayman said:
    Seems my setup is failing to read the first block in 4 bit mode, no matter clock speed. Only thing I can think of is the series resistor, but that seems like a stretch…

    Also, guess I have all pull-ups in fet side were you have one on the rail. Could that matter?

    When it's all powered up and source+drain are at the same voltage it shouldn't matter as much, but the SD card could be getting parasitically powered prior to FET enable through these pullups on the P2 supply side which isn't ideal. Not a clean way to start up.

    At low speeds the missing series resistor is probably not so important but could be when the data is clocked faster. Maybe try lowering the P2 clock speed if you can with evanh's code.

  • evanhevanh Posts: 16,023

    Try setting-D NOREADBLOCKCRC on the compile line. Or commenting out the #define SD_BLOCK_CRC in the driver. That changes the read blocks structure notably.

  • RaymanRayman Posts: 14,744

    @evanh Definitely happier with that define commented out...
    This is what get now:

    mount: OK                                                                       
    Tester...                                                                       
    opening...                                                                      
    opening file speed1.bin                                                         
    memset done...                                                                  
    doing f_open..                                                                  
      mounting volume                                                               
    Going high speed                                                                
    reading buffer                                                                  
    Verifying                                                                       
    CID register backed up                                                          
      disk inited 0                                                                 
      finding volume                                                                
      checking fs   format 2                                                        
      volume found 0                                                                
      volume mounted 0                                                              
    Create or open res = 4                                                          
      f_open returned 0                                                             
    open...                                                                         
     Buffer = 2 kB,    clkfreq = 100000000   clkmode = 0x100090b                    
     Clock divider for SD card is 4 (25 MHz)                                        
    open sdcard: using pins: 44 45 40 39 52                                         
    mount fail: Device or resource busy                                             
    
    exit 
    

    Some of this output may be stuff I added...
    Probably should revert to original version and try again...

  • RaymanRayman Posts: 14,744

    Guess the layout could be wrong as never used all four data pins before... Going to triple check that...

  • evanhevanh Posts: 16,023

    Updated the driver in the zip file at top of page again.

  • RaymanRayman Posts: 14,744

    @evanh what version of flexprop are you using?

    Something very strange going on with tx_datablock( )...
    Seems to go off the rails after the first __asm block...

  • RaymanRayman Posts: 14,744

    Tried old Flexprop, no joy.
    Added series resistors, still not working.

    Is not working at all with block CRC a sign that something is wrong?

  • evanhevanh Posts: 16,023
    edited 2024-10-13 22:31

    I haven't updated flexspin in a while: Version 7.0.0-beta-v6.9.7-62-g0917374f Compiled on: Jul 12 2024
    I'll park that idea without some more evidence first though.

    Grab the driver at the top of this forum page. It has the block performance debugging option that I used for examining the behaviour of the filesystem. Uncomment the #define SD_DEBUG_PERFORMANCE That'll tell us if any blocks are read or written successfully.

    PS: The diskio.h file is also updated in the zip file, That's to handle the renamed driver.

  • RaymanRayman Posts: 14,744
    edited 2024-10-13 23:01

    Any chance it’s the way the card was formatted?

    Are your cards formatted with windows?

    Isn’t the files posted here for drives <2 gb?

  • evanhevanh Posts: 16,023

    @evanh said:
    I haven't updated flexspin in a while: Version 7.0.0-beta-v6.9.7-62-g0917374f Compiled on: Jul 12 2024
    I'll park that idea without some more evidence first though.

    Actually looks pretty quiet on the compiler changes front. Eric has been working on new feature not yet ready and has been busy at his work.
    Since July, looks like just the littlefs changes and float_to_int bounding change.

    I've now updated to very latest master branch: Version 7.0.0-beta-v6.9.7-67-g479049f9 Compiled on: Oct 14 2024

  • evanhevanh Posts: 16,023

    @Rayman said:
    Any chance it’s the way the card was formatted?

    Are your cards formatted with windows?

    That's a good reason to look at the filesystem's block access sequence.

    Isn’t the files posted here for drives <2 gb?

    Nope, I don't have any uSD cards that small to test with. I added the ability but it's still to be tested.

  • evanhevanh Posts: 16,023
    edited 2024-10-13 23:42

    @evanh said:

    @evanh said:
    I haven't updated flexspin in a while: Version 7.0.0-beta-v6.9.7-62-g0917374f Compiled on: Jul 12 2024
    I'll park that idea without some more evidence first though.

    Actually looks pretty quiet on the compiler changes front. Eric has been working on new feature not yet ready and has been busy at his work.
    Since July, looks like just the littlefs changes and float_to_int bounding change.

    I've now updated to very latest master branch: Version 7.0.0-beta-v6.9.7-67-g479049f9 Compiled on: Oct 14 2024

    Oh! Actually, there was a fix Eric did for me not that long ago. It's in the v7.0.0 fixes list. It was a misbehaviour of for() loops when using an unsigned control variable. You'll need to update to newest Flexspin compiler on top of the newest Flexprop IDE.

    Here it is https://forums.parallax.com/discussion/comment/1560438/#Comment_1560438 fixed early July.

    EDIT: On second thoughts. There is only a single for() loop in the entire driver. It can happily be changed to using signed integers. I'll do that ... done.

  • evanhevanh Posts: 16,023
    edited 2024-10-14 14:57

    [Note to self] include/libc/stdio/fwrite.c modified (removal of fflush() call) to better streamline use of SD cache extension.

  • size_t fwrite(const void *ptr, size_t size, size_t n, FILE *f)
    {
        size *= n;
        fflush(f);
        return _vfswrite(f, ptr, size);
    }
    

    ??? why does it flush the file before writing? That makes no sense and seems like it would destroy performance when doing small-sized writes. It does the same thing in fread. Why?

  • RaymanRayman Posts: 14,744

    @evanh It's the same story:

       clkfreq = 100000000   clkmode = 0x100090b                                    
    Filesystem = fatfs,  Driver = sdsdcard                                          
     Clock divider for SD card is 3 (33 MHz)                                        
     Set pins: CLK_PIN=44 CMD_PIN=45 DAT_PIN=40 POW_PIN=39 LED_PIN=46               
     Card detected ... power cycle of SD card                                       
      power-down threshold = 37   pin state = 1                                     
      power-down slope = 12861 us   pin state = 0                                   
      power-up threshold = 209   pin state = 0                                      
      power-up slope = 1049 us   pin state = 1                                      
     SD clock divider set to sysclock/250.  'rxlag' compensation is 0               
    Card idle OK                                                                    
     OCR register c0ff8000  - SDHC/SDXC Card                                        
    Data Transfer Mode entered - Published RCA aaaa0000                             
    4-bit data interface engaged    
    
  • RaymanRayman Posts: 14,744

    Like before, does better with blockcrc off:

    Cache (A2 extension) supported = no                                             
    High-Speed access mode engaged                                                  
    CID register backed up                                                          
     SD clock divider set to sysclock/3.  'rxlag' compensation is 0                 
    . CMD10 error!                                                                  
    . CMD10 error!                                                                  
    ................................................................................
    ................................................................................
    ................................................................................
    . CMD10 error!   rxlag=4 selected  Lowest=3 Highest=5                           
    CID decode:  ManID=03   OEMID=SD  Name=SC128                                    
      Ver=8.0   Serial=1C4D0732   Date=2020-3                                       
    SD Card Init Successful                                                         
    mount sd: Unknown error                                                         
     Clear pins: 44 45 40 39 46                                                     
    
    exit                                                                            
    
    
  • RaymanRayman Posts: 14,744

    No idea why blockcrc doesn't work here.
    But was poking around the previous code and see that seems to have trouble finding the FAT volume.
    It does find the MBR signature, but then gets lost...

  • evanhevanh Posts: 16,023

    Rayman,
    Turn on SD_DEBUG_PERFORMANCE so we can see if any blocks are successful. It looks like nothing is working because it can't even read the MBR.

  • evanhevanh Posts: 16,023

    @Wuerfel_21 said:
    ??? why does it flush the file before writing? That makes no sense and seems like it would destroy performance when doing small-sized writes. It does the same thing in fread. Why?

    Heh, I'm glad you're surprised by that too.

  • RaymanRayman Posts: 14,744

    Does seem to get further with a Mac formatted disk:

      SD clock divider set to sysclock/4.  'rxlag' compensation is 0                 
    . CMD10 error!                                                                  
    ................................................................................
    ................................................................................
    ................................................................................
    ................................................................................
    . CMD10 error!   rxlag=3 selected  Lowest=2 Highest=5                           
    CID decode:  ManID=03   OEMID=SD  Name=SA08G                                    
      Ver=8.0   Serial=17A32AA1   Date=2024-2                                       
    SD Card Init Successful                                                         
    mount sd: OK                                                                    
    fopen returning 11314 state=6                                                   
     Buffer = 2 kB, v_flush() !   
    
Sign In or Register to comment.