Shop OBEX P1 Docs P2 Docs Learn Events
Problem Mounting SD Card — Parallax Forums

Problem Mounting SD Card

EquinoctumEquinoctum Posts: 4
edited 2012-07-22 15:07 in Propeller 1
I am new to propeller and have been trying to make a barebones SD card reader. However, I am having issues mounting the SD card using FSRW 2.6. Attached is the circuit diagram and the file I have been using to test. Power and ground are drawn from a BoeBot board.

I have repetitively checked the connections for shorts and incorrect wiring, and have remade boards. I have tried using different propeller chips, prop plugs, and connecting the SD card to different pins. I am using a SanDisk 2GB Class 2 SD card, formatted Fat 16 (tried both quick and full formatting). On a Windows 7 x64 OS, I have tried using different USB cables and updating the VCP drivers. I have also tried running on Windows XP x32.

Every time I run the program I fail to mount.

Any insight would be greatly appreciated.
580 x 808 - 77K

Comments

  • LeonLeon Posts: 7,620
    edited 2012-07-21 19:55
    Here is the schematic of a little PCB I made for using an SD card with a Proto Board:

    http://www.leonheller.com/Propeller/miniSD%20BO/miniSD%20BO%20sch.pdf

    Here is the PCB layout:

    http://www.leonheller.com/Propeller/miniSD%20BO/miniSD%20BO%20Layout.GIF

    I used a Yamaichi NMS011-2000-1 card connector from RS Components (493-2052).

    It works OK with the FSRW 2.6 software.
  • EquinoctumEquinoctum Posts: 4
    edited 2012-07-21 23:03
    Thanks for the quick reply, Leon. Unfortunately, I am still failing to mount with the schematic you provided. I also tried running the code on different xtal and pll. Some show 'fail to mount' while others display nothing or faulty text on the serial terminal.
    Leon wrote: »
    Here is the schematic of a little PCB I made for using an SD card with a Proto Board:

    http://www.leonheller.com/Propeller/miniSD BO/miniSD BO sch.pdf

    Here is the PCB layout:

    http://www.leonheller.com/Propeller/miniSD BO/miniSD BO Layout.GIF

    I used a Yamaichi NMS011-2000-1 card connector from RS Components (493-2052).

    It works OK with the FSRW 2.6 software.
  • pik33pik33 Posts: 2,413
    edited 2012-07-22 00:33
    Check yor connections (bad solder etc), then check your pin assignment. Try to use Kye's driver http://obex.parallax.com/objects/619/ instead of fsrw. Maybe a 100 µF capacitor soldered directly to SD socket will help (as it helped for me when I had problems with reliable SD card mounting - I have my SD connected directly to Propeller without any resistors, only this 100 µF capacitor between Vdd and Vss)
  • LeonLeon Posts: 7,620
    edited 2012-07-22 01:01
    Have you tried a different card connector?
  • EquinoctumEquinoctum Posts: 4
    edited 2012-07-22 03:03
    Pin assignment is correct and all the connections appear to be good. Kye's driver gives the error light. The SD card still does not mount after adding a 100uF capacitor between Vss and Vdd.

    I have also tried making different card connectors, and using various combinations of with/without 10k pull-up resistors.
  • LeonLeon Posts: 7,620
    edited 2012-07-22 03:36
    The only think left seems to be your software. I used test.spin:
    '
    '   Copyright 2009  Tomas Rokicki and Jonathan Dummer
    '
    '   See end of file for terms of use.
    '
    '   This object does some basic tests, first functional,
    '   then speed.  It will potentially destroy the data on the card, although
    '   only if the card has more than a few megabytes of data (we write random
    '   junk at the 8MB point).  So please try to run it on a freshly formatted
    '   card.
    '
    obj
       term: "sysdep"
       block: "safe_spi"
       'block: "mb_spi" ' this *must* match what is in the sdfat object
       'block: "mb_rawb_spi"
       'block: "sb_rawb_spi"
       sdfat[2]: "fsrw"'
    CON
       _clkmode        = term#_clkmode
       _xinfreq        = term#_xinfreq
       offset = 8 * 2048 ' the block offset of where we do writes
    var
       long speedresults[24]
       long sr
       long maxdur
       byte bigbuf[8192]
    pub go | x
       maxdur := 2 ' the max duration in seconds; keep below 10sec to avoid clock wrap
       maxdur *= clkfreq
       x := \start
       term.str(string("Erroneously returned from start!", 13))
       term.dec(x)
       term.tx(13)
    pub start_block_layer : retval | i
      retval := \block.start_explicit(term#sd_DO, term#sd_CLK, term#sd_DI, term#sd_CS)
      if retval < 0
        term.str( string( 13, "Mount failed spectacularly!", 13, "Command => Response", 13 ) )
        {
        i := block.get_log_pointer
        repeat while byte[i] <> 0
          term.dec( byte[i++] & 63 )
          term.str( string( " => "  ) )
          term.dec( byte[i++] )
          term.tx( 13 )
        }
        abort( retval )
    pub stop_block_layer
       block.stop
    pub start
       term.start
       repeat
          sr := 0
          term.str(string(13, "Waiting for key press to start tests", 13))
          term.rx
          ' if these fail, comment out the next line
          mounttests
          rawspeed
          fsrwspeed
          sdfat.unmount
          term.str(string("Repeating all the speed results:", 13))
          showallspeed
          term.str(string("All done!", 13))
    pub error(s)
       term.str(s)
       abort(-1234)
    pub mounttests | r, startcnt, bytes, n, duration, i
       term.str(string("Mount tests first", 13))
       term.str(string("First mount.", 13))
       start_block_layer
       term.str(string("Succeeded; stopping cog.", 13))
       stop_block_layer
       term.str(string("Second mount.", 13))
       start_block_layer
       term.str(string("Succeeded.", 13))
       term.str(string("Reading block 0 (should be a boot block)", 13)) 
       bytefill(@bigbuf, 0, 512)
       block.readblock(0, @bigbuf)
       term.str(string("Read finished; checking for boot block signature", 13))
       if !(bigbuf[510] == $55 and bigbuf[511] == $aa)
          error(string("boot block signature not found",13))
       term.str(string("Boot block checks out; unmounting", 13))
       stop_block_layer
       term.str(string("Third mount.", 13))
       start_block_layer
       term.str(string("Succeeded.", 13))
       term.str(string("Reading block 0 again (should still be a boot block)", 13)) 
       bytefill(@bigbuf, 0, 512)
       block.readblock(0, @bigbuf)
       term.str(string("Read finished; checking for boot block signature", 13))
       if !(bigbuf[510] == $55 and bigbuf[511] == $aa)
          error(string("boot block signature not found",13))
       term.str(string("Boot block checks out; writing it back", 13))
       block.writeblock(0, @bigbuf)
       term.str(string("Write finished; unmounting", 13))
       stop_block_layer
       term.str(string("Fourth mount.", 13))
       start_block_layer
       term.str(string("Succeeded.", 13))
       term.str(string("Reading block 0 again (should still be a boot block)", 13)) 
       bytefill(@bigbuf, 0, 512)
       block.readblock(0, @bigbuf)
       term.str(string("Read finished; checking for boot block signature", 13))
       if !(bigbuf[510] == $55 and bigbuf[511] == $aa)
          error(string("boot block signature not found",13))
       stop_block_layer
       term.str(string("Block layer seems to check out", 13))
       return
    pub showspeed(b) | duration, bytes
       duration := long[b][1]
       bytes := long[b][2]
       term.str(long[b][0])
       term.tx(" ")
       term.dec( (bytes + 512) / 1024 )
       term.str(string(" kB in "))
       term.dec(duration/(clkfreq/1000))
       term.str(string(" ms at "))
       term.dec(bytes/(duration/(clkfreq/1024)))
       term.str(string(" kB/s",13))
    pub addspeed(s, dur, n)
       speedresults[sr++] := s
       speedresults[sr++] := dur
       speedresults[sr++] := n
       showspeed(@speedresults[sr-3])
    pub showallspeed | s
       term.str(string(13, "Clock: "))
       term.dec(clkfreq)
       term.str(string(" ClusterSize: "))
       term.dec(sdfat.getclustersize)
       term.str(string(" ClusterCount: "))
       term.dec(sdfat.getclustercount)
       term.tx(13)
       repeat s from 0 to sr-3 step 3
          showspeed(@speedresults[s])
    pub rawspeed | r, startcnt, bytes, n, duration, ptr
       start_block_layer
       term.str(string("Now speed tests", 13))
    
       ' NOTE: SOME CARDS CAN NOT HANDLE A WRITE BEFORE A READ!!
       ' (not an issue for fsrw, we always read block 0 first thing)
       block.readblock(0, @bigbuf) 
    '
    '   For writes, we will destroy whatever data is wherever we write, if there is data
    '   there.  So we write high up on the card.  But at the same time, we don't want to
    '   mess up the metadata.
    '   
       term.str(string("How fast can we write, sequentially?", 13))
       n := 128
       duration := 0
       ptr := offset
       repeat while duration < maxdur
          n += n
          duration -= cnt
          repeat n
             block.writeblock(ptr++, @bigbuf)
          duration += cnt
       addspeed(string("Raw write"), duration, (ptr-offset)*512)
       ' try a non-sequential write
       term.str(string("Do a single non-sequential write..."))
       ptr += 10   
       block.writeblock(ptr, @bigbuf)
       term.str(string("Done", 13))
    
       term.str(string("How fast can we read, sequentially?", 13))
       n := 128
       duration := 0
       ptr := offset
       repeat while duration < maxdur
          n += n
          duration -= cnt
          repeat n
             block.readblock(ptr++, @bigbuf)
          duration += cnt
       addspeed(string("Raw read"), duration, (ptr-offset)*512)
    '
    '   That's it for the block layer.
    '
       stop_block_layer
    pub fsrwspeed | r, startcnt, bytes, n, duration, i
    '
    '   Now we move on to the filesystem layer.
    '
       term.str(string("Now the filesystem tests",13))
       term.str(string("Trying to mount",13))
       sdfat.mount_explicit(term#sd_DO, term#sd_CLK, term#sd_DI, term#sd_CS)
       term.str(string("Mounted.",13))
       ' determine the write speed first, then use that size for the read
       term.str(string("How fast can we write using pwrite?",13))
       n := 0
       i := 2
       duration := 0
       sdfat.popen(string("speed.tst"),"w")
       repeat while duration < maxdur
          i += i
          n += i
          duration -= cnt
          repeat i
             sdfat.pwrite(@bigbuf, 8192)
          duration += cnt
       sdfat.pclose
       addspeed(string("fsrw pwrite"), duration, n*8192)
       ' now determine the read speed
       term.str(string("How fast can we read using pread?",13))
       sdfat.popen(string("speed.tst"),"r")
       duration := -cnt
       repeat n
          sdfat.pread(@bigbuf, 8192)
       duration += cnt
       sdfat.pclose
       addspeed(string("fsrw pread"), duration, n*8192)
    
       term.str(string("How fast can we write using pputc?",13))
       n := 0
       i := 512
       duration := 0
       sdfat.popen(string("speed.tst"),"w")
       repeat while duration < maxdur
          i += i
          n += i      
          duration -= cnt
          repeat i
             sdfat.pputc("!")
          duration += cnt
       sdfat.pclose
       addspeed(string("FSRW pputc"), duration, n)
       
       term.str(string("How fast can we read using pgetc?",13))
       sdfat.popen(string("speed.tst"),"r")
       duration := -cnt
       repeat n
         sdfat.pgetc
       duration += cnt
       sdfat.pclose
       addspeed(string("FSRW pgetc"), duration, n)
    
    ' copy speed.tst to speed2.tst
    
       sdfat.popen(string("speed.tst"),"r")
       sdfat[1].popen(string("speed2.tst"),"w")
       repeat while (i:=sdfat.pgetc)=>0
          sdfat[1].pputc(i)
       sdfat.pclose
       sdfat[1].pclose
       
    {{
    '  Permission is hereby granted, free of charge, to any person obtaining
    '  a copy of this software and associated documentation files
    '  (the "Software"), to deal in the Software without restriction,
    '  including without limitation the rights to use, copy, modify, merge,
    '  publish, distribute, sublicense, and/or sell copies of the Software,
    '  and to permit persons to whom the Software is furnished to do so,
    '  subject to the following conditions:
    '
    '  The above copyright notice and this permission notice shall be included
    '  in all copies or substantial portions of the Software.
    '
    '  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    '  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    '  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    '  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    '  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    '  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    '  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    }}
    

    with appropriate changes to sysdep.spin:
    {{
       fsrw Copyright 2009  Tomas Rokicki and Jonathan Dummer
    
       See end of file for terms of use.
    
       This object contains the system dependencies.  This
       includes stdin (maybe keyboard, maybe serial),
       stdout (may serial, maybe tvtext, maybe vga) and
       information on where the SD card is attached.  It
       defines rx (input), tx, dec, and str (output),
       sd_base and start methods.  It also defines clock
       speed.
    
       I use serial I/O and connect my SD card starting at
       pin 0 on a demo board.
    }}
    con
       _clkmode = xtal1 + pll16x
       _xinfreq = 5_000_000
       sd_DO = 12
       sd_CLK = 13
       sd_DI = 14
       sd_CS = 15
    obj
       term : "FullDuplexSerial"   
    {{
       This should start stdin and out, but *not* anything on the
       secure digital card.
    }}
    pub start
       term.start( 31, 30, 0, 115200 )
    pub rx
       return term.rx
    {{
       If you don't have an input device, this definition of rx will allow
       the test to run once, and only once.
    
    var
       long testcounter
    pub rx
       repeat while testcounter==1
       testcounter++
       return " "
    }}
    pub rxtime( t )
       return term.rxtime( t )
    pub rxcheck
       return term.rxcheck
    pub tx(a)
       return term.tx(a) ' this may be out in some objects
    pub str(a)
       return term.str(a)
    pub dec(a)
       return term.dec(a)
    pub hex(a,d)
       return term.hex(a,d)
    {{
    '  Permission is hereby granted, free of charge, to any person obtaining
    '  a copy of this software and associated documentation files
    '  (the "Software"), to deal in the Software without restriction,
    '  including without limitation the rights to use, copy, modify, merge,
    '  publish, distribute, sublicense, and/or sell copies of the Software,
    '  and to permit persons to whom the Software is furnished to do so,
    '  subject to the following conditions:
    '
    '  The above copyright notice and this permission notice shall be included
    '  in all copies or substantial portions of the Software.
    '
    '  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    '  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    '  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    '  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    '  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    '  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    '  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    }}
    
  • andYManOneandYManOne Posts: 21
    edited 2012-07-22 04:52
    Equinoctum wrote: »
    I am new to propeller and have been trying to make a barebones SD card reader. However, I am having issues mounting the SD card using FSRW 2.6. Attached is the circuit diagram and the file I have been using to test. Power and ground are drawn from a BoeBot board.

    I have repetitively checked the connections for shorts and incorrect wiring, and have remade boards. I have tried using different propeller chips, prop plugs, and connecting the SD card to different pins. I am using a SanDisk 2GB Class 2 SD card, formatted Fat 16 (tried both quick and full formatting). On a Windows 7 x64 OS, I have tried using different USB cables and updating the VCP drivers. I have also tried running on Windows XP x32.

    Every time I run the program I fail to mount.

    Any insight would be greatly appreciated.
    Hi Equinoctum, have you ever tried out, to leave off the 4x 10k resistors (R31 - R34) but use 2 more pullup resitors (one for SD8 (Datal line 1) and one SD9 (Data line 2)?

    I built my own SD-Card Adapter in 2008 in this way and it works on the first try without any probs :)

    BR,
    andY
    640 x 480 - 106K
    640 x 480 - 109K
    1024 x 583 - 25K
  • Don MDon M Posts: 1,654
    edited 2012-07-22 05:56
    If you have only tried just that 1 card you can't rule out the possibility that particular card just won't work with the program. See this thread and post #3:

    http://forums.parallax.com/showthread.php?139976-Update-for-un-usable-SD-Cards&p=1096887#post1096887

    You may need to try a different card.
  • EquinoctumEquinoctum Posts: 4
    edited 2012-07-22 14:57
    I finally figured out my problem -- a jumpy voltage supply and loose connection to the SD card. I switched the card's voltage supply to two AAA batteries (instead of voltage dividing the Vdd of the BoeBot's Board of Education Development Board) and after applying some pressure to the SD card connection pins, everything ran smoothly, passing all the tests. I'm running it fine now without any pull-up resistors or capacitors between Vss and Vdd.

    Thank you so much everyone for all your help!! I can finally rest in peace tonight :smile:
  • andYManOneandYManOne Posts: 21
    edited 2012-07-22 15:07
    Equinoctum wrote: »
    I finally figured out my problem -- a jumpy voltage supply and loose connection to the SD card. I switched the card's voltage supply to two AAA batteries (instead of voltage dividing the Vdd of the BoeBot's Board of Education Development Board) and after applying some pressure to the SD card connection pins, everything ran smoothly, passing all the tests. I'm running it fine now without any pull-up resistors or capacitors between Vss and Vdd.

    Thank you so much everyone for all your help!! I can finally rest in peace tonight :smile:
    Sounds good, fine that it´s finally works now :) !

    BR,
    andY
Sign In or Register to comment.