I am using a MSP430F5438A microcontroller to read and write on a delkin 2GB micro SD card using SPI interface following the Part1_Physical_Layer_Simplified_Specification_Ver6.00. I could successfully read and write on the card initially but one day the card just cannot be read and written to anymore, but initialization of card seems to be still fine. This has happened for a few times. Sometimes it takes a few days before it happens, sometimes it takes a few months. The screenshots taken below are captured using the Beagle I2C/SPI analyzer.

This is how I initialized the card.

enter image description here

and the response I get is

enter image description here

After that, I tried sending the SEND_STATUS command (CMD13) and the response I received is 0x0001 which indicates that the card is in a locked state.

enter image description here

I did not send any lock command in my firmware. After initializing the SD card, I only performs block write (CMD24), block read (CMD17) and block erase (CMD32), so I am unsure how did the card get locked or what the pwd is to unlock it. So I tried to force erase the card. When I do that, the card seems to enter an infinite busy state until I power cycle. I attached a screenshot of the MOSI transmission and the corresponding MISO transmission below

[Force erase command MOSI data]4

[Force erase command MISO data]5

As captured in the screenshot, I send the SET_BLOCKLEN (CMD16) command to change the block length to 1 before sending the LOCK_UNLOCK (CMD42) command followed by a data of 0x08 (ERASE bit set) and two bytes CRC. The response I get from doing so is 0xE5 which seems to indicate that the data is accepted. However, after that my MISO line is stuck low infinitely. I attached another screenshot below showing the overview of what happened

enter image description here

So I would like to ask how can I recover the card from this state and what could be a possible reason why the card enters this locked state even though no lock command was sent to the card.


Edit 1:

enter image description here

I added a screenshot showing the response when I try to erase, read and write from the card after it entered this locked state. All three response seems to indicate an illegal command, even for read block command (CMD17). So it does not seems like the card entered read-only but more of it cannot even be read anymore.

  • 1
    \$\begingroup\$ I was facing similar issue once (with STM32). I was somehow able to reduce the number of locks using a lot of dummy clock cycles before and after the commands and with a good power decoupling for SD card (!). I added pullups to SPI lines (not sure if it did anything). It was almost impossible to debug and I have never really found what was wrong. In the next PCB revision I made a power kill switch for the SD card so when it locked I could reset it (I was flushing files often). I was not able to reset it just with SPI... Later I moved to SDIO and the problems were gone. \$\endgroup\$
    – Pan Vi
    Commented Jun 4, 2021 at 7:32

1 Answer 1


SD cards, SSD disk-like devices, USB flash storages all have the common habbit of becoming read-only when they wear out and exhaust their spare blocks.

You cannot revert this state short of fiddling with the SD card firmware settings and declarng the 2GB SD to be e.g. 1GB and proclaiming the rest of the blocks as spare.

You may or may not have access to these settings. There is no standard way, there are only leaked manufacturer software found on obscure websites, good for some batches of some models of flash-based storage.

In short, that's how sane flash-based storages die. You can at least get your data back.

Non-sane ones die in different ways.

  • \$\begingroup\$ Thanks for the reply. However, based on the response I received from the read block command (CMD17), it seems like I cannot even read from the card anymore. So it seems to be different from the read-only situation which you described. I attached a screenshot in my edit 1 showing the response from the erase, read and write command which seems to all show illegal commands. \$\endgroup\$
    – Kelvin Ng
    Commented Jun 9, 2021 at 2:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.