CARME-M4 BSP
V1.5
|
This file provides all the SD Card driver firmware functions. More...
Modules | |
CARME SDIO SD LLD | |
Low level driver for CARME SDIO SD. | |
Data Structures | |
struct | SD_CSD |
Card Specific Data: CSD Register. More... | |
struct | SD_CID |
Card Identification Data: CID Register. More... | |
struct | SD_CardStatus |
SD Card Status. More... | |
struct | SD_CardInfo |
SD Card information. More... | |
Macros | |
#define | SD_CMD_GO_IDLE_STATE ((uint8_t)0) |
SDIO Commands Index. | |
#define | SD_CMD_SEND_OP_COND ((uint8_t)1) |
#define | SD_CMD_ALL_SEND_CID ((uint8_t)2) |
#define | SD_CMD_SET_REL_ADDR ((uint8_t)3) |
#define | SD_CMD_SET_DSR ((uint8_t)4) |
#define | SD_CMD_SDIO_SEN_OP_COND ((uint8_t)5) |
#define | SD_CMD_HS_SWITCH ((uint8_t)6) |
#define | SD_CMD_SEL_DESEL_CARD ((uint8_t)7) |
#define | SD_CMD_HS_SEND_EXT_CSD ((uint8_t)8) |
#define | SD_CMD_SEND_CSD ((uint8_t)9) |
#define | SD_CMD_SEND_CID ((uint8_t)10) |
#define | SD_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11) |
#define | SD_CMD_STOP_TRANSMISSION ((uint8_t)12) |
#define | SD_CMD_SEND_STATUS ((uint8_t)13) |
#define | SD_CMD_HS_BUSTEST_READ ((uint8_t)14) |
#define | SD_CMD_GO_INACTIVE_STATE ((uint8_t)15) |
#define | SD_CMD_SET_BLOCKLEN ((uint8_t)16) |
#define | SD_CMD_READ_SINGLE_BLOCK ((uint8_t)17) |
#define | SD_CMD_READ_MULT_BLOCK ((uint8_t)18) |
#define | SD_CMD_HS_BUSTEST_WRITE ((uint8_t)19) |
#define | SD_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20) |
#define | SD_CMD_SET_BLOCK_COUNT ((uint8_t)23) |
#define | SD_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24) |
#define | SD_CMD_WRITE_MULT_BLOCK ((uint8_t)25) |
#define | SD_CMD_PROG_CID ((uint8_t)26) |
#define | SD_CMD_PROG_CSD ((uint8_t)27) |
#define | SD_CMD_SET_WRITE_PROT ((uint8_t)28) |
#define | SD_CMD_CLR_WRITE_PROT ((uint8_t)29) |
#define | SD_CMD_SEND_WRITE_PROT ((uint8_t)30) |
#define | SD_CMD_SD_ERASE_GRP_START ((uint8_t)32) |
#define | SD_CMD_SD_ERASE_GRP_END ((uint8_t)33) |
#define | SD_CMD_ERASE_GRP_START ((uint8_t)35) |
#define | SD_CMD_ERASE_GRP_END ((uint8_t)36) |
#define | SD_CMD_ERASE ((uint8_t)38) |
#define | SD_CMD_FAST_IO ((uint8_t)39) |
#define | SD_CMD_GO_IRQ_STATE ((uint8_t)40) |
#define | SD_CMD_LOCK_UNLOCK ((uint8_t)42) |
#define | SD_CMD_APP_CMD ((uint8_t)55) |
#define | SD_CMD_GEN_CMD ((uint8_t)56) |
#define | SD_CMD_NO_CMD ((uint8_t)64) |
#define | SD_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6) |
Following commands are SD Card Specific commands. SDIO_APP_CMD should be sent before sending these commands. More... | |
#define | SD_CMD_SD_APP_STAUS ((uint8_t)13) |
#define | SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22) |
#define | SD_CMD_SD_APP_OP_COND ((uint8_t)41) |
#define | SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42) |
#define | SD_CMD_SD_APP_SEND_SCR ((uint8_t)51) |
#define | SD_CMD_SDIO_RW_DIRECT ((uint8_t)52) |
#define | SD_CMD_SDIO_RW_EXTENDED ((uint8_t)53) |
#define | SD_CMD_SD_APP_GET_MKB ((uint8_t)43) |
Following commands are SD Card Specific security commands. SDIO_APP_CMD should be sent before sending these commands. More... | |
#define | SD_CMD_SD_APP_GET_MID ((uint8_t)44) |
#define | SD_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45) |
#define | SD_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46) |
#define | SD_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47) |
#define | SD_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48) |
#define | SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18) |
#define | SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25) |
#define | SD_CMD_SD_APP_SECURE_ERASE ((uint8_t)38) |
#define | SD_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49) |
#define | SD_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48) |
#define | SD_DMA_MODE ((uint32_t)0x00000000) |
#define | SD_PRESENT ((uint8_t)0x01) |
SD detection on its memory slot. | |
#define | SD_NOT_PRESENT ((uint8_t)0x00) |
#define | SDIO_STD_CAPACITY_SD_CARD_V1_1 ((uint32_t)0x00000000) |
Supported SD Memory Cards. | |
#define | SDIO_STD_CAPACITY_SD_CARD_V2_0 ((uint32_t)0x00000001) |
#define | SDIO_HIGH_CAPACITY_SD_CARD ((uint32_t)0x00000002) |
#define | SDIO_MULTIMEDIA_CARD ((uint32_t)0x00000003) |
#define | SDIO_SECURE_DIGITAL_IO_CARD ((uint32_t)0x00000004) |
#define | SDIO_HIGH_SPEED_MULTIMEDIA_CARD ((uint32_t)0x00000005) |
#define | SDIO_SECURE_DIGITAL_IO_COMBO_CARD ((uint32_t)0x00000006) |
#define | SDIO_HIGH_CAPACITY_MMC_CARD ((uint32_t)0x00000007) |
#define | NULL 0 |
SDIO Static flags, TimeOut, FIFO Address. | |
#define | SDIO_STATIC_FLAGS ((uint32_t)0x000005FF) |
#define | SDIO_CMD0TIMEOUT ((uint32_t)0x00010000) |
#define | SD_OCR_ADDR_OUT_OF_RANGE ((uint32_t)0x80000000) |
Mask for errors Card Status R1 (OCR Register) | |
#define | SD_OCR_ADDR_MISALIGNED ((uint32_t)0x40000000) |
#define | SD_OCR_BLOCK_LEN_ERR ((uint32_t)0x20000000) |
#define | SD_OCR_ERASE_SEQ_ERR ((uint32_t)0x10000000) |
#define | SD_OCR_BAD_ERASE_PARAM ((uint32_t)0x08000000) |
#define | SD_OCR_WRITE_PROT_VIOLATION ((uint32_t)0x04000000) |
#define | SD_OCR_LOCK_UNLOCK_FAILED ((uint32_t)0x01000000) |
#define | SD_OCR_COM_CRC_FAILED ((uint32_t)0x00800000) |
#define | SD_OCR_ILLEGAL_CMD ((uint32_t)0x00400000) |
#define | SD_OCR_CARD_ECC_FAILED ((uint32_t)0x00200000) |
#define | SD_OCR_CC_ERROR ((uint32_t)0x00100000) |
#define | SD_OCR_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00080000) |
#define | SD_OCR_STREAM_READ_UNDERRUN ((uint32_t)0x00040000) |
#define | SD_OCR_STREAM_WRITE_OVERRUN ((uint32_t)0x00020000) |
#define | SD_OCR_CID_CSD_OVERWRIETE ((uint32_t)0x00010000) |
#define | SD_OCR_WP_ERASE_SKIP ((uint32_t)0x00008000) |
#define | SD_OCR_CARD_ECC_DISABLED ((uint32_t)0x00004000) |
#define | SD_OCR_ERASE_RESET ((uint32_t)0x00002000) |
#define | SD_OCR_AKE_SEQ_ERROR ((uint32_t)0x00000008) |
#define | SD_OCR_ERRORBITS ((uint32_t)0xFDFFE008) |
#define | SD_R6_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00002000) |
Masks for R6 Response. | |
#define | SD_R6_ILLEGAL_CMD ((uint32_t)0x00004000) |
#define | SD_R6_COM_CRC_FAILED ((uint32_t)0x00008000) |
#define | SD_VOLTAGE_WINDOW_SD ((uint32_t)0x80100000) |
#define | SD_HIGH_CAPACITY ((uint32_t)0x40000000) |
#define | SD_STD_CAPACITY ((uint32_t)0x00000000) |
#define | SD_CHECK_PATTERN ((uint32_t)0x000001AA) |
#define | SD_MAX_VOLT_TRIAL ((uint32_t)0x0000FFFF) |
#define | SD_ALLZERO ((uint32_t)0x00000000) |
#define | SD_WIDE_BUS_SUPPORT ((uint32_t)0x00040000) |
#define | SD_SINGLE_BUS_SUPPORT ((uint32_t)0x00010000) |
#define | SD_CARD_LOCKED ((uint32_t)0x02000000) |
#define | SD_DATATIMEOUT ((uint32_t)0xFFFFFFFF) |
#define | SD_0TO7BITS ((uint32_t)0x000000FF) |
#define | SD_8TO15BITS ((uint32_t)0x0000FF00) |
#define | SD_16TO23BITS ((uint32_t)0x00FF0000) |
#define | SD_24TO31BITS ((uint32_t)0xFF000000) |
#define | SD_MAX_DATA_LENGTH ((uint32_t)0x01FFFFFF) |
#define | SD_HALFFIFO ((uint32_t)0x00000008) |
#define | SD_HALFFIFOBYTES ((uint32_t)0x00000020) |
#define | SD_CCCC_LOCK_UNLOCK ((uint32_t)0x00000080) |
Command Class Supported. | |
#define | SD_CCCC_WRITE_PROT ((uint32_t)0x00000040) |
#define | SD_CCCC_ERASE ((uint32_t)0x00000020) |
#define | SDIO_SEND_IF_COND ((uint32_t)0x00000008) |
Following commands are SD Card Specific commands. SDIO_APP_CMD should be sent before sending these commands. | |
Enumerations | |
enum | SD_Error { SD_CMD_CRC_FAIL = (1), SD_DATA_CRC_FAIL = (2), SD_CMD_RSP_TIMEOUT = (3), SD_DATA_TIMEOUT = (4), SD_TX_UNDERRUN = (5), SD_RX_OVERRUN = (6), SD_START_BIT_ERR = (7), SD_CMD_OUT_OF_RANGE = (8), SD_ADDR_MISALIGNED = (9), SD_BLOCK_LEN_ERR = (10), SD_ERASE_SEQ_ERR = (11), SD_BAD_ERASE_PARAM = (12), SD_WRITE_PROT_VIOLATION = (13), SD_LOCK_UNLOCK_FAILED = (14), SD_COM_CRC_FAILED = (15), SD_ILLEGAL_CMD = (16), SD_CARD_ECC_FAILED = (17), SD_CC_ERROR = (18), SD_GENERAL_UNKNOWN_ERROR = (19), SD_STREAM_READ_UNDERRUN = (20), SD_STREAM_WRITE_OVERRUN = (21), SD_CID_CSD_OVERWRITE = (22), SD_WP_ERASE_SKIP = (23), SD_CARD_ECC_DISABLED = (24), SD_ERASE_RESET = (25), SD_AKE_SEQ_ERROR = (26), SD_INVALID_VOLTRANGE = (27), SD_ADDR_OUT_OF_RANGE = (28), SD_SWITCH_ERROR = (29), SD_SDIO_DISABLED = (30), SD_SDIO_FUNCTION_BUSY = (31), SD_SDIO_FUNCTION_FAILED = (32), SD_SDIO_UNKNOWN_FUNCTION = (33), SD_INTERNAL_ERROR, SD_NOT_CONFIGURED, SD_REQUEST_PENDING, SD_REQUEST_NOT_APPLICABLE, SD_INVALID_PARAMETER, SD_UNSUPPORTED_FEATURE, SD_UNSUPPORTED_HW, SD_ERROR, SD_OK = 0 } |
enum | SDTransferState { SD_TRANSFER_OK = 0, SD_TRANSFER_BUSY = 1, SD_TRANSFER_ERROR } |
SDIO Transfer state. | |
enum | SDCardState { SD_CARD_READY = ((uint32_t)0x00000001), SD_CARD_IDENTIFICATION = ((uint32_t)0x00000002), SD_CARD_STANDBY = ((uint32_t)0x00000003), SD_CARD_TRANSFER = ((uint32_t)0x00000004), SD_CARD_SENDING = ((uint32_t)0x00000005), SD_CARD_RECEIVING = ((uint32_t)0x00000006), SD_CARD_PROGRAMMING = ((uint32_t)0x00000007), SD_CARD_DISCONNECTED = ((uint32_t)0x00000008), SD_CARD_ERROR = ((uint32_t)0x000000FF) } |
SD Card States. | |
Functions | |
void | SD_DeInit (void) |
DeInitializes the SDIO interface. More... | |
SD_Error | SD_Init (void) |
Initializes the SD Card and put it into StandBy State (Ready for data transfer). More... | |
SDTransferState | SD_GetStatus (void) |
Gets the cuurent sd card data transfer status. More... | |
SDCardState | SD_GetState (void) |
Returns the current card's state. More... | |
uint8_t | SD_Detect (void) |
Detect if SD card is correctly plugged in the memory slot. More... | |
SD_Error | SD_PowerON (void) |
Enquires cards about their operating voltage and configures clock controls. More... | |
SD_Error | SD_PowerOFF (void) |
Turns the SDIO output signals off. More... | |
SD_Error | SD_InitializeCards (void) |
Intialises all cards or single card as the case may be Card(s) come into standby state. More... | |
SD_Error | SD_GetCardInfo (SD_CardInfo *cardinfo) |
Returns information about specific card. More... | |
SD_Error | SD_GetCardStatus (SD_CardStatus *cardstatus) |
Enables wide bus opeartion for the requeseted card if supported by card. More... | |
SD_Error | SD_EnableWideBusOperation (uint32_t WideMode) |
Enables wide bus opeartion for the requeseted card if supported by card. More... | |
SD_Error | SD_SelectDeselect (uint32_t addr) |
Selects od Deselects the corresponding card. More... | |
SD_Error | SD_ReadBlock (uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize) |
Allows to read one block from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode. More... | |
SD_Error | SD_ReadMultiBlocks (uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks) |
Allows to read blocks from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode. More... | |
SD_Error | SD_ReadMultiBlocksFIXED (uint8_t *readbuff, uint32_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks) |
SD_Error | SD_WriteBlock (uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize) |
Allows to write one block starting from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode. More... | |
SD_Error | SD_WriteMultiBlocks (uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks) |
Allows to write blocks starting from a specified address in a card. The Data transfer can be managed by DMA mode only. More... | |
SD_Error | SD_WriteMultiBlocksFIXED (uint8_t *writebuff, uint32_t WriteAddr, uint32_t BlockSize, uint32_t NumberOfBlocks) |
SDTransferState | SD_GetTransferState (void) |
Gets the cuurent data transfer state. More... | |
SD_Error | SD_StopTransfer (void) |
Aborts an ongoing data transfer. More... | |
SD_Error | SD_Erase (uint32_t startaddr, uint32_t endaddr) |
Allows to erase memory area specified for the given card. More... | |
SD_Error | SD_SendStatus (uint32_t *pcardstatus) |
Returns the current card's status. More... | |
SD_Error | SD_SendSDStatus (uint32_t *psdstatus) |
Returns the current SD card's status. More... | |
SD_Error | SD_ProcessIRQSrc (void) |
Allows to process all the interrupts that are high. More... | |
void | SD_ProcessDMAIRQ (void) |
This function waits until the SDIO DMA data transfer is finished. More... | |
SD_Error | SD_WaitReadOperation (void) |
This function waits until the SDIO DMA data transfer is finished. This function should be called after SDIO_ReadMultiBlocks() function to insure that all data sent by the card are already transferred by the DMA controller. More... | |
SD_Error | SD_WaitWriteOperation (void) |
This function waits until the SDIO DMA data transfer is finished. This function should be called after SDIO_WriteBlock() and SDIO_WriteMultiBlocks() function to insure that all data sent by the card are already transferred by the DMA controller. More... | |
static SD_Error | CmdError (void) |
Checks for error conditions for CMD0. More... | |
static SD_Error | CmdResp1Error (uint8_t cmd) |
Checks for error conditions for R1 response. More... | |
static SD_Error | CmdResp7Error (void) |
Checks for error conditions for R7 response. More... | |
static SD_Error | CmdResp3Error (void) |
Checks for error conditions for R3 (OCR) response. More... | |
static SD_Error | CmdResp2Error (void) |
Checks for error conditions for R2 (CID or CSD) response. More... | |
static SD_Error | CmdResp6Error (uint8_t cmd, uint16_t *prca) |
Checks for error conditions for R6 (RCA) response. More... | |
static SD_Error | SDEnWideBus (FunctionalState NewState) |
Enables or disables the SDIO wide bus mode. More... | |
static SD_Error | IsCardProgramming (uint8_t *pstatus) |
Checks if the SD card is in programming state. More... | |
static SD_Error | FindSCR (uint16_t rca, uint32_t *pscr) |
Find the SD card SCR register value. More... | |
uint8_t | convert_from_bytes_to_power_of_two (uint16_t NumberOfBytes) |
Converts the number of bytes in power of two and returns the power. More... | |
Variables | |
SD_CardInfo | SDCardInfo |
static uint32_t | CardType = SDIO_STD_CAPACITY_SD_CARD_V1_1 |
static uint32_t | CSD_Tab [4] |
static uint32_t | CID_Tab [4] |
static uint32_t | RCA = 0 |
static uint8_t | SDSTATUS_Tab [16] |
__IO uint32_t | StopCondition = 0 |
__IO SD_Error | TransferError = SD_OK |
__IO uint32_t | TransferEnd = 0 |
__IO uint32_t | DMAEndOfTransfer = 0 |
SD_CardInfo | SDCardInfo |
SDIO_InitTypeDef | SDIO_InitStructure |
SDIO_CmdInitTypeDef | SDIO_CmdInitStructure |
SDIO_DataInitTypeDef | SDIO_DataInitStructure |
This file provides all the SD Card driver firmware functions.
#define SD_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6) |
Following commands are SD Card Specific commands. SDIO_APP_CMD should be sent before sending these commands.
For SD Card only
Definition at line 278 of file stm32f4_sdio_sd.h.
#define SD_CMD_ERASE_GRP_END ((uint8_t)36) |
To set the address of the last write block of the continuous range to be erased. (For MMC card only spec 3.31)
Definition at line 262 of file stm32f4_sdio_sd.h.
#define SD_CMD_ERASE_GRP_START ((uint8_t)35) |
To set the address of the first write block to be erased. (For MMC card only spec 3.31)
Definition at line 258 of file stm32f4_sdio_sd.h.
#define SD_CMD_FAST_IO ((uint8_t)39) |
SD Card doesn't support it
Definition at line 267 of file stm32f4_sdio_sd.h.
#define SD_CMD_GO_IRQ_STATE ((uint8_t)40) |
SD Card doesn't support it
Definition at line 268 of file stm32f4_sdio_sd.h.
#define SD_CMD_PROG_CID ((uint8_t)26) |
reserved for manufacturers
Definition at line 247 of file stm32f4_sdio_sd.h.
#define SD_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11) |
SD Card doesn't support it
Definition at line 234 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49) |
For SD Card only
Definition at line 300 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48) |
For SD Card only
Definition at line 296 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46) |
For SD Card only
Definition at line 294 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_GET_MID ((uint8_t)44) |
For SD Card only
Definition at line 292 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_GET_MKB ((uint8_t)43) |
Following commands are SD Card Specific security commands. SDIO_APP_CMD should be sent before sending these commands.
For SD Card only
Definition at line 291 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_OP_COND ((uint8_t)41) |
For SD Card only
Definition at line 281 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_SECURE_ERASE ((uint8_t)38) |
For SD Card only
Definition at line 299 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18) |
For SD Card only
Definition at line 297 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48) |
For SD Card only
Definition at line 301 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25) |
For SD Card only
Definition at line 298 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22) |
For SD Card only
Definition at line 280 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_SEND_SCR ((uint8_t)51) |
For SD Card only
Definition at line 283 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47) |
For SD Card only
Definition at line 295 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45) |
For SD Card only
Definition at line 293 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42) |
For SD Card only
Definition at line 282 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_APP_STAUS ((uint8_t)13) |
For SD Card only
Definition at line 279 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_ERASE_GRP_END ((uint8_t)33) |
To set the address of the last write block of the continuous range to be erased. (For SD card only)
Definition at line 255 of file stm32f4_sdio_sd.h.
#define SD_CMD_SD_ERASE_GRP_START ((uint8_t)32) |
To set the address of the first write block to be erased. (For SD card only)
Definition at line 252 of file stm32f4_sdio_sd.h.
#define SD_CMD_SDIO_RW_DIRECT ((uint8_t)52) |
For SD I/O Card only
Definition at line 284 of file stm32f4_sdio_sd.h.
#define SD_CMD_SDIO_RW_EXTENDED ((uint8_t)53) |
For SD I/O Card only
Definition at line 285 of file stm32f4_sdio_sd.h.
#define SD_CMD_SET_BLOCK_COUNT ((uint8_t)23) |
SD Card doesn't support it
Definition at line 244 of file stm32f4_sdio_sd.h.
#define SD_CMD_SET_REL_ADDR ((uint8_t)3) |
SDIO_SEND_REL_ADDR for SD Card
Definition at line 226 of file stm32f4_sdio_sd.h.
#define SD_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20) |
SD Card doesn't support it
Definition at line 243 of file stm32f4_sdio_sd.h.
enum SD_Error |
Definition at line 48 of file stm32f4_sdio_sd.h.
|
static |
Checks for error conditions for CMD0.
SD_Error | SD Card Error code. |
< 10000
Definition at line 2176 of file stm32f4_sdio_sd.c.
|
static |
Checks for error conditions for R1 response.
cmd | The sent command index. |
SD_Error | SD Card Error code. |
< We have received response, retrieve it for analysis
Definition at line 2243 of file stm32f4_sdio_sd.c.
|
static |
Checks for error conditions for R2 (CID or CSD) response.
SD_Error | SD Card Error code. |
Definition at line 2417 of file stm32f4_sdio_sd.c.
|
static |
Checks for error conditions for R3 (OCR) response.
SD_Error | SD Card Error code. |
Definition at line 2389 of file stm32f4_sdio_sd.c.
|
static |
Checks for error conditions for R6 (RCA) response.
cmd | The sent command index. |
prca | pointer to the variable that will contain the SD card relative address RCA. |
SD_Error | SD Card Error code. |
< We have received response, retrieve it.
Definition at line 2456 of file stm32f4_sdio_sd.c.
|
static |
Checks for error conditions for R7 response.
SD_Error | SD Card Error code. |
< Card is not V2.0 complient or card does not support the set voltage range
< Card is SD V2.0 compliant
Definition at line 2205 of file stm32f4_sdio_sd.c.
uint8_t convert_from_bytes_to_power_of_two | ( | uint16_t | NumberOfBytes | ) |
Converts the number of bytes in power of two and returns the power.
NumberOfBytes | number of bytes. |
None |
Definition at line 2911 of file stm32f4_sdio_sd.c.
|
static |
Find the SD card SCR register value.
rca | selected card address. |
pscr | pointer to the buffer that will contain the SCR value. |
SD_Error | SD Card Error code. |
< Set Block Size To 8 Bytes
< Send CMD55 APP_CMD with argument as card's RCA
< Send ACMD51 SD_APP_SEND_SCR with argument as 0
Definition at line 2801 of file stm32f4_sdio_sd.c.
|
static |
Checks if the SD card is in programming state.
pstatus | pointer to the variable that will contain the SD card state. |
SD_Error | SD Card Error code. |
< Check response received is of desired command
< We have received response, retrieve it for analysis
< Find out card status
Definition at line 2641 of file stm32f4_sdio_sd.c.
void SD_DeInit | ( | void | ) |
DeInitializes the SDIO interface.
None |
Definition at line 342 of file stm32f4_sdio_sd.c.
uint8_t SD_Detect | ( | void | ) |
Detect if SD card is correctly plugged in the memory slot.
Return | if SD is detected or not |
< Check GPIO to detect SD
Definition at line 465 of file stm32f4_sdio_sd.c.
SD_Error SD_EnableWideBusOperation | ( | uint32_t | WideMode | ) |
Enables wide bus opeartion for the requeseted card if supported by card.
WideMode | Specifies the SD card wide bus mode. This parameter can be one of the following values:
|
SD_Error | SD Card Error code. |
< MMC Card doesn't support this feature
< Configure the SDIO peripheral
< Configure the SDIO peripheral
Definition at line 1030 of file stm32f4_sdio_sd.c.
SD_Error SD_Erase | ( | uint32_t | startaddr, |
uint32_t | endaddr | ||
) |
Allows to erase memory area specified for the given card.
startaddr | the start address. |
endaddr | the end address. |
SD_Error | SD Card Error code. |
< Check if the card coomnd class supports erase command
< Send CMD32 SD_ERASE_GRP_START with argument as addr
Definition at line 1867 of file stm32f4_sdio_sd.c.
SD_Error SD_GetCardInfo | ( | SD_CardInfo * | cardinfo | ) |
Returns information about specific card.
cardinfo | pointer to a SD_CardInfo structure that contains all SD card information. |
SD_Error | SD Card Error code. |
< Byte 0
< Byte 1
< Byte 2
< Byte 3
< Byte 4
< Byte 5
< Byte 6
< Reserved
< Byte 7
< Byte 8
< Byte 9
< Byte 10
< Byte 7
< Byte 8
< Byte 9
< Byte 10
< Byte 11
< Byte 12
< Byte 13
< Byte 14
< Byte 15
< Byte 0
< Byte 1
< Byte 2
< Byte 3
< Byte 4
< Byte 5
< Byte 6
< Byte 7
< Byte 8
< Byte 9
< Byte 10
< Byte 11
< Byte 12
< Byte 13
< Byte 14
< Byte 15
Definition at line 735 of file stm32f4_sdio_sd.c.
SD_Error SD_GetCardStatus | ( | SD_CardStatus * | cardstatus | ) |
Enables wide bus opeartion for the requeseted card if supported by card.
cardstatus | Specifies the SD card. |
SD_Error | SD Card Error code. |
< Byte 0
< Byte 2
< Byte 3
< Byte 4
< Byte 5
< Byte 6
< Byte 7
< Byte 8
< Byte 9
< Byte 10
< Byte 11
< Byte 12
< Byte 13
< Byte 13
Definition at line 944 of file stm32f4_sdio_sd.c.
SDCardState SD_GetState | ( | void | ) |
Returns the current card's state.
SDCardState | SD Card Error or SD Card Current State. |
Definition at line 439 of file stm32f4_sdio_sd.c.
SDTransferState SD_GetStatus | ( | void | ) |
Gets the cuurent sd card data transfer status.
SDTransferState | Data Transfer state. This value can be:
|
Definition at line 414 of file stm32f4_sdio_sd.c.
SDTransferState SD_GetTransferState | ( | void | ) |
Gets the cuurent data transfer state.
SDTransferState | Data Transfer state. This value can be:
|
Definition at line 1826 of file stm32f4_sdio_sd.c.
SD_Error SD_Init | ( | void | ) |
Initializes the SD Card and put it into StandBy State (Ready for data transfer).
SD_Error | SD Card Error code. |
< CMD Response TimeOut (wait for CMDSENT flag)
< CMD Response TimeOut (wait for CMDSENT flag)
< SDIO_CK = SDIOCLK / (SDIO_TRANSFER_CLK_DIV + 2)
< on STM32F4xx devices, SDIOCLK is fixed to 48MHz
Definition at line 353 of file stm32f4_sdio_sd.c.
SD_Error SD_InitializeCards | ( | void | ) |
Intialises all cards or single card as the case may be Card(s) come into standby state.
SD_Error | SD Card Error code. |
< Send CMD2 ALL_SEND_CID
< Send CMD3 SET_REL_ADDR with argument 0
< SD Card publishes its RCA.
< Send CMD9 SEND_CSD with argument as card's RCA
< All cards get intialized
Definition at line 645 of file stm32f4_sdio_sd.c.
SD_Error SD_PowerOFF | ( | void | ) |
Turns the SDIO output signals off.
SD_Error | SD Card Error code. |
< Set Power State to OFF
Definition at line 629 of file stm32f4_sdio_sd.c.
SD_Error SD_PowerON | ( | void | ) |
Enquires cards about their operating voltage and configures clock controls.
SD_Error | SD Card Error code. |
< Power ON Sequence –—————————————————
< Configure the SDIO peripheral
< SDIO_CK = SDIOCLK / (SDIO_INIT_CLK_DIV + 2)
< on STM32F4xx devices, SDIOCLK is fixed to 48MHz
< SDIO_CK for initialization should not exceed 400 KHz
< Set Power State to ON
< Enable SDIO Clock
< CMD0: GO_IDLE_STATE ------------—————————————
< No CMD response required
< CMD Response TimeOut (wait for CMDSENT flag)
< Send CMD8 to verify SD card interface operating condition
< Argument: - [31:12]: Reserved (shall be set to '0')
< CMD Response: R7
< SD Card 2.0
< CMD55
< If errorstatus is Command TimeOut, it is a MMC card
< If errorstatus is SD_OK it is a SD card: SD card 2.0 (voltage range mismatch) or SD card 1.x
< SD CARD
< Send ACMD41 SD_APP_OP_COND with Argument 0x80100000
< SEND CMD55 APP_CMD with RCA as 0
Definition at line 485 of file stm32f4_sdio_sd.c.
void SD_ProcessDMAIRQ | ( | void | ) |
This function waits until the SDIO DMA data transfer is finished.
None. |
Definition at line 2162 of file stm32f4_sdio_sd.c.
SD_Error SD_ProcessIRQSrc | ( | void | ) |
Allows to process all the interrupts that are high.
SD_Error | SD Card Error code. |
Definition at line 2117 of file stm32f4_sdio_sd.c.
SD_Error SD_ReadBlock | ( | uint8_t * | readbuff, |
uint32_t | ReadAddr, | ||
uint16_t | BlockSize | ||
) |
Allows to read one block from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode.
readbuff | pointer to the buffer that will contain the received data |
ReadAddr | Address from where data are to be read. |
BlockSize | the SD card Data block size. The Block size should be 512. |
SD_Error | SD Card Error code. |
< Send CMD17 READ_SINGLE_BLOCK
Definition at line 1123 of file stm32f4_sdio_sd.c.
SD_Error SD_ReadMultiBlocks | ( | uint8_t * | readbuff, |
uint32_t | ReadAddr, | ||
uint16_t | BlockSize, | ||
uint32_t | NumberOfBlocks | ||
) |
Allows to read blocks from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode.
readbuff | pointer to the buffer that will contain the received data. |
ReadAddr | Address from where data are to be read. |
BlockSize | the SD card Data block size. The Block size should be 512. |
NumberOfBlocks | number of blocks to be read. |
SD_Error | SD Card Error code. |
< Send CMD18 READ_MULT_BLOCK with argument data address
Definition at line 1257 of file stm32f4_sdio_sd.c.
SD_Error SD_ReadMultiBlocksFIXED | ( | uint8_t * | readbuff, |
uint32_t | ReadAddr, | ||
uint32_t | BlockSize, | ||
uint32_t | NumberOfBlocks | ||
) |
< Set Block Size for Card
< Send CMD18 READ_MULT_BLOCK with argument data address
Definition at line 1319 of file stm32f4_sdio_sd.c.
SD_Error SD_SelectDeselect | ( | uint32_t | addr | ) |
Selects od Deselects the corresponding card.
addr | Address of the Card to be selected. |
SD_Error | SD Card Error code. |
< Send CMD7 SDIO_SEL_DESEL_CARD
Definition at line 1090 of file stm32f4_sdio_sd.c.
SD_Error SD_SendSDStatus | ( | uint32_t * | psdstatus | ) |
Returns the current SD card's status.
psdstatus | pointer to the buffer that will contain the SD card status (SD Status register). |
SD_Error | SD Card Error code. |
< Send ACMD13 SD_APP_STAUS with argument as card's RCA.
Definition at line 2000 of file stm32f4_sdio_sd.c.
SD_Error SD_SendStatus | ( | uint32_t * | pcardstatus | ) |
Returns the current card's status.
pcardstatus | pointer to the buffer that will contain the SD card status (Card Status register). |
SD_Error | SD Card Error code. |
Definition at line 1964 of file stm32f4_sdio_sd.c.
SD_Error SD_StopTransfer | ( | void | ) |
Aborts an ongoing data transfer.
SD_Error | SD Card Error code. |
< Send CMD12 STOP_TRANSMISSION
Definition at line 1843 of file stm32f4_sdio_sd.c.
SD_Error SD_WaitReadOperation | ( | void | ) |
This function waits until the SDIO DMA data transfer is finished. This function should be called after SDIO_ReadMultiBlocks() function to insure that all data sent by the card are already transferred by the DMA controller.
SD_Error | SD Card Error code. |
Definition at line 1386 of file stm32f4_sdio_sd.c.
SD_Error SD_WaitWriteOperation | ( | void | ) |
This function waits until the SDIO DMA data transfer is finished. This function should be called after SDIO_WriteBlock() and SDIO_WriteMultiBlocks() function to insure that all data sent by the card are already transferred by the DMA controller.
SD_Error | SD Card Error code. |
Definition at line 1774 of file stm32f4_sdio_sd.c.
SD_Error SD_WriteBlock | ( | uint8_t * | writebuff, |
uint32_t | WriteAddr, | ||
uint16_t | BlockSize | ||
) |
Allows to write one block starting from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode.
writebuff | pointer to the buffer that contain the data to be transferred. |
WriteAddr | Address from where data are to be read. |
BlockSize | the SD card Data block size. The Block size should be 512. |
SD_Error | SD Card Error code. |
< In case of single data block transfer no need of stop command at all
Definition at line 1446 of file stm32f4_sdio_sd.c.
SD_Error SD_WriteMultiBlocks | ( | uint8_t * | writebuff, |
uint32_t | WriteAddr, | ||
uint16_t | BlockSize, | ||
uint32_t | NumberOfBlocks | ||
) |
Allows to write blocks starting from a specified address in a card. The Data transfer can be managed by DMA mode only.
WriteAddr | Address from where data are to be read. |
writebuff | pointer to the buffer that contain the data to be transferred. |
BlockSize | the SD card Data block size. The Block size should be 512. |
NumberOfBlocks | number of blocks to be written. |
SD_Error | SD Card Error code. |
Definition at line 1581 of file stm32f4_sdio_sd.c.
|
static |
Enables or disables the SDIO wide bus mode.
NewState | new state of the SDIO wide bus mode. This parameter can be: ENABLE or DISABLE. |
SD_Error | SD Card Error code. |
< If requested card supports wide bus operation
< Send CMD55 APP_CMD with argument as card's RCA.
< If requested card supports 1 bit mode operation
< Send CMD55 APP_CMD with argument as card's RCA.
Definition at line 2526 of file stm32f4_sdio_sd.c.