SD/MMC/SDIO basic APIs used by SD/MMC/SDIO memory APIs (sd_mmc_stack_mem_group).
Also, it can be used by application which use the SDIO card or specific application which does not need of File System.
For usual application which use the SD/MMC card in memory mode with a file system, please refer to sd_mmc_stack_mem_group.
Modules | |
Common SPI interface for SD/MMC stack | |
SD/MMC Protocol Definition | |
Macros | |
#define | SD_MMC_BLOCK_SIZE 512 |
This SD MMC stack uses the maximum block size autorized (512 bytes) More... | |
Typedefs | |
typedef uint8_t | card_type_t |
Type of card type. More... | |
typedef uint8_t | card_version_t |
Type of card version. More... | |
typedef uint8_t | sd_mmc_err_t |
Type of return error code. More... | |
Functions | |
sd_mmc_err_t | sd_mmc_check (uint8_t slot) |
Performs a card checks. More... | |
uint32_t | sd_mmc_get_capacity (uint8_t slot) |
Get the memory capacity. More... | |
card_type_t | sd_mmc_get_type (uint8_t slot) |
Get the card type. More... | |
card_version_t | sd_mmc_get_version (uint8_t slot) |
Get the card version. More... | |
void | sd_mmc_init (void) |
Initialize the SD/MMC stack and low level driver required. More... | |
sd_mmc_err_t | sd_mmc_init_read_blocks (uint8_t slot, uint32_t start, uint16_t nb_block) |
Initialize the read blocks of data from the card. More... | |
sd_mmc_err_t | sd_mmc_init_write_blocks (uint8_t slot, uint32_t start, uint16_t nb_block) |
Initialize the write blocks of data. More... | |
bool | sd_mmc_is_write_protected (uint8_t slot) |
Get the card write protection status. More... | |
uint8_t | sd_mmc_nb_slot (void) |
Return the number of slot available. More... | |
sd_mmc_err_t | sd_mmc_start_read_blocks (void *dest, uint16_t nb_block) |
Start the read blocks of data from the card. More... | |
sd_mmc_err_t | sd_mmc_start_write_blocks (const void *src, uint16_t nb_block) |
Start the write blocks of data. More... | |
sd_mmc_err_t | sd_mmc_wait_end_of_read_blocks (bool abort) |
Wait the end of read blocks of data from the card. More... | |
sd_mmc_err_t | sd_mmc_wait_end_of_write_blocks (bool abort) |
Wait the end of write blocks of data. More... | |
sd_mmc_err_t | sdio_read_direct (uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t *dest) |
Read one byte from SDIO using RW_DIRECT command. More... | |
sd_mmc_err_t | sdio_read_extended (uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t inc_addr, uint8_t *dest, uint16_t size) |
Read bytes from SDIO using RW_EXTENDED command. More... | |
sd_mmc_err_t | sdio_write_direct (uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t data) |
Write one byte to SDIO using RW_DIRECT command. More... | |
sd_mmc_err_t | sdio_write_extended (uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t inc_addr, uint8_t *src, uint16_t size) |
Write bytes to SDIO using RW_EXTENDED command. More... | |
Return error codes | |
#define | SD_MMC_OK 0 |
#define | SD_MMC_INIT_ONGOING 1 |
#define | SD_MMC_ERR_NO_CARD 2 |
#define | SD_MMC_ERR_UNUSABLE 3 |
#define | SD_MMC_ERR_SLOT 4 |
#define | SD_MMC_ERR_COMM 5 |
#define | SD_MMC_ERR_PARAM 6 |
#define | SD_MMC_ERR_WP 7 |
Card Types | |
#define | CARD_TYPE_UNKNOWN (0) |
Unknown type card. More... | |
#define | CARD_TYPE_SD (1 << 0) |
SD card. More... | |
#define | CARD_TYPE_MMC (1 << 1) |
MMC card. More... | |
#define | CARD_TYPE_SDIO (1 << 2) |
SDIO card. More... | |
#define | CARD_TYPE_HC (1 << 3) |
High capacity card. More... | |
#define | CARD_TYPE_SD_COMBO (CARD_TYPE_SD | CARD_TYPE_SDIO) |
SD combo card (io + memory) More... | |
Card Versions | |
#define | CARD_VER_UNKNOWN (0) |
#define | CARD_VER_SD_1_0 (0x10) |
#define | CARD_VER_SD_1_10 (0x1A) |
#define | CARD_VER_SD_2_0 (0X20) |
#define | CARD_VER_SD_3_0 (0X30) |
#define | CARD_VER_MMC_1_2 (0x12) |
#define | CARD_VER_MMC_1_4 (0x14) |
#define | CARD_VER_MMC_2_2 (0x22) |
#define | CARD_VER_MMC_3 (0x30) |
#define | CARD_VER_MMC_4 (0x40) |
#define CARD_TYPE_HC (1 << 3) |
High capacity card.
Referenced by mmc_mci_op_cond(), mmc_spi_op_cond(), sd_mci_op_cond(), sd_mmc_init_read_blocks(), sd_mmc_init_write_blocks(), sd_mmc_spi_card_init(), and sd_spi_op_cond().
#define CARD_TYPE_MMC (1 << 1) |
MMC card.
Referenced by run_sd_mmc_sdio_rw_test(), sd_mmc_mci_card_init(), and sd_mmc_spi_card_init().
#define CARD_TYPE_SD (1 << 0) |
SD card.
Referenced by run_sd_mmc_sdio_rw_test(), sd_mmc_mci_card_init(), and sd_mmc_spi_card_init().
#define CARD_TYPE_SD_COMBO (CARD_TYPE_SD | CARD_TYPE_SDIO) |
SD combo card (io + memory)
Referenced by sdio_op_cond().
#define CARD_TYPE_SDIO (1 << 2) |
SDIO card.
Referenced by run_sd_mmc_sdio_rw_test(), and sdio_op_cond().
#define CARD_TYPE_UNKNOWN (0) |
Unknown type card.
Referenced by sd_mmc_get_type().
#define CARD_VER_MMC_1_2 (0x12) |
Referenced by mmc_decode_csd().
#define CARD_VER_MMC_1_4 (0x14) |
Referenced by mmc_decode_csd().
#define CARD_VER_MMC_2_2 (0x22) |
Referenced by mmc_decode_csd().
#define CARD_VER_MMC_3 (0x30) |
Referenced by mmc_decode_csd().
#define CARD_VER_MMC_4 (0x40) |
Referenced by mmc_decode_csd(), sd_mmc_mci_install_mmc(), and sd_mmc_spi_install_mmc().
#define CARD_VER_SD_1_0 (0x10) |
Referenced by sd_acmd51(), and sd_mmc_mci_card_init().
#define CARD_VER_SD_1_10 (0x1A) |
Referenced by sd_acmd51().
#define CARD_VER_SD_2_0 (0X20) |
Referenced by sd_acmd51().
#define CARD_VER_SD_3_0 (0X30) |
Referenced by sd_acmd51().
#define CARD_VER_UNKNOWN (0) |
Referenced by sd_mmc_get_version(), sd_mmc_mci_card_init(), and sd_mmc_spi_card_init().
#define SD_MMC_BLOCK_SIZE 512 |
This SD MMC stack uses the maximum block size autorized (512 bytes)
Referenced by run_sd_mmc_rw_test(), sd_mmc_init_read_blocks(), sd_mmc_init_write_blocks(), sd_mmc_mci_card_init(), sd_mmc_mci_install_mmc(), sd_mmc_spi_card_init(), and sd_mmc_spi_install_mmc().
#define SD_MMC_ERR_COMM 5 |
#define SD_MMC_ERR_NO_CARD 2 |
Referenced by run_sd_mmc_init_test(), and sd_mmc_select_slot().
#define SD_MMC_ERR_PARAM 6 |
Referenced by sdio_read_direct(), sdio_read_extended(), and sdio_write_extended().
#define SD_MMC_ERR_SLOT 4 |
Referenced by sd_mmc_select_slot().
#define SD_MMC_ERR_UNUSABLE 3 |
Referenced by sd_mmc_check(), and sd_mmc_select_slot().
#define SD_MMC_ERR_WP 7 |
Referenced by sd_mmc_init_write_blocks().
#define SD_MMC_INIT_ONGOING 1 |
Referenced by run_sd_mmc_init_test(), sd_mmc_check(), and sd_mmc_select_slot().
#define SD_MMC_OK 0 |
Referenced by run_sd_mmc_init_test(), run_sd_mmc_rw_test(), run_sd_mmc_sdio_rw_test(), run_sdio_rw_test(), sd_mmc_get_capacity(), sd_mmc_get_type(), sd_mmc_get_version(), sd_mmc_init_read_blocks(), sd_mmc_init_write_blocks(), sd_mmc_select_slot(), sd_mmc_start_read_blocks(), sd_mmc_start_write_blocks(), sd_mmc_wait_end_of_read_blocks(), sd_mmc_wait_end_of_write_blocks(), sdio_read_direct(), sdio_read_extended(), sdio_write_direct(), and sdio_write_extended().
typedef uint8_t card_type_t |
Type of card type.
typedef uint8_t card_version_t |
Type of card version.
typedef uint8_t sd_mmc_err_t |
Type of return error code.
sd_mmc_err_t sd_mmc_check | ( | uint8_t | slot | ) |
Performs a card checks.
slot | Card slot to use |
SD_MMC_OK | Card ready |
SD_MMC_INIT_ONGOING | Initialization on going |
SD_MMC_ERR_NO_CARD | Card not present in slot |
Other | value for error cases, see sd_mmc_err_t |
References SD_MMC_CARD_STATE_READY, SD_MMC_CARD_STATE_UNUSABLE, sd_mmc_debug, sd_mmc_deselect_slot(), SD_MMC_ERR_UNUSABLE, SD_MMC_INIT_ONGOING, sd_mmc_is_spi, sd_mmc_mci_card_init(), sd_mmc_select_slot(), sd_mmc_spi_card_init(), and sd_mmc_card::state.
Referenced by run_sd_mmc_init_test(), and run_sd_mmc_sdio_rw_test().
uint32_t sd_mmc_get_capacity | ( | uint8_t | slot | ) |
Get the memory capacity.
slot | Card slot |
References sd_mmc_card::capacity, sd_mmc_deselect_slot(), SD_MMC_OK, and sd_mmc_select_slot().
Referenced by run_sd_mmc_rw_test().
card_type_t sd_mmc_get_type | ( | uint8_t | slot | ) |
Get the card type.
slot | Card slot |
References CARD_TYPE_UNKNOWN, sd_mmc_deselect_slot(), SD_MMC_OK, sd_mmc_select_slot(), and sd_mmc_card::type.
Referenced by run_sd_mmc_sdio_rw_test().
card_version_t sd_mmc_get_version | ( | uint8_t | slot | ) |
Get the card version.
slot | Card slot |
References CARD_VER_UNKNOWN, sd_mmc_deselect_slot(), SD_MMC_OK, sd_mmc_select_slot(), and sd_mmc_card::version.
void sd_mmc_init | ( | void | ) |
Initialize the SD/MMC stack and low level driver required.
Enable the PMC clock for the card detect pins
Enable the PMC clock for the card write protection pins
References driver_init, MREPEAT, SD_MMC_CARD_STATE_NO_CARD, sd_mmc_cards, SD_MMC_ENABLE_CD_PIN, SD_MMC_ENABLE_WP_PIN, SD_MMC_MEM_CNT, sd_mmc_slot_sel, and sd_mmc_card::state.
Referenced by run_sd_mmc_init_test().
sd_mmc_err_t sd_mmc_init_read_blocks | ( | uint8_t | slot, |
uint32_t | start, | ||
uint16_t | nb_block | ||
) |
Initialize the read blocks of data from the card.
slot | Card slot to use |
start | Start block number to to read. |
nb_block | Total number of blocks to be read. |
References CARD_STATUS_ERR_RD_WR, CARD_TYPE_HC, driver_adtc_start, driver_get_response, SD_MMC_BLOCK_SIZE, sd_mmc_cmd13(), sd_mmc_debug, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, sd_mmc_is_mci, sd_mmc_nb_block_remaining, sd_mmc_nb_block_to_tranfer, SD_MMC_OK, sd_mmc_select_slot(), SDMMC_CMD17_READ_SINGLE_BLOCK, SDMMC_CMD18_READ_MULTIPLE_BLOCK, SDMMC_CMD_GET_INDEX, and sd_mmc_card::type.
Referenced by run_sd_mmc_rw_test().
sd_mmc_err_t sd_mmc_init_write_blocks | ( | uint8_t | slot, |
uint32_t | start, | ||
uint16_t | nb_block | ||
) |
Initialize the write blocks of data.
slot | Card slot to use |
start | Start block number to be written. |
nb_block | Total number of blocks to be written. |
References CARD_STATUS_ERR_RD_WR, CARD_TYPE_HC, driver_adtc_start, driver_get_response, SD_MMC_BLOCK_SIZE, sd_mmc_debug, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, SD_MMC_ERR_WP, sd_mmc_is_mci, sd_mmc_is_write_protected(), sd_mmc_nb_block_remaining, sd_mmc_nb_block_to_tranfer, SD_MMC_OK, sd_mmc_select_slot(), SDMMC_CMD24_WRITE_BLOCK, SDMMC_CMD25_WRITE_MULTIPLE_BLOCK, SDMMC_CMD_GET_INDEX, and sd_mmc_card::type.
Referenced by run_sd_mmc_rw_test().
bool sd_mmc_is_write_protected | ( | uint8_t | slot | ) |
Get the card write protection status.
slot | Card slot |
References ioport_get_pin_level(), sd_mmc_cards, and UNUSED.
Referenced by run_sd_mmc_rw_test(), and sd_mmc_init_write_blocks().
uint8_t sd_mmc_nb_slot | ( | void | ) |
Return the number of slot available.
References SD_MMC_MEM_CNT.
sd_mmc_err_t sd_mmc_start_read_blocks | ( | void * | dest, |
uint16_t | nb_block | ||
) |
Start the read blocks of data from the card.
dest | Pointer to read buffer. |
nb_block | Number of blocks to be read. |
References Assert, driver_start_read_blocks, SD_MMC_ERR_COMM, sd_mmc_nb_block_remaining, and SD_MMC_OK.
Referenced by run_sd_mmc_rw_test().
sd_mmc_err_t sd_mmc_start_write_blocks | ( | const void * | src, |
uint16_t | nb_block | ||
) |
Start the write blocks of data.
src | Pointer to write buffer. |
nb_block | Number of blocks to be written. |
References Assert, driver_start_write_blocks, SD_MMC_ERR_COMM, sd_mmc_nb_block_remaining, and SD_MMC_OK.
Referenced by run_sd_mmc_rw_test().
sd_mmc_err_t sd_mmc_wait_end_of_read_blocks | ( | bool | abort | ) |
Wait the end of read blocks of data from the card.
abort | Abort reading process initialized by sd_mmc_init_read_blocks() after the reading issued by sd_mmc_start_read_blocks() is done |
References driver_adtc_stop, driver_wait_end_of_read_blocks, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, sd_mmc_nb_block_remaining, sd_mmc_nb_block_to_tranfer, SD_MMC_OK, and SDMMC_CMD12_STOP_TRANSMISSION.
Referenced by run_sd_mmc_rw_test().
sd_mmc_err_t sd_mmc_wait_end_of_write_blocks | ( | bool | abort | ) |
Wait the end of write blocks of data.
abort | Abort writing process initialized by sd_mmc_init_write_blocks() after the writing issued by sd_mmc_start_write_blocks() is done |
References driver_adtc_stop, driver_wait_end_of_write_blocks, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, sd_mmc_is_mci, sd_mmc_nb_block_remaining, sd_mmc_nb_block_to_tranfer, SD_MMC_OK, and SDMMC_CMD12_STOP_TRANSMISSION.
Referenced by run_sd_mmc_rw_test().
sd_mmc_err_t sdio_read_direct | ( | uint8_t | slot, |
uint8_t | func_num, | ||
uint32_t | addr, | ||
uint8_t * | dest | ||
) |
Read one byte from SDIO using RW_DIRECT command.
slot | Card slot to use |
func_num | Function number. |
addr | Register address to read from. |
dest | Pointer to read buffer. |
References sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, SD_MMC_ERR_PARAM, SD_MMC_OK, sd_mmc_select_slot(), sdio_cmd52(), and SDIO_CMD52_READ_FLAG.
Referenced by run_sdio_rw_test().
sd_mmc_err_t sdio_read_extended | ( | uint8_t | slot, |
uint8_t | func_num, | ||
uint32_t | addr, | ||
uint8_t | inc_addr, | ||
uint8_t * | dest, | ||
uint16_t | size | ||
) |
Read bytes from SDIO using RW_EXTENDED command.
slot | Card slot to use |
func_num | Function number. |
addr | First register address to read from. |
inc_addr | 0 - The data address is fixed. 1 - The data address increase automatically. |
dest | Pointer to read buffer. |
size | Number of bytes to read (1 ~ 512). |
References driver_start_read_blocks, driver_wait_end_of_read_blocks, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, SD_MMC_ERR_PARAM, SD_MMC_OK, sd_mmc_select_slot(), sdio_cmd53(), and SDIO_CMD53_READ_FLAG.
Referenced by run_sdio_rw_test().
sd_mmc_err_t sdio_write_direct | ( | uint8_t | slot, |
uint8_t | func_num, | ||
uint32_t | addr, | ||
uint8_t | data | ||
) |
Write one byte to SDIO using RW_DIRECT command.
slot | Card slot to use |
func_num | Function number. |
addr | Register address to read from. |
data | Data to be written. |
References sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, SD_MMC_OK, sd_mmc_select_slot(), sdio_cmd52(), and SDIO_CMD52_WRITE_FLAG.
Referenced by run_sdio_rw_test().
sd_mmc_err_t sdio_write_extended | ( | uint8_t | slot, |
uint8_t | func_num, | ||
uint32_t | addr, | ||
uint8_t | inc_addr, | ||
uint8_t * | src, | ||
uint16_t | size | ||
) |
Write bytes to SDIO using RW_EXTENDED command.
slot | Card slot to use |
func_num | Function number. |
addr | First register address to write to. |
inc_addr | 0 - The data address is fixed. 1 - The data address increase automatically. |
src | Pointer to write buffer. |
size | Number of bytes to read (1 ~ 512). |
References driver_start_write_blocks, driver_wait_end_of_write_blocks, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, SD_MMC_ERR_PARAM, SD_MMC_OK, sd_mmc_select_slot(), sdio_cmd53(), and SDIO_CMD53_WRITE_FLAG.
Referenced by run_sdio_rw_test().