dev_sflash.h 3.7 KB

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