drv_sdcard.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-05-13 onelife Initial creation for using EFM32 USART module
  9. * 2011-07-07 onelife Modify initialization function to return error code
  10. */
  11. #ifndef __DEV_SDCARD_H__
  12. #define __DEV_SDCARD_H__
  13. /* Includes ------------------------------------------------------------------*/
  14. /* Exported types ------------------------------------------------------------*/
  15. /* Exported constants --------------------------------------------------------*/
  16. /* Exported macro ------------------------------------------------------------*/
  17. #define EFM32_SDCLK_LOW (100000)
  18. #if defined(EFM32_GXXX_DK)
  19. #define EFM32_SDCLK_HIGH (16000000)
  20. #elif defined(EFM32GG_DK3750)
  21. #define EFM32_SDCLK_HIGH (19000000)
  22. #endif
  23. #if (EFM32_SDCLK_HIGH > (EFM32_HFXO_FREQUENCY/2))
  24. #error "EFM32 SPI clock should not be more than (EFM32_HFXO_FREQUENCY/2)"
  25. #endif
  26. #define SD_SPEED_LOW (0)
  27. #define SD_SPEED_HIGH (1)
  28. #define SD_WAIT_PERIOD (RT_TICK_PER_SECOND)
  29. #define SD_SECTOR_SIZE_SHIFT (9)
  30. #define SD_SECTOR_SIZE (1 << SD_SECTOR_SIZE_SHIFT)
  31. #define SD_BLOCK_SIZE_CSD (16)
  32. #define SD_BLOCK_SIZE_CID (16)
  33. #define SD_BLOCK_SIZE_OCR (4)
  34. #define SD_BLOCK_SIZE_SDSTAT (64)
  35. /* Card type definitions (CardType) */
  36. #define CT_MMC (0x01)
  37. #define CT_SD1 (0x02)
  38. #define CT_SD2 (0x04)
  39. #define CT_SDC (CT_SD1|CT_SD2)
  40. #define CT_BLOCK (0x08)
  41. /* Definitions for MMC/SDC command */
  42. #define CMD0 (0) /* GO_IDLE_STATE */
  43. #define CMD1 (1) /* SEND_OP_COND */
  44. #define ACMD41 (41|0x80) /* SEND_OP_COND (SDC) */
  45. #define CMD8 (8) /* SEND_IF_COND */
  46. #define CMD9 (9) /* SEND_CSD */
  47. #define CMD10 (10) /* SEND_CID */
  48. #define CMD12 (12) /* STOP_TRANSMISSION */
  49. #define ACMD13 (13|0x80) /* SD_STATUS (SDC) */
  50. #define CMD16 (16) /* SET_BLOCKLEN */
  51. #define CMD17 (17) /* READ_SINGLE_BLOCK */
  52. #define CMD18 (18) /* READ_MULTIPLE_BLOCK */
  53. #define CMD23 (23) /* SET_BLOCK_COUNT */
  54. #define ACMD23 (23|0x80) /* SET_WR_BLK_ERASE_COUNT (SDC) */
  55. #define CMD24 (24) /* WRITE_BLOCK */
  56. #define CMD25 (25) /* WRITE_MULTIPLE_BLOCK */
  57. #define CMD41 (41) /* SEND_OP_COND (ACMD) */
  58. #define CMD55 (55) /* APP_CMD */
  59. #define CMD58 (58) /* READ_OCR */
  60. /* Exported functions ------------------------------------------------------- */
  61. rt_err_t efm_spiSd_init(void);
  62. void efm_spiSd_deinit(void);
  63. #endif /* __DEV_SDCARD_H__ */