33#define SD_HC_BLOCK_SIZE (512)
34#define SDCARD_SPI_INIT_ERROR (-1)
35#define SDCARD_SPI_OK (0)
37#define SD_SIZE_OF_OID 2
38#define SD_SIZE_OF_PNM 5
240 void *data, uint16_t blocksize,
267 const void *data, uint16_t blocksize,
Low-level GPIO peripheral driver interface definitions.
sd_version_t
version type of SD-card
int sdcard_spi_init(sdcard_spi_t *card, const sdcard_spi_params_t *params)
Initializes the sd-card with the given parameters in sdcard_spi_t structure.
uint64_t sdcard_spi_get_capacity(sdcard_spi_t *card)
Gets the capacity of the card.
int sdcard_spi_write_blocks(sdcard_spi_t *card, uint32_t blockaddr, const void *data, uint16_t blocksize, uint16_t nblocks, sd_rw_response_t *state)
Writes data blocks (usually multiples of 512 Bytes) from buffer to card.
sd_rw_response_t
sdcard_spi r/w-operation return values
int sdcard_spi_read_blocks(sdcard_spi_t *card, uint32_t blockaddr, void *data, uint16_t blocksize, uint16_t nblocks, sd_rw_response_t *state)
Reads data blocks (usually multiples of 512 Bytes) from card to buffer.
#define SD_SIZE_OF_OID
OID (OEM/application ID field in CID reg)
#define SD_SIZE_OF_PNM
PNM (product name field in CID reg)
@ SD_UNKNOWN
SD-version unknown.
@ SD_RW_TIMEOUT
cmd timed out (not-busy-state wasn't entered)
@ SD_RW_WRITE_ERROR
data-packet response indicates error
@ SD_RW_NOT_SUPPORTED
operation not supported on used card
@ SD_RW_RX_TX_ERROR
error while performing SPI read/write
@ SD_RW_CRC_MISMATCH
CRC-mismatch of received data.
@ SD_RW_NO_TOKEN
no token was received (on block read)
Low-level SPI peripheral driver interface definition.
CID register see section 5.2 in SD-Spec v5.00.
uint8_t CID_CRC
CRC7 checksum.
uint8_t MID
Manufacturer ID.
uint32_t PSN
Product serial number.
uint16_t MDT
Manufacturing date.
uint8_t PRV
Product revision.
CSD register with csd structure version 1.0 see section 5.3.2 in SD-Spec v5.00.
uint8_t WRITE_BL_LEN
see section 5.3.2 in SD-Spec v5.00
uint8_t R2W_FACTOR
see section 5.3.2 in SD-Spec v5.00
uint8_t WP_GRP_ENABLE
see section 5.3.2 in SD-Spec v5.00
uint8_t FILE_FORMAT_GRP
see section 5.3.2 in SD-Spec v5.00
uint8_t TAAC
see section 5.3.2 in SD-Spec v5.00
uint8_t TRAN_SPEED
see section 5.3.2 in SD-Spec v5.00
uint8_t READ_BL_PARTIAL
see section 5.3.2 in SD-Spec v5.00
uint8_t WRITE_BLK_MISALIGN
see section 5.3.2 in SD-Spec v5.00
uint8_t TMP_WRITE_PROTECT
see section 5.3.2 in SD-Spec v5.00
uint8_t CSD_CRC
see section 5.3.2 in SD-Spec v5.00
uint8_t READ_BL_LEN
see section 5.3.2 in SD-Spec v5.00
uint8_t COPY
see section 5.3.2 in SD-Spec v5.00
uint8_t SECTOR_SIZE
see section 5.3.2 in SD-Spec v5.00
uint16_t C_SIZE
see section 5.3.2 in SD-Spec v5.00
uint8_t VDD_W_CURR_MIN
see section 5.3.2 in SD-Spec v5.00
uint8_t VDD_W_CURR_MAX
see section 5.3.2 in SD-Spec v5.00
uint8_t WP_GRP_SIZE
see section 5.3.2 in SD-Spec v5.00
uint8_t DSR_IMP
see section 5.3.2 in SD-Spec v5.00
uint8_t WRITE_BL_PARTIAL
see section 5.3.2 in SD-Spec v5.00
uint8_t NSAC
see section 5.3.2 in SD-Spec v5.00
uint8_t READ_BLK_MISALIGN
see section 5.3.2 in SD-Spec v5.00
uint16_t CCC
see section 5.3.2 in SD-Spec v5.00
uint8_t CSD_STRUCTURE
see section 5.3.2 in SD-Spec v5.00
uint8_t FILE_FORMAT
see section 5.3.2 in SD-Spec v5.00
uint8_t VDD_R_CURR_MIN
see section 5.3.2 in SD-Spec v5.00
uint8_t C_SIZE_MULT
see section 5.3.2 in SD-Spec v5.00
uint8_t VDD_R_CURR_MAX
see section 5.3.2 in SD-Spec v5.00
uint8_t PERM_WRITE_PROTECT
see section 5.3.2 in SD-Spec v5.00
uint8_t ERASE_BLK_EN
see section 5.3.2 in SD-Spec v5.00
CSD register with csd structure version 2.0 see section 5.3.3 in SD-Spec v5.00.
uint8_t READ_BLK_MISALIGN
see section 5.3.3 in SD-Spec v5.00
uint32_t C_SIZE
see section 5.3.3 in SD-Spec v5.00
uint8_t WP_GRP_ENABLE
see section 5.3.3 in SD-Spec v5.00
uint8_t TAAC
see section 5.3.3 in SD-Spec v5.00
uint8_t R2W_FACTOR
see section 5.3.3 in SD-Spec v5.00
uint8_t CSD_STRUCTURE
see section 5.3.3 in SD-Spec v5.00
uint8_t READ_BL_PARTIAL
see section 5.3.3 in SD-Spec v5.00
uint8_t READ_BL_LEN
see section 5.3.3 in SD-Spec v5.00
uint8_t FILE_FORMAT_GRP
see section 5.3.3 in SD-Spec v5.00
uint8_t TRAN_SPEED
see section 5.3.3 in SD-Spec v5.00
uint8_t ERASE_BLK_EN
see section 5.3.3 in SD-Spec v5.00
uint8_t WRITE_BL_LEN
see section 5.3.3 in SD-Spec v5.00
uint8_t WRITE_BLK_MISALIGN
see section 5.3.3 in SD-Spec v5.00
uint8_t CSD_CRC
see section 5.3.3 in SD-Spec v5.00
uint8_t COPY
see section 5.3.3 in SD-Spec v5.00
uint16_t CCC
see section 5.3.3 in SD-Spec v5.00
uint8_t TMP_WRITE_PROTECT
see section 5.3.3 in SD-Spec v5.00
uint8_t NSAC
see section 5.3.3 in SD-Spec v5.00
uint8_t PERM_WRITE_PROTECT
see section 5.3.3 in SD-Spec v5.00
uint8_t WP_GRP_SIZE
see section 5.3.3 in SD-Spec v5.00
uint8_t SECTOR_SIZE
see section 5.3.3 in SD-Spec v5.00
uint8_t WRITE_BL_PARTIAL
see section 5.3.3 in SD-Spec v5.00
uint8_t FILE_FORMAT
see section 5.3.3 in SD-Spec v5.00
uint8_t DSR_IMP
see section 5.3.3 in SD-Spec v5.00
SD status register (see section 4.10.2 in SD-Spec v5.00)
uint8_t AU_SIZE
see section 4.10.2.4 in SD-Spec v5.00
uint8_t DAT_BUS_WIDTH
see section 4.10.2 in SD-Spec v5.00
uint32_t VSC_AU_SIZE
see section 4.10.2.11 in SD-Spec v5.00
uint8_t SPEED_CLASS
see section 4.10.2.2 in SD-Spec v5.00
uint8_t ERASE_OFFSET
see section 4.10.2.7 in SD-Spec v5.00
uint16_t SD_CARD_TYPE
see section 4.10.2 in SD-Spec v5.00
uint8_t SECURED_MODE
see section 4.10.2 in SD-Spec v5.00
uint16_t ERASE_SIZE
see section 4.10.2.5 in SD-Spec v5.00
uint32_t SUS_ADDR
see section 4.10.2.12 in SD-Spec v5.00
uint8_t UHS_SPEED_GRADE
see section 4.10.2.8 in SD-Spec v5.00
uint8_t ERASE_TIMEOUT
see section 4.10.2.6 in SD-Spec v5.00
uint8_t VIDEO_SPEED_CLASS
see section 4.10.2.10 in SD-Spec v5.00
uint32_t SIZE_OF_PROTECTED_AREA
see section 4.10.2 in SD-Spec v5.00
uint8_t UHS_AU_SIZE
see section 4.10.2.9 in SD-Spec v5.00
uint8_t PERFORMANCE_MOVE
see section 4.10.2.3 in SD-Spec v5.00
gpio_t clk
pin connected to the CLK sd pad
gpio_t cs
pin connected to the DAT3 sd pad
bool power_act_high
true if card power is enabled by 'power'-pin HIGH
spi_t spi_dev
SPI bus used.
gpio_t mosi
pin connected to the CMD sd pad
gpio_t power
pin that controls sd power circuit
gpio_t miso
pin connected to the DAT0 sd pad
Device descriptor for sdcard_spi.
spi_clk_t spi_clk
active SPI clock speed
bool init_done
set to true once the init procedure completed successfully
bool use_block_addr
true if block addressing (vs.
int csd_structure
version of the CSD register structure
const sdcard_spi_params_t * params
parameters for pin and spi config
sd_version_t card_type
version of SD-card
CSD register (see section 5.3 in SD-Spec v5.00)
csd_v1_t v1
see section 5.3.2 in SD-Spec v5.00
csd_v2_t v2
see section 5.3.3 in SD-Spec v5.00