class SDCard – secure digital memory card
SD cards are one of the most common small form factor removable storage media.
SD cards come in a variety of sizes and physical form factors. MMC cards are
similar removable storage devices while eMMC devices are electrically similar
storage devices designed to be embedded into other systems. All three form
share a common protocol for communication with their host system and high-level
support looks the same for them all. As such in MicroPython they are implemented
in a single class called machine.SDCard .
Both SD and MMC interfaces support being accessed with a variety of bus widths.
When being accessed with a 1-bit wide interface they can be accessed using the
SPI protocol. Different MicroPython hardware platforms support different widths
and pin configurations but for most platforms there is a standard configuration
for any given hardware. In general constructing an SDCard object with without
passing any parameters will initialise the interface to the default card slot
for the current hardware. The arguments listed below represent the common
arguments that might need to be set in order to use either a non-standard slot
or a non-standard pin assignment. The exact subset of arguments supported will
vary from platform to platform.
- SDCard(slot=1, width=1, cd=None, wp=None, sck=None, miso=None, mosi=None,
- cs=None, cmd=None, data=None, freq=20000000)
This class provides access to SD or MMC storage cards using either a dedicated SD/MMC interface hardware or through an SPI channel. The class implements the block protocol defined by
vfs.AbstractBlockDev. This allows the mounting of an SD card to be as simple as:vfs.mount(machine.SDCard(), "/sd")
The constructor takes the following parameters:
slot selects which of the available interfaces to use. Leaving this unset will select the default interface.
width selects the bus width for the SD/MMC interface. This many data pins must be connected to the SD card.
cd can be used to specify a card-detect pin.
wp can be used to specify a write-protect pin.
sck can be used to specify an SPI clock pin.
miso can be used to specify an SPI miso pin.
mosi can be used to specify an SPI mosi pin.
cs can be used to specify an SPI chip select pin.
Implementation-specific details
Different implementations of the SDCard class on different hardware support
varying subsets of the options above.
W55MH32L-EVB
The W55MH32L-EVB has just one slot. No arguments are necessary or supported.
- class machine.SDCard(slot=1)
The pins used for the USDHC peripheral have to be configured in mpconfigboard.h.
Most of the controllers supported by the mimxrt port provide up to two USDHC
peripherals. Therefore the pin configuration is performed using the macro
MICROPY_USDHCx with x being 1 or 2 respectively.
The following shows an example configuration for USDHC1:
#define MICROPY_USDHC1 \
{ \
.cmd = { GPIO_SD_B0_02_USDHC1_CMD}, \
.clk = { GPIO_SD_B0_03_USDHC1_CLK }, \
.cd_b = { GPIO_SD_B0_06_USDHC1_CD_B },\
.data0 = { GPIO_SD_B0_04_USDHC1_DATA0 },\
.data1 = { GPIO_SD_B0_05_USDHC1_DATA1 },\
.data2 = { GPIO_SD_B0_00_USDHC1_DATA2 },\
.data3 = { GPIO_SD_B0_01_USDHC1_DATA3 },\
}
If the card detect pin is not used (cb_b pin) then the respective entry has to be filled with the following dummy value:
#define USDHC_DUMMY_PIN NULL , 0
Based on the definition of macro MICROPY_USDHC1 and/or MICROPY_USDHC2
the machine.SDCard module either supports one or two slots. If only one of
the defines is provided, calling machine.SDCard() or machine.SDCard(1)
will return an instance using the respective USDHC peripheral. When both macros
are defined, calling machine.SDCard(2) returns an instance using USDHC2.