Flash memory

From Helpful
Revision as of 00:49, 21 April 2024 by Helpful (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The lower-level parts of computers

General: Computer power consumption · Computer noises

Memory: Some understanding of memory hardware · CPU cache · Flash memory · Virtual memory · Memory mapped IO and files · RAM disk · Memory limits on 32-bit and 64-bit machines

Related: Network wiring notes - Power over Ethernet · 19" rack sizes

Unsorted: GPU, GPGPU, OpenCL, CUDA notes · Computer booting

Memory card types

📃 These are primarily notes, intended to be a collection of useful fragments, that will probably never be complete in any sense.

For different kinds of memory cards, see Common plugs and connectors#Memory_cards

Secure Digital (SD, miniSD, microSD), and MMC details

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

Capacity types / families

  • SD (now named SDSC, 'standard capacity', to distinguish it)
    • size (somewhat artificially) limited to 1-4GB
  • SDHC (high capacity), since approx 2006
    • physically identical but conforming to a new standard that allows for higher capacity and speed.
    • adressing limited to 32GB
  • SDXC (eXtended-Capacity), since approx 2009
    • successor to SDHC that allows for higher capacity and speed
    • UHS was introduced since roughly then. Note that only some cards use UHS.
    • adressing limited to 2TB
  • Ultra-Capacity (SDUC), since approx 2018
    • limited to 128TB
  • SDIO
    • allows more arbitrary communication, basically a way to plug in specific accessories on supporting hosts - not really an arbitrarily usable bus for consumers
    • (supports devices like GPS, wired and wireless networking)

The above is partly about capacity, and partly about function. It's also not entirely aligned with SD versions, protocolwise it's even more interesting, particularly with the extra buses for the faster (UHS and Express) modes.

I think most people have list track of the details by now.


Power is 3.3V, though there are some lower-voltage details - in particular the LVDS being lower voltage (1.8V(verify)).

(MMC had 7 pins)

SD has 9 pins before up until UHS-II

SD with UHS-II adds 8 pins for a total of 17 pins

two more LVDS pairs, and more power and ground

MicroSD has 8 pins

MicroSD with UHS-II has 17 pins

Protocol (and DIY options)

Since there are a a few card types and more transfer modes over the years, supporting all the possible things a card can do is fairly involved.

Even detecting what kind of card is there is interesting. You'ld think this is part of negotiation, but for historical reasons you need some fallback logic even in the initialisation commands.

Since you're talking to the flash controller, there is a minimal mode, namely to start talking SPI.

There are a handful of protocol variations, that are basically negotiated from the most basic one. Any fancy device will want to do that for speed, but for DIY that choice of SPI is much simpler. (note there are some recent cards where SPI mode is optional, though(verify))

In SPI mode the pins are mostly just SPI's MOSI, MISO, SCLK, select, and ground, and Vcc.

Code-wise, you'll want to find a library. If you don't, you'll probably end up writing much of one anyway.

SD Speed rating

Actual performance

There are two gotchas to speed ratings:

  • due to the nature of flash, it will write slower than it will read
how much faster/slower depends, but it's easily a factor 2
whenever marketers can get away with it, they will specify the read speed
note that the differences vary, due to differences in controlles. E.g. external card readers tend to be cheap shit, though there are some examples of slow
  • writes can be faster in short bursts.
because you're actually talking to a storage controller, managing the flash
You usually care about sustained average write instead
And sometimes about the guaranteed speed, i.e. the minimum per second-or-so

This tells us it's a UHS-I card, it's video class 10, UHS class 1, and speed class 10


  • Speed class - looks like a circle with a number in it - one of 2, 4, 6, or 10
(and a class 0, which doesn't specify performance so is meaningless)
tyhat figure is which is MB/s
apparently this was intended as a minimum sustained write speed, but practice proves not everyone keeps to this, so if specs look optimistic, they probably are. It seems to vary with honesty, so a good Class 6 card may well perform better than a bad Class 10 one.
there is no larger-than-10, no matter how much fast it actually is
those details (and the fact that these days most SD can sustain 10MB/s) means this class system is no longer informative
  • Video speed class - V with a number, V6, V10, V30, V60, or V 90.
again, it's just MB/s
These were introduced because realtime-not-too-compressed HD video tends to want
perhaps 10MByte/s for 1080p
perhaps 30MByte/s for FHD
perhaps 60MByte/s for 4k
perhaps 90MByte/s for 8k
These are apparently required to be sustained speeds(verify)
  • UHS speed class - looks like a U with a number in it (1, 2, or 3)
1 is 10MB/s
3 is 30MB/s
...so UHS speed class has very little to do with UHS version
  • Packaging may try to stunt with speed, but tend to say "up to" (possibly in tiny print)
For example, I have a card that says writes up to 80MB/s and reads up to 170MB/s, yet all the logos on it suggest it can't guarantee sustaining more than 30MB/s. Curious...
so assume this is marketing bullshit in general

For video, you probably want 10MB/s for standard definition, 30MB/s for 1080p, 60MB/s for 4K, and 90MB/s for 8K

Bus speed:

Bus speed is how much the wiring can carry data. Note this says nothing about whether the card actually will, so this is mostly unimportant

Classically there's

  • Standard
12MB/s max
  • High-speed - clocks SDSC and SDHC at double the rate
25MB/s max

  • UHS-I
Introduced in version 3.01 (~2010, basically around when SDXC was introduced)
for SDHC and SDXC
one LDVS pair on the same row, bus speed specced at ~100MB/s max
  • UHS-II
Introduced in version 4.0 (~2011)
for SDHC and SDXC?
an extra row of eight pins: two extra LDVS pairs, and more power and ground)
bus speed specced at ~300MB/s max
  • UHS-III is only part of SDUC(verify)
introduced in version 6.0
bus speed specced at ~600MB/s max
Also introduced "Video Speed Class" rating
Express, which are primarily about extra speed --
  • SD Express (introduced in version 7.0)
bus speed specced at ~900MB/s max

I'm still confused about how SD Express and UHS-III relate


On fake flash

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

Fake flash refers to a scam where cards's controller reports a larger size than the actual storage has.

These seem to come in roughly two variants:

addressing storage that isn't there will fail,
or it will wrap back on itself and write in existing area.

...which isn't an important distinction, in that the result is just that it appears to be broken. It will seem to work for a little while, and in both cases it will corrupt later.

There are some tools to detect fake flash. You can e.g. read out what flash memory chips are in there and whether that adds up. Scammers don't go so far to fake this.

But the more thorough check is a write-and-verify test, see below.

Memory card health

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

While memory cards and USB sticks are made of flash memory, much like SSDs, memory cards and USB sticks usually lack wear leveling and health introspection like SMART.

So you should assume that they will fail completely, without warning, so never keep your only copy of something on them.

At lower level, even if they are still completely readable (and that's not a guarantee), filesystems are not made to deal with write failure, so you may need special tools, and/or a technical friend, for recovery.

You can check, non-destructively, whether it's all still readable with a tool that just read all disk surface (for chkdsk it's the 'scan for an attempt recovery of bad sectors" checkbox, but there are clearer ways with better summaries)

The only real test of whether it's fully writable is to write to all of it, but

that will actively wear it a little
it's destructive of the data still on there.
it only proves that it hasn't failed already, not that it won't do so soon

...this can still be a halfway decent way to inspect a pile of cards you don't know - to gauge speed, whether they haven't failed yet, and are fake flash.

One useful tool is H2testw, which creates a file in free space (if empty, then almost all the SD card)

It will also tell you actual average write and read speed, not the potential lie on the front.

What's stored