stm32f7xx_hal_sd.h
Go to the documentation of this file.
1 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32F7xx_HAL_SD_H
22 #define STM32F7xx_HAL_SD_H
23 
24 #ifdef __cplusplus
25  extern "C" {
26 #endif
27 
28 #if defined(SDMMC1)
29 
30 /* Includes ------------------------------------------------------------------*/
31 #include "stm32f7xx_ll_sdmmc.h"
32 
42 /* Exported types ------------------------------------------------------------*/
50 typedef enum
51 {
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
60 }HAL_SD_StateTypeDef;
68 typedef uint32_t HAL_SD_CardStateTypeDef;
69 
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
88 
92 typedef struct
93 {
94  uint32_t CardType;
96  uint32_t CardVersion;
98  uint32_t Class;
100  uint32_t RelCardAdd;
102  uint32_t BlockNbr;
104  uint32_t BlockSize;
106  uint32_t LogBlockNbr;
108  uint32_t LogBlockSize;
110 }HAL_SD_CardInfoTypeDef;
111 
115 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
116 typedef struct __SD_HandleTypeDef
117 #else
118 typedef struct
119 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
120 {
121  SD_TypeDef *Instance;
123  SD_InitTypeDef Init;
125  HAL_LockTypeDef Lock;
127  uint8_t *pTxBuffPtr;
129  uint32_t TxXferSize;
131  uint8_t *pRxBuffPtr;
133  uint32_t RxXferSize;
135  __IO uint32_t Context;
137  __IO HAL_SD_StateTypeDef State;
139  __IO uint32_t ErrorCode;
141  DMA_HandleTypeDef *hdmatx;
143  DMA_HandleTypeDef *hdmarx;
145  HAL_SD_CardInfoTypeDef SdCard;
147  uint32_t CSD[4];
149  uint32_t CID[4];
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);
156 
157  void (* MspInitCallback) (struct __SD_HandleTypeDef *hsd);
158  void (* MspDeInitCallback) (struct __SD_HandleTypeDef *hsd);
159 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
160 }SD_HandleTypeDef;
161 
169 typedef struct
170 {
171  __IO uint8_t CSDStruct;
172  __IO uint8_t SysSpecVersion;
173  __IO uint8_t Reserved1;
174  __IO uint8_t TAAC;
175  __IO uint8_t NSAC;
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;
205  __IO uint8_t ECC;
206  __IO uint8_t CSD_CRC;
207  __IO uint8_t Reserved4;
208 }HAL_SD_CardCSDTypeDef;
216 typedef struct
217 {
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;
237 typedef struct
238 {
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)
256 
259 typedef enum
260 {
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);
280 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
281 
285 /* Exported constants --------------------------------------------------------*/
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
334 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
335 
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
360 
368 #define CARD_V1_X 0x00000000U
369 #define CARD_V2_X 0x00000001U
370 
378 /* Exported macro ------------------------------------------------------------*/
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; \
392  } while(0)
393 #else
394 #define __HAL_SD_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SD_STATE_RESET)
395 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
396 
401 #define __HAL_SD_ENABLE(__HANDLE__) __SDMMC_ENABLE((__HANDLE__)->Instance)
402 
407 #define __HAL_SD_DISABLE(__HANDLE__) __SDMMC_DISABLE((__HANDLE__)->Instance)
408 
413 #define __HAL_SD_DMA_ENABLE(__HANDLE__) __SDMMC_DMA_ENABLE((__HANDLE__)->Instance)
414 
419 #define __HAL_SD_DMA_DISABLE(__HANDLE__) __SDMMC_DMA_DISABLE((__HANDLE__)->Instance)
420 
450 #define __HAL_SD_ENABLE_IT(__HANDLE__, __INTERRUPT__) __SDMMC_ENABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
451 
481 #define __HAL_SD_DISABLE_IT(__HANDLE__, __INTERRUPT__) __SDMMC_DISABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
482 
512 #define __HAL_SD_GET_FLAG(__HANDLE__, __FLAG__) __SDMMC_GET_FLAG((__HANDLE__)->Instance, (__FLAG__))
513 
532 #define __HAL_SD_CLEAR_FLAG(__HANDLE__, __FLAG__) __SDMMC_CLEAR_FLAG((__HANDLE__)->Instance, (__FLAG__))
533 
563 #define __HAL_SD_GET_IT(__HANDLE__, __INTERRUPT__) __SDMMC_GET_IT((__HANDLE__)->Instance, (__INTERRUPT__))
564 
582 #define __HAL_SD_CLEAR_IT(__HANDLE__, __INTERRUPT__) __SDMMC_CLEAR_IT((__HANDLE__)->Instance, (__INTERRUPT__))
583 
588 /* Exported functions --------------------------------------------------------*/
596 HAL_StatusTypeDef HAL_SD_Init(SD_HandleTypeDef *hsd);
597 HAL_StatusTypeDef HAL_SD_InitCard(SD_HandleTypeDef *hsd);
598 HAL_StatusTypeDef HAL_SD_DeInit (SD_HandleTypeDef *hsd);
599 void HAL_SD_MspInit(SD_HandleTypeDef *hsd);
600 void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd);
608 /* Blocking mode: Polling */
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);
612 /* Non-Blocking mode: IT */
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);
615 /* Non-Blocking mode: DMA */
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);
618 
619 void HAL_SD_IRQHandler(SD_HandleTypeDef *hsd);
620 
621 /* Callback in non blocking modes (DMA) */
622 void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd);
623 void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd);
624 void HAL_SD_ErrorCallback(SD_HandleTypeDef *hsd);
625 void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd);
626 
627 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
628 /* SD callback registering/unregistering */
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);
631 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
632 
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);
670 HAL_StatusTypeDef HAL_SD_Abort(SD_HandleTypeDef *hsd);
671 HAL_StatusTypeDef HAL_SD_Abort_IT(SD_HandleTypeDef *hsd);
676 /* Private types -------------------------------------------------------------*/
685 /* Private defines -----------------------------------------------------------*/
694 /* Private variables ---------------------------------------------------------*/
703 /* Private constants ---------------------------------------------------------*/
712 /* Private macros ------------------------------------------------------------*/
721 /* Private functions prototypes ----------------------------------------------*/
730 /* Private functions ---------------------------------------------------------*/
752 #endif /* SDMMC1 */
753 
754 #ifdef __cplusplus
755 }
756 #endif
757 
758 
759 #endif /* STM32F7xx_HAL_SD_H */
760 
761 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
__IO
#define __IO
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:237
Init
napi_value Init(napi_env env, napi_value exports)
Definition: porcupine/demo/c/pvrecorder/node/pv_recorder_napi.c:197
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:40
stm32f7xx_ll_sdmmc.h
Header file of SDMMC HAL module.
__DMA_HandleTypeDef
DMA handle Structure definition.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:139
HAL_LockTypeDef
HAL_LockTypeDef
HAL Lock structures definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:51
HAL_SD_AbortCallback
void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd)
SD Abort callbacks.
Definition: stm32f769i_discovery_sd.c:543
HAL_SD_TxCpltCallback
void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
Tx Transfer completed callbacks.
Definition: stm32f769i_discovery_sd.c:553
HAL_SD_RxCpltCallback
void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
Rx Transfer completed callbacks.
Definition: stm32f769i_discovery_sd.c:563


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:53