You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

717 lines
35 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_sd.h
  4. * @author MCD Application Team
  5. * @version V1.2.2
  6. * @date 14-April-2017
  7. * @brief Header file of SD HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  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.
  23. *
  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.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_HAL_SD_H
  39. #define __STM32F7xx_HAL_SD_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_ll_sdmmc.h"
  45. /** @addtogroup STM32F7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @defgroup SD SD
  49. * @brief SD HAL module driver
  50. * @{
  51. */
  52. /* Exported types ------------------------------------------------------------*/
  53. /** @defgroup SD_Exported_Types SD Exported Types
  54. * @{
  55. */
  56. /** @defgroup SD_Exported_Types_Group1 SD State enumeration structure
  57. * @{
  58. */
  59. typedef enum
  60. {
  61. HAL_SD_STATE_RESET = ((uint32_t)0x00000000U), /*!< SD not yet initialized or disabled */
  62. HAL_SD_STATE_READY = ((uint32_t)0x00000001U), /*!< SD initialized and ready for use */
  63. HAL_SD_STATE_TIMEOUT = ((uint32_t)0x00000002U), /*!< SD Timeout state */
  64. HAL_SD_STATE_BUSY = ((uint32_t)0x00000003U), /*!< SD process ongoing */
  65. HAL_SD_STATE_PROGRAMMING = ((uint32_t)0x00000004U), /*!< SD Programming State */
  66. HAL_SD_STATE_RECEIVING = ((uint32_t)0x00000005U), /*!< SD Receinving State */
  67. HAL_SD_STATE_TRANSFER = ((uint32_t)0x00000006U), /*!< SD Transfert State */
  68. HAL_SD_STATE_ERROR = ((uint32_t)0x0000000FU) /*!< SD is in error state */
  69. }HAL_SD_StateTypeDef;
  70. /**
  71. * @}
  72. */
  73. /** @defgroup SD_Exported_Types_Group2 SD Card State enumeration structure
  74. * @{
  75. */
  76. typedef enum
  77. {
  78. HAL_SD_CARD_READY = ((uint32_t)0x00000001U), /*!< Card state is ready */
  79. HAL_SD_CARD_IDENTIFICATION = ((uint32_t)0x00000002U), /*!< Card is in identification state */
  80. HAL_SD_CARD_STANDBY = ((uint32_t)0x00000003U), /*!< Card is in standby state */
  81. HAL_SD_CARD_TRANSFER = ((uint32_t)0x00000004U), /*!< Card is in transfer state */
  82. HAL_SD_CARD_SENDING = ((uint32_t)0x00000005U), /*!< Card is sending an operation */
  83. HAL_SD_CARD_RECEIVING = ((uint32_t)0x00000006U), /*!< Card is receiving operation information */
  84. HAL_SD_CARD_PROGRAMMING = ((uint32_t)0x00000007U), /*!< Card is in programming state */
  85. HAL_SD_CARD_DISCONNECTED = ((uint32_t)0x00000008U), /*!< Card is disconnected */
  86. HAL_SD_CARD_ERROR = ((uint32_t)0x000000FFU) /*!< Card response Error */
  87. }HAL_SD_CardStateTypeDef;
  88. /**
  89. * @}
  90. */
  91. /** @defgroup SD_Exported_Types_Group3 SD Handle Structure definition
  92. * @{
  93. */
  94. #define SD_InitTypeDef SDMMC_InitTypeDef
  95. #define SD_TypeDef SDMMC_TypeDef
  96. /**
  97. * @brief SD Card Information Structure definition
  98. */
  99. typedef struct
  100. {
  101. uint32_t CardType; /*!< Specifies the card Type */
  102. uint32_t CardVersion; /*!< Specifies the card version */
  103. uint32_t Class; /*!< Specifies the class of the card class */
  104. uint32_t RelCardAdd; /*!< Specifies the Relative Card Address */
  105. uint32_t BlockNbr; /*!< Specifies the Card Capacity in blocks */
  106. uint32_t BlockSize; /*!< Specifies one block size in bytes */
  107. uint32_t LogBlockNbr; /*!< Specifies the Card logical Capacity in blocks */
  108. uint32_t LogBlockSize; /*!< Specifies logical block size in bytes */
  109. }HAL_SD_CardInfoTypeDef;
  110. /**
  111. * @brief SD handle Structure definition
  112. */
  113. typedef struct
  114. {
  115. SD_TypeDef *Instance; /*!< SD registers base address */
  116. SD_InitTypeDef Init; /*!< SD required parameters */
  117. HAL_LockTypeDef Lock; /*!< SD locking object */
  118. uint32_t *pTxBuffPtr; /*!< Pointer to SD Tx transfer Buffer */
  119. uint32_t TxXferSize; /*!< SD Tx Transfer size */
  120. uint32_t *pRxBuffPtr; /*!< Pointer to SD Rx transfer Buffer */
  121. uint32_t RxXferSize; /*!< SD Rx Transfer size */
  122. __IO uint32_t Context; /*!< SD transfer context */
  123. __IO HAL_SD_StateTypeDef State; /*!< SD card State */
  124. __IO uint32_t ErrorCode; /*!< SD Card Error codes */
  125. DMA_HandleTypeDef *hdmarx; /*!< SD Rx DMA handle parameters */
  126. DMA_HandleTypeDef *hdmatx; /*!< SD Tx DMA handle parameters */
  127. HAL_SD_CardInfoTypeDef SdCard; /*!< SD Card information */
  128. uint32_t CSD[4]; /*!< SD card specific data table */
  129. uint32_t CID[4]; /*!< SD card identification number table */
  130. }SD_HandleTypeDef;
  131. /**
  132. * @}
  133. */
  134. /** @defgroup SD_Exported_Types_Group4 Card Specific Data: CSD Register
  135. * @{
  136. */
  137. typedef struct
  138. {
  139. __IO uint8_t CSDStruct; /*!< CSD structure */
  140. __IO uint8_t SysSpecVersion; /*!< System specification version */
  141. __IO uint8_t Reserved1; /*!< Reserved */
  142. __IO uint8_t TAAC; /*!< Data read access time 1 */
  143. __IO uint8_t NSAC; /*!< Data read access time 2 in CLK cycles */
  144. __IO uint8_t MaxBusClkFrec; /*!< Max. bus clock frequency */
  145. __IO uint16_t CardComdClasses; /*!< Card command classes */
  146. __IO uint8_t RdBlockLen; /*!< Max. read data block length */
  147. __IO uint8_t PartBlockRead; /*!< Partial blocks for read allowed */
  148. __IO uint8_t WrBlockMisalign; /*!< Write block misalignment */
  149. __IO uint8_t RdBlockMisalign; /*!< Read block misalignment */
  150. __IO uint8_t DSRImpl; /*!< DSR implemented */
  151. __IO uint8_t Reserved2; /*!< Reserved */
  152. __IO uint32_t DeviceSize; /*!< Device Size */
  153. __IO uint8_t MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */
  154. __IO uint8_t MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */
  155. __IO uint8_t MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */
  156. __IO uint8_t MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */
  157. __IO uint8_t DeviceSizeMul; /*!< Device size multiplier */
  158. __IO uint8_t EraseGrSize; /*!< Erase group size */
  159. __IO uint8_t EraseGrMul; /*!< Erase group size multiplier */
  160. __IO uint8_t WrProtectGrSize; /*!< Write protect group size */
  161. __IO uint8_t WrProtectGrEnable; /*!< Write protect group enable */
  162. __IO uint8_t ManDeflECC; /*!< Manufacturer default ECC */
  163. __IO uint8_t WrSpeedFact; /*!< Write speed factor */
  164. __IO uint8_t MaxWrBlockLen; /*!< Max. write data block length */
  165. __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */
  166. __IO uint8_t Reserved3; /*!< Reserved */
  167. __IO uint8_t ContentProtectAppli; /*!< Content protection application */
  168. __IO uint8_t FileFormatGrouop; /*!< File format group */
  169. __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */
  170. __IO uint8_t PermWrProtect; /*!< Permanent write protection */
  171. __IO uint8_t TempWrProtect; /*!< Temporary write protection */
  172. __IO uint8_t FileFormat; /*!< File format */
  173. __IO uint8_t ECC; /*!< ECC code */
  174. __IO uint8_t CSD_CRC; /*!< CSD CRC */
  175. __IO uint8_t Reserved4; /*!< Always 1 */
  176. }HAL_SD_CardCSDTypeDef;
  177. /**
  178. * @}
  179. */
  180. /** @defgroup SD_Exported_Types_Group5 Card Identification Data: CID Register
  181. * @{
  182. */
  183. typedef struct
  184. {
  185. __IO uint8_t ManufacturerID; /*!< Manufacturer ID */
  186. __IO uint16_t OEM_AppliID; /*!< OEM/Application ID */
  187. __IO uint32_t ProdName1; /*!< Product Name part1 */
  188. __IO uint8_t ProdName2; /*!< Product Name part2 */
  189. __IO uint8_t ProdRev; /*!< Product Revision */
  190. __IO uint32_t ProdSN; /*!< Product Serial Number */
  191. __IO uint8_t Reserved1; /*!< Reserved1 */
  192. __IO uint16_t ManufactDate; /*!< Manufacturing Date */
  193. __IO uint8_t CID_CRC; /*!< CID CRC */
  194. __IO uint8_t Reserved2; /*!< Always 1 */
  195. }HAL_SD_CardCIDTypeDef;
  196. /**
  197. * @}
  198. */
  199. /** @defgroup SD_Exported_Types_Group6 SD Card Status returned by ACMD13
  200. * @{
  201. */
  202. typedef struct
  203. {
  204. __IO uint8_t DataBusWidth; /*!< Shows the currently defined data bus width */
  205. __IO uint8_t SecuredMode; /*!< Card is in secured mode of operation */
  206. __IO uint16_t CardType; /*!< Carries information about card type */
  207. __IO uint32_t ProtectedAreaSize; /*!< Carries information about the capacity of protected area */
  208. __IO uint8_t SpeedClass; /*!< Carries information about the speed class of the card */
  209. __IO uint8_t PerformanceMove; /*!< Carries information about the card's performance move */
  210. __IO uint8_t AllocationUnitSize; /*!< Carries information about the card's allocation unit size */
  211. __IO uint16_t EraseSize; /*!< Determines the number of AUs to be erased in one operation */
  212. __IO uint8_t EraseTimeout; /*!< Determines the timeout for any number of AU erase */
  213. __IO uint8_t EraseOffset; /*!< Carries information about the erase offset */
  214. }HAL_SD_CardStatusTypeDef;
  215. /**
  216. * @}
  217. */
  218. /**
  219. * @}
  220. */
  221. /* Exported constants --------------------------------------------------------*/
  222. /** @defgroup SD_Exported_Constants Exported Constants
  223. * @{
  224. */
  225. #define BLOCKSIZE ((uint32_t)512U) /*!< Block size is 512 bytes */
  226. /** @defgroup SD_Exported_Constansts_Group1 SD Error status enumeration Structure definition
  227. * @{
  228. */
  229. #define HAL_SD_ERROR_NONE SDMMC_ERROR_NONE /*!< No error */
  230. #define HAL_SD_ERROR_CMD_CRC_FAIL SDMMC_ERROR_CMD_CRC_FAIL /*!< Command response received (but CRC check failed) */
  231. #define HAL_SD_ERROR_DATA_CRC_FAIL SDMMC_ERROR_DATA_CRC_FAIL /*!< Data block sent/received (CRC check failed) */
  232. #define HAL_SD_ERROR_CMD_RSP_TIMEOUT SDMMC_ERROR_CMD_RSP_TIMEOUT /*!< Command response timeout */
  233. #define HAL_SD_ERROR_DATA_TIMEOUT SDMMC_ERROR_DATA_TIMEOUT /*!< Data timeout */
  234. #define HAL_SD_ERROR_TX_UNDERRUN SDMMC_ERROR_TX_UNDERRUN /*!< Transmit FIFO underrun */
  235. #define HAL_SD_ERROR_RX_OVERRUN SDMMC_ERROR_RX_OVERRUN /*!< Receive FIFO overrun */
  236. #define HAL_SD_ERROR_ADDR_MISALIGNED SDMMC_ERROR_ADDR_MISALIGNED /*!< Misaligned address */
  237. #define HAL_SD_ERROR_BLOCK_LEN_ERR SDMMC_ERROR_BLOCK_LEN_ERR /*!< Transferred block length is not allowed for the card or the
  238. number of transferred bytes does not match the block length */
  239. #define HAL_SD_ERROR_ERASE_SEQ_ERR SDMMC_ERROR_ERASE_SEQ_ERR /*!< An error in the sequence of erase command occurs */
  240. #define HAL_SD_ERROR_BAD_ERASE_PARAM SDMMC_ERROR_BAD_ERASE_PARAM /*!< An invalid selection for erase groups */
  241. #define HAL_SD_ERROR_WRITE_PROT_VIOLATION SDMMC_ERROR_WRITE_PROT_VIOLATION /*!< Attempt to program a write protect block */
  242. #define HAL_SD_ERROR_LOCK_UNLOCK_FAILED SDMMC_ERROR_LOCK_UNLOCK_FAILED /*!< Sequence or password error has been detected in unlock
  243. command or if there was an attempt to access a locked card */
  244. #define HAL_SD_ERROR_COM_CRC_FAILED SDMMC_ERROR_COM_CRC_FAILED /*!< CRC check of the previous command failed */
  245. #define HAL_SD_ERROR_ILLEGAL_CMD SDMMC_ERROR_ILLEGAL_CMD /*!< Command is not legal for the card state */
  246. #define HAL_SD_ERROR_CARD_ECC_FAILED SDMMC_ERROR_CARD_ECC_FAILED /*!< Card internal ECC was applied but failed to correct the data */
  247. #define HAL_SD_ERROR_CC_ERR SDMMC_ERROR_CC_ERR /*!< Internal card controller error */
  248. #define HAL_SD_ERROR_GENERAL_UNKNOWN_ERR SDMMC_ERROR_GENERAL_UNKNOWN_ERR /*!< General or unknown error */
  249. #define HAL_SD_ERROR_STREAM_READ_UNDERRUN SDMMC_ERROR_STREAM_READ_UNDERRUN /*!< The card could not sustain data reading in stream rmode */
  250. #define HAL_SD_ERROR_STREAM_WRITE_OVERRUN SDMMC_ERROR_STREAM_WRITE_OVERRUN /*!< The card could not sustain data programming in stream mode */
  251. #define HAL_SD_ERROR_CID_CSD_OVERWRITE SDMMC_ERROR_CID_CSD_OVERWRITE /*!< CID/CSD overwrite error */
  252. #define HAL_SD_ERROR_WP_ERASE_SKIP SDMMC_ERROR_WP_ERASE_SKIP /*!< Only partial address space was erased */
  253. #define HAL_SD_ERROR_CARD_ECC_DISABLED SDMMC_ERROR_CARD_ECC_DISABLED /*!< Command has been executed without using internal ECC */
  254. #define HAL_SD_ERROR_ERASE_RESET SDMMC_ERROR_ERASE_RESET /*!< Erase sequence was cleared before executing because an out
  255. of erase sequence command was received */
  256. #define HAL_SD_ERROR_AKE_SEQ_ERR SDMMC_ERROR_AKE_SEQ_ERR /*!< Error in sequence of authentication */
  257. #define HAL_SD_ERROR_INVALID_VOLTRANGE SDMMC_ERROR_INVALID_VOLTRANGE /*!< Error in case of invalid voltage range */
  258. #define HAL_SD_ERROR_ADDR_OUT_OF_RANGE SDMMC_ERROR_ADDR_OUT_OF_RANGE /*!< Error when addressed block is out of range */
  259. #define HAL_SD_ERROR_REQUEST_NOT_APPLICABLE SDMMC_ERROR_REQUEST_NOT_APPLICABLE /*!< Error when command request is not applicable */
  260. #define HAL_SD_ERROR_PARAM SDMMC_ERROR_INVALID_PARAMETER /*!< the used parameter is not valid */
  261. #define HAL_SD_ERROR_UNSUPPORTED_FEATURE SDMMC_ERROR_UNSUPPORTED_FEATURE /*!< Error when feature is not insupported */
  262. #define HAL_SD_ERROR_BUSY SDMMC_ERROR_BUSY /*!< Error when transfer process is busy */
  263. #define HAL_SD_ERROR_DMA SDMMC_ERROR_DMA /*!< Error while DMA transfer */
  264. #define HAL_SD_ERROR_TIMEOUT SDMMC_ERROR_TIMEOUT /*!< Timeout error */
  265. /**
  266. * @}
  267. */
  268. /** @defgroup SD_Exported_Constansts_Group2 SD context enumeration
  269. * @{
  270. */
  271. #define SD_CONTEXT_NONE ((uint32_t)0x00000000U) /*!< None */
  272. #define SD_CONTEXT_READ_SINGLE_BLOCK ((uint32_t)0x00000001U) /*!< Read single block operation */
  273. #define SD_CONTEXT_READ_MULTIPLE_BLOCK ((uint32_t)0x00000002U) /*!< Read multiple blocks operation */
  274. #define SD_CONTEXT_WRITE_SINGLE_BLOCK ((uint32_t)0x00000010U) /*!< Write single block operation */
  275. #define SD_CONTEXT_WRITE_MULTIPLE_BLOCK ((uint32_t)0x00000020U) /*!< Write multiple blocks operation */
  276. #define SD_CONTEXT_IT ((uint32_t)0x00000008U) /*!< Process in Interrupt mode */
  277. #define SD_CONTEXT_DMA ((uint32_t)0x00000080U) /*!< Process in DMA mode */
  278. /**
  279. * @}
  280. */
  281. /** @defgroup SD_Exported_Constansts_Group3 SD Supported Memory Cards
  282. * @{
  283. */
  284. #define CARD_SDSC ((uint32_t)0x00000000U)
  285. #define CARD_SDHC_SDXC ((uint32_t)0x00000001U)
  286. #define CARD_SECURED ((uint32_t)0x00000003U)
  287. /**
  288. * @}
  289. */
  290. /** @defgroup SD_Exported_Constansts_Group4 SD Supported Version
  291. * @{
  292. */
  293. #define CARD_V1_X ((uint32_t)0x00000000U)
  294. #define CARD_V2_X ((uint32_t)0x00000001U)
  295. /**
  296. * @}
  297. */
  298. /**
  299. * @}
  300. */
  301. /* Exported macro ------------------------------------------------------------*/
  302. /** @defgroup SD_Exported_macros SD Exported Macros
  303. * @brief macros to handle interrupts and specific clock configurations
  304. * @{
  305. */
  306. /**
  307. * @brief Enable the SD device.
  308. * @retval None
  309. */
  310. #define __HAL_SD_ENABLE(__HANDLE__) __SDMMC_ENABLE((__HANDLE__)->Instance)
  311. /**
  312. * @brief Disable the SD device.
  313. * @retval None
  314. */
  315. #define __HAL_SD_DISABLE(__HANDLE__) __SDMMC_DISABLE((__HANDLE__)->Instance)
  316. /**
  317. * @brief Enable the SDMMC DMA transfer.
  318. * @retval None
  319. */
  320. #define __HAL_SD_DMA_ENABLE(__HANDLE__) __SDMMC_DMA_ENABLE((__HANDLE__)->Instance)
  321. /**
  322. * @brief Disable the SDMMC DMA transfer.
  323. * @retval None
  324. */
  325. #define __HAL_SD_DMA_DISABLE(__HANDLE__) __SDMMC_DMA_DISABLE((__HANDLE__)->Instance)
  326. /**
  327. * @brief Enable the SD device interrupt.
  328. * @param __HANDLE__: SD Handle
  329. * @param __INTERRUPT__: specifies the SDMMC interrupt sources to be enabled.
  330. * This parameter can be one or a combination of the following values:
  331. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  332. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  333. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  334. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  335. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  336. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  337. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  338. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  339. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  340. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  341. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  342. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  343. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  344. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  345. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  346. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  347. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  348. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  349. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  350. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  351. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  352. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  353. * @retval None
  354. */
  355. #define __HAL_SD_ENABLE_IT(__HANDLE__, __INTERRUPT__) __SDMMC_ENABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
  356. /**
  357. * @brief Disable the SD device interrupt.
  358. * @param __HANDLE__: SD Handle
  359. * @param __INTERRUPT__: specifies the SDMMC interrupt sources to be disabled.
  360. * This parameter can be one or a combination of the following values:
  361. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  362. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  363. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  364. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  365. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  366. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  367. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  368. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  369. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  370. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  371. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  372. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  373. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  374. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  375. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  376. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  377. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  378. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  379. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  380. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  381. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  382. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  383. * @retval None
  384. */
  385. #define __HAL_SD_DISABLE_IT(__HANDLE__, __INTERRUPT__) __SDMMC_DISABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
  386. /**
  387. * @brief Check whether the specified SD flag is set or not.
  388. * @param __HANDLE__: SD Handle
  389. * @param __FLAG__: specifies the flag to check.
  390. * This parameter can be one of the following values:
  391. * @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed)
  392. * @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  393. * @arg SDMMC_FLAG_CTIMEOUT: Command response timeout
  394. * @arg SDMMC_FLAG_DTIMEOUT: Data timeout
  395. * @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error
  396. * @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error
  397. * @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed)
  398. * @arg SDMMC_FLAG_CMDSENT: Command sent (no response required)
  399. * @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  400. * @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  401. * @arg SDMMC_FLAG_CMDACT: Command transfer in progress
  402. * @arg SDMMC_FLAG_TXACT: Data transmit in progress
  403. * @arg SDMMC_FLAG_RXACT: Data receive in progress
  404. * @arg SDMMC_FLAG_TXFIFOHE: Transmit FIFO Half Empty
  405. * @arg SDMMC_FLAG_RXFIFOHF: Receive FIFO Half Full
  406. * @arg SDMMC_FLAG_TXFIFOF: Transmit FIFO full
  407. * @arg SDMMC_FLAG_RXFIFOF: Receive FIFO full
  408. * @arg SDMMC_FLAG_TXFIFOE: Transmit FIFO empty
  409. * @arg SDMMC_FLAG_RXFIFOE: Receive FIFO empty
  410. * @arg SDMMC_FLAG_TXDAVL: Data available in transmit FIFO
  411. * @arg SDMMC_FLAG_RXDAVL: Data available in receive FIFO
  412. * @arg SDMMC_FLAG_SDIOIT: SD I/O interrupt received
  413. * @retval The new state of SD FLAG (SET or RESET).
  414. */
  415. #define __HAL_SD_GET_FLAG(__HANDLE__, __FLAG__) __SDMMC_GET_FLAG((__HANDLE__)->Instance, (__FLAG__))
  416. /**
  417. * @brief Clear the SD's pending flags.
  418. * @param __HANDLE__: SD Handle
  419. * @param __FLAG__: specifies the flag to clear.
  420. * This parameter can be one or a combination of the following values:
  421. * @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed)
  422. * @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  423. * @arg SDMMC_FLAG_CTIMEOUT: Command response timeout
  424. * @arg SDMMC_FLAG_DTIMEOUT: Data timeout
  425. * @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error
  426. * @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error
  427. * @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed)
  428. * @arg SDMMC_FLAG_CMDSENT: Command sent (no response required)
  429. * @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  430. * @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  431. * @arg SDMMC_FLAG_SDIOIT: SD I/O interrupt received
  432. * @retval None
  433. */
  434. #define __HAL_SD_CLEAR_FLAG(__HANDLE__, __FLAG__) __SDMMC_CLEAR_FLAG((__HANDLE__)->Instance, (__FLAG__))
  435. /**
  436. * @brief Check whether the specified SD interrupt has occurred or not.
  437. * @param __HANDLE__: SD Handle
  438. * @param __INTERRUPT__: specifies the SDMMC interrupt source to check.
  439. * This parameter can be one of the following values:
  440. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  441. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  442. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  443. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  444. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  445. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  446. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  447. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  448. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  449. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  450. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  451. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  452. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  453. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  454. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  455. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  456. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  457. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  458. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  459. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  460. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  461. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  462. * @retval The new state of SD IT (SET or RESET).
  463. */
  464. #define __HAL_SD_GET_IT(__HANDLE__, __INTERRUPT__) __SDMMC_GET_IT((__HANDLE__)->Instance, (__INTERRUPT__))
  465. /**
  466. * @brief Clear the SD's interrupt pending bits.
  467. * @param __HANDLE__: SD Handle
  468. * @param __INTERRUPT__: specifies the interrupt pending bit to clear.
  469. * This parameter can be one or a combination of the following values:
  470. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  471. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  472. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  473. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  474. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  475. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  476. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  477. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  478. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDMMC_DCOUNT, is zero) interrupt
  479. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  480. * @retval None
  481. */
  482. #define __HAL_SD_CLEAR_IT(__HANDLE__, __INTERRUPT__) __SDMMC_CLEAR_IT((__HANDLE__)->Instance, (__INTERRUPT__))
  483. /**
  484. * @}
  485. */
  486. /* Exported functions --------------------------------------------------------*/
  487. /** @defgroup SD_Exported_Functions SD Exported Functions
  488. * @{
  489. */
  490. /** @defgroup SD_Exported_Functions_Group1 Initialization and de-initialization functions
  491. * @{
  492. */
  493. HAL_StatusTypeDef HAL_SD_Init(SD_HandleTypeDef *hsd);
  494. HAL_StatusTypeDef HAL_SD_InitCard(SD_HandleTypeDef *hsd);
  495. HAL_StatusTypeDef HAL_SD_DeInit (SD_HandleTypeDef *hsd);
  496. void HAL_SD_MspInit(SD_HandleTypeDef *hsd);
  497. void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd);
  498. /**
  499. * @}
  500. */
  501. /** @defgroup SD_Exported_Functions_Group2 Input and Output operation functions
  502. * @{
  503. */
  504. /* Blocking mode: Polling */
  505. HAL_StatusTypeDef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout);
  506. HAL_StatusTypeDef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout);
  507. HAL_StatusTypeDef HAL_SD_Erase(SD_HandleTypeDef *hsd, uint32_t BlockStartAdd, uint32_t BlockEndAdd);
  508. /* Non-Blocking mode: IT */
  509. HAL_StatusTypeDef HAL_SD_ReadBlocks_IT(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
  510. HAL_StatusTypeDef HAL_SD_WriteBlocks_IT(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
  511. /* Non-Blocking mode: DMA */
  512. HAL_StatusTypeDef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
  513. HAL_StatusTypeDef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
  514. void HAL_SD_IRQHandler(SD_HandleTypeDef *hsd);
  515. /* Callback in non blocking modes (DMA) */
  516. void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd);
  517. void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd);
  518. void HAL_SD_ErrorCallback(SD_HandleTypeDef *hsd);
  519. void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd);
  520. /**
  521. * @}
  522. */
  523. /** @defgroup SD_Exported_Functions_Group3 Peripheral Control functions
  524. * @{
  525. */
  526. HAL_StatusTypeDef HAL_SD_ConfigWideBusOperation(SD_HandleTypeDef *hsd, uint32_t WideMode);
  527. /**
  528. * @}
  529. */
  530. /** @defgroup SD_Exported_Functions_Group4 SD card related functions
  531. * @{
  532. */
  533. HAL_StatusTypeDef HAL_SD_SendSDStatus(SD_HandleTypeDef *hsd, uint32_t *pSDstatus);
  534. HAL_SD_CardStateTypeDef HAL_SD_GetCardState(SD_HandleTypeDef *hsd);
  535. HAL_StatusTypeDef HAL_SD_GetCardCID(SD_HandleTypeDef *hsd, HAL_SD_CardCIDTypeDef *pCID);
  536. HAL_StatusTypeDef HAL_SD_GetCardCSD(SD_HandleTypeDef *hsd, HAL_SD_CardCSDTypeDef *pCSD);
  537. HAL_StatusTypeDef HAL_SD_GetCardStatus(SD_HandleTypeDef *hsd, HAL_SD_CardStatusTypeDef *pStatus);
  538. HAL_StatusTypeDef HAL_SD_GetCardInfo(SD_HandleTypeDef *hsd, HAL_SD_CardInfoTypeDef *pCardInfo);
  539. /**
  540. * @}
  541. */
  542. /** @defgroup SD_Exported_Functions_Group5 Peripheral State and Errors functions
  543. * @{
  544. */
  545. HAL_SD_StateTypeDef HAL_SD_GetState(SD_HandleTypeDef *hsd);
  546. uint32_t HAL_SD_GetError(SD_HandleTypeDef *hsd);
  547. /**
  548. * @}
  549. */
  550. /** @defgroup SD_Exported_Functions_Group6 Perioheral Abort management
  551. * @{
  552. */
  553. HAL_StatusTypeDef HAL_SD_Abort(SD_HandleTypeDef *hsd);
  554. HAL_StatusTypeDef HAL_SD_Abort_IT(SD_HandleTypeDef *hsd);
  555. /**
  556. * @}
  557. */
  558. /* Private types -------------------------------------------------------------*/
  559. /** @defgroup SD_Private_Types SD Private Types
  560. * @{
  561. */
  562. /**
  563. * @}
  564. */
  565. /* Private defines -----------------------------------------------------------*/
  566. /** @defgroup SD_Private_Defines SD Private Defines
  567. * @{
  568. */
  569. /**
  570. * @}
  571. */
  572. /* Private variables ---------------------------------------------------------*/
  573. /** @defgroup SD_Private_Variables SD Private Variables
  574. * @{
  575. */
  576. /**
  577. * @}
  578. */
  579. /* Private constants ---------------------------------------------------------*/
  580. /** @defgroup SD_Private_Constants SD Private Constants
  581. * @{
  582. */
  583. /**
  584. * @}
  585. */
  586. /* Private macros ------------------------------------------------------------*/
  587. /** @defgroup SD_Private_Macros SD Private Macros
  588. * @{
  589. */
  590. /**
  591. * @}
  592. */
  593. /* Private functions prototypes ----------------------------------------------*/
  594. /** @defgroup SD_Private_Functions_Prototypes SD Private Functions Prototypes
  595. * @{
  596. */
  597. /**
  598. * @}
  599. */
  600. /* Private functions ---------------------------------------------------------*/
  601. /** @defgroup SD_Private_Functions SD Private Functions
  602. * @{
  603. */
  604. /**
  605. * @}
  606. */
  607. /**
  608. * @}
  609. */
  610. /**
  611. * @}
  612. */
  613. /**
  614. * @}
  615. */
  616. #ifdef __cplusplus
  617. }
  618. #endif
  619. #endif /* __STM32F7xx_HAL_SD_H */
  620. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/