LPCOpen Platform for LPC112X microcontrollers
112X
LPCOpen Platform for the NXP LPC112X family of Microcontrollers
Main Page
Modules
Data Structures
Files
File List
Globals
software
lpc_core
lpc_chip
chip_common
sdmmc.h
Go to the documentation of this file.
1
/*
2
* @brief Common definitions used in SD/MMC cards
3
* @note
4
* Copyright(C) NXP Semiconductors, 2012
5
* All rights reserved.
6
*
7
* @par
8
* Software that is described herein is for illustrative purposes only
9
* which provides customers with programming information regarding the
10
* LPC products. This software is supplied "AS IS" without any warranties of
11
* any kind, and NXP Semiconductors and its licensor disclaim any and
12
* all warranties, express or implied, including all implied warranties of
13
* merchantability, fitness for a particular purpose and non-infringement of
14
* intellectual property rights. NXP Semiconductors assumes no responsibility
15
* or liability for the use of the software, conveys no license or rights under any
16
* patent, copyright, mask work right, or any other intellectual property rights in
17
* or to any products. NXP Semiconductors reserves the right to make changes
18
* in the software without notification. NXP Semiconductors also makes no
19
* representation or warranty that such application will be suitable for the
20
* specified use without further testing or modification.
21
*
22
* @par
23
* Permission to use, copy, modify, and distribute this software and its
24
* documentation is hereby granted, under NXP Semiconductors' and its
25
* licensor's relevant copyrights in the software, without fee, provided that it
26
* is used in conjunction with NXP Semiconductors microcontrollers. This
27
* copyright, permission, and disclaimer notice must appear in all copies of
28
* this code.
29
*/
30
31
#ifndef __SDMMC_H
32
#define __SDMMC_H
33
34
#ifdef __cplusplus
35
extern
"C"
{
36
#endif
37
47
#define SDC_OCR_20_21 (((uint32_t) 1) << 8)
48
49
#define SDC_OCR_21_22 (((uint32_t) 1) << 9)
50
51
#define SDC_OCR_22_23 (((uint32_t) 1) << 10)
52
53
#define SDC_OCR_23_24 (((uint32_t) 1) << 11)
54
55
#define SDC_OCR_24_25 (((uint32_t) 1) << 12)
56
57
#define SDC_OCR_25_26 (((uint32_t) 1) << 13)
58
59
#define SDC_OCR_26_27 (((uint32_t) 1) << 14)
60
61
#define SDC_OCR_27_28 (((uint32_t) 1) << 15)
62
63
#define SDC_OCR_28_29 (((uint32_t) 1) << 16)
64
65
#define SDC_OCR_29_30 (((uint32_t) 1) << 17)
66
67
#define SDC_OCR_30_31 (((uint32_t) 1) << 18)
68
69
#define SDC_OCR_31_32 (((uint32_t) 1) << 19)
70
71
#define SDC_OCR_32_33 (((uint32_t) 1) << 20)
72
73
#define SDC_OCR_33_34 (((uint32_t) 1) << 21)
74
75
#define SDC_OCR_34_35 (((uint32_t) 1) << 22)
76
77
#define SDC_OCR_35_36 (((uint32_t) 1) << 23)
78
79
#define SDC_OCR_27_36 ((uint32_t) 0x00FF8000)
80
81
#define SDC_OCR_HC_CCS (((uint32_t) 1) << 30)
82
83
#define SDC_OCR_IDLE (((uint32_t) 1) << 31)
84
#define SDC_OCR_BUSY (((uint32_t) 0) << 31)
85
86
/* SD/MMC commands - this matrix shows the command, response types, and
87
supported card type for that command.
88
Command Number Resp SD MMC
89
----------------------- ------ ----- --- ---
90
Reset (go idle) CMD0 NA x x
91
Send op condition CMD1 R3 x
92
All send CID CMD2 R2 x x
93
Send relative address CMD3 R1 x
94
Send relative address CMD3 R6 x
95
Program DSR CMD4 NA x
96
Select/deselect card CMD7 R1b x
97
Select/deselect card CMD7 R1 x
98
Send CSD CMD9 R2 x x
99
Send CID CMD10 R2 x x
100
Read data until stop CMD11 R1 x x
101
Stop transmission CMD12 R1/b x x
102
Send status CMD13 R1 x x
103
Go inactive state CMD15 NA x x
104
Set block length CMD16 R1 x x
105
Read single block CMD17 R1 x x
106
Read multiple blocks CMD18 R1 x x
107
Write data until stop CMD20 R1 x
108
Setblock count CMD23 R1 x
109
Write single block CMD24 R1 x x
110
Write multiple blocks CMD25 R1 x x
111
Program CID CMD26 R1 x
112
Program CSD CMD27 R1 x x
113
Set write protection CMD28 R1b x x
114
Clear write protection CMD29 R1b x x
115
Send write protection CMD30 R1 x x
116
Erase block start CMD32 R1 x
117
Erase block end CMD33 R1 x
118
Erase block start CMD35 R1 x
119
Erase block end CMD36 R1 x
120
Erase blocks CMD38 R1b x
121
Fast IO CMD39 R4 x
122
Go IRQ state CMD40 R5 x
123
Lock/unlock CMD42 R1b x
124
Application command CMD55 R1 x
125
General command CMD56 R1b x
126
127
*** SD card application commands - these must be preceded with ***
128
*** MMC CMD55 application specific command first ***
129
Set bus width ACMD6 R1 x
130
Send SD status ACMD13 R1 x
131
Send number WR blocks ACMD22 R1 x
132
Set WR block erase cnt ACMD23 R1 x
133
Send op condition ACMD41 R3 x
134
Set clear card detect ACMD42 R1 x
135
Send CSR ACMD51 R1 x */
136
141
typedef
enum
{
142
SD_SET_BUS_WIDTH
,
143
SD_SEND_STATUS
,
144
SD_SEND_WR_BLOCKS
,
145
SD_SET_ERASE_COUNT
,
146
SD_SENDOP_COND
,
147
SD_CLEAR_CARD_DET
,
148
SD_SEND_SCR
,
149
SD_INVALID_APP_CMD
150
}
SD_APP_CMD_T
;
151
155
typedef
enum
{
156
SDMMC_RESPONSE_R1
,
157
SDMMC_RESPONSE_R1B
,
158
SDMMC_RESPONSE_R2
,
159
SDMMC_RESPONSE_R3
,
160
SDMMC_RESPONSE_R4
,
161
SDMMC_RESPONSE_R5
,
162
SDMMC_RESPONSE_R6
,
163
SDMMC_RESPONSE_NONE
164
}
SDMMC_RESPONSE_T
;
165
169
typedef
enum
{
170
SDMMC_IDLE_ST
= 0,
171
SDMMC_READY_ST
,
172
SDMMC_IDENT_ST
,
173
SDMMC_STBY_ST
,
174
SDMMC_TRAN_ST
,
175
SDMMC_DATA_ST
,
176
SDMMC_RCV_ST
,
177
SDMMC_PRG_ST
,
178
SDMMC_DIS_ST
179
}
SDMMC_STATE_T
;
180
181
/* Function prototype for event setup function */
182
typedef
void (*
SDMMC_EVSETUP_FUNC_T
)(
void
*);
183
184
/* Function prototype for wait for event function */
185
typedef
uint32_t (*
SDMMC_EVWAIT_FUNC_T
)(void);
186
187
/* Function prototype for milliSecond delay function */
188
typedef
void (*
SDMMC_MSDELAY_FUNC_T
)(uint32_t);
189
193
typedef
struct
{
194
uint32_t response[4];
195
uint32_t cid[4];
196
uint32_t csd[4];
197
uint32_t ext_csd[512 / 4];
198
uint32_t
card_type
;
199
uint16_t
rca
;
200
uint32_t
speed
;
201
uint32_t
block_len
;
202
uint64_t
device_size
;
203
uint32_t
blocknr
;
204
uint32_t
clk_rate
;
205
SDMMC_EVSETUP_FUNC_T
evsetup_cb
;
206
SDMMC_EVWAIT_FUNC_T
waitfunc_cb
;
207
SDMMC_MSDELAY_FUNC_T
msdelay_func
;
208
}
SDMMC_CARD_T
;
209
214
/* class 1 */
215
#define MMC_GO_IDLE_STATE 0
/* bc */
216
#define MMC_SEND_OP_COND 1
/* bcr [31:0] OCR R3 */
217
#define MMC_ALL_SEND_CID 2
/* bcr R2 */
218
#define MMC_SET_RELATIVE_ADDR 3
/* ac [31:16] RCA R1 */
219
#define MMC_SET_DSR 4
/* bc [31:16] RCA */
220
#define MMC_SELECT_CARD 7
/* ac [31:16] RCA R1 */
221
#define MMC_SEND_EXT_CSD 8
/* bc R1 */
222
#define MMC_SEND_CSD 9
/* ac [31:16] RCA R2 */
223
#define MMC_SEND_CID 10
/* ac [31:16] RCA R2 */
224
#define MMC_STOP_TRANSMISSION 12
/* ac R1b */
225
#define MMC_SEND_STATUS 13
/* ac [31:16] RCA R1 */
226
#define MMC_GO_INACTIVE_STATE 15
/* ac [31:16] RCA */
227
228
/* class 2 */
229
#define MMC_SET_BLOCKLEN 16
/* ac [31:0] block len R1 */
230
#define MMC_READ_SINGLE_BLOCK 17
/* adtc [31:0] data addr R1 */
231
#define MMC_READ_MULTIPLE_BLOCK 18
/* adtc [31:0] data addr R1 */
232
233
/* class 3 */
234
#define MMC_WRITE_DAT_UNTIL_STOP 20
/* adtc [31:0] data addr R1 */
235
236
/* class 4 */
237
#define MMC_SET_BLOCK_COUNT 23
/* adtc [31:0] data addr R1 */
238
#define MMC_WRITE_BLOCK 24
/* adtc [31:0] data addr R1 */
239
#define MMC_WRITE_MULTIPLE_BLOCK 25
/* adtc R1 */
240
#define MMC_PROGRAM_CID 26
/* adtc R1 */
241
#define MMC_PROGRAM_CSD 27
/* adtc R1 */
242
243
/* class 6 */
244
#define MMC_SET_WRITE_PROT 28
/* ac [31:0] data addr R1b */
245
#define MMC_CLR_WRITE_PROT 29
/* ac [31:0] data addr R1b */
246
#define MMC_SEND_WRITE_PROT 30
/* adtc [31:0] wpdata addr R1 */
247
248
/* class 5 */
249
#define MMC_ERASE_GROUP_START 35
/* ac [31:0] data addr R1 */
250
#define MMC_ERASE_GROUP_END 36
/* ac [31:0] data addr R1 */
251
#define MMC_ERASE 37
/* ac R1b */
252
#define SD_ERASE_WR_BLK_START 32
/* ac [31:0] data addr R1 */
253
#define SD_ERASE_WR_BLK_END 33
/* ac [31:0] data addr R1 */
254
#define SD_ERASE 38
/* ac R1b */
255
256
/* class 9 */
257
#define MMC_FAST_IO 39
/* ac <Complex> R4 */
258
#define MMC_GO_IRQ_STATE 40
/* bcr R5 */
259
260
/* class 7 */
261
#define MMC_LOCK_UNLOCK 42
/* adtc R1b */
262
263
/* class 8 */
264
#define MMC_APP_CMD 55
/* ac [31:16] RCA R1 */
265
#define MMC_GEN_CMD 56
/* adtc [0] RD/WR R1b */
266
267
/* SD commands type argument response */
268
/* class 8 */
269
/* This is basically the same command as for MMC with some quirks. */
270
#define SD_SEND_RELATIVE_ADDR 3
/* ac R6 */
271
#define SD_CMD8 8
/* bcr [31:0] OCR R3 */
272
273
/* Application commands */
274
#define SD_APP_SET_BUS_WIDTH 6
/* ac [1:0] bus width R1 */
275
#define SD_APP_OP_COND 41
/* bcr [31:0] OCR R1 (R4) */
276
#define SD_APP_SEND_SCR 51
/* adtc R1 */
277
293
#define R1_OUT_OF_RANGE (1UL << 31)
/* er, c */
294
#define R1_ADDRESS_ERROR (1 << 30)
/* erx, c */
295
#define R1_BLOCK_LEN_ERROR (1 << 29)
/* er, c */
296
#define R1_ERASE_SEQ_ERROR (1 << 28)
/* er, c */
297
#define R1_ERASE_PARAM (1 << 27)
/* ex, c */
298
#define R1_WP_VIOLATION (1 << 26)
/* erx, c */
299
#define R1_CARD_IS_LOCKED (1 << 25)
/* sx, a */
300
#define R1_LOCK_UNLOCK_FAILED (1 << 24)
/* erx, c */
301
#define R1_COM_CRC_ERROR (1 << 23)
/* er, b */
302
#define R1_ILLEGAL_COMMAND (1 << 22)
/* er, b */
303
#define R1_CARD_ECC_FAILED (1 << 21)
/* ex, c */
304
#define R1_CC_ERROR (1 << 20)
/* erx, c */
305
#define R1_ERROR (1 << 19)
/* erx, c */
306
#define R1_UNDERRUN (1 << 18)
/* ex, c */
307
#define R1_OVERRUN (1 << 17)
/* ex, c */
308
#define R1_CID_CSD_OVERWRITE (1 << 16)
/* erx, c, CID/CSD overwrite */
309
#define R1_WP_ERASE_SKIP (1 << 15)
/* sx, c */
310
#define R1_CARD_ECC_DISABLED (1 << 14)
/* sx, a */
311
#define R1_ERASE_RESET (1 << 13)
/* sr, c */
312
#define R1_STATUS(x) (x & 0xFFFFE000)
313
#define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9)
/* sx, b (4 bits) */
314
#define R1_READY_FOR_DATA (1 << 8)
/* sx, a */
315
#define R1_APP_CMD (1 << 5)
/* sr, c */
316
320
#define OCR_ALL_READY (1UL << 31)
/* Card Power up status bit */
321
#define OCR_HC_CCS (1 << 30)
/* High capacity card */
322
#define OCR_VOLTAGE_RANGE_MSK (0x00FF8000)
323
324
#define SD_SEND_IF_ARG 0x000001AA
325
#define SD_SEND_IF_ECHO_MSK 0x000000FF
326
#define SD_SEND_IF_RESP 0x000000AA
327
331
#define CMDRESP_R3_OCR_VAL(n) (((uint32_t) n) & 0xFFFFFF)
332
#define CMDRESP_R3_S18A (((uint32_t) 1 ) << 24)
333
#define CMDRESP_R3_HC_CCS (((uint32_t) 1 ) << 30)
334
#define CMDRESP_R3_INIT_COMPLETE (((uint32_t) 1 ) << 31)
335
339
#define CMDRESP_R6_RCA_VAL(n) (((uint32_t) (n >> 16)) & 0xFFFF)
340
#define CMDRESP_R6_CARD_STATUS(n) (((uint32_t) (n & 0x1FFF)) | \
341
((n & (1 << 13)) ? (1 << 19) : 0) | \
342
((n & (1 << 14)) ? (1 << 22) : 0) | \
343
((n & (1 << 15)) ? (1 << 23) : 0))
344
349
#define CMDRESP_R7_CHECK_PATTERN(n) (((uint32_t) n ) & 0xFF)
350
351
#define CMDRESP_R7_VOLTAGE_ACCEPTED (((uint32_t) 1 ) << 8)
352
357
#define CMD3_RCA(n) (((uint32_t) (n & 0xFFFF) ) << 16)
358
363
#define CMD7_RCA(n) (((uint32_t) (n & 0xFFFF) ) << 16)
364
369
#define CMD8_CHECKPATTERN(n) (((uint32_t) (n & 0xFF) ) << 0)
370
371
#define CMD8_DEF_PATTERN (0xAA)
372
373
#define CMD8_VOLTAGESUPPLIED_27_36 (((uint32_t) 1 ) << 8)
374
378
#define CMD9_RCA(n) (((uint32_t) (n & 0xFFFF) ) << 16)
379
383
#define CMD13_RCA(n) (((uint32_t) (n & 0xFFFF) ) << 16)
384
388
#define CMD55_RCA(n) (((uint32_t) (n & 0xFFFF) ) << 16)
389
393
#define ACMD41_OCR(n) (((uint32_t) n) & 0xFFFFFF)
394
#define ACMD41_S18R (((uint32_t) 1 ) << 24)
395
#define ACMD41_XPC (((uint32_t) 1 ) << 28)
396
#define ACMD41_HCS (((uint32_t) 1 ) << 30)
397
401
#define ACMD6_BUS_WIDTH(n) ((uint32_t) n & 0x03)
402
#define ACMD6_BUS_WIDTH_1 (0)
403
#define ACMD6_BUS_WIDTH_4 (2)
404
407
#define CARD_TYPE_SD (1 << 0)
408
#define CARD_TYPE_4BIT (1 << 1)
409
#define CARD_TYPE_8BIT (1 << 2)
410
#define CARD_TYPE_HC (OCR_HC_CCS)
415
#define MMC_SECTOR_SIZE 512
416
420
#define SD_MMC_ENUM_CLOCK 400000
421
425
#define MMC_MAX_CLOCK 20000000
426
430
#define MMC_LOW_BUS_MAX_CLOCK 26000000
431
435
#define MMC_HIGH_BUS_MAX_CLOCK 52000000
436
440
#define SD_MAX_CLOCK 25000000
441
442
#ifdef __cplusplus
443
}
444
#endif
445
450
#endif
/* __SDMMC_H */
Generated on Fri Feb 20 2015 22:12:06 for LPCOpen Platform for LPC112X microcontrollers by
1.8.3.1