drv_sdcard.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /***************************************************************************//**
  2. * @file drv_sdcard.h
  3. * @brief Memory card driver (SPI mode) of RT-Thread RTOS for using EFM32
  4. * USART module
  5. * COPYRIGHT (C) 2012, RT-Thread Development Team
  6. * @author onelife
  7. * @version 1.0
  8. *******************************************************************************
  9. * @section License
  10. * The license and distribution terms for this file may be found in the file
  11. * LICENSE in this distribution or at http://www.rt-thread.org/license/LICENSE
  12. *******************************************************************************
  13. * @section Change Logs
  14. * Date Author Notes
  15. * 2011-05-13 onelife Initial creation for using EFM32 USART module
  16. * 2011-07-07 onelife Modify initialization function to return error code
  17. ******************************************************************************/
  18. #ifndef __DEV_SDCARD_H__
  19. #define __DEV_SDCARD_H__
  20. /* Includes ------------------------------------------------------------------*/
  21. /* Exported types ------------------------------------------------------------*/
  22. /* Exported constants --------------------------------------------------------*/
  23. /* Exported macro ------------------------------------------------------------*/
  24. #define EFM32_SDCLK_LOW (100000)
  25. #if defined(EFM32_GXXX_DK)
  26. #define EFM32_SDCLK_HIGH (16000000)
  27. #elif defined(EFM32GG_DK3750)
  28. #define EFM32_SDCLK_HIGH (19000000)
  29. #endif
  30. #if (EFM32_SDCLK_HIGH > (EFM32_HFXO_FREQUENCY/2))
  31. #error "EFM32 SPI clock should not be more than (EFM32_HFXO_FREQUENCY/2)"
  32. #endif
  33. #define SD_SPEED_LOW (0)
  34. #define SD_SPEED_HIGH (1)
  35. #define SD_WAIT_PERIOD (RT_TICK_PER_SECOND)
  36. #define SD_SECTOR_SIZE_SHIFT (9)
  37. #define SD_SECTOR_SIZE (1 << SD_SECTOR_SIZE_SHIFT)
  38. #define SD_BLOCK_SIZE_CSD (16)
  39. #define SD_BLOCK_SIZE_CID (16)
  40. #define SD_BLOCK_SIZE_OCR (4)
  41. #define SD_BLOCK_SIZE_SDSTAT (64)
  42. /* Card type definitions (CardType) */
  43. #define CT_MMC (0x01)
  44. #define CT_SD1 (0x02)
  45. #define CT_SD2 (0x04)
  46. #define CT_SDC (CT_SD1|CT_SD2)
  47. #define CT_BLOCK (0x08)
  48. /* Definitions for MMC/SDC command */
  49. #define CMD0 (0) /* GO_IDLE_STATE */
  50. #define CMD1 (1) /* SEND_OP_COND */
  51. #define ACMD41 (41|0x80) /* SEND_OP_COND (SDC) */
  52. #define CMD8 (8) /* SEND_IF_COND */
  53. #define CMD9 (9) /* SEND_CSD */
  54. #define CMD10 (10) /* SEND_CID */
  55. #define CMD12 (12) /* STOP_TRANSMISSION */
  56. #define ACMD13 (13|0x80) /* SD_STATUS (SDC) */
  57. #define CMD16 (16) /* SET_BLOCKLEN */
  58. #define CMD17 (17) /* READ_SINGLE_BLOCK */
  59. #define CMD18 (18) /* READ_MULTIPLE_BLOCK */
  60. #define CMD23 (23) /* SET_BLOCK_COUNT */
  61. #define ACMD23 (23|0x80) /* SET_WR_BLK_ERASE_COUNT (SDC) */
  62. #define CMD24 (24) /* WRITE_BLOCK */
  63. #define CMD25 (25) /* WRITE_MULTIPLE_BLOCK */
  64. #define CMD41 (41) /* SEND_OP_COND (ACMD) */
  65. #define CMD55 (55) /* APP_CMD */
  66. #define CMD58 (58) /* READ_OCR */
  67. /* Exported functions ------------------------------------------------------- */
  68. rt_err_t efm_spiSd_init(void);
  69. void efm_spiSd_deinit(void);
  70. #endif /* __DEV_SDCARD_H__ */