stm32f1xx_hal_mmc.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_mmc.h
  4. * @author MCD Application Team
  5. * @brief Header file of MMC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32F1xx_HAL_MMC_H
  20. #define STM32F1xx_HAL_MMC_H
  21. #if defined(SDIO)
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f1xx_ll_sdmmc.h"
  27. /** @addtogroup STM32F1xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup MMC
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup MMC_Exported_Types MMC Exported Types
  35. * @{
  36. */
  37. /** @defgroup MMC_Exported_Types_Group1 MMC State enumeration structure
  38. * @{
  39. */
  40. typedef enum
  41. {
  42. HAL_MMC_STATE_RESET = 0x00000000U, /*!< MMC not yet initialized or disabled */
  43. HAL_MMC_STATE_READY = 0x00000001U, /*!< MMC initialized and ready for use */
  44. HAL_MMC_STATE_TIMEOUT = 0x00000002U, /*!< MMC Timeout state */
  45. HAL_MMC_STATE_BUSY = 0x00000003U, /*!< MMC process ongoing */
  46. HAL_MMC_STATE_PROGRAMMING = 0x00000004U, /*!< MMC Programming State */
  47. HAL_MMC_STATE_RECEIVING = 0x00000005U, /*!< MMC Receinving State */
  48. HAL_MMC_STATE_TRANSFER = 0x00000006U, /*!< MMC Transfer State */
  49. HAL_MMC_STATE_ERROR = 0x0000000FU /*!< MMC is in error state */
  50. }HAL_MMC_StateTypeDef;
  51. /**
  52. * @}
  53. */
  54. /** @defgroup MMC_Exported_Types_Group2 MMC Card State enumeration structure
  55. * @{
  56. */
  57. typedef uint32_t HAL_MMC_CardStateTypeDef;
  58. #define HAL_MMC_CARD_READY 0x00000001U /*!< Card state is ready */
  59. #define HAL_MMC_CARD_IDENTIFICATION 0x00000002U /*!< Card is in identification state */
  60. #define HAL_MMC_CARD_STANDBY 0x00000003U /*!< Card is in standby state */
  61. #define HAL_MMC_CARD_TRANSFER 0x00000004U /*!< Card is in transfer state */
  62. #define HAL_MMC_CARD_SENDING 0x00000005U /*!< Card is sending an operation */
  63. #define HAL_MMC_CARD_RECEIVING 0x00000006U /*!< Card is receiving operation information */
  64. #define HAL_MMC_CARD_PROGRAMMING 0x00000007U /*!< Card is in programming state */
  65. #define HAL_MMC_CARD_DISCONNECTED 0x00000008U /*!< Card is disconnected */
  66. #define HAL_MMC_CARD_ERROR 0x000000FFU /*!< Card response Error */
  67. /**
  68. * @}
  69. */
  70. /** @defgroup MMC_Exported_Types_Group3 MMC Handle Structure definition
  71. * @{
  72. */
  73. #define MMC_InitTypeDef SDIO_InitTypeDef
  74. #define MMC_TypeDef SDIO_TypeDef
  75. /**
  76. * @brief MMC Card Information Structure definition
  77. */
  78. typedef struct
  79. {
  80. uint32_t CardType; /*!< Specifies the card Type */
  81. uint32_t Class; /*!< Specifies the class of the card class */
  82. uint32_t RelCardAdd; /*!< Specifies the Relative Card Address */
  83. uint32_t BlockNbr; /*!< Specifies the Card Capacity in blocks */
  84. uint32_t BlockSize; /*!< Specifies one block size in bytes */
  85. uint32_t LogBlockNbr; /*!< Specifies the Card logical Capacity in blocks */
  86. uint32_t LogBlockSize; /*!< Specifies logical block size in bytes */
  87. }HAL_MMC_CardInfoTypeDef;
  88. /**
  89. * @brief MMC handle Structure definition
  90. */
  91. #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
  92. typedef struct __MMC_HandleTypeDef
  93. #else
  94. typedef struct
  95. #endif /* USE_HAL_MMC_REGISTER_CALLBACKS */
  96. {
  97. MMC_TypeDef *Instance; /*!< MMC registers base address */
  98. MMC_InitTypeDef Init; /*!< MMC required parameters */
  99. HAL_LockTypeDef Lock; /*!< MMC locking object */
  100. uint8_t *pTxBuffPtr; /*!< Pointer to MMC Tx transfer Buffer */
  101. uint32_t TxXferSize; /*!< MMC Tx Transfer size */
  102. uint8_t *pRxBuffPtr; /*!< Pointer to MMC Rx transfer Buffer */
  103. uint32_t RxXferSize; /*!< MMC Rx Transfer size */
  104. __IO uint32_t Context; /*!< MMC transfer context */
  105. __IO HAL_MMC_StateTypeDef State; /*!< MMC card State */
  106. __IO uint32_t ErrorCode; /*!< MMC Card Error codes */
  107. DMA_HandleTypeDef *hdmarx; /*!< MMC Rx DMA handle parameters */
  108. DMA_HandleTypeDef *hdmatx; /*!< MMC Tx DMA handle parameters */
  109. HAL_MMC_CardInfoTypeDef MmcCard; /*!< MMC Card information */
  110. uint32_t CSD[4U]; /*!< MMC card specific data table */
  111. uint32_t CID[4U]; /*!< MMC card identification number table */
  112. uint32_t Ext_CSD[128];
  113. #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
  114. void (* TxCpltCallback) (struct __MMC_HandleTypeDef *hmmc);
  115. void (* RxCpltCallback) (struct __MMC_HandleTypeDef *hmmc);
  116. void (* ErrorCallback) (struct __MMC_HandleTypeDef *hmmc);
  117. void (* AbortCpltCallback) (struct __MMC_HandleTypeDef *hmmc);
  118. void (* MspInitCallback) (struct __MMC_HandleTypeDef *hmmc);
  119. void (* MspDeInitCallback) (struct __MMC_HandleTypeDef *hmmc);
  120. #endif
  121. }MMC_HandleTypeDef;
  122. /**
  123. * @}
  124. */
  125. /** @defgroup MMC_Exported_Types_Group4 Card Specific Data: CSD Register
  126. * @{
  127. */
  128. typedef struct
  129. {
  130. __IO uint8_t CSDStruct; /*!< CSD structure */
  131. __IO uint8_t SysSpecVersion; /*!< System specification version */
  132. __IO uint8_t Reserved1; /*!< Reserved */
  133. __IO uint8_t TAAC; /*!< Data read access time 1 */
  134. __IO uint8_t NSAC; /*!< Data read access time 2 in CLK cycles */
  135. __IO uint8_t MaxBusClkFrec; /*!< Max. bus clock frequency */
  136. __IO uint16_t CardComdClasses; /*!< Card command classes */
  137. __IO uint8_t RdBlockLen; /*!< Max. read data block length */
  138. __IO uint8_t PartBlockRead; /*!< Partial blocks for read allowed */
  139. __IO uint8_t WrBlockMisalign; /*!< Write block misalignment */
  140. __IO uint8_t RdBlockMisalign; /*!< Read block misalignment */
  141. __IO uint8_t DSRImpl; /*!< DSR implemented */
  142. __IO uint8_t Reserved2; /*!< Reserved */
  143. __IO uint32_t DeviceSize; /*!< Device Size */
  144. __IO uint8_t MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */
  145. __IO uint8_t MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */
  146. __IO uint8_t MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */
  147. __IO uint8_t MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */
  148. __IO uint8_t DeviceSizeMul; /*!< Device size multiplier */
  149. __IO uint8_t EraseGrSize; /*!< Erase group size */
  150. __IO uint8_t EraseGrMul; /*!< Erase group size multiplier */
  151. __IO uint8_t WrProtectGrSize; /*!< Write protect group size */
  152. __IO uint8_t WrProtectGrEnable; /*!< Write protect group enable */
  153. __IO uint8_t ManDeflECC; /*!< Manufacturer default ECC */
  154. __IO uint8_t WrSpeedFact; /*!< Write speed factor */
  155. __IO uint8_t MaxWrBlockLen; /*!< Max. write data block length */
  156. __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */
  157. __IO uint8_t Reserved3; /*!< Reserved */
  158. __IO uint8_t ContentProtectAppli; /*!< Content protection application */
  159. __IO uint8_t FileFormatGroup; /*!< File format group */
  160. __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */
  161. __IO uint8_t PermWrProtect; /*!< Permanent write protection */
  162. __IO uint8_t TempWrProtect; /*!< Temporary write protection */
  163. __IO uint8_t FileFormat; /*!< File format */
  164. __IO uint8_t ECC; /*!< ECC code */
  165. __IO uint8_t CSD_CRC; /*!< CSD CRC */
  166. __IO uint8_t Reserved4; /*!< Always 1 */
  167. }HAL_MMC_CardCSDTypeDef;
  168. /**
  169. * @}
  170. */
  171. /** @defgroup MMC_Exported_Types_Group5 Card Identification Data: CID Register
  172. * @{
  173. */
  174. typedef struct
  175. {
  176. __IO uint8_t ManufacturerID; /*!< Manufacturer ID */
  177. __IO uint16_t OEM_AppliID; /*!< OEM/Application ID */
  178. __IO uint32_t ProdName1; /*!< Product Name part1 */
  179. __IO uint8_t ProdName2; /*!< Product Name part2 */
  180. __IO uint8_t ProdRev; /*!< Product Revision */
  181. __IO uint32_t ProdSN; /*!< Product Serial Number */
  182. __IO uint8_t Reserved1; /*!< Reserved1 */
  183. __IO uint16_t ManufactDate; /*!< Manufacturing Date */
  184. __IO uint8_t CID_CRC; /*!< CID CRC */
  185. __IO uint8_t Reserved2; /*!< Always 1 */
  186. }HAL_MMC_CardCIDTypeDef;
  187. /**
  188. * @}
  189. */
  190. #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
  191. /** @defgroup MMC_Exported_Types_Group6 MMC Callback ID enumeration definition
  192. * @{
  193. */
  194. typedef enum
  195. {
  196. HAL_MMC_TX_CPLT_CB_ID = 0x00U, /*!< MMC Tx Complete Callback ID */
  197. HAL_MMC_RX_CPLT_CB_ID = 0x01U, /*!< MMC Rx Complete Callback ID */
  198. HAL_MMC_ERROR_CB_ID = 0x02U, /*!< MMC Error Callback ID */
  199. HAL_MMC_ABORT_CB_ID = 0x03U, /*!< MMC Abort Callback ID */
  200. HAL_MMC_MSP_INIT_CB_ID = 0x10U, /*!< MMC MspInit Callback ID */
  201. HAL_MMC_MSP_DEINIT_CB_ID = 0x11U /*!< MMC MspDeInit Callback ID */
  202. }HAL_MMC_CallbackIDTypeDef;
  203. /**
  204. * @}
  205. */
  206. /** @defgroup MMC_Exported_Types_Group7 MMC Callback pointer definition
  207. * @{
  208. */
  209. typedef void (*pMMC_CallbackTypeDef) (MMC_HandleTypeDef *hmmc);
  210. /**
  211. * @}
  212. */
  213. #endif
  214. /**
  215. * @}
  216. */
  217. /* Exported constants --------------------------------------------------------*/
  218. /** @defgroup MMC_Exported_Constants Exported Constants
  219. * @{
  220. */
  221. #define MMC_BLOCKSIZE 512U /*!< Block size is 512 bytes */
  222. /** @defgroup MMC_Exported_Constansts_Group1 MMC Error status enumeration Structure definition
  223. * @{
  224. */
  225. #define HAL_MMC_ERROR_NONE SDMMC_ERROR_NONE /*!< No error */
  226. #define HAL_MMC_ERROR_CMD_CRC_FAIL SDMMC_ERROR_CMD_CRC_FAIL /*!< Command response received (but CRC check failed) */
  227. #define HAL_MMC_ERROR_DATA_CRC_FAIL SDMMC_ERROR_DATA_CRC_FAIL /*!< Data block sent/received (CRC check failed) */
  228. #define HAL_MMC_ERROR_CMD_RSP_TIMEOUT SDMMC_ERROR_CMD_RSP_TIMEOUT /*!< Command response timeout */
  229. #define HAL_MMC_ERROR_DATA_TIMEOUT SDMMC_ERROR_DATA_TIMEOUT /*!< Data timeout */
  230. #define HAL_MMC_ERROR_TX_UNDERRUN SDMMC_ERROR_TX_UNDERRUN /*!< Transmit FIFO underrun */
  231. #define HAL_MMC_ERROR_RX_OVERRUN SDMMC_ERROR_RX_OVERRUN /*!< Receive FIFO overrun */
  232. #define HAL_MMC_ERROR_ADDR_MISALIGNED SDMMC_ERROR_ADDR_MISALIGNED /*!< Misaligned address */
  233. #define HAL_MMC_ERROR_BLOCK_LEN_ERR SDMMC_ERROR_BLOCK_LEN_ERR /*!< Transferred block length is not allowed for the card or the
  234. number of transferred bytes does not match the block length */
  235. #define HAL_MMC_ERROR_ERASE_SEQ_ERR SDMMC_ERROR_ERASE_SEQ_ERR /*!< An error in the sequence of erase command occurs */
  236. #define HAL_MMC_ERROR_BAD_ERASE_PARAM SDMMC_ERROR_BAD_ERASE_PARAM /*!< An invalid selection for erase groups */
  237. #define HAL_MMC_ERROR_WRITE_PROT_VIOLATION SDMMC_ERROR_WRITE_PROT_VIOLATION /*!< Attempt to program a write protect block */
  238. #define HAL_MMC_ERROR_LOCK_UNLOCK_FAILED SDMMC_ERROR_LOCK_UNLOCK_FAILED /*!< Sequence or password error has been detected in unlock
  239. command or if there was an attempt to access a locked card */
  240. #define HAL_MMC_ERROR_COM_CRC_FAILED SDMMC_ERROR_COM_CRC_FAILED /*!< CRC check of the previous command failed */
  241. #define HAL_MMC_ERROR_ILLEGAL_CMD SDMMC_ERROR_ILLEGAL_CMD /*!< Command is not legal for the card state */
  242. #define HAL_MMC_ERROR_CARD_ECC_FAILED SDMMC_ERROR_CARD_ECC_FAILED /*!< Card internal ECC was applied but failed to correct the data */
  243. #define HAL_MMC_ERROR_CC_ERR SDMMC_ERROR_CC_ERR /*!< Internal card controller error */
  244. #define HAL_MMC_ERROR_GENERAL_UNKNOWN_ERR SDMMC_ERROR_GENERAL_UNKNOWN_ERR /*!< General or unknown error */
  245. #define HAL_MMC_ERROR_STREAM_READ_UNDERRUN SDMMC_ERROR_STREAM_READ_UNDERRUN /*!< The card could not sustain data reading in stream rmode */
  246. #define HAL_MMC_ERROR_STREAM_WRITE_OVERRUN SDMMC_ERROR_STREAM_WRITE_OVERRUN /*!< The card could not sustain data programming in stream mode */
  247. #define HAL_MMC_ERROR_CID_CSD_OVERWRITE SDMMC_ERROR_CID_CSD_OVERWRITE /*!< CID/CSD overwrite error */
  248. #define HAL_MMC_ERROR_WP_ERASE_SKIP SDMMC_ERROR_WP_ERASE_SKIP /*!< Only partial address space was erased */
  249. #define HAL_MMC_ERROR_CARD_ECC_DISABLED SDMMC_ERROR_CARD_ECC_DISABLED /*!< Command has been executed without using internal ECC */
  250. #define HAL_MMC_ERROR_ERASE_RESET SDMMC_ERROR_ERASE_RESET /*!< Erase sequence was cleared before executing because an out
  251. of erase sequence command was received */
  252. #define HAL_MMC_ERROR_AKE_SEQ_ERR SDMMC_ERROR_AKE_SEQ_ERR /*!< Error in sequence of authentication */
  253. #define HAL_MMC_ERROR_INVALID_VOLTRANGE SDMMC_ERROR_INVALID_VOLTRANGE /*!< Error in case of invalid voltage range */
  254. #define HAL_MMC_ERROR_ADDR_OUT_OF_RANGE SDMMC_ERROR_ADDR_OUT_OF_RANGE /*!< Error when addressed block is out of range */
  255. #define HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE SDMMC_ERROR_REQUEST_NOT_APPLICABLE /*!< Error when command request is not applicable */
  256. #define HAL_MMC_ERROR_PARAM SDMMC_ERROR_INVALID_PARAMETER /*!< the used parameter is not valid */
  257. #define HAL_MMC_ERROR_UNSUPPORTED_FEATURE SDMMC_ERROR_UNSUPPORTED_FEATURE /*!< Error when feature is not insupported */
  258. #define HAL_MMC_ERROR_BUSY SDMMC_ERROR_BUSY /*!< Error when transfer process is busy */
  259. #define HAL_MMC_ERROR_DMA SDMMC_ERROR_DMA /*!< Error while DMA transfer */
  260. #define HAL_MMC_ERROR_TIMEOUT SDMMC_ERROR_TIMEOUT /*!< Timeout error */
  261. #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
  262. #define HAL_MMC_ERROR_INVALID_CALLBACK SDMMC_ERROR_INVALID_PARAMETER /*!< Invalid callback error */
  263. #endif
  264. /**
  265. * @}
  266. */
  267. /** @defgroup MMC_Exported_Constansts_Group2 MMC context enumeration
  268. * @{
  269. */
  270. #define MMC_CONTEXT_NONE 0x00000000U /*!< None */
  271. #define MMC_CONTEXT_READ_SINGLE_BLOCK 0x00000001U /*!< Read single block operation */
  272. #define MMC_CONTEXT_READ_MULTIPLE_BLOCK 0x00000002U /*!< Read multiple blocks operation */
  273. #define MMC_CONTEXT_WRITE_SINGLE_BLOCK 0x00000010U /*!< Write single block operation */
  274. #define MMC_CONTEXT_WRITE_MULTIPLE_BLOCK 0x00000020U /*!< Write multiple blocks operation */
  275. #define MMC_CONTEXT_IT 0x00000008U /*!< Process in Interrupt mode */
  276. #define MMC_CONTEXT_DMA 0x00000080U /*!< Process in DMA mode */
  277. /**
  278. * @}
  279. */
  280. /** @defgroup MMC_Exported_Constansts_Group3 MMC Voltage mode
  281. * @{
  282. */
  283. /**
  284. * @brief
  285. */
  286. #define MMC_HIGH_VOLTAGE_RANGE 0x80FF8000U /*!< High voltage in byte mode */
  287. #define MMC_DUAL_VOLTAGE_RANGE 0x80FF8080U /*!< Dual voltage in byte mode */
  288. #define MMC_LOW_VOLTAGE_RANGE 0x80000080U /*!< Low voltage in byte mode */
  289. #define EMMC_HIGH_VOLTAGE_RANGE 0xC0FF8000U /*!< High voltage in sector mode */
  290. #define EMMC_DUAL_VOLTAGE_RANGE 0xC0FF8080U /*!< Dual voltage in sector mode */
  291. #define EMMC_LOW_VOLTAGE_RANGE 0xC0000080U /*!< Low voltage in sector mode */
  292. #define MMC_INVALID_VOLTAGE_RANGE 0x0001FF01U
  293. /**
  294. * @}
  295. */
  296. /** @defgroup MMC_Exported_Constansts_Group4 MMC Memory Cards
  297. * @{
  298. */
  299. #define MMC_LOW_CAPACITY_CARD 0x00000000U /*!< MMC Card Capacity <=2Gbytes */
  300. #define MMC_HIGH_CAPACITY_CARD 0x00000001U /*!< MMC Card Capacity >2Gbytes and <2Tbytes */
  301. /**
  302. * @}
  303. */
  304. /**
  305. * @}
  306. */
  307. /* Exported macro ------------------------------------------------------------*/
  308. /** @defgroup MMC_Exported_macros MMC Exported Macros
  309. * @brief macros to handle interrupts and specific clock configurations
  310. * @{
  311. */
  312. /** @brief Reset MMC handle state.
  313. * @param __HANDLE__ : MMC handle.
  314. * @retval None
  315. */
  316. #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
  317. #define __HAL_MMC_RESET_HANDLE_STATE(__HANDLE__) do { \
  318. (__HANDLE__)->State = HAL_MMC_STATE_RESET; \
  319. (__HANDLE__)->MspInitCallback = NULL; \
  320. (__HANDLE__)->MspDeInitCallback = NULL; \
  321. } while(0)
  322. #else
  323. #define __HAL_MMC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_MMC_STATE_RESET)
  324. #endif
  325. /**
  326. * @brief Enable the MMC device.
  327. * @retval None
  328. */
  329. #define __HAL_MMC_ENABLE(__HANDLE__) __SDIO_ENABLE((__HANDLE__)->Instance)
  330. /**
  331. * @brief Disable the MMC device.
  332. * @retval None
  333. */
  334. #define __HAL_MMC_DISABLE(__HANDLE__) __SDIO_DISABLE((__HANDLE__)->Instance)
  335. /**
  336. * @brief Enable the SDMMC DMA transfer.
  337. * @retval None
  338. */
  339. #define __HAL_MMC_DMA_ENABLE(__HANDLE__) __SDIO_DMA_ENABLE((__HANDLE__)->Instance)
  340. /**
  341. * @brief Disable the SDMMC DMA transfer.
  342. * @retval None
  343. */
  344. #define __HAL_MMC_DMA_DISABLE(__HANDLE__) __SDIO_DMA_DISABLE((__HANDLE__)->Instance)
  345. /**
  346. * @brief Enable the MMC device interrupt.
  347. * @param __HANDLE__: MMC Handle
  348. * @param __INTERRUPT__: specifies the SDMMC interrupt sources to be enabled.
  349. * This parameter can be one or a combination of the following values:
  350. * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  351. * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  352. * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
  353. * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
  354. * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  355. * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
  356. * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
  357. * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
  358. * @arg SDIO_IT_DATAEND: Data end (data counter, DATACOUNT, is zero) interrupt
  359. * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  360. * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
  361. * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
  362. * @arg SDIO_IT_RXACT: Data receive in progress interrupt
  363. * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  364. * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  365. * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
  366. * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
  367. * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
  368. * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
  369. * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
  370. * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
  371. * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
  372. * @retval None
  373. */
  374. #define __HAL_MMC_ENABLE_IT(__HANDLE__, __INTERRUPT__) __SDIO_ENABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
  375. /**
  376. * @brief Disable the MMC device interrupt.
  377. * @param __HANDLE__: MMC Handle
  378. * @param __INTERRUPT__: specifies the SDMMC interrupt sources to be disabled.
  379. * This parameter can be one or a combination of the following values:
  380. * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  381. * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  382. * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
  383. * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
  384. * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  385. * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
  386. * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
  387. * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
  388. * @arg SDIO_IT_DATAEND: Data end (data counter, DATACOUNT, is zero) interrupt
  389. * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  390. * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
  391. * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
  392. * @arg SDIO_IT_RXACT: Data receive in progress interrupt
  393. * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  394. * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  395. * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
  396. * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
  397. * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
  398. * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
  399. * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
  400. * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
  401. * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
  402. * @retval None
  403. */
  404. #define __HAL_MMC_DISABLE_IT(__HANDLE__, __INTERRUPT__) __SDIO_DISABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__))
  405. /**
  406. * @brief Check whether the specified MMC flag is set or not.
  407. * @param __HANDLE__: MMC Handle
  408. * @param __FLAG__: specifies the flag to check.
  409. * This parameter can be one of the following values:
  410. * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
  411. * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  412. * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
  413. * @arg SDIO_FLAG_DTIMEOUT: Data timeout
  414. * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
  415. * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error
  416. * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed)
  417. * @arg SDIO_FLAG_CMDSENT: Command sent (no response required)
  418. * @arg SDIO_FLAG_DATAEND: Data end (data counter, DATACOUNT, is zero)
  419. * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  420. * @arg SDIO_FLAG_CMDACT: Command transfer in progress
  421. * @arg SDIO_FLAG_TXACT: Data transmit in progress
  422. * @arg SDIO_FLAG_RXACT: Data receive in progress
  423. * @arg SDIO_FLAG_TXFIFOHE: Transmit FIFO Half Empty
  424. * @arg SDIO_FLAG_RXFIFOHF: Receive FIFO Half Full
  425. * @arg SDIO_FLAG_TXFIFOF: Transmit FIFO full
  426. * @arg SDIO_FLAG_RXFIFOF: Receive FIFO full
  427. * @arg SDIO_FLAG_TXFIFOE: Transmit FIFO empty
  428. * @arg SDIO_FLAG_RXFIFOE: Receive FIFO empty
  429. * @arg SDIO_FLAG_TXDAVL: Data available in transmit FIFO
  430. * @arg SDIO_FLAG_RXDAVL: Data available in receive FIFO
  431. * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received
  432. * @retval The new state of MMC FLAG (SET or RESET).
  433. */
  434. #define __HAL_MMC_GET_FLAG(__HANDLE__, __FLAG__) __SDIO_GET_FLAG((__HANDLE__)->Instance, (__FLAG__))
  435. /**
  436. * @brief Clear the MMC's pending flags.
  437. * @param __HANDLE__: MMC Handle
  438. * @param __FLAG__: specifies the flag to clear.
  439. * This parameter can be one or a combination of the following values:
  440. * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
  441. * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  442. * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
  443. * @arg SDIO_FLAG_DTIMEOUT: Data timeout
  444. * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
  445. * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error
  446. * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed)
  447. * @arg SDIO_FLAG_CMDSENT: Command sent (no response required)
  448. * @arg SDIO_FLAG_DATAEND: Data end (data counter, DATACOUNT, is zero)
  449. * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  450. * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received
  451. * @retval None
  452. */
  453. #define __HAL_MMC_CLEAR_FLAG(__HANDLE__, __FLAG__) __SDIO_CLEAR_FLAG((__HANDLE__)->Instance, (__FLAG__))
  454. /**
  455. * @brief Check whether the specified MMC interrupt has occurred or not.
  456. * @param __HANDLE__: MMC Handle
  457. * @param __INTERRUPT__: specifies the SDMMC interrupt source to check.
  458. * This parameter can be one of the following values:
  459. * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  460. * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  461. * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
  462. * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
  463. * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  464. * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
  465. * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
  466. * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
  467. * @arg SDIO_IT_DATAEND: Data end (data counter, DATACOUNT, is zero) interrupt
  468. * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  469. * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
  470. * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
  471. * @arg SDIO_IT_RXACT: Data receive in progress interrupt
  472. * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  473. * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  474. * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
  475. * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
  476. * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
  477. * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
  478. * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
  479. * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
  480. * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
  481. * @retval The new state of MMC IT (SET or RESET).
  482. */
  483. #define __HAL_MMC_GET_IT(__HANDLE__, __INTERRUPT__) __SDIO_GET_IT((__HANDLE__)->Instance, (__INTERRUPT__))
  484. /**
  485. * @brief Clear the MMC's interrupt pending bits.
  486. * @param __HANDLE__: MMC Handle
  487. * @param __INTERRUPT__: specifies the interrupt pending bit to clear.
  488. * This parameter can be one or a combination of the following values:
  489. * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  490. * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  491. * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
  492. * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
  493. * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  494. * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
  495. * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
  496. * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
  497. * @arg SDIO_IT_DATAEND: Data end (data counter, DATACOUNT, is zero) interrupt
  498. * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  499. * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  500. * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  501. * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
  502. * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
  503. * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
  504. * @retval None
  505. */
  506. #define __HAL_MMC_CLEAR_IT(__HANDLE__, __INTERRUPT__) __SDIO_CLEAR_IT((__HANDLE__)->Instance, (__INTERRUPT__))
  507. /**
  508. * @}
  509. */
  510. /* Exported functions --------------------------------------------------------*/
  511. /** @defgroup MMC_Exported_Functions MMC Exported Functions
  512. * @{
  513. */
  514. /** @defgroup MMC_Exported_Functions_Group1 Initialization and de-initialization functions
  515. * @{
  516. */
  517. HAL_StatusTypeDef HAL_MMC_Init(MMC_HandleTypeDef *hmmc);
  518. HAL_StatusTypeDef HAL_MMC_InitCard(MMC_HandleTypeDef *hmmc);
  519. HAL_StatusTypeDef HAL_MMC_DeInit (MMC_HandleTypeDef *hmmc);
  520. void HAL_MMC_MspInit(MMC_HandleTypeDef *hmmc);
  521. void HAL_MMC_MspDeInit(MMC_HandleTypeDef *hmmc);
  522. /**
  523. * @}
  524. */
  525. /** @defgroup MMC_Exported_Functions_Group2 Input and Output operation functions
  526. * @{
  527. */
  528. /* Blocking mode: Polling */
  529. HAL_StatusTypeDef HAL_MMC_ReadBlocks(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout);
  530. HAL_StatusTypeDef HAL_MMC_WriteBlocks(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout);
  531. HAL_StatusTypeDef HAL_MMC_Erase(MMC_HandleTypeDef *hmmc, uint32_t BlockStartAdd, uint32_t BlockEndAdd);
  532. /* Non-Blocking mode: IT */
  533. HAL_StatusTypeDef HAL_MMC_ReadBlocks_IT(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
  534. HAL_StatusTypeDef HAL_MMC_WriteBlocks_IT(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
  535. /* Non-Blocking mode: DMA */
  536. HAL_StatusTypeDef HAL_MMC_ReadBlocks_DMA(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
  537. HAL_StatusTypeDef HAL_MMC_WriteBlocks_DMA(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks);
  538. void HAL_MMC_IRQHandler(MMC_HandleTypeDef *hmmc);
  539. /* Callback in non blocking modes (DMA) */
  540. void HAL_MMC_TxCpltCallback(MMC_HandleTypeDef *hmmc);
  541. void HAL_MMC_RxCpltCallback(MMC_HandleTypeDef *hmmc);
  542. void HAL_MMC_ErrorCallback(MMC_HandleTypeDef *hmmc);
  543. void HAL_MMC_AbortCallback(MMC_HandleTypeDef *hmmc);
  544. #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
  545. /* MMC callback registering/unregistering */
  546. HAL_StatusTypeDef HAL_MMC_RegisterCallback (MMC_HandleTypeDef *hmmc, HAL_MMC_CallbackIDTypeDef CallbackId, pMMC_CallbackTypeDef pCallback);
  547. HAL_StatusTypeDef HAL_MMC_UnRegisterCallback(MMC_HandleTypeDef *hmmc, HAL_MMC_CallbackIDTypeDef CallbackId);
  548. #endif
  549. /**
  550. * @}
  551. */
  552. /** @defgroup MMC_Exported_Functions_Group3 Peripheral Control functions
  553. * @{
  554. */
  555. HAL_StatusTypeDef HAL_MMC_ConfigWideBusOperation(MMC_HandleTypeDef *hmmc, uint32_t WideMode);
  556. /**
  557. * @}
  558. */
  559. /** @defgroup MMC_Exported_Functions_Group4 MMC card related functions
  560. * @{
  561. */
  562. HAL_MMC_CardStateTypeDef HAL_MMC_GetCardState(MMC_HandleTypeDef *hmmc);
  563. HAL_StatusTypeDef HAL_MMC_GetCardCID(MMC_HandleTypeDef *hmmc, HAL_MMC_CardCIDTypeDef *pCID);
  564. HAL_StatusTypeDef HAL_MMC_GetCardCSD(MMC_HandleTypeDef *hmmc, HAL_MMC_CardCSDTypeDef *pCSD);
  565. HAL_StatusTypeDef HAL_MMC_GetCardInfo(MMC_HandleTypeDef *hmmc, HAL_MMC_CardInfoTypeDef *pCardInfo);
  566. HAL_StatusTypeDef HAL_MMC_GetCardExtCSD(MMC_HandleTypeDef *hmmc, uint32_t *pExtCSD, uint32_t Timeout);
  567. /**
  568. * @}
  569. */
  570. /** @defgroup MMC_Exported_Functions_Group5 Peripheral State and Errors functions
  571. * @{
  572. */
  573. HAL_MMC_StateTypeDef HAL_MMC_GetState(MMC_HandleTypeDef *hmmc);
  574. uint32_t HAL_MMC_GetError(MMC_HandleTypeDef *hmmc);
  575. /**
  576. * @}
  577. */
  578. /** @defgroup MMC_Exported_Functions_Group6 Peripheral Abort management
  579. * @{
  580. */
  581. HAL_StatusTypeDef HAL_MMC_Abort(MMC_HandleTypeDef *hmmc);
  582. HAL_StatusTypeDef HAL_MMC_Abort_IT(MMC_HandleTypeDef *hmmc);
  583. /**
  584. * @}
  585. */
  586. /* Private types -------------------------------------------------------------*/
  587. /** @defgroup MMC_Private_Types MMC Private Types
  588. * @{
  589. */
  590. /**
  591. * @}
  592. */
  593. /* Private defines -----------------------------------------------------------*/
  594. /** @defgroup MMC_Private_Defines MMC Private Defines
  595. * @{
  596. */
  597. /**
  598. * @}
  599. */
  600. /* Private variables ---------------------------------------------------------*/
  601. /** @defgroup MMC_Private_Variables MMC Private Variables
  602. * @{
  603. */
  604. /**
  605. * @}
  606. */
  607. /* Private constants ---------------------------------------------------------*/
  608. /** @defgroup MMC_Private_Constants MMC Private Constants
  609. * @{
  610. */
  611. /**
  612. * @}
  613. */
  614. /* Private macros ------------------------------------------------------------*/
  615. /** @defgroup MMC_Private_Macros MMC Private Macros
  616. * @{
  617. */
  618. /**
  619. * @}
  620. */
  621. /* Private functions prototypes ----------------------------------------------*/
  622. /** @defgroup MMC_Private_Functions_Prototypes MMC Private Functions Prototypes
  623. * @{
  624. */
  625. /**
  626. * @}
  627. */
  628. /* Private functions ---------------------------------------------------------*/
  629. /** @defgroup MMC_Private_Functions MMC Private Functions
  630. * @{
  631. */
  632. /**
  633. * @}
  634. */
  635. /**
  636. * @}
  637. */
  638. /**
  639. * @}
  640. */
  641. /**
  642. * @}
  643. */
  644. #ifdef __cplusplus
  645. }
  646. #endif
  647. #endif /* SDIO */
  648. #endif /* STM32F1xx_HAL_MMC_H */