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

 
 Common SPI interface for SD/MMC stack
 
 SD/MMC Memory
 SD/MMC memory APIs required by CTRL_ACCESS module (Memory Control Access).
 
 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...
 

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_SD_COMBO   (CARD_TYPE_SD | CARD_TYPE_SDIO)

SD combo card (io + memory)

Referenced by main_display_info_card().

#define CARD_TYPE_SDIO   (1 << 2)

SDIO card.

#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_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_mci_card_init(), sd_mmc_select_slot(), sd_mmc_spi_card_init(), and sd_mmc_card::state.

Referenced by _sd_init(), init_storage(), main(), run_sd_mmc_init_test(), run_sd_mmc_rw_test(), and sd_mmc_test_unit_ready().

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(), main_test_memory(), rw_test(), and sd_mmc_read_capacity().

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(), main_display_info_card(), run_sd_mmc_rw_test(), and sd_mmc_test_unit_ready().

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.

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, and sd_mmc_card::state.

Referenced by _sd_init(), init_storage(), main(), and 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.

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_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(), rw_test(), sd_mmc_mem_2_ram(), and sd_mmc_usb_read_10().

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_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(), rw_test(), sd_mmc_ram_2_mem(), and sd_mmc_usb_write_10().

bool sd_mmc_is_write_protected ( uint8_t  slot)

Get the card write protection status.

Parameters
slotCard slot
Returns
true, if write portected

References port_pin_get_input_level(), sd_mmc_cards, and UNUSED.

Referenced by main_test_memory(), rw_test(), sd_mmc_init_write_blocks(), and sd_mmc_wr_protect().

uint8_t sd_mmc_nb_slot ( void  )

Return the number of slot available.

Returns
Number of card slot available

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, and SD_MMC_OK.

Referenced by main_test_memory(), rw_test(), sd_mmc_mem_2_ram(), and sd_mmc_usb_read_10().

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, and SD_MMC_OK.

Referenced by main_test_memory(), rw_test(), sd_mmc_ram_2_mem(), and sd_mmc_usb_write_10().

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_OK, and SDMMC_CMD12_STOP_TRANSMISSION.

Referenced by main_test_memory(), rw_test(), sd_mmc_mem_2_ram(), and sd_mmc_usb_read_10().

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_OK, and SDMMC_CMD12_STOP_TRANSMISSION.

Referenced by main_test_memory(), rw_test(), sd_mmc_ram_2_mem(), and sd_mmc_usb_write_10().