Shop OBEX P1 Docs P2 Docs Learn Events
Safe removal of SD card? — Parallax Forums

Safe removal of SD card?

I have a W5200 for QuickStart board which comes equipped with a micro SD card slot. The accompanying product sheet says in step 5 on page 8: "Insert the MicroSD card into the W5200 board’s MicroSD card slot. Do this with your QuickStart W5200 board unpowered."

Do I need to power down the board before removing or installing the SD card, or can the card be safely removed as long as there is no active I/O activity?

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-09-10 18:17
    The card can be safely inserted and removed as long as it's not in the process of being written to.

    I often add red and green LEDs to my SD card projects and have the red LED light a second or so before the card is written to. I have the green LED light when it is safe to remove the card. Of course only one LED is needed but I always look for excuses to add LEDs to projects.
  • Great, that makes things much easier. Thank you.
  • I think a little more insight is needed on your software for a 100% accurate response.

    The C/C++ and Spin solutions I've seen for SD cards are not smart enough to re-initialize an SD card on-the-fly, whenever necessary.
    Do I need to power down the board before removing or installing the SD card

    You can remove/install an SD card at any time without physically harming anything.
    can the card be safely removed as long as there is no active I/O activity

    I'm going to assume "safely" refers to data integrity and not physical harm (since that was addressed above).
    This depends entirely on the specific software (driver) being used. SD cards can not be read byte-by-byte, so at a minimum, a driver has to cache 512 bytes at a time. It's possible that the driver could flush the cache with every single byte of data, but that would be wasteful. So, based purely on LED activity, you won't know if your entire file has finished writing, or if there's another 512 bytes still residing in Propeller RAM. And of course, some drivers cache even more than 512 bytes. You need to know more about how your driver and your application work before this question can be answered.

    I like Duane's idea a lot, but lighting those red and green LEDs requires the above knowledge
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-09-10 19:34
    I So, based purely on LED activity, you won't know if your entire file has finished writing, or if there's another 512 bytes still residing in Propeller RAM.

    Have you used the common Spin SD drivers? I was under the impression both Kye's FAT object and fsrw.spin would immediately write a byte when told to do so. I know this is a slower way to write data to the card but I think it's pretty common for people to write just a few bytes at a time as they log data.

    I just looked through Kye's object a bit and it don't see any indication it waits for a full block before writing.

    As you say, one would need to know the specifics of the object one used, but I don't think it's very common for SD drivers (at least the ones I've used) to wait around for more data before writing to the card.

  • Duane Degn wrote: »
    I So, based purely on LED activity, you won't know if your entire file has finished writing, or if there's another 512 bytes still residing in Propeller RAM.

    Have you used the common Spin SD drivers? I was under the impression both Kye's FAT object and fsrw.spin would immediately write a byte when told to do so. I know this is a slower way to write data to the card but I think it's pretty common for people to write just a few bytes at a time as they log data.

    I just looked through Kye's object a bit and it don't see any indication it waits for a full block before writing.

    As you say, one would need to know the specifics of the object one used, but I don't think it's very common for SD drivers (at least the ones I've used) to wait around for more data before writing to the card.

    Oh... that's... odd. nevermind lol
  • I am using the "S35390A_SD-MMC_FATEngine.spin" (v1.9.1). I use an input switch to tell the SPIN code to close any open file and unmount the card. Once that is done it turns on an LED indicating it is "safe" to remove the card. The same input signal is used to indicate that the card is back in so the code can remount it and resume its I/O business.

    I assume the close file operation would flush and data to the card and the unmount makes it safe to physically remove the card.

    Reasonable protocol?
  • A beautiful approach, yes :)
Sign In or Register to comment.