Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SD/MMC/SDIO common stack

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

 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_MMC   (1 << 1)
#define CARD_TYPE_SD   (1 << 0)
#define CARD_TYPE_SD_COMBO   (CARD_TYPE_SD | CARD_TYPE_SDIO)

SD combo card (io + memory)

Referenced by main_display_info_card(), and sdio_op_cond().

#define CARD_TYPE_SDIO   (1 << 2)

SDIO card.

Referenced by main(), main_display_info_card(), and sdio_op_cond().

#define CARD_TYPE_UNKNOWN   (0)

Unknown type card.

Referenced by main_display_info_card(), and 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)
#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)
#define SD_MMC_BLOCK_SIZE   512
#define SD_MMC_ERR_NO_CARD   2

Referenced by main(), and sd_mmc_select_slot().

#define SD_MMC_ERR_PARAM   6
#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
#define SD_MMC_INIT_ONGOING   1

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.

Parameters
slotCard slot to use
Return values
SD_MMC_OKCard ready
SD_MMC_INIT_ONGOINGInitialization on going
SD_MMC_ERR_NO_CARDCard not present in slot
Othervalue 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 main().

uint32_t sd_mmc_get_capacity ( uint8_t  slot)

Get the memory capacity.

Parameters
slotCard slot
Returns
Capacity (unit KB)

References sd_mmc_card::capacity, sd_mmc_deselect_slot(), SD_MMC_OK, and sd_mmc_select_slot().

Referenced by main_display_info_card(), and main_test_memory().

card_type_t sd_mmc_get_type ( uint8_t  slot)

Get the card type.

Parameters
slotCard slot
Returns
Card type (card_type_t)

References CARD_TYPE_UNKNOWN, sd_mmc_deselect_slot(), SD_MMC_OK, sd_mmc_select_slot(), and sd_mmc_card::type.

Referenced by main(), and main_display_info_card().

card_version_t sd_mmc_get_version ( uint8_t  slot)

Get the card version.

Parameters
slotCard slot
Returns
Card version (card_version_t)

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.

Referenced by main().

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.

Parameters
slotCard slot to use
startStart block number to to read.
nb_blockTotal number of blocks to be read.
Returns
return SD_MMC_OK if success, otherwise return an error code (sd_mmc_err_t).

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 main_test_memory().

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.

Parameters
slotCard slot to use
startStart block number to be written.
nb_blockTotal number of blocks to be written.
Returns
return SD_MMC_OK if success, otherwise return an error code (sd_mmc_err_t).

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 main_test_memory().

bool sd_mmc_is_write_protected ( uint8_t  slot)

Get the card write protection status.

Parameters
slotCard slot
Returns
true, if write portected

References ioport_get_pin_level(), sd_mmc_cards, and UNUSED.

Referenced by main_test_memory(), and sd_mmc_init_write_blocks().

uint8_t sd_mmc_nb_slot ( void  )

Return the number of slot available.

Returns
Number of card slot available

References SD_MMC_MEM_CNT.

Referenced by main().

sd_mmc_err_t sd_mmc_start_read_blocks ( void *  dest,
uint16_t  nb_block 
)

Start the read blocks of data from the card.

Parameters
destPointer to read buffer.
nb_blockNumber of blocks to be read.
Returns
return SD_MMC_OK if started, otherwise return an error code (sd_mmc_err_t).

References Assert, driver_start_read_blocks, SD_MMC_ERR_COMM, sd_mmc_nb_block_remaining, and SD_MMC_OK.

Referenced by main_test_memory().

sd_mmc_err_t sd_mmc_start_write_blocks ( const void *  src,
uint16_t  nb_block 
)

Start the write blocks of data.

Parameters
srcPointer to write buffer.
nb_blockNumber of blocks to be written.
Returns
return SD_MMC_OK if started, otherwise return an error code (sd_mmc_err_t).

References Assert, driver_start_write_blocks, SD_MMC_ERR_COMM, sd_mmc_nb_block_remaining, and SD_MMC_OK.

Referenced by main_test_memory().

sd_mmc_err_t sd_mmc_wait_end_of_read_blocks ( bool  abort)

Wait the end of read blocks of data from the card.

Parameters
abortAbort reading process initialized by sd_mmc_init_read_blocks() after the reading issued by sd_mmc_start_read_blocks() is done
Returns
return SD_MMC_OK if success, otherwise return an error code (sd_mmc_err_t).

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 main_test_memory().

sd_mmc_err_t sd_mmc_wait_end_of_write_blocks ( bool  abort)

Wait the end of write blocks of data.

Parameters
abortAbort writing process initialized by sd_mmc_init_write_blocks() after the writing issued by sd_mmc_start_write_blocks() is done
Returns
return SD_MMC_OK if success, otherwise return an error code (sd_mmc_err_t).

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 main_test_memory().

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.

Parameters
slotCard slot to use
func_numFunction number.
addrRegister address to read from.
destPointer to read buffer.
Returns
return SD_MMC_OK if success, otherwise return an error code (sd_mmc_err_t).

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 main_test_sdio().

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.

Parameters
slotCard slot to use
func_numFunction number.
addrFirst register address to read from.
inc_addr0 - The data address is fixed. 1 - The data address increase automatically.
destPointer to read buffer.
sizeNumber of bytes to read (1 ~ 512).
Returns
return SD_MMC_OK if success, otherwise return an error code (sd_mmc_err_t).

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 main_test_sdio().

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.

Parameters
slotCard slot to use
func_numFunction number.
addrRegister address to read from.
dataData to be written.
Returns
return SD_MMC_OK if success, otherwise return an error code (sd_mmc_err_t).

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 main_test_sdio().

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.

Parameters
slotCard slot to use
func_numFunction number.
addrFirst register address to write to.
inc_addr0 - The data address is fixed. 1 - The data address increase automatically.
srcPointer to write buffer.
sizeNumber of bytes to read (1 ~ 512).
Returns
return SD_MMC_OK if success, otherwise return an error code (sd_mmc_err_t).

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 main_test_sdio().