gr533x_hal_exflash.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr533x_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 __GR533x_HAL_EXFLASH_H__
53 #define __GR533x_HAL_EXFLASH_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr533x_ll_xqspi.h"
61 #include "gr533x_hal_xqspi.h"
62 #include "gr533x_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_OTP1 0x01 /**< Security register #1 */
142 #define EXFLASH_LOCK_OTP2 0x02 /**< Security register #2 */
143 #define EXFLASH_LOCK_OTP3 0x04 /**< Security register #3 */
144 /** @} */
145
146 /** @defgroup EXFLASH_ERASE_TYPE EXFLASH Erase Type
147 * @{
148 */
149 #define EXFLASH_ERASE_SECTOR 0 /**< Sector erase */
150 #define EXFLASH_ERASE_BLOCK32K 1 /**< block32 erase */
151 #define EXFLASH_ERASE_BLOCK 2 /**< block erase */
152 #define EXFLASH_ERASE_CHIP 3 /**< Chip erase */
153 /** @} */
154
155 /** @defgroup EXFLASH_BLOCK_PROTECT EXFLASH Block Protect
156 * @{
157 */
158 #define EXFLASH_SINGLE_PAGE_TYPE 0 /**< single page */
159 #define EXFLASH_DUAL_PAGE_TYPE 1 /**< dual page */
160 /** @} */
161
162 /** @defgroup EXFLASH_OTP_ADDR EXFLASH OTP Address
163 * @{
164 */
165 #define EXFLASH_OTP_BASEADDR1 0x001000 /**< Security register #1 */
166 #define EXFLASH_OTP_BASEADDR2 0x002000 /**< Security register #2 */
167 #define EXFLASH_OTP_BASEADDR3 0x003000 /**< Security register #2 */
168 /** @} */
169
170
171 /** @defgroup EXFLASH_SIZE_INFO EXFLASH Size Information
172 * @{
173 */
174 #define EXFLASH_SIZE_PAGE_BYTES ((uint32_t)256) /**< Page size in Bytes */
175 #define EXFLASH_SIZE_SECTOR_BYTES ((uint32_t)4096) /**< Sector size in Bytes */
176 #define EXFLASH_SIZE_BLOCK_32K_BYTES ((uint32_t)32768) /**< block_32K size in Bytes */
177 #define EXFLASH_SIZE_BLOCK_BYTES ((uint32_t)65536) /**< block size in Bytes */
178
179 #define EXFLASH_SIZE_CHIP_BYTES ((uint32_t)0x800000) /**< Chip size in Bytes */
180 #define EXFLASH_START_ADDR FLASH_BASE /**< Flash start address */
181 #define EXFLASH_SIZE GR533X_FLASH_SIZE /**< Flash size */
182 #define EXFLASH_END_ADDR (EXFLASH_START_ADDR + EXFLASH_SIZE) /**< Flash end address */
183
184 #define EXFLASH_ALIAS_OFFSET (0x02000000UL) /**< Alias address offset */
185 /** @} */
186
187 /** @} */
188
189 /** @} */
190
191 /** @addtogroup HAL_EXFLASH_ENUMERATIONS Enumerations
192 * @{
193 */
194 enum
195 {
196 EXFLASH_CONFIG_CACHE_MODE = 0x00,
197 EXFLASH_CONFIG_READ_CMD = 0x01,
198 EXFLASH_CONFIG_BAUD_RATE = 0x02,
199 EXFLASH_CONFIG_CLOCK_MODE = 0x03,
200 EXFLASH_CONFIG_CACHE_FLUSH = 0x04,
201 EXFLASH_CONFIG_PAGE_TYPE = 0x05,
202 };
203 /** @} */
204
205 /** @addtogroup HAL_EXFLASH_STRUCTURES Structures
206 * @{
207 */
208 /**
209 * @brief exFlash AC characteristics
210 */
211 typedef struct _exflash_timing_param
212 {
213 uint8_t flash_tVSL; /**< VCC(min.) to device operation. Uint: 10us */
214
215 uint8_t flash_tESL; /**< Erase suspend latency. Uint: 5us */
216
217 uint8_t flash_tPSL; /**< Program suspend latency. Uint: 5us */
218
219 uint8_t flash_tPRS; /**< Latency between program resume and next suspend. Uint: 5us */
220
221 uint8_t flash_tERS; /**< Latency between erase resume and next suspend. Uint: 5us */
222
223 uint8_t flash_tDP; /**< CS# High to Deep Power-down Mode. Uint: 5us */
224
225 uint8_t flash_tRES2; /**< CS# High To Standby Mode With Electronic Signature Read. Uint: 5us */
226
227 uint8_t flash_tRDINT; /**< Read status register interval when wait busy. Uint: 5us */
228 } exflash_timing_param_t;
229
230 /**
231 * @brief HP Mode structure definition
232 */
233 typedef ll_xqspi_hp_init_t exflash_hp_init_t;
234
235 /**
236 * @brief EXFLASH function Structure definition
237 */
238 typedef struct
239 {
240 uint32_t (*p_exflash_config)(uint32_t configure, uint32_t value); /**< Flash parameter configuration */
241 uint32_t (*p_exflash_enable_quad)(ll_xqspi_hp_init_t hp_init); /**< Enable Quad mode to allow Quad operation */
242 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 */
243 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 */
244 uint32_t (*p_exflash_erase)(uint32_t erase_type, uint32_t addr, uint32_t size); /**< Erase flash region */
245 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 */
246 uint32_t (*p_exflash_suspend)(void); /**< Suspend flash pragram/erase */
247 uint32_t (*p_exflash_resume)(void); /**< Resume flash pragram/erase */
248 uint32_t (*p_exflash_deepsleep)(void); /**< The exFlash will go to the Deep Power-Down Mode */
249 uint32_t (*p_exflash_wakeup)(void); /**< ExFlash will be released from Deep Power-Down Mode */
250 uint32_t (*p_exflash_sr_erase)(uint32_t addr); /**< Erase single flash security register */
251 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 */
252 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 */
253 uint32_t (*p_exflash_sr_protect)(uint32_t lb); /**< This function provide the write protect control and status to the Security Registers */
254 }exflash_func_t;
255 /** @} */
256
257 /**
258 * @defgroup HAL_EXFLASH_MACRO Defines
259 * @{
260 */
261
262 /** @defgroup EXFLASH_EXPORTED_CONSTANTS EXFLASH Exported Constants
263 * @{
264 */
265
266 /** @defgroup EXFLASH_RETRY_DEFINITION EXFLASH Repeat Times definition
267 * @{
268 */
269 #define HAL_EXFLASH_RETRY_DEFAULT_VALUE ((uint32_t)400000) /**< 400000 times */
270 /** @} */
271
272 /** @} */
273
274 /* Exported macro ------------------------------------------------------------*/
275 /** @defgroup EXFLASH_EXPORTED_MACROS EXFLASH Exported Macros
276 * @{
277 */
278
279 /** @brief Enable the specified exFlash power.
280 * @retval None
281 */
282 #define __HAL_EXFLASH_POWER_ON() ll_xqspi_enable_exflash_power()
283
284 /** @brief Disable the specified exFlash power.
285 * @retval None
286 */
287 #define __HAL_EXFLASH_POWER_OFF() ll_xqspi_disable_exflash_power()
288
289 /** @} */
290
291 /* Private macros ------------------------------------------------------------*/
292 /** @defgroup EXFLASH_PRIVATE_MACRO EXFLASH Private Macros
293 * @{
294 */
295
296 /** @} */
297
298 /** @} */
299
300 /* Exported functions --------------------------------------------------------*/
301 /** @addtogroup HAL_EXFLASH_DRIVER_FUNCTIONS Functions
302 * @{
303 */
304
305 /** @defgroup EXFLASH_Exported_Functions_Group1 Initialization and de-initialization functions
306 * @brief Initialization and de-initialization functions
307 *
308 @verbatim
309 ===============================================================================
310 ##### Initialization and de-initialization functions #####
311 ===============================================================================
312 [..] This subsection provides a set of functions allowing to initialize and
313 de-initialize the exFlash peripheral:
314
315 (+) User must implement hal_exflash_msp_init() function in which he configures
316 all related peripherals resources (GPIO, DMA, IT and NVIC ).
317
318 (+) Call the function hal_exflash_deinit() to restore the default configuration
319 of the selected exFlash peripheral.
320
321 @endverbatim
322 * @{
323 */
324
325 /**
326 ****************************************************************************************
327 * @brief Initialize the exFlash according to the specified parameters
328 * in the exflash_init_t and initialize the associated handle.
329 *
330 * @retval ::HAL_OK: Operation is OK.
331 * @retval ::HAL_ERROR: Parameter error or operation not supported.
332 * @retval ::HAL_BUSY: Driver is busy.
333 * @retval ::HAL_TIMEOUT: Timeout occurred.
334 ****************************************************************************************
335 */
336 uint32_t hal_exflash_init(exflash_func_t *exflash_func);
337
338 /** @} */
339
340 /** @defgroup EXFLASH_EXPORTED_FUNCTIONS_GROUP2 IO operation functions
341 * @brief Data transfers functions
342 *
343 @verbatim
344 ==============================================================================
345 ##### IO operation functions #####
346 ===============================================================================
347 [..]
348 This subsection provides a set of functions allowing to manage the exFlash
349 data transfers.
350
351 [..] The exFlash supports XIP and QSPI mode:
352
353 (#) There are only one modes of transfer:
354 (++) Blocking mode: The communication is performed in polling mode.
355 The HAL status of all data processing is returned by the same function
356 after finishing transfer.
357
358 @endverbatim
359 * @{
360 */
361 /**
362 ****************************************************************************************
363 * @brief Configure flash electrical characteristic parameters
364 *
365 * @param[in] p_time: flash timing characteristics
366 *
367 * @retval ::HAL_OK: Operation is OK.
368 * @retval ::HAL_ERROR: Parameter error or operation not supported.
369 * @retval ::HAL_BUSY: Driver is busy.
370 * @retval ::HAL_TIMEOUT: Timeout occurred.
371 ****************************************************************************************
372 */
373 void hal_exflash_timing_set(exflash_timing_param_t *p_time);
374
375 /**
376 ****************************************************************************************
377 * @brief Get flash id and size
378 *
379 * @param[out] id: Pointer to flash id
380 * @param[out] size: Pointer to flash size
381 *
382 * @retval ::HAL_OK: Operation is OK.
383 * @retval ::HAL_ERROR: Parameter error or operation not supported.
384 * @retval ::HAL_BUSY: Driver is busy.
385 * @retval ::HAL_TIMEOUT: Timeout occurred.
386 ****************************************************************************************
387 */
388 void hal_exflash_get_info(uint32_t *id, uint32_t *size);
389
390
391 /**
392 ****************************************************************************************
393 * @brief flash parameter configuration
394 *
395 * @param[in] configure: flash parameter configuration item
396 * @param[in] value: flash parameter configuration value
397 *
398 * @retval ::HAL_OK: Operation is OK.
399 * @retval ::HAL_ERROR: Parameter error or operation not supported.
400 * @retval ::HAL_BUSY: Driver is busy.
401 * @retval ::HAL_TIMEOUT: Timeout occurred.
402 ****************************************************************************************
403 */
404 uint32_t hal_exflash_config(uint32_t configure, uint32_t value);
405
406 /**
407 ****************************************************************************************
408 * @brief Enable Quad mode to allow Quad operation.
409 *
410 * @note This function is used only in Mirror Mode.
411 *
412 * @retval ::HAL_OK: Operation is OK.
413 * @retval ::HAL_ERROR: Parameter error or operation not supported.
414 * @retval ::HAL_BUSY: Driver is busy.
415 * @retval ::HAL_TIMEOUT: Timeout occurred.
416 ****************************************************************************************
417 */
418 uint32_t hal_exflash_enable_quad(ll_xqspi_hp_init_t hp_init);
419
420
421 /**
422 ****************************************************************************************
423 * @brief Write an amount of data with specified instruction and address to flash.
424 *
425 * @note This function is used only in Indirect Write Mode. In secure mode, address alignment requires 4 bytes.
426 *
427 * @param[in] addr: Address to write data in flash, start at @ref EXFLASH_START_ADDR.
428 * @param[in] p_data: Pointer to data buffer
429 * @param[in] size: Size of buffer bytes
430 *
431 * @retval ::HAL_OK: Operation is OK.
432 * @retval ::HAL_ERROR: Parameter error or operation not supported.
433 * @retval ::HAL_BUSY: Driver is busy.
434 * @retval ::HAL_TIMEOUT: Timeout occurred.
435 ****************************************************************************************
436 */
437 uint32_t hal_exflash_write(uint32_t addr, uint8_t *p_data, uint32_t size);
438
439 /**
440 ****************************************************************************************
441 * @brief Read an amount of data with specified instruction and address from flash.
442 *
443 * @note This function is used only in non-encrypted Indirect Read Mode.
444 *
445 * @param[in] addr: Address to read data in flash, start at @ref EXFLASH_START_ADDR.
446 * @param[out] p_data: Pointer to data buffer
447 * @param[in] size: Size of buffer bytes
448 *
449 * @retval ::HAL_OK: Operation is OK.
450 * @retval ::HAL_ERROR: Parameter error or operation not supported.
451 * @retval ::HAL_BUSY: Driver is busy.
452 * @retval ::HAL_TIMEOUT: Timeout occurred.
453 ****************************************************************************************
454 */
455 uint32_t hal_exflash_read(uint32_t addr, uint8_t *p_data, uint32_t size);
456
457 /**
458 ****************************************************************************************
459 * @brief Erase flash region.
460 *
461 * @note All sectors that have address in range of [addr, addr+len] will be erased. If addr is not sector aligned,
462 * preceding data on the sector that addr belongs to will also be erased. If (addr + size) is not sector
463 * aligned, the whole sector will also be erased. If erase_type is @ref EXFLASH_ERASE_CHIP , all data in flash
464 * will be erased ignored addr and size.
465 *
466 * @param[in] erase_type: Erase flash with page/sector/chip.
467 * @arg @ref EXFLASH_ERASE_SECTOR
468 * @arg @ref EXFLASH_ERASE_CHIP
469 * @param[in] addr: Address to erased data in flash, start at @ref EXFLASH_START_ADDR.
470 * @param[in] size: Size of erased bytes.
471 *
472 * @retval ::HAL_OK: Operation is OK.
473 * @retval ::HAL_ERROR: Parameter error or operation not supported.
474 * @retval ::HAL_BUSY: Driver is busy.
475 * @retval ::HAL_TIMEOUT: Timeout occurred.
476 ****************************************************************************************
477 */
478 uint32_t hal_exflash_erase(uint32_t erase_type, uint32_t addr, uint32_t size);
479
480 /**
481 ****************************************************************************************
482 * @brief Lock area of flash to be software protected against Write and Erase operation..
483 *
484 * @param[in] cmp: It is used in conjunction the BPs bits to provide more flexibility for the array protection.
485 * @param[in] bp: Specifies the value to be written to the selected bit.
486 * This parameter can be one of the EXFLASH_PROTECTED_AREA_SIZE values:
487 * @arg @ref EXFLASH_PROTECT_AREA_00000
488 * @arg @ref EXFLASH_PROTECT_AREA_00001
489 * @arg @ref EXFLASH_PROTECT_AREA_00010
490 * @arg @ref EXFLASH_PROTECT_AREA_00011
491 * @arg @ref EXFLASH_PROTECT_AREA_01001
492 * @arg @ref EXFLASH_PROTECT_AREA_01010
493 * @arg @ref EXFLASH_PROTECT_AREA_01011
494 * @arg @ref EXFLASH_PROTECT_AREA_00100
495 * @arg @ref EXFLASH_PROTECT_AREA_10001
496 * @arg @ref EXFLASH_PROTECT_AREA_10010
497 * @arg @ref EXFLASH_PROTECT_AREA_10011
498 * @arg @ref EXFLASH_PROTECT_AREA_10100
499 * @arg @ref EXFLASH_PROTECT_AREA_10110
500 * @arg @ref EXFLASH_PROTECT_AREA_11001
501 * @arg @ref EXFLASH_PROTECT_AREA_11010
502 * @arg @ref EXFLASH_PROTECT_AREA_11011
503 * @arg @ref EXFLASH_PROTECT_AREA_11100
504 * @arg @ref EXFLASH_PROTECT_AREA_11110
505 * @arg @ref EXFLASH_PROTECT_AREA_11111
506 * @retval ::HAL_OK: Operation is OK.
507 * @retval ::HAL_ERROR: Parameter error or operation not supported.
508 * @retval ::HAL_BUSY: Driver is busy.
509 * @retval ::HAL_TIMEOUT: Timeout occurred.
510 ****************************************************************************************
511 */
512 uint32_t hal_exflash_block_protect(uint32_t cmp, uint32_t bp);
513
514 /**
515 ****************************************************************************************
516 * @brief the exFlash will go to the Deep Power-Down Mode.
517 *
518 * @note This function is used only in Mirror Mode.
519 *
520 * @retval ::HAL_OK: Operation is OK.
521 * @retval ::HAL_ERROR: Parameter error or operation not supported.
522 * @retval ::HAL_BUSY: Driver is busy.
523 * @retval ::HAL_TIMEOUT: Timeout occurred.
524 ****************************************************************************************
525 */
526 uint32_t hal_exflash_deepsleep(void);
527
528 /**
529 ****************************************************************************************
530 * @brief exFlash will be released from Deep Power-Down Mode.
531 *
532 * @note This function is used only in Mirror Mode.
533 *
534 * @retval ::HAL_OK: Operation is OK.
535 * @retval ::HAL_ERROR: Parameter error or operation not supported.
536 * @retval ::HAL_BUSY: Driver is busy.
537 * @retval ::HAL_TIMEOUT: Timeout occurred.
538 ****************************************************************************************
539 */
540 uint32_t hal_exflash_wakeup(void);
541
542 /**
543 ****************************************************************************************
544 * @brief Erase single flash security register.
545 *
546 * @note This function erase only single security register.
547 * If initial_mode is XIP, it will swich to QSPI mode to execute command and switch to XIP mode finally.
548 *
549 * @param[in] addr: Security Registers address of flash
550 *
551 * @retval ::HAL_OK: Operation is OK.
552 * @retval ::HAL_ERROR: Parameter error or operation not supported.
553 * @retval ::HAL_BUSY: Driver is busy.
554 * @retval ::HAL_TIMEOUT: Timeout occurred.
555 ****************************************************************************************
556 */
557 uint32_t hal_exflash_sr_erase(uint32_t addr);
558
559 /**
560 ****************************************************************************************
561 * @brief Write an amount of data into flash security register
562 *
563 * @note This function is used only in non-encrypted Indirect Write Mode.
564 * If initial_mode is XIP, it will swich to QSPI mode to execute command and switch to XIP mode finally.
565 *
566 * @param[in] addr: Security Registers address of flash
567 * @param[out] p_data: Pointer to data buffer
568 * @param[in] size: Size of data buffer bytes, and need be smaller than single security register
569 *
570 * @retval ::HAL_OK: Operation is OK.
571 * @retval ::HAL_ERROR: Parameter error or operation not supported.
572 * @retval ::HAL_BUSY: Driver is busy.
573 * @retval ::HAL_TIMEOUT: Timeout occurred.
574 ****************************************************************************************
575 */
576 uint32_t hal_exflash_sr_program(uint32_t addr, uint8_t *p_data, uint32_t size);
577
578 /**
579 ****************************************************************************************
580 * @brief Read an amount of data from flash security register
581 *
582 * @note This function is used only in non-encrypted Indirect Read Mode.
583 * If initial_mode is XIP, it will swich to QSPI mode to execute command and switch to XIP mode finally.
584 *
585 * @param[in] addr: Security Registers address of flash
586 * @param[out] p_data: Pointer to data buffer
587 * @param[in] size: Size of data buffer bytes, and need be smaller than single security register
588 *
589 * @retval ::HAL_OK: Operation is OK.
590 * @retval ::HAL_ERROR: Parameter error or operation not supported.
591 * @retval ::HAL_BUSY: Driver is busy.
592 * @retval ::HAL_TIMEOUT: Timeout occurred.
593 ****************************************************************************************
594 */
595 uint32_t hal_exflash_sr_read(uint32_t addr, uint8_t *p_data, uint32_t size);
596
597 /**
598 ****************************************************************************************
599 * @brief This function provide the write protect control and status to the Security Registers.
600 *
601 * @note The LB3-BL1bits of flash status register are One Time Programmable, once its set to 1,
602 * the Security Registers will become read-only permanently.
603 *
604 * @param[in] lb: Locked security registers.
605 * This parameter can be a combination of the following values:
606 * @arg @ref EXFLASH_LOCK_OTP1
607 * @arg @ref EXFLASH_LOCK_OTP2
608 * @arg @ref EXFLASH_LOCK_OTP3
609 * @retval ::HAL_OK: Operation is OK.
610 * @retval ::HAL_ERROR: Parameter error or operation not supported.
611 * @retval ::HAL_BUSY: Driver is busy.
612 * @retval ::HAL_TIMEOUT: Timeout occurred.
613 ****************************************************************************************
614 */
615 uint32_t hal_exflash_sr_protect(uint32_t lb);
616
617 /**
618 ****************************************************************************************
619 * @brief This function reads the status register of a flash.
620 *
621 * @note The status register is a 16-bit register that provides information about the flash operation status.
622 *
623 * @param[in] p_reg_status: Pointer of status register.
624 * @retval ::HAL_OK: Operation is OK.
625 * @retval ::HAL_ERROR: Parameter error or operation not supported.
626 * @retval ::HAL_BUSY: Driver is busy.
627 * @retval ::HAL_TIMEOUT: Timeout occurred.
628 ****************************************************************************************
629 */
630 hal_status_t hal_exflash_read_status_reg(uint16_t* p_reg_status);
631
632 /**
633 ****************************************************************************************
634 * @brief This function writes the status register of a flash.
635 *
636 * @note The status register is a 16-bit register that provides information about the flash operation status.
637 *
638 * @param reg_status: An integer value representing the content to be written to the flash status register.
639 *
640 * @retval ::HAL_OK: Operation is OK.
641 * @retval ::HAL_ERROR: Parameter error or operation not supported.
642 * @retval ::HAL_BUSY: Driver is busy.
643 * @retval ::HAL_TIMEOUT: Timeout occurred.
644 ****************************************************************************************
645 */
646 hal_status_t hal_exflash_write_status_reg(uint16_t reg_status);
647
648 /**
649 ****************************************************************************************
650 * @brief This function serves to read UID of flash
651 *
652 * @param[out] uid: store 16 Byte flash UID
653 *
654 * @retval ::HAL_OK: Operation is OK.
655 * @retval ::HAL_ERROR: Parameter error or operation not supported.
656 * @retval ::HAL_BUSY: Driver is busy.
657 * @retval ::HAL_TIMEOUT: Timeout occurred.
658 ****************************************************************************************
659 */
660 hal_status_t hal_exflash_read_uid(uint8_t *uid);
661 /** @} */
662
663 /** @} */
664
665 #ifdef __cplusplus
666 }
667 #endif
668
669 #endif /* __GR533x_HAL_EXFLASH_H__ */
670
671 /** @} */
672
673 /** @} */
674
675 /** @} */
exflash_timing_param_t
struct _exflash_timing_param exflash_timing_param_t
exFlash AC characteristics
EXFLASH_CONFIG_READ_CMD
@ EXFLASH_CONFIG_READ_CMD
Definition: gr533x_hal_exflash.h:197
EXFLASH_CONFIG_CACHE_FLUSH
@ EXFLASH_CONFIG_CACHE_FLUSH
Definition: gr533x_hal_exflash.h:200
EXFLASH_CONFIG_BAUD_RATE
@ EXFLASH_CONFIG_BAUD_RATE
Definition: gr533x_hal_exflash.h:198
exflash_func_t
EXFLASH function Structure definition.
Definition: gr533x_hal_exflash.h:239
gr533x_ll_xqspi.h
Header file containing functions prototypes of XQSPI LL library.
_exflash_timing_param::flash_tRES2
uint8_t flash_tRES2
Definition: gr533x_hal_exflash.h:225
_exflash_timing_param::flash_tERS
uint8_t flash_tERS
Definition: gr533x_hal_exflash.h:221
_exflash_timing_param::flash_tPRS
uint8_t flash_tPRS
Definition: gr533x_hal_exflash.h:219
_exflash_timing_param::flash_tDP
uint8_t flash_tDP
Definition: gr533x_hal_exflash.h:223
hal_exflash_sr_erase
uint32_t hal_exflash_sr_erase(uint32_t addr)
Erase single flash security register.
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: gr533x_ll_xqspi.h:77
gr533x_hal_xqspi.h
Header file containing functions prototypes of XQSPI HAL library.
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: gr533x_hal_exflash.h:233
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: gr533x_hal_exflash.h:217
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: gr533x_hal_exflash.h:213
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: gr533x_hal_exflash.h:212
_exflash_timing_param::flash_tRDINT
uint8_t flash_tRDINT
Definition: gr533x_hal_exflash.h:227
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_status_t
hal_status_t
HAL Status structures definition.
Definition: gr533x_hal_def.h:70
EXFLASH_CONFIG_CACHE_MODE
@ EXFLASH_CONFIG_CACHE_MODE
Definition: gr533x_hal_exflash.h:196
_exflash_timing_param::flash_tESL
uint8_t flash_tESL
Definition: gr533x_hal_exflash.h:215
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.
EXFLASH_CONFIG_PAGE_TYPE
@ EXFLASH_CONFIG_PAGE_TYPE
Definition: gr533x_hal_exflash.h:201
gr533x_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
EXFLASH_CONFIG_CLOCK_MODE
@ EXFLASH_CONFIG_CLOCK_MODE
Definition: gr533x_hal_exflash.h:199
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.