hal_sdio.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// @file hal_gpio.h
  3. /// @author AE TEAM
  4. /// @brief THIS FILE CONTAINS ALL THE FUNCTIONS PROTOTYPES FOR THE GPIO
  5. /// FIRMWARE LIBRARY.
  6. ////////////////////////////////////////////////////////////////////////////////
  7. /// @attention
  8. ///
  9. /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
  10. /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
  11. /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
  12. /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
  13. /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
  14. /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
  15. ///
  16. /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // Define to prevent recursive inclusion
  19. #ifndef __HAL_SDIO_H
  20. #define __HAL_SDIO_H
  21. // Files includes
  22. #include "mm32_reg.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. ////////////////////////////////////////////////////////////////////////////////
  27. /// @addtogroup MM32_Hardware_Abstract_Layer
  28. /// @{
  29. ////////////////////////////////////////////////////////////////////////////////
  30. /// @defgroup GPIO_HAL
  31. /// @brief GPIO HAL modules
  32. /// @{
  33. ////////////////////////////////////////////////////////////////////////////////
  34. /// @defgroup GPIO_Exported_Types
  35. /// @{
  36. ////////////////////////////////////////////////////////////////////////////////
  37. /// @brief Output Maximum frequency selection
  38. ////////////////////////////////////////////////////////////////////////////////
  39. #define SDIO_FLAG_CCRCFAIL ((u32)0x00000001)
  40. #define SDIO_FLAG_DCRCFAIL ((u32)0x00000002)
  41. #define SDIO_FLAG_CTIMEOUT ((u32)0x00000004)
  42. #define SDIO_FLAG_DTIMEOUT ((u32)0x00000008)
  43. #define SDIO_FLAG_TXUNDERR ((u32)0x00000010)
  44. #define SDIO_FLAG_RXOVERR ((u32)0x00000020)
  45. #define SDIO_FLAG_CMDREND ((u32)0x00000040)
  46. #define SDIO_FLAG_CMDSENT ((u32)0x00000080)
  47. #define SDIO_FLAG_DATAEND ((u32)0x00000100)
  48. #define SDIO_FLAG_STBITERR ((u32)0x00000200)
  49. #define SDIO_FLAG_DBCKEND ((u32)0x00000400)
  50. #define SDIO_FLAG_CMDACT ((u32)0x00000800)
  51. #define SDIO_FLAG_TXACT ((u32)0x00001000)
  52. #define SDIO_FLAG_RXACT ((u32)0x00002000)
  53. #define SDIO_FLAG_TXFIFOHE ((u32)0x00004000)
  54. #define SDIO_FLAG_RXFIFOHF ((u32)0x00008000)
  55. #define SDIO_FLAG_TXFIFOF ((u32)0x00010000)
  56. #define SDIO_FLAG_RXFIFOF ((u32)0x00020000)
  57. #define SDIO_FLAG_TXFIFOE ((u32)0x00040000)
  58. #define SDIO_FLAG_RXFIFOE ((u32)0x00080000)
  59. #define SDIO_FLAG_TXDAVL ((u32)0x00100000)
  60. #define SDIO_FLAG_RXDAVL ((u32)0x00200000)
  61. #define SDIO_FLAG_SDIOIT ((u32)0x00400000)
  62. #define SDIO_FLAG_CEATAEND ((u32)0x00800000)
  63. ////////////////////////////////////////////////////////////////////////////////////////////////////
  64. //SDIO working mode define ,SDIO working mode definition, set through the SD_SetDevice Mode function.
  65. #define SD_POLLING_MODE 0 /// Query mode. In this mode, it is recommended to increase the setting of SDIO_TRANSFER_CLK_DIV if there are problems with reading and writing.
  66. #define SD_DMA_MODE 1 /// In DMA mode, it is recommended to increase the setting of SDIO_TRANSFER_CLK_DIV if there are problems with reading and writing.
  67. ////////////////////////////////////////////////////////////////////////////////
  68. /// @brief SDIO Various error enumeration definitions
  69. ////////////////////////////////////////////////////////////////////////////////
  70. typedef enum {
  71. SD_CMD_CRC_FAIL = 1, ///< Command response received (but CRC check failed)
  72. SD_DATA_CRC_FAIL, ///< Data bock sent/received (CRC check Failed)
  73. SD_CMD_RSP_TIMEOUT, ///< Command response timeout
  74. SD_DATA_TIMEOUT, ///< Data time out
  75. SD_TX_UNDERRUN, ///< Transmit FIFO under-run
  76. SD_RX_OVERRUN, ///< Receive FIFO over-run
  77. SD_START_BIT_ERR, ///< Start bit not detected on all data signals in widE bus mode
  78. SD_CMD_OUT_OF_RANGE, ///< CMD's argument was out of range.
  79. SD_ADDR_MISALIGNED, ///< Misaligned address
  80. SD_BLOCK_LEN_ERR, ///< Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length
  81. SD_ERASE_SEQ_ERR, ///< An error in the sequence of erase command occurs.
  82. SD_BAD_ERASE_PARAM, ///< An Invalid selection for erase groups
  83. SD_WRITE_PROT_VIOLATION, ///< Attempt to program a write protect block
  84. SD_LOCK_UNLOCK_FAILED, ///< Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card
  85. SD_COM_CRC_FAILED, ///< CRC check of the previous command failed
  86. SD_ILLEGAL_CMD, ///< Command is not legal for the card state
  87. SD_CARD_ECC_FAILED, ///< Card internal ECC was applied but failed to correct the data
  88. SD_CC_ERROR, ///< Internal card controller error
  89. SD_GENERAL_UNKNOWN_ERROR, ///< General or Unknown error
  90. SD_STREAM_READ_UNDERRUN, ///< The card could not sustain data transfer in stream read operation.
  91. SD_STREAM_WRITE_OVERRUN, ///< The card could not sustain data programming in stream mode
  92. SD_CID_CSD_OVERWRITE, ///< CID/CSD overwrite error
  93. SD_WP_ERASE_SKIP, ///< only partial address space was erased
  94. SD_CARD_ECC_DISABLED, ///< Command has been executed without using internal ECC
  95. SD_ERASE_RESET, ///< Erase sequence was cleared before executing because an out of erase sequence command was received
  96. SD_AKE_SEQ_ERROR, ///< Error in sequence of authentication.
  97. SD_INVALID_VOLTRANGE, ///< SD invalid voltage range,
  98. SD_ADDR_OUT_OF_RANGE, ///< SD addresses are out of range,
  99. SD_SWITCH_ERROR, ///< SD switch error,
  100. SD_SDIO_DISABLED, ///< SD SDIO disability,
  101. SD_SDIO_FUNCTION_BUSY, ///< SD SDIO function busy,
  102. SD_SDIO_FUNCTION_FAILED, ///< SD SDIO failed,
  103. SD_SDIO_UNKNOWN_FUNCTION, ///< SDIO unknown function,
  104. SD_INTERNAL_ERROR, ///< SD internal error,
  105. SD_NOT_CONFIGURED, ///< SD is not configured,
  106. SD_REQUEST_PENDING, ///< The SD request waits,
  107. SD_REQUEST_NOT_APPLICABLE, ///< The SD requirement does not apply,
  108. SD_INVALID_PARAMETER, ///< Invalid SD parameter,
  109. SD_UNSUPPORTED_FEATURE, ///< Features not supported by SD,
  110. SD_UNSUPPORTED_HW, ///< HW not supported by SD,
  111. SD_ERROR, ///< SD error
  112. SD_OK = 0 ///< SD OK
  113. } SD_Error;
  114. ////////////////////////////////////////////////////////////////////////////////
  115. /// @brief SD card CSD register data
  116. ////////////////////////////////////////////////////////////////////////////////
  117. typedef struct {
  118. u8 CSDStruct; ///< CSD structure
  119. u8 SysSpecVersion; ///< System specification version
  120. u8 Reserved1; ///< Reserved
  121. u8 TAAC; ///< Data read access-time 1
  122. u8 NSAC; ///< Data read access-time 2 in CLK cycles
  123. u8 MaxBusClkFrec; ///< Max. bus clock frequency
  124. u16 CardComdClasses; ///< Card command classes
  125. u8 RdBlockLen; ///< Max. read data block length
  126. u8 PartBlockRead; ///< Partial blocks for read allowed
  127. u8 WrBlockMisalign; ///< Write block misalignment
  128. u8 RdBlockMisalign; ///< Read block misalignment
  129. u8 DSRImpl; ///< DSR implemented
  130. u8 Reserved2; ///< Reserved
  131. u32 DeviceSize; ///< Device Size
  132. u8 MaxRdCurrentVDDMin; ///< Max. read current @ VDD min
  133. u8 MaxRdCurrentVDDMax; ///< Max. read current @ VDD max
  134. u8 MaxWrCurrentVDDMin; ///< Max. write current @ VDD min
  135. u8 MaxWrCurrentVDDMax; ///< Max. write current @ VDD max
  136. u8 DeviceSizeMul; ///< Device size multiplier
  137. u8 EraseGrSize; ///< Erase group size
  138. u8 EraseGrMul; ///< Erase group size multiplier
  139. u8 WrProtectGrSize; ///< Write protect group size
  140. u8 WrProtectGrEnable; ///< Write protect group enable
  141. u8 ManDeflECC; ///< Manufacturer default ECC
  142. u8 WrSpeedFact; ///< Write speed factor
  143. u8 MaxWrBlockLen; ///< Max. write data block length
  144. u8 WriteBlockPaPartial; ///< Partial blocks for write allowed
  145. u8 Reserved3; ///< Reserded
  146. u8 ContentProtectAppli; ///< Content protection application
  147. u8 FileFormatGrouop; ///< File format group
  148. u8 CopyFlag; ///< Copy flag (OTP)
  149. u8 PermWrProtect; ///< Permanent write protection
  150. u8 TempWrProtect; ///< Temporary write protection
  151. u8 FileFormat; ///< File Format
  152. u8 ECC; ///< ECC code
  153. u8 CSD_CRC; ///< CSD CRC
  154. u8 Reserved4; ///< always 1
  155. } SD_CSD;
  156. ////////////////////////////////////////////////////////////////////////////////
  157. /// @brief SD card CID register data
  158. ////////////////////////////////////////////////////////////////////////////////
  159. typedef struct {
  160. u8 ManufacturerID; ///< ManufacturerID
  161. u16 OEM_AppliID; ///< OEM/Application ID
  162. u32 ProdName1; ///< Product Name part1
  163. u8 ProdName2; ///< Product Name part2
  164. u8 ProdRev; ///< Product Revision
  165. u32 ProdSN; ///< Product Serial Number
  166. u8 Reserved1; ///< Reserved1
  167. u16 ManufactDate; ///< Manufacturing Date
  168. u8 CID_CRC; ///< CID CRC
  169. u8 Reserved2; ///< always 1
  170. } SD_CID;
  171. ////////////////////////////////////////////////////////////////////////////////
  172. /// @brief SD state
  173. ////////////////////////////////////////////////////////////////////////////////
  174. typedef enum {
  175. SD_CARD_READY = ((u32)0x00000001),
  176. SD_CARD_IDENTIFICATION = ((u32)0x00000002),
  177. SD_CARD_STANDBY = ((u32)0x00000003),
  178. SD_CARD_TRANSFER = ((u32)0x00000004),
  179. SD_CARD_SENDING = ((u32)0x00000005),
  180. SD_CARD_RECEIVING = ((u32)0x00000006),
  181. SD_CARD_PROGRAMMING = ((u32)0x00000007),
  182. SD_CARD_DISCONNECTED = ((u32)0x00000008),
  183. SD_CARD_ERROR = ((u32)0x000000FF)
  184. } SDCardState;
  185. ////////////////////////////////////////////////////////////////////////////////
  186. /// @brief SD message ,include CSD,CID data
  187. ////////////////////////////////////////////////////////////////////////////////
  188. typedef struct {
  189. SD_CSD SD_csd;
  190. SD_CID SD_cid;
  191. long long CardCapacity;
  192. u32 CardBlockSize;
  193. u16 RCA;
  194. u8 CardType;
  195. } SD_CardInfo;
  196. ////////////////////////////////////////////////////////////////////////////////
  197. /// @brief SDIO init
  198. ////////////////////////////////////////////////////////////////////////////////
  199. typedef struct {
  200. u8 SDIO_MDEN;
  201. u8 SDIO_DATWT;
  202. u8 SDIO_SelPTSM;
  203. u8 SDIO_CLKSP;
  204. u8 SDIO_OUTM;
  205. u8 SDIO_SelSM;
  206. u8 SDIO_OPMSel;
  207. } SDIO_InitTypeDef;
  208. typedef struct {
  209. u32 SDIO_Argument; ///Specifies the SDIO command argument which is sent
  210. ///to a card as part of a command message. If a command
  211. ///contains an argument, it must be loaded into this register
  212. ///before writing the command to the command register
  213. u32 SDIO_CmdIndex; ///Specifies the SDIO command index. It must be lower than 0x40.
  214. u32 SDIO_Response; ///Specifies the SDIO response type.
  215. ///This parameter can be a value of @ref SDIO_Response_Type
  216. u32 SDIO_Wait; ///Specifies whether SDIO wait-for-interrupt request is enabled or disabled.
  217. ///This parameter can be a value of @ref SDIO_Wait_Interrupt_State
  218. /// u32 SDIO_CPSM; ///Specifies whether SDIO Command path state machine (CPSM)
  219. ///is enabled or disabled.
  220. ///This parameter can be a value of @ref SDIO_CPSM_State
  221. } SDIO_CmdInitTypeDef;
  222. typedef struct {
  223. u32 SDIO_DataTimeOut; // < Specifies the data timeout period in card bus clock periods.
  224. //
  225. u32 SDIO_DataLength; // < Specifies the number of data bytes to be transferred.
  226. //
  227. u32 SDIO_DataBlockSize; // < Specifies the data block size for block transfer.
  228. // This parameter can be a value of @ref SDIO_Data_Block_Size
  229. //
  230. u32 SDIO_TransferDir; // < Specifies the data transfer direction, whether the transfer
  231. // is a read or write.
  232. // This parameter can be a value of @ref SDIO_Transfer_Direction
  233. //
  234. // u32 SDIO_TransferMode; // < Specifies whether data transfer is in stream or block mode.
  235. // // This parameter can be a value of @ref SDIO_Transfer_Type
  236. // //
  237. // u32 SDIO_DPSM; // < Specifies whether SDIO Data path state machine (DPSM)
  238. // // is enabled or disabled.
  239. // // This parameter can be a value of @ref SDIO_DPSM_State
  240. } SDIO_DataInitTypeDef;
  241. extern SD_CardInfo SDCardInfo;
  242. ////////////////////////////////////////////////////////////////////////////////
  243. /// @defgroup SDIO ָinstruction set
  244. /// @{
  245. #define SD_CMD_GO_IDLE_STATE ((u8)0)
  246. #define SD_CMD_SEND_OP_COND ((u8)1)
  247. #define SD_CMD_ALL_SEND_CID ((u8)2)
  248. #define SD_CMD_SET_REL_ADDR ((u8)3)
  249. #define SD_CMD_SET_DSR ((u8)4)
  250. #define SD_CMD_SDIO_SEN_OP_COND ((u8)5)
  251. #define SD_CMD_HS_SWITCH ((u8)6)
  252. #define SD_CMD_SEL_DESEL_CARD ((u8)7)
  253. #define SD_CMD_HS_SEND_EXT_CSD ((u8)8)
  254. #define SD_CMD_SEND_CSD ((u8)9)
  255. #define SD_CMD_SEND_CID ((u8)10)
  256. #define SD_CMD_READ_DAT_UNTIL_STOP ((u8)11)
  257. #define SD_CMD_STOP_TRANSMISSION ((u8)12)
  258. #define SD_CMD_SEND_STATUS ((u8)13)
  259. #define SD_CMD_HS_BUSTEST_READ ((u8)14)
  260. #define SD_CMD_GO_INACTIVE_STATE ((u8)15)
  261. #define SD_CMD_SET_BLOCKLEN ((u8)16)
  262. #define SD_CMD_READ_SINGLE_BLOCK ((u8)17)
  263. #define SD_CMD_READ_MULT_BLOCK ((u8)18)
  264. #define SD_CMD_HS_BUSTEST_WRITE ((u8)19)
  265. #define SD_CMD_WRITE_DAT_UNTIL_STOP ((u8)20)
  266. #define SD_CMD_SET_BLOCK_COUNT ((u8)23)
  267. #define SD_CMD_WRITE_SINGLE_BLOCK ((u8)24)
  268. #define SD_CMD_WRITE_MULT_BLOCK ((u8)25)
  269. #define SD_CMD_PROG_CID ((u8)26)
  270. #define SD_CMD_PROG_CSD ((u8)27)
  271. #define SD_CMD_SET_WRITE_PROT ((u8)28)
  272. #define SD_CMD_CLR_WRITE_PROT ((u8)29)
  273. #define SD_CMD_SEND_WRITE_PROT ((u8)30)
  274. #define SD_CMD_SD_ERASE_GRP_START ((u8)32)
  275. #define SD_CMD_SD_ERASE_GRP_END ((u8)33)
  276. #define SD_CMD_ERASE_GRP_START ((u8)35)
  277. #define SD_CMD_ERASE_GRP_END ((u8)36)
  278. #define SD_CMD_ERASE ((u8)38)
  279. #define SD_CMD_FAST_IO ((u8)39)
  280. #define SD_CMD_GO_IRQ_STATE ((u8)40)
  281. #define SD_CMD_LOCK_UNLOCK ((u8)42)
  282. #define SD_CMD_APP_CMD ((u8)55)
  283. #define SD_CMD_GEN_CMD ((u8)56)
  284. #define SD_CMD_NO_CMD ((u8)64)
  285. /// @}
  286. ////////////////////////////////////////////////////////////////////////////////
  287. /// @defgroup Following commands are SD Card Specific commands.
  288. /// @{
  289. #define SD_CMD_APP_SD_SET_BUSWIDTH ((u8)6)
  290. #define SD_CMD_SD_APP_STAUS ((u8)13)
  291. #define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((u8)22)
  292. #define SD_CMD_SD_APP_OP_COND ((u8)41)
  293. #define SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((u8)42)
  294. #define SD_CMD_SD_APP_SEND_SCR ((u8)51)
  295. #define SD_CMD_SDIO_RW_DIRECT ((u8)52)
  296. #define SD_CMD_SDIO_RW_EXTENDED ((u8)53)
  297. #define SD_CMD_SD_APP_GET_MKB ((u8)43)
  298. #define SD_CMD_SD_APP_GET_MID ((u8)44)
  299. #define SD_CMD_SD_APP_SET_CER_RN1 ((u8)45)
  300. #define SD_CMD_SD_APP_GET_CER_RN2 ((u8)46)
  301. #define SD_CMD_SD_APP_SET_CER_RES2 ((u8)47)
  302. #define SD_CMD_SD_APP_GET_CER_RES1 ((u8)48)
  303. #define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((u8)18)
  304. #define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((u8)25)
  305. #define SD_CMD_SD_APP_SECURE_ERASE ((u8)38)
  306. #define SD_CMD_SD_APP_CHANGE_SECURE_AREA ((u8)49)
  307. #define SD_CMD_SD_APP_SECURE_WRITE_MKB ((u8)48)
  308. /// @}
  309. ////////////////////////////////////////////////////////////////////////////////
  310. /// @defgroup SD support define.
  311. /// @{
  312. #define SDIO_STD_CAPACITY_SD_CARD_V1_1 ((u32)0x00000000)
  313. #define SDIO_STD_CAPACITY_SD_CARD_V2_0 ((u32)0x00000001)
  314. #define SDIO_HIGH_CAPACITY_SD_CARD ((u32)0x00000002)
  315. #define SDIO_MULTIMEDIA_CARD ((u32)0x00000003)
  316. #define SDIO_SECURE_DIGITAL_IO_CARD ((u32)0x00000004)
  317. #define SDIO_HIGH_SPEED_MULTIMEDIA_CARD ((u32)0x00000005)
  318. #define SDIO_SECURE_DIGITAL_IO_COMBO_CARD ((u32)0x00000006)
  319. #define SDIO_HIGH_CAPACITY_MMC_CARD ((u32)0x00000007)
  320. /// @}
  321. #ifndef NULL
  322. #define NULL 0
  323. #endif
  324. #define SDIO_STATIC_FLAGS ((u32)0x000005FF)
  325. #define SDIO_CMD0TIMEOUT ((u32)0x00010000)
  326. #define SDIO_DATATIMEOUT ((u32)0xFFFFFFFF)
  327. #define SDIO_FIFO_Address ((u32)0x40018080)
  328. ////////////////////////////////////////////////////////////////////////////////
  329. /// @defgroup Mask for errors Card Status R1 (OCR Register)
  330. /// @{
  331. #define SD_OCR_ADDR_OUT_OF_RANGE ((u32)0x80000000)
  332. #define SD_OCR_ADDR_MISALIGNED ((u32)0x40000000)
  333. #define SD_OCR_BLOCK_LEN_ERR ((u32)0x20000000)
  334. #define SD_OCR_ERASE_SEQ_ERR ((u32)0x10000000)
  335. #define SD_OCR_BAD_ERASE_PARAM ((u32)0x08000000)
  336. #define SD_OCR_WRITE_PROT_VIOLATION ((u32)0x04000000)
  337. #define SD_OCR_LOCK_UNLOCK_FAILED ((u32)0x01000000)
  338. #define SD_OCR_COM_CRC_FAILED ((u32)0x00800000)
  339. #define SD_OCR_ILLEGAL_CMD ((u32)0x00400000)
  340. #define SD_OCR_CARD_ECC_FAILED ((u32)0x00200000)
  341. #define SD_OCR_CC_ERROR ((u32)0x00100000)
  342. #define SD_OCR_GENERAL_UNKNOWN_ERROR ((u32)0x00080000)
  343. #define SD_OCR_STREAM_READ_UNDERRUN ((u32)0x00040000)
  344. #define SD_OCR_STREAM_WRITE_OVERRUN ((u32)0x00020000)
  345. #define SD_OCR_CID_CSD_OVERWRIETE ((u32)0x00010000)
  346. #define SD_OCR_WP_ERASE_SKIP ((u32)0x00008000)
  347. #define SD_OCR_CARD_ECC_DISABLED ((u32)0x00004000)
  348. #define SD_OCR_ERASE_RESET ((u32)0x00002000)
  349. #define SD_OCR_AKE_SEQ_ERROR ((u32)0x00000008)
  350. #define SD_OCR_ERRORBITS ((u32)0xFDFFE008)
  351. /// @}
  352. ////////////////////////////////////////////////////////////////////////////////
  353. /// @defgroup Masks for R6 Response
  354. /// @{
  355. #define SD_R6_GENERAL_UNKNOWN_ERROR ((u32)0x00002000)
  356. #define SD_R6_ILLEGAL_CMD ((u32)0x00004000)
  357. #define SD_R6_COM_CRC_FAILED ((u32)0x00008000)
  358. /// @}
  359. #define SD_VOLTAGE_WINDOW_SD ((u32)0x80100000)
  360. #define SD_HIGH_CAPACITY ((u32)0x40000000)
  361. #define SD_STD_CAPACITY ((u32)0x00000000)
  362. #define SD_CHECK_PATTERN ((u32)0x000001AA)
  363. #define SD_VOLTAGE_WINDOW_MMC ((u32)0x80FF8000)
  364. #define SD_MAX_VOLT_TRIAL ((u32)0x0000FFFF)
  365. #define SD_ALLZERO ((u32)0x00000000)
  366. #define SD_WIDE_BUS_SUPPORT ((u32)0x00040000)
  367. #define SD_SINGLE_BUS_SUPPORT ((u32)0x00010000)
  368. #define SD_CARD_LOCKED ((u32)0x02000000)
  369. #define SD_CARD_PROGRAMMING ((u32)0x00000007)
  370. #define SD_CARD_RECEIVING ((u32)0x00000006)
  371. #define SD_DATATIMEOUT ((u32)0xFFFFFFFF)
  372. #define SD_0TO7BITS ((u32)0x000000FF)
  373. #define SD_8TO15BITS ((u32)0x0000FF00)
  374. #define SD_16TO23BITS ((u32)0x00FF0000)
  375. #define SD_24TO31BITS ((u32)0xFF000000)
  376. #define SD_MAX_DATA_LENGTH ((u32)0x01FFFFFF)
  377. #define SD_HALFFIFO ((u32)0x00000008)
  378. #define SD_HALFFIFOBYTES ((u32)0x00000020)
  379. #define SD_CCCC_LOCK_UNLOCK ((u32)0x00000080)
  380. #define SD_CCCC_WRITE_PROT ((u32)0x00000040)
  381. #define SD_CCCC_ERASE ((u32)0x00000020)
  382. #define SDIO_SEND_IF_COND ((u32)0x00000008)
  383. #define SDIO_Response_No ((u32)0x00)
  384. #define SDIO_Response_Short ((u32)0x01)
  385. #define SDIO_Response_Long ((u32)0x03)
  386. #define SDIO_DataBlockSize_1b ((u32)0x00000000)
  387. #define SDIO_DataBlockSize_2b ((u32)0x00000001)
  388. #define SDIO_DataBlockSize_4b ((u32)0x00000002)
  389. #define SDIO_DataBlockSize_8b ((u32)0x00000003)
  390. #define SDIO_DataBlockSize_16b ((u32)0x00000004)
  391. #define SDIO_DataBlockSize_32b ((u32)0x00000005)
  392. #define SDIO_DataBlockSize_64b ((u32)0x00000006)
  393. #define SDIO_DataBlockSize_128b ((u32)0x00000007)
  394. #define SDIO_DataBlockSize_256b ((u32)0x00000008)
  395. #define SDIO_DataBlockSize_512b ((u32)0x00000009)
  396. #define SDIO_DataBlockSize_1024b ((u32)0x0000000A)
  397. #define SDIO_DataBlockSize_2048b ((u32)0x0000000B)
  398. #define SDIO_DataBlockSize_4096b ((u32)0x0000000C)
  399. #define SDIO_DataBlockSize_8192b ((u32)0x0000000D)
  400. #define SDIO_DataBlockSize_16384b ((u32)0x0000000E)
  401. //Define the data block length when the block data transfer mode is selected:
  402. //0000: (0 decimal) lock length = 2^0 = 1 byte
  403. //0001: (1 decimal) lock length = 2^1 = 2 bytes
  404. //0010: (2 decimal) lock length = 2^2 = 4 bytes
  405. //0011: (3 decimal) lock length = 2^3 = 8 bytes
  406. //0100: (4 decimal) lock length = 2^4 = 16 bytes
  407. //0101: (5 decimal) lock length = 2^5 = 32 bytes
  408. //0110: (6 decimal) lock length = 2^6 = 64 bytes
  409. //0111: (7 decimal) lock length = 2^7 = 128 bytes
  410. //1000: (8 decimal) lock length = 2^8 = 256 bytes
  411. //1001: (9 decimal) lock length = 2^9 = 512 bytes
  412. //1010: (10 decimal) lock length = 2^10 = 1024 bytes
  413. //1011: (11 decimal) lock length = 2^11 = 2048 bytes
  414. //1100: (12 decimal) lock length = 2^12 = 4096 bytes
  415. //1101: (13 decimal) lock length = 2^13 = 8192 bytes
  416. //1110: (14 decimal) lock length = 2^14 = 16384 bytes
  417. //1111: (15 decimal) reserved
  418. #define SDIO_TransferDir_ToCard ((u32)0x00000000)
  419. #define SDIO_TransferDir_ToSDIO ((u32)0x00000002)
  420. #define SDIO_Wait_No ((u32)0x00000000) // SDIO No Wait, TimeOut is enabled
  421. #define SDIO_Wait_IT ((u32)0x00000100) //SDIO Wait Interrupt Request
  422. #define SDIO_Wait_Pend ((u32)0x00000200) // SDIO Wait End of transfer
  423. ////////////////////////////////////////////////////////////////////////////////
  424. /// @defgroup I2C_Exported_Functions
  425. /// @{
  426. void SDIO_DeInit(void);
  427. void SDIO_StructInit(SDIO_InitTypeDef* SDIO_InitStruct);
  428. void SDIO_ClockSet(u32 value);
  429. void SDIO_Init(SDIO_InitTypeDef* SDIO_InitStruct);
  430. void SDIO_ITConfig(u32 SDIO_IT, FunctionalState state);
  431. void SDIO_CRCConfig(u32 SDIO_CRC, FunctionalState state);
  432. void SDIO_Clock_Set(u8 clkdiv);
  433. void SDIO_Send_Cmd(u8 cmdindex, u8 waitrsp, u32 arg);
  434. SD_Error SD_PowerOFF(void);
  435. SD_Error CmdError(void);
  436. SD_Error CmdResp2Error(void);
  437. SD_Error CmdResp3Error(void);
  438. SD_Error CmdResp6Error(u8 cmd, u16* prca);
  439. SD_Error CmdResp7Error(void);
  440. SD_Error CmdResp1Error(u8 cmd);
  441. void SDIO_Send_Data_Cfg(u32 datatimeout, u32 datalen, u8 blksize, u8 dir);
  442. void SDIO_ClearITPendingBit(u32 SDIO_IT);
  443. FlagStatus SDIO_GetFlagStatus(u32 SDIO_FLAG);
  444. u32 SDIO_GetTimeOutCounter(void);
  445. u32 SDIO_ReadData(void);
  446. void SDIO_WriteData(u32 tempbuff);
  447. void SDIO_DMACmd(FunctionalState state);
  448. /// @}
  449. #ifdef __cplusplus
  450. }
  451. #endif
  452. /// @}
  453. /// @}
  454. /// @}
  455. ////////////////////////////////////////////////////////////////////////////////
  456. #endif
  457. ////////////////////////////////////////////////////////////////////////////////