Go Down

Topic: Maximum Capacity for microSD Card used with Arduino+SD module: 2GB or 32GB? (Read 3237 times) previous topic - next topic

Lucario448

I am curious about the Program-Erase cycles
Long story short, NAND flash memories can "drain" individual bits from 1 to 0, but not the other way around. For that, you'll have to re-set all the bits of the page, then clear out the corresponding ones.

In a write cycle, re-setting the whole page (with 1s) is the "erase" stage; this is what takes most of the time and causes wear to a page. The "program" stage is simply clearing out (from 1 to 0) the neccesary bits in order to create the intended data to store.

is the size of them always 512Bytes, in all microSD cards no matter the card's capacity?
(meaning this 512 number is defined by the manufacturer of the microSD card, in hardware)
Not entirely sure. Either these boundaries are defined by the built-in controller (the chip who actually "talks" with the Arduino or any other card reader), or it's the actual (physical) page size of the memory itself.

In SDSC (cards up to 2 GB), it's actually possible to change the block size to a smaller one (although it's done virtually by the card's controller), and write a single byte like an EEPROM.
However, in SDHC (4-32 GB) and beyond, this is not possible anymore, and the block size is always fixed to 512 bytes.


Or is this number affected by the user somehow, for example when Formatting the card?

(from what I remember from Format programs, you can only choose the Cluster size, not the Sector size..)
No, that's something defined by software (high level); the sector size is indeed defined by hardware (low level).

In digital mass-storage devices, a cluster is just a software-defined group of contiguous hardware-defined sectors (hence its name), in order to simplify some the free space and file allocation management. Larger clusters means less filesystem's data structure and processing overhead (which may also translate in support for a bigger volume/partition), but at the same time potentially larger "slack" or "internal fragmentation" (wasted disk space, unusable by the filesystem) in small files.

That's why you can change the cluster size, and not the sector size.

card5

Really interesting, thank you very much.


In SDSC (cards up to 2 GB), it's actually possible to change the block size to a smaller one (although it's done virtually by the card's controller), and write a single byte like an EEPROM.
However, in SDHC (4-32 GB) and beyond, this is not possible anymore, and the block size is always fixed to 512 bytes.
That's nice, too bad this option was omitted.


BTW,
I saw a microSD card module, that claims to be High-Speed.
https://robotdyn.com/catalog/modules/memory/microsd-card-module.html


It seems that it contains a CD4050, for high-speed communication.

From what I understand, the CD4050 is a Buffer IC,
but the term "Buffer" can be quite misleading here, for people who come from the software field.
The IC cannot and doesn't store anything, it is just used for Level Conversion, from what I understand.


So when they say that using the CD4050 makes the module high-speed,
do they say it versus using Transistors for Level Conversion, like we see in other modules (that support 5v and don't have the CD4050)?
The Transistors are slower than the CD4050?

If indeed the CD4050 is faster than Transistors, I wonder if this extra speed is relevant to the speeds that we can get when using Arduino and a microSD card, which from what I understood are around 200KBps for writing, and 300KBps for reading..


Here is for example one with the SMD Transistors, that I bought several years ago:
https://www.itead.cc/prototyping/basic-module/sd-micro-sd-card-breakout-module.html

Lucario448

The IC cannot and doesn't store anything, it is just used for Level Conversion, from what I understand.

So when they say that using the CD4050 makes the module high-speed,
do they say it versus using Transistors for Level Conversion, like we see in other modules (that support 5v and don't have the CD4050)?
The Transistors are slower than the CD4050?
Maybe they are implying that? Who knows

Furthermore, every transistor has a minimum on/off time plus any stray capacitance; those factors do limit the working speed. For example: the typical ATmega328 runnning at 16 MHz can operate its SPI master controller up to 8 MHz (always half the system's frequency, also called "full speed" by the SPI library); thus any transistor used for level conversion must have an on/off time of at most 125 ns.

Slow transistors and high stray capacitances can cause from ocasional jitter (uneven pulse periods) to missing pulses (so out-of-sync communications and thus corrupted data), of course unless the working frequency is low enough.



If indeed the CD4050 is faster than Transistors, I wonder if this extra speed is relevant to the speeds that we can get when using Arduino and a microSD card, which from what I understood are around 200KBps for writing, and 300KBps for reading..
That's an average data rate, but the SPI lines will still be pulsing at 8 MHz for instance. It's not continuous because of all the processing involved between transfers.
Anyway, if you somehow manage to do it (e.g. via DMA), you wouldn't get the theoretical maximum (8 MHz = 8 Mbit/s = 1 MB/s) but close to. If processing isn't the delay, then the communitaction protocol (command, parameters, CRC if kept required, and response) and the card's controller busy state (for instance, applied when executing an erase-program cycle during a write operation) will be.

card5

I see.

I think I will also buy the module with the CD4050,
for experimenting and comparing the max. speed it can give vs. the other microSD modules I have.

(when something costs 1$, it's hard to resist)

ShermanP

But isn't the CD4050 there as a level shifter - from 5V to 3.3V, not really as a buffer?  I think most modules use the 74LVC125A, but the function is the same.

Lucario448

I think I will also buy the module with the CD4050,
for experimenting and comparing the max. speed it can give vs. the other microSD modules I have.
Go ahead, but I predict it will work fine in 8 MHz (aka "full speed" on a 16 MHz ATmega)


(when something costs 1$, it's hard to resist)
Not impressed actually, nowadays many types of sensors and breakout boards for Arduino are as cheap as below $10. The only components I found somewhat expensive are: RGB LED matrices (the 8x8 ones made of addressable LEDs), character LCD displays, color TFT LCD displays, and e-paper displays (the two latter ones are even more expensive than an Arduino Mega clone).


But isn't the CD4050 there as a level shifter - from 5V to 3.3V, not really as a buffer?  I think most modules use the 74LVC125A, but the function is the same.
Yeah probably it functions as a level shifter, because from what I've understood of the datasheet, it passes digital signals but at the same time isolate (but not galvanically like an optocoupler) two systems from operating voltage differences.

So for the sake of an SD card breakout board, should be no difference.

card5

color TFT LCD displays, and e-paper displays
Color TFT LCD displays for Arduino are expensive?

https://www.ebay.com/itm/ILI9341-2-8-inch-SPI-TFT-LCD-Display-Touch-Panel-240x320-with-PCB-5V-3-3V-STM32/323873611328


Or maybe you meant bigger sizes?

I haven't seen bigger sizes for Arduino, If you have a link it'll be interesting to check..

Lucario448

Or maybe you meant bigger sizes?
Maybe, or I just recalled it wrongly. But I know for sure e-paper displays aren't that cheap for now.

Also I think I've saw character LCD displays for above the $10 mark, specially the 20x4 ones.


card5

Hi all


We talked about the Program-Erase cycles, being done on 512B blocks,
and I am reading in Wikipedia, and found this:

Quote
While reading and programming is performed on a page basis, erasure can only be performed on a block basis.
https://en.wikipedia.org/wiki/Flash_memory#NAND_memories


More from that section in Wikipedia:

Quote
The pages are typically 512, 2,048, or 4,096 Bytes in size.
Quote
Typical block sizes include:
- 32 pages of 512+16 bytes each for a block size (effective) of 16KB
- 64 pages of 2,048+64 bytes each for a block size of 128KB
- 64 pages of 4,096+128 bytes each for a block size of 256KB
- 128 pages of 4,096+128 bytes each for a block size of 512KB
They say that writing is done to a whole Page (e.g. 512B),
but Erasing is done only on a full Block of Pages (e.g. 16KB, or upto 0.5MB...)


This is now a much bigger problem than the 512B that we worried about, for a page..


To prevent this bigger problem,
ideally the sd/microSD card's blocks should be Erased beforehand,
that way when you want to use the card and write to it,
your only "problem" will be 512Bytes (Whole Page Writing),
and not 16KB or upto 0.5MB of Block Erasing...


I wonder if regular Format programs, (when not choosing the Quick Format option),
do the required Block Erasing operation, when recognizing that the media is SD/microSD card..

If not, then a dedicated Format program could be helpful..

Lucario448

They say that writing is done to a whole Page (e.g. 512B),
but Erasing is done only on a full Block of Pages (e.g. 16KB, or upto 0.5MB...)


This is now a much bigger problem than the 512B that we worried about, for a page..
Again, it depends on the NAND chip itself. From an SD card, it's very hard to tell unless it's mentioned in a datasheet or something.


ideally the sd/microSD card's blocks should be Erased beforehand
As a maintenance routine or an excuse to wipe out (unrecoverably) any remainder data (sort of like a "low-level format" on magnetic HDDs).

As a maintenance routine would be similar when a computer OS issues the so-known "TRIM" command to an SSD: it erases all blocks that correspond to free clusters marked by the used filesystem (if they are enough contiguously when erase block size and cluster size don't match or they aren't "aligned"; which is a terrible performance issue).



I wonder if regular Format programs, (when not choosing the Quick Format option),
do the required Block Erasing operation, when recognizing that the media is SD/microSD card..
Only if the OS somehow realizes that it's an SD card and not a generic mass storage device (which I think is treated kind of as a magnetic HDD by default).
Doing a full format as a HDD doesn't make much sense to a NAND flash; the longest stage only reads the whole capacity to find and mark bad sectors, but it does not apply any erasing at all.

I've never seen an SD card reader connected to a more "flexible" (protocol-wise) bus such as PCI-e, but only USB nowadays.
Unless the reader identifies itself with an special "device class" (what is it) and not as the standard generic mass storage device class (like pendrives and external HDDs), otherwise it seems unlikely the computer OS will tell the difference; although as an "special device" would mean special drivers required, and thus kinda beats up the plug-and-play purpose of USB.

However, USB mass storage devices "talk" SCSI, and fortunately SCSI also has an "erase block" command; so on a computer it should be possible to erase free blocks on an SD card as well. That is, if the reader's controller support such command and translates it to the card.
Also I'm not sure if SCSI can retrieve storage-medium-specific information that an OS can tell apart SD cards from pendrives or external HDDs.




If not, then a dedicated Format program could be helpful..
It does exist, and it's called "SD Formatter". Again, if the OS can't tell if it's actually an SD card; then the program will blindly assume that whatever drive you selected is the card.

How it knows the block size? I think it's by the reported capacity. For example: this program formatted me a 1 and 2 GB card with 16 KB clusters, 4 and 8 GB with 32 KB clusters.
So are those the actual erase block sizes? Or the assumptions might be wrong?

card5

It does exist, and it's called "SD Formatter".
Probably also SdFat library's Formatting program

Lucario448

It does, it's even mentioned in the commentaries at the beginning.

Not sure if SD Formatter is open source, if not then it's reverse engineered by emulating its behavior.
Remember that a SD card in SPI mode has a command to retrieve its information (like serial number, raw capacity in sectors of 512 bytes, type, and maybe brand/manufacturer's information), and read/write/erase blocks; so it's possible to edit partitions and format them with an Arduino since those commands are at a low level and data-structure-independent (partitions and filesystems are handled entirely by software).

Go Up