
On Hacking MicroSD Cards (2013) - peter_d_sherman
https://www.bunniestudios.com/blog/?p=3554
======
dang
If curious see also

2019
[https://news.ycombinator.com/item?id=18959766](https://news.ycombinator.com/item?id=18959766)

Discussed at the time:
[https://news.ycombinator.com/item?id=6980058](https://news.ycombinator.com/item?id=6980058)

------
slowhand09
On a similar note... [https://hackaday.com/2020/09/08/size-does-matter-when-
it-com...](https://hackaday.com/2020/09/08/size-does-matter-when-it-comes-to-
sd-cards/)

------
peter_d_sherman
>"Flash memory is really cheap. So cheap, in fact, that it’s too good to be
true. In reality, all flash memory is riddled with defects — without
exception. The illusion of a contiguous, reliable storage media is crafted
through sophisticated error correction and bad block management functions.
This is the result of a constant arms race between the engineers and mother
nature; with every fabrication process shrink, memory becomes cheaper but more
unreliable. Likewise, with every generation, the engineers come up with more
sophisticated and complicated algorithms to compensate for mother nature’s
propensity for entropy and randomness at the atomic scale.

These algorithms are too complicated and too device-specific to be run at the
application or OS level, and so it turns out that every flash memory disk
ships with a reasonably powerful microcontroller to run a custom set of disk
abstraction algorithms. Even the diminutive microSD card contains not one, but
at least two chips — a controller, and at least one flash chip (high density
cards will stack multiple flash die)."

[...]

>"The embedded microcontroller is typically a heavily modified 8051 or ARM
CPU. In modern implementations, the microcontroller will approach 100 MHz
performance levels, and also have several hardware accelerators on-die.

 _Amazingly, the cost of adding these controllers to the device is probably on
the order of $0.15-$0.30_ ,

particularly for companies that can fab both the flash memory and the
controllers within the same business unit. It’s probably cheaper to add these
microcontrollers than to thoroughly test and characterize each flash memory
chip, which explains why managed flash devices can be cheaper per bit than raw
flash chips, despite the inclusion of a microcontroller.

The downside of all this complexity is that there can be bugs in the hardware
abstraction layer, especially since every flash implementation has unique
algorithmic requirements, leading to an explosion in the number of hardware
abstraction layers that a microcontroller has to potentially handle. The
inevitable firmware bugs are now a reality of the flash memory business, and
as a result it’s not feasible, particularly for third party controllers, to
indelibly burn a static body of code into on-chip ROM."

[...]

>"From the DIY and hacker perspective, our findings indicate a

 _potentially interesting source of cheap and powerful microcontrollers for
use in simple projects._

An Arduino, with its 8-bit 16 MHz microcontroller, will set you back around
$20.

 _A microSD card with several gigabytes of memory and a microcontroller with
several times the performance could be purchased for a fraction of the price._

While SD cards are admittedly I/O-limited, some clever hacking of the
microcontroller in an SD card could make for a very economical and compact
data logging solution for I2C or SPI-based sensors."

~~~
p1necone
Aren't Arduino's more expensive because they're built specifically for the
hobbyist market? I'm sure you can buy similar microcontrollers to those found
in SD cards cheaper than an Arduino - you just have to deal with the baggage
that that comes with (less tutorials, tooling etc)

~~~
charlesdaniels
This is very much the case. Arduino gives you a nice board with a decent power
circuit, clock circuit with crystal oscillator, strips of headers to plug
wires into, a USB connector, UART to USB adapter, and often other goodies. The
exact same MCU, the ATMega328P can be had for $2.08 each[0], or less if you
buy in bulk.

For your $2, you get:

* An internal oscillator which lets you run without an external clock circuit (typically limited to around 8MHz, and can cause clock drift, so not good of accurate timing is important).

* Hardware UART interfacing logic

* Hardware SPI interfacing logic

* Hardware I2C interfacing logic

* Several ADCs

* 23 GPIOs

* 2kB data memory

* 1kB EEPROM

* 32kb flash memroy

There are other microcontrollers out there, each with their own trade-offs. I
personally like AVRs, as they have good quality open source compilers, you can
mooch off the Arduino community for libraries[3], and in-circuit programmers
can be had for cheap[1].

If you want to learn more, I suggest this article[2].

0 - [https://www.mouser.com/ProductDetail/Microchip-Technology-
At...](https://www.mouser.com/ProductDetail/Microchip-Technology-
Atmel/ATMEGA328P-PU?qs=K8BHR703ZXguOQv3sKbWcg%3D%3D)

1 - [https://www.adafruit.com/product/46](https://www.adafruit.com/product/46)

2 - [https://www.evilmadscientist.com/2007/using-avr-
microcontrol...](https://www.evilmadscientist.com/2007/using-avr-
microcontrollers-minimalist-target-boards/)

3 - [https://github.com/oshlab/Breadboard-
Arduino](https://github.com/oshlab/Breadboard-Arduino)

~~~
05
Or you could buy a 32-bit ARM Cortex-M0 for 50¢ (STM32F0 series)

~~~
rcxdude
This. AVR chips are not a great cost comparison point anymore, they're very
expensive, especially for the speed you get.

~~~
kaoD
I'm sure you're already aware, but being _bigger_ is actually a benefit for
the beginner hobbyist market.

There is a DIP ATMega328P version and in fact it's the one used on the Arduino
UNO. It's also socketed! You can program it on the UNO, take it off, and it's
good to go to be plugged into a breadboard, soldered standalone on perfboard,
etc. and replaced with a new one.

~~~
charlesdaniels
Indeed, for educational use cases and hobbyists, there are tons of resources
available for the AVR. Being able to buy it in a DIP package is ideal, since
it really lowers the barrier of entry in terms of skills and tools required.
There are also tons of libraries and code examples both for AVR itself and for
the Arduino platform.

------
saagarjha
microSD cards are part of the reason why I always amazed at how much stuff we
can fit into such a small package.

~~~
jbverschoor
The microfilm.

But yeah, 64gb in basically half a fingernail is unbelievable

~~~
seba_dos1
64GB? I'm looking at 256GB cards right now. It's crazy.

~~~
gen3
What I find even crazier is that the 1TB cards are not a scam anymore.
[https://shop.westerndigital.com/products/memory-
cards/sandis...](https://shop.westerndigital.com/products/memory-
cards/sandisk-extreme-uhs-i-
microsd?utm_medium=pdsh2&utm_source=bing&utm_campaign=SanDisk-US-
PLA&utm_content=s&utm_term=SDSQXA1-1T00-AN6MA#SDSQXA1-1T00-AN6MA)

~~~
shadowoflight
Plummeting microSD card prices are astounding, and also exciting since I have
some devices that can only use microSD for storage. For instance, I'm really
hoping we get 1TB cards close to the $150 price point this Black Friday/Cyber
Monday so I can stop running out of space on my Nintendo Switch's current
200GB microSD.

------
synack
(2013)

