obj_sdmmc_sdcard.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. #ifndef __SDMMC_SDCARD_H
  2. #define __SDMMC_SDCARD_H
  3. #include "sys_type.h"
  4. //////////////////////////////////////////////////////////////////////////////////
  5. //本程序只供学习使用,未经作者许可,不得用于其它任何用途
  6. //ALIENTEK STM32H7开发板
  7. //SDMMC 驱动代码 (仅提供查询模式驱动代码)
  8. //正点原子@ALIENTEK
  9. //技术论坛:www.openedv.com
  10. //创建日期:2018/7/31
  11. //版本:V1.0
  12. //版权所有,盗版必究。
  13. //Copyright(C) 广州市星翼电子科技有限公司 2014-2024
  14. //All rights reserved
  15. //********************************************************************************
  16. //升级说明
  17. //无
  18. //////////////////////////////////////////////////////////////////////////////////
  19. //用户配置区
  20. //SDMMC时钟计算公式:SDMMC_CK时钟=sdmmc_ker_ck/[2*clkdiv];其中,sdmmc_ker_ck来自pll1_q_ck,为200Mhz
  21. //如果出现驱动错误,请尝试将SDMMC_TRANSFER_CLK_DIV频率降低
  22. //#define SDMMC_INIT_CLK_DIV 0xFA //SDMMC初始化频率,200M/(250*2)=400Khz,最大400Kh
  23. #define SDMMC_TRANSFER_CLK_DIV 0x04 //SDMMC传输频率,该值太小可能会导致读写文件出错
  24. //SD卡操作 各种错误枚举定义
  25. typedef enum
  26. {
  27. //特殊错误定义
  28. SD_CMD_CRC_FAIL = (1), /*!< Command response received (but CRC check failed) */
  29. SD_DATA_CRC_FAIL = (2), /*!< Data block sent/received (CRC check failed) */
  30. SD_CMD_RSP_TIMEOUT = (3), /*!< Command response timeout */
  31. SD_DATA_TIMEOUT = (4), /*!< Data timeout */
  32. SD_TX_UNDERRUN = (5), /*!< Transmit FIFO underrun */
  33. SD_RX_OVERRUN = (6), /*!< Receive FIFO overrun */
  34. SD_START_BIT_ERR = (7), /*!< Start bit not detected on all data signals in wide bus mode */
  35. SD_CMD_OUT_OF_RANGE = (8), /*!< Command's argument was out of range. */
  36. SD_ADDR_MISALIGNED = (9), /*!< Misaligned address */
  37. SD_BLOCK_LEN_ERR = (10), /*!< Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length */
  38. SD_ERASE_SEQ_ERR = (11), /*!< An error in the sequence of erase command occurs. */
  39. SD_BAD_ERASE_PARAM = (12), /*!< An invalid selection for erase groups */
  40. SD_WRITE_PROT_VIOLATION = (13), /*!< Attempt to program a write protect block */
  41. SD_LOCK_UNLOCK_FAILED = (14), /*!< Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
  42. SD_COM_CRC_FAILED = (15), /*!< CRC check of the previous command failed */
  43. SD_ILLEGAL_CMD = (16), /*!< Command is not legal for the card state */
  44. SD_CARD_ECC_FAILED = (17), /*!< Card internal ECC was applied but failed to correct the data */
  45. SD_CC_ERROR = (18), /*!< Internal card controller error */
  46. SD_GENERAL_UNKNOWN_ERROR = (19), /*!< General or unknown error */
  47. SD_STREAM_READ_UNDERRUN = (20), /*!< The card could not sustain data transfer in stream read operation. */
  48. SD_STREAM_WRITE_OVERRUN = (21), /*!< The card could not sustain data programming in stream mode */
  49. SD_CID_CSD_OVERWRITE = (22), /*!< CID/CSD overwrite error */
  50. SD_WP_ERASE_SKIP = (23), /*!< Only partial address space was erased */
  51. SD_CARD_ECC_DISABLED = (24), /*!< Command has been executed without using internal ECC */
  52. SD_ERASE_RESET = (25), /*!< Erase sequence was cleared before executing because an out of erase sequence command was received */
  53. SD_AKE_SEQ_ERROR = (26), /*!< Error in sequence of authentication. */
  54. SD_INVALID_VOLTRANGE = (27),
  55. SD_ADDR_OUT_OF_RANGE = (28),
  56. SD_SWITCH_ERROR = (29),
  57. SD_SDMMC_DISABLED = (30),
  58. SD_SDMMC_FUNCTION_BUSY = (31),
  59. SD_SDMMC_FUNCTION_FAILED = (32),
  60. SD_SDMMC_UNKNOWN_FUNCTION = (33),
  61. //标准错误定义
  62. SD_INTERNAL_ERROR = (34),
  63. SD_NOT_CONFIGURED = (35),
  64. SD_REQUEST_PENDING = (36),
  65. SD_REQUEST_NOT_APPLICABLE = (37),
  66. SD_INVALID_PARAMETER = (38),
  67. SD_UNSUPPORTED_FEATURE = (39),
  68. SD_UNSUPPORTED_HW = (40),
  69. SD_ERROR = (41),
  70. SD_OK = (0)
  71. } SD_Error;
  72. //SD卡CSD寄存器数据
  73. typedef struct
  74. {
  75. u8 CSDStruct; /*!< CSD structure */
  76. u8 SysSpecVersion; /*!< System specification version */
  77. u8 Reserved1; /*!< Reserved */
  78. u8 TAAC; /*!< Data read access-time 1 */
  79. u8 NSAC; /*!< Data read access-time 2 in CLK cycles */
  80. u8 MaxBusClkFrec; /*!< Max. bus clock frequency */
  81. u16 CardComdClasses; /*!< Card command classes */
  82. u8 RdBlockLen; /*!< Max. read data block length */
  83. u8 PartBlockRead; /*!< Partial blocks for read allowed */
  84. u8 WrBlockMisalign; /*!< Write block misalignment */
  85. u8 RdBlockMisalign; /*!< Read block misalignment */
  86. u8 DSRImpl; /*!< DSR implemented */
  87. u8 Reserved2; /*!< Reserved */
  88. u32 DeviceSize; /*!< Device Size */
  89. u8 MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */
  90. u8 MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */
  91. u8 MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */
  92. u8 MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */
  93. u8 DeviceSizeMul; /*!< Device size multiplier */
  94. u8 EraseGrSize; /*!< Erase group size */
  95. u8 EraseGrMul; /*!< Erase group size multiplier */
  96. u8 WrProtectGrSize; /*!< Write protect group size */
  97. u8 WrProtectGrEnable; /*!< Write protect group enable */
  98. u8 ManDeflECC; /*!< Manufacturer default ECC */
  99. u8 WrSpeedFact; /*!< Write speed factor */
  100. u8 MaxWrBlockLen; /*!< Max. write data block length */
  101. u8 WriteBlockPaPartial; /*!< Partial blocks for write allowed */
  102. u8 Reserved3; /*!< Reserded */
  103. u8 ContentProtectAppli; /*!< Content protection application */
  104. u8 FileFormatGrouop; /*!< File format group */
  105. u8 CopyFlag; /*!< Copy flag (OTP) */
  106. u8 PermWrProtect; /*!< Permanent write protection */
  107. u8 TempWrProtect; /*!< Temporary write protection */
  108. u8 FileFormat; /*!< File Format */
  109. u8 ECC; /*!< ECC code */
  110. u8 CSD_CRC; /*!< CSD CRC */
  111. u8 Reserved4; /*!< always 1*/
  112. } SD_CSD;
  113. //SD卡CID寄存器数据
  114. typedef struct
  115. {
  116. u8 ManufacturerID; /*!< ManufacturerID */
  117. u16 OEM_AppliID; /*!< OEM/Application ID */
  118. u32 ProdName1; /*!< Product Name part1 */
  119. u8 ProdName2; /*!< Product Name part2*/
  120. u8 ProdRev; /*!< Product Revision */
  121. u32 ProdSN; /*!< Product Serial Number */
  122. u8 Reserved1; /*!< Reserved1 */
  123. u16 ManufactDate; /*!< Manufacturing Date */
  124. u8 CID_CRC; /*!< CID CRC */
  125. u8 Reserved2; /*!< always 1 */
  126. } SD_CID;
  127. //SD卡状态
  128. typedef enum
  129. {
  130. SD_CARD_READY = ((uint32_t)0x00000001),
  131. SD_CARD_IDENTIFICATION = ((uint32_t)0x00000002),
  132. SD_CARD_STANDBY = ((uint32_t)0x00000003),
  133. SD_CARD_TRANSFER = ((uint32_t)0x00000004),
  134. SD_CARD_SENDING = ((uint32_t)0x00000005),
  135. SD_CARD_RECEIVING = ((uint32_t)0x00000006),
  136. SD_CARD_PROGRAMMING = ((uint32_t)0x00000007),
  137. SD_CARD_DISCONNECTED = ((uint32_t)0x00000008),
  138. SD_CARD_ERROR = ((uint32_t)0x000000FF)
  139. }SDCardState;
  140. //SD卡信息,包括CSD,CID等数据
  141. typedef struct
  142. {
  143. SD_CSD SD_csd;
  144. SD_CID SD_cid;
  145. long long CardCapacity; //SD卡容量,单位:字节,最大支持2^64字节大小的卡.
  146. u32 CardBlockSize; //SD卡块大小
  147. u16 RCA; //卡相对地址
  148. u8 CardType; //卡类型
  149. } SD_CardInfo;
  150. extern SD_CardInfo SDCardInfo;//SD卡信息
  151. ////////////////////////////////////////////////////////////////////////////////////////////////////
  152. //SDMMC卡 指令集
  153. //拷贝自:stm32f7xx_hal_sd.h
  154. #define SD_CMD_GO_IDLE_STATE ((uint8_t)0U) /*!< Resets the SD memory card. */
  155. #define SD_CMD_SEND_OP_COND ((uint8_t)1U) /*!< Sends host capacity support information and activates the card's initialization process. */
  156. #define SD_CMD_ALL_SEND_CID ((uint8_t)2U) /*!< Asks any card connected to the host to send the CID numbers on the CMD line. */
  157. #define SD_CMD_SET_REL_ADDR ((uint8_t)3U) /*!< Asks the card to publish a new relative address (RCA). */
  158. #define SD_CMD_SET_DSR ((uint8_t)4U) /*!< Programs the DSR of all cards. */
  159. #define SD_CMD_SDMMC_SEN_OP_COND ((uint8_t)5U) /*!< Sends host capacity support information (HCS) and asks the accessed card to send its
  160. operating condition register (OCR) content in the response on the CMD line. */
  161. #define SD_CMD_HS_SWITCH ((uint8_t)6U) /*!< Checks switchable function (mode 0) and switch card function (mode 1). */
  162. #define SD_CMD_SEL_DESEL_CARD ((uint8_t)7U) /*!< Selects the card by its own relative address and gets deselected by any other address */
  163. #define SD_CMD_HS_SEND_EXT_CSD ((uint8_t)8U) /*!< Sends SD Memory Card interface condition, which includes host supply voltage information
  164. and asks the card whether card supports voltage. */
  165. #define SD_CMD_SEND_CSD ((uint8_t)9U) /*!< Addressed card sends its card specific data (CSD) on the CMD line. */
  166. #define SD_CMD_SEND_CID ((uint8_t)10U) /*!< Addressed card sends its card identification (CID) on the CMD line. */
  167. #define SD_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11U) /*!< SD card doesn't support it. */
  168. #define SD_CMD_STOP_TRANSMISSION ((uint8_t)12U) /*!< Forces the card to stop transmission. */
  169. #define SD_CMD_SEND_STATUS ((uint8_t)13U) /*!< Addressed card sends its status register. */
  170. #define SD_CMD_HS_BUSTEST_READ ((uint8_t)14U)
  171. #define SD_CMD_GO_INACTIVE_STATE ((uint8_t)15U) /*!< Sends an addressed card into the inactive state. */
  172. #define SD_CMD_SET_BLOCKLEN ((uint8_t)16U) /*!< Sets the block length (in bytes for SDSC) for all following block commands
  173. (read, write, lock). Default block length is fixed to 512 Bytes. Not effective
  174. for SDHS and SDXC. */
  175. #define SD_CMD_READ_SINGLE_BLOCK ((uint8_t)17U) /*!< Reads single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of
  176. fixed 512 bytes in case of SDHC and SDXC. */
  177. #define SD_CMD_READ_MULT_BLOCK ((uint8_t)18U) /*!< Continuously transfers data blocks from card to host until interrupted by
  178. STOP_TRANSMISSION command. */
  179. #define SD_CMD_HS_BUSTEST_WRITE ((uint8_t)19U) /*!< 64 bytes tuning pattern is sent for SDR50 and SDR104. */
  180. #define SD_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20U) /*!< Speed class control command. */
  181. #define SD_CMD_SET_BLOCK_COUNT ((uint8_t)23U) /*!< Specify block count for CMD18 and CMD25. */
  182. #define SD_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24U) /*!< Writes single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of
  183. fixed 512 bytes in case of SDHC and SDXC. */
  184. #define SD_CMD_WRITE_MULT_BLOCK ((uint8_t)25U) /*!< Continuously writes blocks of data until a STOP_TRANSMISSION follows. */
  185. #define SD_CMD_PROG_CID ((uint8_t)26U) /*!< Reserved for manufacturers. */
  186. #define SD_CMD_PROG_CSD ((uint8_t)27U) /*!< Programming of the programmable bits of the CSD. */
  187. #define SD_CMD_SET_WRITE_PROT ((uint8_t)28U) /*!< Sets the write protection bit of the addressed group. */
  188. #define SD_CMD_CLR_WRITE_PROT ((uint8_t)29U) /*!< Clears the write protection bit of the addressed group. */
  189. #define SD_CMD_SEND_WRITE_PROT ((uint8_t)30U) /*!< Asks the card to send the status of the write protection bits. */
  190. #define SD_CMD_SD_ERASE_GRP_START ((uint8_t)32U) /*!< Sets the address of the first write block to be erased. (For SD card only). */
  191. #define SD_CMD_SD_ERASE_GRP_END ((uint8_t)33U) /*!< Sets the address of the last write block of the continuous range to be erased. */
  192. #define SD_CMD_ERASE_GRP_START ((uint8_t)35U) /*!< Sets the address of the first write block to be erased. Reserved for each command
  193. system set by switch function command (CMD6). */
  194. #define SD_CMD_ERASE_GRP_END ((uint8_t)36U) /*!< Sets the address of the last write block of the continuous range to be erased.
  195. Reserved for each command system set by switch function command (CMD6). */
  196. #define SD_CMD_ERASE ((uint8_t)38U) /*!< Reserved for SD security applications. */
  197. #define SD_CMD_FAST_IO ((uint8_t)39U) /*!< SD card doesn't support it (Reserved). */
  198. #define SD_CMD_GO_IRQ_STATE ((uint8_t)40U) /*!< SD card doesn't support it (Reserved). */
  199. #define SD_CMD_LOCK_UNLOCK ((uint8_t)42U) /*!< Sets/resets the password or lock/unlock the card. The size of the data block is set by
  200. the SET_BLOCK_LEN command. */
  201. #define SD_CMD_APP_CMD ((uint8_t)55U) /*!< Indicates to the card that the next command is an application specific command rather
  202. than a standard command. */
  203. #define SD_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
  204. for general purpose/application specific commands. */
  205. #define SD_CMD_NO_CMD ((uint8_t)64U)
  206. /**
  207. * @brief Following commands are SD Card Specific commands.
  208. * SDMMC_APP_CMD should be sent before sending these commands.
  209. */
  210. #define SD_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6U) /*!< (ACMD6) Defines the data bus width to be used for data transfer. The allowed data bus
  211. widths are given in SCR register. */
  212. #define SD_CMD_SD_APP_STATUS ((uint8_t)13U) /*!< (ACMD13) Sends the SD status. */
  213. #define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22U) /*!< (ACMD22) Sends the number of the written (without errors) write blocks. Responds with
  214. 32bit+CRC data block. */
  215. #define SD_CMD_SD_APP_OP_COND ((uint8_t)41U) /*!< (ACMD41) Sends host capacity support information (HCS) and asks the accessed card to
  216. send its operating condition register (OCR) content in the response on the CMD line. */
  217. #define SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42U) /*!< (ACMD42) Connects/Disconnects the 50 KOhm pull-up resistor on CD/DAT3 (pin 1) of the card. */
  218. #define SD_CMD_SD_APP_SEND_SCR ((uint8_t)51U) /*!< Reads the SD Configuration Register (SCR). */
  219. #define SD_CMD_SDMMC_RW_DIRECT ((uint8_t)52U) /*!< For SD I/O card only, reserved for security specification. */
  220. #define SD_CMD_SDMMC_RW_EXTENDED ((uint8_t)53U) /*!< For SD I/O card only, reserved for security specification. */
  221. /**
  222. * @brief Following commands are SD Card Specific security commands.
  223. * SD_CMD_APP_CMD should be sent before sending these commands.
  224. */
  225. #define SD_CMD_SD_APP_GET_MKB ((uint8_t)43U) /*!< For SD card only */
  226. #define SD_CMD_SD_APP_GET_MID ((uint8_t)44U) /*!< For SD card only */
  227. #define SD_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45U) /*!< For SD card only */
  228. #define SD_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46U) /*!< For SD card only */
  229. #define SD_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47U) /*!< For SD card only */
  230. #define SD_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48U) /*!< For SD card only */
  231. #define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18U) /*!< For SD card only */
  232. #define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25U) /*!< For SD card only */
  233. #define SD_CMD_SD_APP_SECURE_ERASE ((uint8_t)38U) /*!< For SD card only */
  234. #define SD_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49U) /*!< For SD card only */
  235. #define SD_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48U) /*!< For SD card only */
  236. //CMD8指令
  237. #define SD_SDMMC_SEND_IF_COND ((uint32_t)SD_CMD_HS_SEND_EXT_CSD)
  238. ////////////////////////////////////////////////////////////////////////////////////////////////////
  239. //支持的SD卡定义
  240. #define STD_CAPACITY_SD_CARD_V1_1 ((uint32_t)0x00000000U)
  241. #define STD_CAPACITY_SD_CARD_V2_0 ((uint32_t)0x00000001U)
  242. #define HIGH_CAPACITY_SD_CARD ((uint32_t)0x00000002U)
  243. #define MULTIMEDIA_CARD ((uint32_t)0x00000003U)
  244. #define SECURE_DIGITAL_IO_CARD ((uint32_t)0x00000004U)
  245. #define HIGH_SPEED_MULTIMEDIA_CARD ((uint32_t)0x00000005U)
  246. #define SECURE_DIGITAL_IO_COMBO_CARD ((uint32_t)0x00000006U)
  247. #define HIGH_CAPACITY_MMC_CARD ((uint32_t)0x00000007U)
  248. //SDMMC相关参数定义
  249. #define NULL 0
  250. //#define SDMMC_STATIC_FLAGS ((u32)0x000205FF)
  251. #define SDMMC_CMD0TIMEOUT ((u32)0x00010000)
  252. //#define SDMMC_DATATIMEOUT ((u32)0xFFFFFFFF)
  253. //Mask for errors Card Status R1 (OCR Register)
  254. #define SD_OCR_ADDR_OUT_OF_RANGE ((u32)0x80000000)
  255. #define SD_OCR_ADDR_MISALIGNED ((u32)0x40000000)
  256. #define SD_OCR_BLOCK_LEN_ERR ((u32)0x20000000)
  257. #define SD_OCR_ERASE_SEQ_ERR ((u32)0x10000000)
  258. #define SD_OCR_BAD_ERASE_PARAM ((u32)0x08000000)
  259. #define SD_OCR_WRITE_PROT_VIOLATION ((u32)0x04000000)
  260. #define SD_OCR_LOCK_UNLOCK_FAILED ((u32)0x01000000)
  261. #define SD_OCR_COM_CRC_FAILED ((u32)0x00800000)
  262. #define SD_OCR_ILLEGAL_CMD ((u32)0x00400000)
  263. #define SD_OCR_CARD_ECC_FAILED ((u32)0x00200000)
  264. #define SD_OCR_CC_ERROR ((u32)0x00100000)
  265. #define SD_OCR_GENERAL_UNKNOWN_ERROR ((u32)0x00080000)
  266. #define SD_OCR_STREAM_READ_UNDERRUN ((u32)0x00040000)
  267. #define SD_OCR_STREAM_WRITE_OVERRUN ((u32)0x00020000)
  268. //#define SD_OCR_CID_CSD_OVERWRIETE ((u32)0x00010000)
  269. #define SD_OCR_WP_ERASE_SKIP ((u32)0x00008000)
  270. #define SD_OCR_CARD_ECC_DISABLED ((u32)0x00004000)
  271. #define SD_OCR_ERASE_RESET ((u32)0x00002000)
  272. #define SD_OCR_AKE_SEQ_ERROR ((u32)0x00000008)
  273. #define SD_OCR_ERRORBITS ((u32)0xFDFFE008)
  274. //Masks for R6 Response
  275. #define SD_R6_GENERAL_UNKNOWN_ERROR ((u32)0x00002000)
  276. #define SD_R6_ILLEGAL_CMD ((u32)0x00004000)
  277. #define SD_R6_COM_CRC_FAILED ((u32)0x00008000)
  278. #define SD_VOLTAGE_WINDOW_SD ((u32)0x80100000)
  279. #define SD_HIGH_CAPACITY ((u32)0x40000000)
  280. #define SD_STD_CAPACITY ((u32)0x00000000)
  281. #define SD_CHECK_PATTERN ((u32)0x000001AA)
  282. #define SD_VOLTAGE_WINDOW_MMC ((u32)0x80FF8000)
  283. #define SD_MAX_VOLT_TRIAL ((u32)0x0000FFFF)
  284. #define SD_ALLZERO ((u32)0x00000000)
  285. #define SD_WIDE_BUS_SUPPORT ((u32)0x00040000)
  286. #define SD_SINGLE_BUS_SUPPORT ((u32)0x00010000)
  287. #define SD_CARD_LOCKED ((u32)0x02000000)
  288. #define SD_CARD_PROGRAMMING ((u32)0x00000007)
  289. #define SD_CARD_RECEIVING ((u32)0x00000006)
  290. #define SD_DATATIMEOUT ((u32)0xFFFFFFFF)
  291. #define SD_0TO7BITS ((u32)0x000000FF)
  292. #define SD_8TO15BITS ((u32)0x0000FF00)
  293. #define SD_16TO23BITS ((u32)0x00FF0000)
  294. #define SD_24TO31BITS ((u32)0xFF000000)
  295. #define SD_MAX_DATA_LENGTH ((u32)0x01FFFFFF)
  296. #define SD_HALFFIFO ((u32)0x00000008)
  297. #define SD_HALFFIFOBYTES ((u32)0x00000020)
  298. //Command Class Supported
  299. #define SD_CCCC_LOCK_UNLOCK ((u32)0x00000080)
  300. #define SD_CCCC_WRITE_PROT ((u32)0x00000040)
  301. #define SD_CCCC_ERASE ((u32)0x00000020)
  302. ////////////////////////////////////////////////////////////////////////////////////////////////////
  303. //相关函数定义
  304. SD_Error SD_Init(void);
  305. void SDMMC_Clock_Set(u16 clkdiv);
  306. void SDMMC_Send_Cmd(u8 cmdindex,u8 waitrsp,u32 arg);
  307. void SDMMC_Send_Data_Cfg(u32 datatimeout,u32 datalen,u8 blksize,u8 dir);
  308. SD_Error SD_PowerON(void);
  309. SD_Error SD_PowerOFF(void);
  310. SD_Error SD_InitializeCards(void);
  311. SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo);
  312. SD_Error SD_EnableWideBusOperation(u32 wmode);
  313. SD_Error SD_SelectDeselect(u32 addr);
  314. SD_Error SD_SendStatus(uint32_t *pcardstatus);
  315. SDCardState SD_GetState(void);
  316. SD_Error SD_ReadBlocks(u8 *buf,long long addr,u16 blksize,u32 nblks);
  317. SD_Error SD_WriteBlocks(u8 *buf,long long addr,u16 blksize,u32 nblks);
  318. SD_Error CmdError(void);
  319. SD_Error CmdResp7Error(void);
  320. SD_Error CmdResp1Error(u8 cmd);
  321. SD_Error CmdResp3Error(void);
  322. SD_Error CmdResp2Error(void);
  323. SD_Error CmdResp6Error(u8 cmd,u16*prca);
  324. SD_Error SDEnWideBus(u8 enx);
  325. SD_Error IsCardProgramming(u8 *pstatus);
  326. SD_Error FindSCR(u16 rca,u32 *pscr);
  327. u8 SD_ReadDisk(u8*buf,u32 sector,u32 cnt); //读SD卡,fatfs/usb调用
  328. u8 SD_WriteDisk(u8*buf,u32 sector,u32 cnt); //写SD卡,fatfs/usb调用
  329. #endif