2 ******************************************************************************
3 * @file stm32f4xx_hal_sd.h
4 * @author MCD Application Team
7 * @brief Header file of SD HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_SD_H
40 #define __STM32F4xx_HAL_SD_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_ll_sdmmc.h"
49 /** @addtogroup STM32F4xx_HAL_Driver
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup SD_Exported_Types
61 #define SD_InitTypeDef SDIO_InitTypeDef
62 #define SD_TypeDef SDIO_TypeDef
65 * @brief SDIO Handle Structure definition
69 SD_TypeDef *Instance; /*!< SDIO register base address */
71 SD_InitTypeDef Init; /*!< SD required parameters */
73 HAL_LockTypeDef Lock; /*!< SD locking object */
75 uint32_t CardType; /*!< SD card type */
77 uint32_t RCA; /*!< SD relative card address */
79 uint32_t CSD[4]; /*!< SD card specific data table */
81 uint32_t CID[4]; /*!< SD card identification number table */
83 __IO uint32_t SdTransferCplt; /*!< SD transfer complete flag in non blocking mode */
85 __IO uint32_t SdTransferErr; /*!< SD transfer error flag in non blocking mode */
87 __IO uint32_t DmaTransferCplt; /*!< SD DMA transfer complete flag */
89 __IO uint32_t SdOperation; /*!< SD transfer operation (read/write) */
91 DMA_HandleTypeDef *hdmarx; /*!< SD Rx DMA handle parameters */
93 DMA_HandleTypeDef *hdmatx; /*!< SD Tx DMA handle parameters */
98 * @brief Card Specific Data: CSD Register
102 __IO uint8_t CSDStruct; /*!< CSD structure */
103 __IO uint8_t SysSpecVersion; /*!< System specification version */
104 __IO uint8_t Reserved1; /*!< Reserved */
105 __IO uint8_t TAAC; /*!< Data read access time 1 */
106 __IO uint8_t NSAC; /*!< Data read access time 2 in CLK cycles */
107 __IO uint8_t MaxBusClkFrec; /*!< Max. bus clock frequency */
108 __IO uint16_t CardComdClasses; /*!< Card command classes */
109 __IO uint8_t RdBlockLen; /*!< Max. read data block length */
110 __IO uint8_t PartBlockRead; /*!< Partial blocks for read allowed */
111 __IO uint8_t WrBlockMisalign; /*!< Write block misalignment */
112 __IO uint8_t RdBlockMisalign; /*!< Read block misalignment */
113 __IO uint8_t DSRImpl; /*!< DSR implemented */
114 __IO uint8_t Reserved2; /*!< Reserved */
115 __IO uint32_t DeviceSize; /*!< Device Size */
116 __IO uint8_t MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */
117 __IO uint8_t MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */
118 __IO uint8_t MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */
119 __IO uint8_t MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */
120 __IO uint8_t DeviceSizeMul; /*!< Device size multiplier */
121 __IO uint8_t EraseGrSize; /*!< Erase group size */
122 __IO uint8_t EraseGrMul; /*!< Erase group size multiplier */
123 __IO uint8_t WrProtectGrSize; /*!< Write protect group size */
124 __IO uint8_t WrProtectGrEnable; /*!< Write protect group enable */
125 __IO uint8_t ManDeflECC; /*!< Manufacturer default ECC */
126 __IO uint8_t WrSpeedFact; /*!< Write speed factor */
127 __IO uint8_t MaxWrBlockLen; /*!< Max. write data block length */
128 __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */
129 __IO uint8_t Reserved3; /*!< Reserved */
130 __IO uint8_t ContentProtectAppli; /*!< Content protection application */
131 __IO uint8_t FileFormatGrouop; /*!< File format group */
132 __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */
133 __IO uint8_t PermWrProtect; /*!< Permanent write protection */
134 __IO uint8_t TempWrProtect; /*!< Temporary write protection */
135 __IO uint8_t FileFormat; /*!< File format */
136 __IO uint8_t ECC; /*!< ECC code */
137 __IO uint8_t CSD_CRC; /*!< CSD CRC */
138 __IO uint8_t Reserved4; /*!< Always 1 */
143 * @brief Card Identification Data: CID Register
147 __IO uint8_t ManufacturerID; /*!< Manufacturer ID */
148 __IO uint16_t OEM_AppliID; /*!< OEM/Application ID */
149 __IO uint32_t ProdName1; /*!< Product Name part1 */
150 __IO uint8_t ProdName2; /*!< Product Name part2 */
151 __IO uint8_t ProdRev; /*!< Product Revision */
152 __IO uint32_t ProdSN; /*!< Product Serial Number */
153 __IO uint8_t Reserved1; /*!< Reserved1 */
154 __IO uint16_t ManufactDate; /*!< Manufacturing Date */
155 __IO uint8_t CID_CRC; /*!< CID CRC */
156 __IO uint8_t Reserved2; /*!< Always 1 */
161 * @brief SD Card Status returned by ACMD13
165 __IO uint8_t DAT_BUS_WIDTH; /*!< Shows the currently defined data bus width */
166 __IO uint8_t SECURED_MODE; /*!< Card is in secured mode of operation */
167 __IO uint16_t SD_CARD_TYPE; /*!< Carries information about card type */
168 __IO uint32_t SIZE_OF_PROTECTED_AREA; /*!< Carries information about the capacity of protected area */
169 __IO uint8_t SPEED_CLASS; /*!< Carries information about the speed class of the card */
170 __IO uint8_t PERFORMANCE_MOVE; /*!< Carries information about the card's performance move */
171 __IO uint8_t AU_SIZE; /*!< Carries information about the card's allocation unit size */
172 __IO uint16_t ERASE_SIZE; /*!< Determines the number of AUs to be erased in one operation */
173 __IO uint8_t ERASE_TIMEOUT; /*!< Determines the timeout for any number of AU erase */
174 __IO uint8_t ERASE_OFFSET; /*!< Carries information about the erase offset */
176 }HAL_SD_CardStatusTypedef;
179 * @brief SD Card information structure
183 HAL_SD_CSDTypedef SD_csd; /*!< SD card specific data register */
184 HAL_SD_CIDTypedef SD_cid; /*!< SD card identification number register */
185 uint64_t CardCapacity; /*!< Card capacity */
186 uint32_t CardBlockSize; /*!< Card block size */
187 uint16_t RCA; /*!< SD relative card address */
188 uint8_t CardType; /*!< SD card type */
190 }HAL_SD_CardInfoTypedef;
193 * @brief SD Error status enumeration Structure definition
198 * @brief SD specific error defines
200 SD_CMD_CRC_FAIL = (1), /*!< Command response received (but CRC check failed) */
201 SD_DATA_CRC_FAIL = (2), /*!< Data block sent/received (CRC check failed) */
202 SD_CMD_RSP_TIMEOUT = (3), /*!< Command response timeout */
203 SD_DATA_TIMEOUT = (4), /*!< Data timeout */
204 SD_TX_UNDERRUN = (5), /*!< Transmit FIFO underrun */
205 SD_RX_OVERRUN = (6), /*!< Receive FIFO overrun */
206 SD_START_BIT_ERR = (7), /*!< Start bit not detected on all data signals in wide bus mode */
207 SD_CMD_OUT_OF_RANGE = (8), /*!< Command's argument was out of range. */
208 SD_ADDR_MISALIGNED = (9), /*!< Misaligned address */
209 SD_BLOCK_LEN_ERR = (10), /*!< Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length */
210 SD_ERASE_SEQ_ERR = (11), /*!< An error in the sequence of erase command occurs. */
211 SD_BAD_ERASE_PARAM = (12), /*!< An invalid selection for erase groups */
212 SD_WRITE_PROT_VIOLATION = (13), /*!< Attempt to program a write protect block */
213 SD_LOCK_UNLOCK_FAILED = (14), /*!< Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
214 SD_COM_CRC_FAILED = (15), /*!< CRC check of the previous command failed */
215 SD_ILLEGAL_CMD = (16), /*!< Command is not legal for the card state */
216 SD_CARD_ECC_FAILED = (17), /*!< Card internal ECC was applied but failed to correct the data */
217 SD_CC_ERROR = (18), /*!< Internal card controller error */
218 SD_GENERAL_UNKNOWN_ERROR = (19), /*!< General or unknown error */
219 SD_STREAM_READ_UNDERRUN = (20), /*!< The card could not sustain data transfer in stream read operation. */
220 SD_STREAM_WRITE_OVERRUN = (21), /*!< The card could not sustain data programming in stream mode */
221 SD_CID_CSD_OVERWRITE = (22), /*!< CID/CSD overwrite error */
222 SD_WP_ERASE_SKIP = (23), /*!< Only partial address space was erased */
223 SD_CARD_ECC_DISABLED = (24), /*!< Command has been executed without using internal ECC */
224 SD_ERASE_RESET = (25), /*!< Erase sequence was cleared before executing because an out of erase sequence command was received */
225 SD_AKE_SEQ_ERROR = (26), /*!< Error in sequence of authentication. */
226 SD_INVALID_VOLTRANGE = (27),
227 SD_ADDR_OUT_OF_RANGE = (28),
228 SD_SWITCH_ERROR = (29),
229 SD_SDIO_DISABLED = (30),
230 SD_SDIO_FUNCTION_BUSY = (31),
231 SD_SDIO_FUNCTION_FAILED = (32),
232 SD_SDIO_UNKNOWN_FUNCTION = (33),
235 * @brief Standard error defines
237 SD_INTERNAL_ERROR = (34),
238 SD_NOT_CONFIGURED = (35),
239 SD_REQUEST_PENDING = (36),
240 SD_REQUEST_NOT_APPLICABLE = (37),
241 SD_INVALID_PARAMETER = (38),
242 SD_UNSUPPORTED_FEATURE = (39),
243 SD_UNSUPPORTED_HW = (40),
247 }HAL_SD_ErrorTypedef;
250 * @brief SD Transfer state enumeration structure
254 SD_TRANSFER_OK = 0, /*!< Transfer success */
255 SD_TRANSFER_BUSY = 1, /*!< Transfer is occurring */
256 SD_TRANSFER_ERROR = 2 /*!< Transfer failed */
258 }HAL_SD_TransferStateTypedef;
261 * @brief SD Card State enumeration structure
265 SD_CARD_READY = ((uint32_t)0x00000001), /*!< Card state is ready */
266 SD_CARD_IDENTIFICATION = ((uint32_t)0x00000002), /*!< Card is in identification state */
267 SD_CARD_STANDBY = ((uint32_t)0x00000003), /*!< Card is in standby state */
268 SD_CARD_TRANSFER = ((uint32_t)0x00000004), /*!< Card is in transfer state */
269 SD_CARD_SENDING = ((uint32_t)0x00000005), /*!< Card is sending an operation */
270 SD_CARD_RECEIVING = ((uint32_t)0x00000006), /*!< Card is receiving operation information */
271 SD_CARD_PROGRAMMING = ((uint32_t)0x00000007), /*!< Card is in programming state */
272 SD_CARD_DISCONNECTED = ((uint32_t)0x00000008), /*!< Card is disconnected */
273 SD_CARD_ERROR = ((uint32_t)0x000000FF) /*!< Card is in error state */
275 }HAL_SD_CardStateTypedef;
278 * @brief SD Operation enumeration structure
282 SD_READ_SINGLE_BLOCK = 0, /*!< Read single block operation */
283 SD_READ_MULTIPLE_BLOCK = 1, /*!< Read multiple blocks operation */
284 SD_WRITE_SINGLE_BLOCK = 2, /*!< Write single block operation */
285 SD_WRITE_MULTIPLE_BLOCK = 3 /*!< Write multiple blocks operation */
287 }HAL_SD_OperationTypedef;
290 /* Exported constants --------------------------------------------------------*/
291 /** @defgroup SD_Exported_Constants
296 * @brief SD Commands Index
298 #define SD_CMD_GO_IDLE_STATE ((uint8_t)0) /*!< Resets the SD memory card. */
299 #define SD_CMD_SEND_OP_COND ((uint8_t)1) /*!< Sends host capacity support information and activates the card's initialization process. */
300 #define SD_CMD_ALL_SEND_CID ((uint8_t)2) /*!< Asks any card connected to the host to send the CID numbers on the CMD line. */
301 #define SD_CMD_SET_REL_ADDR ((uint8_t)3) /*!< Asks the card to publish a new relative address (RCA). */
302 #define SD_CMD_SET_DSR ((uint8_t)4) /*!< Programs the DSR of all cards. */
303 #define SD_CMD_SDIO_SEN_OP_COND ((uint8_t)5) /*!< Sends host capacity support information (HCS) and asks the accessed card to send its
304 operating condition register (OCR) content in the response on the CMD line. */
305 #define SD_CMD_HS_SWITCH ((uint8_t)6) /*!< Checks switchable function (mode 0) and switch card function (mode 1). */
306 #define SD_CMD_SEL_DESEL_CARD ((uint8_t)7) /*!< Selects the card by its own relative address and gets deselected by any other address */
307 #define SD_CMD_HS_SEND_EXT_CSD ((uint8_t)8) /*!< Sends SD Memory Card interface condition, which includes host supply voltage information
308 and asks the card whether card supports voltage. */
309 #define SD_CMD_SEND_CSD ((uint8_t)9) /*!< Addressed card sends its card specific data (CSD) on the CMD line. */
310 #define SD_CMD_SEND_CID ((uint8_t)10) /*!< Addressed card sends its card identification (CID) on the CMD line. */
311 #define SD_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11) /*!< SD card doesn't support it. */
312 #define SD_CMD_STOP_TRANSMISSION ((uint8_t)12) /*!< Forces the card to stop transmission. */
313 #define SD_CMD_SEND_STATUS ((uint8_t)13) /*!< Addressed card sends its status register. */
314 #define SD_CMD_HS_BUSTEST_READ ((uint8_t)14)
315 #define SD_CMD_GO_INACTIVE_STATE ((uint8_t)15) /*!< Sends an addressed card into the inactive state. */
316 #define SD_CMD_SET_BLOCKLEN ((uint8_t)16) /*!< Sets the block length (in bytes for SDSC) for all following block commands
317 (read, write, lock). Default block length is fixed to 512 Bytes. Not effective
318 for SDHS and SDXC. */
319 #define SD_CMD_READ_SINGLE_BLOCK ((uint8_t)17) /*!< Reads single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of
320 fixed 512 bytes in case of SDHC and SDXC. */
321 #define SD_CMD_READ_MULT_BLOCK ((uint8_t)18) /*!< Continuously transfers data blocks from card to host until interrupted by
322 STOP_TRANSMISSION command. */
323 #define SD_CMD_HS_BUSTEST_WRITE ((uint8_t)19) /*!< 64 bytes tuning pattern is sent for SDR50 and SDR104. */
324 #define SD_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20) /*!< Speed class control command. */
325 #define SD_CMD_SET_BLOCK_COUNT ((uint8_t)23) /*!< Specify block count for CMD18 and CMD25. */
326 #define SD_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24) /*!< Writes single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of
327 fixed 512 bytes in case of SDHC and SDXC. */
328 #define SD_CMD_WRITE_MULT_BLOCK ((uint8_t)25) /*!< Continuously writes blocks of data until a STOP_TRANSMISSION follows. */
329 #define SD_CMD_PROG_CID ((uint8_t)26) /*!< Reserved for manufacturers. */
330 #define SD_CMD_PROG_CSD ((uint8_t)27) /*!< Programming of the programmable bits of the CSD. */
331 #define SD_CMD_SET_WRITE_PROT ((uint8_t)28) /*!< Sets the write protection bit of the addressed group. */
332 #define SD_CMD_CLR_WRITE_PROT ((uint8_t)29) /*!< Clears the write protection bit of the addressed group. */
333 #define SD_CMD_SEND_WRITE_PROT ((uint8_t)30) /*!< Asks the card to send the status of the write protection bits. */
334 #define SD_CMD_SD_ERASE_GRP_START ((uint8_t)32) /*!< Sets the address of the first write block to be erased. (For SD card only). */
335 #define SD_CMD_SD_ERASE_GRP_END ((uint8_t)33) /*!< Sets the address of the last write block of the continuous range to be erased. */
336 #define SD_CMD_ERASE_GRP_START ((uint8_t)35) /*!< Sets the address of the first write block to be erased. Reserved for each command
337 system set by switch function command (CMD6). */
338 #define SD_CMD_ERASE_GRP_END ((uint8_t)36) /*!< Sets the address of the last write block of the continuous range to be erased.
339 Reserved for each command system set by switch function command (CMD6). */
340 #define SD_CMD_ERASE ((uint8_t)38) /*!< Reserved for SD security applications. */
341 #define SD_CMD_FAST_IO ((uint8_t)39) /*!< SD card doesn't support it (Reserved). */
342 #define SD_CMD_GO_IRQ_STATE ((uint8_t)40) /*!< SD card doesn't support it (Reserved). */
343 #define SD_CMD_LOCK_UNLOCK ((uint8_t)42) /*!< Sets/resets the password or lock/unlock the card. The size of the data block is set by
344 the SET_BLOCK_LEN command. */
345 #define SD_CMD_APP_CMD ((uint8_t)55) /*!< Indicates to the card that the next command is an application specific command rather
346 than a standard command. */
347 #define SD_CMD_GEN_CMD ((uint8_t)56) /*!< Used either to transfer a data block to the card or to get a data block from the card
348 for general purpose/application specific commands. */
349 #define SD_CMD_NO_CMD ((uint8_t)64)
352 * @brief Following commands are SD Card Specific commands.
353 * SDIO_APP_CMD should be sent before sending these commands.
355 #define SD_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6) /*!< (ACMD6) Defines the data bus width to be used for data transfer. The allowed data bus
356 widths are given in SCR register. */
357 #define SD_CMD_SD_APP_STAUS ((uint8_t)13) /*!< (ACMD13) Sends the SD status. */
358 #define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22) /*!< (ACMD22) Sends the number of the written (without errors) write blocks. Responds with
359 32bit+CRC data block. */
360 #define SD_CMD_SD_APP_OP_COND ((uint8_t)41) /*!< (ACMD41) Sends host capacity support information (HCS) and asks the accessed card to
361 send its operating condition register (OCR) content in the response on the CMD line. */
362 #define SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42) /*!< (ACMD42) Connects/Disconnects the 50 KOhm pull-up resistor on CD/DAT3 (pin 1) of the card. */
363 #define SD_CMD_SD_APP_SEND_SCR ((uint8_t)51) /*!< Reads the SD Configuration Register (SCR). */
364 #define SD_CMD_SDIO_RW_DIRECT ((uint8_t)52) /*!< For SD I/O card only, reserved for security specification. */
365 #define SD_CMD_SDIO_RW_EXTENDED ((uint8_t)53) /*!< For SD I/O card only, reserved for security specification. */
368 * @brief Following commands are SD Card Specific security commands.
369 * SD_CMD_APP_CMD should be sent before sending these commands.
371 #define SD_CMD_SD_APP_GET_MKB ((uint8_t)43) /*!< For SD card only */
372 #define SD_CMD_SD_APP_GET_MID ((uint8_t)44) /*!< For SD card only */
373 #define SD_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45) /*!< For SD card only */
374 #define SD_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46) /*!< For SD card only */
375 #define SD_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47) /*!< For SD card only */
376 #define SD_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48) /*!< For SD card only */
377 #define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18) /*!< For SD card only */
378 #define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25) /*!< For SD card only */
379 #define SD_CMD_SD_APP_SECURE_ERASE ((uint8_t)38) /*!< For SD card only */
380 #define SD_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49) /*!< For SD card only */
381 #define SD_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48) /*!< For SD card only */
384 * @brief Supported SD Memory Cards
386 #define STD_CAPACITY_SD_CARD_V1_1 ((uint32_t)0x00000000)
387 #define STD_CAPACITY_SD_CARD_V2_0 ((uint32_t)0x00000001)
388 #define HIGH_CAPACITY_SD_CARD ((uint32_t)0x00000002)
389 #define MULTIMEDIA_CARD ((uint32_t)0x00000003)
390 #define SECURE_DIGITAL_IO_CARD ((uint32_t)0x00000004)
391 #define HIGH_SPEED_MULTIMEDIA_CARD ((uint32_t)0x00000005)
392 #define SECURE_DIGITAL_IO_COMBO_CARD ((uint32_t)0x00000006)
393 #define HIGH_CAPACITY_MMC_CARD ((uint32_t)0x00000007)
398 /* Exported macro ------------------------------------------------------------*/
400 /** @defgroup SD_Exported_macros
401 * @brief macros to handle interrupts and specific clock configurations
406 * @brief Enable the SD device.
409 #define __HAL_SD_SDIO_ENABLE() __SDIO_ENABLE()
412 * @brief Disable the SD device.
415 #define __HAL_SD_SDIO_DISABLE() __SDIO_DISABLE()
418 * @brief Enable the SDIO DMA transfer.
421 #define __HAL_SD_SDIO_DMA_ENABLE() __SDIO_DMA_ENABLE()
424 * @brief Disable the SDIO DMA transfer.
427 #define __HAL_SD_SDIO_DMA_DISABLE() __SDIO_DMA_DISABLE()
430 * @brief Enable the SD device interrupt.
431 * @param __HANDLE__: SD Handle
432 * @param __INTERRUPT__: specifies the SDIO interrupt sources to be enabled.
433 * This parameter can be one or a combination of the following values:
434 * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
435 * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
436 * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
437 * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
438 * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
439 * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
440 * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
441 * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
442 * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
443 * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
445 * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
446 * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
447 * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
448 * @arg SDIO_IT_RXACT: Data receive in progress interrupt
449 * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
450 * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
451 * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
452 * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
453 * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
454 * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
455 * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
456 * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
457 * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
458 * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61 interrupt
461 #define __HAL_SD_SDIO_ENABLE_IT(__HANDLE__, __INTERRUPT__) __SDIO_ENABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
464 * @brief Disable the SD device interrupt.
465 * @param __HANDLE__: SD Handle
466 * @param __INTERRUPT__: specifies the SDIO interrupt sources to be disabled.
467 * This parameter can be one or a combination of the following values:
468 * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
469 * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
470 * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
471 * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
472 * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
473 * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
474 * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
475 * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
476 * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
477 * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
479 * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
480 * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
481 * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
482 * @arg SDIO_IT_RXACT: Data receive in progress interrupt
483 * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
484 * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
485 * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
486 * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
487 * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
488 * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
489 * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
490 * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
491 * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
492 * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61 interrupt
495 #define __HAL_SD_SDIO_DISABLE_IT(__HANDLE__, __INTERRUPT__) __SDIO_DISABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
498 * @brief Check whether the specified SD flag is set or not.
499 * @param __HANDLE__: SD Handle
500 * @param __FLAG__: specifies the flag to check.
501 * This parameter can be one of the following values:
502 * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
503 * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
504 * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
505 * @arg SDIO_FLAG_DTIMEOUT: Data timeout
506 * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
507 * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error
508 * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed)
509 * @arg SDIO_FLAG_CMDSENT: Command sent (no response required)
510 * @arg SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
511 * @arg SDIO_FLAG_STBITERR: Start bit not detected on all data signals in wide bus mode.
512 * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed)
513 * @arg SDIO_FLAG_CMDACT: Command transfer in progress
514 * @arg SDIO_FLAG_TXACT: Data transmit in progress
515 * @arg SDIO_FLAG_RXACT: Data receive in progress
516 * @arg SDIO_FLAG_TXFIFOHE: Transmit FIFO Half Empty
517 * @arg SDIO_FLAG_RXFIFOHF: Receive FIFO Half Full
518 * @arg SDIO_FLAG_TXFIFOF: Transmit FIFO full
519 * @arg SDIO_FLAG_RXFIFOF: Receive FIFO full
520 * @arg SDIO_FLAG_TXFIFOE: Transmit FIFO empty
521 * @arg SDIO_FLAG_RXFIFOE: Receive FIFO empty
522 * @arg SDIO_FLAG_TXDAVL: Data available in transmit FIFO
523 * @arg SDIO_FLAG_RXDAVL: Data available in receive FIFO
524 * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received
525 * @arg SDIO_FLAG_CEATAEND: CE-ATA command completion signal received for CMD61
526 * @retval The new state of SD FLAG (SET or RESET).
528 #define __HAL_SD_SDIO_GET_FLAG(__HANDLE__, __FLAG__) __SDIO_GET_FLAG((__HANDLE__)->Instance, (__FLAG__))
531 * @brief Clear the SD's pending flags.
532 * @param __HANDLE__: SD Handle
533 * @param __FLAG__: specifies the flag to clear.
534 * This parameter can be one or a combination of the following values:
535 * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
536 * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
537 * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
538 * @arg SDIO_FLAG_DTIMEOUT: Data timeout
539 * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
540 * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error
541 * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed)
542 * @arg SDIO_FLAG_CMDSENT: Command sent (no response required)
543 * @arg SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
544 * @arg SDIO_FLAG_STBITERR: Start bit not detected on all data signals in wide bus mode
545 * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed)
546 * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received
547 * @arg SDIO_FLAG_CEATAEND: CE-ATA command completion signal received for CMD61
550 #define __HAL_SD_SDIO_CLEAR_FLAG(__HANDLE__, __FLAG__) __SDIO_CLEAR_FLAG((__HANDLE__)->Instance, (__FLAG__))
553 * @brief Check whether the specified SD interrupt has occurred or not.
554 * @param __HANDLE__: SD Handle
555 * @param __INTERRUPT__: specifies the SDIO interrupt source to check.
556 * This parameter can be one of the following values:
557 * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
558 * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
559 * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
560 * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
561 * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
562 * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
563 * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
564 * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
565 * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
566 * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
568 * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
569 * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
570 * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
571 * @arg SDIO_IT_RXACT: Data receive in progress interrupt
572 * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
573 * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
574 * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
575 * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
576 * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
577 * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
578 * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
579 * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
580 * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
581 * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61 interrupt
582 * @retval The new state of SD IT (SET or RESET).
584 #define __HAL_SD_SDIO_GET_IT (__HANDLE__, __INTERRUPT__) __SDIO_GET_IT ((__HANDLE__)->Instance, __INTERRUPT__)
587 * @brief Clear the SD's interrupt pending bits.
588 * @param __HANDLE__ : SD Handle
589 * @param __INTERRUPT__: specifies the interrupt pending bit to clear.
590 * This parameter can be one or a combination of the following values:
591 * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
592 * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
593 * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
594 * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
595 * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
596 * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
597 * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
598 * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
599 * @arg SDIO_IT_DATAEND: Data end (data counter, SDIO_DCOUNT, is zero) interrupt
600 * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
602 * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
603 * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61
606 #define __HAL_SD_SDIO_CLEAR_IT(__HANDLE__, __INTERRUPT__) __SDIO_CLEAR_IT((__HANDLE__)->Instance, (__INTERRUPT__))
611 /* Exported functions --------------------------------------------------------*/
612 /** @addtogroup SD_Exported_Functions
616 /* Initialization/de-initialization functions ********************************/
617 /** @addtogroup SD_Group1
620 HAL_SD_ErrorTypedef HAL_SD_Init(SD_HandleTypeDef *hsd, HAL_SD_CardInfoTypedef *SDCardInfo);
621 HAL_StatusTypeDef HAL_SD_DeInit (SD_HandleTypeDef *hsd);
622 void HAL_SD_MspInit(SD_HandleTypeDef *hsd);
623 void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd);
628 /* I/O operation functions ***************************************************/
629 /** @addtogroup SD_Group2
632 /* Blocking mode: Polling */
633 HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks);
634 HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumberOfBlocks);
635 HAL_SD_ErrorTypedef HAL_SD_Erase(SD_HandleTypeDef *hsd, uint64_t startaddr, uint64_t endaddr);
637 /* Non-Blocking mode: Interrupt */
638 void HAL_SD_IRQHandler(SD_HandleTypeDef *hsd);
640 /* Callback in non blocking modes (DMA) */
641 void HAL_SD_DMA_RxCpltCallback(DMA_HandleTypeDef *hdma);
642 void HAL_SD_DMA_RxErrorCallback(DMA_HandleTypeDef *hdma);
643 void HAL_SD_DMA_TxCpltCallback(DMA_HandleTypeDef *hdma);
644 void HAL_SD_DMA_TxErrorCallback(DMA_HandleTypeDef *hdma);
645 void HAL_SD_XferCpltCallback(SD_HandleTypeDef *hsd);
646 void HAL_SD_XferErrorCallback(SD_HandleTypeDef *hsd);
648 /* Non-Blocking mode: DMA */
649 HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks);
650 HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumberOfBlocks);
651 HAL_SD_ErrorTypedef HAL_SD_CheckWriteOperation(SD_HandleTypeDef *hsd, uint32_t Timeout);
652 HAL_SD_ErrorTypedef HAL_SD_CheckReadOperation(SD_HandleTypeDef *hsd, uint32_t Timeout);
657 /* Peripheral Control functions **********************************************/
658 /** @addtogroup SD_Group3
661 HAL_SD_ErrorTypedef HAL_SD_Get_CardInfo(SD_HandleTypeDef *hsd, HAL_SD_CardInfoTypedef *pCardInfo);
662 HAL_SD_ErrorTypedef HAL_SD_WideBusOperation_Config(SD_HandleTypeDef *hsd, uint32_t WideMode);
663 HAL_SD_ErrorTypedef HAL_SD_StopTransfer(SD_HandleTypeDef *hsd);
664 HAL_SD_ErrorTypedef HAL_SD_HighSpeed (SD_HandleTypeDef *hsd);
669 /* Peripheral State functions ************************************************/
670 /** @addtogroup SD_Group4
673 HAL_SD_ErrorTypedef HAL_SD_SendSDStatus(SD_HandleTypeDef *hsd, uint32_t *pSDstatus);
674 HAL_SD_ErrorTypedef HAL_SD_GetCardStatus(SD_HandleTypeDef *hsd, HAL_SD_CardStatusTypedef *pCardStatus);
675 HAL_SD_TransferStateTypedef HAL_SD_GetStatus(SD_HandleTypeDef *hsd);
697 #endif /* __STM32F4xx_HAL_SD_H */
699 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/