2 * @brief Common definitions used in SD/MMC cards
\r
4 * Copyright(C) NXP Semiconductors, 2012
\r
5 * All rights reserved.
\r
8 * Software that is described herein is for illustrative purposes only
\r
9 * which provides customers with programming information regarding the
\r
10 * LPC products. This software is supplied "AS IS" without any warranties of
\r
11 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
12 * all warranties, express or implied, including all implied warranties of
\r
13 * merchantability, fitness for a particular purpose and non-infringement of
\r
14 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
15 * or liability for the use of the software, conveys no license or rights under any
\r
16 * patent, copyright, mask work right, or any other intellectual property rights in
\r
17 * or to any products. NXP Semiconductors reserves the right to make changes
\r
18 * in the software without notification. NXP Semiconductors also makes no
\r
19 * representation or warranty that such application will be suitable for the
\r
20 * specified use without further testing or modification.
\r
23 * Permission to use, copy, modify, and distribute this software and its
\r
24 * documentation is hereby granted, under NXP Semiconductors' and its
\r
25 * licensor's relevant copyrights in the software, without fee, provided that it
\r
26 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
27 * copyright, permission, and disclaimer notice must appear in all copies of
\r
31 #ifndef __LPC_SDMMC_H
\r
32 #define __LPC_SDMMC_H
\r
38 /** @defgroup CHIP_SDMMC_Definitions CHIP: Common SD/MMC definitions
\r
39 * @ingroup CHIP_Common
\r
44 * @brief OCR Register definitions
\r
46 /** Support voltage range 2.0-2.1 (this bit is reserved in SDC)*/
\r
47 #define SDC_OCR_20_21 (((uint32_t) 1) << 8)
\r
48 /** Support voltage range 2.1-2.2 (this bit is reserved in SDC)*/
\r
49 #define SDC_OCR_21_22 (((uint32_t) 1) << 9)
\r
50 /** Support voltage range 2.2-2.3 (this bit is reserved in SDC)*/
\r
51 #define SDC_OCR_22_23 (((uint32_t) 1) << 10)
\r
52 /** Support voltage range 2.3-2.4 (this bit is reserved in SDC)*/
\r
53 #define SDC_OCR_23_24 (((uint32_t) 1) << 11)
\r
54 /** Support voltage range 2.4-2.5 (this bit is reserved in SDC)*/
\r
55 #define SDC_OCR_24_25 (((uint32_t) 1) << 12)
\r
56 /** Support voltage range 2.5-2.6 (this bit is reserved in SDC)*/
\r
57 #define SDC_OCR_25_26 (((uint32_t) 1) << 13)
\r
58 /** Support voltage range 2.6-2.7 (this bit is reserved in SDC)*/
\r
59 #define SDC_OCR_26_27 (((uint32_t) 1) << 14)
\r
60 /** Support voltage range 2.7-2.8 */
\r
61 #define SDC_OCR_27_28 (((uint32_t) 1) << 15)
\r
62 /** Support voltage range 2.8-2.9*/
\r
63 #define SDC_OCR_28_29 (((uint32_t) 1) << 16)
\r
64 /** Support voltage range 2.9-3.0 */
\r
65 #define SDC_OCR_29_30 (((uint32_t) 1) << 17)
\r
66 /** Support voltage range 3.0-3.1 */
\r
67 #define SDC_OCR_30_31 (((uint32_t) 1) << 18)
\r
68 /** Support voltage range 3.1-3.2 */
\r
69 #define SDC_OCR_31_32 (((uint32_t) 1) << 19)
\r
70 /** Support voltage range 3.2-3.3 */
\r
71 #define SDC_OCR_32_33 (((uint32_t) 1) << 20)
\r
72 /** Support voltage range 3.3-3.4 */
\r
73 #define SDC_OCR_33_34 (((uint32_t) 1) << 21)
\r
74 /** Support voltage range 3.4-3.5 */
\r
75 #define SDC_OCR_34_35 (((uint32_t) 1) << 22)
\r
76 /** Support voltage range 3.5-3.6 */
\r
77 #define SDC_OCR_35_36 (((uint32_t) 1) << 23)
\r
78 /** Support voltage range 2.7-3.6 */
\r
79 #define SDC_OCR_27_36 ((uint32_t) 0x00FF8000)
\r
80 /** Card Capacity Status (CCS). (this bit is reserved in MMC) */
\r
81 #define SDC_OCR_HC_CCS (((uint32_t) 1) << 30)
\r
82 /** Card power up status bit */
\r
83 #define SDC_OCR_IDLE (((uint32_t) 1) << 31)
\r
84 #define SDC_OCR_BUSY (((uint32_t) 0) << 31)
\r
86 /* SD/MMC commands - this matrix shows the command, response types, and
\r
87 supported card type for that command.
\r
88 Command Number Resp SD MMC
\r
89 ----------------------- ------ ----- --- ---
\r
90 Reset (go idle) CMD0 NA x x
\r
91 Send op condition CMD1 R3 x
\r
92 All send CID CMD2 R2 x x
\r
93 Send relative address CMD3 R1 x
\r
94 Send relative address CMD3 R6 x
\r
95 Program DSR CMD4 NA x
\r
96 Select/deselect card CMD7 R1b x
\r
97 Select/deselect card CMD7 R1 x
\r
98 Send CSD CMD9 R2 x x
\r
99 Send CID CMD10 R2 x x
\r
100 Read data until stop CMD11 R1 x x
\r
101 Stop transmission CMD12 R1/b x x
\r
102 Send status CMD13 R1 x x
\r
103 Go inactive state CMD15 NA x x
\r
104 Set block length CMD16 R1 x x
\r
105 Read single block CMD17 R1 x x
\r
106 Read multiple blocks CMD18 R1 x x
\r
107 Write data until stop CMD20 R1 x
\r
108 Setblock count CMD23 R1 x
\r
109 Write single block CMD24 R1 x x
\r
110 Write multiple blocks CMD25 R1 x x
\r
111 Program CID CMD26 R1 x
\r
112 Program CSD CMD27 R1 x x
\r
113 Set write protection CMD28 R1b x x
\r
114 Clear write protection CMD29 R1b x x
\r
115 Send write protection CMD30 R1 x x
\r
116 Erase block start CMD32 R1 x
\r
117 Erase block end CMD33 R1 x
\r
118 Erase block start CMD35 R1 x
\r
119 Erase block end CMD36 R1 x
\r
120 Erase blocks CMD38 R1b x
\r
122 Go IRQ state CMD40 R5 x
\r
123 Lock/unlock CMD42 R1b x
\r
124 Application command CMD55 R1 x
\r
125 General command CMD56 R1b x
\r
127 *** SD card application commands - these must be preceded with ***
\r
128 *** MMC CMD55 application specific command first ***
\r
129 Set bus width ACMD6 R1 x
\r
130 Send SD status ACMD13 R1 x
\r
131 Send number WR blocks ACMD22 R1 x
\r
132 Set WR block erase cnt ACMD23 R1 x
\r
133 Send op condition ACMD41 R3 x
\r
134 Set clear card detect ACMD42 R1 x
\r
135 Send CSR ACMD51 R1 x */
\r
138 * @brief SD/MMC application specific commands for SD cards only - these
\r
139 * must be preceded by the SDMMC CMD55 to work correctly
\r
142 SD_SET_BUS_WIDTH, /*!< Set the SD bus width */
\r
143 SD_SEND_STATUS, /*!< Send the SD card status */
\r
144 SD_SEND_WR_BLOCKS, /*!< Send the number of written clocks */
\r
145 SD_SET_ERASE_COUNT, /*!< Set the number of blocks to pre-erase */
\r
146 SD_SENDOP_COND, /*!< Send the OCR register (init) */
\r
147 SD_CLEAR_CARD_DET, /*!< Set or clear the 50K detect pullup */
\r
148 SD_SEND_SCR, /*!< Send the SD configuration register */
\r
149 SD_INVALID_APP_CMD /*!< Invalid SD application command */
\r
153 * @brief Possible SDMMC response types
\r
156 SDMMC_RESPONSE_R1, /*!< Typical status */
\r
157 SDMMC_RESPONSE_R1B, /*!< Typical status with busy */
\r
158 SDMMC_RESPONSE_R2, /*!< CID/CSD registers (CMD2 and CMD10) */
\r
159 SDMMC_RESPONSE_R3, /*!< OCR register (CMD1, ACMD41) */
\r
160 SDMMC_RESPONSE_R4, /*!< Fast IO response word */
\r
161 SDMMC_RESPONSE_R5, /*!< Go IRQ state response word */
\r
162 SDMMC_RESPONSE_R6, /*!< Published RCA response */
\r
163 SDMMC_RESPONSE_NONE /*!< No response expected */
\r
164 } SDMMC_RESPONSE_T;
\r
167 * @brief Possible SDMMC card state types
\r
170 SDMMC_IDLE_ST = 0, /*!< Idle state */
\r
171 SDMMC_READY_ST, /*!< Ready state */
\r
172 SDMMC_IDENT_ST, /*!< Identification State */
\r
173 SDMMC_STBY_ST, /*!< standby state */
\r
174 SDMMC_TRAN_ST, /*!< transfer state */
\r
175 SDMMC_DATA_ST, /*!< Sending-data State */
\r
176 SDMMC_RCV_ST, /*!< Receive-data State */
\r
177 SDMMC_PRG_ST, /*!< Programming State */
\r
178 SDMMC_DIS_ST /*!< Disconnect State */
\r
181 /* Function prototype for event setup function */
\r
182 typedef void (*SDMMC_EVSETUP_FUNC_T)(void *);
\r
184 /* Function prototype for wait for event function */
\r
185 typedef uint32_t (*SDMMC_EVWAIT_FUNC_T)(void);
\r
187 /* Function prototype for milliSecond delay function */
\r
188 typedef void (*SDMMC_MSDELAY_FUNC_T)(uint32_t);
\r
191 * @brief SD/MMC Card specific setup data structure
\r
194 uint32_t response[4]; /*!< Most recent response */
\r
195 uint32_t cid[4]; /*!< CID of acquired card */
\r
196 uint32_t csd[4]; /*!< CSD of acquired card */
\r
197 uint32_t ext_csd[512 / 4]; /*!< Ext CSD */
\r
198 uint32_t card_type; /*!< Card Type */
\r
199 uint16_t rca; /*!< Relative address assigned to card */
\r
200 uint32_t speed; /*!< Speed */
\r
201 uint32_t block_len; /*!< Card sector size */
\r
202 uint32_t device_size; /*!< Device Size */
\r
203 uint32_t blocknr; /*!< Block Number */
\r
204 uint32_t clk_rate; /*! Clock rate */
\r
205 SDMMC_EVSETUP_FUNC_T evsetup_cb; /*!< Function to setup event information */
\r
206 SDMMC_EVWAIT_FUNC_T waitfunc_cb; /*!< Function to wait for event */
\r
207 SDMMC_MSDELAY_FUNC_T msdelay_func; /*!< Function to sleep in ms */
\r
211 * @brief SD/MMC commands, arguments and responses
\r
212 * Standard SD/MMC commands (3.1) type argument response
\r
215 #define MMC_GO_IDLE_STATE 0 /* bc */
\r
216 #define MMC_SEND_OP_COND 1 /* bcr [31:0] OCR R3 */
\r
217 #define MMC_ALL_SEND_CID 2 /* bcr R2 */
\r
218 #define MMC_SET_RELATIVE_ADDR 3 /* ac [31:16] RCA R1 */
\r
219 #define MMC_SET_DSR 4 /* bc [31:16] RCA */
\r
220 #define MMC_SELECT_CARD 7 /* ac [31:16] RCA R1 */
\r
221 #define MMC_SEND_EXT_CSD 8 /* bc R1 */
\r
222 #define MMC_SEND_CSD 9 /* ac [31:16] RCA R2 */
\r
223 #define MMC_SEND_CID 10 /* ac [31:16] RCA R2 */
\r
224 #define MMC_STOP_TRANSMISSION 12 /* ac R1b */
\r
225 #define MMC_SEND_STATUS 13 /* ac [31:16] RCA R1 */
\r
226 #define MMC_GO_INACTIVE_STATE 15 /* ac [31:16] RCA */
\r
229 #define MMC_SET_BLOCKLEN 16 /* ac [31:0] block len R1 */
\r
230 #define MMC_READ_SINGLE_BLOCK 17 /* adtc [31:0] data addr R1 */
\r
231 #define MMC_READ_MULTIPLE_BLOCK 18 /* adtc [31:0] data addr R1 */
\r
234 #define MMC_WRITE_DAT_UNTIL_STOP 20 /* adtc [31:0] data addr R1 */
\r
237 #define MMC_SET_BLOCK_COUNT 23 /* adtc [31:0] data addr R1 */
\r
238 #define MMC_WRITE_BLOCK 24 /* adtc [31:0] data addr R1 */
\r
239 #define MMC_WRITE_MULTIPLE_BLOCK 25 /* adtc R1 */
\r
240 #define MMC_PROGRAM_CID 26 /* adtc R1 */
\r
241 #define MMC_PROGRAM_CSD 27 /* adtc R1 */
\r
244 #define MMC_SET_WRITE_PROT 28 /* ac [31:0] data addr R1b */
\r
245 #define MMC_CLR_WRITE_PROT 29 /* ac [31:0] data addr R1b */
\r
246 #define MMC_SEND_WRITE_PROT 30 /* adtc [31:0] wpdata addr R1 */
\r
249 #define MMC_ERASE_GROUP_START 35 /* ac [31:0] data addr R1 */
\r
250 #define MMC_ERASE_GROUP_END 36 /* ac [31:0] data addr R1 */
\r
251 #define MMC_ERASE 37 /* ac R1b */
\r
252 #define SD_ERASE_WR_BLK_START 32 /* ac [31:0] data addr R1 */
\r
253 #define SD_ERASE_WR_BLK_END 33 /* ac [31:0] data addr R1 */
\r
254 #define SD_ERASE 38 /* ac R1b */
\r
257 #define MMC_FAST_IO 39 /* ac <Complex> R4 */
\r
258 #define MMC_GO_IRQ_STATE 40 /* bcr R5 */
\r
261 #define MMC_LOCK_UNLOCK 42 /* adtc R1b */
\r
264 #define MMC_APP_CMD 55 /* ac [31:16] RCA R1 */
\r
265 #define MMC_GEN_CMD 56 /* adtc [0] RD/WR R1b */
\r
267 /* SD commands type argument response */
\r
269 /* This is basically the same command as for MMC with some quirks. */
\r
270 #define SD_SEND_RELATIVE_ADDR 3 /* ac R6 */
\r
271 #define SD_CMD8 8 /* bcr [31:0] OCR R3 */
\r
273 /* Application commands */
\r
274 #define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */
\r
275 #define SD_APP_OP_COND 41 /* bcr [31:0] OCR R1 (R4) */
\r
276 #define SD_APP_SEND_SCR 51 /* adtc R1 */
\r
279 * @brief MMC status in R1<br>
\r
281 * e : error bit<br>
\r
282 * s : status bit<br>
\r
283 * r : detected and set for the actual command response<br>
\r
284 * x : detected and set during command execution. the host must poll
\r
285 * the card by sending status command in order to read these bits.
\r
286 * Clear condition<br>
\r
287 * a : according to the card state<br>
\r
288 * b : always related to the previous command. Reception of
\r
289 * a valid command will clear it (with a delay of one command)<br>
\r
290 * c : clear by read<br>
\r
293 #define R1_OUT_OF_RANGE (1UL << 31) /* er, c */
\r
294 #define R1_ADDRESS_ERROR (1 << 30) /* erx, c */
\r
295 #define R1_BLOCK_LEN_ERROR (1 << 29) /* er, c */
\r
296 #define R1_ERASE_SEQ_ERROR (1 << 28) /* er, c */
\r
297 #define R1_ERASE_PARAM (1 << 27) /* ex, c */
\r
298 #define R1_WP_VIOLATION (1 << 26) /* erx, c */
\r
299 #define R1_CARD_IS_LOCKED (1 << 25) /* sx, a */
\r
300 #define R1_LOCK_UNLOCK_FAILED (1 << 24) /* erx, c */
\r
301 #define R1_COM_CRC_ERROR (1 << 23) /* er, b */
\r
302 #define R1_ILLEGAL_COMMAND (1 << 22) /* er, b */
\r
303 #define R1_CARD_ECC_FAILED (1 << 21) /* ex, c */
\r
304 #define R1_CC_ERROR (1 << 20) /* erx, c */
\r
305 #define R1_ERROR (1 << 19) /* erx, c */
\r
306 #define R1_UNDERRUN (1 << 18) /* ex, c */
\r
307 #define R1_OVERRUN (1 << 17) /* ex, c */
\r
308 #define R1_CID_CSD_OVERWRITE (1 << 16) /* erx, c, CID/CSD overwrite */
\r
309 #define R1_WP_ERASE_SKIP (1 << 15) /* sx, c */
\r
310 #define R1_CARD_ECC_DISABLED (1 << 14) /* sx, a */
\r
311 #define R1_ERASE_RESET (1 << 13) /* sr, c */
\r
312 #define R1_STATUS(x) (x & 0xFFFFE000)
\r
313 #define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9) /* sx, b (4 bits) */
\r
314 #define R1_READY_FOR_DATA (1 << 8) /* sx, a */
\r
315 #define R1_APP_CMD (1 << 5) /* sr, c */
\r
318 * @brief SD/MMC card OCR register bits
\r
320 #define OCR_ALL_READY (1UL << 31) /* Card Power up status bit */
\r
321 #define OCR_HC_CCS (1 << 30) /* High capacity card */
\r
322 #define OCR_VOLTAGE_RANGE_MSK (0x00FF8000)
\r
324 #define SD_SEND_IF_ARG 0x000001AA
\r
325 #define SD_SEND_IF_ECHO_MSK 0x000000FF
\r
326 #define SD_SEND_IF_RESP 0x000000AA
\r
329 * @brief R3 response definitions
\r
331 #define CMDRESP_R3_OCR_VAL(n) (((uint32_t) n) & 0xFFFFFF)
\r
332 #define CMDRESP_R3_S18A (((uint32_t) 1 ) << 24)
\r
333 #define CMDRESP_R3_HC_CCS (((uint32_t) 1 ) << 30)
\r
334 #define CMDRESP_R3_INIT_COMPLETE (((uint32_t) 1 ) << 31)
\r
337 * @brief R6 response definitions
\r
339 #define CMDRESP_R6_RCA_VAL(n) (((uint32_t) (n >> 16)) & 0xFFFF)
\r
340 #define CMDRESP_R6_CARD_STATUS(n) (((uint32_t) (n & 0x1FFF)) | \
\r
341 ((n & (1 << 13)) ? (1 << 19) : 0) | \
\r
342 ((n & (1 << 14)) ? (1 << 22) : 0) | \
\r
343 ((n & (1 << 15)) ? (1 << 23) : 0))
\r
346 * @brief R7 response definitions
\r
348 /** Echo-back of check-pattern */
\r
349 #define CMDRESP_R7_CHECK_PATTERN(n) (((uint32_t) n ) & 0xFF)
\r
350 /** Voltage accepted */
\r
351 #define CMDRESP_R7_VOLTAGE_ACCEPTED (((uint32_t) 1 ) << 8)
\r
354 * @brief CMD3 command definitions
\r
356 /** Card Address */
\r
357 #define CMD3_RCA(n) (((uint32_t) (n & 0xFFFF) ) << 16)
\r
360 * @brief CMD7 command definitions
\r
362 /** Card Address */
\r
363 #define CMD7_RCA(n) (((uint32_t) (n & 0xFFFF) ) << 16)
\r
366 * @brief CMD8 command definitions
\r
368 /** Check pattern */
\r
369 #define CMD8_CHECKPATTERN(n) (((uint32_t) (n & 0xFF) ) << 0)
\r
370 /** Recommended pattern */
\r
371 #define CMD8_DEF_PATTERN (0xAA)
\r
372 /** Voltage supplied.*/
\r
373 #define CMD8_VOLTAGESUPPLIED_27_36 (((uint32_t) 1 ) << 8)
\r
376 * @brief CMD9 command definitions
\r
378 #define CMD9_RCA(n) (((uint32_t) (n & 0xFFFF) ) << 16)
\r
381 * @brief CMD13 command definitions
\r
383 #define CMD13_RCA(n) (((uint32_t) (n & 0xFFFF) ) << 16)
\r
386 * @brief APP_CMD command definitions
\r
388 #define CMD55_RCA(n) (((uint32_t) (n & 0xFFFF) ) << 16)
\r
391 * @brief ACMD41 command definitions
\r
393 #define ACMD41_OCR(n) (((uint32_t) n) & 0xFFFFFF)
\r
394 #define ACMD41_S18R (((uint32_t) 1 ) << 24)
\r
395 #define ACMD41_XPC (((uint32_t) 1 ) << 28)
\r
396 #define ACMD41_HCS (((uint32_t) 1 ) << 30)
\r
399 * @brief ACMD6 command definitions
\r
401 #define ACMD6_BUS_WIDTH(n) ((uint32_t) n & 0x03)
\r
402 #define ACMD6_BUS_WIDTH_1 (0)
\r
403 #define ACMD6_BUS_WIDTH_4 (2)
\r
405 /** @brief Card type defines
\r
407 #define CARD_TYPE_SD (1 << 0)
\r
408 #define CARD_TYPE_4BIT (1 << 1)
\r
409 #define CARD_TYPE_8BIT (1 << 2)
\r
410 #define CARD_TYPE_HC (OCR_HC_CCS)/*!< high capacity card > 2GB */
\r
413 * @brief SD/MMC sector size in bytes
\r
415 #define MMC_SECTOR_SIZE 512
\r
425 #endif /* __LPC_SDMMC_H */
\r