stm32l4xx_ll_sdmmc.h 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_sdmmc.h
  4. * @author MCD Application Team
  5. * @brief Header file of low layer 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 __STM32L4xx_LL_SDMMC_H
  37. #define __STM32L4xx_LL_SDMMC_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. #if defined(SDMMC1)
  42. /* Includes ------------------------------------------------------------------*/
  43. #include "stm32l4xx_hal_def.h"
  44. /** @addtogroup STM32L4xx_Driver
  45. * @{
  46. */
  47. /** @addtogroup SDMMC_LL
  48. * @{
  49. */
  50. /* Exported types ------------------------------------------------------------*/
  51. /** @defgroup SDMMC_LL_Exported_Types SDMMC_LL Exported Types
  52. * @{
  53. */
  54. /**
  55. * @brief SDMMC Configuration Structure definition
  56. */
  57. typedef struct
  58. {
  59. uint32_t ClockEdge; /*!< Specifies the clock transition on which the bit capture is made.
  60. This parameter can be a value of @ref SDMMC_LL_Clock_Edge */
  61. #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx)
  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. #endif /* !STM32L4R5xx && !STM32L4R7xx && !STM32L4R9xx && !STM32L4S5xx && !STM32L4S7xx && !STM32L4S9xx */
  66. uint32_t ClockPowerSave; /*!< Specifies whether SDMMC Clock output is enabled or
  67. disabled when the bus is idle.
  68. This parameter can be a value of @ref SDMMC_LL_Clock_Power_Save */
  69. uint32_t BusWide; /*!< Specifies the SDMMC bus width.
  70. This parameter can be a value of @ref SDMMC_LL_Bus_Wide */
  71. uint32_t HardwareFlowControl; /*!< Specifies whether the SDMMC hardware flow control is enabled or disabled.
  72. This parameter can be a value of @ref SDMMC_LL_Hardware_Flow_Control */
  73. uint32_t ClockDiv; /*!< Specifies the clock frequency of the SDMMC controller.
  74. This parameter can be a value between Min_Data = 0 and Max_Data = 255 */
  75. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  76. uint32_t Transceiver; /*!< Specifies whether external Transceiver is enabled or disabled.
  77. This parameter can be a value of @ref SDMMC_LL_Transceiver */
  78. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  79. }SDMMC_InitTypeDef;
  80. /**
  81. * @brief SDMMC Command Control structure
  82. */
  83. typedef struct
  84. {
  85. uint32_t Argument; /*!< Specifies the SDMMC command argument which is sent
  86. to a card as part of a command message. If a command
  87. contains an argument, it must be loaded into this register
  88. before writing the command to the command register. */
  89. uint32_t CmdIndex; /*!< Specifies the SDMMC command index. It must be Min_Data = 0 and
  90. Max_Data = 64 */
  91. uint32_t Response; /*!< Specifies the SDMMC response type.
  92. This parameter can be a value of @ref SDMMC_LL_Response_Type */
  93. uint32_t WaitForInterrupt; /*!< Specifies whether SDMMC wait for interrupt request is
  94. enabled or disabled.
  95. This parameter can be a value of @ref SDMMC_LL_Wait_Interrupt_State */
  96. uint32_t CPSM; /*!< Specifies whether SDMMC Command path state machine (CPSM)
  97. is enabled or disabled.
  98. This parameter can be a value of @ref SDMMC_LL_CPSM_State */
  99. }SDMMC_CmdInitTypeDef;
  100. /**
  101. * @brief SDMMC Data Control structure
  102. */
  103. typedef struct
  104. {
  105. uint32_t DataTimeOut; /*!< Specifies the data timeout period in card bus clock periods. */
  106. uint32_t DataLength; /*!< Specifies the number of data bytes to be transferred. */
  107. uint32_t DataBlockSize; /*!< Specifies the data block size for block transfer.
  108. This parameter can be a value of @ref SDMMC_LL_Data_Block_Size */
  109. uint32_t TransferDir; /*!< Specifies the data transfer direction, whether the transfer
  110. is a read or write.
  111. This parameter can be a value of @ref SDMMC_LL_Transfer_Direction */
  112. uint32_t TransferMode; /*!< Specifies whether data transfer is in stream or block mode.
  113. This parameter can be a value of @ref SDMMC_LL_Transfer_Type */
  114. uint32_t DPSM; /*!< Specifies whether SDMMC Data path state machine (DPSM)
  115. is enabled or disabled.
  116. This parameter can be a value of @ref SDMMC_LL_DPSM_State */
  117. }SDMMC_DataInitTypeDef;
  118. /**
  119. * @}
  120. */
  121. /* Exported constants --------------------------------------------------------*/
  122. /** @defgroup SDMMC_LL_Exported_Constants SDMMC_LL Exported Constants
  123. * @{
  124. */
  125. #define SDMMC_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
  126. #define SDMMC_ERROR_CMD_CRC_FAIL ((uint32_t)0x00000001U) /*!< Command response received (but CRC check failed) */
  127. #define SDMMC_ERROR_DATA_CRC_FAIL ((uint32_t)0x00000002U) /*!< Data block sent/received (CRC check failed) */
  128. #define SDMMC_ERROR_CMD_RSP_TIMEOUT ((uint32_t)0x00000004U) /*!< Command response timeout */
  129. #define SDMMC_ERROR_DATA_TIMEOUT ((uint32_t)0x00000008U) /*!< Data timeout */
  130. #define SDMMC_ERROR_TX_UNDERRUN ((uint32_t)0x00000010U) /*!< Transmit FIFO underrun */
  131. #define SDMMC_ERROR_RX_OVERRUN ((uint32_t)0x00000020U) /*!< Receive FIFO overrun */
  132. #define SDMMC_ERROR_ADDR_MISALIGNED ((uint32_t)0x00000040U) /*!< Misaligned address */
  133. #define SDMMC_ERROR_BLOCK_LEN_ERR ((uint32_t)0x00000080U) /*!< Transferred block length is not allowed for the card or the
  134. number of transferred bytes does not match the block length */
  135. #define SDMMC_ERROR_ERASE_SEQ_ERR ((uint32_t)0x00000100U) /*!< An error in the sequence of erase command occurs */
  136. #define SDMMC_ERROR_BAD_ERASE_PARAM ((uint32_t)0x00000200U) /*!< An invalid selection for erase groups */
  137. #define SDMMC_ERROR_WRITE_PROT_VIOLATION ((uint32_t)0x00000400U) /*!< Attempt to program a write protect block */
  138. #define SDMMC_ERROR_LOCK_UNLOCK_FAILED ((uint32_t)0x00000800U) /*!< Sequence or password error has been detected in unlock
  139. command or if there was an attempt to access a locked card */
  140. #define SDMMC_ERROR_COM_CRC_FAILED ((uint32_t)0x00001000U) /*!< CRC check of the previous command failed */
  141. #define SDMMC_ERROR_ILLEGAL_CMD ((uint32_t)0x00002000U) /*!< Command is not legal for the card state */
  142. #define SDMMC_ERROR_CARD_ECC_FAILED ((uint32_t)0x00004000U) /*!< Card internal ECC was applied but failed to correct the data */
  143. #define SDMMC_ERROR_CC_ERR ((uint32_t)0x00008000U) /*!< Internal card controller error */
  144. #define SDMMC_ERROR_GENERAL_UNKNOWN_ERR ((uint32_t)0x00010000U) /*!< General or unknown error */
  145. #define SDMMC_ERROR_STREAM_READ_UNDERRUN ((uint32_t)0x00020000U) /*!< The card could not sustain data reading in stream rmode */
  146. #define SDMMC_ERROR_STREAM_WRITE_OVERRUN ((uint32_t)0x00040000U) /*!< The card could not sustain data programming in stream mode */
  147. #define SDMMC_ERROR_CID_CSD_OVERWRITE ((uint32_t)0x00080000U) /*!< CID/CSD overwrite error */
  148. #define SDMMC_ERROR_WP_ERASE_SKIP ((uint32_t)0x00100000U) /*!< Only partial address space was erased */
  149. #define SDMMC_ERROR_CARD_ECC_DISABLED ((uint32_t)0x00200000U) /*!< Command has been executed without using internal ECC */
  150. #define SDMMC_ERROR_ERASE_RESET ((uint32_t)0x00400000U) /*!< Erase sequence was cleared before executing because an out
  151. of erase sequence command was received */
  152. #define SDMMC_ERROR_AKE_SEQ_ERR ((uint32_t)0x00800000U) /*!< Error in sequence of authentication */
  153. #define SDMMC_ERROR_INVALID_VOLTRANGE ((uint32_t)0x01000000U) /*!< Error in case of invalid voltage range */
  154. #define SDMMC_ERROR_ADDR_OUT_OF_RANGE ((uint32_t)0x02000000U) /*!< Error when addressed block is out of range */
  155. #define SDMMC_ERROR_REQUEST_NOT_APPLICABLE ((uint32_t)0x04000000U) /*!< Error when command request is not applicable */
  156. #define SDMMC_ERROR_INVALID_PARAMETER ((uint32_t)0x08000000U) /*!< the used parameter is not valid */
  157. #define SDMMC_ERROR_UNSUPPORTED_FEATURE ((uint32_t)0x10000000U) /*!< Error when feature is not insupported */
  158. #define SDMMC_ERROR_BUSY ((uint32_t)0x20000000U) /*!< Error when transfer process is busy */
  159. #define SDMMC_ERROR_DMA ((uint32_t)0x40000000U) /*!< Error while DMA transfer */
  160. #define SDMMC_ERROR_TIMEOUT ((uint32_t)0x80000000U) /*!< Timeout error */
  161. /**
  162. * @brief SDMMC Commands Index
  163. */
  164. #define SDMMC_CMD_GO_IDLE_STATE ((uint8_t)0U) /*!< Resets the SD memory card. */
  165. #define SDMMC_CMD_SEND_OP_COND ((uint8_t)1U) /*!< Sends host capacity support information and activates the card's initialization process. */
  166. #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. */
  167. #define SDMMC_CMD_SET_REL_ADDR ((uint8_t)3U) /*!< Asks the card to publish a new relative address (RCA). */
  168. #define SDMMC_CMD_SET_DSR ((uint8_t)4U) /*!< Programs the DSR of all cards. */
  169. #define SDMMC_CMD_SDMMC_SEN_OP_COND ((uint8_t)5U) /*!< Sends host capacity support information (HCS) and asks the accessed card to send its
  170. operating condition register (OCR) content in the response on the CMD line. */
  171. #define SDMMC_CMD_HS_SWITCH ((uint8_t)6U) /*!< Checks switchable function (mode 0) and switch card function (mode 1). */
  172. #define SDMMC_CMD_SEL_DESEL_CARD ((uint8_t)7U) /*!< Selects the card by its own relative address and gets deselected by any other address */
  173. #define SDMMC_CMD_HS_SEND_EXT_CSD ((uint8_t)8U) /*!< Sends SD Memory Card interface condition, which includes host supply voltage information
  174. and asks the card whether card supports voltage. */
  175. #define SDMMC_CMD_SEND_CSD ((uint8_t)9U) /*!< Addressed card sends its card specific data (CSD) on the CMD line. */
  176. #define SDMMC_CMD_SEND_CID ((uint8_t)10U) /*!< Addressed card sends its card identification (CID) on the CMD line. */
  177. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  178. #define SDMMC_CMD_VOLTAGE_SWITCH ((uint8_t)11U) /*!< SD card Voltage switch to 1.8V mode. */
  179. #else
  180. #define SDMMC_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11U) /*!< SD card doesn't support it. */
  181. #endif
  182. #define SDMMC_CMD_STOP_TRANSMISSION ((uint8_t)12U) /*!< Forces the card to stop transmission. */
  183. #define SDMMC_CMD_SEND_STATUS ((uint8_t)13U) /*!< Addressed card sends its status register. */
  184. #define SDMMC_CMD_HS_BUSTEST_READ ((uint8_t)14U) /*!< Reserved */
  185. #define SDMMC_CMD_GO_INACTIVE_STATE ((uint8_t)15U) /*!< Sends an addressed card into the inactive state. */
  186. #define SDMMC_CMD_SET_BLOCKLEN ((uint8_t)16U) /*!< Sets the block length (in bytes for SDSC) for all following block commands
  187. (read, write, lock). Default block length is fixed to 512 Bytes. Not effective
  188. for SDHS and SDXC. */
  189. #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
  190. fixed 512 bytes in case of SDHC and SDXC. */
  191. #define SDMMC_CMD_READ_MULT_BLOCK ((uint8_t)18U) /*!< Continuously transfers data blocks from card to host until interrupted by
  192. STOP_TRANSMISSION command. */
  193. #define SDMMC_CMD_HS_BUSTEST_WRITE ((uint8_t)19U) /*!< 64 bytes tuning pattern is sent for SDR50 and SDR104. */
  194. #define SDMMC_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20U) /*!< Speed class control command. */
  195. #define SDMMC_CMD_SET_BLOCK_COUNT ((uint8_t)23U) /*!< Specify block count for CMD18 and CMD25. */
  196. #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
  197. fixed 512 bytes in case of SDHC and SDXC. */
  198. #define SDMMC_CMD_WRITE_MULT_BLOCK ((uint8_t)25U) /*!< Continuously writes blocks of data until a STOP_TRANSMISSION follows. */
  199. #define SDMMC_CMD_PROG_CID ((uint8_t)26U) /*!< Reserved for manufacturers. */
  200. #define SDMMC_CMD_PROG_CSD ((uint8_t)27U) /*!< Programming of the programmable bits of the CSD. */
  201. #define SDMMC_CMD_SET_WRITE_PROT ((uint8_t)28U) /*!< Sets the write protection bit of the addressed group. */
  202. #define SDMMC_CMD_CLR_WRITE_PROT ((uint8_t)29U) /*!< Clears the write protection bit of the addressed group. */
  203. #define SDMMC_CMD_SEND_WRITE_PROT ((uint8_t)30U) /*!< Asks the card to send the status of the write protection bits. */
  204. #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). */
  205. #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. */
  206. #define SDMMC_CMD_ERASE_GRP_START ((uint8_t)35U) /*!< Sets the address of the first write block to be erased. Reserved for each command
  207. system set by switch function command (CMD6). */
  208. #define SDMMC_CMD_ERASE_GRP_END ((uint8_t)36U) /*!< Sets the address of the last write block of the continuous range to be erased.
  209. Reserved for each command system set by switch function command (CMD6). */
  210. #define SDMMC_CMD_ERASE ((uint8_t)38U) /*!< Reserved for SD security applications. */
  211. #define SDMMC_CMD_FAST_IO ((uint8_t)39U) /*!< SD card doesn't support it (Reserved). */
  212. #define SDMMC_CMD_GO_IRQ_STATE ((uint8_t)40U) /*!< SD card doesn't support it (Reserved). */
  213. #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
  214. the SET_BLOCK_LEN command. */
  215. #define SDMMC_CMD_APP_CMD ((uint8_t)55U) /*!< Indicates to the card that the next command is an application specific command rather
  216. than a standard command. */
  217. #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
  218. for general purpose/application specific commands. */
  219. #define SDMMC_CMD_NO_CMD ((uint8_t)64U) /*!< No command */
  220. /**
  221. * @brief Following commands are SD Card Specific commands.
  222. * SDMMC_APP_CMD should be sent before sending these commands.
  223. */
  224. #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
  225. widths are given in SCR register. */
  226. #define SDMMC_CMD_SD_APP_STATUS ((uint8_t)13U) /*!< (ACMD13) Sends the SD status. */
  227. #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
  228. 32bit+CRC data block. */
  229. #define SDMMC_CMD_SD_APP_OP_COND ((uint8_t)41U) /*!< (ACMD41) Sends host capacity support information (HCS) and asks the accessed card to
  230. send its operating condition register (OCR) content in the response on the CMD line. */
  231. #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 */
  232. #define SDMMC_CMD_SD_APP_SEND_SCR ((uint8_t)51U) /*!< Reads the SD Configuration Register (SCR). */
  233. #define SDMMC_CMD_SDMMC_RW_DIRECT ((uint8_t)52U) /*!< For SD I/O card only, reserved for security specification. */
  234. #define SDMMC_CMD_SDMMC_RW_EXTENDED ((uint8_t)53U) /*!< For SD I/O card only, reserved for security specification. */
  235. /**
  236. * @brief Following commands are SD Card Specific security commands.
  237. * SDMMC_CMD_APP_CMD should be sent before sending these commands.
  238. */
  239. #define SDMMC_CMD_SD_APP_GET_MKB ((uint8_t)43U)
  240. #define SDMMC_CMD_SD_APP_GET_MID ((uint8_t)44U)
  241. #define SDMMC_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45U)
  242. #define SDMMC_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46U)
  243. #define SDMMC_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47U)
  244. #define SDMMC_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48U)
  245. #define SDMMC_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18U)
  246. #define SDMMC_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25U)
  247. #define SDMMC_CMD_SD_APP_SECURE_ERASE ((uint8_t)38U)
  248. #define SDMMC_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49U)
  249. #define SDMMC_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48U)
  250. /**
  251. * @brief Masks for errors Card Status R1 (OCR Register)
  252. */
  253. #define SDMMC_OCR_ADDR_OUT_OF_RANGE ((uint32_t)0x80000000U)
  254. #define SDMMC_OCR_ADDR_MISALIGNED ((uint32_t)0x40000000U)
  255. #define SDMMC_OCR_BLOCK_LEN_ERR ((uint32_t)0x20000000U)
  256. #define SDMMC_OCR_ERASE_SEQ_ERR ((uint32_t)0x10000000U)
  257. #define SDMMC_OCR_BAD_ERASE_PARAM ((uint32_t)0x08000000U)
  258. #define SDMMC_OCR_WRITE_PROT_VIOLATION ((uint32_t)0x04000000U)
  259. #define SDMMC_OCR_LOCK_UNLOCK_FAILED ((uint32_t)0x01000000U)
  260. #define SDMMC_OCR_COM_CRC_FAILED ((uint32_t)0x00800000U)
  261. #define SDMMC_OCR_ILLEGAL_CMD ((uint32_t)0x00400000U)
  262. #define SDMMC_OCR_CARD_ECC_FAILED ((uint32_t)0x00200000U)
  263. #define SDMMC_OCR_CC_ERROR ((uint32_t)0x00100000U)
  264. #define SDMMC_OCR_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00080000U)
  265. #define SDMMC_OCR_STREAM_READ_UNDERRUN ((uint32_t)0x00040000U)
  266. #define SDMMC_OCR_STREAM_WRITE_OVERRUN ((uint32_t)0x00020000U)
  267. #define SDMMC_OCR_CID_CSD_OVERWRITE ((uint32_t)0x00010000U)
  268. #define SDMMC_OCR_WP_ERASE_SKIP ((uint32_t)0x00008000U)
  269. #define SDMMC_OCR_CARD_ECC_DISABLED ((uint32_t)0x00004000U)
  270. #define SDMMC_OCR_ERASE_RESET ((uint32_t)0x00002000U)
  271. #define SDMMC_OCR_AKE_SEQ_ERROR ((uint32_t)0x00000008U)
  272. #define SDMMC_OCR_ERRORBITS ((uint32_t)0xFDFFE008U)
  273. /**
  274. * @brief Masks for R6 Response
  275. */
  276. #define SDMMC_R6_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00002000U)
  277. #define SDMMC_R6_ILLEGAL_CMD ((uint32_t)0x00004000U)
  278. #define SDMMC_R6_COM_CRC_FAILED ((uint32_t)0x00008000U)
  279. #define SDMMC_VOLTAGE_WINDOW_SD ((uint32_t)0x80100000U)
  280. #define SDMMC_HIGH_CAPACITY ((uint32_t)0x40000000U)
  281. #define SDMMC_STD_CAPACITY ((uint32_t)0x00000000U)
  282. #define SDMMC_CHECK_PATTERN ((uint32_t)0x000001AAU)
  283. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  284. #define SD_SWITCH_1_8V_CAPACITY ((uint32_t)0x01000000U)
  285. #define SDMMC_SDR50_SWITCH_PATTERN ((uint32_t)0x80FF1F02U)
  286. #define SDMMC_SDR25_SWITCH_PATTERN ((uint32_t)0x80FFFF01U)
  287. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  288. #define SDMMC_MAX_VOLT_TRIAL ((uint32_t)0x0000FFFFU)
  289. #define SDMMC_MAX_TRIAL ((uint32_t)0x0000FFFFU)
  290. #define SDMMC_ALLZERO ((uint32_t)0x00000000U)
  291. #define SDMMC_WIDE_BUS_SUPPORT ((uint32_t)0x00040000U)
  292. #define SDMMC_SINGLE_BUS_SUPPORT ((uint32_t)0x00010000U)
  293. #define SDMMC_CARD_LOCKED ((uint32_t)0x02000000U)
  294. #define SDMMC_DATATIMEOUT ((uint32_t)0xFFFFFFFFU)
  295. #define SDMMC_0TO7BITS ((uint32_t)0x000000FFU)
  296. #define SDMMC_8TO15BITS ((uint32_t)0x0000FF00U)
  297. #define SDMMC_16TO23BITS ((uint32_t)0x00FF0000U)
  298. #define SDMMC_24TO31BITS ((uint32_t)0xFF000000U)
  299. #define SDMMC_MAX_DATA_LENGTH ((uint32_t)0x01FFFFFFU)
  300. #define SDMMC_HALFFIFO ((uint32_t)0x00000008U)
  301. #define SDMMC_HALFFIFOBYTES ((uint32_t)0x00000020U)
  302. /**
  303. * @brief Command Class supported
  304. */
  305. #define SDMMC_CCCC_ERASE ((uint32_t)0x00000020U)
  306. #define SDMMC_CMDTIMEOUT ((uint32_t)5000U) /* Command send and response timeout */
  307. #define SDMMC_MAXERASETIMEOUT ((uint32_t)63000U) /* Max erase Timeout 63 s */
  308. #define SDMMC_STOPTRANSFERTIMEOUT ((uint32_t)100000000U) /* Timeout for STOP TRANSMISSION command */
  309. /** @defgroup SDMMC_LL_Clock_Edge Clock Edge
  310. * @{
  311. */
  312. #define SDMMC_CLOCK_EDGE_RISING ((uint32_t)0x00000000U)
  313. #define SDMMC_CLOCK_EDGE_FALLING SDMMC_CLKCR_NEGEDGE
  314. #define IS_SDMMC_CLOCK_EDGE(EDGE) (((EDGE) == SDMMC_CLOCK_EDGE_RISING) || \
  315. ((EDGE) == SDMMC_CLOCK_EDGE_FALLING))
  316. /**
  317. * @}
  318. */
  319. #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx)
  320. /** @defgroup SDMMC_LL_Clock_Bypass Clock Bypass
  321. * @{
  322. */
  323. #define SDMMC_CLOCK_BYPASS_DISABLE ((uint32_t)0x00000000U)
  324. #define SDMMC_CLOCK_BYPASS_ENABLE SDMMC_CLKCR_BYPASS
  325. #define IS_SDMMC_CLOCK_BYPASS(BYPASS) (((BYPASS) == SDMMC_CLOCK_BYPASS_DISABLE) || \
  326. ((BYPASS) == SDMMC_CLOCK_BYPASS_ENABLE))
  327. /**
  328. * @}
  329. */
  330. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  331. /** @defgroup SDMMC_LL_Clock_Power_Save Clock Power Saving
  332. * @{
  333. */
  334. #define SDMMC_CLOCK_POWER_SAVE_DISABLE ((uint32_t)0x00000000U)
  335. #define SDMMC_CLOCK_POWER_SAVE_ENABLE SDMMC_CLKCR_PWRSAV
  336. #define IS_SDMMC_CLOCK_POWER_SAVE(SAVE) (((SAVE) == SDMMC_CLOCK_POWER_SAVE_DISABLE) || \
  337. ((SAVE) == SDMMC_CLOCK_POWER_SAVE_ENABLE))
  338. /**
  339. * @}
  340. */
  341. /** @defgroup SDMMC_LL_Bus_Wide Bus Width
  342. * @{
  343. */
  344. #define SDMMC_BUS_WIDE_1B ((uint32_t)0x00000000U)
  345. #define SDMMC_BUS_WIDE_4B SDMMC_CLKCR_WIDBUS_0
  346. #define SDMMC_BUS_WIDE_8B SDMMC_CLKCR_WIDBUS_1
  347. #define IS_SDMMC_BUS_WIDE(WIDE) (((WIDE) == SDMMC_BUS_WIDE_1B) || \
  348. ((WIDE) == SDMMC_BUS_WIDE_4B) || \
  349. ((WIDE) == SDMMC_BUS_WIDE_8B))
  350. /**
  351. * @}
  352. */
  353. /** @defgroup SDMMC_LL_Hardware_Flow_Control Hardware Flow Control
  354. * @{
  355. */
  356. #define SDMMC_HARDWARE_FLOW_CONTROL_DISABLE ((uint32_t)0x00000000U)
  357. #define SDMMC_HARDWARE_FLOW_CONTROL_ENABLE SDMMC_CLKCR_HWFC_EN
  358. #define IS_SDMMC_HARDWARE_FLOW_CONTROL(CONTROL) (((CONTROL) == SDMMC_HARDWARE_FLOW_CONTROL_DISABLE) || \
  359. ((CONTROL) == SDMMC_HARDWARE_FLOW_CONTROL_ENABLE))
  360. /**
  361. * @}
  362. */
  363. /** @defgroup SDMMC_LL_Clock_Division Clock Division
  364. * @{
  365. */
  366. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  367. /* SDMMC_CK frequency = SDMMCCLK / [2 * CLKDIV] */
  368. #define IS_SDMMC_CLKDIV(DIV) ((DIV) < 0x400)
  369. #else
  370. #define IS_SDMMC_CLKDIV(DIV) ((DIV) <= 0xFF)
  371. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  372. /**
  373. * @}
  374. */
  375. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  376. /** @defgroup SDMMC_LL_Transceiver Transceiver
  377. * @{
  378. */
  379. #define SDMMC_TRANSCEIVER_DISABLE ((uint32_t)0x00000000U)
  380. #define SDMMC_TRANSCEIVER_ENABLE ((uint32_t)0x00000001U)
  381. #define IS_SDMMC_TRANSCEIVER(MODE) (((MODE) == SDMMC_TRANSCEIVER_DISABLE) || \
  382. ((MODE) == SDMMC_TRANSCEIVER_ENABLE))
  383. /**
  384. * @}
  385. */
  386. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  387. /** @defgroup SDMMC_LL_Command_Index Command Index
  388. * @{
  389. */
  390. #define IS_SDMMC_CMD_INDEX(INDEX) ((INDEX) < 0x40)
  391. /**
  392. * @}
  393. */
  394. /** @defgroup SDMMC_LL_Response_Type Response Type
  395. * @{
  396. */
  397. #define SDMMC_RESPONSE_NO ((uint32_t)0x00000000U)
  398. #define SDMMC_RESPONSE_SHORT SDMMC_CMD_WAITRESP_0
  399. #define SDMMC_RESPONSE_LONG SDMMC_CMD_WAITRESP
  400. #define IS_SDMMC_RESPONSE(RESPONSE) (((RESPONSE) == SDMMC_RESPONSE_NO) || \
  401. ((RESPONSE) == SDMMC_RESPONSE_SHORT) || \
  402. ((RESPONSE) == SDMMC_RESPONSE_LONG))
  403. /**
  404. * @}
  405. */
  406. /** @defgroup SDMMC_LL_Wait_Interrupt_State Wait Interrupt
  407. * @{
  408. */
  409. #define SDMMC_WAIT_NO ((uint32_t)0x00000000U)
  410. #define SDMMC_WAIT_IT SDMMC_CMD_WAITINT
  411. #define SDMMC_WAIT_PEND SDMMC_CMD_WAITPEND
  412. #define IS_SDMMC_WAIT(WAIT) (((WAIT) == SDMMC_WAIT_NO) || \
  413. ((WAIT) == SDMMC_WAIT_IT) || \
  414. ((WAIT) == SDMMC_WAIT_PEND))
  415. /**
  416. * @}
  417. */
  418. /** @defgroup SDMMC_LL_CPSM_State CPSM State
  419. * @{
  420. */
  421. #define SDMMC_CPSM_DISABLE ((uint32_t)0x00000000U)
  422. #define SDMMC_CPSM_ENABLE SDMMC_CMD_CPSMEN
  423. #define IS_SDMMC_CPSM(CPSM) (((CPSM) == SDMMC_CPSM_DISABLE) || \
  424. ((CPSM) == SDMMC_CPSM_ENABLE))
  425. /**
  426. * @}
  427. */
  428. /** @defgroup SDMMC_LL_Response_Registers Response Register
  429. * @{
  430. */
  431. #define SDMMC_RESP1 ((uint32_t)0x00000000U)
  432. #define SDMMC_RESP2 ((uint32_t)0x00000004U)
  433. #define SDMMC_RESP3 ((uint32_t)0x00000008U)
  434. #define SDMMC_RESP4 ((uint32_t)0x0000000CU)
  435. #define IS_SDMMC_RESP(RESP) (((RESP) == SDMMC_RESP1) || \
  436. ((RESP) == SDMMC_RESP2) || \
  437. ((RESP) == SDMMC_RESP3) || \
  438. ((RESP) == SDMMC_RESP4))
  439. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  440. /** @defgroup SDMMC_Internal_DMA_Mode SDMMC Internal DMA Mode
  441. * @{
  442. */
  443. #define SDMMC_DISABLE_IDMA ((uint32_t)0x00000000)
  444. #define SDMMC_ENABLE_IDMA_SINGLE_BUFF (SDMMC_IDMA_IDMAEN)
  445. #define SDMMC_ENABLE_IDMA_DOUBLE_BUFF0 (SDMMC_IDMA_IDMAEN | SDMMC_IDMA_IDMABMODE)
  446. #define SDMMC_ENABLE_IDMA_DOUBLE_BUFF1 (SDMMC_IDMA_IDMAEN | SDMMC_IDMA_IDMABMODE | SDMMC_IDMA_IDMABACT)
  447. /**
  448. * @}
  449. */
  450. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  451. /**
  452. * @}
  453. */
  454. /** @defgroup SDMMC_LL_Data_Length Data Lenght
  455. * @{
  456. */
  457. #define IS_SDMMC_DATA_LENGTH(LENGTH) ((LENGTH) <= 0x01FFFFFF)
  458. /**
  459. * @}
  460. */
  461. /** @defgroup SDMMC_LL_Data_Block_Size Data Block Size
  462. * @{
  463. */
  464. #define SDMMC_DATABLOCK_SIZE_1B ((uint32_t)0x00000000U)
  465. #define SDMMC_DATABLOCK_SIZE_2B SDMMC_DCTRL_DBLOCKSIZE_0
  466. #define SDMMC_DATABLOCK_SIZE_4B SDMMC_DCTRL_DBLOCKSIZE_1
  467. #define SDMMC_DATABLOCK_SIZE_8B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1)
  468. #define SDMMC_DATABLOCK_SIZE_16B SDMMC_DCTRL_DBLOCKSIZE_2
  469. #define SDMMC_DATABLOCK_SIZE_32B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_2)
  470. #define SDMMC_DATABLOCK_SIZE_64B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2)
  471. #define SDMMC_DATABLOCK_SIZE_128B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2)
  472. #define SDMMC_DATABLOCK_SIZE_256B SDMMC_DCTRL_DBLOCKSIZE_3
  473. #define SDMMC_DATABLOCK_SIZE_512B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_3)
  474. #define SDMMC_DATABLOCK_SIZE_1024B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_3)
  475. #define SDMMC_DATABLOCK_SIZE_2048B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_3)
  476. #define SDMMC_DATABLOCK_SIZE_4096B (SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3)
  477. #define SDMMC_DATABLOCK_SIZE_8192B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3)
  478. #define SDMMC_DATABLOCK_SIZE_16384B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3)
  479. #define IS_SDMMC_BLOCK_SIZE(SIZE) (((SIZE) == SDMMC_DATABLOCK_SIZE_1B) || \
  480. ((SIZE) == SDMMC_DATABLOCK_SIZE_2B) || \
  481. ((SIZE) == SDMMC_DATABLOCK_SIZE_4B) || \
  482. ((SIZE) == SDMMC_DATABLOCK_SIZE_8B) || \
  483. ((SIZE) == SDMMC_DATABLOCK_SIZE_16B) || \
  484. ((SIZE) == SDMMC_DATABLOCK_SIZE_32B) || \
  485. ((SIZE) == SDMMC_DATABLOCK_SIZE_64B) || \
  486. ((SIZE) == SDMMC_DATABLOCK_SIZE_128B) || \
  487. ((SIZE) == SDMMC_DATABLOCK_SIZE_256B) || \
  488. ((SIZE) == SDMMC_DATABLOCK_SIZE_512B) || \
  489. ((SIZE) == SDMMC_DATABLOCK_SIZE_1024B) || \
  490. ((SIZE) == SDMMC_DATABLOCK_SIZE_2048B) || \
  491. ((SIZE) == SDMMC_DATABLOCK_SIZE_4096B) || \
  492. ((SIZE) == SDMMC_DATABLOCK_SIZE_8192B) || \
  493. ((SIZE) == SDMMC_DATABLOCK_SIZE_16384B))
  494. /**
  495. * @}
  496. */
  497. /** @defgroup SDMMC_LL_Transfer_Direction Transfer Direction
  498. * @{
  499. */
  500. #define SDMMC_TRANSFER_DIR_TO_CARD ((uint32_t)0x00000000U)
  501. #define SDMMC_TRANSFER_DIR_TO_SDMMC SDMMC_DCTRL_DTDIR
  502. #define IS_SDMMC_TRANSFER_DIR(DIR) (((DIR) == SDMMC_TRANSFER_DIR_TO_CARD) || \
  503. ((DIR) == SDMMC_TRANSFER_DIR_TO_SDMMC))
  504. /**
  505. * @}
  506. */
  507. /** @defgroup SDMMC_LL_Transfer_Type Transfer Type
  508. * @{
  509. */
  510. #define SDMMC_TRANSFER_MODE_BLOCK ((uint32_t)0x00000000U)
  511. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  512. #define SDMMC_TRANSFER_MODE_STREAM SDMMC_DCTRL_DTMODE_1
  513. #else
  514. #define SDMMC_TRANSFER_MODE_STREAM SDMMC_DCTRL_DTMODE
  515. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  516. #define IS_SDMMC_TRANSFER_MODE(MODE) (((MODE) == SDMMC_TRANSFER_MODE_BLOCK) || \
  517. ((MODE) == SDMMC_TRANSFER_MODE_STREAM))
  518. /**
  519. * @}
  520. */
  521. /** @defgroup SDMMC_LL_DPSM_State DPSM State
  522. * @{
  523. */
  524. #define SDMMC_DPSM_DISABLE ((uint32_t)0x00000000U)
  525. #define SDMMC_DPSM_ENABLE SDMMC_DCTRL_DTEN
  526. #define IS_SDMMC_DPSM(DPSM) (((DPSM) == SDMMC_DPSM_DISABLE) ||\
  527. ((DPSM) == SDMMC_DPSM_ENABLE))
  528. /**
  529. * @}
  530. */
  531. /** @defgroup SDMMC_LL_Read_Wait_Mode Read Wait Mode
  532. * @{
  533. */
  534. #define SDMMC_READ_WAIT_MODE_DATA2 ((uint32_t)0x00000000U)
  535. #define SDMMC_READ_WAIT_MODE_CLK (SDMMC_DCTRL_RWMOD)
  536. #define IS_SDMMC_READWAIT_MODE(MODE) (((MODE) == SDMMC_READ_WAIT_MODE_CLK) || \
  537. ((MODE) == SDMMC_READ_WAIT_MODE_DATA2))
  538. /**
  539. * @}
  540. */
  541. /** @defgroup SDMMC_LL_Interrupt_sources Interrupt Sources
  542. * @{
  543. */
  544. #define SDMMC_IT_CCRCFAIL SDMMC_MASK_CCRCFAILIE
  545. #define SDMMC_IT_DCRCFAIL SDMMC_MASK_DCRCFAILIE
  546. #define SDMMC_IT_CTIMEOUT SDMMC_MASK_CTIMEOUTIE
  547. #define SDMMC_IT_DTIMEOUT SDMMC_MASK_DTIMEOUTIE
  548. #define SDMMC_IT_TXUNDERR SDMMC_MASK_TXUNDERRIE
  549. #define SDMMC_IT_RXOVERR SDMMC_MASK_RXOVERRIE
  550. #define SDMMC_IT_CMDREND SDMMC_MASK_CMDRENDIE
  551. #define SDMMC_IT_CMDSENT SDMMC_MASK_CMDSENTIE
  552. #define SDMMC_IT_DATAEND SDMMC_MASK_DATAENDIE
  553. #define SDMMC_IT_DBCKEND SDMMC_MASK_DBCKENDIE
  554. #define SDMMC_IT_TXFIFOHE SDMMC_MASK_TXFIFOHEIE
  555. #define SDMMC_IT_RXFIFOHF SDMMC_MASK_RXFIFOHFIE
  556. #define SDMMC_IT_RXFIFOF SDMMC_MASK_RXFIFOFIE
  557. #define SDMMC_IT_TXFIFOE SDMMC_MASK_TXFIFOEIE
  558. #define SDMMC_IT_SDIOIT SDMMC_MASK_SDIOITIE
  559. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  560. #define SDMMC_IT_DHOLD SDMMC_MASK_DHOLDIE
  561. #define SDMMC_IT_DABORT SDMMC_MASK_DABORTIE
  562. #define SDMMC_IT_BUSYD0END SDMMC_MASK_BUSYD0ENDIE
  563. #define SDMMC_IT_ACKFAIL SDMMC_MASK_ACKFAILIE
  564. #define SDMMC_IT_ACKTIMEOUT SDMMC_MASK_ACKTIMEOUTIE
  565. #define SDMMC_IT_VSWEND SDMMC_MASK_VSWENDIE
  566. #define SDMMC_IT_CKSTOP SDMMC_MASK_CKSTOPIE
  567. #define SDMMC_IT_IDMABTC SDMMC_MASK_IDMABTCIE
  568. #else
  569. #define SDMMC_IT_CMDACT SDMMC_MASK_CMDACTIE
  570. #define SDMMC_IT_TXACT SDMMC_MASK_TXACTIE
  571. #define SDMMC_IT_RXACT SDMMC_MASK_RXACTIE
  572. #define SDMMC_IT_TXFIFOF SDMMC_MASK_TXFIFOFIE
  573. #define SDMMC_IT_RXFIFOE SDMMC_MASK_RXFIFOEIE
  574. #define SDMMC_IT_TXDAVL SDMMC_MASK_TXDAVLIE
  575. #define SDMMC_IT_RXDAVL SDMMC_MASK_RXDAVLIE
  576. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  577. /**
  578. * @}
  579. */
  580. /** @defgroup SDMMC_LL_Flags Flags
  581. * @{
  582. */
  583. #define SDMMC_FLAG_CCRCFAIL SDMMC_STA_CCRCFAIL
  584. #define SDMMC_FLAG_DCRCFAIL SDMMC_STA_DCRCFAIL
  585. #define SDMMC_FLAG_CTIMEOUT SDMMC_STA_CTIMEOUT
  586. #define SDMMC_FLAG_DTIMEOUT SDMMC_STA_DTIMEOUT
  587. #define SDMMC_FLAG_TXUNDERR SDMMC_STA_TXUNDERR
  588. #define SDMMC_FLAG_RXOVERR SDMMC_STA_RXOVERR
  589. #define SDMMC_FLAG_CMDREND SDMMC_STA_CMDREND
  590. #define SDMMC_FLAG_CMDSENT SDMMC_STA_CMDSENT
  591. #define SDMMC_FLAG_DATAEND SDMMC_STA_DATAEND
  592. #define SDMMC_FLAG_DBCKEND SDMMC_STA_DBCKEND
  593. #define SDMMC_FLAG_TXFIFOHE SDMMC_STA_TXFIFOHE
  594. #define SDMMC_FLAG_RXFIFOHF SDMMC_STA_RXFIFOHF
  595. #define SDMMC_FLAG_TXFIFOF SDMMC_STA_TXFIFOF
  596. #define SDMMC_FLAG_RXFIFOF SDMMC_STA_RXFIFOF
  597. #define SDMMC_FLAG_TXFIFOE SDMMC_STA_TXFIFOE
  598. #define SDMMC_FLAG_RXFIFOE SDMMC_STA_RXFIFOE
  599. #define SDMMC_FLAG_SDIOIT SDMMC_STA_SDIOIT
  600. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  601. #define SDMMC_FLAG_DHOLD SDMMC_STA_DHOLD
  602. #define SDMMC_FLAG_DABORT SDMMC_STA_DABORT
  603. #define SDMMC_FLAG_DPSMACT SDMMC_STA_DPSMACT
  604. #define SDMMC_FLAG_CMDACT SDMMC_STA_CPSMACT
  605. #define SDMMC_FLAG_BUSYD0 SDMMC_STA_BUSYD0
  606. #define SDMMC_FLAG_BUSYD0END SDMMC_STA_BUSYD0END
  607. #define SDMMC_FLAG_ACKFAIL SDMMC_STA_ACKFAIL
  608. #define SDMMC_FLAG_ACKTIMEOUT SDMMC_STA_ACKTIMEOUT
  609. #define SDMMC_FLAG_VSWEND SDMMC_STA_VSWEND
  610. #define SDMMC_FLAG_CKSTOP SDMMC_STA_CKSTOP
  611. #define SDMMC_FLAG_IDMATE SDMMC_STA_IDMATE
  612. #define SDMMC_FLAG_IDMABTC SDMMC_STA_IDMABTC
  613. #else
  614. #define SDMMC_FLAG_CMDACT SDMMC_STA_CMDACT
  615. #define SDMMC_FLAG_TXACT SDMMC_STA_TXACT
  616. #define SDMMC_FLAG_RXACT SDMMC_STA_RXACT
  617. #define SDMMC_FLAG_TXDAVL SDMMC_STA_TXDAVL
  618. #define SDMMC_FLAG_RXDAVL SDMMC_STA_RXDAVL
  619. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  620. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  621. #define SDMMC_STATIC_FLAGS ((uint32_t)(SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_CTIMEOUT |\
  622. SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_TXUNDERR | SDMMC_FLAG_RXOVERR |\
  623. SDMMC_FLAG_CMDREND | SDMMC_FLAG_CMDSENT | SDMMC_FLAG_DATAEND |\
  624. SDMMC_FLAG_DHOLD | SDMMC_FLAG_DBCKEND | SDMMC_FLAG_DABORT |\
  625. SDMMC_FLAG_BUSYD0END | SDMMC_FLAG_SDIOIT | SDMMC_FLAG_ACKFAIL |\
  626. SDMMC_FLAG_ACKTIMEOUT | SDMMC_FLAG_VSWEND | SDMMC_FLAG_CKSTOP |\
  627. SDMMC_FLAG_IDMATE | SDMMC_FLAG_IDMABTC))
  628. #define SDMMC_STATIC_CMD_FLAGS ((uint32_t)(SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CTIMEOUT | SDMMC_FLAG_CMDREND |\
  629. SDMMC_FLAG_CMDSENT | SDMMC_FLAG_BUSYD0END))
  630. #define SDMMC_STATIC_DATA_FLAGS ((uint32_t)(SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_TXUNDERR |\
  631. SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DATAEND | SDMMC_FLAG_DHOLD |\
  632. SDMMC_FLAG_DBCKEND | SDMMC_FLAG_DABORT | SDMMC_FLAG_IDMATE |\
  633. SDMMC_FLAG_IDMABTC))
  634. #else
  635. #define SDMMC_STATIC_FLAGS ((uint32_t)(SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_CTIMEOUT |\
  636. SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_TXUNDERR | SDMMC_FLAG_RXOVERR |\
  637. SDMMC_FLAG_CMDREND | SDMMC_FLAG_CMDSENT | SDMMC_FLAG_DATAEND |\
  638. SDMMC_FLAG_DBCKEND | SDMMC_FLAG_SDIOIT))
  639. #define SDMMC_STATIC_CMD_FLAGS ((uint32_t)(SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CTIMEOUT | SDMMC_FLAG_CMDREND |\
  640. SDMMC_FLAG_CMDSENT))
  641. #define SDMMC_STATIC_DATA_FLAGS ((uint32_t)(SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_TXUNDERR |\
  642. SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DATAEND | SDMMC_FLAG_DBCKEND))
  643. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  644. /**
  645. * @}
  646. */
  647. /**
  648. * @}
  649. */
  650. /* Exported macro ------------------------------------------------------------*/
  651. /** @defgroup SDMMC_LL_Exported_macros SDMMC_LL Exported Macros
  652. * @{
  653. */
  654. /** @defgroup SDMMC_LL_Register Bits And Addresses Definitions
  655. * @brief SDMMC_LL registers bit address in the alias region
  656. * @{
  657. */
  658. /* ---------------------- SDMMC registers bit mask --------------------------- */
  659. /* --- CLKCR Register ---*/
  660. /* CLKCR register clear mask */
  661. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  662. #define CLKCR_CLEAR_MASK ((uint32_t)(SDMMC_CLKCR_CLKDIV | SDMMC_CLKCR_PWRSAV |\
  663. SDMMC_CLKCR_WIDBUS |\
  664. SDMMC_CLKCR_NEGEDGE | SDMMC_CLKCR_HWFC_EN))
  665. #else
  666. #define CLKCR_CLEAR_MASK ((uint32_t)(SDMMC_CLKCR_CLKDIV | SDMMC_CLKCR_PWRSAV |\
  667. SDMMC_CLKCR_BYPASS | SDMMC_CLKCR_WIDBUS |\
  668. SDMMC_CLKCR_NEGEDGE | SDMMC_CLKCR_HWFC_EN))
  669. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  670. /* --- DCTRL Register ---*/
  671. /* SDMMC DCTRL Clear Mask */
  672. #define DCTRL_CLEAR_MASK ((uint32_t)(SDMMC_DCTRL_DTEN | SDMMC_DCTRL_DTDIR |\
  673. SDMMC_DCTRL_DTMODE | SDMMC_DCTRL_DBLOCKSIZE))
  674. /* --- CMD Register ---*/
  675. /* CMD Register clear mask */
  676. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  677. #define CMD_CLEAR_MASK ((uint32_t)(SDMMC_CMD_CMDINDEX | SDMMC_CMD_WAITRESP |\
  678. SDMMC_CMD_WAITINT | SDMMC_CMD_WAITPEND |\
  679. SDMMC_CMD_CPSMEN | SDMMC_CMD_CMDSUSPEND))
  680. #else
  681. #define CMD_CLEAR_MASK ((uint32_t)(SDMMC_CMD_CMDINDEX | SDMMC_CMD_WAITRESP |\
  682. SDMMC_CMD_WAITINT | SDMMC_CMD_WAITPEND |\
  683. SDMMC_CMD_CPSMEN | SDMMC_CMD_SDIOSUSPEND))
  684. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  685. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  686. /* SDMMC Initialization Frequency (400KHz max) */
  687. #define SDMMC_INIT_CLK_DIV ((uint8_t)0x3C) /* 48MHz / (SDMMC_INIT_CLK_DIV * 2) < 400KHz */
  688. /* SDMMC Data Transfer Frequency (25MHz max) */
  689. #define SDMMC_TRANSFER_CLK_DIV ((uint8_t)0x1) /* 48MHz / (SDMMC_TRANSFER_CLK_DIV * 2) < 25MHz */
  690. #else
  691. /* SDMMC Initialization Frequency (400KHz max) */
  692. #define SDMMC_INIT_CLK_DIV ((uint8_t)0x76) /* 48MHz / (SDMMC_INIT_CLK_DIV + 2) < 400KHz */
  693. /* SDMMC Data Transfer Frequency (25MHz max) */
  694. #define SDMMC_TRANSFER_CLK_DIV ((uint8_t)0x0) /* 48MHz / (SDMMC_TRANSFER_CLK_DIV + 2) < 25MHz */
  695. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  696. /**
  697. * @}
  698. */
  699. /** @defgroup SDMMC_LL_Interrupt_Clock Interrupt And Clock Configuration
  700. * @brief macros to handle interrupts and specific clock configurations
  701. * @{
  702. */
  703. #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx)
  704. /**
  705. * @brief Enable the SDMMC device.
  706. * @param __INSTANCE__: SDMMC Instance
  707. * @retval None
  708. */
  709. #define __SDMMC_ENABLE(__INSTANCE__) ((__INSTANCE__)->CLKCR |= SDMMC_CLKCR_CLKEN)
  710. /**
  711. * @brief Disable the SDMMC device.
  712. * @param __INSTANCE__: SDMMC Instance
  713. * @retval None
  714. */
  715. #define __SDMMC_DISABLE(__INSTANCE__) ((__INSTANCE__)->CLKCR &= ~SDMMC_CLKCR_CLKEN)
  716. /**
  717. * @brief Enable the SDMMC DMA transfer.
  718. * @param __INSTANCE__: SDMMC Instance
  719. * @retval None
  720. */
  721. #define __SDMMC_DMA_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_DMAEN)
  722. /**
  723. * @brief Disable the SDMMC DMA transfer.
  724. * @param __INSTANCE__: SDMMC Instance
  725. * @retval None
  726. */
  727. #define __SDMMC_DMA_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_DMAEN)
  728. #endif /* !STM32L4R5xx && !STM32L4R7xx && !STM32L4R9xx && !STM32L4S5xx && !STM32L4S7xx && !STM32L4S9xx */
  729. /**
  730. * @brief Enable the SDMMC device interrupt.
  731. * @param __INSTANCE__: Pointer to SDMMC register base
  732. * @param __INTERRUPT__: specifies the SDMMC interrupt sources to be enabled.
  733. * This parameter can be one or a combination of the following values:
  734. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  735. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  736. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  737. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  738. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  739. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  740. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  741. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  742. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  743. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  744. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  745. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  746. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  747. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  748. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  749. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  750. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  751. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  752. * @arg SDMMC_IT_DHOLD: Data transfer Hold interrupt
  753. * @arg SDMMC_IT_DABORT: Data transfer aborted by CMD12 interrupt
  754. * @arg SDMMC_IT_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected interrupt
  755. * @arg SDMMC_IT_ACKFAIL: Boot Acknowledgment received interrupt
  756. * @arg SDMMC_IT_ACKTIMEOUT: Boot Acknowledgment timeout interrupt
  757. * @arg SDMMC_IT_VSWEND: Voltage switch critical timing section completion interrupt
  758. * @arg SDMMC_IT_CKSTOP: SDMMC_CK stopped in Voltage switch procedure interrupt
  759. * @arg SDMMC_IT_IDMABTC: IDMA buffer transfer complete interrupt
  760. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  761. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  762. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  763. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  764. * @retval None
  765. */
  766. #define __SDMMC_ENABLE_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->MASK |= (__INTERRUPT__))
  767. /**
  768. * @brief Disable the SDMMC device interrupt.
  769. * @param __INSTANCE__: Pointer to SDMMC register base
  770. * @param __INTERRUPT__: specifies the SDMMC interrupt sources to be disabled.
  771. * This parameter can be one or a combination of the following values:
  772. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  773. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  774. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  775. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  776. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  777. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  778. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  779. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  780. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  781. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  782. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  783. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  784. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  785. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  786. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  787. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  788. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  789. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  790. * @arg SDMMC_IT_DHOLD: Data transfer Hold interrupt
  791. * @arg SDMMC_IT_DABORT: Data transfer aborted by CMD12 interrupt
  792. * @arg SDMMC_IT_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected interrupt
  793. * @arg SDMMC_IT_ACKFAIL: Boot Acknowledgment received interrupt
  794. * @arg SDMMC_IT_ACKTIMEOUT: Boot Acknowledgment timeout interrupt
  795. * @arg SDMMC_IT_VSWEND: Voltage switch critical timing section completion interrupt
  796. * @arg SDMMC_IT_CKSTOP: SDMMC_CK stopped in Voltage switch procedure interrupt
  797. * @arg SDMMC_IT_IDMABTC: IDMA buffer transfer complete interrupt
  798. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  799. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  800. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  801. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  802. * @retval None
  803. */
  804. #define __SDMMC_DISABLE_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->MASK &= ~(__INTERRUPT__))
  805. /**
  806. * @brief Checks whether the specified SDMMC flag is set or not.
  807. * @param __INSTANCE__: Pointer to SDMMC register base
  808. * @param __FLAG__: specifies the flag to check.
  809. * This parameter can be one of the following values:
  810. * @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed)
  811. * @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  812. * @arg SDMMC_FLAG_CTIMEOUT: Command response timeout
  813. * @arg SDMMC_FLAG_DTIMEOUT: Data timeout
  814. * @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error
  815. * @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error
  816. * @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed)
  817. * @arg SDMMC_FLAG_CMDSENT: Command sent (no response required)
  818. * @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  819. * @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  820. * @arg SDMMC_FLAG_CMDACT: Command transfer in progress
  821. * @arg SDMMC_FLAG_TXFIFOHE: Transmit FIFO Half Empty
  822. * @arg SDMMC_FLAG_RXFIFOHF: Receive FIFO Half Full
  823. * @arg SDMMC_FLAG_TXFIFOF: Transmit FIFO full
  824. * @arg SDMMC_FLAG_RXFIFOF: Receive FIFO full
  825. * @arg SDMMC_FLAG_TXFIFOE: Transmit FIFO empty
  826. * @arg SDMMC_FLAG_RXFIFOE: Receive FIFO empty
  827. * @arg SDMMC_FLAG_SDIOIT: SD I/O interrupt received
  828. * @arg SDMMC_FLAG_DHOLD: Data transfer Hold
  829. * @arg SDMMC_FLAG_DABORT: Data transfer aborted by CMD12
  830. * @arg SDMMC_FLAG_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected
  831. * @arg SDMMC_FLAG_ACKFAIL: Boot Acknowledgment received
  832. * @arg SDMMC_FLAG_ACKTIMEOUT: Boot Acknowledgment timeout
  833. * @arg SDMMC_FLAG_VSWEND: Voltage switch critical timing section completion
  834. * @arg SDMMC_FLAG_CKSTOP: SDMMC_CK stopped in Voltage switch procedure
  835. * @arg SDMMC_FLAG_IDMATE: IDMA transfer error
  836. * @arg SDMMC_FLAG_IDMABTC: IDMA buffer transfer complete
  837. * @arg SDMMC_FLAG_TXACT: Data transmit in progress
  838. * @arg SDMMC_FLAG_RXACT: Data receive in progress
  839. * @arg SDMMC_FLAG_TXDAVL: Data available in transmit FIFO
  840. * @arg SDMMC_FLAG_RXDAVL: Data available in receive FIFO
  841. * @retval The new state of SDMMC_FLAG (SET or RESET).
  842. */
  843. #define __SDMMC_GET_FLAG(__INSTANCE__, __FLAG__) (((__INSTANCE__)->STA &(__FLAG__)) != RESET)
  844. /**
  845. * @brief Clears the SDMMC pending flags.
  846. * @param __INSTANCE__: Pointer to SDMMC register base
  847. * @param __FLAG__: specifies the flag to clear.
  848. * This parameter can be one or a combination of the following values:
  849. * @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed)
  850. * @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  851. * @arg SDMMC_FLAG_CTIMEOUT: Command response timeout
  852. * @arg SDMMC_FLAG_DTIMEOUT: Data timeout
  853. * @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error
  854. * @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error
  855. * @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed)
  856. * @arg SDMMC_FLAG_CMDSENT: Command sent (no response required)
  857. * @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  858. * @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  859. * @arg SDMMC_FLAG_SDIOIT: SD I/O interrupt received
  860. * @arg SDMMC_FLAG_DHOLD: Data transfer Hold
  861. * @arg SDMMC_FLAG_DABORT: Data transfer aborted by CMD12
  862. * @arg SDMMC_FLAG_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected
  863. * @arg SDMMC_FLAG_ACKFAIL: Boot Acknowledgment received
  864. * @arg SDMMC_FLAG_ACKTIMEOUT: Boot Acknowledgment timeout
  865. * @arg SDMMC_FLAG_VSWEND: Voltage switch critical timing section completion
  866. * @arg SDMMC_FLAG_CKSTOP: SDMMC_CK stopped in Voltage switch procedure
  867. * @arg SDMMC_FLAG_IDMATE: IDMA transfer error
  868. * @arg SDMMC_FLAG_IDMABTC: IDMA buffer transfer complete
  869. * @retval None
  870. */
  871. #define __SDMMC_CLEAR_FLAG(__INSTANCE__, __FLAG__) ((__INSTANCE__)->ICR = (__FLAG__))
  872. /**
  873. * @brief Checks whether the specified SDMMC interrupt has occurred or not.
  874. * @param __INSTANCE__: Pointer to SDMMC register base
  875. * @param __INTERRUPT__: specifies the SDMMC interrupt source to check.
  876. * This parameter can be one of the following values:
  877. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  878. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  879. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  880. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  881. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  882. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  883. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  884. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  885. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  886. * @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  887. * @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt
  888. * @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  889. * @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  890. * @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt
  891. * @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt
  892. * @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt
  893. * @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt
  894. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  895. * @arg SDMMC_IT_DHOLD: Data transfer Hold interrupt
  896. * @arg SDMMC_IT_DABORT: Data transfer aborted by CMD12 interrupt
  897. * @arg SDMMC_IT_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected interrupt
  898. * @arg SDMMC_IT_ACKFAIL: Boot Acknowledgment received interrupt
  899. * @arg SDMMC_IT_ACKTIMEOUT: Boot Acknowledgment timeout interrupt
  900. * @arg SDMMC_IT_VSWEND: Voltage switch critical timing section completion interrupt
  901. * @arg SDMMC_IT_CKSTOP: SDMMC_CK stopped in Voltage switch procedure interrupt
  902. * @arg SDMMC_IT_IDMABTC: IDMA buffer transfer complete interrupt
  903. * @arg SDMMC_IT_TXACT: Data transmit in progress interrupt
  904. * @arg SDMMC_IT_RXACT: Data receive in progress interrupt
  905. * @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt
  906. * @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt
  907. * @retval The new state of SDMMC_IT (SET or RESET).
  908. */
  909. #define __SDMMC_GET_IT(__INSTANCE__, __INTERRUPT__) (((__INSTANCE__)->STA &(__INTERRUPT__)) == (__INTERRUPT__))
  910. /**
  911. * @brief Clears the SDMMC's interrupt pending bits.
  912. * @param __INSTANCE__: Pointer to SDMMC register base
  913. * @param __INTERRUPT__: specifies the interrupt pending bit to clear.
  914. * This parameter can be one or a combination of the following values:
  915. * @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  916. * @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  917. * @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt
  918. * @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt
  919. * @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  920. * @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt
  921. * @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt
  922. * @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt
  923. * @arg SDMMC_IT_DATAEND: Data end (data counter, SDMMC_DCOUNT, is zero) interrupt
  924. * @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt
  925. * @arg SDMMC_IT_DHOLD: Data transfer Hold interrupt
  926. * @arg SDMMC_IT_DABORT: Data transfer aborted by CMD12 interrupt
  927. * @arg SDMMC_IT_BUSYD0END: End of SDMMC_D0 Busy following a CMD response detected interrupt
  928. * @arg SDMMC_IT_ACKFAIL: Boot Acknowledgment received interrupt
  929. * @arg SDMMC_IT_ACKTIMEOUT: Boot Acknowledgment timeout interrupt
  930. * @arg SDMMC_IT_VSWEND: Voltage switch critical timing section completion interrupt
  931. * @arg SDMMC_IT_CKSTOP: SDMMC_CK stopped in Voltage switch procedure interrupt
  932. * @arg SDMMC_IT_IDMABTC: IDMA buffer transfer complete interrupt
  933. * @retval None
  934. */
  935. #define __SDMMC_CLEAR_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->ICR = (__INTERRUPT__))
  936. /**
  937. * @brief Enable Start the SD I/O Read Wait operation.
  938. * @param __INSTANCE__: Pointer to SDMMC register base
  939. * @retval None
  940. */
  941. #define __SDMMC_START_READWAIT_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_RWSTART)
  942. /**
  943. * @brief Disable Start the SD I/O Read Wait operations.
  944. * @param __INSTANCE__: Pointer to SDMMC register base
  945. * @retval None
  946. */
  947. #define __SDMMC_START_READWAIT_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_RWSTART)
  948. /**
  949. * @brief Enable Start the SD I/O Read Wait operation.
  950. * @param __INSTANCE__: Pointer to SDMMC register base
  951. * @retval None
  952. */
  953. #define __SDMMC_STOP_READWAIT_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_RWSTOP)
  954. /**
  955. * @brief Disable Stop the SD I/O Read Wait operations.
  956. * @param __INSTANCE__: Pointer to SDMMC register base
  957. * @retval None
  958. */
  959. #define __SDMMC_STOP_READWAIT_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_RWSTOP)
  960. /**
  961. * @brief Enable the SD I/O Mode Operation.
  962. * @param __INSTANCE__: Pointer to SDMMC register base
  963. * @retval None
  964. */
  965. #define __SDMMC_OPERATION_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_SDIOEN)
  966. /**
  967. * @brief Disable the SD I/O Mode Operation.
  968. * @param __INSTANCE__: Pointer to SDMMC register base
  969. * @retval None
  970. */
  971. #define __SDMMC_OPERATION_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_SDIOEN)
  972. /**
  973. * @brief Enable the SD I/O Suspend command sending.
  974. * @param __INSTANCE__: Pointer to SDMMC register base
  975. * @retval None
  976. */
  977. #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx)
  978. #define __SDMMC_SUSPEND_CMD_ENABLE(__INSTANCE__) ((__INSTANCE__)->CMD |= SDMMC_CMD_SDIOSUSPEND)
  979. #else
  980. #define __SDMMC_SUSPEND_CMD_ENABLE(__INSTANCE__) ((__INSTANCE__)->CMD |= SDMMC_CMD_CMDSUSPEND)
  981. #endif /* !STM32L4R5xx && !STM32L4R7xx && !STM32L4R9xx && !STM32L4S5xx && !STM32L4S7xx && !STM32L4S9xx */
  982. /**
  983. * @brief Disable the SD I/O Suspend command sending.
  984. * @param __INSTANCE__: Pointer to SDMMC register base
  985. * @retval None
  986. */
  987. #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx)
  988. #define __SDMMC_SUSPEND_CMD_DISABLE(__INSTANCE__) ((__INSTANCE__)->CMD &= ~SDMMC_CMD_SDIOSUSPEND)
  989. #else
  990. #define __SDMMC_SUSPEND_CMD_DISABLE(__INSTANCE__) ((__INSTANCE__)->CMD &= ~SDMMC_CMD_CMDSUSPEND)
  991. #endif /* !STM32L4R5xx && !STM32L4R7xx && !STM32L4R9xx && !STM32L4S5xx && !STM32L4S7xx && !STM32L4S9xx */
  992. /**
  993. * @brief Enable the CMDTRANS mode.
  994. * @param __INSTANCE__ : Pointer to SDMMC register base
  995. * @retval None
  996. */
  997. #define __SDMMC_CMDTRANS_ENABLE(__INSTANCE__) ((__INSTANCE__)->CMD |= SDMMC_CMD_CMDTRANS)
  998. /**
  999. * @brief Disable the CMDTRANS mode.
  1000. * @param __INSTANCE__ : Pointer to SDMMC register base
  1001. * @retval None
  1002. */
  1003. #define __SDMMC_CMDTRANS_DISABLE(__INSTANCE__) ((__INSTANCE__)->CMD &= ~SDMMC_CMD_CMDTRANS)
  1004. /**
  1005. * @}
  1006. */
  1007. /**
  1008. * @}
  1009. */
  1010. /* Exported functions --------------------------------------------------------*/
  1011. /** @addtogroup SDMMC_LL_Exported_Functions
  1012. * @{
  1013. */
  1014. /* Initialization/de-initialization functions **********************************/
  1015. /** @addtogroup HAL_SDMMC_LL_Group1
  1016. * @{
  1017. */
  1018. HAL_StatusTypeDef SDMMC_Init(SDMMC_TypeDef *SDMMCx, SDMMC_InitTypeDef Init);
  1019. /**
  1020. * @}
  1021. */
  1022. /* I/O operation functions *****************************************************/
  1023. /** @addtogroup HAL_SDMMC_LL_Group2
  1024. * @{
  1025. */
  1026. uint32_t SDMMC_ReadFIFO(SDMMC_TypeDef *SDMMCx);
  1027. HAL_StatusTypeDef SDMMC_WriteFIFO(SDMMC_TypeDef *SDMMCx, uint32_t *pWriteData);
  1028. /**
  1029. * @}
  1030. */
  1031. /* Peripheral Control functions ************************************************/
  1032. /** @addtogroup HAL_SDMMC_LL_Group3
  1033. * @{
  1034. */
  1035. HAL_StatusTypeDef SDMMC_PowerState_ON(SDMMC_TypeDef *SDMMCx);
  1036. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  1037. HAL_StatusTypeDef SDMMC_PowerState_Cycle(SDMMC_TypeDef *SDMMCx);
  1038. #endif /* !STM32L4R5xx && !STM32L4R7xx && !STM32L4R9xx && !STM32L4S5xx && !STM32L4S7xx && !STM32L4S9xx */
  1039. HAL_StatusTypeDef SDMMC_PowerState_OFF(SDMMC_TypeDef *SDMMCx);
  1040. uint32_t SDMMC_GetPowerState(SDMMC_TypeDef *SDMMCx);
  1041. /* Command path state machine (CPSM) management functions */
  1042. HAL_StatusTypeDef SDMMC_SendCommand(SDMMC_TypeDef *SDMMCx, SDMMC_CmdInitTypeDef *Command);
  1043. uint8_t SDMMC_GetCommandResponse(SDMMC_TypeDef *SDMMCx);
  1044. uint32_t SDMMC_GetResponse(SDMMC_TypeDef *SDMMCx, uint32_t Response);
  1045. /* Data path state machine (DPSM) management functions */
  1046. HAL_StatusTypeDef SDMMC_ConfigData(SDMMC_TypeDef *SDMMCx, SDMMC_DataInitTypeDef* Data);
  1047. uint32_t SDMMC_GetDataCounter(SDMMC_TypeDef *SDMMCx);
  1048. uint32_t SDMMC_GetFIFOCount(SDMMC_TypeDef *SDMMCx);
  1049. /* SDMMC Cards mode management functions */
  1050. HAL_StatusTypeDef SDMMC_SetSDMMCReadWaitMode(SDMMC_TypeDef *SDMMCx, uint32_t SDMMC_ReadWaitMode);
  1051. /* SDMMC Commands management functions */
  1052. uint32_t SDMMC_CmdBlockLength(SDMMC_TypeDef *SDMMCx, uint32_t BlockSize);
  1053. uint32_t SDMMC_CmdReadSingleBlock(SDMMC_TypeDef *SDMMCx, uint32_t ReadAdd);
  1054. uint32_t SDMMC_CmdReadMultiBlock(SDMMC_TypeDef *SDMMCx, uint32_t ReadAdd);
  1055. uint32_t SDMMC_CmdWriteSingleBlock(SDMMC_TypeDef *SDMMCx, uint32_t WriteAdd);
  1056. uint32_t SDMMC_CmdWriteMultiBlock(SDMMC_TypeDef *SDMMCx, uint32_t WriteAdd);
  1057. uint32_t SDMMC_CmdEraseStartAdd(SDMMC_TypeDef *SDMMCx, uint32_t StartAdd);
  1058. uint32_t SDMMC_CmdSDEraseStartAdd(SDMMC_TypeDef *SDMMCx, uint32_t StartAdd);
  1059. uint32_t SDMMC_CmdEraseEndAdd(SDMMC_TypeDef *SDMMCx, uint32_t EndAdd);
  1060. uint32_t SDMMC_CmdSDEraseEndAdd(SDMMC_TypeDef *SDMMCx, uint32_t EndAdd);
  1061. uint32_t SDMMC_CmdErase(SDMMC_TypeDef *SDMMCx);
  1062. uint32_t SDMMC_CmdStopTransfer(SDMMC_TypeDef *SDMMCx);
  1063. uint32_t SDMMC_CmdSelDesel(SDMMC_TypeDef *SDMMCx, uint64_t Addr);
  1064. uint32_t SDMMC_CmdGoIdleState(SDMMC_TypeDef *SDMMCx);
  1065. uint32_t SDMMC_CmdOperCond(SDMMC_TypeDef *SDMMCx);
  1066. uint32_t SDMMC_CmdAppCommand(SDMMC_TypeDef *SDMMCx, uint32_t Argument);
  1067. uint32_t SDMMC_CmdAppOperCommand(SDMMC_TypeDef *SDMMCx, uint32_t Argument);
  1068. uint32_t SDMMC_CmdBusWidth(SDMMC_TypeDef *SDMMCx, uint32_t BusWidth);
  1069. uint32_t SDMMC_CmdSendSCR(SDMMC_TypeDef *SDMMCx);
  1070. uint32_t SDMMC_CmdSendCID(SDMMC_TypeDef *SDMMCx);
  1071. uint32_t SDMMC_CmdSendCSD(SDMMC_TypeDef *SDMMCx, uint32_t Argument);
  1072. uint32_t SDMMC_CmdSetRelAdd(SDMMC_TypeDef *SDMMCx, uint16_t *pRCA);
  1073. uint32_t SDMMC_CmdSendStatus(SDMMC_TypeDef *SDMMCx, uint32_t Argument);
  1074. uint32_t SDMMC_CmdStatusRegister(SDMMC_TypeDef *SDMMCx);
  1075. uint32_t SDMMC_CmdOpCondition(SDMMC_TypeDef *SDMMCx, uint32_t Argument);
  1076. uint32_t SDMMC_CmdSwitch(SDMMC_TypeDef *SDMMCx, uint32_t Argument);
  1077. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  1078. uint32_t SDMMC_CmdVoltageSwitch(SDMMC_TypeDef *SDMMCx);
  1079. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  1080. /**
  1081. * @}
  1082. */
  1083. /**
  1084. * @}
  1085. */
  1086. /**
  1087. * @}
  1088. */
  1089. /**
  1090. * @}
  1091. */
  1092. #endif /* SDMMC1 */
  1093. #ifdef __cplusplus
  1094. }
  1095. #endif
  1096. #endif /* __STM32L4xx_LL_SDMMC_H */
  1097. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/