sddriver.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef __SDDRIVER_H
  2. #define __SDDRIVER_H
  3. #include "stm32f10x_conf.h"
  4. #define printf
  5. #define SD_CS_ENABLE() GPIO_ResetBits(GPIOA, GPIO_Pin_4) /*使能SD卡*/
  6. #define SD_CS_DISABLE() GPIO_SetBits(GPIOA, GPIO_Pin_4) /*失能SD卡*/
  7. #define SPI_SPEED_LOW 0
  8. #define SPI_SPEED_HIGH 1
  9. /* Private define ------------------------------------------------------------*/
  10. /* SD卡类型定义 */
  11. #define SD_TYPE_MMC 0
  12. #define SD_TYPE_V1 1
  13. #define SD_TYPE_V2 2
  14. #define SD_TYPE_V2HC 4
  15. /* SD传输数据结束后是否释放总线宏定义 */
  16. #define NO_RELEASE 0
  17. #define RELEASE 1
  18. /* SD卡指令表 */
  19. #define CMD0 0 //卡复位
  20. #define CMD9 9 //命令9 ,读CSD数据
  21. #define CMD10 10 //命令10,读CID数据
  22. #define CMD12 12 //命令12,停止数据传输
  23. #define CMD16 16 //命令16,设置SectorSize 应返回0x00
  24. #define CMD17 17 //命令17,读sector
  25. #define CMD18 18 //命令18,读Multi sector
  26. #define ACMD23 23 //命令23,设置多sector写入前预先擦除N个block
  27. #define CMD24 24 //命令24,写sector
  28. #define CMD25 25 //命令25,写Multi sector
  29. #define ACMD41 41 //命令41,应返回0x00
  30. #define CMD55 55 //命令55,应返回0x01
  31. #define CMD58 58 //命令58,读OCR信息
  32. #define CMD59 59 //命令59,使能/禁止CRC,应返回0x00
  33. /* SPI波特率设置 低速256分频 */
  34. uint8_t SD_Init(void);
  35. void SPI_Configuration(void);
  36. void SPI_SetSpeed(u8 SpeedSet);
  37. u8 SPI_ReadWriteByte(u8 TxData);
  38. u8 SD_SendCommand(u8 cmd, u32 arg, u8 crc);
  39. u8 SD_SendCommand_NoDeassert(u8 cmd, u32 arg, u8 crc);
  40. u8 SD_ReadSingleBlock(u32 sector, u8 *buffer);
  41. u8 SD_ReadMultiBlock(u32 sector, u8 *buffer, u8 count);
  42. u8 SD_WriteSingleBlock(u32 sector, const u8 *data);
  43. u8 SD_WriteMultiBlock(u32 sector, const u8 *data, u8 count);
  44. u8 SD_WaitReady(void);
  45. u32 SD_GetCapacity(void);
  46. u8 SD_GetCSD(u8 *csd_data);
  47. u8 SD_ReceiveData(u8 *data, u16 len, u8 release);
  48. #endif