hal_exflash.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file hal_exflash.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of EXFLASH HAL library.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2019 GOODIX
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of GOODIX nor the names of its contributors may be used
21  to endorse or promote products derived from this software without
22  specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE.
35  ****************************************************************************************
36  */
37 
38 /** @addtogroup PERIPHERAL Peripheral Driver
39  * @{
40  */
41 
42 /** @addtogroup HAL_DRIVER HAL Driver
43  * @{
44  */
45 
46 /** @defgroup HAL_EXFLASH EXFLASH
47  * @brief exFlash HAL module driver.
48  * @{
49  */
50 
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef ___HAL_EXFLASH_H__
53 #define ___HAL_EXFLASH_H__
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "ll_xqspi.h"
61 #include "hal_xqspi.h"
62 #include "hal_def.h"
63 
64 /* Exported types ------------------------------------------------------------*/
65 /**
66  * @defgroup HAL_EXFLASH_MACRO Defines
67  * @{
68  */
69 
70 /* Exported constants --------------------------------------------------------*/
71 /** @defgroup EXFLASH_EXPORTED_CONSTANTS EXFLASH Exported Constants
72  * @{
73  */
74 
75 /** @defgroup EXFLASH_ERROR_CODE EXFLASH Error Code
76  * @{
77  */
78 #define EXFLASH_ERROR_NONE ((uint32_t)0x00000000) /**< No error */
79 #define EXFLASH_ERROR_TIMEOUT ((uint32_t)0x00000001) /**< Timeout error */
80 #define EXFLASH_ERROR_STATUS ((uint32_t)0x00000002) /**< Timeout error */
81 #define EXFLASH_ERROR_TRANSFER ((uint32_t)0x00000003) /**< Transfer error */
82 #define EXFLASH_ERROR_ID ((uint32_t)0x00000004) /**< Flash ID error */
83 #define EXFLASH_ERROR_QUAD ((uint32_t)0x00000005) /**< Quad mode error */
84 #define EXFLASH_ERROR_INVALID_PARAM ((uint32_t)0x00000006) /**< Invalid parameters error */
85 #define EXFLASH_ERROR_INIT ((uint32_t)0x00000007) /**< Invalid parameters error */
86 #define EXFLASH_ERROR_DEINIT ((uint32_t)0x00000008) /**< Invalid parameters error */
87 #define EXFLASH_ERROR_WAKEUP ((uint32_t)0x00000009) /**< Invalid parameters error */
88 #define EXFLASH_ERROR_DEEPSLEEP ((uint32_t)0x0000000A) /**< Invalid parameters error */
89 #define EXFLASH_ERROR_SUSPEND ((uint32_t)0x0000000B) /**< Invalid parameters error */
90 #define EXFLASH_ERROR_RESUME ((uint32_t)0x0000000C) /**< Invalid parameters error */
91 #define EXFLASH_ERROR_LOCK ((uint32_t)0x0000000D) /**< Invalid parameters error */
92 #define EXFLASH_ERROR_UNLOCK ((uint32_t)0x0000000E) /**< Invalid parameters error */
93 #define EXFLASH_ERROR_RESET ((uint32_t)0x0000000F) /**< Invalid parameters error */
94 #define EXFLASH_ERROR_ENABLE_QUAD ((uint32_t)0x00000010) /**< Invalid parameters error */
95 #define EXFLASH_ERROR_BUSY ((uint32_t)0x00000011) /**< Invalid parameters error */
96 /** @} */
97 
98 /** @defgroup EXFLASH_PROTECTED_AREA_SIZE EXFLASH Protected Area Sizes
99  * @{
100  */
101 #define EXFLASH_PROTECT_AREA_00000 0x00 /**< If CMP set to 0, Non-Protection blocks. If CMP set to 1, All Block Protected. */
102 #define EXFLASH_PROTECT_AREA_00001 0x01 /**< If CMP set to 0, the protected data portion is the upper 1/8 of flash memory,
103  If CMP set to 1, the protected data portion is the lower 7/8 of flash memory */
104 #define EXFLASH_PROTECT_AREA_00010 0x02 /**< If CMP set to 0, the protected data portion is the upper 1/4 of flash memory,
105  If CMP set to 1, the protected data portion is the lower 3/4 of flash memory */
106 #define EXFLASH_PROTECT_AREA_00011 0x03 /**< If CMP set to 0, the protected data portion is the upper 1/2 of flash memory,
107  If CMP set to 1, the protected data portion is the lower 1/2 of flash memory */
108 #define EXFLASH_PROTECT_AREA_01001 0x09 /**< If CMP set to 0, the protected data portion is the lower 1/8 of flash memory,
109  If CMP set to 1, the protected data portion is the upper 7/8 of flash memory */
110 #define EXFLASH_PROTECT_AREA_01010 0x0A /**< If CMP set to 0, the protected data portion is the lower 1/4 of flash memory,
111  If CMP set to 1, the protected data portion is the upper 3/4 of flash memory */
112 #define EXFLASH_PROTECT_AREA_01011 0x0B /**< If CMP set to 0, the protected data portion is the lower 1/2 of flash memory,
113  If CMP set to 1, the protected data portion is the upper 1/2 of flash memory */
114 #define EXFLASH_PROTECT_AREA_00100 0x04 /**< If CMP set to 0, All Block Protected, If CMP set to 1, Non-Protection blocks */
115 #define EXFLASH_PROTECT_AREA_10001 0x11 /**< If CMP set to 0, the protected data portion is the upper 1/128 of flash memory,
116  If CMP set to 1, the protected data portion is the lower 127/128 of flash memory */
117 #define EXFLASH_PROTECT_AREA_10010 0x12 /**< If CMP set to 0, the protected data portion is the upper 1/64 of flash memory,
118  If CMP set to 1, the protected data portion is the lower 63/64 of flash memory */
119 #define EXFLASH_PROTECT_AREA_10011 0x13 /**< If CMP set to 0, the protected data portion is the upper 1/32 of flash memory,
120  If CMP set to 1, the protected data portion is the lower 31/32 of flash memory */
121 #define EXFLASH_PROTECT_AREA_10100 0x14 /**< If CMP set to 0, the protected data portion is the upper 1/16 of flash memory,
122  If CMP set to 1, the protected data portion is the lower 15/16 of flash memory */
123 #define EXFLASH_PROTECT_AREA_10110 0x16 /**< If CMP set to 0, the protected data portion is the upper 1/16 of flash memory,
124  If CMP set to 1, the protected data portion is the lower 15/16 of flash memory */
125 #define EXFLASH_PROTECT_AREA_11001 0x19 /**< If CMP set to 0, the protected data portion is the lower 1/128 of flash memory,
126  If CMP set to 1, the protected data portion is the upper 127/128 of flash memory */
127 #define EXFLASH_PROTECT_AREA_11010 0x1A /**< If CMP set to 0, the protected data portion is the lower 1/64 of flash memory,
128  If CMP set to 1, the protected data portion is the upper 63/64 of flash memory */
129 #define EXFLASH_PROTECT_AREA_11011 0x1B /**< If CMP set to 0, the protected data portion is the lower 1/32 of flash memory,
130  If CMP set to 1, the protected data portion is the upper 31/32 of flash memory */
131 #define EXFLASH_PROTECT_AREA_11100 0x1C /**< If CMP set to 0, the protected data portion is the lower 1/16 of flash memory,
132  If CMP set to 1, the protected data portion is the upper 15/16 of flash memory */
133 #define EXFLASH_PROTECT_AREA_11110 0x1E /**< If CMP set to 0, the protected data portion is the lower 1/16 of flash memory,
134  If CMP set to 1, the protected data portion is the upper 15/16 of flash memory */
135 #define EXFLASH_PROTECT_AREA_11111 0x1F /**< If CMP set to 0, All Block Protected, If CMP set to 1, Non-Protection blocks */
136 /** @} */
137 
138 /** @defgroup EXFLASH_OTP_LOCK EXFLASH OTP Locked
139  * @{
140  */
141 #define EXFLASH_LOCK_OTP 0x01 /**< Security register #1#2#3#4 */
142 /** @} */
143 
144 /** @defgroup EXFLASH_ERASE_TYPE EXFLASH Erase Type
145  * @{
146  */
147 #define EXFLASH_ERASE_SECTOR 0 /**< Sector erase */
148 #define EXFLASH_ERASE_BLOCK32K 1 /**< block32 erase */
149 #define EXFLASH_ERASE_BLOCK 2 /**< block erase */
150 #define EXFLASH_ERASE_CHIP 3 /**< Chip erase */
151 /** @} */
152 
153 /** @defgroup EXFLASH_BLOCK_PROTECT EXFLASH Block Protect
154  * @{
155  */
156 #define EXFLASH_SINGLE_PAGE_TYPE 0 /**< single page */
157 #define EXFLASH_DUAL_PAGE_TYPE 1 /**< dual page */
158 /** @} */
159 
160 /** @defgroup EXFLASH_OTP_ADDR EXFLASH OTP Address
161  * @{
162  */
163 #define EXFLASH_OTP_BASEADDR1 0x000000 /**< Security register #1 */
164 #define EXFLASH_OTP_BASEADDR2 0x000100 /**< Security register #2 */
165 #define EXFLASH_OTP_BASEADDR3 0x000200 /**< Security register #3 */
166 #define EXFLASH_OTP_BASEADDR4 0x000300 /**< Security register #4 */
167 /** @} */
168 
169 
170 /** @defgroup EXFLASH_SIZE_INFO EXFLASH Size Information
171  * @{
172  */
173 #define EXFLASH_SIZE_PAGE_BYTES ((uint32_t)256) /**< Page size in Bytes */
174 #define EXFLASH_SIZE_SECTOR_BYTES ((uint32_t)4096) /**< Sector size in Bytes */
175 #define EXFLASH_SIZE_BLOCK_32K_BYTES ((uint32_t)32768) /**< block_32K size in Bytes */
176 #define EXFLASH_SIZE_BLOCK_BYTES ((uint32_t)65536) /**< block size in Bytes */
177 
178 #define EXFLASH_SIZE_CHIP_BYTES ((uint32_t)0x800000) /**< Chip size in Bytes */
179 #define EXFLASH_START_ADDR FLASH_BASE /**< Flash start address */
180 #define EXFLASH_SIZE GR5405_FLASH_SIZE /**< Flash size */
181 #define EXFLASH_END_ADDR (EXFLASH_START_ADDR + EXFLASH_SIZE) /**< Flash end address */
182 
183 #define EXFLASH_ALIAS_OFFSET (0x02000000UL) /**< Alias address offset */
184 /** @} */
185 
186 /** @} */
187 
188 /** @} */
189 
190 /** @addtogroup HAL_EXFLASH_ENUMERATIONS Enumerations
191  * @{
192  */
193 enum
194 {
201 };
202 /** @} */
203 
204 /** @addtogroup HAL_EXFLASH_STRUCTURES Structures
205  * @{
206  */
207 /**
208  * @brief exFlash AC characteristics
209  */
210 typedef struct _exflash_timing_param
211 {
212  uint8_t flash_tVSL; /**< VCC(min.) to device operation. Uint: 10us */
213 
214  uint8_t flash_tESL; /**< Erase suspend latency. Uint: 5us */
215 
216  uint8_t flash_tPSL; /**< Program suspend latency. Uint: 5us */
217 
218  uint8_t flash_tPRS; /**< Latency between program resume and next suspend. Uint: 5us */
219 
220  uint8_t flash_tERS; /**< Latency between erase resume and next suspend. Uint: 5us */
221 
222  uint8_t flash_tDP; /**< CS# High to Deep Power-down Mode. Uint: 5us */
223 
224  uint8_t flash_tRES2; /**< CS# High To Standby Mode With Electronic Signature Read. Uint: 5us */
225 
226  uint8_t flash_tRDINT; /**< Read status register interval when wait busy. Uint: 5us */
228 
229 /**
230  * @brief HP Mode structure definition
231  */
233 
234 /**
235  * @brief EXFLASH function Structure definition
236  */
237 typedef struct
238 {
239  uint32_t (*p_exflash_config)(uint32_t configure, uint32_t value); /**< Flash parameter configuration */
240  uint32_t (*p_exflash_enable_quad)(ll_xqspi_hp_init_t hp_init); /**< Enable Quad mode to allow Quad operation */
241  uint32_t (*p_exflash_read)(uint32_t addr, uint8_t *p_data, uint32_t size); /**< Read an amount of data with specified instruction and address from flash */
242  uint32_t (*p_exflash_write)(uint32_t addr, uint8_t *p_data, uint32_t size); /**< Write an amount of data with specified instruction and address to flash */
243  uint32_t (*p_exflash_erase)(uint32_t erase_type, uint32_t addr, uint32_t size); /**< Erase flash region */
244  uint32_t (*p_exflash_block_protect)(uint32_t cmp, uint32_t bp); /**< Lock area of flash to be software protected against Write and Erase operation */
245  uint32_t (*p_exflash_suspend)(void); /**< Suspend flash pragram/erase */
246  uint32_t (*p_exflash_resume)(void); /**< Resume flash pragram/erase */
247  uint32_t (*p_exflash_deepsleep)(void); /**< The exFlash will go to the Deep Power-Down Mode */
248  uint32_t (*p_exflash_wakeup)(void); /**< ExFlash will be released from Deep Power-Down Mode */
249  uint32_t (*p_exflash_sr_erase)(uint32_t addr); /**< Erase single flash security register */
250  uint32_t (*p_exflash_sr_program)(uint32_t addr, uint8_t *p_data, uint32_t size); /**< Write an amount of data into flash security register */
251  uint32_t (*p_exflash_sr_read)(uint32_t addr, uint8_t *p_data, uint32_t size); /**< Read an amount of data from flash security register */
252  uint32_t (*p_exflash_sr_protect)(uint32_t lb); /**< This function provide the write protect control and status to the Security Registers */
254 /** @} */
255 
256 /**
257  * @defgroup HAL_EXFLASH_MACRO Defines
258  * @{
259  */
260 
261 /** @defgroup EXFLASH_EXPORTED_CONSTANTS EXFLASH Exported Constants
262  * @{
263  */
264 
265 /** @defgroup EXFLASH_RETRY_DEFINITION EXFLASH Repeat Times definition
266  * @{
267  */
268 #define HAL_EXFLASH_RETRY_DEFAULT_VALUE ((uint32_t)400000) /**< 400000 times */
269 /** @} */
270 
271 /** @} */
272 
273 /* Exported macro ------------------------------------------------------------*/
274 /** @defgroup EXFLASH_EXPORTED_MACROS EXFLASH Exported Macros
275  * @{
276  */
277 
278 /** @brief Enable the specified exFlash power.
279  * @retval None
280  */
281 #define __HAL_EXFLASH_POWER_ON() ll_xqspi_enable_exflash_power()
282 
283 /** @brief Disable the specified exFlash power.
284  * @retval None
285  */
286 #define __HAL_EXFLASH_POWER_OFF() ll_xqspi_disable_exflash_power()
287 
288 /** @} */
289 
290 /* Private macros ------------------------------------------------------------*/
291 /** @defgroup EXFLASH_PRIVATE_MACRO EXFLASH Private Macros
292  * @{
293  */
294 
295 /** @} */
296 
297 /** @} */
298 
299 /* Exported functions --------------------------------------------------------*/
300 /** @addtogroup HAL_EXFLASH_DRIVER_FUNCTIONS Functions
301  * @{
302  */
303 
304 /** @defgroup EXFLASH_Exported_Functions_Group1 Initialization and de-initialization functions
305  * @brief Initialization and de-initialization functions
306  *
307 @verbatim
308  ===============================================================================
309  ##### Initialization and de-initialization functions #####
310  ===============================================================================
311  [..] This subsection provides a set of functions allowing to initialize and
312  de-initialize the exFlash peripheral:
313 
314  (+) User must implement hal_exflash_msp_init() function in which he configures
315  all related peripherals resources (GPIO, DMA, IT and NVIC ).
316 
317  (+) Call the function hal_exflash_deinit() to restore the default configuration
318  of the selected exFlash peripheral.
319 
320 @endverbatim
321  * @{
322  */
323 
324 /**
325  ****************************************************************************************
326  * @brief Initialize the exFlash according to the specified parameters
327  * in the exflash_init_t and initialize the associated handle.
328  *
329  * @retval ::HAL_OK: Operation is OK.
330  * @retval ::HAL_ERROR: Parameter error or operation not supported.
331  * @retval ::HAL_BUSY: Driver is busy.
332  * @retval ::HAL_TIMEOUT: Timeout occurred.
333  ****************************************************************************************
334  */
335 uint32_t hal_exflash_init(exflash_func_t *exflash_func);
336 
337 /**
338  ****************************************************************************************
339  * @brief De-Initialize the exFlash.
340  *
341  ****************************************************************************************
342  */
344 
345 /** @} */
346 
347 /** @defgroup EXFLASH_EXPORTED_FUNCTIONS_GROUP2 IO operation functions
348  * @brief Data transfers functions
349  *
350 @verbatim
351  ==============================================================================
352  ##### IO operation functions #####
353  ===============================================================================
354  [..]
355  This subsection provides a set of functions allowing to manage the exFlash
356  data transfers.
357 
358  [..] The exFlash supports XIP and QSPI mode:
359 
360  (#) There are only one modes of transfer:
361  (++) Blocking mode: The communication is performed in polling mode.
362  The HAL status of all data processing is returned by the same function
363  after finishing transfer.
364 
365 @endverbatim
366  * @{
367  */
368 /**
369  ****************************************************************************************
370  * @brief Configure flash electrical characteristic parameters
371  *
372  * @param[in] p_time: flash timing characteristics
373  *
374  * @retval ::HAL_OK: Operation is OK.
375  * @retval ::HAL_ERROR: Parameter error or operation not supported.
376  * @retval ::HAL_BUSY: Driver is busy.
377  * @retval ::HAL_TIMEOUT: Timeout occurred.
378  ****************************************************************************************
379 */
381 
382 /**
383  ****************************************************************************************
384  * @brief Get flash id and size
385  *
386  * @param[out] id: Pointer to flash id
387  * @param[out] size: Pointer to flash size
388  *
389  * @retval ::HAL_OK: Operation is OK.
390  * @retval ::HAL_ERROR: Parameter error or operation not supported.
391  * @retval ::HAL_BUSY: Driver is busy.
392  * @retval ::HAL_TIMEOUT: Timeout occurred.
393  ****************************************************************************************
394 */
395 void hal_exflash_get_info(uint32_t *id, uint32_t *size);
396 
397 
398 /**
399  ****************************************************************************************
400  * @brief flash parameter configuration
401  *
402  * @param[in] configure: flash parameter configuration item
403  * @param[in] value: flash parameter configuration value
404  *
405  * @retval ::HAL_OK: Operation is OK.
406  * @retval ::HAL_ERROR: Parameter error or operation not supported.
407  * @retval ::HAL_BUSY: Driver is busy.
408  * @retval ::HAL_TIMEOUT: Timeout occurred.
409  ****************************************************************************************
410 */
411 uint32_t hal_exflash_config(uint32_t configure, uint32_t value);
412 
413 /**
414  ****************************************************************************************
415  * @brief Enable Quad mode to allow Quad operation.
416  *
417  * @note This function is used only in Mirror Mode.
418  *
419  * @retval ::HAL_OK: Operation is OK.
420  * @retval ::HAL_ERROR: Parameter error or operation not supported.
421  * @retval ::HAL_BUSY: Driver is busy.
422  * @retval ::HAL_TIMEOUT: Timeout occurred.
423  ****************************************************************************************
424  */
426 
427 
428 /**
429  ****************************************************************************************
430  * @brief Write an amount of data with specified instruction and address to flash.
431  *
432  * @note This function is used only in Indirect Write Mode. In secure mode, address alignment requires 4 bytes.
433  *
434  * @param[in] addr: Address to write data in flash, start at @ref EXFLASH_START_ADDR.
435  * @param[in] p_data: Pointer to data buffer
436  * @param[in] size: Size of buffer bytes
437  *
438  * @retval ::HAL_OK: Operation is OK.
439  * @retval ::HAL_ERROR: Parameter error or operation not supported.
440  * @retval ::HAL_BUSY: Driver is busy.
441  * @retval ::HAL_TIMEOUT: Timeout occurred.
442  ****************************************************************************************
443  */
444 uint32_t hal_exflash_write(uint32_t addr, uint8_t *p_data, uint32_t size);
445 
446 /**
447  ****************************************************************************************
448  * @brief Read an amount of data with specified instruction and address from flash.
449  *
450  * @note This function is used only in non-encrypted Indirect Read Mode.
451  *
452  * @param[in] addr: Address to read data in flash, start at @ref EXFLASH_START_ADDR.
453  * @param[out] p_data: Pointer to data buffer
454  * @param[in] size: Size of buffer bytes
455  *
456  * @retval ::HAL_OK: Operation is OK.
457  * @retval ::HAL_ERROR: Parameter error or operation not supported.
458  * @retval ::HAL_BUSY: Driver is busy.
459  * @retval ::HAL_TIMEOUT: Timeout occurred.
460  ****************************************************************************************
461  */
462 uint32_t hal_exflash_read(uint32_t addr, uint8_t *p_data, uint32_t size);
463 
464 /**
465  ****************************************************************************************
466  * @brief Erase flash region.
467  *
468  * @note All sectors that have address in range of [addr, addr+len] will be erased. If addr is not sector aligned,
469  * preceding data on the sector that addr belongs to will also be erased. If (addr + size) is not sector
470  * aligned, the whole sector will also be erased. If erase_type is @ref EXFLASH_ERASE_CHIP , all data in flash
471  * will be erased ignored addr and size.
472  *
473  * @param[in] erase_type: Erase flash with page/sector/chip.
474  * @arg @ref EXFLASH_ERASE_SECTOR
475  * @arg @ref EXFLASH_ERASE_CHIP
476  * @param[in] addr: Address to erased data in flash, start at @ref EXFLASH_START_ADDR.
477  * @param[in] size: Size of erased bytes.
478  *
479  * @retval ::HAL_OK: Operation is OK.
480  * @retval ::HAL_ERROR: Parameter error or operation not supported.
481  * @retval ::HAL_BUSY: Driver is busy.
482  * @retval ::HAL_TIMEOUT: Timeout occurred.
483  ****************************************************************************************
484  */
485 uint32_t hal_exflash_erase(uint32_t erase_type, uint32_t addr, uint32_t size);
486 
487 /**
488  ****************************************************************************************
489  * @brief Lock area of flash to be software protected against Write and Erase operation..
490  *
491  * @param[in] cmp: It is used in conjunction the BPs bits to provide more flexibility for the array protection.
492  * @param[in] bp: Specifies the value to be written to the selected bit.
493  * This parameter can be one of the EXFLASH_PROTECTED_AREA_SIZE values:
494  * @arg @ref EXFLASH_PROTECT_AREA_00000
495  * @arg @ref EXFLASH_PROTECT_AREA_00001
496  * @arg @ref EXFLASH_PROTECT_AREA_00010
497  * @arg @ref EXFLASH_PROTECT_AREA_00011
498  * @arg @ref EXFLASH_PROTECT_AREA_01001
499  * @arg @ref EXFLASH_PROTECT_AREA_01010
500  * @arg @ref EXFLASH_PROTECT_AREA_01011
501  * @arg @ref EXFLASH_PROTECT_AREA_00100
502  * @arg @ref EXFLASH_PROTECT_AREA_10001
503  * @arg @ref EXFLASH_PROTECT_AREA_10010
504  * @arg @ref EXFLASH_PROTECT_AREA_10011
505  * @arg @ref EXFLASH_PROTECT_AREA_10100
506  * @arg @ref EXFLASH_PROTECT_AREA_10110
507  * @arg @ref EXFLASH_PROTECT_AREA_11001
508  * @arg @ref EXFLASH_PROTECT_AREA_11010
509  * @arg @ref EXFLASH_PROTECT_AREA_11011
510  * @arg @ref EXFLASH_PROTECT_AREA_11100
511  * @arg @ref EXFLASH_PROTECT_AREA_11110
512  * @arg @ref EXFLASH_PROTECT_AREA_11111
513  * @retval ::HAL_OK: Operation is OK.
514  * @retval ::HAL_ERROR: Parameter error or operation not supported.
515  * @retval ::HAL_BUSY: Driver is busy.
516  * @retval ::HAL_TIMEOUT: Timeout occurred.
517  ****************************************************************************************
518  */
519 uint32_t hal_exflash_block_protect(uint32_t cmp, uint32_t bp);
520 
521 /**
522  ****************************************************************************************
523  * @brief the exFlash will go to the Deep Power-Down Mode.
524  *
525  * @note This function is used only in Mirror Mode.
526  *
527  * @retval ::HAL_OK: Operation is OK.
528  * @retval ::HAL_ERROR: Parameter error or operation not supported.
529  * @retval ::HAL_BUSY: Driver is busy.
530  * @retval ::HAL_TIMEOUT: Timeout occurred.
531  ****************************************************************************************
532  */
533 uint32_t hal_exflash_deepsleep(void);
534 
535 /**
536  ****************************************************************************************
537  * @brief exFlash will be released from Deep Power-Down Mode.
538  *
539  * @note This function is used only in Mirror Mode.
540  *
541  * @retval ::HAL_OK: Operation is OK.
542  * @retval ::HAL_ERROR: Parameter error or operation not supported.
543  * @retval ::HAL_BUSY: Driver is busy.
544  * @retval ::HAL_TIMEOUT: Timeout occurred.
545  ****************************************************************************************
546  */
547 uint32_t hal_exflash_wakeup(void);
548 
549 /**
550  ****************************************************************************************
551  * @brief Erase single flash security register.
552  *
553  * @note This function erase only single security register.
554  * If initial_mode is XIP, it will swich to QSPI mode to execute command and switch to XIP mode finally.
555  * This parameter has the following values:
556  * @arg @ref EXFLASH_OTP_BASEADDR1
557  * @param[in] addr: Security Registers address of flash
558  *
559  * @retval ::HAL_OK: Operation is OK.
560  * @retval ::HAL_ERROR: Parameter error or operation not supported.
561  * @retval ::HAL_BUSY: Driver is busy.
562  * @retval ::HAL_TIMEOUT: Timeout occurred.
563  ****************************************************************************************
564  */
565 uint32_t hal_exflash_sr_erase(uint32_t addr);
566 
567 /**
568  ****************************************************************************************
569  * @brief Write an amount of data into flash security register
570  *
571  * @note This function is used only in non-encrypted Indirect Write Mode.
572  * If initial_mode is XIP, it will swich to QSPI mode to execute command and switch to XIP mode finally.
573  *
574  * @param[in] addr: Security Registers address of flash
575  * @param[out] p_data: Pointer to data buffer
576  * @param[in] size: Size of data buffer bytes, and need be smaller than single security register
577  *
578  * @retval ::HAL_OK: Operation is OK.
579  * @retval ::HAL_ERROR: Parameter error or operation not supported.
580  * @retval ::HAL_BUSY: Driver is busy.
581  * @retval ::HAL_TIMEOUT: Timeout occurred.
582  ****************************************************************************************
583  */
584 uint32_t hal_exflash_sr_program(uint32_t addr, uint8_t *p_data, uint32_t size);
585 
586 /**
587  ****************************************************************************************
588  * @brief Read an amount of data from flash security register
589  *
590  * @note This function is used only in non-encrypted Indirect Read Mode.
591  * If initial_mode is XIP, it will swich to QSPI mode to execute command and switch to XIP mode finally.
592  *
593  * @param[in] addr: Security Registers address of flash
594  * @param[out] p_data: Pointer to data buffer
595  * @param[in] size: Size of data buffer bytes, and need be smaller than single security register
596  *
597  * @retval ::HAL_OK: Operation is OK.
598  * @retval ::HAL_ERROR: Parameter error or operation not supported.
599  * @retval ::HAL_BUSY: Driver is busy.
600  * @retval ::HAL_TIMEOUT: Timeout occurred.
601  ****************************************************************************************
602  */
603 uint32_t hal_exflash_sr_read(uint32_t addr, uint8_t *p_data, uint32_t size);
604 
605 /**
606  ****************************************************************************************
607  * @brief This function provide the write protect control and status to the Security Registers.
608  *
609  * @note The LBbits of flash status register are One Time Programmable, once its set to 1,
610  * the Security Registers will become read-only permanently.
611  *
612  * @param[in] lb: Locked security registers.
613  * This parameter can be a combination of the following values:
614  * @arg @ref EXFLASH_LOCK_OTP
615  * @retval ::HAL_OK: Operation is OK.
616  * @retval ::HAL_ERROR: Parameter error or operation not supported.
617  * @retval ::HAL_BUSY: Driver is busy.
618  * @retval ::HAL_TIMEOUT: Timeout occurred.
619  ****************************************************************************************
620  */
621 uint32_t hal_exflash_sr_protect(uint32_t lb);
622 
623 /**
624  ****************************************************************************************
625  * @brief This function reads the status register of a flash.
626  *
627  * @note The status register is a 16-bit register that provides information about the flash operation status.
628  *
629  * @param[in] p_reg_status: Pointer of status register.
630  * @retval ::HAL_OK: Operation is OK.
631  * @retval ::HAL_ERROR: Parameter error or operation not supported.
632  * @retval ::HAL_BUSY: Driver is busy.
633  * @retval ::HAL_TIMEOUT: Timeout occurred.
634  ****************************************************************************************
635  */
637 
638 /**
639  ****************************************************************************************
640  * @brief This function writes the status register of a flash.
641  *
642  * @note The status register is a 16-bit register that provides information about the flash operation status.
643  *
644  * @param reg_status: An integer value representing the content to be written to the flash status register.
645  *
646  * @retval ::HAL_OK: Operation is OK.
647  * @retval ::HAL_ERROR: Parameter error or operation not supported.
648  * @retval ::HAL_BUSY: Driver is busy.
649  * @retval ::HAL_TIMEOUT: Timeout occurred.
650  ****************************************************************************************
651  */
653 
654 /**
655  ****************************************************************************************
656  * @brief This function serves to read UID of flash
657  *
658  * @param[out] uid: store 8 Byte flash UID
659  *
660  * @retval ::HAL_OK: Operation is OK.
661  * @retval ::HAL_ERROR: Parameter error or operation not supported.
662  * @retval ::HAL_BUSY: Driver is busy.
663  * @retval ::HAL_TIMEOUT: Timeout occurred.
664  ****************************************************************************************
665  */
667 
668 /**
669  ****************************************************************************************
670  * @brief This function wait for the flash (in qspi mode) to exit the busy state.
671  *
672  * @param[out] retry: try times.
673  *
674  * @retval ::HAL_OK: Operation is OK.
675  * @retval ::HAL_TIMEOUT: Timeout occurred.
676  ****************************************************************************************
677  */
679 /** @} */
680 
681 /** @} */
682 
683 #ifdef __cplusplus
684 }
685 #endif
686 
687 #endif /* ___HAL_EXFLASH_H__ */
688 
689 /** @} */
690 
691 /** @} */
692 
693 /** @} */
exflash_timing_param_t
struct _exflash_timing_param exflash_timing_param_t
exFlash AC characteristics
EXFLASH_CONFIG_PAGE_TYPE
@ EXFLASH_CONFIG_PAGE_TYPE
Definition: hal_exflash.h:200
exflash_func_t
EXFLASH function Structure definition.
Definition: hal_exflash.h:238
ll_xqspi.h
Header file containing functions prototypes of XQSPI LL library.
EXFLASH_CONFIG_CLOCK_MODE
@ EXFLASH_CONFIG_CLOCK_MODE
Definition: hal_exflash.h:198
_exflash_timing_param::flash_tRES2
uint8_t flash_tRES2
Definition: hal_exflash.h:224
EXFLASH_CONFIG_CACHE_MODE
@ EXFLASH_CONFIG_CACHE_MODE
Definition: hal_exflash.h:195
hal_exflash_wait_busy
hal_status_t hal_exflash_wait_busy(uint32_t retry)
This function wait for the flash (in qspi mode) to exit the busy state.
hal_xqspi.h
Header file containing functions prototypes of XQSPI HAL library.
_exflash_timing_param::flash_tERS
uint8_t flash_tERS
Definition: hal_exflash.h:220
EXFLASH_CONFIG_READ_CMD
@ EXFLASH_CONFIG_READ_CMD
Definition: hal_exflash.h:196
_exflash_timing_param::flash_tPRS
uint8_t flash_tPRS
Definition: hal_exflash.h:218
_exflash_timing_param::flash_tDP
uint8_t flash_tDP
Definition: hal_exflash.h:222
hal_exflash_sr_erase
uint32_t hal_exflash_sr_erase(uint32_t addr)
Erase single flash security register.
hal_exflash_deinit
void hal_exflash_deinit(void)
De-Initialize the exFlash.
hal_exflash_sr_read
uint32_t hal_exflash_sr_read(uint32_t addr, uint8_t *p_data, uint32_t size)
Read an amount of data from flash security register.
hal_exflash_write_status_reg
hal_status_t hal_exflash_write_status_reg(uint16_t reg_status)
This function writes the status register of a flash.
hal_exflash_enable_quad
uint32_t hal_exflash_enable_quad(ll_xqspi_hp_init_t hp_init)
Enable Quad mode to allow Quad operation.
hal_exflash_timing_set
void hal_exflash_timing_set(exflash_timing_param_t *p_time)
Configure flash electrical characteristic parameters.
_ll_xqspi_hp_init_t
XQSPI High Performance mode init structures definition.
Definition: ll_xqspi.h:77
EXFLASH_CONFIG_CACHE_FLUSH
@ EXFLASH_CONFIG_CACHE_FLUSH
Definition: hal_exflash.h:199
hal_exflash_config
uint32_t hal_exflash_config(uint32_t configure, uint32_t value)
flash parameter configuration
exflash_hp_init_t
ll_xqspi_hp_init_t exflash_hp_init_t
HP Mode structure definition.
Definition: hal_exflash.h:232
hal_exflash_sr_program
uint32_t hal_exflash_sr_program(uint32_t addr, uint8_t *p_data, uint32_t size)
Write an amount of data into flash security register.
_exflash_timing_param::flash_tPSL
uint8_t flash_tPSL
Definition: hal_exflash.h:216
hal_exflash_sr_protect
uint32_t hal_exflash_sr_protect(uint32_t lb)
This function provide the write protect control and status to the Security Registers.
hal_exflash_write
uint32_t hal_exflash_write(uint32_t addr, uint8_t *p_data, uint32_t size)
Write an amount of data with specified instruction and address to flash.
_exflash_timing_param::flash_tVSL
uint8_t flash_tVSL
Definition: hal_exflash.h:212
hal_exflash_erase
uint32_t hal_exflash_erase(uint32_t erase_type, uint32_t addr, uint32_t size)
Erase flash region.
_exflash_timing_param
exFlash AC characteristics
Definition: hal_exflash.h:211
EXFLASH_CONFIG_BAUD_RATE
@ EXFLASH_CONFIG_BAUD_RATE
Definition: hal_exflash.h:197
_exflash_timing_param::flash_tRDINT
uint8_t flash_tRDINT
Definition: hal_exflash.h:226
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr_common.h:140
hal_exflash_read_status_reg
hal_status_t hal_exflash_read_status_reg(uint16_t *p_reg_status)
This function reads the status register of a flash.
hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
_exflash_timing_param::flash_tESL
uint8_t flash_tESL
Definition: hal_exflash.h:214
hal_exflash_init
uint32_t hal_exflash_init(exflash_func_t *exflash_func)
Initialize the exFlash according to the specified parameters in the exflash_init_t and initialize the...
hal_exflash_wakeup
uint32_t hal_exflash_wakeup(void)
exFlash will be released from Deep Power-Down Mode.
hal_exflash_block_protect
uint32_t hal_exflash_block_protect(uint32_t cmp, uint32_t bp)
Lock area of flash to be software protected against Write and Erase operation..
hal_exflash_read_uid
hal_status_t hal_exflash_read_uid(uint8_t *uid)
This function serves to read UID of flash.
hal_exflash_read
uint32_t hal_exflash_read(uint32_t addr, uint8_t *p_data, uint32_t size)
Read an amount of data with specified instruction and address from flash.
hal_exflash_deepsleep
uint32_t hal_exflash_deepsleep(void)
the exFlash will go to the Deep Power-Down Mode.
hal_exflash_get_info
void hal_exflash_get_info(uint32_t *id, uint32_t *size)
Get flash id and size.