sdioio – Interface to an SD card via the SDIO bus

class sdioio.SDCard(clock: microcontroller.Pin, command: microcontroller.Pin, data: Sequence[microcontroller.Pin], frequency: int)

SD Card Block Interface with SDIO

Controls an SD card over SDIO. SDIO is a parallel protocol designed for SD cards. It uses a clock pin, a command pin, and 1 or 4 data pins. It can be operated at a high frequency such as 25MHz. Usually an SDCard object is used with storage.VfsFat to allow file I/O to an SD card.

Construct an SDIO SD Card object with the given properties

Parameters:
  • clock (Pin) – the pin to use for the clock.
  • command (Pin) – the pin to use for the command.
  • data – A sequence of pins to use for data.
  • frequency – The frequency of the bus in Hz

Example usage:

import os

import board
import sdioio
import storage

sd = sdioio.SDCard(
    clock=board.SDIO_CLOCK,
    command=board.SDIO_COMMAND,
    data=board.SDIO_DATA,
    frequency=25000000)
vfs = storage.VfsFat(sd)
storage.mount(vfs, '/sd')
os.listdir('/sd')
frequency :int

The actual SDIO bus frequency. This may not match the frequency requested due to internal limitations.

width :int

The actual SDIO bus width, in bits

configure(self, frequency: int = 0, width: int = 0)

Configures the SDIO bus.

Parameters:
  • frequency (int) – the desired clock rate in Hertz. The actual clock rate may be higher or lower due to the granularity of available clock settings. Check the frequency attribute for the actual clock rate.
  • width (int) – the number of data lines to use. Must be 1 or 4 and must also not exceed the number of data lines at construction

Note

Leaving a value unspecified or 0 means the current setting is kept

count(self)

Returns the total number of sectors

Due to technical limitations, this is a function and not a property.

Returns:The number of 512-byte blocks, as a number
readblocks(self, start_block: int, buf: WriteableBuffer)

Read one or more blocks from the card

Parameters:
  • start_block (int) – The block to start reading from
  • buf (WriteableBuffer) – The buffer to write into. Length must be multiple of 512.
Returns:

None

writeblocks(self, start_block: int, buf: ReadableBuffer)

Write one or more blocks to the card

Parameters:
  • start_block (int) – The block to start writing from
  • buf (ReadableBuffer) – The buffer to read from. Length must be multiple of 512.
Returns:

None

deinit(self)

Disable permanently.

Returns:None
__enter__(self)

No-op used by Context Managers. Provided by context manager helper.

__exit__(self)

Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.