39 #define SD_POWERSEQUENCE_CLOCK_COUNT 74
41 #define SD_CARD_PREINIT_CLOCK_PERIOD_US 10
42 #define SD_CARD_WAIT_AFTER_POWER_UP_US 1000
45 #define SD_R1_RESPONSE_PARAM_ERROR (1<<6)
46 #define SD_R1_RESPONSE_ADDR_ERROR (1<<5)
47 #define SD_R1_RESPONSE_ERASE_SEQ_ERROR (1<<4)
48 #define SD_R1_RESPONSE_CMD_CRC_ERROR (1<<3)
49 #define SD_R1_RESPONSE_ILLEGAL_CMD_ERROR (1<<2)
50 #define SD_R1_RESPONSE_ERASE_RESET (1<<1)
51 #define SD_R1_RESPONSE_IN_IDLE_STATE (0x01)
52 #define SD_INVALID_R1_RESPONSE (1<<7)
54 #define R1_VALID(X) (((X) >> 7) == 0)
55 #define R1_PARAM_ERR(X) ((((X) &SD_R1_RESPONSE_PARAM_ERROR) != 0))
56 #define R1_ADDR_ERR(X) ((((X) &SD_R1_RESPONSE_ADDR_ERROR) != 0))
57 #define R1_ERASE_ERR(X) ((((X) &SD_R1_RESPONSE_ERASE_SEQ_ERROR) != 0))
58 #define R1_CMD_CRC_ERR(X) ((((X) &SD_R1_RESPONSE_CMD_CRC_ERROR) != 0))
59 #define R1_ILL_CMD_ERR(X) ((((X) &SD_R1_RESPONSE_ILLEGAL_CMD_ERROR) != 0))
60 #define R1_IDLE_BIT_SET(X) (((X) &SD_R1_RESPONSE_IN_IDLE_STATE) != 0)
61 #define R1_ERROR(X) (R1_PARAM_ERR(X) || R1_ADDR_ERR(X) || R1_ERASE_ERR(X) || \
62 R1_CMD_CRC_ERR(X) || R1_ILL_CMD_ERR(X))
65 #define DATA_RESPONSE_IS_VALID(X) (((X) & 0x11) == 0x01)
66 #define DATA_RESPONSE_ACCEPTED(X) (((X) & 0x0E) == (1<<2))
67 #define DATA_RESPONSE_CRC_ERR(X) (((X) & 0x0E) == 0x0A)
68 #define DATA_RESPONSE_WRITE_ERR(X) (((X) & 0x0E) == 0x0C)
71 #define OCR_VOLTAGE_3_2_TO_3_3 (1L << 20)
72 #define OCR_VOLTAGE_3_3_TO_3_4 (1L << 21)
75 #define OCR_CCS (1L << 30)
78 #define OCR_POWER_UP_STATUS (1L << 31)
82 #define SYSTEM_VOLTAGE (OCR_VOLTAGE_3_2_TO_3_3 | OCR_VOLTAGE_3_2_TO_3_3)
85 #define SD_CMD_PREFIX_MASK (1<<6)
107 #define SD_CMD_8_VHS_2_7_V_TO_3_6_V 0x01
108 #define SD_CMD_8_CHECK_PATTERN 0xB5
109 #define SD_CMD_NO_ARG 0x00000000
110 #define SD_ACMD_41_ARG_HC 0x40000000
111 #define SD_CMD_59_ARG_EN 0x00000001
112 #define SD_CMD_59_ARG_DIS 0x00000000
115 #define SD_DATA_TOKEN_CMD_17_18_24 0xFE
116 #define SD_DATA_TOKEN_CMD_25 0xFC
117 #define SD_DATA_TOKEN_CMD_25_STOP 0xFD
119 #define SD_SIZE_OF_CID_AND_CSD_REG 16
120 #define SD_SIZE_OF_SD_STATUS 64
121 #define SD_BLOCKS_FOR_REG_READ 1
122 #define SD_GET_CSD_STRUCTURE(CSD_RAW_DATA) ((CSD_RAW_DATA)[0] >> 6)
125 #define SD_CSD_VUNSUPPORTED -1
136 #ifndef INIT_CMD_RETRY_US
137 #define INIT_CMD_RETRY_US (250 * US_PER_MS)
139 #ifndef INIT_CMD0_RETRY_US
140 #define INIT_CMD0_RETRY_US (100UL)
142 #ifndef R1_POLLING_RETRY_US
143 #define R1_POLLING_RETRY_US (100 * US_PER_MS)
145 #ifndef SD_DATA_TOKEN_RETRY_US
146 #define SD_DATA_TOKEN_RETRY_US (100 * US_PER_MS)
148 #ifndef SD_WAIT_FOR_NOT_BUSY_US
149 #define SD_WAIT_FOR_NOT_BUSY_US (250 * US_PER_MS)
151 #ifndef SD_BLOCK_READ_CMD_RETRY_US
152 #define SD_BLOCK_READ_CMD_RETRY_US (100UL)
154 #ifndef SD_BLOCK_WRITE_CMD_RETRY_US
155 #define SD_BLOCK_WRITE_CMD_RETRY_US (100UL)
162 #define SD_CSD_V2_C_SIZE_BLOCK_MULT 1024
167 #ifndef SD_CARD_SPI_MODE
168 #define SD_CARD_SPI_MODE SPI_MODE_0
174 #ifndef SD_CARD_SPI_SPEED_PREINIT
175 #define SD_CARD_SPI_SPEED_PREINIT SPI_CLK_400KHZ
181 #ifndef SD_CARD_SPI_SPEED_POSTINIT
182 #define SD_CARD_SPI_SPEED_POSTINIT SPI_CLK_10MHZ
188 #define SD_CARD_DUMMY_BYTE (0xFF)
193 #define SDCARD_SPI_IEC_KIBI (1024L)
198 #define SDCARD_SPI_SI_KILO (1000L)
206 SD_INIT_SPI_POWER_SEQ,
209 SD_INIT_CARD_UNKNOWN,
210 SD_INIT_SEND_ACMD41_HCS,
218 SD_INIT_SET_MAX_SPI_SPEED,
Low-level GPIO peripheral driver interface definitions.
sd_rw_response_t
sdcard_spi r/w-operation return values
Public interface for the sdcard_spi driver.
uint8_t sdcard_spi_send_cmd(sdcard_spi_t *card, uint8_t sd_cmd_idx, uint32_t argument, uint32_t retry_us)
Sends a cmd to the sd card.
uint8_t sdcard_spi_send_acmd(sdcard_spi_t *card, uint8_t sd_cmd_idx, uint32_t argument, uint32_t retry_us)
Sends an acmd to the sd card.
sd_rw_response_t sdcard_spi_read_sds(sdcard_spi_t *card, sd_status_t *sd_status)
Gets the SD status of the card.
uint32_t sdcard_spi_get_sector_count(sdcard_spi_t *card)
Gets the sector count of the card.
uint32_t sdcard_spi_get_au_size(sdcard_spi_t *card)
Gets the allocation unit size of the card.
sd_init_fsm_state_t
SD card driver internal states.
Low-level SPI peripheral driver interface definition.
SD status register (see section 4.10.2 in SD-Spec v5.00)
Device descriptor for sdcard_spi.
Utility library for comparing and computing timestamps.