dev_sflash.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /***************************************************************************//**
  2. * @file dev_sflash.h
  3. * @brief SPI Flash driver of RT-Thread RTOS for EFM32 by using USART module
  4. * COPYRIGHT (C) 2012, RT-Thread Development Team
  5. * @author onelife
  6. * @version 1.0
  7. *******************************************************************************
  8. * @section License
  9. * The license and distribution terms for this file may be found in the file
  10. * LICENSE in this distribution or at http://www.rt-thread.org/license/LICENSE
  11. *******************************************************************************
  12. * @section Change Logs
  13. * Date Author Notes
  14. * 2011-05-06 onelife Initial creation by using USART module
  15. ******************************************************************************/
  16. #ifndef __DEV_SFLASH_H__
  17. #define __DEV_SFLASH_H__
  18. /* Includes ------------------------------------------------------------------*/
  19. /* Exported types ------------------------------------------------------------*/
  20. enum sflash_inst_type_t
  21. {
  22. /* Instruction only */
  23. sflash_inst_wren = 0x00,
  24. sflash_inst_wrdi,
  25. sflash_inst_rdid_l,
  26. sflash_inst_rdid_s,
  27. sflash_inst_rdsr,
  28. sflash_inst_wrsr,
  29. sflash_inst_be,
  30. sflash_inst_dp,
  31. sflash_inst_rdp,
  32. /* Instruction and address */
  33. sflash_inst_wrlr,
  34. sflash_inst_rdlr,
  35. sflash_inst_read,
  36. sflash_inst_potp,
  37. sflash_inst_pp,
  38. sflash_inst_difp,
  39. sflash_inst_sse,
  40. sflash_inst_se,
  41. /* Instruction, address and dummy read */
  42. sflash_inst_read_f,
  43. sflash_inst_dofr,
  44. sflash_inst_rotp
  45. };
  46. /* Exported constants --------------------------------------------------------*/
  47. /* Exported macro ------------------------------------------------------------*/
  48. #define SFLASH_SPI_COMMAND_SKIP (1)
  49. #define SFLASH_SPI_READ_SKIP (2)
  50. #define SFLASH_INST_CODE_WREN (0x06)
  51. #define SFLASH_INST_CODE_WRDI (0x04)
  52. #define SFLASH_INST_CODE_RDID_L (0x9F)
  53. #define SFLASH_INST_CODE_RDID_S (0x9E)
  54. #define SFLASH_INST_CODE_RDSR (0x05)
  55. #define SFLASH_INST_CODE_WRSR (0x01)
  56. #define SFLASH_INST_CODE_WRLR (0xE5)
  57. #define SFLASH_INST_CODE_RDLR (0xE8)
  58. #define SFLASH_INST_CODE_READ (0x03)
  59. #define SFLASH_INST_CODE_READ_F (0x0B)
  60. #define SFLASH_INST_CODE_DOFR (0x3B)
  61. #define SFLASH_INST_CODE_ROTP (0x4B)
  62. #define SFLASH_INST_CODE_POTP (0x42)
  63. #define SFLASH_INST_CODE_PP (0x02)
  64. #define SFLASH_INST_CODE_DIFP (0xA2)
  65. #define SFLASH_INST_CODE_SSE (0x20)
  66. #define SFLASH_INST_CODE_SE (0xD8)
  67. #define SFLASH_INST_CODE_BE (0xC7)
  68. #define SFLASH_INST_CODE_DP (0xB9)
  69. #define SFLASH_INST_CODE_RDP (0xAB)
  70. #define SFLASH_REPLY_LEN_WREN (0)
  71. #define SFLASH_REPLY_LEN_WRDI (0)
  72. #define SFLASH_REPLY_LEN_RDID_L (20)
  73. #define SFLASH_REPLY_LEN_RDID_S (3)
  74. #define SFLASH_REPLY_LEN_RDSR (1)
  75. #define SFLASH_REPLY_LEN_WRSR (1)
  76. #define SFLASH_REPLY_LEN_WRLR (1)
  77. #define SFLASH_REPLY_LEN_RDLR (1)
  78. #define SFLASH_REPLY_LEN_READ (-1)
  79. #define SFLASH_REPLY_LEN_READ_F (-1)
  80. #define SFLASH_REPLY_LEN_DOFR (-1)
  81. #define SFLASH_REPLY_LEN_ROTP (65)
  82. #define SFLASH_REPLY_LEN_POTP (65)
  83. #define SFLASH_REPLY_LEN_PP (256)
  84. #define SFLASH_REPLY_LEN_DIFP (256)
  85. #define SFLASH_REPLY_LEN_SSE (0)
  86. #define SFLASH_REPLY_LEN_SE (0)
  87. #define SFLASH_REPLY_LEN_BE (0)
  88. #define SFLASH_REPLY_LEN_DP (0)
  89. #define SFLASH_REPLY_LEN_RDP (0)
  90. /* Exported functions ------------------------------------------------------- */
  91. rt_err_t efm_spiFlash_init(void);
  92. rt_err_t efm_spiFlash_deinit(void);
  93. rt_uint32_t efm_spiFlash_cmd(
  94. enum sflash_inst_type_t command,
  95. rt_uint32_t address,
  96. rt_uint8_t *buffer,
  97. rt_uint32_t size);
  98. #endif /* __DEV_SFLASH_H__ */