2 ******************************************************************************
3 * @file stm32h7xx_hal_sd.h
4 * @author MCD Application Team
5 * @brief Header file of SD HAL module.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32H7xx_HAL_SD_H
22 #define STM32H7xx_HAL_SD_H
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx_ll_sdmmc.h"
30 #if defined (DLYB_SDMMC1) || defined (DLYB_SDMMC2) || defined (DLYB_SDMMC3)
31 #include "stm32h7xx_ll_delayblock.h"
32 #endif /* (DLYB_SDMMC1) || (DLYB_SDMMC2) */
34 /** @addtogroup STM32H7xx_HAL_Driver
39 * @brief SD HAL module driver
43 /* Exported types ------------------------------------------------------------*/
44 /** @defgroup SD_Exported_Types SD Exported Types
48 /** @defgroup SD_Exported_Types_Group1 SD State enumeration structure
53 HAL_SD_STATE_RESET
= ((uint32_t)0x00000000U
), /*!< SD not yet initialized or disabled */
54 HAL_SD_STATE_READY
= ((uint32_t)0x00000001U
), /*!< SD initialized and ready for use */
55 HAL_SD_STATE_TIMEOUT
= ((uint32_t)0x00000002U
), /*!< SD Timeout state */
56 HAL_SD_STATE_BUSY
= ((uint32_t)0x00000003U
), /*!< SD process ongoing */
57 HAL_SD_STATE_PROGRAMMING
= ((uint32_t)0x00000004U
), /*!< SD Programming State */
58 HAL_SD_STATE_RECEIVING
= ((uint32_t)0x00000005U
), /*!< SD Receiving State */
59 HAL_SD_STATE_TRANSFER
= ((uint32_t)0x00000006U
), /*!< SD Transfert State */
60 HAL_SD_STATE_ERROR
= ((uint32_t)0x0000000FU
) /*!< SD is in error state */
66 /** @defgroup SD_Exported_Types_Group2 SD Card State enumeration structure
69 typedef uint32_t HAL_SD_CardStateTypeDef
;
71 #define HAL_SD_CARD_READY 0x00000001U /*!< Card state is ready */
72 #define HAL_SD_CARD_IDENTIFICATION 0x00000002U /*!< Card is in identification state */
73 #define HAL_SD_CARD_STANDBY 0x00000003U /*!< Card is in standby state */
74 #define HAL_SD_CARD_TRANSFER 0x00000004U /*!< Card is in transfer state */
75 #define HAL_SD_CARD_SENDING 0x00000005U /*!< Card is sending an operation */
76 #define HAL_SD_CARD_RECEIVING 0x00000006U /*!< Card is receiving operation information */
77 #define HAL_SD_CARD_PROGRAMMING 0x00000007U /*!< Card is in programming state */
78 #define HAL_SD_CARD_DISCONNECTED 0x00000008U /*!< Card is disconnected */
79 #define HAL_SD_CARD_ERROR 0x000000FFU /*!< Card response Error */
84 /** @defgroup SD_Exported_Types_Group3 SD Handle Structure definition
87 #define SD_InitTypeDef SDMMC_InitTypeDef
88 #define SD_TypeDef SDMMC_TypeDef
91 * @brief SD Card Information Structure definition
95 uint32_t CardType
; /*!< Specifies the card Type */
97 uint32_t CardVersion
; /*!< Specifies the card version */
99 uint32_t Class
; /*!< Specifies the class of the card class */
101 uint32_t RelCardAdd
; /*!< Specifies the Relative Card Address */
103 uint32_t BlockNbr
; /*!< Specifies the Card Capacity in blocks */
105 uint32_t BlockSize
; /*!< Specifies one block size in bytes */
107 uint32_t LogBlockNbr
; /*!< Specifies the Card logical Capacity in blocks */
109 uint32_t LogBlockSize
; /*!< Specifies logical block size in bytes */
111 uint32_t CardSpeed
; /*!< Specifies the card Speed */
113 }HAL_SD_CardInfoTypeDef
;
116 * @brief SD handle Structure definition
118 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
119 typedef struct __SD_HandleTypeDef
122 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
124 SD_TypeDef
*Instance
; /*!< SD registers base address */
126 SD_InitTypeDef Init
; /*!< SD required parameters */
128 HAL_LockTypeDef Lock
; /*!< SD locking object */
130 uint8_t *pTxBuffPtr
; /*!< Pointer to SD Tx transfer Buffer */
132 uint32_t TxXferSize
; /*!< SD Tx Transfer size */
134 uint8_t *pRxBuffPtr
; /*!< Pointer to SD Rx transfer Buffer */
136 uint32_t RxXferSize
; /*!< SD Rx Transfer size */
138 __IO
uint32_t Context
; /*!< SD transfer context */
140 __IO HAL_SD_StateTypeDef State
; /*!< SD card State */
142 __IO
uint32_t ErrorCode
; /*!< SD Card Error codes */
144 HAL_SD_CardInfoTypeDef SdCard
; /*!< SD Card information */
146 uint32_t CSD
[4]; /*!< SD card specific data table */
148 uint32_t CID
[4]; /*!< SD card identification number table */
150 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
151 void (* TxCpltCallback
) (struct __SD_HandleTypeDef
*hsd
);
152 void (* RxCpltCallback
) (struct __SD_HandleTypeDef
*hsd
);
153 void (* ErrorCallback
) (struct __SD_HandleTypeDef
*hsd
);
154 void (* AbortCpltCallback
) (struct __SD_HandleTypeDef
*hsd
);
155 void (* Read_DMADblBuf0CpltCallback
) (struct __SD_HandleTypeDef
*hsd
);
156 void (* Read_DMADblBuf1CpltCallback
) (struct __SD_HandleTypeDef
*hsd
);
157 void (* Write_DMADblBuf0CpltCallback
) (struct __SD_HandleTypeDef
*hsd
);
158 void (* Write_DMADblBuf1CpltCallback
) (struct __SD_HandleTypeDef
*hsd
);
160 #if (USE_SD_TRANSCEIVER != 0U)
161 void (* DriveTransceiver_1_8V_Callback
) (FlagStatus status
);
162 #endif /* USE_SD_TRANSCEIVER */
164 void (* MspInitCallback
) (struct __SD_HandleTypeDef
*hsd
);
165 void (* MspDeInitCallback
) (struct __SD_HandleTypeDef
*hsd
);
166 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
173 /** @defgroup SD_Exported_Types_Group4 Card Specific Data: CSD Register
178 __IO
uint8_t CSDStruct
; /*!< CSD structure */
179 __IO
uint8_t SysSpecVersion
; /*!< System specification version */
180 __IO
uint8_t Reserved1
; /*!< Reserved */
181 __IO
uint8_t TAAC
; /*!< Data read access time 1 */
182 __IO
uint8_t NSAC
; /*!< Data read access time 2 in CLK cycles */
183 __IO
uint8_t MaxBusClkFrec
; /*!< Max. bus clock frequency */
184 __IO
uint16_t CardComdClasses
; /*!< Card command classes */
185 __IO
uint8_t RdBlockLen
; /*!< Max. read data block length */
186 __IO
uint8_t PartBlockRead
; /*!< Partial blocks for read allowed */
187 __IO
uint8_t WrBlockMisalign
; /*!< Write block misalignment */
188 __IO
uint8_t RdBlockMisalign
; /*!< Read block misalignment */
189 __IO
uint8_t DSRImpl
; /*!< DSR implemented */
190 __IO
uint8_t Reserved2
; /*!< Reserved */
191 __IO
uint32_t DeviceSize
; /*!< Device Size */
192 __IO
uint8_t MaxRdCurrentVDDMin
; /*!< Max. read current @ VDD min */
193 __IO
uint8_t MaxRdCurrentVDDMax
; /*!< Max. read current @ VDD max */
194 __IO
uint8_t MaxWrCurrentVDDMin
; /*!< Max. write current @ VDD min */
195 __IO
uint8_t MaxWrCurrentVDDMax
; /*!< Max. write current @ VDD max */
196 __IO
uint8_t DeviceSizeMul
; /*!< Device size multiplier */
197 __IO
uint8_t EraseGrSize
; /*!< Erase group size */
198 __IO
uint8_t EraseGrMul
; /*!< Erase group size multiplier */
199 __IO
uint8_t WrProtectGrSize
; /*!< Write protect group size */
200 __IO
uint8_t WrProtectGrEnable
; /*!< Write protect group enable */
201 __IO
uint8_t ManDeflECC
; /*!< Manufacturer default ECC */
202 __IO
uint8_t WrSpeedFact
; /*!< Write speed factor */
203 __IO
uint8_t MaxWrBlockLen
; /*!< Max. write data block length */
204 __IO
uint8_t WriteBlockPaPartial
; /*!< Partial blocks for write allowed */
205 __IO
uint8_t Reserved3
; /*!< Reserved */
206 __IO
uint8_t ContentProtectAppli
; /*!< Content protection application */
207 __IO
uint8_t FileFormatGroup
; /*!< File format group */
208 __IO
uint8_t CopyFlag
; /*!< Copy flag (OTP) */
209 __IO
uint8_t PermWrProtect
; /*!< Permanent write protection */
210 __IO
uint8_t TempWrProtect
; /*!< Temporary write protection */
211 __IO
uint8_t FileFormat
; /*!< File format */
212 __IO
uint8_t ECC
; /*!< ECC code */
213 __IO
uint8_t CSD_CRC
; /*!< CSD CRC */
214 __IO
uint8_t Reserved4
; /*!< Always 1 */
215 }HAL_SD_CardCSDTypeDef
;
220 /** @defgroup SD_Exported_Types_Group5 Card Identification Data: CID Register
225 __IO
uint8_t ManufacturerID
; /*!< Manufacturer ID */
226 __IO
uint16_t OEM_AppliID
; /*!< OEM/Application ID */
227 __IO
uint32_t ProdName1
; /*!< Product Name part1 */
228 __IO
uint8_t ProdName2
; /*!< Product Name part2 */
229 __IO
uint8_t ProdRev
; /*!< Product Revision */
230 __IO
uint32_t ProdSN
; /*!< Product Serial Number */
231 __IO
uint8_t Reserved1
; /*!< Reserved1 */
232 __IO
uint16_t ManufactDate
; /*!< Manufacturing Date */
233 __IO
uint8_t CID_CRC
; /*!< CID CRC */
234 __IO
uint8_t Reserved2
; /*!< Always 1 */
236 }HAL_SD_CardCIDTypeDef
;
241 /** @defgroup SD_Exported_Types_Group6 SD Card Status returned by ACMD13
246 __IO
uint8_t DataBusWidth
; /*!< Shows the currently defined data bus width */
247 __IO
uint8_t SecuredMode
; /*!< Card is in secured mode of operation */
248 __IO
uint16_t CardType
; /*!< Carries information about card type */
249 __IO
uint32_t ProtectedAreaSize
; /*!< Carries information about the capacity of protected area */
250 __IO
uint8_t SpeedClass
; /*!< Carries information about the speed class of the card */
251 __IO
uint8_t PerformanceMove
; /*!< Carries information about the card's performance move */
252 __IO
uint8_t AllocationUnitSize
; /*!< Carries information about the card's allocation unit size */
253 __IO
uint16_t EraseSize
; /*!< Determines the number of AUs to be erased in one operation */
254 __IO
uint8_t EraseTimeout
; /*!< Determines the timeout for any number of AU erase */
255 __IO
uint8_t EraseOffset
; /*!< Carries information about the erase offset */
256 __IO
uint8_t UhsSpeedGrade
; /*!< Carries information about the speed grade of UHS card */
257 __IO
uint8_t UhsAllocationUnitSize
; /*!< Carries information about the UHS card's allocation unit size */
258 __IO
uint8_t VideoSpeedClass
; /*!< Carries information about the Video Speed Class of UHS card */
259 }HAL_SD_CardStatusTypeDef
;
264 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
265 /** @defgroup SD_Exported_Types_Group7 SD Callback ID enumeration definition
270 HAL_SD_TX_CPLT_CB_ID
= 0x00U
, /*!< SD Tx Complete Callback ID */
271 HAL_SD_RX_CPLT_CB_ID
= 0x01U
, /*!< SD Rx Complete Callback ID */
272 HAL_SD_ERROR_CB_ID
= 0x02U
, /*!< SD Error Callback ID */
273 HAL_SD_ABORT_CB_ID
= 0x03U
, /*!< SD Abort Callback ID */
274 HAL_SD_READ_DMA_DBL_BUF0_CPLT_CB_ID
= 0x04U
, /*!< SD Rx DMA Double Buffer 0 Complete Callback ID */
275 HAL_SD_READ_DMA_DBL_BUF1_CPLT_CB_ID
= 0x05U
, /*!< SD Rx DMA Double Buffer 1 Complete Callback ID */
276 HAL_SD_WRITE_DMA_DBL_BUF0_CPLT_CB_ID
= 0x06U
, /*!< SD Tx DMA Double Buffer 0 Complete Callback ID */
277 HAL_SD_WRITE_DMA_DBL_BUF1_CPLT_CB_ID
= 0x07U
, /*!< SD Tx DMA Double Buffer 1 Complete Callback ID */
279 HAL_SD_MSP_INIT_CB_ID
= 0x10U
, /*!< SD MspInit Callback ID */
280 HAL_SD_MSP_DEINIT_CB_ID
= 0x11U
/*!< SD MspDeInit Callback ID */
281 }HAL_SD_CallbackIDTypeDef
;
286 /** @defgroup SD_Exported_Types_Group8 SD Callback pointer definition
289 typedef void (*pSD_CallbackTypeDef
) (SD_HandleTypeDef
*hsd
);
290 #if (USE_SD_TRANSCEIVER != 0U)
291 typedef void (*pSD_TransceiverCallbackTypeDef
)(FlagStatus status
);
292 #endif /* USE_SD_TRANSCEIVER */
296 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
301 /* Exported constants --------------------------------------------------------*/
302 /** @defgroup SD_Exported_Constants Exported Constants
306 #define BLOCKSIZE ((uint32_t)512U) /*!< Block size is 512 bytes */
308 /** @defgroup SD_Exported_Constansts_Group1 SD Error status enumeration Structure definition
311 #define HAL_SD_ERROR_NONE SDMMC_ERROR_NONE /*!< No error */
312 #define HAL_SD_ERROR_CMD_CRC_FAIL SDMMC_ERROR_CMD_CRC_FAIL /*!< Command response received (but CRC check failed) */
313 #define HAL_SD_ERROR_DATA_CRC_FAIL SDMMC_ERROR_DATA_CRC_FAIL /*!< Data block sent/received (CRC check failed) */
314 #define HAL_SD_ERROR_CMD_RSP_TIMEOUT SDMMC_ERROR_CMD_RSP_TIMEOUT /*!< Command response timeout */
315 #define HAL_SD_ERROR_DATA_TIMEOUT SDMMC_ERROR_DATA_TIMEOUT /*!< Data timeout */
316 #define HAL_SD_ERROR_TX_UNDERRUN SDMMC_ERROR_TX_UNDERRUN /*!< Transmit FIFO underrun */
317 #define HAL_SD_ERROR_RX_OVERRUN SDMMC_ERROR_RX_OVERRUN /*!< Receive FIFO overrun */
318 #define HAL_SD_ERROR_ADDR_MISALIGNED SDMMC_ERROR_ADDR_MISALIGNED /*!< Misaligned address */
319 #define HAL_SD_ERROR_BLOCK_LEN_ERR SDMMC_ERROR_BLOCK_LEN_ERR /*!< Transferred block length is not allowed for the card or the
320 number of transferred bytes does not match the block length */
321 #define HAL_SD_ERROR_ERASE_SEQ_ERR SDMMC_ERROR_ERASE_SEQ_ERR /*!< An error in the sequence of erase command occurs */
322 #define HAL_SD_ERROR_BAD_ERASE_PARAM SDMMC_ERROR_BAD_ERASE_PARAM /*!< An invalid selection for erase groups */
323 #define HAL_SD_ERROR_WRITE_PROT_VIOLATION SDMMC_ERROR_WRITE_PROT_VIOLATION /*!< Attempt to program a write protect block */
324 #define HAL_SD_ERROR_LOCK_UNLOCK_FAILED SDMMC_ERROR_LOCK_UNLOCK_FAILED /*!< Sequence or password error has been detected in unlock
325 command or if there was an attempt to access a locked card */
326 #define HAL_SD_ERROR_COM_CRC_FAILED SDMMC_ERROR_COM_CRC_FAILED /*!< CRC check of the previous command failed */
327 #define HAL_SD_ERROR_ILLEGAL_CMD SDMMC_ERROR_ILLEGAL_CMD /*!< Command is not legal for the card state */
328 #define HAL_SD_ERROR_CARD_ECC_FAILED SDMMC_ERROR_CARD_ECC_FAILED /*!< Card internal ECC was applied but failed to correct the data */
329 #define HAL_SD_ERROR_CC_ERR SDMMC_ERROR_CC_ERR /*!< Internal card controller error */
330 #define HAL_SD_ERROR_GENERAL_UNKNOWN_ERR SDMMC_ERROR_GENERAL_UNKNOWN_ERR /*!< General or unknown error */
331 #define HAL_SD_ERROR_STREAM_READ_UNDERRUN SDMMC_ERROR_STREAM_READ_UNDERRUN /*!< The card could not sustain data reading in stream rmode */
332 #define HAL_SD_ERROR_STREAM_WRITE_OVERRUN SDMMC_ERROR_STREAM_WRITE_OVERRUN /*!< The card could not sustain data programming in stream mode */
333 #define HAL_SD_ERROR_CID_CSD_OVERWRITE SDMMC_ERROR_CID_CSD_OVERWRITE /*!< CID/CSD overwrite error */
334 #define HAL_SD_ERROR_WP_ERASE_SKIP SDMMC_ERROR_WP_ERASE_SKIP /*!< Only partial address space was erased */
335 #define HAL_SD_ERROR_CARD_ECC_DISABLED SDMMC_ERROR_CARD_ECC_DISABLED /*!< Command has been executed without using internal ECC */
336 #define HAL_SD_ERROR_ERASE_RESET SDMMC_ERROR_ERASE_RESET /*!< Erase sequence was cleared before executing because an out
337 of erase sequence command was received */
338 #define HAL_SD_ERROR_AKE_SEQ_ERR SDMMC_ERROR_AKE_SEQ_ERR /*!< Error in sequence of authentication */
339 #define HAL_SD_ERROR_INVALID_VOLTRANGE SDMMC_ERROR_INVALID_VOLTRANGE /*!< Error in case of invalid voltage range */
340 #define HAL_SD_ERROR_ADDR_OUT_OF_RANGE SDMMC_ERROR_ADDR_OUT_OF_RANGE /*!< Error when addressed block is out of range */
341 #define HAL_SD_ERROR_REQUEST_NOT_APPLICABLE SDMMC_ERROR_REQUEST_NOT_APPLICABLE /*!< Error when command request is not applicable */
342 #define HAL_SD_ERROR_PARAM SDMMC_ERROR_INVALID_PARAMETER /*!< the used parameter is not valid */
343 #define HAL_SD_ERROR_UNSUPPORTED_FEATURE SDMMC_ERROR_UNSUPPORTED_FEATURE /*!< Error when feature is not insupported */
344 #define HAL_SD_ERROR_BUSY SDMMC_ERROR_BUSY /*!< Error when transfer process is busy */
345 #define HAL_SD_ERROR_DMA SDMMC_ERROR_DMA /*!< Error while DMA transfer */
346 #define HAL_SD_ERROR_TIMEOUT SDMMC_ERROR_TIMEOUT /*!< Timeout error */
348 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
349 #define HAL_SD_ERROR_INVALID_CALLBACK SDMMC_ERROR_INVALID_PARAMETER /*!< Invalid callback error */
350 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
355 /** @defgroup SD_Exported_Constansts_Group2 SD context enumeration
358 #define SD_CONTEXT_NONE ((uint32_t)0x00000000U) /*!< None */
359 #define SD_CONTEXT_READ_SINGLE_BLOCK ((uint32_t)0x00000001U) /*!< Read single block operation */
360 #define SD_CONTEXT_READ_MULTIPLE_BLOCK ((uint32_t)0x00000002U) /*!< Read multiple blocks operation */
361 #define SD_CONTEXT_WRITE_SINGLE_BLOCK ((uint32_t)0x00000010U) /*!< Write single block operation */
362 #define SD_CONTEXT_WRITE_MULTIPLE_BLOCK ((uint32_t)0x00000020U) /*!< Write multiple blocks operation */
363 #define SD_CONTEXT_IT ((uint32_t)0x00000008U) /*!< Process in Interrupt mode */
364 #define SD_CONTEXT_DMA ((uint32_t)0x00000080U) /*!< Process in DMA mode */
370 /** @defgroup SD_Exported_Constansts_Group3 SD Supported Memory Cards
373 #define CARD_NORMAL_SPEED ((uint32_t)0x00000000U) /*!< Normal Speed Card <12.5Mo/s , Spec Version 1.01 */
374 #define CARD_HIGH_SPEED ((uint32_t)0x00000100U) /*!< High Speed Card <25Mo/s , Spec version 2.00 */
375 #define CARD_ULTRA_HIGH_SPEED ((uint32_t)0x00000200U) /*!< UHS-I SD Card <50Mo/s for SDR50, DDR5 Cards
376 and <104Mo/s for SDR104, Spec version 3.01 */
378 #define CARD_SDSC ((uint32_t)0x00000000U) /*!< SD Standard Capacity <2Go */
379 #define CARD_SDHC_SDXC ((uint32_t)0x00000001U) /*!< SD High Capacity <32Go, SD Extended Capacity <2To */
380 #define CARD_SECURED ((uint32_t)0x00000003U)
386 /** @defgroup SD_Exported_Constansts_Group4 SD Supported Version
389 #define CARD_V1_X ((uint32_t)0x00000000U)
390 #define CARD_V2_X ((uint32_t)0x00000001U)
399 /* Exported macro ------------------------------------------------------------*/
400 /** @defgroup SD_Exported_macros SD Exported Macros
401 * @brief macros to handle interrupts and specific clock configurations
404 /** @brief Reset SD handle state.
405 * @param __HANDLE__ SD Handle.
408 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
409 #define __HAL_SD_RESET_HANDLE_STATE(__HANDLE__) do { \
410 (__HANDLE__)->State = HAL_SD_STATE_RESET; \
411 (__HANDLE__)->MspInitCallback = NULL; \
412 (__HANDLE__)->MspDeInitCallback = NULL; \
415 #define __HAL_SD_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SD_STATE_RESET)
416 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
419 * @brief Enable the SD device interrupt.
420 * @param __HANDLE__ SD Handle.
421 * @param __INTERRUPT__ specifies the SDMMC interrupt sources to be enabled.
422 * This parameter can be one or a combination of the following values:
423 * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
424 * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
425 * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
426 * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
427 * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
428 * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
429 * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
430 * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
431 * @arg SDMMC_IT_DATAEND: Data end (data counter, DATACOUNT, is zero) interrupt
432 * @arg SDMMC_IT_DHOLD: Data transfer Hold interrupt
433 * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
434 * @arg SDMMC_IT_DABORT: Data transfer aborted by CMD12 interrupt
435 * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
436 * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
437 * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
438 * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
439 * @arg SDMMC_IT_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected interrupt
440 * @arg SDMMC_IT_SDIOIT: SDIO interrupt received interrupt
441 * @arg SDMMC_IT_ACKFAIL: Boot Acknowledgment received interrupt
442 * @arg SDMMC_IT_ACKTIMEOUT: Boot Acknowledgment timeout interrupt
443 * @arg SDMMC_IT_VSWEND: Voltage switch critical timing section completion interrupt
444 * @arg SDMMC_IT_CKSTOP: SDMMC_CK stopped in Voltage switch procedure interrupt
445 * @arg SDMMC_IT_IDMABTC: IDMA buffer transfer complete interrupt
448 #define __HAL_SD_ENABLE_IT(__HANDLE__, __INTERRUPT__) __SDMMC_ENABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
451 * @brief Disable the SD device interrupt.
452 * @param __HANDLE__ SD Handle.
453 * @param __INTERRUPT__ specifies the SDMMC interrupt sources to be disabled.
454 * This parameter can be one or a combination of the following values:
455 * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
456 * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
457 * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
458 * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
459 * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
460 * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
461 * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
462 * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
463 * @arg SDMMC_IT_DATAEND: Data end (data counter, DATACOUNT, is zero) interrupt
464 * @arg SDMMC_IT_DHOLD: Data transfer Hold interrupt
465 * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
466 * @arg SDMMC_IT_DABORT: Data transfer aborted by CMD12 interrupt
467 * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
468 * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
469 * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
470 * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
471 * @arg SDMMC_IT_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected interrupt
472 * @arg SDMMC_IT_SDIOIT: SDIO interrupt received interrupt
473 * @arg SDMMC_IT_ACKFAIL: Boot Acknowledgment received interrupt
474 * @arg SDMMC_IT_ACKTIMEOUT: Boot Acknowledgment timeout interrupt
475 * @arg SDMMC_IT_VSWEND: Voltage switch critical timing section completion interrupt
476 * @arg SDMMC_IT_CKSTOP: SDMMC_CK stopped in Voltage switch procedure interrupt
477 * @arg SDMMC_IT_IDMABTC: IDMA buffer transfer complete interrupt
480 #define __HAL_SD_DISABLE_IT(__HANDLE__, __INTERRUPT__) __SDMMC_DISABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
483 * @brief Check whether the specified SD flag is set or not.
484 * @param __HANDLE__ SD Handle.
485 * @param __FLAG__ specifies the flag to check.
486 * This parameter can be one of the following values:
487 * @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed)
488 * @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
489 * @arg SDMMC_FLAG_CTIMEOUT: Command response timeout
490 * @arg SDMMC_FLAG_DTIMEOUT: Data timeout
491 * @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error
492 * @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error
493 * @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed)
494 * @arg SDMMC_FLAG_CMDSENT: Command sent (no response required)
495 * @arg SDMMC_FLAG_DATAEND: Data end (data counter, DATACOUNT, is zero)
496 * @arg SDMMC_FLAG_DHOLD: Data transfer Hold
497 * @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed)
498 * @arg SDMMC_FLAG_DABORT: Data transfer aborted by CMD12
499 * @arg SDMMC_FLAG_DPSMACT: Data path state machine active
500 * @arg SDMMC_FLAG_CPSMACT: Command path state machine active
501 * @arg SDMMC_FLAG_TXFIFOHE: Transmit FIFO Half Empty
502 * @arg SDMMC_FLAG_RXFIFOHF: Receive FIFO Half Full
503 * @arg SDMMC_FLAG_TXFIFOF: Transmit FIFO full
504 * @arg SDMMC_FLAG_RXFIFOF: Receive FIFO full
505 * @arg SDMMC_FLAG_TXFIFOE: Transmit FIFO empty
506 * @arg SDMMC_FLAG_RXFIFOE: Receive FIFO empty
507 * @arg SDMMC_FLAG_BUSYD0: Inverted value of SDMMC_D0 line (Busy)
508 * @arg SDMMC_FLAG_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected
509 * @arg SDMMC_FLAG_SDIOIT: SDIO interrupt received
510 * @arg SDMMC_FLAG_ACKFAIL: Boot Acknowledgment received
511 * @arg SDMMC_FLAG_ACKTIMEOUT: Boot Acknowledgment timeout
512 * @arg SDMMC_FLAG_VSWEND: Voltage switch critical timing section completion
513 * @arg SDMMC_FLAG_CKSTOP: SDMMC_CK stopped in Voltage switch procedure
514 * @arg SDMMC_FLAG_IDMATE: IDMA transfer error
515 * @arg SDMMC_FLAG_IDMABTC: IDMA buffer transfer complete
516 * @retval The new state of SD FLAG (SET or RESET).
518 #define __HAL_SD_GET_FLAG(__HANDLE__, __FLAG__) __SDMMC_GET_FLAG((__HANDLE__)->Instance, (__FLAG__))
521 * @brief Clear the SD's pending flags.
522 * @param __HANDLE__ SD Handle.
523 * @param __FLAG__ specifies the flag to clear.
524 * This parameter can be one or a combination of the following values:
525 * @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed)
526 * @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
527 * @arg SDMMC_FLAG_CTIMEOUT: Command response timeout
528 * @arg SDMMC_FLAG_DTIMEOUT: Data timeout
529 * @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error
530 * @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error
531 * @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed)
532 * @arg SDMMC_FLAG_CMDSENT: Command sent (no response required)
533 * @arg SDMMC_FLAG_DATAEND: Data end (data counter, DATACOUNT, is zero)
534 * @arg SDMMC_FLAG_DHOLD: Data transfer Hold
535 * @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed)
536 * @arg SDMMC_FLAG_DABORT: Data transfer aborted by CMD12
537 * @arg SDMMC_FLAG_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected
538 * @arg SDMMC_FLAG_SDIOIT: SDIO interrupt received
539 * @arg SDMMC_FLAG_ACKFAIL: Boot Acknowledgment received
540 * @arg SDMMC_FLAG_ACKTIMEOUT: Boot Acknowledgment timeout
541 * @arg SDMMC_FLAG_VSWEND: Voltage switch critical timing section completion
542 * @arg SDMMC_FLAG_CKSTOP: SDMMC_CK stopped in Voltage switch procedure
543 * @arg SDMMC_FLAG_IDMATE: IDMA transfer error
544 * @arg SDMMC_FLAG_IDMABTC: IDMA buffer transfer complete
547 #define __HAL_SD_CLEAR_FLAG(__HANDLE__, __FLAG__) __SDMMC_CLEAR_FLAG((__HANDLE__)->Instance, (__FLAG__))
550 * @brief Check whether the specified SD interrupt has occurred or not.
551 * @param __HANDLE__ SD Handle.
552 * @param __INTERRUPT__ specifies the SDMMC interrupt source to check.
553 * This parameter can be one of the following values:
554 * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
555 * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
556 * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
557 * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
558 * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
559 * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
560 * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
561 * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
562 * @arg SDMMC_IT_DATAEND: Data end (data counter, DATACOUNT, is zero) interrupt
563 * @arg SDMMC_IT_DHOLD: Data transfer Hold interrupt
564 * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
565 * @arg SDMMC_IT_DABORT: Data transfer aborted by CMD12 interrupt
566 * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
567 * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
568 * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
569 * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
570 * @arg SDMMC_IT_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected interrupt
571 * @arg SDMMC_IT_SDIOIT: SDIO interrupt received interrupt
572 * @arg SDMMC_IT_ACKFAIL: Boot Acknowledgment received interrupt
573 * @arg SDMMC_IT_ACKTIMEOUT: Boot Acknowledgment timeout interrupt
574 * @arg SDMMC_IT_VSWEND: Voltage switch critical timing section completion interrupt
575 * @arg SDMMC_IT_CKSTOP: SDMMC_CK stopped in Voltage switch procedure interrupt
576 * @arg SDMMC_IT_IDMABTC: IDMA buffer transfer complete interrupt
577 * @retval The new state of SD IT (SET or RESET).
579 #define __HAL_SD_GET_IT(__HANDLE__, __INTERRUPT__) __SDMMC_GET_IT((__HANDLE__)->Instance, (__INTERRUPT__))
582 * @brief Clear the SD's interrupt pending bits.
583 * @param __HANDLE__ SD Handle.
584 * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
585 * This parameter can be one or a combination of the following values:
586 * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
587 * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
588 * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
589 * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
590 * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
591 * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
592 * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
593 * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
594 * @arg SDMMC_IT_DATAEND: Data end (data counter, DATACOUNT, is zero) interrupt
595 * @arg SDMMC_IT_DHOLD: Data transfer Hold interrupt
596 * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
597 * @arg SDMMC_IT_DABORT: Data transfer aborted by CMD12 interrupt
598 * @arg SDMMC_IT_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected interrupt
599 * @arg SDMMC_IT_SDIOIT: SDIO interrupt received interrupt
600 * @arg SDMMC_IT_ACKFAIL: Boot Acknowledgment received interrupt
601 * @arg SDMMC_IT_ACKTIMEOUT: Boot Acknowledgment timeout interrupt
602 * @arg SDMMC_IT_VSWEND: Voltage switch critical timing section completion interrupt
603 * @arg SDMMC_IT_CKSTOP: SDMMC_CK stopped in Voltage switch procedure interrupt
604 * @arg SDMMC_IT_IDMABTC: IDMA buffer transfer complete interrupt
607 #define __HAL_SD_CLEAR_IT(__HANDLE__, __INTERRUPT__) __SDMMC_CLEAR_IT((__HANDLE__)->Instance, (__INTERRUPT__))
613 /* Include SD HAL Extension module */
614 #include "stm32h7xx_hal_sd_ex.h"
616 /* Exported functions --------------------------------------------------------*/
617 /** @defgroup SD_Exported_Functions SD Exported Functions
621 /** @defgroup SD_Exported_Functions_Group1 Initialization and de-initialization functions
624 HAL_StatusTypeDef
HAL_SD_Init (SD_HandleTypeDef
*hsd
);
625 HAL_StatusTypeDef
HAL_SD_InitCard (SD_HandleTypeDef
*hsd
);
626 HAL_StatusTypeDef
HAL_SD_DeInit (SD_HandleTypeDef
*hsd
);
627 void HAL_SD_MspInit (SD_HandleTypeDef
*hsd
);
628 void HAL_SD_MspDeInit(SD_HandleTypeDef
*hsd
);
633 /** @defgroup SD_Exported_Functions_Group2 Input and Output operation functions
636 /* Blocking mode: Polling */
637 HAL_StatusTypeDef
HAL_SD_ReadBlocks (SD_HandleTypeDef
*hsd
, uint8_t *pData
, uint32_t BlockAdd
, uint32_t NumberOfBlocks
, uint32_t Timeout
);
638 HAL_StatusTypeDef
HAL_SD_WriteBlocks (SD_HandleTypeDef
*hsd
, uint8_t *pData
, uint32_t BlockAdd
, uint32_t NumberOfBlocks
, uint32_t Timeout
);
639 HAL_StatusTypeDef
HAL_SD_Erase (SD_HandleTypeDef
*hsd
, uint32_t BlockStartAdd
, uint32_t BlockEndAdd
);
640 /* Non-Blocking mode: IT */
641 HAL_StatusTypeDef
HAL_SD_ReadBlocks_IT (SD_HandleTypeDef
*hsd
, uint8_t *pData
, uint32_t BlockAdd
, uint32_t NumberOfBlocks
);
642 HAL_StatusTypeDef
HAL_SD_WriteBlocks_IT (SD_HandleTypeDef
*hsd
, uint8_t *pData
, uint32_t BlockAdd
, uint32_t NumberOfBlocks
);
643 /* Non-Blocking mode: DMA */
644 HAL_StatusTypeDef
HAL_SD_ReadBlocks_DMA (SD_HandleTypeDef
*hsd
, uint8_t *pData
, uint32_t BlockAdd
, uint32_t NumberOfBlocks
);
645 HAL_StatusTypeDef
HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef
*hsd
, uint8_t *pData
, uint32_t BlockAdd
, uint32_t NumberOfBlocks
);
647 void HAL_SD_IRQHandler (SD_HandleTypeDef
*hsd
);
649 /* Callback in non blocking modes (DMA) */
650 void HAL_SD_TxCpltCallback (SD_HandleTypeDef
*hsd
);
651 void HAL_SD_RxCpltCallback (SD_HandleTypeDef
*hsd
);
652 void HAL_SD_ErrorCallback (SD_HandleTypeDef
*hsd
);
653 void HAL_SD_AbortCallback (SD_HandleTypeDef
*hsd
);
655 #if (USE_SD_TRANSCEIVER != 0U)
656 /* Callback to switch in 1.8V mode */
657 void HAL_SD_DriveTransceiver_1_8V_Callback(FlagStatus status
);
658 #endif /* USE_SD_TRANSCEIVER */
660 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
661 /* SD callback registering/unregistering */
662 HAL_StatusTypeDef
HAL_SD_RegisterCallback (SD_HandleTypeDef
*hsd
, HAL_SD_CallbackIDTypeDef CallbackID
, pSD_CallbackTypeDef pCallback
);
663 HAL_StatusTypeDef
HAL_SD_UnRegisterCallback(SD_HandleTypeDef
*hsd
, HAL_SD_CallbackIDTypeDef CallbackID
);
665 #if (USE_SD_TRANSCEIVER != 0U)
666 HAL_StatusTypeDef
HAL_SD_RegisterTransceiverCallback (SD_HandleTypeDef
*hsd
, pSD_TransceiverCallbackTypeDef pCallback
);
667 HAL_StatusTypeDef
HAL_SD_UnRegisterTransceiverCallback(SD_HandleTypeDef
*hsd
);
668 #endif /* USE_SD_TRANSCEIVER */
669 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
675 /** @defgroup SD_Exported_Functions_Group3 Peripheral Control functions
678 HAL_StatusTypeDef
HAL_SD_ConfigWideBusOperation(SD_HandleTypeDef
*hsd
, uint32_t WideMode
);
679 HAL_StatusTypeDef
HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef
*hsd
, uint32_t SpeedMode
);
684 /** @defgroup SD_Exported_Functions_Group4 SD card related functions
687 HAL_SD_CardStateTypeDef
HAL_SD_GetCardState(SD_HandleTypeDef
*hsd
);
688 HAL_StatusTypeDef
HAL_SD_GetCardCID (SD_HandleTypeDef
*hsd
, HAL_SD_CardCIDTypeDef
*pCID
);
689 HAL_StatusTypeDef
HAL_SD_GetCardCSD (SD_HandleTypeDef
*hsd
, HAL_SD_CardCSDTypeDef
*pCSD
);
690 HAL_StatusTypeDef
HAL_SD_GetCardStatus(SD_HandleTypeDef
*hsd
, HAL_SD_CardStatusTypeDef
*pStatus
);
691 HAL_StatusTypeDef
HAL_SD_GetCardInfo (SD_HandleTypeDef
*hsd
, HAL_SD_CardInfoTypeDef
*pCardInfo
);
696 /** @defgroup SD_Exported_Functions_Group5 Peripheral State and Errors functions
699 HAL_SD_StateTypeDef
HAL_SD_GetState(SD_HandleTypeDef
*hsd
);
700 uint32_t HAL_SD_GetError(SD_HandleTypeDef
*hsd
);
705 /** @defgroup SD_Exported_Functions_Group6 Perioheral Abort management
708 HAL_StatusTypeDef
HAL_SD_Abort (SD_HandleTypeDef
*hsd
);
709 HAL_StatusTypeDef
HAL_SD_Abort_IT(SD_HandleTypeDef
*hsd
);
714 /* Private types -------------------------------------------------------------*/
715 /** @defgroup SD_Private_Types SD Private Types
723 /* Private defines -----------------------------------------------------------*/
724 /** @defgroup SD_Private_Defines SD Private Defines
732 /* Private variables ---------------------------------------------------------*/
733 /** @defgroup SD_Private_Variables SD Private Variables
741 /* Private constants ---------------------------------------------------------*/
742 /** @defgroup SD_Private_Constants SD Private Constants
750 /* Private macros ------------------------------------------------------------*/
751 /** @defgroup SD_Private_Macros SD Private Macros
759 /* Private functions prototypes ----------------------------------------------*/
760 /** @defgroup SD_Private_Functions_Prototypes SD Private Functions Prototypes
768 /* Private functions ---------------------------------------------------------*/
769 /** @defgroup SD_Private_Functions SD Private Functions
795 #endif /* STM32H7xx_HAL_SD_H */
797 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/