21 #ifndef STM32F7xx_HAL_SD_H
22 #define STM32F7xx_HAL_SD_H
52 HAL_SD_STATE_RESET = 0x00000000U,
53 HAL_SD_STATE_READY = 0x00000001U,
54 HAL_SD_STATE_TIMEOUT = 0x00000002U,
55 HAL_SD_STATE_BUSY = 0x00000003U,
56 HAL_SD_STATE_PROGRAMMING = 0x00000004U,
57 HAL_SD_STATE_RECEIVING = 0x00000005U,
58 HAL_SD_STATE_TRANSFER = 0x00000006U,
59 HAL_SD_STATE_ERROR = 0x0000000FU
68 typedef uint32_t HAL_SD_CardStateTypeDef;
70 #define HAL_SD_CARD_READY 0x00000001U
71 #define HAL_SD_CARD_IDENTIFICATION 0x00000002U
72 #define HAL_SD_CARD_STANDBY 0x00000003U
73 #define HAL_SD_CARD_TRANSFER 0x00000004U
74 #define HAL_SD_CARD_SENDING 0x00000005U
75 #define HAL_SD_CARD_RECEIVING 0x00000006U
76 #define HAL_SD_CARD_PROGRAMMING 0x00000007U
77 #define HAL_SD_CARD_DISCONNECTED 0x00000008U
78 #define HAL_SD_CARD_ERROR 0x000000FFU
86 #define SD_InitTypeDef SDMMC_InitTypeDef
87 #define SD_TypeDef SDMMC_TypeDef
106 uint32_t LogBlockNbr;
108 uint32_t LogBlockSize;
110 }HAL_SD_CardInfoTypeDef;
115 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
116 typedef struct __SD_HandleTypeDef
121 SD_TypeDef *Instance;
135 __IO uint32_t Context;
137 __IO HAL_SD_StateTypeDef State;
139 __IO uint32_t ErrorCode;
145 HAL_SD_CardInfoTypeDef SdCard;
151 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
152 void (* TxCpltCallback) (
struct __SD_HandleTypeDef *hsd);
153 void (* RxCpltCallback) (
struct __SD_HandleTypeDef *hsd);
154 void (* ErrorCallback) (
struct __SD_HandleTypeDef *hsd);
155 void (* AbortCpltCallback) (
struct __SD_HandleTypeDef *hsd);
157 void (* MspInitCallback) (
struct __SD_HandleTypeDef *hsd);
158 void (* MspDeInitCallback) (
struct __SD_HandleTypeDef *hsd);
171 __IO uint8_t CSDStruct;
172 __IO uint8_t SysSpecVersion;
173 __IO uint8_t Reserved1;
176 __IO uint8_t MaxBusClkFrec;
177 __IO uint16_t CardComdClasses;
178 __IO uint8_t RdBlockLen;
179 __IO uint8_t PartBlockRead;
180 __IO uint8_t WrBlockMisalign;
181 __IO uint8_t RdBlockMisalign;
182 __IO uint8_t DSRImpl;
183 __IO uint8_t Reserved2;
184 __IO uint32_t DeviceSize;
185 __IO uint8_t MaxRdCurrentVDDMin;
186 __IO uint8_t MaxRdCurrentVDDMax;
187 __IO uint8_t MaxWrCurrentVDDMin;
188 __IO uint8_t MaxWrCurrentVDDMax;
189 __IO uint8_t DeviceSizeMul;
190 __IO uint8_t EraseGrSize;
191 __IO uint8_t EraseGrMul;
192 __IO uint8_t WrProtectGrSize;
193 __IO uint8_t WrProtectGrEnable;
194 __IO uint8_t ManDeflECC;
195 __IO uint8_t WrSpeedFact;
196 __IO uint8_t MaxWrBlockLen;
197 __IO uint8_t WriteBlockPaPartial;
198 __IO uint8_t Reserved3;
199 __IO uint8_t ContentProtectAppli;
200 __IO uint8_t FileFormatGroup;
201 __IO uint8_t CopyFlag;
202 __IO uint8_t PermWrProtect;
203 __IO uint8_t TempWrProtect;
204 __IO uint8_t FileFormat;
206 __IO uint8_t CSD_CRC;
207 __IO uint8_t Reserved4;
208 }HAL_SD_CardCSDTypeDef;
218 __IO uint8_t ManufacturerID;
219 __IO uint16_t OEM_AppliID;
220 __IO uint32_t ProdName1;
221 __IO uint8_t ProdName2;
222 __IO uint8_t ProdRev;
223 __IO uint32_t ProdSN;
224 __IO uint8_t Reserved1;
225 __IO uint16_t ManufactDate;
226 __IO uint8_t CID_CRC;
227 __IO uint8_t Reserved2;
229 }HAL_SD_CardCIDTypeDef;
239 __IO uint8_t DataBusWidth;
240 __IO uint8_t SecuredMode;
241 __IO uint16_t CardType;
242 __IO uint32_t ProtectedAreaSize;
243 __IO uint8_t SpeedClass;
244 __IO uint8_t PerformanceMove;
245 __IO uint8_t AllocationUnitSize;
246 __IO uint16_t EraseSize;
247 __IO uint8_t EraseTimeout;
248 __IO uint8_t EraseOffset;
250 }HAL_SD_CardStatusTypeDef;
255 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
261 HAL_SD_TX_CPLT_CB_ID = 0x00U,
262 HAL_SD_RX_CPLT_CB_ID = 0x01U,
263 HAL_SD_ERROR_CB_ID = 0x02U,
264 HAL_SD_ABORT_CB_ID = 0x03U,
266 HAL_SD_MSP_INIT_CB_ID = 0x10U,
267 HAL_SD_MSP_DEINIT_CB_ID = 0x11U
268 }HAL_SD_CallbackIDTypeDef;
276 typedef void (*pSD_CallbackTypeDef) (SD_HandleTypeDef *hsd);
290 #define BLOCKSIZE 512U
295 #define HAL_SD_ERROR_NONE SDMMC_ERROR_NONE
296 #define HAL_SD_ERROR_CMD_CRC_FAIL SDMMC_ERROR_CMD_CRC_FAIL
297 #define HAL_SD_ERROR_DATA_CRC_FAIL SDMMC_ERROR_DATA_CRC_FAIL
298 #define HAL_SD_ERROR_CMD_RSP_TIMEOUT SDMMC_ERROR_CMD_RSP_TIMEOUT
299 #define HAL_SD_ERROR_DATA_TIMEOUT SDMMC_ERROR_DATA_TIMEOUT
300 #define HAL_SD_ERROR_TX_UNDERRUN SDMMC_ERROR_TX_UNDERRUN
301 #define HAL_SD_ERROR_RX_OVERRUN SDMMC_ERROR_RX_OVERRUN
302 #define HAL_SD_ERROR_ADDR_MISALIGNED SDMMC_ERROR_ADDR_MISALIGNED
303 #define HAL_SD_ERROR_BLOCK_LEN_ERR SDMMC_ERROR_BLOCK_LEN_ERR
305 #define HAL_SD_ERROR_ERASE_SEQ_ERR SDMMC_ERROR_ERASE_SEQ_ERR
306 #define HAL_SD_ERROR_BAD_ERASE_PARAM SDMMC_ERROR_BAD_ERASE_PARAM
307 #define HAL_SD_ERROR_WRITE_PROT_VIOLATION SDMMC_ERROR_WRITE_PROT_VIOLATION
308 #define HAL_SD_ERROR_LOCK_UNLOCK_FAILED SDMMC_ERROR_LOCK_UNLOCK_FAILED
310 #define HAL_SD_ERROR_COM_CRC_FAILED SDMMC_ERROR_COM_CRC_FAILED
311 #define HAL_SD_ERROR_ILLEGAL_CMD SDMMC_ERROR_ILLEGAL_CMD
312 #define HAL_SD_ERROR_CARD_ECC_FAILED SDMMC_ERROR_CARD_ECC_FAILED
313 #define HAL_SD_ERROR_CC_ERR SDMMC_ERROR_CC_ERR
314 #define HAL_SD_ERROR_GENERAL_UNKNOWN_ERR SDMMC_ERROR_GENERAL_UNKNOWN_ERR
315 #define HAL_SD_ERROR_STREAM_READ_UNDERRUN SDMMC_ERROR_STREAM_READ_UNDERRUN
316 #define HAL_SD_ERROR_STREAM_WRITE_OVERRUN SDMMC_ERROR_STREAM_WRITE_OVERRUN
317 #define HAL_SD_ERROR_CID_CSD_OVERWRITE SDMMC_ERROR_CID_CSD_OVERWRITE
318 #define HAL_SD_ERROR_WP_ERASE_SKIP SDMMC_ERROR_WP_ERASE_SKIP
319 #define HAL_SD_ERROR_CARD_ECC_DISABLED SDMMC_ERROR_CARD_ECC_DISABLED
320 #define HAL_SD_ERROR_ERASE_RESET SDMMC_ERROR_ERASE_RESET
322 #define HAL_SD_ERROR_AKE_SEQ_ERR SDMMC_ERROR_AKE_SEQ_ERR
323 #define HAL_SD_ERROR_INVALID_VOLTRANGE SDMMC_ERROR_INVALID_VOLTRANGE
324 #define HAL_SD_ERROR_ADDR_OUT_OF_RANGE SDMMC_ERROR_ADDR_OUT_OF_RANGE
325 #define HAL_SD_ERROR_REQUEST_NOT_APPLICABLE SDMMC_ERROR_REQUEST_NOT_APPLICABLE
326 #define HAL_SD_ERROR_PARAM SDMMC_ERROR_INVALID_PARAMETER
327 #define HAL_SD_ERROR_UNSUPPORTED_FEATURE SDMMC_ERROR_UNSUPPORTED_FEATURE
328 #define HAL_SD_ERROR_BUSY SDMMC_ERROR_BUSY
329 #define HAL_SD_ERROR_DMA SDMMC_ERROR_DMA
330 #define HAL_SD_ERROR_TIMEOUT SDMMC_ERROR_TIMEOUT
332 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
333 #define HAL_SD_ERROR_INVALID_CALLBACK SDMMC_ERROR_INVALID_PARAMETER
342 #define SD_CONTEXT_NONE 0x00000000U
343 #define SD_CONTEXT_READ_SINGLE_BLOCK 0x00000001U
344 #define SD_CONTEXT_READ_MULTIPLE_BLOCK 0x00000002U
345 #define SD_CONTEXT_WRITE_SINGLE_BLOCK 0x00000010U
346 #define SD_CONTEXT_WRITE_MULTIPLE_BLOCK 0x00000020U
347 #define SD_CONTEXT_IT 0x00000008U
348 #define SD_CONTEXT_DMA 0x00000080U
357 #define CARD_SDSC 0x00000000U
358 #define CARD_SDHC_SDXC 0x00000001U
359 #define CARD_SECURED 0x00000003U
368 #define CARD_V1_X 0x00000000U
369 #define CARD_V2_X 0x00000001U
387 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
388 #define __HAL_SD_RESET_HANDLE_STATE(__HANDLE__) do { \
389 (__HANDLE__)->State = HAL_SD_STATE_RESET; \
390 (__HANDLE__)->MspInitCallback = NULL; \
391 (__HANDLE__)->MspDeInitCallback = NULL; \
394 #define __HAL_SD_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SD_STATE_RESET)
401 #define __HAL_SD_ENABLE(__HANDLE__) __SDMMC_ENABLE((__HANDLE__)->Instance)
407 #define __HAL_SD_DISABLE(__HANDLE__) __SDMMC_DISABLE((__HANDLE__)->Instance)
413 #define __HAL_SD_DMA_ENABLE(__HANDLE__) __SDMMC_DMA_ENABLE((__HANDLE__)->Instance)
419 #define __HAL_SD_DMA_DISABLE(__HANDLE__) __SDMMC_DMA_DISABLE((__HANDLE__)->Instance)
450 #define __HAL_SD_ENABLE_IT(__HANDLE__, __INTERRUPT__) __SDMMC_ENABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
481 #define __HAL_SD_DISABLE_IT(__HANDLE__, __INTERRUPT__) __SDMMC_DISABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
512 #define __HAL_SD_GET_FLAG(__HANDLE__, __FLAG__) __SDMMC_GET_FLAG((__HANDLE__)->Instance, (__FLAG__))
532 #define __HAL_SD_CLEAR_FLAG(__HANDLE__, __FLAG__) __SDMMC_CLEAR_FLAG((__HANDLE__)->Instance, (__FLAG__))
563 #define __HAL_SD_GET_IT(__HANDLE__, __INTERRUPT__) __SDMMC_GET_IT((__HANDLE__)->Instance, (__INTERRUPT__))
582 #define __HAL_SD_CLEAR_IT(__HANDLE__, __INTERRUPT__) __SDMMC_CLEAR_IT((__HANDLE__)->Instance, (__INTERRUPT__))
599 void HAL_SD_MspInit(SD_HandleTypeDef *hsd);
600 void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd);
609 HAL_StatusTypeDef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout);
610 HAL_StatusTypeDef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout);
611 HAL_StatusTypeDef HAL_SD_Erase(SD_HandleTypeDef *hsd, uint32_t BlockStartAdd, uint32_t BlockEndAdd);
613 HAL_StatusTypeDef HAL_SD_ReadBlocks_IT(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
614 HAL_StatusTypeDef HAL_SD_WriteBlocks_IT(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
616 HAL_StatusTypeDef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
617 HAL_StatusTypeDef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
619 void HAL_SD_IRQHandler(SD_HandleTypeDef *hsd);
624 void HAL_SD_ErrorCallback(SD_HandleTypeDef *hsd);
627 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
629 HAL_StatusTypeDef HAL_SD_RegisterCallback (SD_HandleTypeDef *hsd, HAL_SD_CallbackIDTypeDef CallbackId, pSD_CallbackTypeDef pCallback);
630 HAL_StatusTypeDef HAL_SD_UnRegisterCallback(SD_HandleTypeDef *hsd, HAL_SD_CallbackIDTypeDef CallbackId);
640 HAL_StatusTypeDef HAL_SD_ConfigWideBusOperation(SD_HandleTypeDef *hsd, uint32_t WideMode);
648 HAL_StatusTypeDef HAL_SD_SendSDStatus(SD_HandleTypeDef *hsd, uint32_t *pSDstatus);
649 HAL_SD_CardStateTypeDef HAL_SD_GetCardState(SD_HandleTypeDef *hsd);
650 HAL_StatusTypeDef HAL_SD_GetCardCID(SD_HandleTypeDef *hsd, HAL_SD_CardCIDTypeDef *pCID);
651 HAL_StatusTypeDef HAL_SD_GetCardCSD(SD_HandleTypeDef *hsd, HAL_SD_CardCSDTypeDef *pCSD);
652 HAL_StatusTypeDef HAL_SD_GetCardStatus(SD_HandleTypeDef *hsd, HAL_SD_CardStatusTypeDef *pStatus);
653 HAL_StatusTypeDef HAL_SD_GetCardInfo(SD_HandleTypeDef *hsd, HAL_SD_CardInfoTypeDef *pCardInfo);
661 HAL_SD_StateTypeDef HAL_SD_GetState(SD_HandleTypeDef *hsd);
662 uint32_t HAL_SD_GetError(SD_HandleTypeDef *hsd);