Shop OBEX P1 Docs P2 Docs Learn Events
number of sectors in SD card — Parallax Forums

number of sectors in SD card

David BDavid B Posts: 592
edited 2010-01-26 17:05 in Propeller 1
Do any of the existing SD card access propeller codes (by kye, rokiki, lonesock, ?)·provide access to the SD card CSD register?

I'm trying to read the total number of sectors in a card, which is listed in this SD card internal configuration register, but as far as I can tell, all the propeller code I've browsed through return the total number of sectors from the existing formatted filesystem, as reported from the FAT-filesystem boot sector, not of the full card, as reported by the underlying SD card configuration.

I have accessed this register myself in the past with my own clumsy code, but it would be great if it could be read using either rokiki/lonesock's fast low-level routines or kye's much more complete high-level routines.

Comments

  • KyeKye Posts: 2,200
    edited 2010-01-25 18:42
    My code does.

    If you look at the bottom of my ("everything and the kitchen sink") thread in my filesystem driver you'll find a long value in a DAT section near the end of the code which has the card sector count.

    I was going to use that value to allow for Master Boot Record formating code to work. However, I choose not to since it requires ALOT more code to format and resize a FAT partition than just to delete everything on it.

    The "cardSectorNumber" variable gets setup after the mount function has been called.

    Note that the value reflects how many user acessable sectors are avialable on the SD card. Most SD cards have security sectors which can also be acessed if you know the security protocol for SD cards.

    That said, the amount of user acessable sectors is less than the amount quoted on the card sticker.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,

    Post Edited (Kye) : 1/25/2010 6:47:51 PM GMT
  • David BDavid B Posts: 592
    edited 2010-01-25 18:52
    Great! I had missed that. I guess I had looked in an earlier spin-only FATEngine file that didn't include the CSD register read.

    I'll give it a try tonight and let you know how it works.
  • VIRANDVIRAND Posts: 656
    edited 2010-01-26 10:03
    Since the lock switch is fake, I'm curious about what the security sectors do.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    VIRAND, If you spent as much time SPINNING as you do Trolling the Forums,
    you'd have tons of awesome code to post!
    (Note to self)
  • heaterheater Posts: 3,370
    edited 2010-01-26 11:36
    Can anyone suggest how to remove the write protection from a few sectors at the beginning of one of my SD cards?

    I know from trying with "dd" under Linux that I can write to all of that card except a few sectors at the beginning. The SD formatting tool from Panasonic refuses to format the card complaining that some sectors are write protected.

    I can't believe those sectors have "worn out", it has never been used so much.

    I could just bin it, cards are cheap, but it seems a shame and I'd really like to know how to do this.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • David BDavid B Posts: 592
    edited 2010-01-26 16:58
    If the write is failing because a block of sectors has the write protect bit set, there should be an error result bit set to indicate that reason.

    If that really is the case, the SD CMD29 should be able to unset the write protect bit on that block of addresses.

    But you would probably have to do the low-level coding to figure out how to set up the parameters and send CMD29.

    Kye had an older FATEngine.spin that acesses cards entirely from spin. Down in its low-level card access routines, there are some pretty readeable routines that send arbitrary commands to an SD card and receive the cards response. If I were to try to do this, I'd probably start with that code and first try to verify that the sectors really are locked, then try to figure out the total address range of locked sectors, then try to issue the "unlock block" command over that address range.

    It would be a great SD card learning experience to try that, and if you're about to trash the card anyway, you can't do any harm.
  • KyeKye Posts: 2,200
    edited 2010-01-26 17:05
    Good luck.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
Sign In or Register to comment.