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.
 
 

1118 lines
58 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ll_sdmmc.h
  4. * @author MCD Application Team
  5. * @brief Header file of SDMMC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32F4xx_LL_SDMMC_H
  21. #define __STM32F4xx_LL_SDMMC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || \
  26. defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
  27. defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) || \
  28. defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
  29. defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "stm32f4xx_hal_def.h"
  32. /** @addtogroup STM32F4xx_Driver
  33. * @{
  34. */
  35. /** @addtogroup SDMMC_LL
  36. * @{
  37. */
  38. /* Exported types ------------------------------------------------------------*/
  39. /** @defgroup SDMMC_LL_Exported_Types SDMMC_LL Exported Types
  40. * @{
  41. */
  42. /**
  43. * @brief SDMMC Configuration Structure definition
  44. */
  45. typedef struct
  46. {
  47. uint32_t ClockEdge; /*!< Specifies the clock transition on which the bit capture is made.
  48. This parameter can be a value of @ref SDMMC_LL_Clock_Edge */
  49. uint32_t ClockBypass; /*!< Specifies whether the SDMMC Clock divider bypass is
  50. enabled or disabled.
  51. This parameter can be a value of @ref SDMMC_LL_Clock_Bypass */
  52. uint32_t ClockPowerSave; /*!< Specifies whether SDMMC Clock output is enabled or
  53. disabled when the bus is idle.
  54. This parameter can be a value of @ref SDMMC_LL_Clock_Power_Save */
  55. uint32_t BusWide; /*!< Specifies the SDMMC bus width.
  56. This parameter can be a value of @ref SDMMC_LL_Bus_Wide */
  57. uint32_t HardwareFlowControl; /*!< Specifies whether the SDMMC hardware flow control is enabled or disabled.
  58. This parameter can be a value of @ref SDMMC_LL_Hardware_Flow_Control */
  59. uint32_t ClockDiv; /*!< Specifies the clock frequency of the SDMMC controller.
  60. This parameter can be a value between Min_Data = 0 and Max_Data = 255 */
  61. }SDIO_InitTypeDef;
  62. /**
  63. * @brief SDMMC Command Control structure
  64. */
  65. typedef struct
  66. {
  67. uint32_t Argument; /*!< Specifies the SDMMC command argument which is sent
  68. to a card as part of a command message. If a command
  69. contains an argument, it must be loaded into this register
  70. before writing the command to the command register. */
  71. uint32_t CmdIndex; /*!< Specifies the SDMMC command index. It must be Min_Data = 0 and
  72. Max_Data = 64 */
  73. uint32_t Response; /*!< Specifies the SDMMC response type.
  74. This parameter can be a value of @ref SDMMC_LL_Response_Type */
  75. uint32_t WaitForInterrupt; /*!< Specifies whether SDMMC wait for interrupt request is
  76. enabled or disabled.
  77. This parameter can be a value of @ref SDMMC_LL_Wait_Interrupt_State */
  78. uint32_t CPSM; /*!< Specifies whether SDMMC Command path state machine (CPSM)
  79. is enabled or disabled.
  80. This parameter can be a value of @ref SDMMC_LL_CPSM_State */
  81. }SDIO_CmdInitTypeDef;
  82. /**
  83. * @brief SDMMC Data Control structure
  84. */
  85. typedef struct
  86. {
  87. uint32_t DataTimeOut; /*!< Specifies the data timeout period in card bus clock periods. */
  88. uint32_t DataLength; /*!< Specifies the number of data bytes to be transferred. */
  89. uint32_t DataBlockSize; /*!< Specifies the data block size for block transfer.
  90. This parameter can be a value of @ref SDMMC_LL_Data_Block_Size */
  91. uint32_t TransferDir; /*!< Specifies the data transfer direction, whether the transfer
  92. is a read or write.
  93. This parameter can be a value of @ref SDMMC_LL_Transfer_Direction */
  94. uint32_t TransferMode; /*!< Specifies whether data transfer is in stream or block mode.
  95. This parameter can be a value of @ref SDMMC_LL_Transfer_Type */
  96. uint32_t DPSM; /*!< Specifies whether SDMMC Data path state machine (DPSM)
  97. is enabled or disabled.
  98. This parameter can be a value of @ref SDMMC_LL_DPSM_State */
  99. }SDIO_DataInitTypeDef;
  100. /**
  101. * @}
  102. */
  103. /* Exported constants --------------------------------------------------------*/
  104. /** @defgroup SDMMC_LL_Exported_Constants SDMMC_LL Exported Constants
  105. * @{
  106. */
  107. #define SDMMC_ERROR_NONE 0x00000000U /*!< No error */
  108. #define SDMMC_ERROR_CMD_CRC_FAIL 0x00000001U /*!< Command response received (but CRC check failed) */
  109. #define SDMMC_ERROR_DATA_CRC_FAIL 0x00000002U /*!< Data block sent/received (CRC check failed) */
  110. #define SDMMC_ERROR_CMD_RSP_TIMEOUT 0x00000004U /*!< Command response timeout */
  111. #define SDMMC_ERROR_DATA_TIMEOUT 0x00000008U /*!< Data timeout */
  112. #define SDMMC_ERROR_TX_UNDERRUN 0x00000010U /*!< Transmit FIFO underrun */
  113. #define SDMMC_ERROR_RX_OVERRUN 0x00000020U /*!< Receive FIFO overrun */
  114. #define SDMMC_ERROR_ADDR_MISALIGNED 0x00000040U /*!< Misaligned address */
  115. #define SDMMC_ERROR_BLOCK_LEN_ERR 0x00000080U /*!< Transferred block length is not allowed for the card or the
  116. number of transferred bytes does not match the block length */
  117. #define SDMMC_ERROR_ERASE_SEQ_ERR 0x00000100U /*!< An error in the sequence of erase command occurs */
  118. #define SDMMC_ERROR_BAD_ERASE_PARAM 0x00000200U /*!< An invalid selection for erase groups */
  119. #define SDMMC_ERROR_WRITE_PROT_VIOLATION 0x00000400U /*!< Attempt to program a write protect block */
  120. #define SDMMC_ERROR_LOCK_UNLOCK_FAILED 0x00000800U /*!< Sequence or password error has been detected in unlock
  121. command or if there was an attempt to access a locked card */
  122. #define SDMMC_ERROR_COM_CRC_FAILED 0x00001000U /*!< CRC check of the previous command failed */
  123. #define SDMMC_ERROR_ILLEGAL_CMD 0x00002000U /*!< Command is not legal for the card state */
  124. #define SDMMC_ERROR_CARD_ECC_FAILED 0x00004000U /*!< Card internal ECC was applied but failed to correct the data */
  125. #define SDMMC_ERROR_CC_ERR 0x00008000U /*!< Internal card controller error */
  126. #define SDMMC_ERROR_GENERAL_UNKNOWN_ERR 0x00010000U /*!< General or unknown error */
  127. #define SDMMC_ERROR_STREAM_READ_UNDERRUN 0x00020000U /*!< The card could not sustain data reading in stream rmode */
  128. #define SDMMC_ERROR_STREAM_WRITE_OVERRUN 0x00040000U /*!< The card could not sustain data programming in stream mode */
  129. #define SDMMC_ERROR_CID_CSD_OVERWRITE 0x00080000U /*!< CID/CSD overwrite error */
  130. #define SDMMC_ERROR_WP_ERASE_SKIP 0x00100000U /*!< Only partial address space was erased */
  131. #define SDMMC_ERROR_CARD_ECC_DISABLED 0x00200000U /*!< Command has been executed without using internal ECC */
  132. #define SDMMC_ERROR_ERASE_RESET 0x00400000U /*!< Erase sequence was cleared before executing because an out
  133. of erase sequence command was received */
  134. #define SDMMC_ERROR_AKE_SEQ_ERR 0x00800000U /*!< Error in sequence of authentication */
  135. #define SDMMC_ERROR_INVALID_VOLTRANGE 0x01000000U /*!< Error in case of invalid voltage range */
  136. #define SDMMC_ERROR_ADDR_OUT_OF_RANGE 0x02000000U /*!< Error when addressed block is out of range */
  137. #define SDMMC_ERROR_REQUEST_NOT_APPLICABLE 0x04000000U /*!< Error when command request is not applicable */
  138. #define SDMMC_ERROR_INVALID_PARAMETER 0x08000000U /*!< the used parameter is not valid */
  139. #define SDMMC_ERROR_UNSUPPORTED_FEATURE 0x10000000U /*!< Error when feature is not insupported */
  140. #define SDMMC_ERROR_BUSY 0x20000000U /*!< Error when transfer process is busy */
  141. #define SDMMC_ERROR_DMA 0x40000000U /*!< Error while DMA transfer */
  142. #define SDMMC_ERROR_TIMEOUT 0x80000000U /*!< Timeout error */
  143. /**
  144. * @brief SDMMC Commands Index
  145. */
  146. #define SDMMC_CMD_GO_IDLE_STATE ((uint8_t)0) /*!< Resets the SD memory card. */
  147. #define SDMMC_CMD_SEND_OP_COND ((uint8_t)1) /*!< Sends host capacity support information and activates the card's initialization process. */
  148. #define SDMMC_CMD_ALL_SEND_CID ((uint8_t)2) /*!< Asks any card connected to the host to send the CID numbers on the CMD line. */
  149. #define SDMMC_CMD_SET_REL_ADDR ((uint8_t)3) /*!< Asks the card to publish a new relative address (RCA). */
  150. #define SDMMC_CMD_SET_DSR ((uint8_t)4) /*!< Programs the DSR of all cards. */
  151. #define SDMMC_CMD_SDMMC_SEN_OP_COND ((uint8_t)5) /*!< Sends host capacity support information (HCS) and asks the accessed card to send its
  152. operating condition register (OCR) content in the response on the CMD line. */
  153. #define SDMMC_CMD_HS_SWITCH ((uint8_t)6) /*!< Checks switchable function (mode 0) and switch card function (mode 1). */
  154. #define SDMMC_CMD_SEL_DESEL_CARD ((uint8_t)7) /*!< Selects the card by its own relative address and gets deselected by any other address */
  155. #define SDMMC_CMD_HS_SEND_EXT_CSD ((uint8_t)8) /*!< Sends SD Memory Card interface condition, which includes host supply voltage information
  156. and asks the card whether card supports voltage. */
  157. #define SDMMC_CMD_SEND_CSD ((uint8_t)9) /*!< Addressed card sends its card specific data (CSD) on the CMD line. */
  158. #define SDMMC_CMD_SEND_CID ((uint8_t)10) /*!< Addressed card sends its card identification (CID) on the CMD line. */
  159. #define SDMMC_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11) /*!< SD card doesn't support it. */
  160. #define SDMMC_CMD_STOP_TRANSMISSION ((uint8_t)12) /*!< Forces the card to stop transmission. */
  161. #define SDMMC_CMD_SEND_STATUS ((uint8_t)13) /*!< Addressed card sends its status register. */
  162. #define SDMMC_CMD_HS_BUSTEST_READ ((uint8_t)14) /*!< Reserved */
  163. #define SDMMC_CMD_GO_INACTIVE_STATE ((uint8_t)15) /*!< Sends an addressed card into the inactive state. */
  164. #define SDMMC_CMD_SET_BLOCKLEN ((uint8_t)16) /*!< Sets the block length (in bytes for SDSC) for all following block commands
  165. (read, write, lock). Default block length is fixed to 512 Bytes. Not effective
  166. for SDHS and SDXC. */
  167. #define SDMMC_CMD_READ_SINGLE_BLOCK ((uint8_t)17) /*!< Reads single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of
  168. fixed 512 bytes in case of SDHC and SDXC. */
  169. #define SDMMC_CMD_READ_MULT_BLOCK ((uint8_t)18) /*!< Continuously transfers data blocks from card to host until interrupted by
  170. STOP_TRANSMISSION command. */
  171. #define SDMMC_CMD_HS_BUSTEST_WRITE ((uint8_t)19) /*!< 64 bytes tuning pattern is sent for SDR50 and SDR104. */
  172. #define SDMMC_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20) /*!< Speed class control command. */
  173. #define SDMMC_CMD_SET_BLOCK_COUNT ((uint8_t)23) /*!< Specify block count for CMD18 and CMD25. */
  174. #define SDMMC_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24) /*!< Writes single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of
  175. fixed 512 bytes in case of SDHC and SDXC. */
  176. #define SDMMC_CMD_WRITE_MULT_BLOCK ((uint8_t)25) /*!< Continuously writes blocks of data until a STOP_TRANSMISSION follows. */
  177. #define SDMMC_CMD_PROG_CID ((uint8_t)26) /*!< Reserved for manufacturers. */
  178. #define SDMMC_CMD_PROG_CSD ((uint8_t)27) /*!< Programming of the programmable bits of the CSD. */
  179. #define SDMMC_CMD_SET_WRITE_PROT ((uint8_t)28) /*!< Sets the write protection bit of the addressed group. */
  180. #define SDMMC_CMD_CLR_WRITE_PROT ((uint8_t)29) /*!< Clears the write protection bit of the addressed group. */
  181. #define SDMMC_CMD_SEND_WRITE_PROT ((uint8_t)30) /*!< Asks the card to send the status of the write protection bits. */
  182. #define SDMMC_CMD_SD_ERASE_GRP_START ((uint8_t)32) /*!< Sets the address of the first write block to be erased. (For SD card only). */
  183. #define SDMMC_CMD_SD_ERASE_GRP_END ((uint8_t)33) /*!< Sets the address of the last write block of the continuous range to be erased. */
  184. #define SDMMC_CMD_ERASE_GRP_START ((uint8_t)35) /*!< Sets the address of the first write block to be erased. Reserved for each command
  185. system set by switch function command (CMD6). */
  186. #define SDMMC_CMD_ERASE_GRP_END ((uint8_t)36) /*!< Sets the address of the last write block of the continuous range to be erased.
  187. Reserved for each command system set by switch function command (CMD6). */
  188. #define SDMMC_CMD_ERASE ((uint8_t)38) /*!< Reserved for SD security applications. */
  189. #define SDMMC_CMD_FAST_IO ((uint8_t)39) /*!< SD card doesn't support it (Reserved). */
  190. #define SDMMC_CMD_GO_IRQ_STATE ((uint8_t)40) /*!< SD card doesn't support it (Reserved). */
  191. #define SDMMC_CMD_LOCK_UNLOCK ((uint8_t)42) /*!< Sets/resets the password or lock/unlock the card. The size of the data block is set by
  192. the SET_BLOCK_LEN command. */
  193. #define SDMMC_CMD_APP_CMD ((uint8_t)55) /*!< Indicates to the card that the next command is an application specific command rather
  194. than a standard command. */
  195. #define SDMMC_CMD_GEN_CMD ((uint8_t)56) /*!< Used either to transfer a data block to the card or to get a data block from the card
  196. for general purpose/application specific commands. */
  197. #define SDMMC_CMD_NO_CMD ((uint8_t)64) /*!< No command */
  198. /**
  199. * @brief Following commands are SD Card Specific commands.
  200. * SDMMC_APP_CMD should be sent before sending these commands.
  201. */
  202. #define SDMMC_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6) /*!< (ACMD6) Defines the data bus width to be used for data transfer. The allowed data bus
  203. widths are given in SCR register. */
  204. #define SDMMC_CMD_SD_APP_STATUS ((uint8_t)13) /*!< (ACMD13) Sends the SD status. */
  205. #define SDMMC_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22) /*!< (ACMD22) Sends the number of the written (without errors) write blocks. Responds with
  206. 32bit+CRC data block. */
  207. #define SDMMC_CMD_SD_APP_OP_COND ((uint8_t)41) /*!< (ACMD41) Sends host capacity support information (HCS) and asks the accessed card to
  208. send its operating condition register (OCR) content in the response on the CMD line. */
  209. #define SDMMC_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42) /*!< (ACMD42) Connect/Disconnect the 50 KOhm pull-up resistor on CD/DAT3 (pin 1) of the card */
  210. #define SDMMC_CMD_SD_APP_SEND_SCR ((uint8_t)51) /*!< Reads the SD Configuration Register (SCR). */
  211. #define SDMMC_CMD_SDMMC_RW_DIRECT ((uint8_t)52) /*!< For SD I/O card only, reserved for security specification. */
  212. #define SDMMC_CMD_SDMMC_RW_EXTENDED ((uint8_t)53) /*!< For SD I/O card only, reserved for security specification. */
  213. /**
  214. * @brief Following commands are SD Card Specific security commands.
  215. * SDMMC_CMD_APP_CMD should be sent before sending these commands.
  216. */
  217. #define SDMMC_CMD_SD_APP_GET_MKB ((uint8_t)43)
  218. #define SDMMC_CMD_SD_APP_GET_MID ((uint8_t)44)
  219. #define SDMMC_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45)
  220. #define SDMMC_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46)
  221. #define SDMMC_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47)
  222. #define SDMMC_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48)
  223. #define SDMMC_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18)
  224. #define SDMMC_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25)
  225. #define SDMMC_CMD_SD_APP_SECURE_ERASE ((uint8_t)38)
  226. #define SDMMC_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49)
  227. #define SDMMC_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48)
  228. /**
  229. * @brief Masks for errors Card Status R1 (OCR Register)
  230. */
  231. #define SDMMC_OCR_ADDR_OUT_OF_RANGE 0x80000000U
  232. #define SDMMC_OCR_ADDR_MISALIGNED 0x40000000U
  233. #define SDMMC_OCR_BLOCK_LEN_ERR 0x20000000U
  234. #define SDMMC_OCR_ERASE_SEQ_ERR 0x10000000U
  235. #define SDMMC_OCR_BAD_ERASE_PARAM 0x08000000U
  236. #define SDMMC_OCR_WRITE_PROT_VIOLATION 0x04000000U
  237. #define SDMMC_OCR_LOCK_UNLOCK_FAILED 0x01000000U
  238. #define SDMMC_OCR_COM_CRC_FAILED 0x00800000U
  239. #define SDMMC_OCR_ILLEGAL_CMD 0x00400000U
  240. #define SDMMC_OCR_CARD_ECC_FAILED 0x00200000U
  241. #define SDMMC_OCR_CC_ERROR 0x00100000U
  242. #define SDMMC_OCR_GENERAL_UNKNOWN_ERROR 0x00080000U
  243. #define SDMMC_OCR_STREAM_READ_UNDERRUN 0x00040000U
  244. #define SDMMC_OCR_STREAM_WRITE_OVERRUN 0x00020000U
  245. #define SDMMC_OCR_CID_CSD_OVERWRITE 0x00010000U
  246. #define SDMMC_OCR_WP_ERASE_SKIP 0x00008000U
  247. #define SDMMC_OCR_CARD_ECC_DISABLED 0x00004000U
  248. #define SDMMC_OCR_ERASE_RESET 0x00002000U
  249. #define SDMMC_OCR_AKE_SEQ_ERROR 0x00000008U
  250. #define SDMMC_OCR_ERRORBITS 0xFDFFE008U
  251. /**
  252. * @brief Masks for R6 Response
  253. */
  254. #define SDMMC_R6_GENERAL_UNKNOWN_ERROR 0x00002000U
  255. #define SDMMC_R6_ILLEGAL_CMD 0x00004000U
  256. #define SDMMC_R6_COM_CRC_FAILED 0x00008000U
  257. #define SDMMC_VOLTAGE_WINDOW_SD 0x80100000U
  258. #define SDMMC_HIGH_CAPACITY 0x40000000U
  259. #define SDMMC_STD_CAPACITY 0x00000000U
  260. #define SDMMC_CHECK_PATTERN 0x000001AAU
  261. #define SDMMC_MAX_VOLT_TRIAL 0x0000FFFFU
  262. #define SDMMC_MAX_TRIAL 0x0000FFFFU
  263. #define SDMMC_ALLZERO 0x00000000U
  264. #define SDMMC_WIDE_BUS_SUPPORT 0x00040000U
  265. #define SDMMC_SINGLE_BUS_SUPPORT 0x00010000U
  266. #define SDMMC_CARD_LOCKED 0x02000000U
  267. #define SDMMC_DATATIMEOUT 0xFFFFFFFFU
  268. #define SDMMC_0TO7BITS 0x000000FFU
  269. #define SDMMC_8TO15BITS 0x0000FF00U
  270. #define SDMMC_16TO23BITS 0x00FF0000U
  271. #define SDMMC_24TO31BITS 0xFF000000U
  272. #define SDMMC_MAX_DATA_LENGTH 0x01FFFFFFU
  273. #define SDMMC_HALFFIFO 0x00000008U
  274. #define SDMMC_HALFFIFOBYTES 0x00000020U
  275. /**
  276. * @brief Command Class supported
  277. */
  278. #define SDIO_CCCC_ERASE 0x00000020U
  279. #define SDIO_CMDTIMEOUT 5000U /* Command send and response timeout */
  280. #define SDIO_MAXERASETIMEOUT 63000U /* Max erase Timeout 63 s */
  281. /** @defgroup SDIO_LL_Clock_Edge Clock Edge
  282. * @{
  283. */
  284. #define SDIO_CLOCK_EDGE_RISING 0x00000000U
  285. #define SDIO_CLOCK_EDGE_FALLING SDIO_CLKCR_NEGEDGE
  286. #define IS_SDIO_CLOCK_EDGE(EDGE) (((EDGE) == SDIO_CLOCK_EDGE_RISING) || \
  287. ((EDGE) == SDIO_CLOCK_EDGE_FALLING))
  288. /**
  289. * @}
  290. */
  291. /** @defgroup SDIO_LL_Clock_Bypass Clock Bypass
  292. * @{
  293. */
  294. #define SDIO_CLOCK_BYPASS_DISABLE 0x00000000U
  295. #define SDIO_CLOCK_BYPASS_ENABLE SDIO_CLKCR_BYPASS
  296. #define IS_SDIO_CLOCK_BYPASS(BYPASS) (((BYPASS) == SDIO_CLOCK_BYPASS_DISABLE) || \
  297. ((BYPASS) == SDIO_CLOCK_BYPASS_ENABLE))
  298. /**
  299. * @}
  300. */
  301. /** @defgroup SDIO_LL_Clock_Power_Save Clock Power Saving
  302. * @{
  303. */
  304. #define SDIO_CLOCK_POWER_SAVE_DISABLE 0x00000000U
  305. #define SDIO_CLOCK_POWER_SAVE_ENABLE SDIO_CLKCR_PWRSAV
  306. #define IS_SDIO_CLOCK_POWER_SAVE(SAVE) (((SAVE) == SDIO_CLOCK_POWER_SAVE_DISABLE) || \
  307. ((SAVE) == SDIO_CLOCK_POWER_SAVE_ENABLE))
  308. /**
  309. * @}
  310. */
  311. /** @defgroup SDIO_LL_Bus_Wide Bus Width
  312. * @{
  313. */
  314. #define SDIO_BUS_WIDE_1B 0x00000000U
  315. #define SDIO_BUS_WIDE_4B SDIO_CLKCR_WIDBUS_0
  316. #define SDIO_BUS_WIDE_8B SDIO_CLKCR_WIDBUS_1
  317. #define IS_SDIO_BUS_WIDE(WIDE) (((WIDE) == SDIO_BUS_WIDE_1B) || \
  318. ((WIDE) == SDIO_BUS_WIDE_4B) || \
  319. ((WIDE) == SDIO_BUS_WIDE_8B))
  320. /**
  321. * @}
  322. */
  323. /** @defgroup SDIO_LL_Hardware_Flow_Control Hardware Flow Control
  324. * @{
  325. */
  326. #define SDIO_HARDWARE_FLOW_CONTROL_DISABLE 0x00000000U
  327. #define SDIO_HARDWARE_FLOW_CONTROL_ENABLE SDIO_CLKCR_HWFC_EN
  328. #define IS_SDIO_HARDWARE_FLOW_CONTROL(CONTROL) (((CONTROL) == SDIO_HARDWARE_FLOW_CONTROL_DISABLE) || \
  329. ((CONTROL) == SDIO_HARDWARE_FLOW_CONTROL_ENABLE))
  330. /**
  331. * @}
  332. */
  333. /** @defgroup SDIO_LL_Clock_Division Clock Division
  334. * @{
  335. */
  336. #define IS_SDIO_CLKDIV(DIV) ((DIV) <= 0xFFU)
  337. /**
  338. * @}
  339. */
  340. /** @defgroup SDIO_LL_Command_Index Command Index
  341. * @{
  342. */
  343. #define IS_SDIO_CMD_INDEX(INDEX) ((INDEX) < 0x40U)
  344. /**
  345. * @}
  346. */
  347. /** @defgroup SDIO_LL_Response_Type Response Type
  348. * @{
  349. */
  350. #define SDIO_RESPONSE_NO 0x00000000U
  351. #define SDIO_RESPONSE_SHORT SDIO_CMD_WAITRESP_0
  352. #define SDIO_RESPONSE_LONG SDIO_CMD_WAITRESP
  353. #define IS_SDIO_RESPONSE(RESPONSE) (((RESPONSE) == SDIO_RESPONSE_NO) || \
  354. ((RESPONSE) == SDIO_RESPONSE_SHORT) || \
  355. ((RESPONSE) == SDIO_RESPONSE_LONG))
  356. /**
  357. * @}
  358. */
  359. /** @defgroup SDIO_LL_Wait_Interrupt_State Wait Interrupt
  360. * @{
  361. */
  362. #define SDIO_WAIT_NO 0x00000000U
  363. #define SDIO_WAIT_IT SDIO_CMD_WAITINT
  364. #define SDIO_WAIT_PEND SDIO_CMD_WAITPEND
  365. #define IS_SDIO_WAIT(WAIT) (((WAIT) == SDIO_WAIT_NO) || \
  366. ((WAIT) == SDIO_WAIT_IT) || \
  367. ((WAIT) == SDIO_WAIT_PEND))
  368. /**
  369. * @}
  370. */
  371. /** @defgroup SDIO_LL_CPSM_State CPSM State
  372. * @{
  373. */
  374. #define SDIO_CPSM_DISABLE 0x00000000U
  375. #define SDIO_CPSM_ENABLE SDIO_CMD_CPSMEN
  376. #define IS_SDIO_CPSM(CPSM) (((CPSM) == SDIO_CPSM_DISABLE) || \
  377. ((CPSM) == SDIO_CPSM_ENABLE))
  378. /**
  379. * @}
  380. */
  381. /** @defgroup SDIO_LL_Response_Registers Response Register
  382. * @{
  383. */
  384. #define SDIO_RESP1 0x00000000U
  385. #define SDIO_RESP2 0x00000004U
  386. #define SDIO_RESP3 0x00000008U
  387. #define SDIO_RESP4 0x0000000CU
  388. #define IS_SDIO_RESP(RESP) (((RESP) == SDIO_RESP1) || \
  389. ((RESP) == SDIO_RESP2) || \
  390. ((RESP) == SDIO_RESP3) || \
  391. ((RESP) == SDIO_RESP4))
  392. /**
  393. * @}
  394. */
  395. /** @defgroup SDIO_LL_Data_Length Data Lenght
  396. * @{
  397. */
  398. #define IS_SDIO_DATA_LENGTH(LENGTH) ((LENGTH) <= 0x01FFFFFFU)
  399. /**
  400. * @}
  401. */
  402. /** @defgroup SDIO_LL_Data_Block_Size Data Block Size
  403. * @{
  404. */
  405. #define SDIO_DATABLOCK_SIZE_1B 0x00000000U
  406. #define SDIO_DATABLOCK_SIZE_2B SDIO_DCTRL_DBLOCKSIZE_0
  407. #define SDIO_DATABLOCK_SIZE_4B SDIO_DCTRL_DBLOCKSIZE_1
  408. #define SDIO_DATABLOCK_SIZE_8B (SDIO_DCTRL_DBLOCKSIZE_0|SDIO_DCTRL_DBLOCKSIZE_1)
  409. #define SDIO_DATABLOCK_SIZE_16B SDIO_DCTRL_DBLOCKSIZE_2
  410. #define SDIO_DATABLOCK_SIZE_32B (SDIO_DCTRL_DBLOCKSIZE_0|SDIO_DCTRL_DBLOCKSIZE_2)
  411. #define SDIO_DATABLOCK_SIZE_64B (SDIO_DCTRL_DBLOCKSIZE_1|SDIO_DCTRL_DBLOCKSIZE_2)
  412. #define SDIO_DATABLOCK_SIZE_128B (SDIO_DCTRL_DBLOCKSIZE_0|SDIO_DCTRL_DBLOCKSIZE_1|SDIO_DCTRL_DBLOCKSIZE_2)
  413. #define SDIO_DATABLOCK_SIZE_256B SDIO_DCTRL_DBLOCKSIZE_3
  414. #define SDIO_DATABLOCK_SIZE_512B (SDIO_DCTRL_DBLOCKSIZE_0|SDIO_DCTRL_DBLOCKSIZE_3)
  415. #define SDIO_DATABLOCK_SIZE_1024B (SDIO_DCTRL_DBLOCKSIZE_1|SDIO_DCTRL_DBLOCKSIZE_3)
  416. #define SDIO_DATABLOCK_SIZE_2048B (SDIO_DCTRL_DBLOCKSIZE_0|SDIO_DCTRL_DBLOCKSIZE_1|SDIO_DCTRL_DBLOCKSIZE_3)
  417. #define SDIO_DATABLOCK_SIZE_4096B (SDIO_DCTRL_DBLOCKSIZE_2|SDIO_DCTRL_DBLOCKSIZE_3)
  418. #define SDIO_DATABLOCK_SIZE_8192B (SDIO_DCTRL_DBLOCKSIZE_0|SDIO_DCTRL_DBLOCKSIZE_2|SDIO_DCTRL_DBLOCKSIZE_3)
  419. #define SDIO_DATABLOCK_SIZE_16384B (SDIO_DCTRL_DBLOCKSIZE_1|SDIO_DCTRL_DBLOCKSIZE_2|SDIO_DCTRL_DBLOCKSIZE_3)
  420. #define IS_SDIO_BLOCK_SIZE(SIZE) (((SIZE) == SDIO_DATABLOCK_SIZE_1B) || \
  421. ((SIZE) == SDIO_DATABLOCK_SIZE_2B) || \
  422. ((SIZE) == SDIO_DATABLOCK_SIZE_4B) || \
  423. ((SIZE) == SDIO_DATABLOCK_SIZE_8B) || \
  424. ((SIZE) == SDIO_DATABLOCK_SIZE_16B) || \
  425. ((SIZE) == SDIO_DATABLOCK_SIZE_32B) || \
  426. ((SIZE) == SDIO_DATABLOCK_SIZE_64B) || \
  427. ((SIZE) == SDIO_DATABLOCK_SIZE_128B) || \
  428. ((SIZE) == SDIO_DATABLOCK_SIZE_256B) || \
  429. ((SIZE) == SDIO_DATABLOCK_SIZE_512B) || \
  430. ((SIZE) == SDIO_DATABLOCK_SIZE_1024B) || \
  431. ((SIZE) == SDIO_DATABLOCK_SIZE_2048B) || \
  432. ((SIZE) == SDIO_DATABLOCK_SIZE_4096B) || \
  433. ((SIZE) == SDIO_DATABLOCK_SIZE_8192B) || \
  434. ((SIZE) == SDIO_DATABLOCK_SIZE_16384B))
  435. /**
  436. * @}
  437. */
  438. /** @defgroup SDIO_LL_Transfer_Direction Transfer Direction
  439. * @{
  440. */
  441. #define SDIO_TRANSFER_DIR_TO_CARD 0x00000000U
  442. #define SDIO_TRANSFER_DIR_TO_SDIO SDIO_DCTRL_DTDIR
  443. #define IS_SDIO_TRANSFER_DIR(DIR) (((DIR) == SDIO_TRANSFER_DIR_TO_CARD) || \
  444. ((DIR) == SDIO_TRANSFER_DIR_TO_SDIO))
  445. /**
  446. * @}
  447. */
  448. /** @defgroup SDIO_LL_Transfer_Type Transfer Type
  449. * @{
  450. */
  451. #define SDIO_TRANSFER_MODE_BLOCK 0x00000000U
  452. #define SDIO_TRANSFER_MODE_STREAM SDIO_DCTRL_DTMODE
  453. #define IS_SDIO_TRANSFER_MODE(MODE) (((MODE) == SDIO_TRANSFER_MODE_BLOCK) || \
  454. ((MODE) == SDIO_TRANSFER_MODE_STREAM))
  455. /**
  456. * @}
  457. */
  458. /** @defgroup SDIO_LL_DPSM_State DPSM State
  459. * @{
  460. */
  461. #define SDIO_DPSM_DISABLE 0x00000000U
  462. #define SDIO_DPSM_ENABLE SDIO_DCTRL_DTEN
  463. #define IS_SDIO_DPSM(DPSM) (((DPSM) == SDIO_DPSM_DISABLE) ||\
  464. ((DPSM) == SDIO_DPSM_ENABLE))
  465. /**
  466. * @}
  467. */
  468. /** @defgroup SDIO_LL_Read_Wait_Mode Read Wait Mode
  469. * @{
  470. */
  471. #define SDIO_READ_WAIT_MODE_DATA2 0x00000000U
  472. #define SDIO_READ_WAIT_MODE_CLK (SDIO_DCTRL_RWMOD)
  473. #define IS_SDIO_READWAIT_MODE(MODE) (((MODE) == SDIO_READ_WAIT_MODE_CLK) || \
  474. ((MODE) == SDIO_READ_WAIT_MODE_DATA2))
  475. /**
  476. * @}
  477. */
  478. /** @defgroup SDIO_LL_Interrupt_sources Interrupt Sources
  479. * @{
  480. */
  481. #define SDIO_IT_CCRCFAIL SDIO_STA_CCRCFAIL
  482. #define SDIO_IT_DCRCFAIL SDIO_STA_DCRCFAIL
  483. #define SDIO_IT_CTIMEOUT SDIO_STA_CTIMEOUT
  484. #define SDIO_IT_DTIMEOUT SDIO_STA_DTIMEOUT
  485. #define SDIO_IT_TXUNDERR SDIO_STA_TXUNDERR
  486. #define SDIO_IT_RXOVERR SDIO_STA_RXOVERR
  487. #define SDIO_IT_CMDREND SDIO_STA_CMDREND
  488. #define SDIO_IT_CMDSENT SDIO_STA_CMDSENT
  489. #define SDIO_IT_DATAEND SDIO_STA_DATAEND
  490. #define SDIO_IT_STBITERR SDIO_STA_STBITERR
  491. #define SDIO_IT_DBCKEND SDIO_STA_DBCKEND
  492. #define SDIO_IT_CMDACT SDIO_STA_CMDACT
  493. #define SDIO_IT_TXACT SDIO_STA_TXACT
  494. #define SDIO_IT_RXACT SDIO_STA_RXACT
  495. #define SDIO_IT_TXFIFOHE SDIO_STA_TXFIFOHE
  496. #define SDIO_IT_RXFIFOHF SDIO_STA_RXFIFOHF
  497. #define SDIO_IT_TXFIFOF SDIO_STA_TXFIFOF
  498. #define SDIO_IT_RXFIFOF SDIO_STA_RXFIFOF
  499. #define SDIO_IT_TXFIFOE SDIO_STA_TXFIFOE
  500. #define SDIO_IT_RXFIFOE SDIO_STA_RXFIFOE
  501. #define SDIO_IT_TXDAVL SDIO_STA_TXDAVL
  502. #define SDIO_IT_RXDAVL SDIO_STA_RXDAVL
  503. #define SDIO_IT_SDIOIT SDIO_STA_SDIOIT
  504. #define SDIO_IT_CEATAEND SDIO_STA_CEATAEND
  505. /**
  506. * @}
  507. */
  508. /** @defgroup SDIO_LL_Flags Flags
  509. * @{
  510. */
  511. #define SDIO_FLAG_CCRCFAIL SDIO_STA_CCRCFAIL
  512. #define SDIO_FLAG_DCRCFAIL SDIO_STA_DCRCFAIL
  513. #define SDIO_FLAG_CTIMEOUT SDIO_STA_CTIMEOUT
  514. #define SDIO_FLAG_DTIMEOUT SDIO_STA_DTIMEOUT
  515. #define SDIO_FLAG_TXUNDERR SDIO_STA_TXUNDERR
  516. #define SDIO_FLAG_RXOVERR SDIO_STA_RXOVERR
  517. #define SDIO_FLAG_CMDREND SDIO_STA_CMDREND
  518. #define SDIO_FLAG_CMDSENT SDIO_STA_CMDSENT
  519. #define SDIO_FLAG_DATAEND SDIO_STA_DATAEND
  520. #define SDIO_FLAG_STBITERR SDIO_STA_STBITERR
  521. #define SDIO_FLAG_DBCKEND SDIO_STA_DBCKEND
  522. #define SDIO_FLAG_CMDACT SDIO_STA_CMDACT
  523. #define SDIO_FLAG_TXACT SDIO_STA_TXACT
  524. #define SDIO_FLAG_RXACT SDIO_STA_RXACT
  525. #define SDIO_FLAG_TXFIFOHE SDIO_STA_TXFIFOHE
  526. #define SDIO_FLAG_RXFIFOHF SDIO_STA_RXFIFOHF
  527. #define SDIO_FLAG_TXFIFOF SDIO_STA_TXFIFOF
  528. #define SDIO_FLAG_RXFIFOF SDIO_STA_RXFIFOF
  529. #define SDIO_FLAG_TXFIFOE SDIO_STA_TXFIFOE
  530. #define SDIO_FLAG_RXFIFOE SDIO_STA_RXFIFOE
  531. #define SDIO_FLAG_TXDAVL SDIO_STA_TXDAVL
  532. #define SDIO_FLAG_RXDAVL SDIO_STA_RXDAVL
  533. #define SDIO_FLAG_SDIOIT SDIO_STA_SDIOIT
  534. #define SDIO_FLAG_CEATAEND SDIO_STA_CEATAEND
  535. #define SDIO_STATIC_FLAGS ((uint32_t)(SDIO_FLAG_CCRCFAIL | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_CTIMEOUT |\
  536. SDIO_FLAG_DTIMEOUT | SDIO_FLAG_TXUNDERR | SDIO_FLAG_RXOVERR |\
  537. SDIO_FLAG_CMDREND | SDIO_FLAG_CMDSENT | SDIO_FLAG_DATAEND |\
  538. SDIO_FLAG_DBCKEND))
  539. /**
  540. * @}
  541. */
  542. /**
  543. * @}
  544. */
  545. /* Exported macro ------------------------------------------------------------*/
  546. /** @defgroup SDIO_LL_Exported_macros SDIO_LL Exported Macros
  547. * @{
  548. */
  549. /** @defgroup SDMMC_LL_Alias_Region Bit Address in the alias region
  550. * @{
  551. */
  552. /* ------------ SDIO registers bit address in the alias region -------------- */
  553. #define SDIO_OFFSET (SDIO_BASE - PERIPH_BASE)
  554. /* --- CLKCR Register ---*/
  555. /* Alias word address of CLKEN bit */
  556. #define CLKCR_OFFSET (SDIO_OFFSET + 0x04U)
  557. #define CLKEN_BITNUMBER 0x08U
  558. #define CLKCR_CLKEN_BB (PERIPH_BB_BASE + (CLKCR_OFFSET * 32U) + (CLKEN_BITNUMBER * 4U))
  559. /* --- CMD Register ---*/
  560. /* Alias word address of SDIOSUSPEND bit */
  561. #define CMD_OFFSET (SDIO_OFFSET + 0x0CU)
  562. #define SDIOSUSPEND_BITNUMBER 0x0BU
  563. #define CMD_SDIOSUSPEND_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32U) + (SDIOSUSPEND_BITNUMBER * 4U))
  564. /* Alias word address of ENCMDCOMPL bit */
  565. #define ENCMDCOMPL_BITNUMBER 0x0CU
  566. #define CMD_ENCMDCOMPL_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32U) + (ENCMDCOMPL_BITNUMBER * 4U))
  567. /* Alias word address of NIEN bit */
  568. #define NIEN_BITNUMBER 0x0DU
  569. #define CMD_NIEN_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32U) + (NIEN_BITNUMBER * 4U))
  570. /* Alias word address of ATACMD bit */
  571. #define ATACMD_BITNUMBER 0x0EU
  572. #define CMD_ATACMD_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32U) + (ATACMD_BITNUMBER * 4U))
  573. /* --- DCTRL Register ---*/
  574. /* Alias word address of DMAEN bit */
  575. #define DCTRL_OFFSET (SDIO_OFFSET + 0x2CU)
  576. #define DMAEN_BITNUMBER 0x03U
  577. #define DCTRL_DMAEN_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32U) + (DMAEN_BITNUMBER * 4U))
  578. /* Alias word address of RWSTART bit */
  579. #define RWSTART_BITNUMBER 0x08U
  580. #define DCTRL_RWSTART_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32U) + (RWSTART_BITNUMBER * 4U))
  581. /* Alias word address of RWSTOP bit */
  582. #define RWSTOP_BITNUMBER 0x09U
  583. #define DCTRL_RWSTOP_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32U) + (RWSTOP_BITNUMBER * 4U))
  584. /* Alias word address of RWMOD bit */
  585. #define RWMOD_BITNUMBER 0x0AU
  586. #define DCTRL_RWMOD_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32U) + (RWMOD_BITNUMBER * 4U))
  587. /* Alias word address of SDIOEN bit */
  588. #define SDIOEN_BITNUMBER 0x0BU
  589. #define DCTRL_SDIOEN_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32U) + (SDIOEN_BITNUMBER * 4U))
  590. /**
  591. * @}
  592. */
  593. /** @defgroup SDIO_LL_Register Bits And Addresses Definitions
  594. * @brief SDIO_LL registers bit address in the alias region
  595. * @{
  596. */
  597. /* ---------------------- SDIO registers bit mask --------------------------- */
  598. /* --- CLKCR Register ---*/
  599. /* CLKCR register clear mask */
  600. #define CLKCR_CLEAR_MASK ((uint32_t)(SDIO_CLKCR_CLKDIV | SDIO_CLKCR_PWRSAV |\
  601. SDIO_CLKCR_BYPASS | SDIO_CLKCR_WIDBUS |\
  602. SDIO_CLKCR_NEGEDGE | SDIO_CLKCR_HWFC_EN))
  603. /* --- DCTRL Register ---*/
  604. /* SDIO DCTRL Clear Mask */
  605. #define DCTRL_CLEAR_MASK ((uint32_t)(SDIO_DCTRL_DTEN | SDIO_DCTRL_DTDIR |\
  606. SDIO_DCTRL_DTMODE | SDIO_DCTRL_DBLOCKSIZE))
  607. /* --- CMD Register ---*/
  608. /* CMD Register clear mask */
  609. #define CMD_CLEAR_MASK ((uint32_t)(SDIO_CMD_CMDINDEX | SDIO_CMD_WAITRESP |\
  610. SDIO_CMD_WAITINT | SDIO_CMD_WAITPEND |\
  611. SDIO_CMD_CPSMEN | SDIO_CMD_SDIOSUSPEND))
  612. /* SDIO Initialization Frequency (400KHz max) */
  613. #define SDIO_INIT_CLK_DIV ((uint8_t)0x76)
  614. /* SDIO Data Transfer Frequency (25MHz max) */
  615. #define SDIO_TRANSFER_CLK_DIV ((uint8_t)0x0)
  616. /**
  617. * @}
  618. */
  619. /** @defgroup SDIO_LL_Interrupt_Clock Interrupt And Clock Configuration
  620. * @brief macros to handle interrupts and specific clock configurations
  621. * @{
  622. */
  623. /**
  624. * @brief Enable the SDIO device.
  625. * @param __INSTANCE__ SDIO Instance
  626. * @retval None
  627. */
  628. #define __SDIO_ENABLE(__INSTANCE__) (*(__IO uint32_t *)CLKCR_CLKEN_BB = ENABLE)
  629. /**
  630. * @brief Disable the SDIO device.
  631. * @param __INSTANCE__ SDIO Instance
  632. * @retval None
  633. */
  634. #define __SDIO_DISABLE(__INSTANCE__) (*(__IO uint32_t *)CLKCR_CLKEN_BB = DISABLE)
  635. /**
  636. * @brief Enable the SDIO DMA transfer.
  637. * @param __INSTANCE__ SDIO Instance
  638. * @retval None
  639. */
  640. #define __SDIO_DMA_ENABLE(__INSTANCE__) (*(__IO uint32_t *)DCTRL_DMAEN_BB = ENABLE)
  641. /**
  642. * @brief Disable the SDIO DMA transfer.
  643. * @param __INSTANCE__ SDIO Instance
  644. * @retval None
  645. */
  646. #define __SDIO_DMA_DISABLE(__INSTANCE__) (*(__IO uint32_t *)DCTRL_DMAEN_BB = DISABLE)
  647. /**
  648. * @brief Enable the SDIO device interrupt.
  649. * @param __INSTANCE__ Pointer to SDIO register base
  650. * @param __INTERRUPT__ specifies the SDIO interrupt sources to be enabled.
  651. * This parameter can be one or a combination of the following values:
  652. * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  653. * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  654. * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
  655. * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
  656. * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  657. * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
  658. * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
  659. * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
  660. * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  661. * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  662. * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
  663. * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
  664. * @arg SDIO_IT_RXACT: Data receive in progress interrupt
  665. * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  666. * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  667. * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
  668. * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
  669. * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
  670. * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
  671. * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
  672. * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
  673. * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
  674. * @retval None
  675. */
  676. #define __SDIO_ENABLE_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->MASK |= (__INTERRUPT__))
  677. /**
  678. * @brief Disable the SDIO device interrupt.
  679. * @param __INSTANCE__ Pointer to SDIO register base
  680. * @param __INTERRUPT__ specifies the SDIO interrupt sources to be disabled.
  681. * This parameter can be one or a combination of the following values:
  682. * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  683. * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  684. * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
  685. * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
  686. * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  687. * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
  688. * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
  689. * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
  690. * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  691. * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  692. * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
  693. * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
  694. * @arg SDIO_IT_RXACT: Data receive in progress interrupt
  695. * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  696. * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  697. * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
  698. * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
  699. * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
  700. * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
  701. * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
  702. * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
  703. * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
  704. * @retval None
  705. */
  706. #define __SDIO_DISABLE_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->MASK &= ~(__INTERRUPT__))
  707. /**
  708. * @brief Checks whether the specified SDIO flag is set or not.
  709. * @param __INSTANCE__ Pointer to SDIO register base
  710. * @param __FLAG__ specifies the flag to check.
  711. * This parameter can be one of the following values:
  712. * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
  713. * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  714. * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
  715. * @arg SDIO_FLAG_DTIMEOUT: Data timeout
  716. * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
  717. * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error
  718. * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed)
  719. * @arg SDIO_FLAG_CMDSENT: Command sent (no response required)
  720. * @arg SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  721. * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  722. * @arg SDIO_FLAG_CMDACT: Command transfer in progress
  723. * @arg SDIO_FLAG_TXACT: Data transmit in progress
  724. * @arg SDIO_FLAG_RXACT: Data receive in progress
  725. * @arg SDIO_FLAG_TXFIFOHE: Transmit FIFO Half Empty
  726. * @arg SDIO_FLAG_RXFIFOHF: Receive FIFO Half Full
  727. * @arg SDIO_FLAG_TXFIFOF: Transmit FIFO full
  728. * @arg SDIO_FLAG_RXFIFOF: Receive FIFO full
  729. * @arg SDIO_FLAG_TXFIFOE: Transmit FIFO empty
  730. * @arg SDIO_FLAG_RXFIFOE: Receive FIFO empty
  731. * @arg SDIO_FLAG_TXDAVL: Data available in transmit FIFO
  732. * @arg SDIO_FLAG_RXDAVL: Data available in receive FIFO
  733. * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received
  734. * @retval The new state of SDIO_FLAG (SET or RESET).
  735. */
  736. #define __SDIO_GET_FLAG(__INSTANCE__, __FLAG__) (((__INSTANCE__)->STA &(__FLAG__)) != RESET)
  737. /**
  738. * @brief Clears the SDIO pending flags.
  739. * @param __INSTANCE__ Pointer to SDIO register base
  740. * @param __FLAG__ specifies the flag to clear.
  741. * This parameter can be one or a combination of the following values:
  742. * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
  743. * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  744. * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
  745. * @arg SDIO_FLAG_DTIMEOUT: Data timeout
  746. * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
  747. * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error
  748. * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed)
  749. * @arg SDIO_FLAG_CMDSENT: Command sent (no response required)
  750. * @arg SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  751. * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  752. * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received
  753. * @retval None
  754. */
  755. #define __SDIO_CLEAR_FLAG(__INSTANCE__, __FLAG__) ((__INSTANCE__)->ICR = (__FLAG__))
  756. /**
  757. * @brief Checks whether the specified SDIO interrupt has occurred or not.
  758. * @param __INSTANCE__ Pointer to SDIO register base
  759. * @param __INTERRUPT__ specifies the SDIO interrupt source to check.
  760. * This parameter can be one of the following values:
  761. * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  762. * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  763. * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
  764. * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
  765. * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  766. * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
  767. * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
  768. * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
  769. * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  770. * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  771. * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
  772. * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
  773. * @arg SDIO_IT_RXACT: Data receive in progress interrupt
  774. * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  775. * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  776. * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
  777. * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
  778. * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
  779. * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
  780. * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
  781. * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
  782. * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
  783. * @retval The new state of SDIO_IT (SET or RESET).
  784. */
  785. #define __SDIO_GET_IT (__INSTANCE__, __INTERRUPT__) (((__INSTANCE__)->STA &(__INTERRUPT__)) == (__INTERRUPT__))
  786. /**
  787. * @brief Clears the SDIO's interrupt pending bits.
  788. * @param __INSTANCE__ Pointer to SDIO register base
  789. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  790. * This parameter can be one or a combination of the following values:
  791. * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  792. * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  793. * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
  794. * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
  795. * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  796. * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
  797. * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
  798. * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
  799. * @arg SDIO_IT_DATAEND: Data end (data counter, SDIO_DCOUNT, is zero) interrupt
  800. * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
  801. * @retval None
  802. */
  803. #define __SDIO_CLEAR_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->ICR = (__INTERRUPT__))
  804. /**
  805. * @brief Enable Start the SD I/O Read Wait operation.
  806. * @param __INSTANCE__ Pointer to SDIO register base
  807. * @retval None
  808. */
  809. #define __SDIO_START_READWAIT_ENABLE(__INSTANCE__) (*(__IO uint32_t *) DCTRL_RWSTART_BB = ENABLE)
  810. /**
  811. * @brief Disable Start the SD I/O Read Wait operations.
  812. * @param __INSTANCE__ Pointer to SDIO register base
  813. * @retval None
  814. */
  815. #define __SDIO_START_READWAIT_DISABLE(__INSTANCE__) (*(__IO uint32_t *) DCTRL_RWSTART_BB = DISABLE)
  816. /**
  817. * @brief Enable Start the SD I/O Read Wait operation.
  818. * @param __INSTANCE__ Pointer to SDIO register base
  819. * @retval None
  820. */
  821. #define __SDIO_STOP_READWAIT_ENABLE(__INSTANCE__) (*(__IO uint32_t *) DCTRL_RWSTOP_BB = ENABLE)
  822. /**
  823. * @brief Disable Stop the SD I/O Read Wait operations.
  824. * @param __INSTANCE__ Pointer to SDIO register base
  825. * @retval None
  826. */
  827. #define __SDIO_STOP_READWAIT_DISABLE(__INSTANCE__) (*(__IO uint32_t *) DCTRL_RWSTOP_BB = DISABLE)
  828. /**
  829. * @brief Enable the SD I/O Mode Operation.
  830. * @param __INSTANCE__ Pointer to SDIO register base
  831. * @retval None
  832. */
  833. #define __SDIO_OPERATION_ENABLE(__INSTANCE__) (*(__IO uint32_t *) DCTRL_SDIOEN_BB = ENABLE)
  834. /**
  835. * @brief Disable the SD I/O Mode Operation.
  836. * @param __INSTANCE__ Pointer to SDIO register base
  837. * @retval None
  838. */
  839. #define __SDIO_OPERATION_DISABLE(__INSTANCE__) (*(__IO uint32_t *) DCTRL_SDIOEN_BB = DISABLE)
  840. /**
  841. * @brief Enable the SD I/O Suspend command sending.
  842. * @param __INSTANCE__ Pointer to SDIO register base
  843. * @retval None
  844. */
  845. #define __SDIO_SUSPEND_CMD_ENABLE(__INSTANCE__) (*(__IO uint32_t *) CMD_SDIOSUSPEND_BB = ENABLE)
  846. /**
  847. * @brief Disable the SD I/O Suspend command sending.
  848. * @param __INSTANCE__ Pointer to SDIO register base
  849. * @retval None
  850. */
  851. #define __SDIO_SUSPEND_CMD_DISABLE(__INSTANCE__) (*(__IO uint32_t *) CMD_SDIOSUSPEND_BB = DISABLE)
  852. #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
  853. defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  854. defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
  855. /**
  856. * @brief Enable the command completion signal.
  857. * @retval None
  858. */
  859. #define __SDIO_CEATA_CMD_COMPLETION_ENABLE() (*(__IO uint32_t *) CMD_ENCMDCOMPL_BB = ENABLE)
  860. /**
  861. * @brief Disable the command completion signal.
  862. * @retval None
  863. */
  864. #define __SDIO_CEATA_CMD_COMPLETION_DISABLE() (*(__IO uint32_t *) CMD_ENCMDCOMPL_BB = DISABLE)
  865. /**
  866. * @brief Enable the CE-ATA interrupt.
  867. * @retval None
  868. */
  869. #define __SDIO_CEATA_ENABLE_IT() (*(__IO uint32_t *) CMD_NIEN_BB = (uint32_t)0U)
  870. /**
  871. * @brief Disable the CE-ATA interrupt.
  872. * @retval None
  873. */
  874. #define __SDIO_CEATA_DISABLE_IT() (*(__IO uint32_t *) CMD_NIEN_BB = (uint32_t)1U)
  875. /**
  876. * @brief Enable send CE-ATA command (CMD61).
  877. * @retval None
  878. */
  879. #define __SDIO_CEATA_SENDCMD_ENABLE() (*(__IO uint32_t *) CMD_ATACMD_BB = ENABLE)
  880. /**
  881. * @brief Disable send CE-ATA command (CMD61).
  882. * @retval None
  883. */
  884. #define __SDIO_CEATA_SENDCMD_DISABLE() (*(__IO uint32_t *) CMD_ATACMD_BB = DISABLE)
  885. #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F401xC || STM32F401xE || STM32F411xE ||\
  886. STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
  887. /**
  888. * @}
  889. */
  890. /**
  891. * @}
  892. */
  893. /* Exported functions --------------------------------------------------------*/
  894. /** @addtogroup SDMMC_LL_Exported_Functions
  895. * @{
  896. */
  897. /* Initialization/de-initialization functions **********************************/
  898. /** @addtogroup HAL_SDMMC_LL_Group1
  899. * @{
  900. */
  901. HAL_StatusTypeDef SDIO_Init(SDIO_TypeDef *SDIOx, SDIO_InitTypeDef Init);
  902. /**
  903. * @}
  904. */
  905. /* I/O operation functions *****************************************************/
  906. /** @addtogroup HAL_SDMMC_LL_Group2
  907. * @{
  908. */
  909. uint32_t SDIO_ReadFIFO(SDIO_TypeDef *SDIOx);
  910. HAL_StatusTypeDef SDIO_WriteFIFO(SDIO_TypeDef *SDIOx, uint32_t *pWriteData);
  911. /**
  912. * @}
  913. */
  914. /* Peripheral Control functions ************************************************/
  915. /** @addtogroup HAL_SDMMC_LL_Group3
  916. * @{
  917. */
  918. HAL_StatusTypeDef SDIO_PowerState_ON(SDIO_TypeDef *SDIOx);
  919. HAL_StatusTypeDef SDIO_PowerState_OFF(SDIO_TypeDef *SDIOx);
  920. uint32_t SDIO_GetPowerState(SDIO_TypeDef *SDIOx);
  921. /* Command path state machine (CPSM) management functions */
  922. HAL_StatusTypeDef SDIO_SendCommand(SDIO_TypeDef *SDIOx, SDIO_CmdInitTypeDef *Command);
  923. uint8_t SDIO_GetCommandResponse(SDIO_TypeDef *SDIOx);
  924. uint32_t SDIO_GetResponse(SDIO_TypeDef *SDIOx, uint32_t Response);
  925. /* Data path state machine (DPSM) management functions */
  926. HAL_StatusTypeDef SDIO_ConfigData(SDIO_TypeDef *SDIOx, SDIO_DataInitTypeDef* Data);
  927. uint32_t SDIO_GetDataCounter(SDIO_TypeDef *SDIOx);
  928. uint32_t SDIO_GetFIFOCount(SDIO_TypeDef *SDIOx);
  929. /* SDMMC Cards mode management functions */
  930. HAL_StatusTypeDef SDIO_SetSDMMCReadWaitMode(SDIO_TypeDef *SDIOx, uint32_t SDIO_ReadWaitMode);
  931. /* SDMMC Commands management functions */
  932. uint32_t SDMMC_CmdBlockLength(SDIO_TypeDef *SDIOx, uint32_t BlockSize);
  933. uint32_t SDMMC_CmdReadSingleBlock(SDIO_TypeDef *SDIOx, uint32_t ReadAdd);
  934. uint32_t SDMMC_CmdReadMultiBlock(SDIO_TypeDef *SDIOx, uint32_t ReadAdd);
  935. uint32_t SDMMC_CmdWriteSingleBlock(SDIO_TypeDef *SDIOx, uint32_t WriteAdd);
  936. uint32_t SDMMC_CmdWriteMultiBlock(SDIO_TypeDef *SDIOx, uint32_t WriteAdd);
  937. uint32_t SDMMC_CmdSDEraseStartAdd(SDIO_TypeDef *SDIOx, uint32_t StartAdd);
  938. uint32_t SDMMC_CmdSDEraseEndAdd(SDIO_TypeDef *SDIOx, uint32_t EndAdd);
  939. uint32_t SDMMC_CmdErase(SDIO_TypeDef *SDIOx);
  940. uint32_t SDMMC_CmdStopTransfer(SDIO_TypeDef *SDIOx);
  941. uint32_t SDMMC_CmdSelDesel(SDIO_TypeDef *SDIOx, uint64_t Addr);
  942. uint32_t SDMMC_CmdGoIdleState(SDIO_TypeDef *SDIOx);
  943. uint32_t SDMMC_CmdOperCond(SDIO_TypeDef *SDIOx);
  944. uint32_t SDMMC_CmdAppCommand(SDIO_TypeDef *SDIOx, uint32_t Argument);
  945. uint32_t SDMMC_CmdAppOperCommand(SDIO_TypeDef *SDIOx, uint32_t SdType);
  946. uint32_t SDMMC_CmdBusWidth(SDIO_TypeDef *SDIOx, uint32_t BusWidth);
  947. uint32_t SDMMC_CmdSendSCR(SDIO_TypeDef *SDIOx);
  948. uint32_t SDMMC_CmdSendCID(SDIO_TypeDef *SDIOx);
  949. uint32_t SDMMC_CmdSendCSD(SDIO_TypeDef *SDIOx, uint32_t Argument);
  950. uint32_t SDMMC_CmdSetRelAdd(SDIO_TypeDef *SDIOx, uint16_t *pRCA);
  951. uint32_t SDMMC_CmdSendStatus(SDIO_TypeDef *SDIOx, uint32_t Argument);
  952. uint32_t SDMMC_CmdStatusRegister(SDIO_TypeDef *SDIOx);
  953. uint32_t SDMMC_CmdOpCondition(SDIO_TypeDef *SDIOx, uint32_t Argument);
  954. uint32_t SDMMC_CmdSwitch(SDIO_TypeDef *SDIOx, uint32_t Argument);
  955. uint32_t SDMMC_CmdEraseStartAdd(SDIO_TypeDef *SDIOx, uint32_t StartAdd);
  956. uint32_t SDMMC_CmdEraseEndAdd(SDIO_TypeDef *SDIOx, uint32_t EndAdd);
  957. /**
  958. * @}
  959. */
  960. /**
  961. * @}
  962. */
  963. /**
  964. * @}
  965. */
  966. /**
  967. * @}
  968. */
  969. #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx ||
  970. STM32F401xC || STM32F401xE || STM32F411xE || STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Vx ||
  971. STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
  972. #ifdef __cplusplus
  973. }
  974. #endif
  975. #endif /* __STM32F4xx_LL_SDMMC_H */
  976. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/