hal_w25qxx.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /**
  2. *******************************************************************************
  3. * @file w25qxx.c
  4. * @brief This midware 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. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hal_w25qxx.h"
  24. /**
  25. * @addtogroup BSP
  26. * @{
  27. */
  28. /**
  29. * @addtogroup Components
  30. * @{
  31. */
  32. /**
  33. * @defgroup W25QXX Flash Driver for W25QXX
  34. * @{
  35. */
  36. /*******************************************************************************
  37. * Local type definitions ('typedef')
  38. ******************************************************************************/
  39. /*******************************************************************************
  40. * Local pre-processor symbols/macros ('#define')
  41. ******************************************************************************/
  42. /**
  43. * @defgroup W25QXX_Local_Macros W25QXX Local Macros
  44. * @{
  45. */
  46. #define W25QXX_FLAG_BUSY (1UL << 0U)
  47. #define W25QXX_FLAG_WEL (1UL << 1U) /*!< Write Enable Latch */
  48. #define W25QXX_FLAG_SUSPEND (1UL << 15U) /*!< Write Enable Latch */
  49. #define LOAD_CMD(a, cmd, addr) do { \
  50. (a)[0U] = (cmd); \
  51. (a)[1U] = (uint8_t)((addr) >> 16U); \
  52. (a)[2U] = (uint8_t)((addr) >> 8U); \
  53. (a)[3U] = (uint8_t)(addr); \
  54. } while (0U)
  55. /**
  56. * @}
  57. */
  58. /*******************************************************************************
  59. * Global variable definitions (declared in header file with 'extern')
  60. ******************************************************************************/
  61. /*******************************************************************************
  62. * Local function prototypes ('static')
  63. ******************************************************************************/
  64. /*******************************************************************************
  65. * Local variable definitions ('static')
  66. ******************************************************************************/
  67. /*******************************************************************************
  68. * Function implementation - global ('extern') and local ('static')
  69. ******************************************************************************/
  70. /**
  71. * @addtogroup W25QXX_Local_Functions W25QXX Local Functions
  72. * @{
  73. */
  74. /**
  75. * @brief W25QXX write command.
  76. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  77. * @param [in] u8Cmd Command of W25QXX.
  78. * @param [in] pu8CmdData Pointer to a buffer that contains the data following the command.
  79. * @param [in] u32CmdDataLen The length of the command data in bytes.
  80. * @retval int32_t:
  81. * - LL_OK: No error occurred.
  82. * - LL_ERR_TIMEOUT: SPI timeout.
  83. */
  84. static int32_t W25QXX_WriteCmd(const stc_w25qxx_ll_t *pstcW25qxxLL, \
  85. uint8_t u8Cmd, const uint8_t *pu8CmdData, uint32_t u32CmdDataLen)
  86. {
  87. int32_t i32Ret;
  88. pstcW25qxxLL->Active();
  89. i32Ret = pstcW25qxxLL->Trans(&u8Cmd, 1U);
  90. if ((i32Ret == LL_OK) && (pu8CmdData != NULL) && (u32CmdDataLen > 0UL)) {
  91. i32Ret = pstcW25qxxLL->Trans(pu8CmdData, u32CmdDataLen);
  92. }
  93. pstcW25qxxLL->Inactive();
  94. return i32Ret;
  95. }
  96. /**
  97. * @brief W25QXX read command.
  98. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  99. * @param [in] u8Cmd Command of W25QXX.
  100. * @param [in] pu8CmdData Pointer to a buffer that contains the data following the command.
  101. * @param [in] u32CmdDataLen The length of the command data in bytes.
  102. * @param [in] pu8Info The information of the command.
  103. * @param [in] u8InfoLen The length of the information.
  104. * @retval int32_t:
  105. * - LL_OK: No error occurred.
  106. * - LL_ERR_TIMEOUT: SPI timeout.
  107. */
  108. static int32_t W25QXX_ReadCmd(const stc_w25qxx_ll_t *pstcW25qxxLL, \
  109. uint8_t u8Cmd, uint8_t *pu8CmdData, uint32_t u32CmdDataLen,
  110. uint8_t *pu8Info, uint8_t u8InfoLen)
  111. {
  112. int32_t i32Ret;
  113. pstcW25qxxLL->Active();
  114. i32Ret = pstcW25qxxLL->Trans(&u8Cmd, 1U);
  115. if ((i32Ret == LL_OK) && (pu8CmdData != NULL) && (u32CmdDataLen > 0UL)) {
  116. i32Ret = pstcW25qxxLL->Trans(pu8CmdData, u32CmdDataLen);
  117. }
  118. if ((i32Ret == LL_OK) && (pu8Info != NULL) && (u8InfoLen > 0UL)) {
  119. i32Ret = pstcW25qxxLL->Receive(pu8Info, (uint32_t)u8InfoLen);
  120. }
  121. pstcW25qxxLL->Inactive();
  122. return i32Ret;
  123. }
  124. /**
  125. * @brief W25QXX write data.
  126. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  127. * @param [in] u8Cmd Command of W25QXX.
  128. * @param [in] u32Addr The start address of the data to be written.
  129. * @param [in] pu8Data The data to be written.
  130. * @param [in] u32DataLen The length of the data in bytes.
  131. * @retval int32_t:
  132. * - LL_OK: No error occurred.
  133. * - LL_ERR_TIMEOUT: SPI timeout.
  134. */
  135. static int32_t W25QXX_Wt(const stc_w25qxx_ll_t *pstcW25qxxLL, \
  136. uint8_t u8Cmd, uint32_t u32Addr, \
  137. const uint8_t *pu8Data, uint32_t u32DataLen)
  138. {
  139. uint8_t au8Cmd[4U];
  140. int32_t i32Ret;
  141. LOAD_CMD(au8Cmd, u8Cmd, u32Addr);
  142. pstcW25qxxLL->Active();
  143. i32Ret = pstcW25qxxLL->Trans(au8Cmd, 4U);
  144. if ((i32Ret == LL_OK) && (pu8Data != NULL) && (u32DataLen > 0UL)) {
  145. i32Ret = pstcW25qxxLL->Trans(pu8Data, u32DataLen);
  146. }
  147. pstcW25qxxLL->Inactive();
  148. return i32Ret;
  149. }
  150. /**
  151. * @brief W25QXX read data.
  152. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  153. * @param [in] u8Cmd Command of W25QXX.
  154. * @param [in] u32Addr The start address of the data to be written.
  155. * @param [in] pu8Data The data to be stored.
  156. * @param [in] u32DataLen The length of the data in bytes.
  157. * @retval int32_t:
  158. * - LL_OK: No error occurred.
  159. * - LL_ERR_TIMEOUT: SPI timeout.
  160. */
  161. static int32_t W25QXX_Rd(const stc_w25qxx_ll_t *pstcW25qxxLL, \
  162. uint8_t u8Cmd, uint32_t u32Addr, \
  163. uint8_t *pu8Data, uint32_t u32DataLen)
  164. {
  165. uint8_t au8Cmd[4U];
  166. int32_t i32Ret;
  167. LOAD_CMD(au8Cmd, u8Cmd, u32Addr);
  168. pstcW25qxxLL->Active();
  169. i32Ret = pstcW25qxxLL->Trans(au8Cmd, 4U);
  170. if (i32Ret == LL_OK) {
  171. i32Ret = pstcW25qxxLL->Receive(pu8Data, u32DataLen);
  172. }
  173. pstcW25qxxLL->Inactive();
  174. return i32Ret;
  175. }
  176. /**
  177. * @brief W25QXX Write enable.
  178. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  179. * @retval int32_t:
  180. * - LL_OK: No error occurred.
  181. * - LL_ERR_TIMEOUT: SPI timeout.
  182. */
  183. static int32_t W25QXX_WriteEnable(const stc_w25qxx_ll_t *pstcW25qxxLL)
  184. {
  185. return W25QXX_WriteCmd(pstcW25qxxLL, W25QXX_WRITE_ENABLE, NULL, 0U);
  186. }
  187. /**
  188. * @brief W25QXX Write disable.
  189. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  190. * @retval int32_t:
  191. * - LL_OK: No error occurred.
  192. * - LL_ERR_TIMEOUT: SPI timeout.
  193. */
  194. static int32_t W25QXX_WriteDisable(const stc_w25qxx_ll_t *pstcW25qxxLL)
  195. {
  196. return W25QXX_WriteCmd(pstcW25qxxLL, W25QXX_WRITE_DISABLE, NULL, 0U);
  197. }
  198. /**
  199. * @brief Wait for processing done.
  200. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  201. * @retval int32_t:
  202. * - LL_OK: No error occurred.
  203. * - LL_ERR_TIMEOUT: SPI timeout or W25QXX timeout.
  204. */
  205. static int32_t W25QXX_WaitProcessDone(const stc_w25qxx_ll_t *pstcW25qxxLL)
  206. {
  207. uint8_t u8Status;
  208. int32_t i32Ret = LL_ERR_TIMEOUT;
  209. volatile uint32_t u32Timecount = W25QXX_TIMEOUT;
  210. while (u32Timecount-- != 0UL) {
  211. i32Ret = W25QXX_ReadStatus(pstcW25qxxLL, W25QXX_READ_STATUS_REGISTER_1, &u8Status);
  212. if ((i32Ret == LL_OK) && ((u8Status & W25QXX_FLAG_BUSY) == 0U)) {
  213. break;
  214. }
  215. }
  216. return i32Ret;
  217. }
  218. /**
  219. * @}
  220. */
  221. /**
  222. * @defgroup W25QXX_Global_Functions W25QXX Global Functions
  223. * @{
  224. */
  225. /**
  226. * @brief Initializes W25QXX.
  227. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  228. * @retval int32_t:
  229. * - LL_OK: No error occurred.
  230. * - LL_ERR_INVD_PARAM: Invalid parameter
  231. */
  232. int32_t W25QXX_Init(const stc_w25qxx_ll_t *pstcW25qxxLL)
  233. {
  234. int32_t i32Ret = LL_ERR_INVD_PARAM;
  235. if (pstcW25qxxLL != NULL) {
  236. pstcW25qxxLL->Init();
  237. i32Ret = LL_OK;
  238. }
  239. return i32Ret;
  240. }
  241. /**
  242. * @brief De-Initialize W25QXX.
  243. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  244. * @retval int32_t:
  245. * - LL_OK: No error occurred.
  246. * - LL_ERR_INVD_PARAM: Invalid parameter
  247. */
  248. int32_t W25QXX_DeInit(const stc_w25qxx_ll_t *pstcW25qxxLL)
  249. {
  250. int32_t i32Ret = LL_ERR_INVD_PARAM;
  251. if (pstcW25qxxLL != NULL) {
  252. pstcW25qxxLL->DeInit();
  253. i32Ret = LL_OK;
  254. }
  255. return i32Ret;
  256. }
  257. /**
  258. * @brief Read manufacturer device ID.
  259. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  260. * @param [out] pu16ID Pointer to an address to store the device ID.
  261. * @retval int32_t:
  262. * - LL_OK: No error occurred.
  263. * - LL_ERR_INVD_PARAM: Invalid parameter.
  264. * - LL_ERR_TIMEOUT: SPI timeout.
  265. */
  266. int32_t W25QXX_GetManDeviceId(const stc_w25qxx_ll_t *pstcW25qxxLL, uint16_t *pu16ID)
  267. {
  268. uint8_t au8TempId[2U];
  269. uint8_t au8Dummy[3U] = {0U};
  270. uint16_t u16ManID;
  271. int32_t i32Ret = LL_ERR_INVD_PARAM;
  272. if ((pstcW25qxxLL != NULL) && (pu16ID != NULL)) {
  273. i32Ret = W25QXX_ReadCmd(pstcW25qxxLL, W25QXX_MANUFACTURER_DEVICE_ID, au8Dummy, 3U, au8TempId, 2U);
  274. if (i32Ret == LL_OK) {
  275. u16ManID = (uint16_t)au8TempId[0U] << 8U;
  276. u16ManID |= au8TempId[1U];
  277. *pu16ID = u16ManID;
  278. }
  279. }
  280. return i32Ret;
  281. }
  282. /**
  283. * @brief Read unique ID.
  284. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  285. * @param [out] pu8UniqueId Pointer to a buffer the 64 bit unique ID to be stored.
  286. * @retval int32_t:
  287. * - LL_OK: No error occurred.
  288. * - LL_ERR_INVD_PARAM: Invalid parameter.
  289. * - LL_ERR_TIMEOUT: SPI timeout.
  290. */
  291. int32_t W25QXX_GetUniqueId(const stc_w25qxx_ll_t *pstcW25qxxLL, uint8_t *pu8UniqueId)
  292. {
  293. uint8_t au8Dummy[4U] = {0U};
  294. int32_t i32Ret = LL_ERR_INVD_PARAM;
  295. if ((pstcW25qxxLL != NULL) && (pu8UniqueId != NULL)) {
  296. i32Ret = W25QXX_ReadCmd(pstcW25qxxLL, W25QXX_READ_UNIQUE_ID, au8Dummy, 4U, pu8UniqueId, 8U);
  297. }
  298. return i32Ret;
  299. }
  300. /**
  301. * @brief Read status register.
  302. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  303. * @param [in] u8SrRdCmd Command of reading status register.
  304. * @arg W25QXX_READ_STATUS_REGISTER_1: Read status register 1.
  305. * @arg W25QXX_READ_STATUS_REGISTER_2: Read status register 2.
  306. * @arg W25QXX_READ_STATUS_REGISTER_3: Read status register 3.
  307. * @param [out] pu8Status Pointer to an address the status value to be stored.
  308. * @retval int32_t:
  309. * - LL_OK: No error occurred.
  310. * - LL_ERR_INVD_PARAM: Invalid parameter.
  311. * - LL_ERR_TIMEOUT: SPI timeout.
  312. */
  313. int32_t W25QXX_ReadStatus(const stc_w25qxx_ll_t *pstcW25qxxLL, uint8_t u8SrRdCmd, uint8_t *pu8Status)
  314. {
  315. int32_t i32Ret = LL_ERR_INVD_PARAM;
  316. if ((pstcW25qxxLL != NULL) && (pu8Status != NULL)) {
  317. i32Ret = W25QXX_ReadCmd(pstcW25qxxLL, u8SrRdCmd, NULL, 0U, pu8Status, 1U);
  318. }
  319. return i32Ret;
  320. }
  321. /**
  322. * @brief Write status register.
  323. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  324. * @param [in] u8SrWtCmd Command of writting status register.
  325. * @arg W25QXX_WRITE_STATUS_REGISTER_1: Write status register 1.
  326. * @arg W25QXX_WRITE_STATUS_REGISTER_2: Write status register 2.
  327. * @arg W25QXX_WRITE_STATUS_REGISTER_3: Write status register 3.
  328. * @param [in] u8Value 8bit value of the specified status register.
  329. * @retval int32_t:
  330. * - LL_OK: No error occurred.
  331. * - LL_ERR_INVD_PARAM: Invalid parameter.
  332. * - LL_ERR_TIMEOUT: SPI timeout.
  333. */
  334. int32_t W25QXX_WriteStatus(const stc_w25qxx_ll_t *pstcW25qxxLL, uint8_t u8SrWtCmd, uint8_t u8Value)
  335. {
  336. int32_t i32Ret = LL_ERR_INVD_PARAM;
  337. if (pstcW25qxxLL != NULL) {
  338. i32Ret = W25QXX_WriteCmd(pstcW25qxxLL, u8SrWtCmd, &u8Value, 1U);
  339. }
  340. return i32Ret;
  341. }
  342. /**
  343. * @brief Power down.
  344. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  345. * @retval int32_t:
  346. * - LL_OK: No error occurred.
  347. * - LL_ERR_INVD_PARAM: Invalid parameter.
  348. * - LL_ERR_TIMEOUT: SPI timeout.
  349. */
  350. int32_t W25QXX_PowerDown(const stc_w25qxx_ll_t *pstcW25qxxLL)
  351. {
  352. int32_t i32Ret = LL_ERR_INVD_PARAM;
  353. if (pstcW25qxxLL != NULL) {
  354. i32Ret = W25QXX_WriteCmd(pstcW25qxxLL, W25QXX_POWER_DOWN, NULL, 0U);
  355. if (i32Ret == LL_OK) {
  356. pstcW25qxxLL->Delay(1U);
  357. }
  358. }
  359. return i32Ret;
  360. }
  361. /**
  362. * @brief Release power down.
  363. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  364. * @retval int32_t:
  365. * - LL_OK: No error occurred.
  366. * - LL_ERR_INVD_PARAM: Invalid parameter.
  367. * - LL_ERR_TIMEOUT: SPI timeout.
  368. */
  369. int32_t W25QXX_ReleasePowerDown(const stc_w25qxx_ll_t *pstcW25qxxLL)
  370. {
  371. int32_t i32Ret = LL_ERR_INVD_PARAM;
  372. if (pstcW25qxxLL != NULL) {
  373. i32Ret = W25QXX_WriteCmd(pstcW25qxxLL, W25QXX_RELEASE_POWER_DOWN_ID, NULL, 0U);
  374. if (i32Ret == LL_OK) {
  375. pstcW25qxxLL->Delay(1U);
  376. }
  377. }
  378. return i32Ret;
  379. }
  380. /**
  381. * @brief Ease chip.
  382. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  383. * @retval int32_t:
  384. * - LL_OK: No error occurred.
  385. * - LL_ERR_INVD_PARAM: Invalid parameter.
  386. * - LL_ERR_TIMEOUT: SPI timeout or W25QXX timeout.
  387. */
  388. int32_t W25QXX_EraseChip(const stc_w25qxx_ll_t *pstcW25qxxLL)
  389. {
  390. int32_t i32Ret = LL_ERR_INVD_PARAM;
  391. if (pstcW25qxxLL != NULL) {
  392. i32Ret = W25QXX_WriteEnable(pstcW25qxxLL);
  393. if (i32Ret == LL_OK) {
  394. i32Ret = W25QXX_WaitProcessDone(pstcW25qxxLL);
  395. }
  396. if (i32Ret == LL_OK) {
  397. i32Ret = W25QXX_WriteCmd(pstcW25qxxLL, W25QXX_CHIP_ERASE, NULL, 0U);
  398. }
  399. if (i32Ret == LL_OK) {
  400. i32Ret = W25QXX_WaitProcessDone(pstcW25qxxLL);
  401. }
  402. }
  403. return i32Ret;
  404. }
  405. /**
  406. * @brief Ease sector.
  407. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  408. * @param [in] u32Addr Any address of the specified sector.
  409. * @retval int32_t:
  410. * - LL_OK: No error occurred.
  411. * - LL_ERR_INVD_PARAM: Invalid parameter.
  412. * - LL_ERR_TIMEOUT: SPI timeout or W25QXX timeout.
  413. */
  414. int32_t W25QXX_EraseSector(const stc_w25qxx_ll_t *pstcW25qxxLL, uint32_t u32Addr)
  415. {
  416. int32_t i32Ret = LL_ERR_INVD_PARAM;
  417. if (pstcW25qxxLL != NULL) {
  418. i32Ret = W25QXX_WriteEnable(pstcW25qxxLL);
  419. if (i32Ret == LL_OK) {
  420. i32Ret = W25QXX_WaitProcessDone(pstcW25qxxLL);
  421. }
  422. if (i32Ret == LL_OK) {
  423. i32Ret = W25QXX_Wt(pstcW25qxxLL, W25QXX_SECTOR_ERASE, u32Addr, NULL, 0U);
  424. }
  425. if (i32Ret == LL_OK) {
  426. i32Ret = W25QXX_WaitProcessDone(pstcW25qxxLL);
  427. }
  428. if (i32Ret == LL_OK) {
  429. i32Ret = W25QXX_WriteDisable(pstcW25qxxLL);
  430. }
  431. }
  432. return i32Ret;
  433. }
  434. /**
  435. * @brief W25QXX read data.
  436. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  437. * @param [in] u32Addr The start address of the data to be read.
  438. * @param [in] pu8ReadBuf The pointer to the buffer contains the data to be stored.
  439. * @param [in] u32NumByteToRead Buffer size in bytes.
  440. * @retval int32_t:
  441. * - LL_OK: No error occurred.
  442. * - LL_ERR_INVD_PARAM: Invalid parameter.
  443. * - LL_ERR_TIMEOUT: SPI timeout.
  444. */
  445. int32_t W25QXX_ReadData(const stc_w25qxx_ll_t *pstcW25qxxLL, uint32_t u32Addr, \
  446. uint8_t *pu8ReadBuf, uint32_t u32NumByteToRead)
  447. {
  448. int32_t i32Ret = LL_ERR_INVD_PARAM;
  449. if ((pstcW25qxxLL != NULL) && (pu8ReadBuf != NULL) && (u32NumByteToRead != 0UL)) {
  450. i32Ret = W25QXX_Rd(pstcW25qxxLL, W25QXX_READ_DATA, u32Addr, pu8ReadBuf, u32NumByteToRead);
  451. }
  452. return i32Ret;
  453. }
  454. /**
  455. * @brief W25QXX page program.
  456. * @param [in] pstcW25qxxLL Pointer to a @ref stc_w25qxx_ll_t structure.
  457. * @param [in] u32Addr Start address of the page.
  458. * @param [in] pu8Data Pointer to a buffer that contains the data to be written.
  459. * @param [in] u32NumByteToProgram Size of the buffer.
  460. * @retval int32_t:
  461. * - LL_OK: No error occurred.
  462. * - LL_ERR_INVD_PARAM: Invalid parameter.
  463. * - LL_ERR_TIMEOUT: SPI timeout or W25QXX timeout.
  464. */
  465. int32_t W25QXX_PageProgram(const stc_w25qxx_ll_t *pstcW25qxxLL, uint32_t u32Addr, \
  466. const uint8_t *pu8Data, uint32_t u32NumByteToProgram)
  467. {
  468. int32_t i32Ret = LL_ERR_INVD_PARAM;
  469. if ((pstcW25qxxLL != NULL) && (pu8Data != NULL) && (u32NumByteToProgram != 0UL)) {
  470. i32Ret = W25QXX_WriteEnable(pstcW25qxxLL);
  471. if (i32Ret == LL_OK) {
  472. i32Ret = W25QXX_Wt(pstcW25qxxLL, W25QXX_PAGE_PROGRAM, u32Addr, pu8Data, u32NumByteToProgram);
  473. }
  474. if (i32Ret == LL_OK) {
  475. i32Ret = W25QXX_WaitProcessDone(pstcW25qxxLL);
  476. }
  477. }
  478. return i32Ret;
  479. }
  480. /**
  481. * @}
  482. */
  483. /**
  484. * @}
  485. */
  486. /**
  487. * @}
  488. */
  489. /**
  490. * @}
  491. */
  492. /*******************************************************************************
  493. * EOF (not truncated)
  494. ******************************************************************************/