stm32f7xx_ll_sdmmc.h 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_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</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F7xx_LL_SDMMC_H
  37. #define __STM32F7xx_LL_SDMMC_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f7xx_hal_def.h"
  43. /** @addtogroup STM32F7xx_Driver
  44. * @{
  45. */
  46. /** @addtogroup SDMMC_LL
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup SDMMC_LL_Exported_Types SDMMC_LL Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief SDMMC Configuration Structure definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t ClockEdge; /*!< Specifies the clock transition on which the bit capture is made.
  59. This parameter can be a value of @ref SDMMC_LL_Clock_Edge */
  60. uint32_t ClockBypass; /*!< Specifies whether the SDMMC Clock divider bypass is
  61. enabled or disabled.
  62. This parameter can be a value of @ref SDMMC_LL_Clock_Bypass */
  63. uint32_t ClockPowerSave; /*!< Specifies whether SDMMC Clock output is enabled or
  64. disabled when the bus is idle.
  65. This parameter can be a value of @ref SDMMC_LL_Clock_Power_Save */
  66. uint32_t BusWide; /*!< Specifies the SDMMC bus width.
  67. This parameter can be a value of @ref SDMMC_LL_Bus_Wide */
  68. uint32_t HardwareFlowControl; /*!< Specifies whether the SDMMC hardware flow control is enabled or disabled.
  69. This parameter can be a value of @ref SDMMC_LL_Hardware_Flow_Control */
  70. uint32_t ClockDiv; /*!< Specifies the clock frequency of the SDMMC controller.
  71. This parameter can be a value between Min_Data = 0 and Max_Data = 255 */
  72. }SDMMC_InitTypeDef;
  73. /**
  74. * @brief SDMMC Command Control structure
  75. */
  76. typedef struct
  77. {
  78. uint32_t Argument; /*!< Specifies the SDMMC command argument which is sent
  79. to a card as part of a command message. If a command
  80. contains an argument, it must be loaded into this register
  81. before writing the command to the command register. */
  82. uint32_t CmdIndex; /*!< Specifies the SDMMC command index. It must be Min_Data = 0 and
  83. Max_Data = 64 */
  84. uint32_t Response; /*!< Specifies the SDMMC response type.
  85. This parameter can be a value of @ref SDMMC_LL_Response_Type */
  86. uint32_t WaitForInterrupt; /*!< Specifies whether SDMMC wait for interrupt request is
  87. enabled or disabled.
  88. This parameter can be a value of @ref SDMMC_LL_Wait_Interrupt_State */
  89. uint32_t CPSM; /*!< Specifies whether SDMMC Command path state machine (CPSM)
  90. is enabled or disabled.
  91. This parameter can be a value of @ref SDMMC_LL_CPSM_State */
  92. }SDMMC_CmdInitTypeDef;
  93. /**
  94. * @brief SDMMC Data Control structure
  95. */
  96. typedef struct
  97. {
  98. uint32_t DataTimeOut; /*!< Specifies the data timeout period in card bus clock periods. */
  99. uint32_t DataLength; /*!< Specifies the number of data bytes to be transferred. */
  100. uint32_t DataBlockSize; /*!< Specifies the data block size for block transfer.
  101. This parameter can be a value of @ref SDMMC_LL_Data_Block_Size */
  102. uint32_t TransferDir; /*!< Specifies the data transfer direction, whether the transfer
  103. is a read or write.
  104. This parameter can be a value of @ref SDMMC_LL_Transfer_Direction */
  105. uint32_t TransferMode; /*!< Specifies whether data transfer is in stream or block mode.
  106. This parameter can be a value of @ref SDMMC_LL_Transfer_Type */
  107. uint32_t DPSM; /*!< Specifies whether SDMMC Data path state machine (DPSM)
  108. is enabled or disabled.
  109. This parameter can be a value of @ref SDMMC_LL_DPSM_State */
  110. }SDMMC_DataInitTypeDef;
  111. /**
  112. * @}
  113. */
  114. /* Exported constants --------------------------------------------------------*/
  115. /** @defgroup SDMMC_LL_Exported_Constants SDMMC_LL Exported Constants
  116. * @{
  117. */
  118. #define SDMMC_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
  119. #define SDMMC_ERROR_CMD_CRC_FAIL ((uint32_t)0x00000001U) /*!< Command response received (but CRC check failed) */
  120. #define SDMMC_ERROR_DATA_CRC_FAIL ((uint32_t)0x00000002U) /*!< Data block sent/received (CRC check failed) */
  121. #define SDMMC_ERROR_CMD_RSP_TIMEOUT ((uint32_t)0x00000004U) /*!< Command response timeout */
  122. #define SDMMC_ERROR_DATA_TIMEOUT ((uint32_t)0x00000008U) /*!< Data timeout */
  123. #define SDMMC_ERROR_TX_UNDERRUN ((uint32_t)0x00000010U) /*!< Transmit FIFO underrun */
  124. #define SDMMC_ERROR_RX_OVERRUN ((uint32_t)0x00000020U) /*!< Receive FIFO overrun */
  125. #define SDMMC_ERROR_ADDR_MISALIGNED ((uint32_t)0x00000040U) /*!< Misaligned address */
  126. #define SDMMC_ERROR_BLOCK_LEN_ERR ((uint32_t)0x00000080U) /*!< Transferred block length is not allowed for the card or the
  127. number of transferred bytes does not match the block length */
  128. #define SDMMC_ERROR_ERASE_SEQ_ERR ((uint32_t)0x00000100U) /*!< An error in the sequence of erase command occurs */
  129. #define SDMMC_ERROR_BAD_ERASE_PARAM ((uint32_t)0x00000200U) /*!< An invalid selection for erase groups */
  130. #define SDMMC_ERROR_WRITE_PROT_VIOLATION ((uint32_t)0x00000400U) /*!< Attempt to program a write protect block */
  131. #define SDMMC_ERROR_LOCK_UNLOCK_FAILED ((uint32_t)0x00000800U) /*!< Sequence or password error has been detected in unlock
  132. command or if there was an attempt to access a locked card */
  133. #define SDMMC_ERROR_COM_CRC_FAILED ((uint32_t)0x00001000U) /*!< CRC check of the previous command failed */
  134. #define SDMMC_ERROR_ILLEGAL_CMD ((uint32_t)0x00002000U) /*!< Command is not legal for the card state */
  135. #define SDMMC_ERROR_CARD_ECC_FAILED ((uint32_t)0x00004000U) /*!< Card internal ECC was applied but failed to correct the data */
  136. #define SDMMC_ERROR_CC_ERR ((uint32_t)0x00008000U) /*!< Internal card controller error */
  137. #define SDMMC_ERROR_GENERAL_UNKNOWN_ERR ((uint32_t)0x00010000U) /*!< General or unknown error */
  138. #define SDMMC_ERROR_STREAM_READ_UNDERRUN ((uint32_t)0x00020000U) /*!< The card could not sustain data reading in stream rmode */
  139. #define SDMMC_ERROR_STREAM_WRITE_OVERRUN ((uint32_t)0x00040000U) /*!< The card could not sustain data programming in stream mode */
  140. #define SDMMC_ERROR_CID_CSD_OVERWRITE ((uint32_t)0x00080000U) /*!< CID/CSD overwrite error */
  141. #define SDMMC_ERROR_WP_ERASE_SKIP ((uint32_t)0x00100000U) /*!< Only partial address space was erased */
  142. #define SDMMC_ERROR_CARD_ECC_DISABLED ((uint32_t)0x00200000U) /*!< Command has been executed without using internal ECC */
  143. #define SDMMC_ERROR_ERASE_RESET ((uint32_t)0x00400000U) /*!< Erase sequence was cleared before executing because an out
  144. of erase sequence command was received */
  145. #define SDMMC_ERROR_AKE_SEQ_ERR ((uint32_t)0x00800000U) /*!< Error in sequence of authentication */
  146. #define SDMMC_ERROR_INVALID_VOLTRANGE ((uint32_t)0x01000000U) /*!< Error in case of invalid voltage range */
  147. #define SDMMC_ERROR_ADDR_OUT_OF_RANGE ((uint32_t)0x02000000U) /*!< Error when addressed block is out of range */
  148. #define SDMMC_ERROR_REQUEST_NOT_APPLICABLE ((uint32_t)0x04000000U) /*!< Error when command request is not applicable */
  149. #define SDMMC_ERROR_INVALID_PARAMETER ((uint32_t)0x08000000U) /*!< the used parameter is not valid */
  150. #define SDMMC_ERROR_UNSUPPORTED_FEATURE ((uint32_t)0x10000000U) /*!< Error when feature is not insupported */
  151. #define SDMMC_ERROR_BUSY ((uint32_t)0x20000000U) /*!< Error when transfer process is busy */
  152. #define SDMMC_ERROR_DMA ((uint32_t)0x40000000U) /*!< Error while DMA transfer */
  153. #define SDMMC_ERROR_TIMEOUT ((uint32_t)0x80000000U) /*!< Timeout error */
  154. /**
  155. * @brief SDMMC Commands Index
  156. */
  157. #define SDMMC_CMD_GO_IDLE_STATE ((uint8_t)0U) /*!< Resets the SD memory card. */
  158. #define SDMMC_CMD_SEND_OP_COND ((uint8_t)1U) /*!< Sends host capacity support information and activates the card's initialization process. */
  159. #define SDMMC_CMD_ALL_SEND_CID ((uint8_t)2U) /*!< Asks any card connected to the host to send the CID numbers on the CMD line. */
  160. #define SDMMC_CMD_SET_REL_ADDR ((uint8_t)3U) /*!< Asks the card to publish a new relative address (RCA). */
  161. #define SDMMC_CMD_SET_DSR ((uint8_t)4U) /*!< Programs the DSR of all cards. */
  162. #define SDMMC_CMD_SDMMC_SEN_OP_COND ((uint8_t)5U) /*!< Sends host capacity support information (HCS) and asks the accessed card to send its
  163. operating condition register (OCR) content in the response on the CMD line. */
  164. #define SDMMC_CMD_HS_SWITCH ((uint8_t)6U) /*!< Checks switchable function (mode 0) and switch card function (mode 1). */
  165. #define SDMMC_CMD_SEL_DESEL_CARD ((uint8_t)7U) /*!< Selects the card by its own relative address and gets deselected by any other address */
  166. #define SDMMC_CMD_HS_SEND_EXT_CSD ((uint8_t)8U) /*!< Sends SD Memory Card interface condition, which includes host supply voltage information
  167. and asks the card whether card supports voltage. */
  168. #define SDMMC_CMD_SEND_CSD ((uint8_t)9U) /*!< Addressed card sends its card specific data (CSD) on the CMD line. */
  169. #define SDMMC_CMD_SEND_CID ((uint8_t)10U) /*!< Addressed card sends its card identification (CID) on the CMD line. */
  170. #define SDMMC_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11U) /*!< SD card doesn't support it. */
  171. #define SDMMC_CMD_STOP_TRANSMISSION ((uint8_t)12U) /*!< Forces the card to stop transmission. */
  172. #define SDMMC_CMD_SEND_STATUS ((uint8_t)13U) /*!< Addressed card sends its status register. */
  173. #define SDMMC_CMD_HS_BUSTEST_READ ((uint8_t)14U) /*!< Reserved */
  174. #define SDMMC_CMD_GO_INACTIVE_STATE ((uint8_t)15U) /*!< Sends an addressed card into the inactive state. */
  175. #define SDMMC_CMD_SET_BLOCKLEN ((uint8_t)16U) /*!< Sets the block length (in bytes for SDSC) for all following block commands
  176. (read, write, lock). Default block length is fixed to 512 Bytes. Not effective
  177. for SDHS and SDXC. */
  178. #define SDMMC_CMD_READ_SINGLE_BLOCK ((uint8_t)17U) /*!< Reads single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of
  179. fixed 512 bytes in case of SDHC and SDXC. */
  180. #define SDMMC_CMD_READ_MULT_BLOCK ((uint8_t)18U) /*!< Continuously transfers data blocks from card to host until interrupted by
  181. STOP_TRANSMISSION command. */
  182. #define SDMMC_CMD_HS_BUSTEST_WRITE ((uint8_t)19U) /*!< 64 bytes tuning pattern is sent for SDR50 and SDR104. */
  183. #define SDMMC_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20U) /*!< Speed class control command. */
  184. #define SDMMC_CMD_SET_BLOCK_COUNT ((uint8_t)23U) /*!< Specify block count for CMD18 and CMD25. */
  185. #define SDMMC_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24U) /*!< Writes single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of
  186. fixed 512 bytes in case of SDHC and SDXC. */
  187. #define SDMMC_CMD_WRITE_MULT_BLOCK ((uint8_t)25U) /*!< Continuously writes blocks of data until a STOP_TRANSMISSION follows. */
  188. #define SDMMC_CMD_PROG_CID ((uint8_t)26U) /*!< Reserved for manufacturers. */
  189. #define SDMMC_CMD_PROG_CSD ((uint8_t)27U) /*!< Programming of the programmable bits of the CSD. */
  190. #define SDMMC_CMD_SET_WRITE_PROT ((uint8_t)28U) /*!< Sets the write protection bit of the addressed group. */
  191. #define SDMMC_CMD_CLR_WRITE_PROT ((uint8_t)29U) /*!< Clears the write protection bit of the addressed group. */
  192. #define SDMMC_CMD_SEND_WRITE_PROT ((uint8_t)30U) /*!< Asks the card to send the status of the write protection bits. */
  193. #define SDMMC_CMD_SD_ERASE_GRP_START ((uint8_t)32U) /*!< Sets the address of the first write block to be erased. (For SD card only). */
  194. #define SDMMC_CMD_SD_ERASE_GRP_END ((uint8_t)33U) /*!< Sets the address of the last write block of the continuous range to be erased. */
  195. #define SDMMC_CMD_ERASE_GRP_START ((uint8_t)35U) /*!< Sets the address of the first write block to be erased. Reserved for each command
  196. system set by switch function command (CMD6). */
  197. #define SDMMC_CMD_ERASE_GRP_END ((uint8_t)36U) /*!< Sets the address of the last write block of the continuous range to be erased.
  198. Reserved for each command system set by switch function command (CMD6). */
  199. #define SDMMC_CMD_ERASE ((uint8_t)38U) /*!< Reserved for SD security applications. */
  200. #define SDMMC_CMD_FAST_IO ((uint8_t)39U) /*!< SD card doesn't support it (Reserved). */
  201. #define SDMMC_CMD_GO_IRQ_STATE ((uint8_t)40U) /*!< SD card doesn't support it (Reserved). */
  202. #define SDMMC_CMD_LOCK_UNLOCK ((uint8_t)42U) /*!< Sets/resets the password or lock/unlock the card. The size of the data block is set by
  203. the SET_BLOCK_LEN command. */
  204. #define SDMMC_CMD_APP_CMD ((uint8_t)55U) /*!< Indicates to the card that the next command is an application specific command rather
  205. than a standard command. */
  206. #define SDMMC_CMD_GEN_CMD ((uint8_t)56U) /*!< Used either to transfer a data block to the card or to get a data block from the card
  207. for general purpose/application specific commands. */
  208. #define SDMMC_CMD_NO_CMD ((uint8_t)64U) /*!< No command */
  209. /**
  210. * @brief Following commands are SD Card Specific commands.
  211. * SDMMC_APP_CMD should be sent before sending these commands.
  212. */
  213. #define SDMMC_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6U) /*!< (ACMD6) Defines the data bus width to be used for data transfer. The allowed data bus
  214. widths are given in SCR register. */
  215. #define SDMMC_CMD_SD_APP_STATUS ((uint8_t)13U) /*!< (ACMD13) Sends the SD status. */
  216. #define SDMMC_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22U) /*!< (ACMD22) Sends the number of the written (without errors) write blocks. Responds with
  217. 32bit+CRC data block. */
  218. #define SDMMC_CMD_SD_APP_OP_COND ((uint8_t)41U) /*!< (ACMD41) Sends host capacity support information (HCS) and asks the accessed card to
  219. send its operating condition register (OCR) content in the response on the CMD line. */
  220. #define SDMMC_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42U) /*!< (ACMD42) Connect/Disconnect the 50 KOhm pull-up resistor on CD/DAT3 (pin 1) of the card */
  221. #define SDMMC_CMD_SD_APP_SEND_SCR ((uint8_t)51U) /*!< Reads the SD Configuration Register (SCR). */
  222. #define SDMMC_CMD_SDMMC_RW_DIRECT ((uint8_t)52U) /*!< For SD I/O card only, reserved for security specification. */
  223. #define SDMMC_CMD_SDMMC_RW_EXTENDED ((uint8_t)53U) /*!< For SD I/O card only, reserved for security specification. */
  224. /**
  225. * @brief Following commands are SD Card Specific security commands.
  226. * SDMMC_CMD_APP_CMD should be sent before sending these commands.
  227. */
  228. #define SDMMC_CMD_SD_APP_GET_MKB ((uint8_t)43U)
  229. #define SDMMC_CMD_SD_APP_GET_MID ((uint8_t)44U)
  230. #define SDMMC_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45U)
  231. #define SDMMC_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46U)
  232. #define SDMMC_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47U)
  233. #define SDMMC_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48U)
  234. #define SDMMC_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18U)
  235. #define SDMMC_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25U)
  236. #define SDMMC_CMD_SD_APP_SECURE_ERASE ((uint8_t)38U)
  237. #define SDMMC_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49U)
  238. #define SDMMC_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48U)
  239. /**
  240. * @brief Masks for errors Card Status R1 (OCR Register)
  241. */
  242. #define SDMMC_OCR_ADDR_OUT_OF_RANGE ((uint32_t)0x80000000U)
  243. #define SDMMC_OCR_ADDR_MISALIGNED ((uint32_t)0x40000000U)
  244. #define SDMMC_OCR_BLOCK_LEN_ERR ((uint32_t)0x20000000U)
  245. #define SDMMC_OCR_ERASE_SEQ_ERR ((uint32_t)0x10000000U)
  246. #define SDMMC_OCR_BAD_ERASE_PARAM ((uint32_t)0x08000000U)
  247. #define SDMMC_OCR_WRITE_PROT_VIOLATION ((uint32_t)0x04000000U)
  248. #define SDMMC_OCR_LOCK_UNLOCK_FAILED ((uint32_t)0x01000000U)
  249. #define SDMMC_OCR_COM_CRC_FAILED ((uint32_t)0x00800000U)
  250. #define SDMMC_OCR_ILLEGAL_CMD ((uint32_t)0x00400000U)
  251. #define SDMMC_OCR_CARD_ECC_FAILED ((uint32_t)0x00200000U)
  252. #define SDMMC_OCR_CC_ERROR ((uint32_t)0x00100000U)
  253. #define SDMMC_OCR_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00080000U)
  254. #define SDMMC_OCR_STREAM_READ_UNDERRUN ((uint32_t)0x00040000U)
  255. #define SDMMC_OCR_STREAM_WRITE_OVERRUN ((uint32_t)0x00020000U)
  256. #define SDMMC_OCR_CID_CSD_OVERWRITE ((uint32_t)0x00010000U)
  257. #define SDMMC_OCR_WP_ERASE_SKIP ((uint32_t)0x00008000U)
  258. #define SDMMC_OCR_CARD_ECC_DISABLED ((uint32_t)0x00004000U)
  259. #define SDMMC_OCR_ERASE_RESET ((uint32_t)0x00002000U)
  260. #define SDMMC_OCR_AKE_SEQ_ERROR ((uint32_t)0x00000008U)
  261. #define SDMMC_OCR_ERRORBITS ((uint32_t)0xFDFFE008U)
  262. /**
  263. * @brief Masks for R6 Response
  264. */
  265. #define SDMMC_R6_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00002000U)
  266. #define SDMMC_R6_ILLEGAL_CMD ((uint32_t)0x00004000U)
  267. #define SDMMC_R6_COM_CRC_FAILED ((uint32_t)0x00008000U)
  268. #define SDMMC_VOLTAGE_WINDOW_SD ((uint32_t)0x80100000U)
  269. #define SDMMC_HIGH_CAPACITY ((uint32_t)0x40000000U)
  270. #define SDMMC_STD_CAPACITY ((uint32_t)0x00000000U)
  271. #define SDMMC_CHECK_PATTERN ((uint32_t)0x000001AAU)
  272. #define SDMMC_MAX_VOLT_TRIAL ((uint32_t)0x0000FFFFU)
  273. #define SDMMC_MAX_TRIAL ((uint32_t)0x0000FFFFU)
  274. #define SDMMC_ALLZERO ((uint32_t)0x00000000U)
  275. #define SDMMC_WIDE_BUS_SUPPORT ((uint32_t)0x00040000U)
  276. #define SDMMC_SINGLE_BUS_SUPPORT ((uint32_t)0x00010000U)
  277. #define SDMMC_CARD_LOCKED ((uint32_t)0x02000000U)
  278. #define SDMMC_DATATIMEOUT ((uint32_t)0xFFFFFFFFU)
  279. #define SDMMC_0TO7BITS ((uint32_t)0x000000FFU)
  280. #define SDMMC_8TO15BITS ((uint32_t)0x0000FF00U)
  281. #define SDMMC_16TO23BITS ((uint32_t)0x00FF0000U)
  282. #define SDMMC_24TO31BITS ((uint32_t)0xFF000000U)
  283. #define SDMMC_MAX_DATA_LENGTH ((uint32_t)0x01FFFFFFU)
  284. #define SDMMC_HALFFIFO ((uint32_t)0x00000008U)
  285. #define SDMMC_HALFFIFOBYTES ((uint32_t)0x00000020U)
  286. /**
  287. * @brief Command Class supported
  288. */
  289. #define SDMMC_CCCC_ERASE ((uint32_t)0x00000020U)
  290. #define SDMMC_CMDTIMEOUT ((uint32_t)5000U) /* Command send and response timeout */
  291. #define SDMMC_MAXERASETIMEOUT ((uint32_t)63000U) /* Max erase Timeout 63 s */
  292. /** @defgroup SDMMC_LL_Clock_Edge Clock Edge
  293. * @{
  294. */
  295. #define SDMMC_CLOCK_EDGE_RISING ((uint32_t)0x00000000U)
  296. #define SDMMC_CLOCK_EDGE_FALLING SDMMC_CLKCR_NEGEDGE
  297. #define IS_SDMMC_CLOCK_EDGE(EDGE) (((EDGE) == SDMMC_CLOCK_EDGE_RISING) || \
  298. ((EDGE) == SDMMC_CLOCK_EDGE_FALLING))
  299. /**
  300. * @}
  301. */
  302. /** @defgroup SDMMC_LL_Clock_Bypass Clock Bypass
  303. * @{
  304. */
  305. #define SDMMC_CLOCK_BYPASS_DISABLE ((uint32_t)0x00000000U)
  306. #define SDMMC_CLOCK_BYPASS_ENABLE SDMMC_CLKCR_BYPASS
  307. #define IS_SDMMC_CLOCK_BYPASS(BYPASS) (((BYPASS) == SDMMC_CLOCK_BYPASS_DISABLE) || \
  308. ((BYPASS) == SDMMC_CLOCK_BYPASS_ENABLE))
  309. /**
  310. * @}
  311. */
  312. /** @defgroup SDMMC_LL_Clock_Power_Save Clock Power Saving
  313. * @{
  314. */
  315. #define SDMMC_CLOCK_POWER_SAVE_DISABLE ((uint32_t)0x00000000U)
  316. #define SDMMC_CLOCK_POWER_SAVE_ENABLE SDMMC_CLKCR_PWRSAV
  317. #define IS_SDMMC_CLOCK_POWER_SAVE(SAVE) (((SAVE) == SDMMC_CLOCK_POWER_SAVE_DISABLE) || \
  318. ((SAVE) == SDMMC_CLOCK_POWER_SAVE_ENABLE))
  319. /**
  320. * @}
  321. */
  322. /** @defgroup SDMMC_LL_Bus_Wide Bus Width
  323. * @{
  324. */
  325. #define SDMMC_BUS_WIDE_1B ((uint32_t)0x00000000U)
  326. #define SDMMC_BUS_WIDE_4B SDMMC_CLKCR_WIDBUS_0
  327. #define SDMMC_BUS_WIDE_8B SDMMC_CLKCR_WIDBUS_1
  328. #define IS_SDMMC_BUS_WIDE(WIDE) (((WIDE) == SDMMC_BUS_WIDE_1B) || \
  329. ((WIDE) == SDMMC_BUS_WIDE_4B) || \
  330. ((WIDE) == SDMMC_BUS_WIDE_8B))
  331. /**
  332. * @}
  333. */
  334. /** @defgroup SDMMC_LL_Hardware_Flow_Control Hardware Flow Control
  335. * @{
  336. */
  337. #define SDMMC_HARDWARE_FLOW_CONTROL_DISABLE ((uint32_t)0x00000000U)
  338. #define SDMMC_HARDWARE_FLOW_CONTROL_ENABLE SDMMC_CLKCR_HWFC_EN
  339. #define IS_SDMMC_HARDWARE_FLOW_CONTROL(CONTROL) (((CONTROL) == SDMMC_HARDWARE_FLOW_CONTROL_DISABLE) || \
  340. ((CONTROL) == SDMMC_HARDWARE_FLOW_CONTROL_ENABLE))
  341. /**
  342. * @}
  343. */
  344. /** @defgroup SDMMC_LL_Clock_Division Clock Division
  345. * @{
  346. */
  347. #define IS_SDMMC_CLKDIV(DIV) ((DIV) <= 0xFF)
  348. /**
  349. * @}
  350. */
  351. /** @defgroup SDMMC_LL_Command_Index Command Index
  352. * @{
  353. */
  354. #define IS_SDMMC_CMD_INDEX(INDEX) ((INDEX) < 0x40)
  355. /**
  356. * @}
  357. */
  358. /** @defgroup SDMMC_LL_Response_Type Response Type
  359. * @{
  360. */
  361. #define SDMMC_RESPONSE_NO ((uint32_t)0x00000000U)
  362. #define SDMMC_RESPONSE_SHORT SDMMC_CMD_WAITRESP_0
  363. #define SDMMC_RESPONSE_LONG SDMMC_CMD_WAITRESP
  364. #define IS_SDMMC_RESPONSE(RESPONSE) (((RESPONSE) == SDMMC_RESPONSE_NO) || \
  365. ((RESPONSE) == SDMMC_RESPONSE_SHORT) || \
  366. ((RESPONSE) == SDMMC_RESPONSE_LONG))
  367. /**
  368. * @}
  369. */
  370. /** @defgroup SDMMC_LL_Wait_Interrupt_State Wait Interrupt
  371. * @{
  372. */
  373. #define SDMMC_WAIT_NO ((uint32_t)0x00000000U)
  374. #define SDMMC_WAIT_IT SDMMC_CMD_WAITINT
  375. #define SDMMC_WAIT_PEND SDMMC_CMD_WAITPEND
  376. #define IS_SDMMC_WAIT(WAIT) (((WAIT) == SDMMC_WAIT_NO) || \
  377. ((WAIT) == SDMMC_WAIT_IT) || \
  378. ((WAIT) == SDMMC_WAIT_PEND))
  379. /**
  380. * @}
  381. */
  382. /** @defgroup SDMMC_LL_CPSM_State CPSM State
  383. * @{
  384. */
  385. #define SDMMC_CPSM_DISABLE ((uint32_t)0x00000000U)
  386. #define SDMMC_CPSM_ENABLE SDMMC_CMD_CPSMEN
  387. #define IS_SDMMC_CPSM(CPSM) (((CPSM) == SDMMC_CPSM_DISABLE) || \
  388. ((CPSM) == SDMMC_CPSM_ENABLE))
  389. /**
  390. * @}
  391. */
  392. /** @defgroup SDMMC_LL_Response_Registers Response Register
  393. * @{
  394. */
  395. #define SDMMC_RESP1 ((uint32_t)0x00000000U)
  396. #define SDMMC_RESP2 ((uint32_t)0x00000004U)
  397. #define SDMMC_RESP3 ((uint32_t)0x00000008U)
  398. #define SDMMC_RESP4 ((uint32_t)0x0000000C)
  399. #define IS_SDMMC_RESP(RESP) (((RESP) == SDMMC_RESP1) || \
  400. ((RESP) == SDMMC_RESP2) || \
  401. ((RESP) == SDMMC_RESP3) || \
  402. ((RESP) == SDMMC_RESP4))
  403. /**
  404. * @}
  405. */
  406. /** @defgroup SDMMC_LL_Data_Length Data Lenght
  407. * @{
  408. */
  409. #define IS_SDMMC_DATA_LENGTH(LENGTH) ((LENGTH) <= 0x01FFFFFF)
  410. /**
  411. * @}
  412. */
  413. /** @defgroup SDMMC_LL_Data_Block_Size Data Block Size
  414. * @{
  415. */
  416. #define SDMMC_DATABLOCK_SIZE_1B ((uint32_t)0x00000000U)
  417. #define SDMMC_DATABLOCK_SIZE_2B SDMMC_DCTRL_DBLOCKSIZE_0
  418. #define SDMMC_DATABLOCK_SIZE_4B SDMMC_DCTRL_DBLOCKSIZE_1
  419. #define SDMMC_DATABLOCK_SIZE_8B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1)
  420. #define SDMMC_DATABLOCK_SIZE_16B SDMMC_DCTRL_DBLOCKSIZE_2
  421. #define SDMMC_DATABLOCK_SIZE_32B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_2)
  422. #define SDMMC_DATABLOCK_SIZE_64B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2)
  423. #define SDMMC_DATABLOCK_SIZE_128B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2)
  424. #define SDMMC_DATABLOCK_SIZE_256B SDMMC_DCTRL_DBLOCKSIZE_3
  425. #define SDMMC_DATABLOCK_SIZE_512B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_3)
  426. #define SDMMC_DATABLOCK_SIZE_1024B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_3)
  427. #define SDMMC_DATABLOCK_SIZE_2048B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_3)
  428. #define SDMMC_DATABLOCK_SIZE_4096B (SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3)
  429. #define SDMMC_DATABLOCK_SIZE_8192B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3)
  430. #define SDMMC_DATABLOCK_SIZE_16384B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3)
  431. #define IS_SDMMC_BLOCK_SIZE(SIZE) (((SIZE) == SDMMC_DATABLOCK_SIZE_1B) || \
  432. ((SIZE) == SDMMC_DATABLOCK_SIZE_2B) || \
  433. ((SIZE) == SDMMC_DATABLOCK_SIZE_4B) || \
  434. ((SIZE) == SDMMC_DATABLOCK_SIZE_8B) || \
  435. ((SIZE) == SDMMC_DATABLOCK_SIZE_16B) || \
  436. ((SIZE) == SDMMC_DATABLOCK_SIZE_32B) || \
  437. ((SIZE) == SDMMC_DATABLOCK_SIZE_64B) || \
  438. ((SIZE) == SDMMC_DATABLOCK_SIZE_128B) || \
  439. ((SIZE) == SDMMC_DATABLOCK_SIZE_256B) || \
  440. ((SIZE) == SDMMC_DATABLOCK_SIZE_512B) || \
  441. ((SIZE) == SDMMC_DATABLOCK_SIZE_1024B) || \
  442. ((SIZE) == SDMMC_DATABLOCK_SIZE_2048B) || \
  443. ((SIZE) == SDMMC_DATABLOCK_SIZE_4096B) || \
  444. ((SIZE) == SDMMC_DATABLOCK_SIZE_8192B) || \
  445. ((SIZE) == SDMMC_DATABLOCK_SIZE_16384B))
  446. /**
  447. * @}
  448. */
  449. /** @defgroup SDMMC_LL_Transfer_Direction Transfer Direction
  450. * @{
  451. */
  452. #define SDMMC_TRANSFER_DIR_TO_CARD ((uint32_t)0x00000000U)
  453. #define SDMMC_TRANSFER_DIR_TO_SDMMC SDMMC_DCTRL_DTDIR
  454. #define IS_SDMMC_TRANSFER_DIR(DIR) (((DIR) == SDMMC_TRANSFER_DIR_TO_CARD) || \
  455. ((DIR) == SDMMC_TRANSFER_DIR_TO_SDMMC))
  456. /**
  457. * @}
  458. */
  459. /** @defgroup SDMMC_LL_Transfer_Type Transfer Type
  460. * @{
  461. */
  462. #define SDMMC_TRANSFER_MODE_BLOCK ((uint32_t)0x00000000U)
  463. #define SDMMC_TRANSFER_MODE_STREAM SDMMC_DCTRL_DTMODE
  464. #define IS_SDMMC_TRANSFER_MODE(MODE) (((MODE) == SDMMC_TRANSFER_MODE_BLOCK) || \
  465. ((MODE) == SDMMC_TRANSFER_MODE_STREAM))
  466. /**
  467. * @}
  468. */
  469. /** @defgroup SDMMC_LL_DPSM_State DPSM State
  470. * @{
  471. */
  472. #define SDMMC_DPSM_DISABLE ((uint32_t)0x00000000U)
  473. #define SDMMC_DPSM_ENABLE SDMMC_DCTRL_DTEN
  474. #define IS_SDMMC_DPSM(DPSM) (((DPSM) == SDMMC_DPSM_DISABLE) ||\
  475. ((DPSM) == SDMMC_DPSM_ENABLE))
  476. /**
  477. * @}
  478. */
  479. /** @defgroup SDMMC_LL_Read_Wait_Mode Read Wait Mode
  480. * @{
  481. */
  482. #define SDMMC_READ_WAIT_MODE_DATA2 ((uint32_t)0x00000000U)
  483. #define SDMMC_READ_WAIT_MODE_CLK (SDMMC_DCTRL_RWMOD)
  484. #define IS_SDMMC_READWAIT_MODE(MODE) (((MODE) == SDMMC_READ_WAIT_MODE_CLK) || \
  485. ((MODE) == SDMMC_READ_WAIT_MODE_DATA2))
  486. /**
  487. * @}
  488. */
  489. /** @defgroup SDMMC_LL_Interrupt_sources Interrupt Sources
  490. * @{
  491. */
  492. #define SDMMC_IT_CCRCFAIL SDMMC_STA_CCRCFAIL
  493. #define SDMMC_IT_DCRCFAIL SDMMC_STA_DCRCFAIL
  494. #define SDMMC_IT_CTIMEOUT SDMMC_STA_CTIMEOUT
  495. #define SDMMC_IT_DTIMEOUT SDMMC_STA_DTIMEOUT
  496. #define SDMMC_IT_TXUNDERR SDMMC_STA_TXUNDERR
  497. #define SDMMC_IT_RXOVERR SDMMC_STA_RXOVERR
  498. #define SDMMC_IT_CMDREND SDMMC_STA_CMDREND
  499. #define SDMMC_IT_CMDSENT SDMMC_STA_CMDSENT
  500. #define SDMMC_IT_DATAEND SDMMC_STA_DATAEND
  501. #define SDMMC_IT_DBCKEND SDMMC_STA_DBCKEND
  502. #define SDMMC_IT_CMDACT SDMMC_STA_CMDACT
  503. #define SDMMC_IT_TXACT SDMMC_STA_TXACT
  504. #define SDMMC_IT_RXACT SDMMC_STA_RXACT
  505. #define SDMMC_IT_TXFIFOHE SDMMC_STA_TXFIFOHE
  506. #define SDMMC_IT_RXFIFOHF SDMMC_STA_RXFIFOHF
  507. #define SDMMC_IT_TXFIFOF SDMMC_STA_TXFIFOF
  508. #define SDMMC_IT_RXFIFOF SDMMC_STA_RXFIFOF
  509. #define SDMMC_IT_TXFIFOE SDMMC_STA_TXFIFOE
  510. #define SDMMC_IT_RXFIFOE SDMMC_STA_RXFIFOE
  511. #define SDMMC_IT_TXDAVL SDMMC_STA_TXDAVL
  512. #define SDMMC_IT_RXDAVL SDMMC_STA_RXDAVL
  513. #define SDMMC_IT_SDIOIT SDMMC_STA_SDIOIT
  514. /**
  515. * @}
  516. */
  517. /** @defgroup SDMMC_LL_Flags Flags
  518. * @{
  519. */
  520. #define SDMMC_FLAG_CCRCFAIL SDMMC_STA_CCRCFAIL
  521. #define SDMMC_FLAG_DCRCFAIL SDMMC_STA_DCRCFAIL
  522. #define SDMMC_FLAG_CTIMEOUT SDMMC_STA_CTIMEOUT
  523. #define SDMMC_FLAG_DTIMEOUT SDMMC_STA_DTIMEOUT
  524. #define SDMMC_FLAG_TXUNDERR SDMMC_STA_TXUNDERR
  525. #define SDMMC_FLAG_RXOVERR SDMMC_STA_RXOVERR
  526. #define SDMMC_FLAG_CMDREND SDMMC_STA_CMDREND
  527. #define SDMMC_FLAG_CMDSENT SDMMC_STA_CMDSENT
  528. #define SDMMC_FLAG_DATAEND SDMMC_STA_DATAEND
  529. #define SDMMC_FLAG_DBCKEND SDMMC_STA_DBCKEND
  530. #define SDMMC_FLAG_CMDACT SDMMC_STA_CMDACT
  531. #define SDMMC_FLAG_TXACT SDMMC_STA_TXACT
  532. #define SDMMC_FLAG_RXACT SDMMC_STA_RXACT
  533. #define SDMMC_FLAG_TXFIFOHE SDMMC_STA_TXFIFOHE
  534. #define SDMMC_FLAG_RXFIFOHF SDMMC_STA_RXFIFOHF
  535. #define SDMMC_FLAG_TXFIFOF SDMMC_STA_TXFIFOF
  536. #define SDMMC_FLAG_RXFIFOF SDMMC_STA_RXFIFOF
  537. #define SDMMC_FLAG_TXFIFOE SDMMC_STA_TXFIFOE
  538. #define SDMMC_FLAG_RXFIFOE SDMMC_STA_RXFIFOE
  539. #define SDMMC_FLAG_TXDAVL SDMMC_STA_TXDAVL
  540. #define SDMMC_FLAG_RXDAVL SDMMC_STA_RXDAVL
  541. #define SDMMC_FLAG_SDIOIT SDMMC_STA_SDIOIT
  542. #define SDMMC_STATIC_FLAGS ((uint32_t)(SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_CTIMEOUT |\
  543. SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_TXUNDERR | SDMMC_FLAG_RXOVERR |\
  544. SDMMC_FLAG_CMDREND | SDMMC_FLAG_CMDSENT | SDMMC_FLAG_DATAEND |\
  545. SDMMC_FLAG_DBCKEND))
  546. /**
  547. * @}
  548. */
  549. /**
  550. * @}
  551. */
  552. /* Exported macro ------------------------------------------------------------*/
  553. /** @defgroup SDMMC_LL_Exported_macros SDMMC_LL Exported Macros
  554. * @{
  555. */
  556. /** @defgroup SDMMC_LL_Register Bits And Addresses Definitions
  557. * @brief SDMMC_LL registers bit address in the alias region
  558. * @{
  559. */
  560. /* ---------------------- SDMMC registers bit mask --------------------------- */
  561. /* --- CLKCR Register ---*/
  562. /* CLKCR register clear mask */
  563. #define CLKCR_CLEAR_MASK ((uint32_t)(SDMMC_CLKCR_CLKDIV | SDMMC_CLKCR_PWRSAV |\
  564. SDMMC_CLKCR_BYPASS | SDMMC_CLKCR_WIDBUS |\
  565. SDMMC_CLKCR_NEGEDGE | SDMMC_CLKCR_HWFC_EN))
  566. /* --- DCTRL Register ---*/
  567. /* SDMMC DCTRL Clear Mask */
  568. #define DCTRL_CLEAR_MASK ((uint32_t)(SDMMC_DCTRL_DTEN | SDMMC_DCTRL_DTDIR |\
  569. SDMMC_DCTRL_DTMODE | SDMMC_DCTRL_DBLOCKSIZE))
  570. /* --- CMD Register ---*/
  571. /* CMD Register clear mask */
  572. #define CMD_CLEAR_MASK ((uint32_t)(SDMMC_CMD_CMDINDEX | SDMMC_CMD_WAITRESP |\
  573. SDMMC_CMD_WAITINT | SDMMC_CMD_WAITPEND |\
  574. SDMMC_CMD_CPSMEN | SDMMC_CMD_SDIOSUSPEND))
  575. /* SDMMC Initialization Frequency (400KHz max) */
  576. #define SDMMC_INIT_CLK_DIV ((uint8_t)0x76)
  577. /* SDMMC Data Transfer Frequency (25MHz max) */
  578. #define SDMMC_TRANSFER_CLK_DIV ((uint8_t)0x0)
  579. /**
  580. * @}
  581. */
  582. /** @defgroup SDMMC_LL_Interrupt_Clock Interrupt And Clock Configuration
  583. * @brief macros to handle interrupts and specific clock configurations
  584. * @{
  585. */
  586. /**
  587. * @brief Enable the SDMMC device.
  588. * @param __INSTANCE__ SDMMC Instance
  589. * @retval None
  590. */
  591. #define __SDMMC_ENABLE(__INSTANCE__) ((__INSTANCE__)->CLKCR |= SDMMC_CLKCR_CLKEN)
  592. /**
  593. * @brief Disable the SDMMC device.
  594. * @param __INSTANCE__ SDMMC Instance
  595. * @retval None
  596. */
  597. #define __SDMMC_DISABLE(__INSTANCE__) ((__INSTANCE__)->CLKCR &= ~SDMMC_CLKCR_CLKEN)
  598. /**
  599. * @brief Enable the SDMMC DMA transfer.
  600. * @param __INSTANCE__ SDMMC Instance
  601. * @retval None
  602. */
  603. #define __SDMMC_DMA_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_DMAEN)
  604. /**
  605. * @brief Disable the SDMMC DMA transfer.
  606. * @param __INSTANCE__ SDMMC Instance
  607. * @retval None
  608. */
  609. #define __SDMMC_DMA_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_DMAEN)
  610. /**
  611. * @brief Enable the SDMMC device interrupt.
  612. * @param __INSTANCE__ Pointer to SDMMC register base
  613. * @param __INTERRUPT__ specifies the SDMMC interrupt sources to be enabled.
  614. * This parameter can be one or a combination of the following values:
  615. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  616. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  617. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  618. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  619. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  620. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  621. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  622. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  623. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  624. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  625. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  626. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  627. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  628. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  629. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  630. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  631. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  632. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  633. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  634. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  635. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  636. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  637. * @retval None
  638. */
  639. #define __SDMMC_ENABLE_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->MASK |= (__INTERRUPT__))
  640. /**
  641. * @brief Disable the SDMMC device interrupt.
  642. * @param __INSTANCE__ Pointer to SDMMC register base
  643. * @param __INTERRUPT__ specifies the SDMMC interrupt sources to be disabled.
  644. * This parameter can be one or a combination of the following values:
  645. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  646. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  647. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  648. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  649. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  650. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  651. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  652. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  653. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  654. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  655. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  656. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  657. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  658. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  659. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  660. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  661. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  662. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  663. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  664. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  665. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  666. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  667. * @retval None
  668. */
  669. #define __SDMMC_DISABLE_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->MASK &= ~(__INTERRUPT__))
  670. /**
  671. * @brief Checks whether the specified SDMMC flag is set or not.
  672. * @param __INSTANCE__ Pointer to SDMMC register base
  673. * @param __FLAG__ specifies the flag to check.
  674. * This parameter can be one of the following values:
  675. * @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed)
  676. * @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  677. * @arg SDMMC_FLAG_CTIMEOUT: Command response timeout
  678. * @arg SDMMC_FLAG_DTIMEOUT: Data timeout
  679. * @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error
  680. * @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error
  681. * @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed)
  682. * @arg SDMMC_FLAG_CMDSENT: Command sent (no response required)
  683. * @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  684. * @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  685. * @arg SDMMC_FLAG_CMDACT: Command transfer in progress
  686. * @arg SDMMC_FLAG_TXACT: Data transmit in progress
  687. * @arg SDMMC_FLAG_RXACT: Data receive in progress
  688. * @arg SDMMC_FLAG_TXFIFOHE: Transmit FIFO Half Empty
  689. * @arg SDMMC_FLAG_RXFIFOHF: Receive FIFO Half Full
  690. * @arg SDMMC_FLAG_TXFIFOF: Transmit FIFO full
  691. * @arg SDMMC_FLAG_RXFIFOF: Receive FIFO full
  692. * @arg SDMMC_FLAG_TXFIFOE: Transmit FIFO empty
  693. * @arg SDMMC_FLAG_RXFIFOE: Receive FIFO empty
  694. * @arg SDMMC_FLAG_TXDAVL: Data available in transmit FIFO
  695. * @arg SDMMC_FLAG_RXDAVL: Data available in receive FIFO
  696. * @arg SDMMC_FLAG_SDMMCIT: SD I/O interrupt received
  697. * @retval The new state of SDMMC_FLAG (SET or RESET).
  698. */
  699. #define __SDMMC_GET_FLAG(__INSTANCE__, __FLAG__) (((__INSTANCE__)->STA &(__FLAG__)) != RESET)
  700. /**
  701. * @brief Clears the SDMMC pending flags.
  702. * @param __INSTANCE__ Pointer to SDMMC register base
  703. * @param __FLAG__ specifies the flag to clear.
  704. * This parameter can be one or a combination of the following values:
  705. * @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed)
  706. * @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  707. * @arg SDMMC_FLAG_CTIMEOUT: Command response timeout
  708. * @arg SDMMC_FLAG_DTIMEOUT: Data timeout
  709. * @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error
  710. * @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error
  711. * @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed)
  712. * @arg SDMMC_FLAG_CMDSENT: Command sent (no response required)
  713. * @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  714. * @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  715. * @arg SDMMC_FLAG_SDMMCIT: SD I/O interrupt received
  716. * @retval None
  717. */
  718. #define __SDMMC_CLEAR_FLAG(__INSTANCE__, __FLAG__) ((__INSTANCE__)->ICR = (__FLAG__))
  719. /**
  720. * @brief Checks whether the specified SDMMC interrupt has occurred or not.
  721. * @param __INSTANCE__ Pointer to SDMMC register base
  722. * @param __INTERRUPT__ specifies the SDMMC interrupt source to check.
  723. * This parameter can be one of the following values:
  724. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  725. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  726. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  727. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  728. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  729. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  730. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  731. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  732. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  733. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  734. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  735. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  736. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  737. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  738. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  739. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  740. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  741. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  742. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  743. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  744. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  745. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  746. * @retval The new state of SDMMC_IT (SET or RESET).
  747. */
  748. #define __SDMMC_GET_IT (__INSTANCE__, __INTERRUPT__) (((__INSTANCE__)->STA &(__INTERRUPT__)) == (__INTERRUPT__))
  749. /**
  750. * @brief Clears the SDMMC's interrupt pending bits.
  751. * @param __INSTANCE__ Pointer to SDMMC register base
  752. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  753. * This parameter can be one or a combination of the following values:
  754. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  755. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  756. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  757. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  758. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  759. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  760. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  761. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  762. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDMMC_DCOUNT, is zero) interrupt
  763. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  764. * @retval None
  765. */
  766. #define __SDMMC_CLEAR_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->ICR = (__INTERRUPT__))
  767. /**
  768. * @brief Enable Start the SD I/O Read Wait operation.
  769. * @param __INSTANCE__ Pointer to SDMMC register base
  770. * @retval None
  771. */
  772. #define __SDMMC_START_READWAIT_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_RWSTART)
  773. /**
  774. * @brief Disable Start the SD I/O Read Wait operations.
  775. * @param __INSTANCE__ Pointer to SDMMC register base
  776. * @retval None
  777. */
  778. #define __SDMMC_START_READWAIT_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_RWSTART)
  779. /**
  780. * @brief Enable Start the SD I/O Read Wait operation.
  781. * @param __INSTANCE__ Pointer to SDMMC register base
  782. * @retval None
  783. */
  784. #define __SDMMC_STOP_READWAIT_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_RWSTOP)
  785. /**
  786. * @brief Disable Stop the SD I/O Read Wait operations.
  787. * @param __INSTANCE__ Pointer to SDMMC register base
  788. * @retval None
  789. */
  790. #define __SDMMC_STOP_READWAIT_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_RWSTOP)
  791. /**
  792. * @brief Enable the SD I/O Mode Operation.
  793. * @param __INSTANCE__ Pointer to SDMMC register base
  794. * @retval None
  795. */
  796. #define __SDMMC_OPERATION_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_SDIOEN)
  797. /**
  798. * @brief Disable the SD I/O Mode Operation.
  799. * @param __INSTANCE__ Pointer to SDMMC register base
  800. * @retval None
  801. */
  802. #define __SDMMC_OPERATION_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_SDIOEN)
  803. /**
  804. * @brief Enable the SD I/O Suspend command sending.
  805. * @param __INSTANCE__ Pointer to SDMMC register base
  806. * @retval None
  807. */
  808. #define __SDMMC_SUSPEND_CMD_ENABLE(__INSTANCE__) ((__INSTANCE__)->CMD |= SDMMC_CMD_SDIOSUSPEND)
  809. /**
  810. * @brief Disable the SD I/O Suspend command sending.
  811. * @param __INSTANCE__ Pointer to SDMMC register base
  812. * @retval None
  813. */
  814. #define __SDMMC_SUSPEND_CMD_DISABLE(__INSTANCE__) ((__INSTANCE__)->CMD &= ~SDMMC_CMD_SDIOSUSPEND)
  815. /**
  816. * @}
  817. */
  818. /**
  819. * @}
  820. */
  821. /* Exported functions --------------------------------------------------------*/
  822. /** @addtogroup SDMMC_LL_Exported_Functions
  823. * @{
  824. */
  825. /* Initialization/de-initialization functions **********************************/
  826. /** @addtogroup HAL_SDMMC_LL_Group1
  827. * @{
  828. */
  829. HAL_StatusTypeDef SDMMC_Init(SDMMC_TypeDef *SDMMCx, SDMMC_InitTypeDef Init);
  830. /**
  831. * @}
  832. */
  833. /* I/O operation functions *****************************************************/
  834. /** @addtogroup HAL_SDMMC_LL_Group2
  835. * @{
  836. */
  837. uint32_t SDMMC_ReadFIFO(SDMMC_TypeDef *SDMMCx);
  838. HAL_StatusTypeDef SDMMC_WriteFIFO(SDMMC_TypeDef *SDMMCx, uint32_t *pWriteData);
  839. /**
  840. * @}
  841. */
  842. /* Peripheral Control functions ************************************************/
  843. /** @addtogroup HAL_SDMMC_LL_Group3
  844. * @{
  845. */
  846. HAL_StatusTypeDef SDMMC_PowerState_ON(SDMMC_TypeDef *SDMMCx);
  847. HAL_StatusTypeDef SDMMC_PowerState_OFF(SDMMC_TypeDef *SDMMCx);
  848. uint32_t SDMMC_GetPowerState(SDMMC_TypeDef *SDMMCx);
  849. /* Command path state machine (CPSM) management functions */
  850. HAL_StatusTypeDef SDMMC_SendCommand(SDMMC_TypeDef *SDMMCx, SDMMC_CmdInitTypeDef *Command);
  851. uint8_t SDMMC_GetCommandResponse(SDMMC_TypeDef *SDMMCx);
  852. uint32_t SDMMC_GetResponse(SDMMC_TypeDef *SDMMCx, uint32_t Response);
  853. /* Data path state machine (DPSM) management functions */
  854. HAL_StatusTypeDef SDMMC_ConfigData(SDMMC_TypeDef *SDMMCx, SDMMC_DataInitTypeDef* Data);
  855. uint32_t SDMMC_GetDataCounter(SDMMC_TypeDef *SDMMCx);
  856. uint32_t SDMMC_GetFIFOCount(SDMMC_TypeDef *SDMMCx);
  857. /* SDMMC Cards mode management functions */
  858. HAL_StatusTypeDef SDMMC_SetSDMMCReadWaitMode(SDMMC_TypeDef *SDMMCx, uint32_t SDMMC_ReadWaitMode);
  859. /* SDMMC Commands management functions */
  860. uint32_t SDMMC_CmdBlockLength(SDMMC_TypeDef *SDMMCx, uint32_t BlockSize);
  861. uint32_t SDMMC_CmdReadSingleBlock(SDMMC_TypeDef *SDMMCx, uint32_t ReadAdd);
  862. uint32_t SDMMC_CmdReadMultiBlock(SDMMC_TypeDef *SDMMCx, uint32_t ReadAdd);
  863. uint32_t SDMMC_CmdWriteSingleBlock(SDMMC_TypeDef *SDMMCx, uint32_t WriteAdd);
  864. uint32_t SDMMC_CmdWriteMultiBlock(SDMMC_TypeDef *SDMMCx, uint32_t WriteAdd);
  865. uint32_t SDMMC_CmdEraseStartAdd(SDMMC_TypeDef *SDMMCx, uint32_t StartAdd);
  866. uint32_t SDMMC_CmdSDEraseStartAdd(SDMMC_TypeDef *SDMMCx, uint32_t StartAdd);
  867. uint32_t SDMMC_CmdEraseEndAdd(SDMMC_TypeDef *SDMMCx, uint32_t EndAdd);
  868. uint32_t SDMMC_CmdSDEraseEndAdd(SDMMC_TypeDef *SDMMCx, uint32_t EndAdd);
  869. uint32_t SDMMC_CmdErase(SDMMC_TypeDef *SDMMCx);
  870. uint32_t SDMMC_CmdStopTransfer(SDMMC_TypeDef *SDMMCx);
  871. uint32_t SDMMC_CmdSelDesel(SDMMC_TypeDef *SDMMCx, uint64_t Addr);
  872. uint32_t SDMMC_CmdGoIdleState(SDMMC_TypeDef *SDMMCx);
  873. uint32_t SDMMC_CmdOperCond(SDMMC_TypeDef *SDMMCx);
  874. uint32_t SDMMC_CmdAppCommand(SDMMC_TypeDef *SDMMCx, uint32_t Argument);
  875. uint32_t SDMMC_CmdAppOperCommand(SDMMC_TypeDef *SDMMCx, uint32_t SdType);
  876. uint32_t SDMMC_CmdBusWidth(SDMMC_TypeDef *SDMMCx, uint32_t BusWidth);
  877. uint32_t SDMMC_CmdSendSCR(SDMMC_TypeDef *SDMMCx);
  878. uint32_t SDMMC_CmdSendCID(SDMMC_TypeDef *SDMMCx);
  879. uint32_t SDMMC_CmdSendCSD(SDMMC_TypeDef *SDMMCx, uint32_t Argument);
  880. uint32_t SDMMC_CmdSetRelAdd(SDMMC_TypeDef *SDMMCx, uint16_t *pRCA);
  881. uint32_t SDMMC_CmdSendStatus(SDMMC_TypeDef *SDMMCx, uint32_t Argument);
  882. uint32_t SDMMC_CmdStatusRegister(SDMMC_TypeDef *SDMMCx);
  883. uint32_t SDMMC_CmdOpCondition(SDMMC_TypeDef *SDMMCx, uint32_t Argument);
  884. uint32_t SDMMC_CmdSwitch(SDMMC_TypeDef *SDMMCx, uint32_t Argument);
  885. /**
  886. * @}
  887. */
  888. /**
  889. * @}
  890. */
  891. /**
  892. * @}
  893. */
  894. /**
  895. * @}
  896. */
  897. #ifdef __cplusplus
  898. }
  899. #endif
  900. #endif /* __STM32F7xx_LL_SDMMC_H */
  901. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/