hal_w25qxx.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**
  2. *******************************************************************************
  3. * @file w25qxx.h
  4. * @brief This file provides firmware functions to W25QXX group spi flash.
  5. @verbatim
  6. Change Logs:
  7. Date Author Notes
  8. 2022-03-31 CDT First version
  9. @endverbatim
  10. *******************************************************************************
  11. * Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved.
  12. *
  13. * This software component is licensed by XHSC under BSD 3-Clause license
  14. * (the "License"); You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. *******************************************************************************
  19. */
  20. #ifndef __HAL_W25QXX_H__
  21. #define __HAL_W25QXX_H__
  22. /* C binding of definitions if building with C++ compiler */
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. /*******************************************************************************
  28. * Include files
  29. ******************************************************************************/
  30. #include "hc32_ll_def.h"
  31. /**
  32. * @addtogroup BSP
  33. * @{
  34. */
  35. /**
  36. * @addtogroup Components
  37. * @{
  38. */
  39. /**
  40. * @addtogroup W25QXX
  41. * @{
  42. */
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /**
  47. * @brief W25QXX low layer structure definition
  48. */
  49. typedef struct {
  50. void (*Delay)(uint32_t);
  51. void (*Init)(void);
  52. void (*DeInit)(void);
  53. void (*Active)(void);
  54. void (*Inactive)(void);
  55. int32_t (*Trans)(const uint8_t *, uint32_t);
  56. int32_t (*Receive)(uint8_t *, uint32_t);
  57. } stc_w25qxx_ll_t;
  58. /*******************************************************************************
  59. * Global pre-processor symbols/macros ('#define')
  60. ******************************************************************************/
  61. /**
  62. * @defgroup W25QXX_Global_Macros W25QXX Global Macros
  63. * @{
  64. */
  65. /**
  66. * @defgroup W25QXX_ID W25QXX ID
  67. * @{
  68. */
  69. #define W25Q80 (0xEF13U)
  70. #define W25Q16 (0xEF14U)
  71. #define W25Q32 (0xEF15U)
  72. #define W25Q64 (0xEF16U)
  73. #define W25Q128 (0xEF17U)
  74. /**
  75. * @}
  76. */
  77. /**
  78. * @defgroup W25QXX_Command W25QXX Command
  79. * @{
  80. */
  81. #define W25QXX_WRITE_ENABLE (0x06U)
  82. #define W25QXX_VOLATILE_SR_WRITE_ENABLE (0x50U)
  83. #define W25QXX_WRITE_DISABLE (0x04U)
  84. #define W25QXX_RELEASE_POWER_DOWN_ID (0xABU)
  85. #define W25QXX_MANUFACTURER_DEVICE_ID (0x90U)
  86. #define W25QXX_JEDEC_ID (0x9FU)
  87. #define W25QXX_READ_UNIQUE_ID (0x4BU)
  88. #define W25QXX_READ_DATA (0x03U)
  89. #define W25QXX_FAST_READ (0x0BU)
  90. #define W25QXX_PAGE_PROGRAM (0x02U)
  91. #define W25QXX_SECTOR_ERASE (0x20U)
  92. #define W25QXX_BLOCK_ERASE_32KB (0x52U)
  93. #define W25QXX_BLOCK_ERASE_64KB (0xD8U)
  94. #define W25QXX_CHIP_ERASE (0xC7U)
  95. #define W25QXX_READ_STATUS_REGISTER_1 (0x05U)
  96. #define W25QXX_WRITE_STATUS_REGISTER_1 (0x01U)
  97. #define W25QXX_READ_STATUS_REGISTER_2 (0x35U)
  98. #define W25QXX_WRITE_STATUS_REGISTER_2 (0x31U)
  99. #define W25QXX_READ_STATUS_REGISTER_3 (0x15U)
  100. #define W25QXX_WRITE_STATUS_REGISTER_3 (0x11U)
  101. #define W25QXX_READ_SFDP_REGISTER (0x5AU)
  102. #define W25QXX_ERASE_SECURITY_REGISTER (0x44U)
  103. #define W25QXX_PROGRAM_SECURITY_REGISTER (0x42U)
  104. #define W25QXX_READ_SECURITY_REGISTER (0x48U)
  105. #define W25QXX_GLOBAL_BLOCK_LOCK (0x7EU)
  106. #define W25QXX_GLOBAL_BLOCK_UNLOCK (0x98U)
  107. #define W25QXX_READ_BLOCK_LOCK (0x3DU)
  108. #define W25QXX_INDIVIDUAL_BLOCK_LOCK (0x36U)
  109. #define W25QXX_INDIVIDUAL_BLOCK_UNLOCK (0x39U)
  110. #define W25QXX_ERASE_PROGRAM_SUSPEND (0x75U)
  111. #define W25QXX_ERASE_PROGRAM_RESUME (0x7AU)
  112. #define W25QXX_POWER_DOWN (0xB9U)
  113. #define W25QXX_ENABLE_RESET (0x66U)
  114. #define W25QXX_RESET_DEVICE (0x99U)
  115. /**
  116. * @}
  117. */
  118. /**
  119. * @defgroup W25QXX_Timeout_Value W25QXX Timeout Value
  120. * @{
  121. */
  122. #define W25QXX_TIMEOUT (100000UL)
  123. /**
  124. * @}
  125. */
  126. /**
  127. * @}
  128. */
  129. /*******************************************************************************
  130. * Global variable definitions ('extern')
  131. ******************************************************************************/
  132. /*******************************************************************************
  133. Global function prototypes (definition in C source)
  134. ******************************************************************************/
  135. /**
  136. * @addtogroup W25QXX_Global_Functions W25QXX Global Functions
  137. * @{
  138. */
  139. int32_t W25QXX_Init(const stc_w25qxx_ll_t *pstcW25qxxLL);
  140. int32_t W25QXX_DeInit(const stc_w25qxx_ll_t *pstcW25qxxLL);
  141. int32_t W25QXX_GetManDeviceId(const stc_w25qxx_ll_t *pstcW25qxxLL, uint16_t *pu16ID);
  142. int32_t W25QXX_GetUniqueId(const stc_w25qxx_ll_t *pstcW25qxxLL, uint8_t *pu8UniqueId);
  143. int32_t W25QXX_ReadStatus(const stc_w25qxx_ll_t *pstcW25qxxLL, uint8_t u8SrRdCmd, uint8_t *pu8Status);
  144. int32_t W25QXX_WriteStatus(const stc_w25qxx_ll_t *pstcW25qxxLL, uint8_t u8SrWtCmd, uint8_t u8Value);
  145. int32_t W25QXX_PowerDown(const stc_w25qxx_ll_t *pstcW25qxxLL);
  146. int32_t W25QXX_ReleasePowerDown(const stc_w25qxx_ll_t *pstcW25qxxLL);
  147. int32_t W25QXX_EraseChip(const stc_w25qxx_ll_t *pstcW25qxxLL);
  148. int32_t W25QXX_EraseSector(const stc_w25qxx_ll_t *pstcW25qxxLL, uint32_t u32Addr);
  149. int32_t W25QXX_ReadData(const stc_w25qxx_ll_t *pstcW25qxxLL, uint32_t u32Addr, uint8_t *pu8ReadBuf, uint32_t u32NumByteToRead);
  150. int32_t W25QXX_PageProgram(const stc_w25qxx_ll_t *pstcW25qxxLL, uint32_t u32Addr, const uint8_t *pu8Data, uint32_t u32NumByteToProgram);
  151. /**
  152. * @}
  153. */
  154. /**
  155. * @}
  156. */
  157. /**
  158. * @}
  159. */
  160. /**
  161. * @}
  162. */
  163. #ifdef __cplusplus
  164. }
  165. #endif
  166. #endif /* __W25QXX_H__ */
  167. /*******************************************************************************
  168. * EOF (not truncated)
  169. ******************************************************************************/