5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
24 #define SDIO_STATIC_FLAGS ((uint32_t)0x000005FF)
25 #define SDIO_CMD0TIMEOUT ((uint32_t)0x00010000)
27 #define SD_OCR_ADDR_OUT_OF_RANGE ((uint32_t)0x80000000)
28 #define SD_OCR_ADDR_MISALIGNED ((uint32_t)0x40000000)
29 #define SD_OCR_BLOCK_LEN_ERR ((uint32_t)0x20000000)
30 #define SD_OCR_ERASE_SEQ_ERR ((uint32_t)0x10000000)
31 #define SD_OCR_BAD_ERASE_PARAM ((uint32_t)0x08000000)
32 #define SD_OCR_WRITE_PROT_VIOLATION ((uint32_t)0x04000000)
33 #define SD_OCR_LOCK_UNLOCK_FAILED ((uint32_t)0x01000000)
34 #define SD_OCR_COM_CRC_FAILED ((uint32_t)0x00800000)
35 #define SD_OCR_ILLEGAL_CMD ((uint32_t)0x00400000)
36 #define SD_OCR_CARD_ECC_FAILED ((uint32_t)0x00200000)
37 #define SD_OCR_CC_ERROR ((uint32_t)0x00100000)
38 #define SD_OCR_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00080000)
39 #define SD_OCR_STREAM_READ_UNDERRUN ((uint32_t)0x00040000)
40 #define SD_OCR_STREAM_WRITE_OVERRUN ((uint32_t)0x00020000)
41 #define SD_OCR_CID_CSD_OVERWRIETE ((uint32_t)0x00010000)
42 #define SD_OCR_WP_ERASE_SKIP ((uint32_t)0x00008000)
43 #define SD_OCR_CARD_ECC_DISABLED ((uint32_t)0x00004000)
44 #define SD_OCR_ERASE_RESET ((uint32_t)0x00002000)
45 #define SD_OCR_AKE_SEQ_ERROR ((uint32_t)0x00000008)
46 #define SD_OCR_ERRORBITS ((uint32_t)0xFDFFE008)
48 #define SD_R6_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00002000)
49 #define SD_R6_ILLEGAL_CMD ((uint32_t)0x00004000)
50 #define SD_R6_COM_CRC_FAILED ((uint32_t)0x00008000)
52 #define SD_VOLTAGE_WINDOW_SD ((uint32_t)0x80100000)
53 #define SD_HIGH_CAPACITY ((uint32_t)0x40000000)
54 #define SD_STD_CAPACITY ((uint32_t)0x00000000)
55 #define SD_CHECK_PATTERN ((uint32_t)0x000001AA)
57 #define SD_MAX_VOLT_TRIAL ((uint32_t)0x0000FFFF)
58 #define SD_ALLZERO ((uint32_t)0x00000000)
60 #define SD_WIDE_BUS_SUPPORT ((uint32_t)0x00040000)
61 #define SD_SINGLE_BUS_SUPPORT ((uint32_t)0x00010000)
62 #define SD_CARD_LOCKED ((uint32_t)0x02000000)
64 #define SD_DATATIMEOUT ((uint32_t)1000000)
65 #define SD_0TO7BITS ((uint32_t)0x000000FF)
66 #define SD_8TO15BITS ((uint32_t)0x0000FF00)
67 #define SD_16TO23BITS ((uint32_t)0x00FF0000)
68 #define SD_24TO31BITS ((uint32_t)0xFF000000)
70 #define SDIO_SEND_IF_COND ((uint32_t)0x00000008)
73 #define SD_CMD_GO_IDLE_STATE ((uint8_t)0)
74 #define SD_CMD_SEND_OP_COND ((uint8_t)1)
75 #define SD_CMD_ALL_SEND_CID ((uint8_t)2)
76 #define SD_CMD_SET_REL_ADDR ((uint8_t)3) /*!< SDIO_SEND_REL_ADDR for SD Card */
77 #define SD_CMD_SET_DSR ((uint8_t)4)
78 #define SD_CMD_SDIO_SEN_OP_COND ((uint8_t)5)
79 #define SD_CMD_HS_SWITCH ((uint8_t)6)
80 #define SD_CMD_SEL_DESEL_CARD ((uint8_t)7)
81 #define SD_CMD_HS_SEND_EXT_CSD ((uint8_t)8)
82 #define SD_CMD_SEND_CSD ((uint8_t)9)
83 #define SD_CMD_SEND_CID ((uint8_t)10)
84 #define SD_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11) /*!< SD Card doesn't support it */
85 #define SD_CMD_STOP_TRANSMISSION ((uint8_t)12)
86 #define SD_CMD_SEND_STATUS ((uint8_t)13)
87 #define SD_CMD_HS_BUSTEST_READ ((uint8_t)14)
88 #define SD_CMD_GO_INACTIVE_STATE ((uint8_t)15)
89 #define SD_CMD_SET_BLOCKLEN ((uint8_t)16)
90 #define SD_CMD_READ_SINGLE_BLOCK ((uint8_t)17)
91 #define SD_CMD_READ_MULT_BLOCK ((uint8_t)18)
92 #define SD_CMD_HS_BUSTEST_WRITE ((uint8_t)19)
93 #define SD_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20) /*!< SD Card doesn't support it */
94 #define SD_CMD_SET_BLOCK_COUNT ((uint8_t)23) /*!< SD Card doesn't support it */
95 #define SD_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24)
96 #define SD_CMD_WRITE_MULT_BLOCK ((uint8_t)25)
97 #define SD_CMD_PROG_CID ((uint8_t)26) /*!< reserved for manufacturers */
98 #define SD_CMD_PROG_CSD ((uint8_t)27)
99 #define SD_CMD_SET_WRITE_PROT ((uint8_t)28)
100 #define SD_CMD_CLR_WRITE_PROT ((uint8_t)29)
101 #define SD_CMD_SEND_WRITE_PROT ((uint8_t)30)
102 #define SD_CMD_SD_ERASE_GRP_START ((uint8_t)32) /*!< To set the address of the first write
103 block to be erased. (For SD card only) */
104 #define SD_CMD_SD_ERASE_GRP_END ((uint8_t)33) /*!< To set the address of the last write block of the
105 continuous range to be erased. (For SD card only) */
106 #define SD_CMD_ERASE_GRP_START ((uint8_t)35) /*!< To set the address of the first write block to be erased.
107 (For MMC card only spec 3.31) */
109 #define SD_CMD_ERASE_GRP_END ((uint8_t)36) /*!< To set the address of the last write block of the
110 continuous range to be erased. (For MMC card only spec 3.31) */
112 #define SD_CMD_ERASE ((uint8_t)38)
113 #define SD_CMD_FAST_IO ((uint8_t)39) /*!< SD Card doesn't support it */
114 #define SD_CMD_GO_IRQ_STATE ((uint8_t)40) /*!< SD Card doesn't support it */
115 #define SD_CMD_LOCK_UNLOCK ((uint8_t)42)
116 #define SD_CMD_APP_CMD ((uint8_t)55)
117 #define SD_CMD_GEN_CMD ((uint8_t)56)
118 #define SD_CMD_NO_CMD ((uint8_t)64)
120 #define SD_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6) /*!< For SD Card only */
121 #define SD_CMD_SD_APP_STAUS ((uint8_t)13) /*!< For SD Card only */
122 #define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22) /*!< For SD Card only */
123 #define SD_CMD_SD_APP_OP_COND ((uint8_t)41) /*!< For SD Card only */
124 #define SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42) /*!< For SD Card only */
125 #define SD_CMD_SD_APP_SEND_SCR ((uint8_t)51) /*!< For SD Card only */
126 #define SD_CMD_SDIO_RW_DIRECT ((uint8_t)52) /*!< For SD I/O Card only */
127 #define SD_CMD_SDIO_RW_EXTENDED ((uint8_t)53) /*!< For SD I/O Card only */
129 #define SD_CMD_SD_APP_GET_MKB ((uint8_t)43) /*!< For SD Card only */
130 #define SD_CMD_SD_APP_GET_MID ((uint8_t)44) /*!< For SD Card only */
131 #define SD_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45) /*!< For SD Card only */
132 #define SD_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46) /*!< For SD Card only */
133 #define SD_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47) /*!< For SD Card only */
134 #define SD_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48) /*!< For SD Card only */
135 #define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18) /*!< For SD Card only */
136 #define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25) /*!< For SD Card only */
137 #define SD_CMD_SD_APP_SECURE_ERASE ((uint8_t)38) /*!< For SD Card only */
138 #define SD_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49) /*!< For SD Card only */
139 #define SD_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48) /*!< For SD Card only */
141 #define SDIO_STD_CAPACITY_SD_CARD_V1_1 ((uint32_t)0x00000000)
142 #define SDIO_STD_CAPACITY_SD_CARD_V2_0 ((uint32_t)0x00000001)
143 #define SDIO_HIGH_CAPACITY_SD_CARD ((uint32_t)0x00000002)
144 #define SDIO_MULTIMEDIA_CARD ((uint32_t)0x00000003)
145 #define SDIO_SECURE_DIGITAL_IO_CARD ((uint32_t)0x00000004)
146 #define SDIO_HIGH_SPEED_MULTIMEDIA_CARD ((uint32_t)0x00000005)
147 #define SDIO_SECURE_DIGITAL_IO_COMBO_CARD ((uint32_t)0x00000006)
148 #define SDIO_HIGH_CAPACITY_MMC_CARD ((uint32_t)0x00000007)
153 SD_CARD_READY
= ((uint32_t)0x00000001),
154 SD_CARD_IDENTIFICATION
= ((uint32_t)0x00000002),
155 SD_CARD_STANDBY
= ((uint32_t)0x00000003),
156 SD_CARD_TRANSFER
= ((uint32_t)0x00000004),
157 SD_CARD_SENDING
= ((uint32_t)0x00000005),
158 SD_CARD_RECEIVING
= ((uint32_t)0x00000006),
159 SD_CARD_PROGRAMMING
= ((uint32_t)0x00000007),
160 SD_CARD_DISCONNECTED
= ((uint32_t)0x00000008),
161 SD_CARD_ERROR
= ((uint32_t)0x000000FF)
165 static uint32_t CardType
= SDIO_STD_CAPACITY_SD_CARD_V1_1
;
166 static uint32_t CSD_Tab
[4], CID_Tab
[4], RCA
= 0;
167 __IO
uint8_t StopCondition
= 0;
168 __IO SD_Error TransferError
= SD_OK
;
169 __IO
uint8_t TransferEnd
= 0, DMAEndOfTransfer
= 0;
170 SD_CardInfo SDCardInfo
;
172 SDIO_InitTypeDef SDIO_InitStructure
;
173 SDIO_CmdInitTypeDef SDIO_CmdInitStructure
;
174 SDIO_DataInitTypeDef SDIO_DataInitStructure
;
176 static SD_Error
CmdError(void);
177 static SD_Error
CmdResp1Error(uint8_t cmd
);
178 static SD_Error
CmdResp7Error(void);
179 static SD_Error
CmdResp3Error(void);
180 static SD_Error
CmdResp2Error(void);
181 static SD_Error
CmdResp6Error(uint8_t cmd
, uint16_t *prca
);
182 static SD_Error
SDEnWideBus(FunctionalState NewState
);
183 static SD_Error
FindSCR(uint16_t rca
, uint32_t *pscr
);
185 SD_Error
SD_PowerON(void);
186 SDCardState
SD_GetState(void);
187 SD_Error
SD_InitializeCards(void);
188 SD_Error
SD_GetCardInfo(SD_CardInfo
*cardinfo
);
189 SD_Error
SD_EnableWideBusOperation(uint32_t WideMode
);
190 SD_Error
SD_SelectDeselect(uint32_t addr
);
191 SD_Error
SD_StopTransfer(void);
192 SD_Error
SD_SendStatus(uint32_t *pcardstatus
);
194 void SD_LowLevel_Init(void)
196 GPIO_InitTypeDef GPIO_InitStructure
;
198 GPIO_PinAFConfig(GPIOC
, GPIO_PinSource8
, GPIO_AF_SDIO
);
199 GPIO_PinAFConfig(GPIOC
, GPIO_PinSource9
, GPIO_AF_SDIO
);
200 GPIO_PinAFConfig(GPIOC
, GPIO_PinSource10
, GPIO_AF_SDIO
);
201 GPIO_PinAFConfig(GPIOC
, GPIO_PinSource11
, GPIO_AF_SDIO
);
202 GPIO_PinAFConfig(GPIOC
, GPIO_PinSource12
, GPIO_AF_SDIO
);
203 GPIO_PinAFConfig(GPIOD
, GPIO_PinSource2
, GPIO_AF_SDIO
);
205 /* Configure PC.08, PC.09, PC.10, PC.11 pins: D0, D1, D2, D3 pins */
206 GPIO_InitStructure
.GPIO_Pin
= GPIO_Pin_8
| GPIO_Pin_9
| GPIO_Pin_10
| GPIO_Pin_11
;
207 GPIO_InitStructure
.GPIO_Speed
= GPIO_Speed_50MHz
;
208 GPIO_InitStructure
.GPIO_Mode
= GPIO_Mode_AF
;
209 GPIO_InitStructure
.GPIO_OType
= GPIO_OType_PP
;
210 GPIO_InitStructure
.GPIO_PuPd
= GPIO_PuPd_UP
;
211 GPIO_Init(GPIOC
, &GPIO_InitStructure
);
213 /* Configure PD.02 CMD line */
214 GPIO_InitStructure
.GPIO_Pin
= GPIO_Pin_2
;
215 GPIO_Init(GPIOD
, &GPIO_InitStructure
);
217 /* Configure PC.12 pin: CLK pin */
218 GPIO_InitStructure
.GPIO_Pin
= GPIO_Pin_12
;
219 GPIO_InitStructure
.GPIO_PuPd
= GPIO_PuPd_NOPULL
;
220 GPIO_Init(GPIOC
, &GPIO_InitStructure
);
222 /* Enable the SDIO APB2 Clock */
223 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDIO
, ENABLE
);
225 // SDIO Interrupt ENABLE
226 NVIC_InitTypeDef NVIC_InitStructure
;
227 NVIC_InitStructure
.NVIC_IRQChannel
= SDIO_IRQn
;
228 NVIC_InitStructure
.NVIC_IRQChannelPreemptionPriority
= 0;
229 NVIC_InitStructure
.NVIC_IRQChannelSubPriority
= 0;
230 NVIC_InitStructure
.NVIC_IRQChannelCmd
= ENABLE
;
231 NVIC_Init(&NVIC_InitStructure
);
232 // DMA2 STREAMx Interrupt ENABLE
233 NVIC_InitStructure
.NVIC_IRQChannel
= SD_SDIO_DMA_IRQn
;
234 NVIC_InitStructure
.NVIC_IRQChannelPreemptionPriority
= 1;
235 NVIC_Init(&NVIC_InitStructure
);
238 void SD_LowLevel_DMA_TxConfig(uint32_t * BufferSRC
, uint32_t BufferSize
)
240 DMA_InitTypeDef SDDMA_InitStructure
;
242 DMA_ClearFlag(SD_SDIO_DMA_STREAM
, SD_SDIO_DMA_FLAG_FEIF
| SD_SDIO_DMA_FLAG_DMEIF
| SD_SDIO_DMA_FLAG_TEIF
| SD_SDIO_DMA_FLAG_HTIF
| SD_SDIO_DMA_FLAG_TCIF
);
244 /* DMA2 Stream3 or Stream6 disable */
245 DMA_Cmd(SD_SDIO_DMA_STREAM
, DISABLE
);
247 /* DMA2 Stream3 or Stream6 Config */
248 DMA_DeInit(SD_SDIO_DMA_STREAM
);
250 SDDMA_InitStructure
.DMA_Channel
= SD_SDIO_DMA_CHANNEL
;
251 SDDMA_InitStructure
.DMA_PeripheralBaseAddr
= SD_SDIO_FIFO_ADDRESS
;
252 SDDMA_InitStructure
.DMA_Memory0BaseAddr
= (uint32_t)BufferSRC
;
253 SDDMA_InitStructure
.DMA_DIR
= DMA_DIR_MemoryToPeripheral
;
254 SDDMA_InitStructure
.DMA_BufferSize
= 1;
255 SDDMA_InitStructure
.DMA_PeripheralInc
= DMA_PeripheralInc_Disable
;
256 SDDMA_InitStructure
.DMA_MemoryInc
= DMA_MemoryInc_Enable
;
257 SDDMA_InitStructure
.DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Word
;
258 SDDMA_InitStructure
.DMA_MemoryDataSize
= DMA_MemoryDataSize_Word
;
259 SDDMA_InitStructure
.DMA_Mode
= DMA_Mode_Normal
;
260 SDDMA_InitStructure
.DMA_Priority
= DMA_Priority_VeryHigh
;
261 SDDMA_InitStructure
.DMA_FIFOMode
= DMA_FIFOMode_Enable
;
262 SDDMA_InitStructure
.DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
;
263 SDDMA_InitStructure
.DMA_MemoryBurst
= DMA_MemoryBurst_INC4
;
264 SDDMA_InitStructure
.DMA_PeripheralBurst
= DMA_PeripheralBurst_INC4
;
265 DMA_Init(SD_SDIO_DMA_STREAM
, &SDDMA_InitStructure
);
266 DMA_ITConfig(SD_SDIO_DMA_STREAM
, DMA_IT_TC
, ENABLE
);
267 DMA_FlowControllerConfig(SD_SDIO_DMA_STREAM
, DMA_FlowCtrl_Peripheral
);
269 /* DMA2 Stream3 or Stream6 enable */
270 DMA_Cmd(SD_SDIO_DMA_STREAM
, ENABLE
);
274 void SD_LowLevel_DMA_RxConfig(uint32_t *BufferDST
, uint32_t BufferSize
)
276 DMA_InitTypeDef SDDMA_InitStructure
;
278 DMA_ClearFlag(SD_SDIO_DMA_STREAM
, SD_SDIO_DMA_FLAG_FEIF
| SD_SDIO_DMA_FLAG_DMEIF
| SD_SDIO_DMA_FLAG_TEIF
| SD_SDIO_DMA_FLAG_HTIF
| SD_SDIO_DMA_FLAG_TCIF
);
280 /* DMA2 Stream3 or Stream6 disable */
281 DMA_Cmd(SD_SDIO_DMA_STREAM
, DISABLE
);
283 /* DMA2 Stream3 or Stream6 Config */
284 DMA_DeInit(SD_SDIO_DMA_STREAM
);
286 SDDMA_InitStructure
.DMA_Channel
= SD_SDIO_DMA_CHANNEL
;
287 SDDMA_InitStructure
.DMA_PeripheralBaseAddr
= SD_SDIO_FIFO_ADDRESS
;
288 SDDMA_InitStructure
.DMA_Memory0BaseAddr
= (uint32_t)BufferDST
;
289 SDDMA_InitStructure
.DMA_DIR
= DMA_DIR_PeripheralToMemory
;
290 SDDMA_InitStructure
.DMA_BufferSize
= 1;
291 SDDMA_InitStructure
.DMA_PeripheralInc
= DMA_PeripheralInc_Disable
;
292 SDDMA_InitStructure
.DMA_MemoryInc
= DMA_MemoryInc_Enable
;
293 SDDMA_InitStructure
.DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Word
;
294 SDDMA_InitStructure
.DMA_MemoryDataSize
= DMA_MemoryDataSize_Word
;
295 SDDMA_InitStructure
.DMA_Mode
= DMA_Mode_Normal
;
296 SDDMA_InitStructure
.DMA_Priority
= DMA_Priority_VeryHigh
;
297 SDDMA_InitStructure
.DMA_FIFOMode
= DMA_FIFOMode_Enable
;
298 SDDMA_InitStructure
.DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
;
299 SDDMA_InitStructure
.DMA_MemoryBurst
= DMA_MemoryBurst_INC4
;
300 SDDMA_InitStructure
.DMA_PeripheralBurst
= DMA_PeripheralBurst_INC4
;
301 DMA_Init(SD_SDIO_DMA_STREAM
, &SDDMA_InitStructure
);
302 DMA_ITConfig(SD_SDIO_DMA_STREAM
, DMA_IT_TC
, ENABLE
);
303 DMA_FlowControllerConfig(SD_SDIO_DMA_STREAM
, DMA_FlowCtrl_Peripheral
);
305 /* DMA2 Stream3 or Stream6 enable */
306 DMA_Cmd(SD_SDIO_DMA_STREAM
, ENABLE
);
309 SD_Error
SD_Init(void)
311 __IO SD_Error errorstatus
= SD_OK
;
313 /* SDIO Peripheral Low Level Init */
318 errorstatus
= SD_PowerON();
319 if (errorstatus
!= SD_OK
) {
320 TRACE("SD_PowerON() status=%d", errorstatus
);
321 /*!< CMD Response TimeOut (wait for CMDSENT flag) */
325 errorstatus
= SD_InitializeCards();
326 if (errorstatus
!= SD_OK
) {
327 TRACE("SD_InitializeCards() status=%d", errorstatus
);
328 /*!< CMD Response TimeOut (wait for CMDSENT flag) */
332 /*!< Configure the SDIO peripheral */
333 /*!< SDIO_CK = SDIOCLK / (SDIO_TRANSFER_CLK_DIV + 2) */
334 /*!< on STM32F4xx devices, SDIOCLK is fixed to 48MHz */
335 SDIO_InitStructure
.SDIO_ClockDiv
= SD_SDIO_TRANSFER_CLK_DIV
;
336 SDIO_InitStructure
.SDIO_ClockEdge
= SDIO_ClockEdge_Rising
;
337 SDIO_InitStructure
.SDIO_ClockBypass
= SDIO_ClockBypass_Disable
;
338 SDIO_InitStructure
.SDIO_ClockPowerSave
= SDIO_ClockPowerSave_Disable
;
339 SDIO_InitStructure
.SDIO_BusWide
= SDIO_BusWide_1b
;
340 SDIO_InitStructure
.SDIO_HardwareFlowControl
= SDIO_HardwareFlowControl_Disable
;
341 SDIO_Init(&SDIO_InitStructure
);
343 /*----------------- Read CSD/CID MSD registers ------------------*/
344 errorstatus
= SD_GetCardInfo(&SDCardInfo
);
346 if (errorstatus
== SD_OK
) {
347 /*----------------- Select Card --------------------------------*/
348 errorstatus
= SD_SelectDeselect((uint32_t) (SDCardInfo
.RCA
<< 16));
351 if (errorstatus
== SD_OK
) {
352 errorstatus
= SD_EnableWideBusOperation(SDIO_BusWide_4b
);
359 * @brief Gets the cuurent sd card data transfer status.
361 * @retval SDTransferState: Data Transfer state.
363 * - SD_TRANSFER_OK: No data transfer is acting
364 * - SD_TRANSFER_BUSY: Data transfer is acting
366 SDTransferState
SD_GetStatus(void)
368 SDCardState cardstate
= SD_GetState();
370 if (cardstate
== SD_CARD_TRANSFER
) {
371 return SD_TRANSFER_OK
;
373 else if (cardstate
== SD_CARD_ERROR
) {
374 return SD_TRANSFER_ERROR
;
377 return SD_TRANSFER_BUSY
;
382 * @brief Returns the current card's state.
384 * @retval SDCardState: SD Card Error or SD Card Current State.
386 SDCardState
SD_GetState(void)
390 if (SD_Detect()== SD_PRESENT
) {
391 if (SD_SendStatus(&resp1
) != SD_OK
) {
392 return SD_CARD_ERROR
;
395 return (SDCardState
)((resp1
>> 9) & 0x0F);
399 return SD_CARD_ERROR
;
404 * @brief Detect if SD card is correctly plugged in the memory slot.
406 * @retval Return if SD is detected or not
408 uint8_t SD_Detect(void)
410 __IO
uint8_t status
= SD_PRESENT
;
413 /*!< Check GPIO to detect SD */
414 if (GPIO_ReadInputDataBit(SD_DETECT_GPIO_PORT
, SD_DETECT_PIN
) != Bit_RESET
) {
415 status
= SD_NOT_PRESENT
;
422 //---------------------------------------------------------------------------------------
424 #define OPTIMIZE(level) __attribute__((optimize(level)))
427 * @brief Enquires cards about their operating voltage and configures
430 * @retval SD_Error: SD Card Error code.
432 OPTIMIZE("O0") SD_Error
SD_PowerON(void)
434 __IO SD_Error errorstatus
= SD_OK
;
435 uint32_t response
= 0, count
= 0, validvoltage
= 0;
436 uint32_t SDType
= SD_STD_CAPACITY
;
438 /*!< Power ON Sequence -----------------------------------------------------*/
439 /*!< Configure the SDIO peripheral */
440 /*!< SDIO_CK = SDIOCLK / (SDIO_INIT_CLK_DIV + 2) */
441 /*!< on STM32F4xx devices, SDIOCLK is fixed to 48MHz */
442 /*!< SDIO_CK for initialization should not exceed 400 KHz */
443 SDIO_InitStructure
.SDIO_ClockDiv
= SD_SDIO_INIT_CLK_DIV
;
444 SDIO_InitStructure
.SDIO_ClockEdge
= SDIO_ClockEdge_Rising
;
445 SDIO_InitStructure
.SDIO_ClockBypass
= SDIO_ClockBypass_Disable
;
446 SDIO_InitStructure
.SDIO_ClockPowerSave
= SDIO_ClockPowerSave_Disable
;
447 SDIO_InitStructure
.SDIO_BusWide
= SDIO_BusWide_1b
;
448 SDIO_InitStructure
.SDIO_HardwareFlowControl
= SDIO_HardwareFlowControl_Disable
;
449 SDIO_Init(&SDIO_InitStructure
);
451 /*!< Set Power State to ON */
452 SDIO_SetPowerState(SDIO_PowerState_ON
);
454 /*!< Enable SDIO Clock */
455 SDIO_ClockCmd(ENABLE
);
457 /*!< CMD0: GO_IDLE_STATE ---------------------------------------------------*/
458 /*!< No CMD response required */
459 SDIO_CmdInitStructure
.SDIO_Argument
= 0x0;
460 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_GO_IDLE_STATE
;
461 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_No
;
462 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
463 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
464 SDIO_SendCommand(&SDIO_CmdInitStructure
);
466 errorstatus
= CmdError();
468 if (errorstatus
!= SD_OK
) {
469 TRACE("SD_CMD_GO_IDLE_STATE status=%d", errorstatus
);
470 /*!< CMD Response TimeOut (wait for CMDSENT flag) */
474 /*!< CMD8: SEND_IF_COND ----------------------------------------------------*/
475 /*!< Send CMD8 to verify SD card interface operating condition */
476 /*!< Argument: - [31:12]: Reserved (shall be set to '0')
477 - [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)
478 - [7:0]: Check Pattern (recommended 0xAA) */
479 /*!< CMD Response: R7 */
480 SDIO_CmdInitStructure
.SDIO_Argument
= SD_CHECK_PATTERN
;
481 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SDIO_SEND_IF_COND
;
482 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
483 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
484 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
485 SDIO_SendCommand(&SDIO_CmdInitStructure
);
487 errorstatus
= CmdResp7Error();
489 if (errorstatus
== SD_OK
) {
490 CardType
= SDIO_STD_CAPACITY_SD_CARD_V2_0
; /*!< SD Card 2.0 */
491 SDType
= SD_HIGH_CAPACITY
;
495 SDIO_CmdInitStructure
.SDIO_Argument
= 0x00;
496 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_APP_CMD
;
497 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
498 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
499 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
500 SDIO_SendCommand(&SDIO_CmdInitStructure
);
501 errorstatus
= CmdResp1Error(SD_CMD_APP_CMD
);
504 SDIO_CmdInitStructure
.SDIO_Argument
= 0x00;
505 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_APP_CMD
;
506 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
507 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
508 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
509 SDIO_SendCommand(&SDIO_CmdInitStructure
);
510 errorstatus
= CmdResp1Error(SD_CMD_APP_CMD
);
512 /*!< If errorstatus is Command TimeOut, it is a MMC card */
513 /*!< If errorstatus is SD_OK it is a SD card: SD card 2.0 (voltage range mismatch)
515 if (errorstatus
== SD_OK
) {
517 /*!< Send ACMD41 SD_APP_OP_COND with Argument 0x80100000 */
518 while ((!validvoltage
) && (count
< SD_MAX_VOLT_TRIAL
)) {
520 /*!< SEND CMD55 APP_CMD with RCA as 0 */
521 SDIO_CmdInitStructure
.SDIO_Argument
= 0x00;
522 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_APP_CMD
;
523 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
524 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
525 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
526 SDIO_SendCommand(&SDIO_CmdInitStructure
);
528 errorstatus
= CmdResp1Error(SD_CMD_APP_CMD
);
530 if (errorstatus
!= SD_OK
) {
531 TRACE("SD_CMD_APP_CMD status=%d", errorstatus
);
534 SDIO_CmdInitStructure
.SDIO_Argument
= SD_VOLTAGE_WINDOW_SD
| SDType
;
535 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SD_APP_OP_COND
;
536 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
537 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
538 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
539 SDIO_SendCommand(&SDIO_CmdInitStructure
);
541 errorstatus
= CmdResp3Error();
542 if (errorstatus
!= SD_OK
) {
543 TRACE("SD_CMD_SD_APP_OP_COND status=%d", errorstatus
);
547 response
= SDIO_GetResponse(SDIO_RESP1
);
548 validvoltage
= (((response
>> 31) == 1) ? 1 : 0);
551 if (count
>= SD_MAX_VOLT_TRIAL
) {
552 errorstatus
= SD_INVALID_VOLTRANGE
;
556 if (response
&= SD_HIGH_CAPACITY
) {
557 CardType
= SDIO_HIGH_CAPACITY_SD_CARD
;
566 * @brief Turns the SDIO output signals off.
568 * @retval SD_Error: SD Card Error code.
570 OPTIMIZE("O0") SD_Error
SD_PowerOFF(void)
572 SD_Error errorstatus
= SD_OK
;
574 /*!< Set Power State to OFF */
575 SDIO_SetPowerState(SDIO_PowerState_OFF
);
581 * @brief Intialises all cards or single card as the case may be Card(s) come
582 * into standby state.
584 * @retval SD_Error: SD Card Error code.
586 OPTIMIZE("O0") SD_Error
SD_InitializeCards(void)
588 SD_Error errorstatus
= SD_OK
;
591 if (SDIO_GetPowerState() == SDIO_PowerState_OFF
) {
592 errorstatus
= SD_REQUEST_NOT_APPLICABLE
;
596 if (SDIO_SECURE_DIGITAL_IO_CARD
!= CardType
) {
597 /*!< Send CMD2 ALL_SEND_CID */
598 SDIO_CmdInitStructure
.SDIO_Argument
= 0x0;
599 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_ALL_SEND_CID
;
600 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Long
;
601 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
602 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
603 SDIO_SendCommand(&SDIO_CmdInitStructure
);
605 errorstatus
= CmdResp2Error();
607 if (SD_OK
!= errorstatus
) {
611 CID_Tab
[0] = SDIO_GetResponse(SDIO_RESP1
);
612 CID_Tab
[1] = SDIO_GetResponse(SDIO_RESP2
);
613 CID_Tab
[2] = SDIO_GetResponse(SDIO_RESP3
);
614 CID_Tab
[3] = SDIO_GetResponse(SDIO_RESP4
);
617 if ((SDIO_STD_CAPACITY_SD_CARD_V1_1
== CardType
) || (SDIO_STD_CAPACITY_SD_CARD_V2_0
== CardType
) || (SDIO_SECURE_DIGITAL_IO_COMBO_CARD
== CardType
)
618 || (SDIO_HIGH_CAPACITY_SD_CARD
== CardType
)) {
619 /*!< Send CMD3 SET_REL_ADDR with argument 0 */
620 /*!< SD Card publishes its RCA. */
621 SDIO_CmdInitStructure
.SDIO_Argument
= 0x00;
622 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SET_REL_ADDR
;
623 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
624 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
625 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
626 SDIO_SendCommand(&SDIO_CmdInitStructure
);
628 errorstatus
= CmdResp6Error(SD_CMD_SET_REL_ADDR
, &rca
);
630 if (SD_OK
!= errorstatus
) {
635 if (SDIO_SECURE_DIGITAL_IO_CARD
!= CardType
) {
638 /*!< Send CMD9 SEND_CSD with argument as card's RCA */
639 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t)(rca
<< 16);
640 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SEND_CSD
;
641 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Long
;
642 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
643 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
644 SDIO_SendCommand(&SDIO_CmdInitStructure
);
646 errorstatus
= CmdResp2Error();
648 if (SD_OK
!= errorstatus
) {
652 CSD_Tab
[0] = SDIO_GetResponse(SDIO_RESP1
);
653 CSD_Tab
[1] = SDIO_GetResponse(SDIO_RESP2
);
654 CSD_Tab
[2] = SDIO_GetResponse(SDIO_RESP3
);
655 CSD_Tab
[3] = SDIO_GetResponse(SDIO_RESP4
);
658 errorstatus
= SD_OK
; /*!< All cards get intialized */
664 * @brief Returns information about specific card.
665 * @param cardinfo: pointer to a SD_CardInfo structure that contains all SD card
667 * @retval SD_Error: SD Card Error code.
669 OPTIMIZE("O0") SD_Error
SD_GetCardInfo(SD_CardInfo
*cardinfo
)
671 SD_Error errorstatus
= SD_OK
;
674 cardinfo
->CardType
= (uint8_t)CardType
;
675 cardinfo
->RCA
= (uint16_t)RCA
;
678 tmp
= (uint8_t)((CSD_Tab
[0] & 0xFF000000) >> 24);
679 cardinfo
->SD_csd
.CSDStruct
= (tmp
& 0xC0) >> 6;
680 cardinfo
->SD_csd
.SysSpecVersion
= (tmp
& 0x3C) >> 2;
681 cardinfo
->SD_csd
.Reserved1
= tmp
& 0x03;
684 tmp
= (uint8_t)((CSD_Tab
[0] & 0x00FF0000) >> 16);
685 cardinfo
->SD_csd
.TAAC
= tmp
;
688 tmp
= (uint8_t)((CSD_Tab
[0] & 0x0000FF00) >> 8);
689 cardinfo
->SD_csd
.NSAC
= tmp
;
692 tmp
= (uint8_t)(CSD_Tab
[0] & 0x000000FF);
693 cardinfo
->SD_csd
.MaxBusClkFrec
= tmp
;
696 tmp
= (uint8_t)((CSD_Tab
[1] & 0xFF000000) >> 24);
697 cardinfo
->SD_csd
.CardComdClasses
= tmp
<< 4;
700 tmp
= (uint8_t)((CSD_Tab
[1] & 0x00FF0000) >> 16);
701 cardinfo
->SD_csd
.CardComdClasses
|= (tmp
& 0xF0) >> 4;
702 cardinfo
->SD_csd
.RdBlockLen
= tmp
& 0x0F;
705 tmp
= (uint8_t)((CSD_Tab
[1] & 0x0000FF00) >> 8);
706 cardinfo
->SD_csd
.PartBlockRead
= (tmp
& 0x80) >> 7;
707 cardinfo
->SD_csd
.WrBlockMisalign
= (tmp
& 0x40) >> 6;
708 cardinfo
->SD_csd
.RdBlockMisalign
= (tmp
& 0x20) >> 5;
709 cardinfo
->SD_csd
.DSRImpl
= (tmp
& 0x10) >> 4;
710 cardinfo
->SD_csd
.Reserved2
= 0; /*!< Reserved */
712 if ((CardType
== SDIO_STD_CAPACITY_SD_CARD_V1_1
) || (CardType
== SDIO_STD_CAPACITY_SD_CARD_V2_0
)) {
713 cardinfo
->SD_csd
.DeviceSize
= (tmp
& 0x03) << 10;
716 tmp
= (uint8_t)(CSD_Tab
[1] & 0x000000FF);
717 cardinfo
->SD_csd
.DeviceSize
|= (tmp
) << 2;
720 tmp
= (uint8_t)((CSD_Tab
[2] & 0xFF000000) >> 24);
721 cardinfo
->SD_csd
.DeviceSize
|= (tmp
& 0xC0) >> 6;
723 cardinfo
->SD_csd
.MaxRdCurrentVDDMin
= (tmp
& 0x38) >> 3;
724 cardinfo
->SD_csd
.MaxRdCurrentVDDMax
= (tmp
& 0x07);
727 tmp
= (uint8_t)((CSD_Tab
[2] & 0x00FF0000) >> 16);
728 cardinfo
->SD_csd
.MaxWrCurrentVDDMin
= (tmp
& 0xE0) >> 5;
729 cardinfo
->SD_csd
.MaxWrCurrentVDDMax
= (tmp
& 0x1C) >> 2;
730 cardinfo
->SD_csd
.DeviceSizeMul
= (tmp
& 0x03) << 1;
732 tmp
= (uint8_t)((CSD_Tab
[2] & 0x0000FF00) >> 8);
733 cardinfo
->SD_csd
.DeviceSizeMul
|= (tmp
& 0x80) >> 7;
735 cardinfo
->CardCapacity
= (cardinfo
->SD_csd
.DeviceSize
+ 1) ;
736 cardinfo
->CardCapacity
*= (1 << (cardinfo
->SD_csd
.DeviceSizeMul
+ 2));
737 cardinfo
->CardBlockSize
= 1 << (cardinfo
->SD_csd
.RdBlockLen
);
738 cardinfo
->CardCapacity
*= cardinfo
->CardBlockSize
;
740 else if (CardType
== SDIO_HIGH_CAPACITY_SD_CARD
) {
742 tmp
= (uint8_t)(CSD_Tab
[1] & 0x000000FF);
743 cardinfo
->SD_csd
.DeviceSize
= (tmp
& 0x3F) << 16;
746 tmp
= (uint8_t)((CSD_Tab
[2] & 0xFF000000) >> 24);
748 cardinfo
->SD_csd
.DeviceSize
|= (tmp
<< 8);
751 tmp
= (uint8_t)((CSD_Tab
[2] & 0x00FF0000) >> 16);
753 cardinfo
->SD_csd
.DeviceSize
|= (tmp
);
756 tmp
= (uint8_t)((CSD_Tab
[2] & 0x0000FF00) >> 8);
758 cardinfo
->CardCapacity
= ((uint64_t)cardinfo
->SD_csd
.DeviceSize
+ 1) * 512 * 1024;
759 cardinfo
->CardBlockSize
= 512;
763 cardinfo
->SD_csd
.EraseGrSize
= (tmp
& 0x40) >> 6;
764 cardinfo
->SD_csd
.EraseGrMul
= (tmp
& 0x3F) << 1;
767 tmp
= (uint8_t)(CSD_Tab
[2] & 0x000000FF);
768 cardinfo
->SD_csd
.EraseGrMul
|= (tmp
& 0x80) >> 7;
769 cardinfo
->SD_csd
.WrProtectGrSize
= (tmp
& 0x7F);
772 tmp
= (uint8_t)((CSD_Tab
[3] & 0xFF000000) >> 24);
773 cardinfo
->SD_csd
.WrProtectGrEnable
= (tmp
& 0x80) >> 7;
774 cardinfo
->SD_csd
.ManDeflECC
= (tmp
& 0x60) >> 5;
775 cardinfo
->SD_csd
.WrSpeedFact
= (tmp
& 0x1C) >> 2;
776 cardinfo
->SD_csd
.MaxWrBlockLen
= (tmp
& 0x03) << 2;
779 tmp
= (uint8_t)((CSD_Tab
[3] & 0x00FF0000) >> 16);
780 cardinfo
->SD_csd
.MaxWrBlockLen
|= (tmp
& 0xC0) >> 6;
781 cardinfo
->SD_csd
.WriteBlockPaPartial
= (tmp
& 0x20) >> 5;
782 cardinfo
->SD_csd
.Reserved3
= 0;
783 cardinfo
->SD_csd
.ContentProtectAppli
= (tmp
& 0x01);
786 tmp
= (uint8_t)((CSD_Tab
[3] & 0x0000FF00) >> 8);
787 cardinfo
->SD_csd
.FileFormatGrouop
= (tmp
& 0x80) >> 7;
788 cardinfo
->SD_csd
.CopyFlag
= (tmp
& 0x40) >> 6;
789 cardinfo
->SD_csd
.PermWrProtect
= (tmp
& 0x20) >> 5;
790 cardinfo
->SD_csd
.TempWrProtect
= (tmp
& 0x10) >> 4;
791 cardinfo
->SD_csd
.FileFormat
= (tmp
& 0x0C) >> 2;
792 cardinfo
->SD_csd
.ECC
= (tmp
& 0x03);
795 tmp
= (uint8_t)(CSD_Tab
[3] & 0x000000FF);
796 cardinfo
->SD_csd
.CSD_CRC
= (tmp
& 0xFE) >> 1;
797 cardinfo
->SD_csd
.Reserved4
= 1;
801 tmp
= (uint8_t)((CID_Tab
[0] & 0xFF000000) >> 24);
802 cardinfo
->SD_cid
.ManufacturerID
= tmp
;
805 tmp
= (uint8_t)((CID_Tab
[0] & 0x00FF0000) >> 16);
806 cardinfo
->SD_cid
.OEM_AppliID
= tmp
<< 8;
809 tmp
= (uint8_t)((CID_Tab
[0] & 0x000000FF00) >> 8);
810 cardinfo
->SD_cid
.OEM_AppliID
|= tmp
;
813 tmp
= (uint8_t)(CID_Tab
[0] & 0x000000FF);
814 cardinfo
->SD_cid
.ProdName1
= tmp
<< 24;
817 tmp
= (uint8_t)((CID_Tab
[1] & 0xFF000000) >> 24);
818 cardinfo
->SD_cid
.ProdName1
|= tmp
<< 16;
821 tmp
= (uint8_t)((CID_Tab
[1] & 0x00FF0000) >> 16);
822 cardinfo
->SD_cid
.ProdName1
|= tmp
<< 8;
825 tmp
= (uint8_t)((CID_Tab
[1] & 0x0000FF00) >> 8);
826 cardinfo
->SD_cid
.ProdName1
|= tmp
;
829 tmp
= (uint8_t)(CID_Tab
[1] & 0x000000FF);
830 cardinfo
->SD_cid
.ProdName2
= tmp
;
833 tmp
= (uint8_t)((CID_Tab
[2] & 0xFF000000) >> 24);
834 cardinfo
->SD_cid
.ProdRev
= tmp
;
837 tmp
= (uint8_t)((CID_Tab
[2] & 0x00FF0000) >> 16);
838 cardinfo
->SD_cid
.ProdSN
= tmp
<< 24;
841 tmp
= (uint8_t)((CID_Tab
[2] & 0x0000FF00) >> 8);
842 cardinfo
->SD_cid
.ProdSN
|= tmp
<< 16;
845 tmp
= (uint8_t)(CID_Tab
[2] & 0x000000FF);
846 cardinfo
->SD_cid
.ProdSN
|= tmp
<< 8;
849 tmp
= (uint8_t)((CID_Tab
[3] & 0xFF000000) >> 24);
850 cardinfo
->SD_cid
.ProdSN
|= tmp
;
853 tmp
= (uint8_t)((CID_Tab
[3] & 0x00FF0000) >> 16);
854 cardinfo
->SD_cid
.Reserved1
|= (tmp
& 0xF0) >> 4;
855 cardinfo
->SD_cid
.ManufactDate
= (tmp
& 0x0F) << 8;
858 tmp
= (uint8_t)((CID_Tab
[3] & 0x0000FF00) >> 8);
859 cardinfo
->SD_cid
.ManufactDate
|= tmp
;
862 tmp
= (uint8_t)(CID_Tab
[3] & 0x000000FF);
863 cardinfo
->SD_cid
.CID_CRC
= (tmp
& 0xFE) >> 1;
864 cardinfo
->SD_cid
.Reserved2
= 1;
870 * @brief Enables wide bus opeartion for the requeseted card if supported by
872 * @param WideMode: Specifies the SD card wide bus mode.
873 * This parameter can be one of the following values:
874 * @arg SDIO_BusWide_8b: 8-bit data transfer (Only for MMC)
875 * @arg SDIO_BusWide_4b: 4-bit data transfer
876 * @arg SDIO_BusWide_1b: 1-bit data transfer
877 * @retval SD_Error: SD Card Error code.
879 OPTIMIZE("O0") SD_Error
SD_EnableWideBusOperation(uint32_t WideMode
)
881 SD_Error errorstatus
= SD_OK
;
883 /*!< MMC Card doesn't support this feature */
884 if (SDIO_MULTIMEDIA_CARD
== CardType
) {
885 errorstatus
= SD_UNSUPPORTED_FEATURE
;
888 else if ((SDIO_STD_CAPACITY_SD_CARD_V1_1
== CardType
) || (SDIO_STD_CAPACITY_SD_CARD_V2_0
== CardType
) || (SDIO_HIGH_CAPACITY_SD_CARD
== CardType
)) {
889 if (SDIO_BusWide_8b
== WideMode
) {
890 errorstatus
= SD_UNSUPPORTED_FEATURE
;
893 else if (SDIO_BusWide_4b
== WideMode
) {
894 errorstatus
= SDEnWideBus(ENABLE
);
896 if (SD_OK
== errorstatus
) {
897 /*!< Configure the SDIO peripheral */
898 SDIO_InitStructure
.SDIO_ClockDiv
= SD_SDIO_TRANSFER_CLK_DIV
;
899 SDIO_InitStructure
.SDIO_ClockEdge
= SDIO_ClockEdge_Rising
;
900 SDIO_InitStructure
.SDIO_ClockBypass
= SDIO_ClockBypass_Disable
;
901 SDIO_InitStructure
.SDIO_ClockPowerSave
= SDIO_ClockPowerSave_Disable
;
902 SDIO_InitStructure
.SDIO_BusWide
= SDIO_BusWide_4b
;
903 SDIO_InitStructure
.SDIO_HardwareFlowControl
= SDIO_HardwareFlowControl_Disable
;
904 SDIO_Init(&SDIO_InitStructure
);
908 errorstatus
= SDEnWideBus(DISABLE
);
910 if (SD_OK
== errorstatus
) {
911 /*!< Configure the SDIO peripheral */
912 SDIO_InitStructure
.SDIO_ClockDiv
= SD_SDIO_TRANSFER_CLK_DIV
;
913 SDIO_InitStructure
.SDIO_ClockEdge
= SDIO_ClockEdge_Rising
;
914 SDIO_InitStructure
.SDIO_ClockBypass
= SDIO_ClockBypass_Disable
;
915 SDIO_InitStructure
.SDIO_ClockPowerSave
= SDIO_ClockPowerSave_Disable
;
916 SDIO_InitStructure
.SDIO_BusWide
= SDIO_BusWide_1b
;
917 SDIO_InitStructure
.SDIO_HardwareFlowControl
= SDIO_HardwareFlowControl_Disable
;
918 SDIO_Init(&SDIO_InitStructure
);
927 * @brief Selects od Deselects the corresponding card.
928 * @param addr: Address of the Card to be selected.
929 * @retval SD_Error: SD Card Error code.
931 OPTIMIZE("O0") SD_Error
SD_SelectDeselect(uint32_t addr
)
933 SD_Error errorstatus
;
935 /*!< Send CMD7 SDIO_SEL_DESEL_CARD */
936 SDIO_CmdInitStructure
.SDIO_Argument
= addr
;
937 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SEL_DESEL_CARD
;
938 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
939 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
940 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
941 SDIO_SendCommand(&SDIO_CmdInitStructure
);
943 errorstatus
= CmdResp1Error(SD_CMD_SEL_DESEL_CARD
);
949 * @brief Allows to read one block from a specified address in a card. The Data
950 * transfer can be managed by DMA mode or Polling mode.
951 * @note This operation should be followed by two functions to check if the
952 * DMA Controller and SD Card status.
953 * - SD_ReadWaitOperation(): this function insure that the DMA
954 * controller has finished all data transfer.
955 * - SD_GetStatus(): to check that the SD Card has finished the
956 * data transfer and it is ready for data.
957 * @param readbuff: pointer to the buffer that will contain the received data
958 * @param ReadAddr: Address from where data are to be read.
959 * @param BlockSize: the SD card Data block size. The Block size should be 512.
960 * @retval SD_Error: SD Card Error code.
962 OPTIMIZE("O0") SD_Error
SD_ReadBlock(uint8_t *readbuff
, uint32_t ReadAddr
, uint16_t BlockSize
)
964 SD_Error errorstatus
= SD_OK
;
966 TransferError
= SD_OK
;
969 DMAEndOfTransfer
= 0;
973 SDIO_ITConfig(SDIO_IT_DCRCFAIL
| SDIO_IT_DTIMEOUT
| SDIO_IT_DATAEND
| SDIO_IT_RXOVERR
| SDIO_IT_STBITERR
, ENABLE
);
975 SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff
, BlockSize
);
977 if (CardType
== SDIO_HIGH_CAPACITY_SD_CARD
)
982 /* Set Block Size for Card */
983 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t) BlockSize
;
984 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SET_BLOCKLEN
;
985 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
986 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
987 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
988 SDIO_SendCommand(&SDIO_CmdInitStructure
);
990 errorstatus
= CmdResp1Error(SD_CMD_SET_BLOCKLEN
);
992 if (SD_OK
!= errorstatus
) {
996 SDIO_DataInitStructure
.SDIO_DataTimeOut
= SD_DATATIMEOUT
;
997 SDIO_DataInitStructure
.SDIO_DataLength
= BlockSize
;
998 SDIO_DataInitStructure
.SDIO_DataBlockSize
= SDIO_DataBlockSize_512b
;
999 SDIO_DataInitStructure
.SDIO_TransferDir
= SDIO_TransferDir_ToSDIO
;
1000 SDIO_DataInitStructure
.SDIO_TransferMode
= SDIO_TransferMode_Block
;
1001 SDIO_DataInitStructure
.SDIO_DPSM
= SDIO_DPSM_Enable
;
1002 SDIO_DataConfig(&SDIO_DataInitStructure
);
1004 /*!< Send CMD17 READ_SINGLE_BLOCK */
1005 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t)ReadAddr
;
1006 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_READ_SINGLE_BLOCK
;
1007 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1008 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1009 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1010 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1012 errorstatus
= CmdResp1Error(SD_CMD_READ_SINGLE_BLOCK
);
1014 if (errorstatus
!= SD_OK
) {
1022 * @brief Allows to read blocks from a specified address in a card. The Data
1023 * transfer can be managed by DMA mode or Polling mode.
1024 * @note This operation should be followed by two functions to check if the
1025 * DMA Controller and SD Card status.
1026 * - SD_ReadWaitOperation(): this function insure that the DMA
1027 * controller has finished all data transfer.
1028 * - SD_GetStatus(): to check that the SD Card has finished the
1029 * data transfer and it is ready for data.
1030 * @param readbuff: pointer to the buffer that will contain the received data.
1031 * @param ReadAddr: Address from where data are to be read.
1032 * @param BlockSize: the SD card Data block size. The Block size should be 512.
1033 * @param NumberOfBlocks: number of blocks to be read.
1034 * @retval SD_Error: SD Card Error code.
1036 OPTIMIZE("O0") SD_Error
SD_ReadMultiBlocks(uint8_t *readbuff
, uint32_t ReadAddr
, uint16_t BlockSize
, uint32_t NumberOfBlocks
)
1038 SD_Error errorstatus
= SD_OK
;
1039 TransferError
= SD_OK
;
1042 DMAEndOfTransfer
= 0;
1046 SDIO_ITConfig(SDIO_IT_DCRCFAIL
| SDIO_IT_DTIMEOUT
| SDIO_IT_DATAEND
| SDIO_IT_RXOVERR
| SDIO_IT_STBITERR
, ENABLE
);
1047 SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff
, (NumberOfBlocks
* BlockSize
));
1048 SDIO_DMACmd(ENABLE
);
1050 if (CardType
== SDIO_HIGH_CAPACITY_SD_CARD
)
1055 /*!< Set Block Size for Card */
1056 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t) BlockSize
;
1057 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SET_BLOCKLEN
;
1058 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1059 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1060 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1061 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1063 errorstatus
= CmdResp1Error(SD_CMD_SET_BLOCKLEN
);
1065 if (SD_OK
!= errorstatus
) {
1069 SDIO_DataInitStructure
.SDIO_DataTimeOut
= SD_DATATIMEOUT
* NumberOfBlocks
;
1070 SDIO_DataInitStructure
.SDIO_DataLength
= NumberOfBlocks
* BlockSize
;
1071 SDIO_DataInitStructure
.SDIO_DataBlockSize
= SDIO_DataBlockSize_512b
;
1072 SDIO_DataInitStructure
.SDIO_TransferDir
= SDIO_TransferDir_ToSDIO
;
1073 SDIO_DataInitStructure
.SDIO_TransferMode
= SDIO_TransferMode_Block
;
1074 SDIO_DataInitStructure
.SDIO_DPSM
= SDIO_DPSM_Enable
;
1075 SDIO_DataConfig(&SDIO_DataInitStructure
);
1077 /*!< Send CMD18 READ_MULT_BLOCK with argument data address */
1078 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t)ReadAddr
;
1079 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_READ_MULT_BLOCK
;
1080 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1081 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1082 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1083 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1085 errorstatus
= CmdResp1Error(SD_CMD_READ_MULT_BLOCK
);
1087 if (errorstatus
!= SD_OK
) {
1095 * @brief This function waits until the SDIO DMA data transfer is finished.
1096 * This function should be called after SDIO_ReadMultiBlocks() function
1097 * to insure that all data sent by the card are already transferred by
1098 * the DMA controller.
1100 * @retval SD_Error: SD Card Error code.
1102 OPTIMIZE("O0") SD_Error
SD_WaitReadOperation(uint32_t timeout
)
1104 SD_Error errorstatus
= SD_OK
;
1106 while (!DMAEndOfTransfer
&& !TransferEnd
&& (TransferError
== SD_OK
) && (timeout
> 0)) {
1110 TRACE_SD_CARD_EVENT((timeout
== 0), sd_wait_read
, (TransferError
<< 8) + (DMAEndOfTransfer
<< 1) + TransferEnd
);
1112 DMAEndOfTransfer
= 0;
1116 while(((SDIO
->STA
& SDIO_FLAG_RXACT
)) && (timeout
> 0)) {
1120 TRACE_SD_CARD_EVENT((timeout
== 0), sd_wait_read
, -1);
1122 if (StopCondition
== 1) {
1123 errorstatus
= SD_StopTransfer();
1127 if ((timeout
== 0) && (errorstatus
== SD_OK
)) {
1128 errorstatus
= SD_DATA_TIMEOUT
;
1131 /*!< Clear all the static flags */
1132 SDIO_ClearFlag(SDIO_STATIC_FLAGS
);
1134 if (TransferError
!= SD_OK
) {
1135 return TransferError
;
1143 * @brief Allows to write one block starting from a specified address in a card.
1144 * The Data transfer can be managed by DMA mode or Polling mode.
1145 * @note This operation should be followed by two functions to check if the
1146 * DMA Controller and SD Card status.
1147 * - SD_ReadWaitOperation(): this function insure that the DMA
1148 * controller has finished all data transfer.
1149 * - SD_GetStatus(): to check that the SD Card has finished the
1150 * data transfer and it is ready for data.
1151 * @param writebuff: pointer to the buffer that contain the data to be transferred.
1152 * @param WriteAddr: Address from where data are to be read.
1153 * @param BlockSize: the SD card Data block size. The Block size should be 512.
1154 * @retval SD_Error: SD Card Error code.
1156 OPTIMIZE("O0") SD_Error
SD_WriteBlock(uint8_t *writebuff
, uint32_t WriteAddr
, uint16_t BlockSize
)
1158 SD_Error errorstatus
= SD_OK
;
1160 TransferError
= SD_OK
;
1166 SDIO_ITConfig(SDIO_IT_DCRCFAIL
| SDIO_IT_DTIMEOUT
| SDIO_IT_DATAEND
| SDIO_IT_RXOVERR
| SDIO_IT_STBITERR
, ENABLE
);
1167 SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff
, BlockSize
);
1168 SDIO_DMACmd(ENABLE
);
1170 if (CardType
== SDIO_HIGH_CAPACITY_SD_CARD
)
1175 /* Set Block Size for Card */
1176 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t) BlockSize
;
1177 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SET_BLOCKLEN
;
1178 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1179 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1180 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1181 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1183 errorstatus
= CmdResp1Error(SD_CMD_SET_BLOCKLEN
);
1185 if (SD_OK
!= errorstatus
) {
1189 /*!< Send CMD24 WRITE_SINGLE_BLOCK */
1190 SDIO_CmdInitStructure
.SDIO_Argument
= WriteAddr
;
1191 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_WRITE_SINGLE_BLOCK
;
1192 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1193 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1194 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1195 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1197 errorstatus
= CmdResp1Error(SD_CMD_WRITE_SINGLE_BLOCK
);
1199 if (errorstatus
!= SD_OK
) {
1203 SDIO_DataInitStructure
.SDIO_DataTimeOut
= SD_DATATIMEOUT
;
1204 SDIO_DataInitStructure
.SDIO_DataLength
= BlockSize
;
1205 SDIO_DataInitStructure
.SDIO_DataBlockSize
= SDIO_DataBlockSize_512b
;
1206 SDIO_DataInitStructure
.SDIO_TransferDir
= SDIO_TransferDir_ToCard
;
1207 SDIO_DataInitStructure
.SDIO_TransferMode
= SDIO_TransferMode_Block
;
1208 SDIO_DataInitStructure
.SDIO_DPSM
= SDIO_DPSM_Enable
;
1209 SDIO_DataConfig(&SDIO_DataInitStructure
);
1215 * @brief Allows to write blocks starting from a specified address in a card.
1216 * The Data transfer can be managed by DMA mode only.
1217 * @note This operation should be followed by two functions to check if the
1218 * DMA Controller and SD Card status.
1219 * - SD_ReadWaitOperation(): this function insure that the DMA
1220 * controller has finished all data transfer.
1221 * - SD_GetStatus(): to check that the SD Card has finished the
1222 * data transfer and it is ready for data.
1223 * @param WriteAddr: Address from where data are to be read.
1224 * @param writebuff: pointer to the buffer that contain the data to be transferred.
1225 * @param BlockSize: the SD card Data block size. The Block size should be 512.
1226 * @param NumberOfBlocks: number of blocks to be written.
1227 * @retval SD_Error: SD Card Error code.
1229 OPTIMIZE("O0") SD_Error
SD_WriteMultiBlocks(uint8_t *writebuff
, uint32_t WriteAddr
, uint16_t BlockSize
, uint32_t NumberOfBlocks
)
1231 SD_Error errorstatus
= SD_OK
;
1233 TransferError
= SD_OK
;
1239 SDIO_ITConfig(SDIO_IT_DCRCFAIL
| SDIO_IT_DTIMEOUT
| SDIO_IT_DATAEND
| SDIO_IT_TXUNDERR
| SDIO_IT_STBITERR
, ENABLE
);
1240 SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff
, (NumberOfBlocks
* BlockSize
));
1241 SDIO_DMACmd(ENABLE
);
1243 if (CardType
== SDIO_HIGH_CAPACITY_SD_CARD
) {
1250 /* Set Block Size for Card */
1251 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t) BlockSize
;
1252 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SET_BLOCKLEN
;
1253 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1254 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1255 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1256 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1258 errorstatus
= CmdResp1Error(SD_CMD_SET_BLOCKLEN
);
1260 if (SD_OK
!= errorstatus
) {
1264 /*!< To improve performance */
1265 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t) (RCA
<< 16);
1266 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_APP_CMD
;
1267 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1268 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1269 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1270 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1273 errorstatus
= CmdResp1Error(SD_CMD_APP_CMD
);
1275 if (errorstatus
!= SD_OK
) {
1278 /*!< To improve performance */
1279 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t)NumberOfBlocks
;
1280 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SET_BLOCK_COUNT
;
1281 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1282 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1283 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1284 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1286 errorstatus
= CmdResp1Error(SD_CMD_SET_BLOCK_COUNT
);
1288 if (errorstatus
!= SD_OK
) {
1293 /*!< Send CMD25 WRITE_MULT_BLOCK with argument data address */
1294 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t)WriteAddr
;
1295 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_WRITE_MULT_BLOCK
;
1296 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1297 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1298 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1299 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1301 errorstatus
= CmdResp1Error(SD_CMD_WRITE_MULT_BLOCK
);
1303 if (SD_OK
!= errorstatus
) {
1307 SDIO_DataInitStructure
.SDIO_DataTimeOut
= SD_DATATIMEOUT
* NumberOfBlocks
;
1308 SDIO_DataInitStructure
.SDIO_DataLength
= NumberOfBlocks
* BlockSize
;
1309 SDIO_DataInitStructure
.SDIO_DataBlockSize
= SDIO_DataBlockSize_512b
;
1310 SDIO_DataInitStructure
.SDIO_TransferDir
= SDIO_TransferDir_ToCard
;
1311 SDIO_DataInitStructure
.SDIO_TransferMode
= SDIO_TransferMode_Block
;
1312 SDIO_DataInitStructure
.SDIO_DPSM
= SDIO_DPSM_Enable
;
1313 SDIO_DataConfig(&SDIO_DataInitStructure
);
1320 * @brief This function waits until the SDIO DMA data transfer is finished.
1321 * This function should be called after SDIO_WriteBlock() and
1322 * SDIO_WriteMultiBlocks() function to insure that all data sent by the
1323 * card are already transferred by the DMA controller.
1325 * @retval SD_Error: SD Card Error code.
1327 OPTIMIZE("O0") SD_Error
SD_WaitWriteOperation(uint32_t timeout
)
1329 SD_Error errorstatus
= SD_OK
;
1331 while (!DMAEndOfTransfer
&& !TransferEnd
&& (TransferError
== SD_OK
) && (timeout
> 0)) {
1335 TRACE_SD_CARD_EVENT((timeout
== 0), sd_wait_write
, (TransferError
<< 8) + (DMAEndOfTransfer
<< 1) + TransferEnd
);
1337 DMAEndOfTransfer
= 0;
1341 while(((SDIO
->STA
& SDIO_FLAG_TXACT
)) && (timeout
> 0)) {
1345 TRACE_SD_CARD_EVENT((timeout
== 0), sd_wait_write
, -1);
1347 if (StopCondition
== 1) {
1348 errorstatus
= SD_StopTransfer();
1352 if ((timeout
== 0) && (errorstatus
== SD_OK
)) {
1353 errorstatus
= SD_DATA_TIMEOUT
;
1356 /*!< Clear all the static flags */
1357 SDIO_ClearFlag(SDIO_STATIC_FLAGS
);
1359 if (TransferError
!= SD_OK
) {
1360 return TransferError
;
1368 * @brief Gets the cuurent data transfer state.
1370 * @retval SDTransferState: Data Transfer state.
1371 * This value can be:
1372 * - SD_TRANSFER_OK: No data transfer is acting
1373 * - SD_TRANSFER_BUSY: Data transfer is acting
1375 OPTIMIZE("O0") SDTransferState
SD_GetTransferState(void)
1377 if (SDIO
->STA
& (SDIO_FLAG_TXACT
| SDIO_FLAG_RXACT
)) {
1378 return SD_TRANSFER_BUSY
;
1381 return SD_TRANSFER_OK
;
1386 * @brief Aborts an ongoing data transfer.
1388 * @retval SD_Error: SD Card Error code.
1390 OPTIMIZE("O0") SD_Error
SD_StopTransfer(void)
1392 SD_Error errorstatus
= SD_OK
;
1394 /*!< Send CMD12 STOP_TRANSMISSION */
1395 SDIO_CmdInitStructure
.SDIO_Argument
= 0x0;
1396 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_STOP_TRANSMISSION
;
1397 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1398 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1399 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1400 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1402 errorstatus
= CmdResp1Error(SD_CMD_STOP_TRANSMISSION
);
1408 * @brief Returns the current card's status.
1409 * @param pcardstatus: pointer to the buffer that will contain the SD card
1410 * status (Card Status register).
1411 * @retval SD_Error: SD Card Error code.
1413 OPTIMIZE("O0") SD_Error
SD_SendStatus(uint32_t *pcardstatus
)
1415 SD_Error errorstatus
= SD_OK
;
1417 if (pcardstatus
== NULL
) {
1418 errorstatus
= SD_INVALID_PARAMETER
;
1422 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t) RCA
<< 16;
1423 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SEND_STATUS
;
1424 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1425 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1426 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1427 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1429 errorstatus
= CmdResp1Error(SD_CMD_SEND_STATUS
);
1431 if (errorstatus
!= SD_OK
) {
1435 *pcardstatus
= SDIO_GetResponse(SDIO_RESP1
);
1441 * @brief Allows to process all the interrupts that are high.
1443 * @retval SD_Error: SD Card Error code.
1445 OPTIMIZE("O0") void SD_ProcessIRQ(void)
1447 if (SDIO_GetITStatus(SDIO_IT_DATAEND
) != RESET
) {
1448 TransferError
= SD_OK
;
1449 SDIO_ClearITPendingBit(SDIO_IT_DATAEND
);
1452 else if (SDIO_GetITStatus(SDIO_IT_DCRCFAIL
) != RESET
) {
1453 SDIO_ClearITPendingBit(SDIO_IT_DCRCFAIL
);
1454 TransferError
= SD_DATA_CRC_FAIL
;
1456 else if (SDIO_GetITStatus(SDIO_IT_DTIMEOUT
) != RESET
) {
1457 SDIO_ClearITPendingBit(SDIO_IT_DTIMEOUT
);
1458 TransferError
= SD_DATA_TIMEOUT
;
1460 else if (SDIO_GetITStatus(SDIO_IT_RXOVERR
) != RESET
) {
1461 SDIO_ClearITPendingBit(SDIO_IT_RXOVERR
);
1462 TransferError
= SD_RX_OVERRUN
;
1464 else if (SDIO_GetITStatus(SDIO_IT_TXUNDERR
) != RESET
) {
1465 SDIO_ClearITPendingBit(SDIO_IT_TXUNDERR
);
1466 TransferError
= SD_TX_UNDERRUN
;
1468 else if (SDIO_GetITStatus(SDIO_IT_STBITERR
) != RESET
) {
1469 SDIO_ClearITPendingBit(SDIO_IT_STBITERR
);
1470 TransferError
= SD_START_BIT_ERR
;
1473 SDIO_ITConfig(SDIO_IT_DCRCFAIL
| SDIO_IT_DTIMEOUT
| SDIO_IT_DATAEND
|
1474 SDIO_IT_TXFIFOHE
| SDIO_IT_RXFIFOHF
| SDIO_IT_TXUNDERR
|
1475 SDIO_IT_RXOVERR
| SDIO_IT_STBITERR
, DISABLE
);
1477 TRACE_SD_CARD_EVENT((TransferError
!= SD_OK
), sd_irq
, TransferError
);
1481 * @brief This function waits until the SDIO DMA data transfer is finished.
1485 OPTIMIZE("O0") void SD_ProcessDMAIRQ(void)
1487 if (DMA2
->LISR
& SD_SDIO_DMA_FLAG_TCIF
) {
1488 DMAEndOfTransfer
= 1;
1489 DMA_ClearFlag(SD_SDIO_DMA_STREAM
, SD_SDIO_DMA_FLAG_TCIF
|SD_SDIO_DMA_FLAG_FEIF
);
1494 * @brief Checks for error conditions for CMD0.
1496 * @retval SD_Error: SD Card Error code.
1498 OPTIMIZE("O0") static SD_Error
CmdError(void)
1500 SD_Error errorstatus
= SD_OK
;
1503 timeout
= SDIO_CMD0TIMEOUT
; /*!< 10000 */
1505 while ((timeout
> 0) && (SDIO_GetFlagStatus(SDIO_FLAG_CMDSENT
) == RESET
)) {
1510 errorstatus
= SD_CMD_RSP_TIMEOUT
;
1514 /*!< Clear all the static flags */
1515 SDIO_ClearFlag(SDIO_STATIC_FLAGS
);
1521 * @brief Checks for error conditions for R7 response.
1523 * @retval SD_Error: SD Card Error code.
1525 OPTIMIZE("O0") static SD_Error
CmdResp7Error(void)
1527 SD_Error errorstatus
= SD_OK
;
1529 uint32_t timeout
= SDIO_CMD0TIMEOUT
;
1533 while (!(status
& (SDIO_FLAG_CCRCFAIL
| SDIO_FLAG_CMDREND
| SDIO_FLAG_CTIMEOUT
)) && (timeout
> 0)) {
1538 if ((timeout
== 0) || (status
& SDIO_FLAG_CTIMEOUT
)) {
1539 /*!< Card is not V2.0 complient or card does not support the set voltage range */
1540 errorstatus
= SD_CMD_RSP_TIMEOUT
;
1541 SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT
);
1545 if (status
& SDIO_FLAG_CMDREND
) {
1546 /*!< Card is SD V2.0 compliant */
1547 errorstatus
= SD_OK
;
1548 SDIO_ClearFlag(SDIO_FLAG_CMDREND
);
1555 * @brief Checks for error conditions for R1 response.
1556 * @param cmd: The sent command index.
1557 * @retval SD_Error: SD Card Error code.
1559 OPTIMIZE("O0") static SD_Error
CmdResp1Error(uint8_t cmd
)
1561 SD_Error errorstatus
= SD_OK
;
1563 uint32_t response_r1
;
1567 while (!(status
& (SDIO_FLAG_CCRCFAIL
| SDIO_FLAG_CMDREND
| SDIO_FLAG_CTIMEOUT
))) {
1571 if (status
& SDIO_FLAG_CTIMEOUT
) {
1572 errorstatus
= SD_CMD_RSP_TIMEOUT
;
1573 SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT
);
1576 else if (status
& SDIO_FLAG_CCRCFAIL
) {
1577 errorstatus
= SD_CMD_CRC_FAIL
;
1578 SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL
);
1582 /*!< Check response received is of desired command */
1583 if (SDIO_GetCommandResponse() != cmd
) {
1584 errorstatus
= SD_ILLEGAL_CMD
;
1588 /*!< Clear all the static flags */
1589 SDIO_ClearFlag(SDIO_STATIC_FLAGS
);
1591 /*!< We have received response, retrieve it for analysis */
1592 response_r1
= SDIO_GetResponse(SDIO_RESP1
);
1594 if ((response_r1
& SD_OCR_ERRORBITS
) == SD_ALLZERO
) {
1598 if (response_r1
& SD_OCR_ADDR_OUT_OF_RANGE
) {
1599 return SD_ADDR_OUT_OF_RANGE
;
1602 if (response_r1
& SD_OCR_ADDR_MISALIGNED
) {
1603 return SD_ADDR_MISALIGNED
;
1606 if (response_r1
& SD_OCR_BLOCK_LEN_ERR
) {
1607 return SD_BLOCK_LEN_ERR
;
1610 if (response_r1
& SD_OCR_ERASE_SEQ_ERR
) {
1611 return SD_ERASE_SEQ_ERR
;
1614 if (response_r1
& SD_OCR_BAD_ERASE_PARAM
) {
1615 return SD_BAD_ERASE_PARAM
;
1618 if (response_r1
& SD_OCR_WRITE_PROT_VIOLATION
) {
1619 return SD_WRITE_PROT_VIOLATION
;
1622 if (response_r1
& SD_OCR_LOCK_UNLOCK_FAILED
) {
1623 return SD_LOCK_UNLOCK_FAILED
;
1626 if (response_r1
& SD_OCR_COM_CRC_FAILED
) {
1627 return SD_COM_CRC_FAILED
;
1630 if (response_r1
& SD_OCR_ILLEGAL_CMD
) {
1631 return SD_ILLEGAL_CMD
;
1634 if (response_r1
& SD_OCR_CARD_ECC_FAILED
) {
1635 return SD_CARD_ECC_FAILED
;
1638 if (response_r1
& SD_OCR_CC_ERROR
) {
1642 if (response_r1
& SD_OCR_GENERAL_UNKNOWN_ERROR
) {
1643 return SD_GENERAL_UNKNOWN_ERROR
;
1646 if (response_r1
& SD_OCR_STREAM_READ_UNDERRUN
) {
1647 return SD_STREAM_READ_UNDERRUN
;
1650 if (response_r1
& SD_OCR_STREAM_WRITE_OVERRUN
) {
1651 return SD_STREAM_WRITE_OVERRUN
;
1654 if (response_r1
& SD_OCR_CID_CSD_OVERWRIETE
) {
1655 return SD_CID_CSD_OVERWRITE
;
1658 if (response_r1
& SD_OCR_WP_ERASE_SKIP
) {
1659 return SD_WP_ERASE_SKIP
;
1662 if (response_r1
& SD_OCR_CARD_ECC_DISABLED
) {
1663 return SD_CARD_ECC_DISABLED
;
1666 if (response_r1
& SD_OCR_ERASE_RESET
) {
1667 return SD_ERASE_RESET
;
1670 if (response_r1
& SD_OCR_AKE_SEQ_ERROR
) {
1671 return SD_AKE_SEQ_ERROR
;
1678 * @brief Checks for error conditions for R3 (OCR) response.
1680 * @retval SD_Error: SD Card Error code.
1682 OPTIMIZE("O0") static SD_Error
CmdResp3Error(void)
1684 SD_Error errorstatus
= SD_OK
;
1689 while (!(status
& (SDIO_FLAG_CCRCFAIL
| SDIO_FLAG_CMDREND
| SDIO_FLAG_CTIMEOUT
))) {
1693 if (status
& SDIO_FLAG_CTIMEOUT
) {
1694 errorstatus
= SD_CMD_RSP_TIMEOUT
;
1695 SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT
);
1698 /*!< Clear all the static flags */
1699 SDIO_ClearFlag(SDIO_STATIC_FLAGS
);
1704 * @brief Checks for error conditions for R2 (CID or CSD) response.
1706 * @retval SD_Error: SD Card Error code.
1708 OPTIMIZE("O0") static SD_Error
CmdResp2Error(void)
1710 SD_Error errorstatus
= SD_OK
;
1715 while (!(status
& (SDIO_FLAG_CCRCFAIL
| SDIO_FLAG_CTIMEOUT
| SDIO_FLAG_CMDREND
))) {
1719 if (status
& SDIO_FLAG_CTIMEOUT
) {
1720 errorstatus
= SD_CMD_RSP_TIMEOUT
;
1721 SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT
);
1724 else if (status
& SDIO_FLAG_CCRCFAIL
) {
1725 errorstatus
= SD_CMD_CRC_FAIL
;
1726 SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL
);
1730 /*!< Clear all the static flags */
1731 SDIO_ClearFlag(SDIO_STATIC_FLAGS
);
1737 * @brief Checks for error conditions for R6 (RCA) response.
1738 * @param cmd: The sent command index.
1739 * @param prca: pointer to the variable that will contain the SD card relative
1741 * @retval SD_Error: SD Card Error code.
1743 OPTIMIZE("O0") static SD_Error
CmdResp6Error(uint8_t cmd
, uint16_t *prca
)
1745 SD_Error errorstatus
= SD_OK
;
1747 uint32_t response_r1
;
1751 while (!(status
& (SDIO_FLAG_CCRCFAIL
| SDIO_FLAG_CTIMEOUT
| SDIO_FLAG_CMDREND
))) {
1755 if (status
& SDIO_FLAG_CTIMEOUT
) {
1756 errorstatus
= SD_CMD_RSP_TIMEOUT
;
1757 SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT
);
1760 else if (status
& SDIO_FLAG_CCRCFAIL
) {
1761 errorstatus
= SD_CMD_CRC_FAIL
;
1762 SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL
);
1766 /*!< Check response received is of desired command */
1767 if (SDIO_GetCommandResponse() != cmd
) {
1768 errorstatus
= SD_ILLEGAL_CMD
;
1772 /*!< Clear all the static flags */
1773 SDIO_ClearFlag(SDIO_STATIC_FLAGS
);
1775 /*!< We have received response, retrieve it. */
1776 response_r1
= SDIO_GetResponse(SDIO_RESP1
);
1778 if (SD_ALLZERO
== (response_r1
& (SD_R6_GENERAL_UNKNOWN_ERROR
| SD_R6_ILLEGAL_CMD
| SD_R6_COM_CRC_FAILED
))) {
1779 *prca
= (uint16_t) (response_r1
>> 16);
1783 if (response_r1
& SD_R6_GENERAL_UNKNOWN_ERROR
) {
1784 return SD_GENERAL_UNKNOWN_ERROR
;
1787 if (response_r1
& SD_R6_ILLEGAL_CMD
) {
1788 return SD_ILLEGAL_CMD
;
1791 if (response_r1
& SD_R6_COM_CRC_FAILED
) {
1792 return SD_COM_CRC_FAILED
;
1799 * @brief Enables or disables the SDIO wide bus mode.
1800 * @param NewState: new state of the SDIO wide bus mode.
1801 * This parameter can be: ENABLE or DISABLE.
1802 * @retval SD_Error: SD Card Error code.
1804 OPTIMIZE("O0") static SD_Error
SDEnWideBus(FunctionalState NewState
)
1806 SD_Error errorstatus
= SD_OK
;
1808 uint32_t scr
[2] = {0, 0};
1810 if (SDIO_GetResponse(SDIO_RESP1
) & SD_CARD_LOCKED
) {
1811 errorstatus
= SD_LOCK_UNLOCK_FAILED
;
1815 /*!< Get SCR Register */
1816 errorstatus
= FindSCR(RCA
, scr
);
1818 if (errorstatus
!= SD_OK
) {
1822 /*!< If wide bus operation to be enabled */
1823 if (NewState
== ENABLE
) {
1824 /*!< If requested card supports wide bus operation */
1825 if ((scr
[1] & SD_WIDE_BUS_SUPPORT
) != SD_ALLZERO
) {
1826 /*!< Send CMD55 APP_CMD with argument as card's RCA.*/
1827 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t) RCA
<< 16;
1828 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_APP_CMD
;
1829 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1830 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1831 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1832 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1834 errorstatus
= CmdResp1Error(SD_CMD_APP_CMD
);
1836 if (errorstatus
!= SD_OK
) {
1840 /*!< Send ACMD6 APP_CMD with argument as 2 for wide bus mode */
1841 SDIO_CmdInitStructure
.SDIO_Argument
= 0x2;
1842 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_APP_SD_SET_BUSWIDTH
;
1843 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1844 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1845 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1846 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1848 errorstatus
= CmdResp1Error(SD_CMD_APP_SD_SET_BUSWIDTH
);
1850 if (errorstatus
!= SD_OK
) {
1856 errorstatus
= SD_REQUEST_NOT_APPLICABLE
;
1859 } /*!< If wide bus operation to be disabled */
1861 /*!< If requested card supports 1 bit mode operation */
1862 if ((scr
[1] & SD_SINGLE_BUS_SUPPORT
) != SD_ALLZERO
) {
1863 /*!< Send CMD55 APP_CMD with argument as card's RCA.*/
1864 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t) RCA
<< 16;
1865 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_APP_CMD
;
1866 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1867 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1868 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1869 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1872 errorstatus
= CmdResp1Error(SD_CMD_APP_CMD
);
1874 if (errorstatus
!= SD_OK
) {
1878 /*!< Send ACMD6 APP_CMD with argument as 2 for wide bus mode */
1879 SDIO_CmdInitStructure
.SDIO_Argument
= 0x00;
1880 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_APP_SD_SET_BUSWIDTH
;
1881 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1882 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1883 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1884 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1886 errorstatus
= CmdResp1Error(SD_CMD_APP_SD_SET_BUSWIDTH
);
1888 if (errorstatus
!= SD_OK
) {
1895 errorstatus
= SD_REQUEST_NOT_APPLICABLE
;
1902 * @brief Find the SD card SCR register value.
1903 * @param rca: selected card address.
1904 * @param pscr: pointer to the buffer that will contain the SCR value.
1905 * @retval SD_Error: SD Card Error code.
1907 OPTIMIZE("O0") static SD_Error
FindSCR(uint16_t rca
, uint32_t *pscr
)
1910 SD_Error errorstatus
= SD_OK
;
1911 uint32_t tempscr
[2] = {0, 0};
1913 /*!< Set Block Size To 8 Bytes */
1914 /*!< Send CMD55 APP_CMD with argument as card's RCA */
1915 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t)8;
1916 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SET_BLOCKLEN
;
1917 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1918 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1919 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1920 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1922 errorstatus
= CmdResp1Error(SD_CMD_SET_BLOCKLEN
);
1924 if (errorstatus
!= SD_OK
) {
1928 /*!< Send CMD55 APP_CMD with argument as card's RCA */
1929 SDIO_CmdInitStructure
.SDIO_Argument
= (uint32_t) RCA
<< 16;
1930 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_APP_CMD
;
1931 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1932 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1933 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1934 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1936 errorstatus
= CmdResp1Error(SD_CMD_APP_CMD
);
1938 if (errorstatus
!= SD_OK
) {
1941 SDIO_DataInitStructure
.SDIO_DataTimeOut
= SD_DATATIMEOUT
;
1942 SDIO_DataInitStructure
.SDIO_DataLength
= 8;
1943 SDIO_DataInitStructure
.SDIO_DataBlockSize
= SDIO_DataBlockSize_8b
;
1944 SDIO_DataInitStructure
.SDIO_TransferDir
= SDIO_TransferDir_ToSDIO
;
1945 SDIO_DataInitStructure
.SDIO_TransferMode
= SDIO_TransferMode_Block
;
1946 SDIO_DataInitStructure
.SDIO_DPSM
= SDIO_DPSM_Enable
;
1947 SDIO_DataConfig(&SDIO_DataInitStructure
);
1950 /*!< Send ACMD51 SD_APP_SEND_SCR with argument as 0 */
1951 SDIO_CmdInitStructure
.SDIO_Argument
= 0x0;
1952 SDIO_CmdInitStructure
.SDIO_CmdIndex
= SD_CMD_SD_APP_SEND_SCR
;
1953 SDIO_CmdInitStructure
.SDIO_Response
= SDIO_Response_Short
;
1954 SDIO_CmdInitStructure
.SDIO_Wait
= SDIO_Wait_No
;
1955 SDIO_CmdInitStructure
.SDIO_CPSM
= SDIO_CPSM_Enable
;
1956 SDIO_SendCommand(&SDIO_CmdInitStructure
);
1958 errorstatus
= CmdResp1Error(SD_CMD_SD_APP_SEND_SCR
);
1960 if (errorstatus
!= SD_OK
) {
1964 while (!(SDIO
->STA
& (SDIO_FLAG_RXOVERR
| SDIO_FLAG_DCRCFAIL
| SDIO_FLAG_DTIMEOUT
| SDIO_FLAG_DBCKEND
| SDIO_FLAG_STBITERR
))) {
1965 if (SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL
) != RESET
) {
1966 *(tempscr
+ index
) = SDIO_ReadData();
1971 if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT
) != RESET
) {
1972 SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT
);
1973 errorstatus
= SD_DATA_TIMEOUT
;
1976 else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL
) != RESET
) {
1977 SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL
);
1978 errorstatus
= SD_DATA_CRC_FAIL
;
1981 else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR
) != RESET
) {
1982 SDIO_ClearFlag(SDIO_FLAG_RXOVERR
);
1983 errorstatus
= SD_RX_OVERRUN
;
1986 else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR
) != RESET
) {
1987 SDIO_ClearFlag(SDIO_FLAG_STBITERR
);
1988 errorstatus
= SD_START_BIT_ERR
;
1992 /*!< Clear all the static flags */
1993 SDIO_ClearFlag(SDIO_STATIC_FLAGS
);
1995 *(pscr
+ 1) = ((tempscr
[0] & SD_0TO7BITS
) << 24) | ((tempscr
[0] & SD_8TO15BITS
) << 8) | ((tempscr
[0] & SD_16TO23BITS
) >> 8) | ((tempscr
[0] & SD_24TO31BITS
) >> 24);
1997 *(pscr
) = ((tempscr
[1] & SD_0TO7BITS
) << 24) | ((tempscr
[1] & SD_8TO15BITS
) << 8) | ((tempscr
[1] & SD_16TO23BITS
) >> 8) | ((tempscr
[1] & SD_24TO31BITS
) >> 24);
2002 void SDIO_IRQHandler(void)
2004 DEBUG_INTERRUPT(INT_SDIO
);
2008 void SD_SDIO_DMA_IRQHANDLER(void)
2010 DEBUG_INTERRUPT(INT_SDIO_DMA
);
2014 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/