Device::Chip::SDCard - chip driver for SD and MMC cards
my $card = Device::Chip::SDCard->new;
await $card->mount( Device::Chip::Adapter::...->new );
my $bytes = await $card->read_block( 0 );
print "Read block zero:\n";
printf "%v02X\n", $bytes;
This Device::Chip subclass provides specific communication to an SD or MMC storage card attached via an SPI adapter.
At present it only supports MMC and SDSC ("standard capacity") cards, not SDHC or SDXC.
The following methods documented in an await expression return Future instances.
Checks that an SD card is present, switches it into SPI mode and waits for its initialisation process to complete.
$n_bytes = await $card->size;
Returns the size of the media card in bytes.
$data = await $card->read_csd;
Returns a HASH reference containing decoded fields from the SD card's CSD ("card-specific data") register.
This hash will contain the following fields:
The hash will also contain the following calculated fields, derived from the decoded fields above for convenience of calling code.
blocks # number of blocks implied by C_SIZE / C_SIZE_MULT
bytes # number of bytes of storage, implied by blocks and READ_BL_LEN
$fields = await $card->read_ocr;
Returns a HASH reference containing decoded fields from the card's OCR ("operating conditions register").
3V5, 3V4, 3V3, ..., 2V7
$bytes = await $card->read_block( $lba );
Returns a 512-byte bytestring containing data read from the given sector of the card.
Support block writing.
Support the different initialisation sequence (and block size requirements) of SDHC cards.
Paul Evans <firstname.lastname@example.org>
To install Device::Chip::SDCard, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.