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.
 
 
 

805 lines
34 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_ll_sdmmc.h
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 25-June-2015
  7. * @brief Header file of SDMMC HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 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_LL_SDMMC_H
  39. #define __STM32F7xx_LL_SDMMC_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_Driver
  46. * @{
  47. */
  48. /** @addtogroup SDMMC_LL
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup SDMMC_LL_Exported_Types SDMMC_LL Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief SDMMC Configuration Structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t ClockEdge; /*!< Specifies the clock transition on which the bit capture is made.
  61. This parameter can be a value of @ref SDMMC_LL_Clock_Edge */
  62. uint32_t ClockBypass; /*!< Specifies whether the SDMMC Clock divider bypass is
  63. enabled or disabled.
  64. This parameter can be a value of @ref SDMMC_LL_Clock_Bypass */
  65. uint32_t ClockPowerSave; /*!< Specifies whether SDMMC Clock output is enabled or
  66. disabled when the bus is idle.
  67. This parameter can be a value of @ref SDMMC_LL_Clock_Power_Save */
  68. uint32_t BusWide; /*!< Specifies the SDMMC bus width.
  69. This parameter can be a value of @ref SDMMC_LL_Bus_Wide */
  70. uint32_t HardwareFlowControl; /*!< Specifies whether the SDMMC hardware flow control is enabled or disabled.
  71. This parameter can be a value of @ref SDMMC_LL_Hardware_Flow_Control */
  72. uint32_t ClockDiv; /*!< Specifies the clock frequency of the SDMMC controller.
  73. This parameter can be a value between Min_Data = 0 and Max_Data = 255 */
  74. }SDMMC_InitTypeDef;
  75. /**
  76. * @brief SDMMC Command Control structure
  77. */
  78. typedef struct
  79. {
  80. uint32_t Argument; /*!< Specifies the SDMMC command argument which is sent
  81. to a card as part of a command message. If a command
  82. contains an argument, it must be loaded into this register
  83. before writing the command to the command register. */
  84. uint32_t CmdIndex; /*!< Specifies the SDMMC command index. It must be Min_Data = 0 and
  85. Max_Data = 64 */
  86. uint32_t Response; /*!< Specifies the SDMMC response type.
  87. This parameter can be a value of @ref SDMMC_LL_Response_Type */
  88. uint32_t WaitForInterrupt; /*!< Specifies whether SDMMC wait for interrupt request is
  89. enabled or disabled.
  90. This parameter can be a value of @ref SDMMC_LL_Wait_Interrupt_State */
  91. uint32_t CPSM; /*!< Specifies whether SDMMC Command path state machine (CPSM)
  92. is enabled or disabled.
  93. This parameter can be a value of @ref SDMMC_LL_CPSM_State */
  94. }SDMMC_CmdInitTypeDef;
  95. /**
  96. * @brief SDMMC Data Control structure
  97. */
  98. typedef struct
  99. {
  100. uint32_t DataTimeOut; /*!< Specifies the data timeout period in card bus clock periods. */
  101. uint32_t DataLength; /*!< Specifies the number of data bytes to be transferred. */
  102. uint32_t DataBlockSize; /*!< Specifies the data block size for block transfer.
  103. This parameter can be a value of @ref SDMMC_LL_Data_Block_Size */
  104. uint32_t TransferDir; /*!< Specifies the data transfer direction, whether the transfer
  105. is a read or write.
  106. This parameter can be a value of @ref SDMMC_LL_Transfer_Direction */
  107. uint32_t TransferMode; /*!< Specifies whether data transfer is in stream or block mode.
  108. This parameter can be a value of @ref SDMMC_LL_Transfer_Type */
  109. uint32_t DPSM; /*!< Specifies whether SDMMC Data path state machine (DPSM)
  110. is enabled or disabled.
  111. This parameter can be a value of @ref SDMMC_LL_DPSM_State */
  112. }SDMMC_DataInitTypeDef;
  113. /**
  114. * @}
  115. */
  116. /* Exported constants --------------------------------------------------------*/
  117. /** @defgroup SDMMC_LL_Exported_Constants SDMMC_LL Exported Constants
  118. * @{
  119. */
  120. /** @defgroup SDMMC_LL_Clock_Edge Clock Edge
  121. * @{
  122. */
  123. #define SDMMC_CLOCK_EDGE_RISING ((uint32_t)0x00000000)
  124. #define SDMMC_CLOCK_EDGE_FALLING SDMMC_CLKCR_NEGEDGE
  125. #define IS_SDMMC_CLOCK_EDGE(EDGE) (((EDGE) == SDMMC_CLOCK_EDGE_RISING) || \
  126. ((EDGE) == SDMMC_CLOCK_EDGE_FALLING))
  127. /**
  128. * @}
  129. */
  130. /** @defgroup SDMMC_LL_Clock_Bypass Clock Bypass
  131. * @{
  132. */
  133. #define SDMMC_CLOCK_BYPASS_DISABLE ((uint32_t)0x00000000)
  134. #define SDMMC_CLOCK_BYPASS_ENABLE SDMMC_CLKCR_BYPASS
  135. #define IS_SDMMC_CLOCK_BYPASS(BYPASS) (((BYPASS) == SDMMC_CLOCK_BYPASS_DISABLE) || \
  136. ((BYPASS) == SDMMC_CLOCK_BYPASS_ENABLE))
  137. /**
  138. * @}
  139. */
  140. /** @defgroup SDMMC_LL_Clock_Power_Save Clock Power Saving
  141. * @{
  142. */
  143. #define SDMMC_CLOCK_POWER_SAVE_DISABLE ((uint32_t)0x00000000)
  144. #define SDMMC_CLOCK_POWER_SAVE_ENABLE SDMMC_CLKCR_PWRSAV
  145. #define IS_SDMMC_CLOCK_POWER_SAVE(SAVE) (((SAVE) == SDMMC_CLOCK_POWER_SAVE_DISABLE) || \
  146. ((SAVE) == SDMMC_CLOCK_POWER_SAVE_ENABLE))
  147. /**
  148. * @}
  149. */
  150. /** @defgroup SDMMC_LL_Bus_Wide Bus Width
  151. * @{
  152. */
  153. #define SDMMC_BUS_WIDE_1B ((uint32_t)0x00000000)
  154. #define SDMMC_BUS_WIDE_4B SDMMC_CLKCR_WIDBUS_0
  155. #define SDMMC_BUS_WIDE_8B SDMMC_CLKCR_WIDBUS_1
  156. #define IS_SDMMC_BUS_WIDE(WIDE) (((WIDE) == SDMMC_BUS_WIDE_1B) || \
  157. ((WIDE) == SDMMC_BUS_WIDE_4B) || \
  158. ((WIDE) == SDMMC_BUS_WIDE_8B))
  159. /**
  160. * @}
  161. */
  162. /** @defgroup SDMMC_LL_Hardware_Flow_Control Hardware Flow Control
  163. * @{
  164. */
  165. #define SDMMC_HARDWARE_FLOW_CONTROL_DISABLE ((uint32_t)0x00000000)
  166. #define SDMMC_HARDWARE_FLOW_CONTROL_ENABLE SDMMC_CLKCR_HWFC_EN
  167. #define IS_SDMMC_HARDWARE_FLOW_CONTROL(CONTROL) (((CONTROL) == SDMMC_HARDWARE_FLOW_CONTROL_DISABLE) || \
  168. ((CONTROL) == SDMMC_HARDWARE_FLOW_CONTROL_ENABLE))
  169. /**
  170. * @}
  171. */
  172. /** @defgroup SDMMC_LL_Clock_Division Clock Division
  173. * @{
  174. */
  175. #define IS_SDMMC_CLKDIV(DIV) ((DIV) <= 0xFF)
  176. /**
  177. * @}
  178. */
  179. /** @defgroup SDMMC_LL_Command_Index Command Index
  180. * @{
  181. */
  182. #define IS_SDMMC_CMD_INDEX(INDEX) ((INDEX) < 0x40)
  183. /**
  184. * @}
  185. */
  186. /** @defgroup SDMMC_LL_Response_Type Response Type
  187. * @{
  188. */
  189. #define SDMMC_RESPONSE_NO ((uint32_t)0x00000000)
  190. #define SDMMC_RESPONSE_SHORT SDMMC_CMD_WAITRESP_0
  191. #define SDMMC_RESPONSE_LONG SDMMC_CMD_WAITRESP
  192. #define IS_SDMMC_RESPONSE(RESPONSE) (((RESPONSE) == SDMMC_RESPONSE_NO) || \
  193. ((RESPONSE) == SDMMC_RESPONSE_SHORT) || \
  194. ((RESPONSE) == SDMMC_RESPONSE_LONG))
  195. /**
  196. * @}
  197. */
  198. /** @defgroup SDMMC_LL_Wait_Interrupt_State Wait Interrupt
  199. * @{
  200. */
  201. #define SDMMC_WAIT_NO ((uint32_t)0x00000000)
  202. #define SDMMC_WAIT_IT SDMMC_CMD_WAITINT
  203. #define SDMMC_WAIT_PEND SDMMC_CMD_WAITPEND
  204. #define IS_SDMMC_WAIT(WAIT) (((WAIT) == SDMMC_WAIT_NO) || \
  205. ((WAIT) == SDMMC_WAIT_IT) || \
  206. ((WAIT) == SDMMC_WAIT_PEND))
  207. /**
  208. * @}
  209. */
  210. /** @defgroup SDMMC_LL_CPSM_State CPSM State
  211. * @{
  212. */
  213. #define SDMMC_CPSM_DISABLE ((uint32_t)0x00000000)
  214. #define SDMMC_CPSM_ENABLE SDMMC_CMD_CPSMEN
  215. #define IS_SDMMC_CPSM(CPSM) (((CPSM) == SDMMC_CPSM_DISABLE) || \
  216. ((CPSM) == SDMMC_CPSM_ENABLE))
  217. /**
  218. * @}
  219. */
  220. /** @defgroup SDMMC_LL_Response_Registers Response Register
  221. * @{
  222. */
  223. #define SDMMC_RESP1 ((uint32_t)0x00000000)
  224. #define SDMMC_RESP2 ((uint32_t)0x00000004)
  225. #define SDMMC_RESP3 ((uint32_t)0x00000008)
  226. #define SDMMC_RESP4 ((uint32_t)0x0000000C)
  227. #define IS_SDMMC_RESP(RESP) (((RESP) == SDMMC_RESP1) || \
  228. ((RESP) == SDMMC_RESP2) || \
  229. ((RESP) == SDMMC_RESP3) || \
  230. ((RESP) == SDMMC_RESP4))
  231. /**
  232. * @}
  233. */
  234. /** @defgroup SDMMC_LL_Data_Length Data Lenght
  235. * @{
  236. */
  237. #define IS_SDMMC_DATA_LENGTH(LENGTH) ((LENGTH) <= 0x01FFFFFF)
  238. /**
  239. * @}
  240. */
  241. /** @defgroup SDMMC_LL_Data_Block_Size Data Block Size
  242. * @{
  243. */
  244. #define SDMMC_DATABLOCK_SIZE_1B ((uint32_t)0x00000000)
  245. #define SDMMC_DATABLOCK_SIZE_2B SDMMC_DCTRL_DBLOCKSIZE_0
  246. #define SDMMC_DATABLOCK_SIZE_4B SDMMC_DCTRL_DBLOCKSIZE_1
  247. #define SDMMC_DATABLOCK_SIZE_8B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1)
  248. #define SDMMC_DATABLOCK_SIZE_16B SDMMC_DCTRL_DBLOCKSIZE_2
  249. #define SDMMC_DATABLOCK_SIZE_32B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_2)
  250. #define SDMMC_DATABLOCK_SIZE_64B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2)
  251. #define SDMMC_DATABLOCK_SIZE_128B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2)
  252. #define SDMMC_DATABLOCK_SIZE_256B SDMMC_DCTRL_DBLOCKSIZE_3
  253. #define SDMMC_DATABLOCK_SIZE_512B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_3)
  254. #define SDMMC_DATABLOCK_SIZE_1024B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_3)
  255. #define SDMMC_DATABLOCK_SIZE_2048B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_3)
  256. #define SDMMC_DATABLOCK_SIZE_4096B (SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3)
  257. #define SDMMC_DATABLOCK_SIZE_8192B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3)
  258. #define SDMMC_DATABLOCK_SIZE_16384B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3)
  259. #define IS_SDMMC_BLOCK_SIZE(SIZE) (((SIZE) == SDMMC_DATABLOCK_SIZE_1B) || \
  260. ((SIZE) == SDMMC_DATABLOCK_SIZE_2B) || \
  261. ((SIZE) == SDMMC_DATABLOCK_SIZE_4B) || \
  262. ((SIZE) == SDMMC_DATABLOCK_SIZE_8B) || \
  263. ((SIZE) == SDMMC_DATABLOCK_SIZE_16B) || \
  264. ((SIZE) == SDMMC_DATABLOCK_SIZE_32B) || \
  265. ((SIZE) == SDMMC_DATABLOCK_SIZE_64B) || \
  266. ((SIZE) == SDMMC_DATABLOCK_SIZE_128B) || \
  267. ((SIZE) == SDMMC_DATABLOCK_SIZE_256B) || \
  268. ((SIZE) == SDMMC_DATABLOCK_SIZE_512B) || \
  269. ((SIZE) == SDMMC_DATABLOCK_SIZE_1024B) || \
  270. ((SIZE) == SDMMC_DATABLOCK_SIZE_2048B) || \
  271. ((SIZE) == SDMMC_DATABLOCK_SIZE_4096B) || \
  272. ((SIZE) == SDMMC_DATABLOCK_SIZE_8192B) || \
  273. ((SIZE) == SDMMC_DATABLOCK_SIZE_16384B))
  274. /**
  275. * @}
  276. */
  277. /** @defgroup SDMMC_LL_Transfer_Direction Transfer Direction
  278. * @{
  279. */
  280. #define SDMMC_TRANSFER_DIR_TO_CARD ((uint32_t)0x00000000)
  281. #define SDMMC_TRANSFER_DIR_TO_SDMMC SDMMC_DCTRL_DTDIR
  282. #define IS_SDMMC_TRANSFER_DIR(DIR) (((DIR) == SDMMC_TRANSFER_DIR_TO_CARD) || \
  283. ((DIR) == SDMMC_TRANSFER_DIR_TO_SDMMC))
  284. /**
  285. * @}
  286. */
  287. /** @defgroup SDMMC_LL_Transfer_Type Transfer Type
  288. * @{
  289. */
  290. #define SDMMC_TRANSFER_MODE_BLOCK ((uint32_t)0x00000000)
  291. #define SDMMC_TRANSFER_MODE_STREAM SDMMC_DCTRL_DTMODE
  292. #define IS_SDMMC_TRANSFER_MODE(MODE) (((MODE) == SDMMC_TRANSFER_MODE_BLOCK) || \
  293. ((MODE) == SDMMC_TRANSFER_MODE_STREAM))
  294. /**
  295. * @}
  296. */
  297. /** @defgroup SDMMC_LL_DPSM_State DPSM State
  298. * @{
  299. */
  300. #define SDMMC_DPSM_DISABLE ((uint32_t)0x00000000)
  301. #define SDMMC_DPSM_ENABLE SDMMC_DCTRL_DTEN
  302. #define IS_SDMMC_DPSM(DPSM) (((DPSM) == SDMMC_DPSM_DISABLE) ||\
  303. ((DPSM) == SDMMC_DPSM_ENABLE))
  304. /**
  305. * @}
  306. */
  307. /** @defgroup SDMMC_LL_Read_Wait_Mode Read Wait Mode
  308. * @{
  309. */
  310. #define SDMMC_READ_WAIT_MODE_DATA2 ((uint32_t)0x00000000)
  311. #define SDMMC_READ_WAIT_MODE_CLK (SDMMC_DCTRL_RWMOD)
  312. #define IS_SDMMC_READWAIT_MODE(MODE) (((MODE) == SDMMC_READ_WAIT_MODE_CLK) || \
  313. ((MODE) == SDMMC_READ_WAIT_MODE_DATA2))
  314. /**
  315. * @}
  316. */
  317. /** @defgroup SDMMC_LL_Interrupt_sources Interrupt Sources
  318. * @{
  319. */
  320. #define SDMMC_IT_CCRCFAIL SDMMC_STA_CCRCFAIL
  321. #define SDMMC_IT_DCRCFAIL SDMMC_STA_DCRCFAIL
  322. #define SDMMC_IT_CTIMEOUT SDMMC_STA_CTIMEOUT
  323. #define SDMMC_IT_DTIMEOUT SDMMC_STA_DTIMEOUT
  324. #define SDMMC_IT_TXUNDERR SDMMC_STA_TXUNDERR
  325. #define SDMMC_IT_RXOVERR SDMMC_STA_RXOVERR
  326. #define SDMMC_IT_CMDREND SDMMC_STA_CMDREND
  327. #define SDMMC_IT_CMDSENT SDMMC_STA_CMDSENT
  328. #define SDMMC_IT_DATAEND SDMMC_STA_DATAEND
  329. #define SDMMC_IT_DBCKEND SDMMC_STA_DBCKEND
  330. #define SDMMC_IT_CMDACT SDMMC_STA_CMDACT
  331. #define SDMMC_IT_TXACT SDMMC_STA_TXACT
  332. #define SDMMC_IT_RXACT SDMMC_STA_RXACT
  333. #define SDMMC_IT_TXFIFOHE SDMMC_STA_TXFIFOHE
  334. #define SDMMC_IT_RXFIFOHF SDMMC_STA_RXFIFOHF
  335. #define SDMMC_IT_TXFIFOF SDMMC_STA_TXFIFOF
  336. #define SDMMC_IT_RXFIFOF SDMMC_STA_RXFIFOF
  337. #define SDMMC_IT_TXFIFOE SDMMC_STA_TXFIFOE
  338. #define SDMMC_IT_RXFIFOE SDMMC_STA_RXFIFOE
  339. #define SDMMC_IT_TXDAVL SDMMC_STA_TXDAVL
  340. #define SDMMC_IT_RXDAVL SDMMC_STA_RXDAVL
  341. #define SDMMC_IT_SDIOIT SDMMC_STA_SDIOIT
  342. /**
  343. * @}
  344. */
  345. /** @defgroup SDMMC_LL_Flags Flags
  346. * @{
  347. */
  348. #define SDMMC_FLAG_CCRCFAIL SDMMC_STA_CCRCFAIL
  349. #define SDMMC_FLAG_DCRCFAIL SDMMC_STA_DCRCFAIL
  350. #define SDMMC_FLAG_CTIMEOUT SDMMC_STA_CTIMEOUT
  351. #define SDMMC_FLAG_DTIMEOUT SDMMC_STA_DTIMEOUT
  352. #define SDMMC_FLAG_TXUNDERR SDMMC_STA_TXUNDERR
  353. #define SDMMC_FLAG_RXOVERR SDMMC_STA_RXOVERR
  354. #define SDMMC_FLAG_CMDREND SDMMC_STA_CMDREND
  355. #define SDMMC_FLAG_CMDSENT SDMMC_STA_CMDSENT
  356. #define SDMMC_FLAG_DATAEND SDMMC_STA_DATAEND
  357. #define SDMMC_FLAG_DBCKEND SDMMC_STA_DBCKEND
  358. #define SDMMC_FLAG_CMDACT SDMMC_STA_CMDACT
  359. #define SDMMC_FLAG_TXACT SDMMC_STA_TXACT
  360. #define SDMMC_FLAG_RXACT SDMMC_STA_RXACT
  361. #define SDMMC_FLAG_TXFIFOHE SDMMC_STA_TXFIFOHE
  362. #define SDMMC_FLAG_RXFIFOHF SDMMC_STA_RXFIFOHF
  363. #define SDMMC_FLAG_TXFIFOF SDMMC_STA_TXFIFOF
  364. #define SDMMC_FLAG_RXFIFOF SDMMC_STA_RXFIFOF
  365. #define SDMMC_FLAG_TXFIFOE SDMMC_STA_TXFIFOE
  366. #define SDMMC_FLAG_RXFIFOE SDMMC_STA_RXFIFOE
  367. #define SDMMC_FLAG_TXDAVL SDMMC_STA_TXDAVL
  368. #define SDMMC_FLAG_RXDAVL SDMMC_STA_RXDAVL
  369. #define SDMMC_FLAG_SDIOIT SDMMC_STA_SDIOIT
  370. /**
  371. * @}
  372. */
  373. /**
  374. * @}
  375. */
  376. /* Exported macro ------------------------------------------------------------*/
  377. /** @defgroup SDMMC_LL_Exported_macros SDMMC_LL Exported Macros
  378. * @{
  379. */
  380. /** @defgroup SDMMC_LL_Register Bits And Addresses Definitions
  381. * @brief SDMMC_LL registers bit address in the alias region
  382. * @{
  383. */
  384. /* ---------------------- SDMMC registers bit mask --------------------------- */
  385. /* --- CLKCR Register ---*/
  386. /* CLKCR register clear mask */
  387. #define CLKCR_CLEAR_MASK ((uint32_t)(SDMMC_CLKCR_CLKDIV | SDMMC_CLKCR_PWRSAV |\
  388. SDMMC_CLKCR_BYPASS | SDMMC_CLKCR_WIDBUS |\
  389. SDMMC_CLKCR_NEGEDGE | SDMMC_CLKCR_HWFC_EN))
  390. /* --- DCTRL Register ---*/
  391. /* SDMMC DCTRL Clear Mask */
  392. #define DCTRL_CLEAR_MASK ((uint32_t)(SDMMC_DCTRL_DTEN | SDMMC_DCTRL_DTDIR |\
  393. SDMMC_DCTRL_DTMODE | SDMMC_DCTRL_DBLOCKSIZE))
  394. /* --- CMD Register ---*/
  395. /* CMD Register clear mask */
  396. #define CMD_CLEAR_MASK ((uint32_t)(SDMMC_CMD_CMDINDEX | SDMMC_CMD_WAITRESP |\
  397. SDMMC_CMD_WAITINT | SDMMC_CMD_WAITPEND |\
  398. SDMMC_CMD_CPSMEN | SDMMC_CMD_SDIOSUSPEND))
  399. /* SDMMC Initialization Frequency (400KHz max) */
  400. #define SDMMC_INIT_CLK_DIV ((uint8_t)0x76)
  401. /* SDMMC Data Transfer Frequency (25MHz max) */
  402. #define SDMMC_TRANSFER_CLK_DIV ((uint8_t)0x0)
  403. /**
  404. * @}
  405. */
  406. /** @defgroup SDMMC_LL_Interrupt_Clock Interrupt And Clock Configuration
  407. * @brief macros to handle interrupts and specific clock configurations
  408. * @{
  409. */
  410. /**
  411. * @brief Enable the SDMMC device.
  412. * @param __INSTANCE__: SDMMC Instance
  413. * @retval None
  414. */
  415. #define __SDMMC_ENABLE(__INSTANCE__) ((__INSTANCE__)->CLKCR |= SDMMC_CLKCR_CLKEN)
  416. /**
  417. * @brief Disable the SDMMC device.
  418. * @param __INSTANCE__: SDMMC Instance
  419. * @retval None
  420. */
  421. #define __SDMMC_DISABLE(__INSTANCE__) ((__INSTANCE__)->CLKCR &= ~SDMMC_CLKCR_CLKEN)
  422. /**
  423. * @brief Enable the SDMMC DMA transfer.
  424. * @param __INSTANCE__: SDMMC Instance
  425. * @retval None
  426. */
  427. #define __SDMMC_DMA_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_DMAEN)
  428. /**
  429. * @brief Disable the SDMMC DMA transfer.
  430. * @param __INSTANCE__: SDMMC Instance
  431. * @retval None
  432. */
  433. #define __SDMMC_DMA_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_DMAEN)
  434. /**
  435. * @brief Enable the SDMMC device interrupt.
  436. * @param __INSTANCE__ : Pointer to SDMMC register base
  437. * @param __INTERRUPT__ : specifies the SDMMC interrupt sources to be enabled.
  438. * This parameter can be one or a combination of the following values:
  439. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  440. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  441. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  442. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  443. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  444. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  445. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  446. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  447. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  448. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  449. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  450. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  451. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  452. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  453. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  454. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  455. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  456. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  457. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  458. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  459. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  460. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  461. * @retval None
  462. */
  463. #define __SDMMC_ENABLE_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->MASK |= (__INTERRUPT__))
  464. /**
  465. * @brief Disable the SDMMC device interrupt.
  466. * @param __INSTANCE__ : Pointer to SDMMC register base
  467. * @param __INTERRUPT__ : specifies the SDMMC interrupt sources to be disabled.
  468. * This parameter can be one or a combination of the following values:
  469. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  470. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  471. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  472. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  473. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  474. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  475. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  476. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  477. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  478. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  479. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  480. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  481. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  482. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  483. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  484. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  485. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  486. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  487. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  488. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  489. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  490. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  491. * @retval None
  492. */
  493. #define __SDMMC_DISABLE_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->MASK &= ~(__INTERRUPT__))
  494. /**
  495. * @brief Checks whether the specified SDMMC flag is set or not.
  496. * @param __INSTANCE__ : Pointer to SDMMC register base
  497. * @param __FLAG__: specifies the flag to check.
  498. * This parameter can be one of the following values:
  499. * @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed)
  500. * @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  501. * @arg SDMMC_FLAG_CTIMEOUT: Command response timeout
  502. * @arg SDMMC_FLAG_DTIMEOUT: Data timeout
  503. * @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error
  504. * @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error
  505. * @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed)
  506. * @arg SDMMC_FLAG_CMDSENT: Command sent (no response required)
  507. * @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  508. * @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  509. * @arg SDMMC_FLAG_CMDACT: Command transfer in progress
  510. * @arg SDMMC_FLAG_TXACT: Data transmit in progress
  511. * @arg SDMMC_FLAG_RXACT: Data receive in progress
  512. * @arg SDMMC_FLAG_TXFIFOHE: Transmit FIFO Half Empty
  513. * @arg SDMMC_FLAG_RXFIFOHF: Receive FIFO Half Full
  514. * @arg SDMMC_FLAG_TXFIFOF: Transmit FIFO full
  515. * @arg SDMMC_FLAG_RXFIFOF: Receive FIFO full
  516. * @arg SDMMC_FLAG_TXFIFOE: Transmit FIFO empty
  517. * @arg SDMMC_FLAG_RXFIFOE: Receive FIFO empty
  518. * @arg SDMMC_FLAG_TXDAVL: Data available in transmit FIFO
  519. * @arg SDMMC_FLAG_RXDAVL: Data available in receive FIFO
  520. * @arg SDMMC_FLAG_SDMMCIT: SD I/O interrupt received
  521. * @retval The new state of SDMMC_FLAG (SET or RESET).
  522. */
  523. #define __SDMMC_GET_FLAG(__INSTANCE__, __FLAG__) (((__INSTANCE__)->STA &(__FLAG__)) != RESET)
  524. /**
  525. * @brief Clears the SDMMC pending flags.
  526. * @param __INSTANCE__ : Pointer to SDMMC register base
  527. * @param __FLAG__: specifies the flag to clear.
  528. * This parameter can be one or a combination of the following values:
  529. * @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed)
  530. * @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  531. * @arg SDMMC_FLAG_CTIMEOUT: Command response timeout
  532. * @arg SDMMC_FLAG_DTIMEOUT: Data timeout
  533. * @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error
  534. * @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error
  535. * @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed)
  536. * @arg SDMMC_FLAG_CMDSENT: Command sent (no response required)
  537. * @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  538. * @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  539. * @arg SDMMC_FLAG_SDMMCIT: SD I/O interrupt received
  540. * @retval None
  541. */
  542. #define __SDMMC_CLEAR_FLAG(__INSTANCE__, __FLAG__) ((__INSTANCE__)->ICR = (__FLAG__))
  543. /**
  544. * @brief Checks whether the specified SDMMC interrupt has occurred or not.
  545. * @param __INSTANCE__ : Pointer to SDMMC register base
  546. * @param __INTERRUPT__: specifies the SDMMC interrupt source to check.
  547. * This parameter can be one of the following values:
  548. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  549. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  550. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  551. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  552. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  553. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  554. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  555. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  556. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  557. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  558. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  559. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  560. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  561. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  562. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  563. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  564. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  565. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  566. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  567. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  568. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  569. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  570. * @retval The new state of SDMMC_IT (SET or RESET).
  571. */
  572. #define __SDMMC_GET_IT (__INSTANCE__, __INTERRUPT__) (((__INSTANCE__)->STA &(__INTERRUPT__)) == (__INTERRUPT__))
  573. /**
  574. * @brief Clears the SDMMC's interrupt pending bits.
  575. * @param __INSTANCE__ : Pointer to SDMMC register base
  576. * @param __INTERRUPT__: specifies the interrupt pending bit to clear.
  577. * This parameter can be one or a combination of the following values:
  578. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  579. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  580. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  581. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  582. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  583. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  584. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  585. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  586. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDMMC_DCOUNT, is zero) interrupt
  587. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  588. * @retval None
  589. */
  590. #define __SDMMC_CLEAR_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->ICR = (__INTERRUPT__))
  591. /**
  592. * @brief Enable Start the SD I/O Read Wait operation.
  593. * @param __INSTANCE__ : Pointer to SDMMC register base
  594. * @retval None
  595. */
  596. #define __SDMMC_START_READWAIT_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_RWSTART)
  597. /**
  598. * @brief Disable Start the SD I/O Read Wait operations.
  599. * @param __INSTANCE__ : Pointer to SDMMC register base
  600. * @retval None
  601. */
  602. #define __SDMMC_START_READWAIT_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_RWSTART)
  603. /**
  604. * @brief Enable Start the SD I/O Read Wait operation.
  605. * @param __INSTANCE__ : Pointer to SDMMC register base
  606. * @retval None
  607. */
  608. #define __SDMMC_STOP_READWAIT_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_RWSTOP)
  609. /**
  610. * @brief Disable Stop the SD I/O Read Wait operations.
  611. * @param __INSTANCE__ : Pointer to SDMMC register base
  612. * @retval None
  613. */
  614. #define __SDMMC_STOP_READWAIT_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_RWSTOP)
  615. /**
  616. * @brief Enable the SD I/O Mode Operation.
  617. * @param __INSTANCE__ : Pointer to SDMMC register base
  618. * @retval None
  619. */
  620. #define __SDMMC_OPERATION_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_SDIOEN)
  621. /**
  622. * @brief Disable the SD I/O Mode Operation.
  623. * @param __INSTANCE__ : Pointer to SDMMC register base
  624. * @retval None
  625. */
  626. #define __SDMMC_OPERATION_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_SDIOEN)
  627. /**
  628. * @brief Enable the SD I/O Suspend command sending.
  629. * @param __INSTANCE__ : Pointer to SDMMC register base
  630. * @retval None
  631. */
  632. #define __SDMMC_SUSPEND_CMD_ENABLE(__INSTANCE__) ((__INSTANCE__)->CMD |= SDMMC_CMD_SDIOSUSPEND)
  633. /**
  634. * @brief Disable the SD I/O Suspend command sending.
  635. * @param __INSTANCE__ : Pointer to SDMMC register base
  636. * @retval None
  637. */
  638. #define __SDMMC_SUSPEND_CMD_DISABLE(__INSTANCE__) ((__INSTANCE__)->CMD &= ~SDMMC_CMD_SDIOSUSPEND)
  639. /**
  640. * @}
  641. */
  642. /**
  643. * @}
  644. */
  645. /* Exported functions --------------------------------------------------------*/
  646. /** @addtogroup SDMMC_LL_Exported_Functions
  647. * @{
  648. */
  649. /* Initialization/de-initialization functions **********************************/
  650. /** @addtogroup HAL_SDMMC_LL_Group1
  651. * @{
  652. */
  653. HAL_StatusTypeDef SDMMC_Init(SDMMC_TypeDef *SDMMCx, SDMMC_InitTypeDef Init);
  654. /**
  655. * @}
  656. */
  657. /* I/O operation functions *****************************************************/
  658. /** @addtogroup HAL_SDMMC_LL_Group2
  659. * @{
  660. */
  661. /* Blocking mode: Polling */
  662. uint32_t SDMMC_ReadFIFO(SDMMC_TypeDef *SDMMCx);
  663. HAL_StatusTypeDef SDMMC_WriteFIFO(SDMMC_TypeDef *SDMMCx, uint32_t *pWriteData);
  664. /**
  665. * @}
  666. */
  667. /* Peripheral Control functions ************************************************/
  668. /** @addtogroup HAL_SDMMC_LL_Group3
  669. * @{
  670. */
  671. HAL_StatusTypeDef SDMMC_PowerState_ON(SDMMC_TypeDef *SDMMCx);
  672. HAL_StatusTypeDef SDMMC_PowerState_OFF(SDMMC_TypeDef *SDMMCx);
  673. uint32_t SDMMC_GetPowerState(SDMMC_TypeDef *SDMMCx);
  674. /* Command path state machine (CPSM) management functions */
  675. HAL_StatusTypeDef SDMMC_SendCommand(SDMMC_TypeDef *SDMMCx, SDMMC_CmdInitTypeDef *Command);
  676. uint8_t SDMMC_GetCommandResponse(SDMMC_TypeDef *SDMMCx);
  677. uint32_t SDMMC_GetResponse(SDMMC_TypeDef *SDMMCx, uint32_t Response);
  678. /* Data path state machine (DPSM) management functions */
  679. HAL_StatusTypeDef SDMMC_DataConfig(SDMMC_TypeDef *SDMMCx, SDMMC_DataInitTypeDef* Data);
  680. uint32_t SDMMC_GetDataCounter(SDMMC_TypeDef *SDMMCx);
  681. uint32_t SDMMC_GetFIFOCount(SDMMC_TypeDef *SDMMCx);
  682. /* SDMMC Cards mode management functions */
  683. HAL_StatusTypeDef SDMMC_SetSDMMCReadWaitMode(SDMMC_TypeDef *SDMMCx, uint32_t SDMMC_ReadWaitMode);
  684. /**
  685. * @}
  686. */
  687. /**
  688. * @}
  689. */
  690. /**
  691. * @}
  692. */
  693. /**
  694. * @}
  695. */
  696. #ifdef __cplusplus
  697. }
  698. #endif
  699. #endif /* __STM32F7xx_LL_SDMMC_H */
  700. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/