W25QXX.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*********************************************************************************************************
  2. *
  3. * File : W25Qx.h
  4. * Hardware Environment:
  5. * Build Environment : RealView MDK-ARM Version: 5.15
  6. * Version : V1.0
  7. * By :
  8. *
  9. * (c) Copyright 2005-2015, WaveShare
  10. * http://www.waveshare.net
  11. * All Rights Reserved
  12. *
  13. *********************************************************************************************************/
  14. /* Define to prevent recursive inclusion -------------------------------------*/
  15. #ifndef __W25QXX_H
  16. #define __W25QXX_H
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f4xx.h"
  22. #include "spi.h"
  23. /** @addtogroup BSP
  24. * @{
  25. */
  26. /** @addtogroup Components
  27. * @{
  28. */
  29. /** @addtogroup W25Q128FV
  30. * @{
  31. */
  32. /** @defgroup W25Q128FV_Exported_Types
  33. * @{
  34. */
  35. /**
  36. * @}
  37. */
  38. /** @defgroup W25Q128FV_Exported_Constants
  39. * @{
  40. */
  41. /**
  42. * @brief W25Q128FV Configuration
  43. */
  44. #define W25Q16FV_FLASH_SIZE 0x200000 /* 16 MBits => 16MBytes */
  45. #define W25Q16FV_SECTOR_SIZE 0x10000 /* 32 sectors of 64KBytes */
  46. #define W25Q16FV_BLOCK_SIZE 0x1000 /* 512 subsectors of 4kBytes */
  47. #define W25Q16FV_PAGE_SIZE 0x100 /* 8192 pages of 256 bytes */
  48. #define W25Q128FV_DUMMY_CYCLES_READ 4
  49. #define W25Q128FV_DUMMY_CYCLES_READ_QUAD 10
  50. #define W25Q128FV_BULK_ERASE_MAX_TIME 250000
  51. #define W25Q128FV_SECTOR_ERASE_MAX_TIME 3000
  52. #define W25Q128FV_SUBSECTOR_ERASE_MAX_TIME 800
  53. #define W25Qx_TIMEOUT_VALUE 1000
  54. /**
  55. * @brief W25Q128FV Commands
  56. */
  57. /* Reset Operations */
  58. #define RESET_ENABLE_CMD 0x66
  59. #define RESET_MEMORY_CMD 0x99
  60. #define ENTER_QPI_MODE_CMD 0x38
  61. #define EXIT_QPI_MODE_CMD 0xFF
  62. /* Identification Operations */
  63. #define READ_ID_CMD 0x90
  64. #define DUAL_READ_ID_CMD 0x92
  65. #define QUAD_READ_ID_CMD 0x94
  66. #define READ_JEDEC_ID_CMD 0x9F
  67. /* Read Operations */
  68. #define READ_CMD 0x03
  69. #define FAST_READ_CMD 0x0B
  70. #define DUAL_OUT_FAST_READ_CMD 0x3B
  71. #define DUAL_INOUT_FAST_READ_CMD 0xBB
  72. #define QUAD_OUT_FAST_READ_CMD 0x6B
  73. #define QUAD_INOUT_FAST_READ_CMD 0xEB
  74. /* Write Operations */
  75. #define WRITE_ENABLE_CMD 0x06
  76. #define WRITE_DISABLE_CMD 0x04
  77. /* Register Operations */
  78. #define READ_STATUS_REG1_CMD 0x05
  79. #define READ_STATUS_REG2_CMD 0x35
  80. #define READ_STATUS_REG3_CMD 0x15
  81. #define WRITE_STATUS_REG1_CMD 0x01
  82. #define WRITE_STATUS_REG2_CMD 0x31
  83. #define WRITE_STATUS_REG3_CMD 0x11
  84. /* Program Operations */
  85. #define PAGE_PROG_CMD 0x02
  86. #define QUAD_INPUT_PAGE_PROG_CMD 0x32
  87. /* Erase Operations */
  88. #define SECTOR_ERASE_CMD 0x20
  89. #define CHIP_ERASE_CMD 0xC7
  90. #define PROG_ERASE_RESUME_CMD 0x7A
  91. #define PROG_ERASE_SUSPEND_CMD 0x75
  92. /* Flag Status Register */
  93. #define W25Q128FV_FSR_BUSY ((uint8_t)0x01) /*!< busy */
  94. #define W25Q128FV_FSR_WREN ((uint8_t)0x02) /*!< write enable */
  95. #define W25Q128FV_FSR_QE ((uint8_t)0x02) /*!< quad enable */
  96. #define W25Qx_Enable() HAL_GPIO_WritePin(OUT_SPI1_CS_GPIO_Port, OUT_SPI1_CS_Pin, GPIO_PIN_RESET)
  97. #define W25Qx_Disable() HAL_GPIO_WritePin(OUT_SPI1_CS_GPIO_Port, OUT_SPI1_CS_Pin, GPIO_PIN_SET)
  98. #define W25Qx_OK ((uint8_t)0x00)
  99. #define W25Qx_ERROR ((uint8_t)0x01)
  100. #define W25Qx_BUSY ((uint8_t)0x02)
  101. #define W25Qx_TIMEOUT ((uint8_t)0x03)
  102. uint8_t BSP_W25Qx_Init(void);
  103. static void BSP_W25Qx_Reset(void);
  104. static uint8_t BSP_W25Qx_GetStatus(void);
  105. uint8_t BSP_W25Qx_WriteEnable(void);
  106. void BSP_W25Qx_Read_ID(uint8_t *ID);
  107. uint8_t BSP_W25Qx_Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size);
  108. uint8_t BSP_W25Qx_Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size);
  109. uint8_t BSP_W25Qx_Erase_Block(uint32_t Address);
  110. uint8_t BSP_W25Qx_Erase_Chip(void);
  111. /**
  112. * @}
  113. */
  114. /** @defgroup W25Q128FV_Exported_Functions
  115. * @{
  116. */
  117. /**
  118. * @}
  119. */
  120. /**
  121. * @}
  122. */
  123. /**
  124. * @}
  125. */
  126. /**
  127. * @}
  128. */
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif /* __W25Qx_H */