s25fl128s.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /**
  2. ******************************************************************************
  3. * @file s25fl128s.h
  4. * @author MCD Application Team
  5. * @brief This file contains all the description of the S25FL128S QSPI memory.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef S25FL128S_H
  20. #define S25FL128S_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "s25fl128s_conf.h"
  26. /** @addtogroup BSP
  27. * @{
  28. */
  29. /** @addtogroup Components
  30. * @{
  31. */
  32. /** @addtogroup S25FL128S
  33. * @brief This file provides a set of definitions for the Spansion
  34. * S25FL128S memory (configuration, commands, registers).
  35. * @{
  36. */
  37. /** @defgroup S25FL128S_Exported_Constants
  38. * @{
  39. */
  40. /* S25FL128SAGMFI01 Spansion Memory */
  41. /**
  42. * @brief S25FL128S Configuration
  43. */
  44. #define S25FL128S_BLOCK_64K (uint32_t) (64 * 1024) /* 256 blocks of 64KBytes */
  45. #define S25FL128S_SECTOR_4K (uint32_t) (4 * 1024) /* 4096 sectors of 4KBytes */
  46. #define S25FL128S_FLASH_SIZE 0x1000000 /* 128 MBits => 16MBytes */
  47. #define S25FL128S_SECTOR_SIZE 0x1000 /* 4096 sectors of 4kBytes */
  48. #define S25FL128S_PAGE_SIZE 0x100 /* 65536 pages of 256 bytes */
  49. #define S25FL128S_BULK_ERASE_MAX_TIME 330000
  50. #define S25FL128S_SECTOR_ERASE_MAX_TIME 130
  51. /**
  52. * @brief S25FL128S Error codes
  53. */
  54. #define S25FL128S_OK (0)
  55. #define S25FL128S_ERROR (-1)
  56. /**
  57. * @brief S25FL128S Commands
  58. */
  59. /* Reset Operations */
  60. #define S25FL128S_SOFTWARE_RESET_CMD 0xF0
  61. #define S25FL128S_MODE_BIT_RESET_CMD 0xFF
  62. /* Identification Operations */
  63. #define S25FL128S_READ_ID_CMD 0x90
  64. #define S25FL128S_READ_ID_CMD2 0x9F
  65. #define S25FL128S_READ_ELECTRONIC_SIGNATURE 0xAB
  66. #define S25FL128S_READ_SERIAL_FLASH_DISCO_PARAM_CMD 0x5A
  67. /* Register Operations */
  68. #define S25FL128S_READ_STATUS_REG1_CMD 0x05
  69. #define S25FL128S_READ_STATUS_REG2_CMD 0x07
  70. #define S25FL128S_READ_CONFIGURATION_REG1_CMD 0x35
  71. #define S25FL128S_WRITE_STATUS_CMD_REG_CMD 0x01
  72. #define S25FL128S_WRITE_DISABLE_CMD 0x04
  73. #define S25FL128S_WRITE_ENABLE_CMD 0x06
  74. #define S25FL128S_CLEAR_STATUS_REG1_CMD 0x30
  75. #define S25FL128S_READ_AUTOBOOT_REG_CMD 0x14
  76. #define S25FL128S_WRITE_AUTOBOOT_REG_CMD 0x15
  77. #define S25FL128S_READ_BANK_REG_CMD 0x16
  78. #define S25FL128S_WRITE_BANK_REG_CMD 0x17
  79. #define S25FL128S_ACCESS_BANK_REG_CMD 0xB9
  80. #define S25FL128S_READ_DATA_LEARNING_PATTERN_CMD 0x41
  81. #define S25FL128S_PGM_NV_DATA_LEARNING_REG_CMD 0x43
  82. #define S25FL128S_WRITE_VOL_DATA_LEARNING_REG_CMD 0x4A
  83. /* Read Operations */
  84. #define S25FL128S_READ_CMD 0x03
  85. #define S25FL128S_READ_4_BYTE_ADDR_CMD 0x13
  86. #define S25FL128S_FAST_READ_CMD 0x0B
  87. #define S25FL128S_FAST_READ_4_BYTE_ADDR_CMD 0x0C
  88. #define S25FL128S_FAST_READ_DDR_CMD 0x0D
  89. #define S25FL128S_FAST_READ__DDR_4_BYTE_ADDR_CMD 0x0E
  90. #define S25FL128S_DUAL_OUT_FAST_READ_CMD 0x3B
  91. #define S25FL128S_DUAL_OUT_FAST_READ_4_BYTE_ADDR_CMD 0x3C
  92. #define S25FL128S_QUAD_OUT_FAST_READ_CMD 0x6B
  93. #define S25FL128S_QUAD_OUT_FAST_READ_4_BYTE_ADDR_CMD 0x6C
  94. #define S25FL128S_DUAL_INOUT_FAST_READ_CMD 0xBB
  95. #define S25FL128S_DUAL_INOUT_FAST_READ_DTR_CMD 0xBD
  96. #define S25FL128S_DUAL_INOUT_FAST_READ_4_BYTE_ADDR_CMD 0xBC
  97. #define S25FL128S_DDR_DUAL_INOUT_READ_4_BYTE_ADDR_CMD 0xBE
  98. #define S25FL128S_QUAD_INOUT_FAST_READ_CMD 0xEB
  99. #define S25FL128S_QUAD_INOUT_FAST_READ_4_BYTE_ADDR_CMD 0xEC
  100. #define S25FL128S_QUAD_INOUT_FAST_READ_DDR_CMD 0xED
  101. #define S25FL128S_QUAD_INOUT_READ_DDR_4_BYTE_ADDR_CMD 0xEE
  102. /* Program Operations */
  103. #define S25FL128S_PAGE_PROG_CMD 0x02
  104. #define S25FL128S_PAGE_PROG_4_BYTE_ADDR_CMD 0x12
  105. #define S25FL128S_QUAD_IN_FAST_PROG_CMD 0x32
  106. #define S25FL128S_QUAD_IN_FAST_PROG_ALTERNATE_CMD 0x38
  107. #define S25FL128S_QUAD_IN_FAST_PROG_4_BYTE_ADDR_CMD 0x34
  108. #define S25FL128S_PROGRAM_SUSPEND_CMD 0x85
  109. #define S25FL128S_PROGRAM_RESUME_CMD 0x8A
  110. /* Erase Operations */
  111. #define S25FL128S_SUBSECTOR_ERASE_CMD_4K 0x20
  112. #define S25FL128S_SUBSECTOR_ERASE_4_BYTE_ADDR_CMD_4K 0x21
  113. #define S25FL128S_SECTOR_ERASE_CMD 0xD8
  114. #define S25FL128S_SECTOR_ERASE_4_BYTE_ADDR_CMD 0xDC
  115. #define S25FL128S_BULK_ERASE_CMD 0x60
  116. #define S25FL128S_BULK_ERASE_ALTERNATE_CMD 0xC7
  117. #define S25FL128S_PROG_ERASE_SUSPEND_CMD 0x75
  118. #define S25FL128S_PROG_ERASE_RESUME_CMD 0x7A
  119. /* One-Time Programmable Operations */
  120. #define S25FL128S_PROG_OTP_ARRAY_CMD 0x42
  121. #define S25FL128S_READ_OTP_ARRAY_CMD 0x4B
  122. /* Deep Power Operations */
  123. #define S25FL128S_ENTER_DEEP_POWER_DOWN 0xB9
  124. /* Advanced Sector Protection Operations */
  125. #define S25FL128S_READ_DYB_CMD 0xE0
  126. #define S25FL128S_WRITE_DYB_CMD 0xE1
  127. #define S25FL128S_READ_PPB_CMD 0xE2
  128. #define S25FL128S_PROGRAM_PPB_CMD 0xE3
  129. #define S25FL128S_ERASE_PPB_CMD 0xE4
  130. #define S25FL128S_READ_ASP_CMD 0x2B
  131. #define S25FL128S_PROGRAM_ASP_CMD 0x2F
  132. #define S25FL128S_READ_PPB_LOCKBIT_CMD 0xA7
  133. #define S25FL128S_WRITE_PPB_LOCKBIT_CMD 0xA6
  134. #define S25FL128S_READ_PASSWORD_CMD 0xE7
  135. #define S25FL128S_PROGRAM_PASSWORD_CMD 0xE8
  136. #define S25FL128S_UNLOCK_PASSWORD_CMD 0xE9
  137. /**
  138. * @brief S25FL128S Registers
  139. */
  140. /* Status Register-1 */
  141. #define S25FL128S_SR1_WIP ((uint8_t)0x01) /*!< Write in progress, device busy */
  142. #define S25FL128S_SR1_WREN ((uint8_t)0x02) /*!< Write Registers, program or commands are accepted */
  143. #define S25FL128S_SR1_BP0 ((uint8_t)0x04) /*!< Sector0 protected from Program or Erase */
  144. #define S25FL128S_SR1_BP1 ((uint8_t)0x08) /*!< Sector1 protected from Program or Erase */
  145. #define S25FL128S_SR1_BP2 ((uint8_t)0x10) /*!< Sector2 protected from Program or Erase */
  146. #define S25FL128S_SR1_ERERR ((uint8_t)0x20) /*!< Erase error */
  147. #define S25FL128S_SR1_PGERR ((uint8_t)0x40) /*!< Program error */
  148. #define S25FL128S_SR1_SRWD ((uint8_t)0x80) /*!< Status Register Write Disable */
  149. /* Status Register-2 */
  150. #define S25FL128S_SR2_PS ((uint8_t)0x01) /*!< Program in Suspend mode */
  151. #define S25FL128S_SR2_ES ((uint8_t)0x02) /*!< Erase Suspend Mode */
  152. /* Configuration Register CR1 */
  153. #define S25FL128S_CR1_FREEZE ((uint8_t)0x01) /*!< Block protection and OTP locked */
  154. #define S25FL128S_CR1_QUAD ((uint8_t)0x02) /*!< Quad mode enable */
  155. #define S25FL128S_CR1_BPNV ((uint8_t)0x08) /*!< BP2-0 bits of Status Reg are volatile */
  156. #define S25FL128S_CR1_TBPROT ((uint8_t)0x20) /*!< BPstarts at bottom */
  157. #define S25FL128S_CR1_LC_MASK ((uint8_t)0xC0) /*!< Latency Code mask */
  158. #define S25FL128S_CR1_LC0 ((uint8_t)0x00) /*!< Latency Code = 0 */
  159. #define S25FL128S_CR1_LC1 ((uint8_t)0x40) /*!< Latency Code = 1 */
  160. #define S25FL128S_CR1_LC2 ((uint8_t)0x80) /*!< Latency Code = 2 */
  161. #define S25FL128S_CR1_LC3 ((uint8_t)0xC0) /*!< Latency Code = 3 */
  162. /* AutoBoot Register */
  163. #define S25FL128S_AB_EN ((uint32_t)0x00000001) /*!< AutoBoot Enabled */
  164. #define S25FL128S_AB_SD_MASK ((uint32_t)0x000001FE) /*!< AutoBoot Start Delay mask */
  165. #define S25FL128S_AB_SA_MASK ((uint32_t)0xFFFFFE00) /*!< AutoBoot Start Address mask */
  166. /* Bank Address Register */
  167. #define S25FL128S_BA_BA24 ((uint8_t)0x01) /*!< A24 for 512 Mb device */
  168. #define S25FL128S_BA_BA25 ((uint8_t)0x02) /*!< A25 for 512 Mb device */
  169. #define S25FL128S_BA_EXTADD ((uint8_t)0x80) /*!< 4 bytes addressing required from command */
  170. /* ASP Register */
  171. #define S25FL128S_ASP_PSTMLB ((uint16_t)0x0002) /*!< Persistent protection mode not permanently enabled */
  172. #define S25FL128S_ASP_PWSMLB ((uint16_t)0x0003) /*!< Password protection mode not permanently enabled */
  173. /* PPB Lock Register */
  174. #define S25FL128S_PPBLOCK ((uint8_t)0x01) /*!< PPB array may be programmed or erased */
  175. /**
  176. * @}
  177. */
  178. /** @defgroup S25FL128S_Exported_Types S25FL128S Exported Types
  179. * @{
  180. */
  181. typedef struct {
  182. uint32_t FlashSize; /*!< Size of the flash */
  183. uint32_t EraseSectorSize; /*!< Size of sectors for the erase operation */
  184. uint32_t EraseSectorsNumber; /*!< Number of sectors for the erase operation */
  185. uint32_t ProgPageSize; /*!< Size of pages for the program operation */
  186. uint32_t ProgPagesNumber; /*!< Number of pages for the program operation */
  187. } S25FL128S_Info_t;
  188. typedef enum
  189. {
  190. S25FL128S_SPI_MODE = 0, /*!< 1-1-1 commands, Power on H/W default setting */
  191. S25FL128S_SPI_1I2O_MODE, /*!< 1-1-2 read commands */
  192. S25FL128S_SPI_2IO_MODE, /*!< 1-2-2 read commands */
  193. S25FL128S_SPI_1I4O_MODE, /*!< 1-1-4 read commands */
  194. S25FL128S_SPI_4IO_MODE, /*!< 1-4-4 read commands */
  195. S25FL128S_DPI_MODE, /*!< 2-2-2 commands */
  196. S25FL128S_QPI_MODE /*!< 4-4-4 commands */
  197. } S25FL128S_Interface_t;
  198. typedef enum
  199. {
  200. S25FL128S_STR_TRANSFER = 0, /*!< Single Transfer Rate */
  201. } S25FL128S_Transfer_t;
  202. typedef enum
  203. {
  204. S25FL128S_DUALFLASH_DISABLE = 0, /*!< Single flash mode */
  205. } S25FL128S_DualFlash_t;
  206. typedef enum
  207. {
  208. S25FL128S_ERASE_4K = 0, /*!< 4K size Sector erase */
  209. S25FL128S_ERASE_64K, /*!< 64K size Block erase */
  210. S25FL128S_ERASE_CHIP /*!< Whole chip erase */
  211. } S25FL128S_Erase_t;
  212. /**
  213. * @}
  214. */
  215. /** @defgroup S25FL128S_Exported_Functions
  216. * @{
  217. */
  218. int32_t S25FL128S_GetFlashInfo(S25FL128S_Info_t *pInfo);
  219. int32_t S25FL128S_AutoPollingMemReady(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode);
  220. int32_t S25FL128S_Enter4BytesAddressMode(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode);
  221. /* Register/Setting Commands *************************************************/
  222. int32_t S25FL128S_WriteEnable(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode);
  223. int32_t S25FL128S_BlockErase(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode, uint32_t BlockAddress, S25FL128S_Erase_t BlockSize);
  224. int32_t S25FL128S_ChipErase(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode);
  225. int32_t S25FL128S_PageProgram(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode, uint8_t *pData, uint32_t WriteAddr, uint32_t Size);
  226. int32_t S25FL128S_ReadSTR(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode, uint8_t *pData, uint32_t ReadAddr, uint32_t Size);
  227. int32_t S25FL128S_ReadStatusRegister(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode, uint8_t *Value);
  228. int32_t S25FL128S_EnableMemoryMappedModeSTR(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode);
  229. int32_t S25FL128S_WriteDisable(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode);
  230. int32_t S25FL128S_ReadID(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode, uint8_t *ID);
  231. int32_t S25FL128S_ResetMemory(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode);
  232. int32_t S25FL128S_ResetEnable(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode);
  233. int32_t S25FL128S_EnterDeepPowerDown(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode);
  234. int32_t S25FL128S_ProgEraseResume(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode);
  235. int32_t S25FL128S_ProgEraseSuspend(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode);
  236. int32_t S25FL128S_ReadSFDP(QSPI_HandleTypeDef *Ctx, S25FL128S_Interface_t Mode, uint8_t *pData, uint32_t ReadAddr, uint32_t Size);
  237. /**
  238. * @}
  239. */
  240. /**
  241. * @}
  242. */
  243. /**
  244. * @}
  245. */
  246. /**
  247. * @}
  248. */
  249. #ifdef __cplusplus
  250. }
  251. #endif
  252. #endif /* S25FL128S_H */