emmcio – Block device access to the on-board eMMC
The emmcio module exposes an eMMC chip as a block device.
It provides no filesystem of its own: to read files, hand an EMMC
object to storage.VfsFat and mount it.
Available on these boards
- class emmcio.EMMC(*, clock: microcontroller.Pin, command: microcontroller.Pin, data: microcontroller.Pin, reset: microcontroller.Pin | None = None, vccq: microcontroller.Pin | None = None, high_speed: bool = False, write_enabled: bool = False)
eMMC as a block device
Power up the card and make it ready for block access.
Only one
EMMCobject may exist at a time. Calldeinit(), or use the object as a context manager, to release the card and its pins.- Parameters:
clock (Pin) – the card’s CLK pin
command (Pin) – the card’s CMD pin
data (Pin) – the card’s DAT0 pin. The bus is 1-bit, so this is a single pin.
reset (Pin) – the card’s RST_n pin, if the board wires one
vccq (Pin) – a pin gating the card’s I/O rail, if the board has one
high_speed (bool) – Run the bus at its faster clock rate. Raises an
OSErrorif the card will not make the switch.write_enabled (bool) – Allow
writeblocks(). WhenFalse, the object is read-only and every write path refuses.
- Raises:
ValueError – if the pins are unusable or already in use, or if the card is owned by the USB drive.
OSError – if the card does not come up.
emmcio failure: nnames the MMC command that did not answer (8being the extended CSD), andhigh_speed failure: nhow far the switch got:0the card does not advertise 52 MHz,1no CMD6 response,2the card never released DAT0,3it never came back to the transfer state,4the EXT_CSD readback did not take,5the 32 MHz smoke test failed,7the card rejected HS_TIMING.
Mount the card’s filesystem:
import board import emmcio import storage emmc = emmcio.EMMC( clock=board.EMMC_CLK, command=board.EMMC_CMD, data=board.EMMC_DAT0, reset=board.EMMC_RESET, vccq=board.EMMC_VCCQ, high_speed=True, write_enabled=True, ) storage.mount(storage.VfsFat(emmc), "/sd")
- deinit() None
Release the card and the pins it uses. Any further use of this object raises a
ValueError.
- __exit__() None
Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.
- readblocks(start_block: int, buf: circuitpython_typing.WriteableBuffer) None
Read into
bufstarting atstart_block.- Parameters:
start_block (int) – the first block to read
buf (WriteableBuffer) – a buffer whose length is a non-zero multiple of
block_size
- Raises:
ValueError – if
bufis the wrong length, or the requested blocks run past the end of the card.OSError – if the card fails to deliver the data.
- writeblocks(start_block: int, buf: circuitpython_typing.ReadableBuffer) None
Write
bufto the card starting atstart_block.- Parameters:
start_block (int) – the first block to write
buf (ReadableBuffer) – a buffer whose length is a non-zero multiple of
block_size
- Raises:
RuntimeError – if this object was not constructed with
write_enabled=True.ValueError – if
bufis the wrong length, or the requested blocks run past the end of the card.OSError – if the write fails.
- ioctl(op: int, arg: int) int | None
Perform a block-device control operation, as required by the block-device protocol. Returns
Nonefor operations this device does not implement.
- write_enabled: bool
Whether
writeblocks()is permitted on this object.