|
PER Firmware
|
#include <stddef.h>#include "common/phal_F4/dma/dma.h"#include "common/phal_F4/gpio/gpio.h"#include "common/phal_F4/rcc/rcc.h"#include "stm32f4xx.h"Go to the source code of this file.
Classes | |
| struct | PHAL_SD_Cmd_t |
| struct | SD_CSD |
| Card Specific Data: CSD Register. More... | |
| struct | SD_CID |
| Card Identification Data: CID Register. More... | |
| struct | SD_CardInfo |
| SD Card information. More... | |
Macros | |
| #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 | SDIO_CMD0TIMEOUT ((uint32_t)0x00010000) |
| #define | SDIO_STATIC_FLAGS ((uint32_t)0x000005FF) |
| #define | SD_CHECK_PATTERN ((uint32_t)0x000001AA) |
| #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. | |
| #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. | |
| #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_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 | SD_PRESENT ((uint8_t)0x01) |
| SD detection on its memory slot. | |
| #define | SD_NOT_PRESENT ((uint8_t)0x00) |
| #define | SDIO_BusWide_1b (1) |
| #define | SDIO_BusWide_4b (4) |
| #define | SDIO_BusWide_8b (8) |
| #define | FATFS_SDIO_4BIT 1 |
| #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. | |
| #define | SDIO_DATABLOCKSIZE ((uint32_t)((9 << 4))) |
| #define | SDIO_INIT_CLK_DIV ((uint8_t)118) |
| SDIO Intialization Frequency (400KHz max) | |
| #define | SDIO_TRANSFER_CLK_DIV ((uint8_t)0) |
| SDIO Data Transfer Frequency (25MHz max) | |
| #define | SD_DMA_MODE ((uint32_t)0x00000000) |
Functions | |
| bool | PHAL_SDIO_init (void) |
| Initialize SDIO peripheral with the configuired structure. | |
| void | SD_LowLevel_DMA_TxConfig (const uint32_t *BufferSRC, uint32_t BufferSize) |
| Configures the DMA 2 Channel 6 for SDIO Tx request. | |
| void | SD_LowLevel_DMA_RxConfig (uint32_t *BufferDST, uint32_t BufferSize) |
| Configures the DMA2 Channel4 for SDIO Rx request. | |
| void | SD_DeInit (void) |
| void | PHAL_SDIO_SendCommand (const PHAL_SD_Cmd_t *cmd) |
| Send a command. | |
| SD_Error | SD_Init (void) |
| Initializes the SD Card and put it into StandBy State (Ready for data transfer). | |
| SDTransferState | SD_GetStatus (void) |
| Gets the cuurent sd card data transfer status. | |
| SDCardState | SD_GetState (void) |
| Returns the current card's state. | |
| uint8_t | SD_Detect (void) |
| Detect if SD card is correctly plugged in the memory slot. | |
| SD_Error | SD_PowerON (void) |
| Enquires cards about their operating voltage and configures clock controls. | |
| 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_GetCardInfo (SD_CardInfo *cardinfo) |
| Returns information about specific card. | |
| SD_Error | SD_EnableWideBusOperation (uint32_t WideMode) |
| Enables wide bus opeartion for the requeseted card if supported by card. | |
| SD_Error | SD_SelectDeselect (uint64_t addr) |
| Selects od Deselects the corresponding card. | |
| SD_Error | SD_ReadMultiBlocks (uint8_t *readbuff, uint64_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. | |
| SD_Error | SD_WriteMultiBlocks (uint8_t *writebuff, uint64_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. | |
| SD_Error | SD_StopTransfer (void) |
| Aborts an ongoing data transfer. | |
| SD_Error | SD_SendStatus (uint32_t *pcardstatus) |
| Returns the current card's status. | |
| 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_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. | |
| #define FATFS_SDIO_4BIT 1 |
| #define SD_0TO7BITS ((uint32_t)0x000000FF) |
| #define SD_16TO23BITS ((uint32_t)0x00FF0000) |
| #define SD_24TO31BITS ((uint32_t)0xFF000000) |
| #define SD_8TO15BITS ((uint32_t)0x0000FF00) |
| #define SD_ALLZERO ((uint32_t)0x00000000) |
| #define SD_CARD_LOCKED ((uint32_t)0x02000000) |
| #define SD_CCCC_ERASE ((uint32_t)0x00000020) |
| #define SD_CCCC_LOCK_UNLOCK ((uint32_t)0x00000080) |
Command Class Supported.
| #define SD_CCCC_WRITE_PROT ((uint32_t)0x00000040) |
| #define SD_CHECK_PATTERN ((uint32_t)0x000001AA) |
| #define SD_CHECK_PATTERN ((uint32_t)0x000001AA) |
| #define SD_CMD_ALL_SEND_CID ((uint8_t)2) |
| #define SD_CMD_APP_CMD ((uint8_t)55) |
| #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
| #define SD_CMD_CLR_WRITE_PROT ((uint8_t)29) |
| #define SD_CMD_ERASE ((uint8_t)38) |
| #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)
| #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)
| #define SD_CMD_FAST_IO ((uint8_t)39) |
SD Card doesn't support it
| #define SD_CMD_GEN_CMD ((uint8_t)56) |
| #define SD_CMD_GO_IDLE_STATE ((uint8_t)0) |
SDIO Commands Index.
| #define SD_CMD_GO_INACTIVE_STATE ((uint8_t)15) |
| #define SD_CMD_GO_IRQ_STATE ((uint8_t)40) |
SD Card doesn't support it
| #define SD_CMD_HS_BUSTEST_READ ((uint8_t)14) |
| #define SD_CMD_HS_BUSTEST_WRITE ((uint8_t)19) |
| #define SD_CMD_HS_SEND_EXT_CSD ((uint8_t)8) |
| #define SD_CMD_HS_SWITCH ((uint8_t)6) |
| #define SD_CMD_LOCK_UNLOCK ((uint8_t)42) |
| #define SD_CMD_NO_CMD ((uint8_t)64) |
| #define SD_CMD_PROG_CID ((uint8_t)26) |
reserved for manufacturers
| #define SD_CMD_PROG_CSD ((uint8_t)27) |
| #define SD_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11) |
SD Card doesn't support it
| #define SD_CMD_READ_MULT_BLOCK ((uint8_t)18) |
| #define SD_CMD_READ_SINGLE_BLOCK ((uint8_t)17) |
| #define SD_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49) |
For SD Card only
| #define SD_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48) |
For SD Card only
| #define SD_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46) |
For SD Card only
| #define SD_CMD_SD_APP_GET_MID ((uint8_t)44) |
For SD Card only
| #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
| #define SD_CMD_SD_APP_OP_COND ((uint8_t)41) |
For SD Card only
| #define SD_CMD_SD_APP_SECURE_ERASE ((uint8_t)38) |
For SD Card only
| #define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18) |
For SD Card only
| #define SD_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48) |
For SD Card only
| #define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25) |
For SD Card only
| #define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22) |
For SD Card only
| #define SD_CMD_SD_APP_SEND_SCR ((uint8_t)51) |
For SD Card only
| #define SD_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47) |
For SD Card only
| #define SD_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45) |
For SD Card only
| #define SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42) |
For SD Card only
| #define SD_CMD_SD_APP_STAUS ((uint8_t)13) |
For SD Card only
| #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)
| #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)
| #define SD_CMD_SDIO_RW_DIRECT ((uint8_t)52) |
For SD I/O Card only
| #define SD_CMD_SDIO_RW_EXTENDED ((uint8_t)53) |
For SD I/O Card only
| #define SD_CMD_SDIO_SEN_OP_COND ((uint8_t)5) |
| #define SD_CMD_SEL_DESEL_CARD ((uint8_t)7) |
| #define SD_CMD_SEND_CID ((uint8_t)10) |
| #define SD_CMD_SEND_CSD ((uint8_t)9) |
| #define SD_CMD_SEND_OP_COND ((uint8_t)1) |
| #define SD_CMD_SEND_STATUS ((uint8_t)13) |
| #define SD_CMD_SEND_WRITE_PROT ((uint8_t)30) |
| #define SD_CMD_SET_BLOCK_COUNT ((uint8_t)23) |
SD Card doesn't support it
| #define SD_CMD_SET_BLOCKLEN ((uint8_t)16) |
| #define SD_CMD_SET_DSR ((uint8_t)4) |
| #define SD_CMD_SET_REL_ADDR ((uint8_t)3) |
SDIO_SEND_REL_ADDR for SD Card
| #define SD_CMD_SET_WRITE_PROT ((uint8_t)28) |
| #define SD_CMD_STOP_TRANSMISSION ((uint8_t)12) |
| #define SD_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20) |
SD Card doesn't support it
| #define SD_CMD_WRITE_MULT_BLOCK ((uint8_t)25) |
| #define SD_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24) |
| #define SD_DATATIMEOUT ((uint32_t)0xFFFFFFFF) |
| #define SD_DMA_MODE ((uint32_t)0x00000000) |
| #define SD_HALFFIFO ((uint32_t)0x00000008) |
| #define SD_HALFFIFOBYTES ((uint32_t)0x00000020) |
| #define SD_HIGH_CAPACITY ((uint32_t)0x40000000) |
| #define SD_MAX_DATA_LENGTH ((uint32_t)0x01FFFFFF) |
| #define SD_MAX_VOLT_TRIAL ((uint32_t)0x0000FFFF) |
| #define SD_NOT_PRESENT ((uint8_t)0x00) |
| #define SD_OCR_ADDR_MISALIGNED ((uint32_t)0x40000000) |
| #define SD_OCR_ADDR_OUT_OF_RANGE ((uint32_t)0x80000000) |
Mask for errors Card Status R1 (OCR Register)
| #define SD_OCR_AKE_SEQ_ERROR ((uint32_t)0x00000008) |
| #define SD_OCR_BAD_ERASE_PARAM ((uint32_t)0x08000000) |
| #define SD_OCR_BLOCK_LEN_ERR ((uint32_t)0x20000000) |
| #define SD_OCR_CARD_ECC_DISABLED ((uint32_t)0x00004000) |
| #define SD_OCR_CARD_ECC_FAILED ((uint32_t)0x00200000) |
| #define SD_OCR_CC_ERROR ((uint32_t)0x00100000) |
| #define SD_OCR_CID_CSD_OVERWRIETE ((uint32_t)0x00010000) |
| #define SD_OCR_COM_CRC_FAILED ((uint32_t)0x00800000) |
| #define SD_OCR_ERASE_RESET ((uint32_t)0x00002000) |
| #define SD_OCR_ERASE_SEQ_ERR ((uint32_t)0x10000000) |
| #define SD_OCR_ERRORBITS ((uint32_t)0xFDFFE008) |
| #define SD_OCR_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00080000) |
| #define SD_OCR_ILLEGAL_CMD ((uint32_t)0x00400000) |
| #define SD_OCR_LOCK_UNLOCK_FAILED ((uint32_t)0x01000000) |
| #define SD_OCR_STREAM_READ_UNDERRUN ((uint32_t)0x00040000) |
| #define SD_OCR_STREAM_WRITE_OVERRUN ((uint32_t)0x00020000) |
| #define SD_OCR_WP_ERASE_SKIP ((uint32_t)0x00008000) |
| #define SD_OCR_WRITE_PROT_VIOLATION ((uint32_t)0x04000000) |
| #define SD_PRESENT ((uint8_t)0x01) |
SD detection on its memory slot.
| #define SD_R6_COM_CRC_FAILED ((uint32_t)0x00008000) |
| #define SD_R6_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00002000) |
Masks for R6 Response.
| #define SD_R6_ILLEGAL_CMD ((uint32_t)0x00004000) |
| #define SD_SINGLE_BUS_SUPPORT ((uint32_t)0x00010000) |
| #define SD_STD_CAPACITY ((uint32_t)0x00000000) |
| #define SD_VOLTAGE_WINDOW_SD ((uint32_t)0x80100000) |
| #define SD_WIDE_BUS_SUPPORT ((uint32_t)0x00040000) |
| #define SDIO_BusWide_1b (1) |
| #define SDIO_BusWide_4b (4) |
| #define SDIO_BusWide_8b (8) |
| #define SDIO_CMD0TIMEOUT ((uint32_t)0x00010000) |
| #define SDIO_DATABLOCKSIZE ((uint32_t)((9 << 4))) |
| #define SDIO_HIGH_CAPACITY_MMC_CARD ((uint32_t)0x00000007) |
| #define SDIO_HIGH_CAPACITY_SD_CARD ((uint32_t)0x00000002) |
| #define SDIO_HIGH_SPEED_MULTIMEDIA_CARD ((uint32_t)0x00000005) |
| #define SDIO_INIT_CLK_DIV ((uint8_t)118) |
SDIO Intialization Frequency (400KHz max)
| #define SDIO_MULTIMEDIA_CARD ((uint32_t)0x00000003) |
| #define SDIO_SECURE_DIGITAL_IO_CARD ((uint32_t)0x00000004) |
| #define SDIO_SECURE_DIGITAL_IO_COMBO_CARD ((uint32_t)0x00000006) |
| #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.
| #define SDIO_STATIC_FLAGS ((uint32_t)0x000005FF) |
| #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_TRANSFER_CLK_DIV ((uint8_t)0) |
SDIO Data Transfer Frequency (25MHz max)
| enum PHAL_SD_CmdResp_t |
| enum SD_Error |
| enum SDCardState |
| enum SDTransferState |
| bool PHAL_SDIO_init | ( | void | ) |
Initialize SDIO peripheral with the configuired structure.
| config | SDIO initial configuration |
Initialize SDIO peripheral with the configuired structure.
| cfg |
| void PHAL_SDIO_SendCommand | ( | const PHAL_SD_Cmd_t * | cmd | ) |
Send a command.
| cmd |
| void SD_DeInit | ( | void | ) |
< Disable SDIO Clock
< Set Power State to OFF
< DeInitializes the SDIO peripheral
| uint8_t SD_Detect | ( | void | ) |
Detect if SD card is correctly plugged in the memory slot.
| None |
| Return | if SD is detected or not |
| 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
| 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
| SDCardState SD_GetState | ( | void | ) |
Returns the current card's state.
| None |
| SDCardState | SD Card Error or SD Card Current State. |
| SDTransferState SD_GetStatus | ( | void | ) |
Gets the cuurent sd card data transfer status.
| None |
| SDTransferState | Data Transfer state. This value can be:
|
| SD_Error SD_Init | ( | void | ) |
Initializes the SD Card and put it into StandBy State (Ready for data transfer).
| None |
| SD_Error | SD Card Error code. |
< CMD Response TimeOut (wait for CMDSENT flag)
| SD_Error SD_InitializeCards | ( | void | ) |
Intialises all cards or single card as the case may be Card(s) come into standby state.
| None |
| 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
| void SD_LowLevel_DMA_RxConfig | ( | uint32_t * | BufferDST, |
| uint32_t | BufferSize ) |
Configures the DMA2 Channel4 for SDIO Rx request.
| BufferDST | pointer to the destination buffer |
| BufferSize | buffer size |
| None |
| void SD_LowLevel_DMA_TxConfig | ( | const uint32_t * | BufferSRC, |
| uint32_t | BufferSize ) |
Configures the DMA 2 Channel 6 for SDIO Tx request.
| BufferSRC | pointer to the source buffer |
| BufferSize | buffer size |
| None |
| SD_Error SD_PowerON | ( | void | ) |
Enquires cards about their operating voltage and configures clock controls.
| None |
| SD_Error | SD Card Error code. |
< CMD0: GO_IDLE_STATE ------------------------------------------------—
< No CMD response required
< CMD Response TimeOut (wait for CMDSENT flag)
< CMD8: SEND_IF_COND -------------------------------------------------—
< 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
| SD_Error SD_ReadMultiBlocks | ( | uint8_t * | readbuff, |
| uint64_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
< Send CMD17 READ_SINGLE_BLOCK with argument data address
| SD_Error SD_SelectDeselect | ( | uint64_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
| 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. |
| SD_Error SD_StopTransfer | ( | void | ) |
Aborts an ongoing data transfer.
| None |
| SD_Error | SD Card Error code. |
< Send CMD12 STOP_TRANSMISSION
| 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.
| None. |
| SD_Error | SD Card Error code. |
| 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.
| None. |
| SD_Error | SD Card Error code. |
| SD_Error SD_WriteMultiBlocks | ( | uint8_t * | writebuff, |
| uint64_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. |