• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  ****************************************************************************************
3  *
4  * @file    gr55xx_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 __GR55xx_HAL_EXFLASH_H__
53 #define __GR55xx_HAL_EXFLASH_H__
54 
55 /* Includes ------------------------------------------------------------------*/
56 #include "gr55xx_ll_xqspi.h"
57 #include "gr55xx_hal_xqspi.h"
58 #include "gr55xx_hal_def.h"
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 /* Exported types ------------------------------------------------------------*/
65 /** @addtogroup HAL_EXFLASH_ENUMERATIONS Enumerations
66   * @{
67   */
68 
69 /** @defgroup HAL_EXFLASH_STATE HAL EXFLASH State
70   * @{
71   */
72 
73 /**
74   * @brief HAL exFlash State Enumerations definition
75   */
76 typedef enum {
77     HAL_EXFLASH_STATE_RESET             = 0x00,    /**< Peripheral not initialized                            */
78     HAL_EXFLASH_STATE_READY             = 0x01,    /**< Peripheral initialized and ready for use              */
79     HAL_EXFLASH_STATE_BUSY              = 0x02,    /**< Peripheral in indirect mode and busy                  */
80     HAL_EXFLASH_STATE_BUSY_READ         = 0x12,    /**< Peripheral in indirect mode with reception ongoing    */
81     HAL_EXFLASH_STATE_BUSY_WRITE        = 0x22,    /**< Peripheral in indirect mode with transmission ongoing */
82     HAL_EXFLASH_STATE_BUSY_ERASE        = 0x42,    /**< Peripheral in indirect mode with erase ongoing        */
83     HAL_EXFLASH_STATE_SUSPEND_WRITE     = 0x21,    /**< Peripheral in suspend mode from transmission          */
84     HAL_EXFLASH_STATE_SUSPEND_ERASE     = 0x41,    /**< Peripheral in suspend mode from erase                 */
85     HAL_EXFLASH_STATE_ERROR             = 0x04     /**< Peripheral in error                                   */
86 } hal_exflash_state_t;
87 
88 /**
89   * @brief HAL exFlash Security Enumerations definition
90   */
91 typedef enum {
92     HAL_EXFLASH_UNENCRYPTED             = 0x00,    /**< Data will not be encrypted and decrypted
93                                                         in write-read operations */
94     HAL_EXFLASH_ENCRYPTED               = 0x01,    /**< Data will be encrypted and decrypted
95                                                         in write-read operations */
96 } hal_eflash_security;
97 
98 /** @} */
99 
100 /** @} */
101 
102 /** @addtogroup HAL_EXFLASH_STRUCTURES Structures
103   * @{
104   */
105 
106 /** @defgroup EXFLASH_HANDLE EXFLASH handle
107   * @{
108   */
109 
110 /**
111   * @brief exFlash handle Structure definition
112   */
113 typedef struct _exflash_handle {
114     xqspi_handle_t       *p_xqspi;          /**< exFlash XQSPI Handle parameters       */
115 
116     __IO uint32_t         fw_mode;          /**< exFlash firmware mode                 */
117 
118     __IO hal_lock_t       lock;             /**< Locking object                        */
119 
120     __IO hal_exflash_state_t state;         /**< exFlash communication state           */
121 
122     __IO hal_eflash_security security;      /**< exFlash data security                 */
123 
124     __IO uint32_t         flash_id;         /**< exFlash ID                            */
125 
126     __IO uint32_t         flash_size;       /**< exFlash Size                          */
127 
128     __IO uint32_t         count;            /**< exFlash count for suspend and resume  */
129 
130     __IO uint32_t         error_code;       /**< exFlash Error code                    */
131 
132     uint32_t              retry;            /**< Repeat times for the exFlash memory access */
133 } exflash_handle_t;
134 /** @} */
135 
136 /** @} */
137 
138 /** @addtogroup HAL_EXFLASH_CALLBACK_STRUCTURES Callback Structures
139   * @{
140   */
141 
142 /** @defgroup HAL_EXFLASH_Callback Callback
143   * @{
144   */
145 
146 /**
147   * @brief HAL_EXFLASH Callback function definition
148   */
149 
150 typedef struct _hal_exflash_callback {
151     void (*exflash_msp_init)(exflash_handle_t *p_exflash);      /**< EXFLASH init MSP callback            */
152     void (*exflash_msp_deinit)(exflash_handle_t *p_exflash);    /**< EXFLASH de-init MSP callback         */
153 } hal_exflash_callback_t;
154 
155 /** @} */
156 
157 /** @} */
158 
159 /**
160   * @defgroup  HAL_EXFLASH_MACRO Defines
161   * @{
162   */
163 
164 /* Exported constants --------------------------------------------------------*/
165 /** @defgroup EXFLASH_EXPORTED_CONSTANTS EXFLASH Exported Constants
166   * @{
167   */
168 
169 /** @defgroup EXFLASH_ERROR_CODE EXFLASH Error Code
170   * @{
171   */
172 #define HAL_EXFLASH_ERROR_NONE              ((uint32_t)0x00000000) /**< No error                 */
173 #define HAL_EXFLASH_ERROR_TIMEOUT           ((uint32_t)0x00000001) /**< Timeout error            */
174 #define HAL_EXFLASH_ERROR_TRANSFER          ((uint32_t)0x00000002) /**< Transfer error           */
175 #define HAL_EXFLASH_ERROR_ID                ((uint32_t)0x00000003) /**< Flash ID error           */
176 #define HAL_EXFLASH_ERROR_QUAD              ((uint32_t)0x00000004) /**< Quad mode error           */
177 #define HAL_EXFLASH_ERROR_INVALID_PARAM     ((uint32_t)0x00000008) /**< Invalid parameters error */
178 /** @} */
179 
180 /** @defgroup EXFLASH_ERASE_TYPE EXFLASH Erase Type
181   * @{
182   */
183 #define EXFLASH_ERASE_SECTOR                0   /**< Sector erase */
184 #define EXFLASH_ERASE_CHIP                  1   /**< Chip erase   */
185 /** @} */
186 
187 /** @defgroup EXFLASH_SIZE_INFO EXFLASH Size Information
188   * @{
189   */
190 #define EXFLASH_SIZE_PAGE_BYTES             ((uint32_t)256)      /**< Page size in Bytes     */
191 #define EXFLASH_SIZE_SECTOR_BYTES           ((uint32_t)4096)     /**< Sector size in Bytes   */
192 #define EXFLASH_SIZE_CHIP_BYTES             ((uint32_t)0x800000) /**< Chip size in Bytes     */
193 #define EXFLASH_START_ADDR                  FLASH_BASE           /**< Flash start address    */
194 #define EXFLASH_SIZE                        (0x00800000UL)       /**< Flash size             */
195 #define EXFLASH_END_ADDR                    (EXFLASH_START_ADDR + EXFLASH_SIZE) /**< Flash end address    */
196 #define EXFLASH_ALIAS_OFFSET                (0x02000000UL)       /**< Alias address offset   */
197 #define EXFLASH_ALIAS_ADDR                  (EXFLASH_START_ADDR + EXFLASH_ALIAS_OFFSET) /**< Alias start address   */
198 /** @} */
199 
200 /** @defgroup EXFLASH_LOCK_AREA_TYPE EXFLASH Lock Area Type
201   * @{
202   */
203 #define EXFLASH_LOCK_AREA_NONE              0       /**< Offset NONE                */
204 #define EXFLASH_LOCK_AREA_UPPER_1_8         1       /**< Offset 0x070000 - 0x07FFFF */
205 #define EXFLASH_LOCK_AREA_UPPER_1_4         2       /**< Offset 0x060000 - 0x07FFFF */
206 #define EXFLASH_LOCK_AREA_UPPER_1_2         3       /**< Offset 0x040000 - 0x07FFFF */
207 #define EXFLASH_LOCK_AREA_LOWER_1_8         9       /**< Offset 0x000000 - 0x00FFFF */
208 #define EXFLASH_LOCK_AREA_LOWER_1_4         10      /**< Offset 0x000000 - 0x01FFFF */
209 #define EXFLASH_LOCK_AREA_LOWER_1_2         11      /**< Offset 0x000000 - 0x03FFFF */
210 #define EXFLASH_LOCK_AREA_ALL               12      /**< Offset 0x000000 - 0x07FFFF */
211 #define EXFLASH_LOCK_AREA_TOP_4K            17      /**< Offset 0x07F000 - 0x07FFFF */
212 #define EXFLASH_LOCK_AREA_TOP_8K            18      /**< Offset 0x07E000 - 0x07FFFF */
213 #define EXFLASH_LOCK_AREA_TOP_16K           19      /**< Offset 0x07C000 - 0x07FFFF */
214 #define EXFLASH_LOCK_AREA_TOP_32K           20      /**< Offset 0x078000 - 0x07FFFF */
215 #define EXFLASH_LOCK_AREA_BOTTOM_4K         25      /**< Offset 0x000000 - 0x000FFF */
216 #define EXFLASH_LOCK_AREA_BOTTOM_8K         26      /**< Offset 0x000000 - 0x001FFF */
217 #define EXFLASH_LOCK_AREA_BOTTOM_16K        27      /**< Offset 0x000000 - 0x003FFF */
218 #define EXFLASH_LOCK_AREA_BOTTOM_32K        28      /**< Offset 0x000000 - 0x007FFF */
219 #define EXFLASH_LOCK_AREA_LOWER_7_8         33      /**< Offset 0x070000 - 0x07FFFF */
220 #define EXFLASH_LOCK_AREA_LOWER_3_4         34      /**< Offset 0x060000 - 0x07FFFF */
221 #define EXFLASH_LOCK_AREA_UPPER_7_8         41      /**< Offset 0x000000 - 0x00FFFF */
222 #define EXFLASH_LOCK_AREA_UPPER_3_4         42      /**< Offset 0x000000 - 0x01FFFF */
223 #define EXFLASH_LOCK_AREA_LOWER_127_128     49      /**< Offset 0x000000 - 0x07EFFF */
224 #define EXFLASH_LOCK_AREA_LOWER_63_64       50      /**< Offset 0x000000 - 0x07DFFF */
225 #define EXFLASH_LOCK_AREA_LOWER_31_32       51      /**< Offset 0x000000 - 0x07BFFF */
226 #define EXFLASH_LOCK_AREA_LOWER_15_16       52      /**< Offset 0x000000 - 0x077FFF */
227 #define EXFLASH_LOCK_AREA_UPPER_127_128     57      /**< Offset 0x001000 - 0x07FFFF */
228 #define EXFLASH_LOCK_AREA_UPPER_63_64       58      /**< Offset 0x002000 - 0x07FFFF */
229 #define EXFLASH_LOCK_AREA_UPPER_31_32       59      /**< Offset 0x004000 - 0x07FFFF */
230 #define EXFLASH_LOCK_AREA_UPPER_15_16       60      /**< Offset 0x008000 - 0x07FFFF */
231 /** @} */
232 
233 /** @defgroup EXFLASH_RETRY_DEFINITION EXFLASH Repeat Times definition
234   * @{
235   */
236 #define HAL_EXFLASH_RETRY_DEFAULT_VALUE     ((uint32_t)400000)          /**< 400000 times */
237 /** @} */
238 
239 /** @} */
240 
241 /* Exported macro ------------------------------------------------------------*/
242 /** @defgroup EXFLASH_EXPORTED_MACROS EXFLASH Exported Macros
243   * @{
244   */
245 
246 /** @brief  Reset exFlash handle states.
247   * @param  __HANDLE__ exFlash handle.
248   * @retval None
249   */
250 #define HAL_EXFLASH_RESET_HANDLE_STATE(__HANDLE__)                ((__HANDLE__)->state = HAL_EXFLASH_STATE_RESET)
251 
252 /** @brief  Enable the specified exFlash power.
253   * @retval None
254   */
255 #define HAL_EXFLASH_POWER_ON()                                    ll_xqspi_enable_exflash_power()
256 
257 /** @brief  Disable the specified exFlash power.
258   * @retval None
259   */
260 #define HAL_EXFLASH_POWER_OFF()                                   ll_xqspi_disable_exflash_power()
261 
262 /* Exported functions --------------------------------------------------------*/
263 /** @addtogroup HAL_EXFLASH_DRIVER_FUNCTIONS Functions
264   * @{
265   */
266 
267 /** @defgroup EXFLASH_Exported_Functions_Group1 Initialization and de-initialization functions
268  *  @brief    Initialization and de-initialization functions
269  *
270 @verbatim
271  ===============================================================================
272               ##### Initialization and de-initialization functions #####
273  ===============================================================================
274     [..]  This subsection provides a set of functions allowing to initialize and
275           de-initialize the exFlash peripheral.
276 
277       (+) User must implement hal_exflash_msp_init() function in which he configures
278           all related peripherals resources (GPIO, DMA, IT and NVIC ).
279 
280       (+) Call the function hal_exflash_deinit() to restore the default configuration
281           of the selected exFlash peripheral.
282 
283 @endverbatim
284   * @{
285   */
286 
287 /**
288  ****************************************************************************************
289  * @brief  Initialize the exFlash according to the specified parameters
290  *         in the exflash_init_t and initialize the associated handle.
291  *
292  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
293  *                        information for the specified exFlash module.
294  *
295  * @retval ::HAL_OK: Operation is OK.
296  * @retval ::HAL_ERROR: Parameter error or operation not supported.
297  * @retval ::HAL_BUSY: Driver is busy.
298  * @retval ::HAL_TIMEOUT: Timeout occurred.
299  ****************************************************************************************
300  */
301 hal_status_t hal_exflash_init(exflash_handle_t *p_exflash);
302 
303 /**
304  ****************************************************************************************
305  * @brief  De-initialize the exFlash peripheral.
306  *
307  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
308  *                        information for the specified exFlash module.
309  *
310  * @retval ::HAL_OK: Operation is OK.
311  * @retval ::HAL_ERROR: Parameter error or operation not supported.
312  * @retval ::HAL_BUSY: Driver is busy.
313  * @retval ::HAL_TIMEOUT: Timeout occurred.
314  ****************************************************************************************
315  */
316 hal_status_t hal_exflash_deinit(exflash_handle_t *p_exflash);
317 
318 /**
319  ****************************************************************************************
320  * @brief  Initialize the exFlash MSP.
321  *
322  * @note   This function should not be modified. When the callback is needed,
323  *          the hal_exflash_msp_deinit can be implemented in the user file.
324  *
325  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
326  *                        information for the specified exFlash module.
327  ****************************************************************************************
328  */
329 void hal_exflash_msp_init(exflash_handle_t *p_exflash);
330 
331 /**
332  ****************************************************************************************
333  * @brief  De-initialize the exFlash MSP.
334  *
335  * @note   This function should not be modified. When the callback is needed,
336  *          the hal_exflash_msp_deinit can be implemented in the user file.
337  *
338  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
339  *                        information for the specified exFlash module.
340  ****************************************************************************************
341  */
342 void hal_exflash_msp_deinit(exflash_handle_t *p_exflash);
343 
344 /** @} */
345 
346 /** @defgroup EXFLASH_EXPORTED_FUNCTIONS_GROUP2 IO operation functions
347  *  @brief   Data transfers functions
348  *
349 @verbatim
350   ==============================================================================
351                       ##### IO operation functions #####
352  ===============================================================================
353  [..]
354     This subsection provides a set of functions allowing to manage the exFlash
355     data transfers.
356 
357     [..] The exFlash supports XIP and QSPI mode:
358 
359     (#) There are only one modes of transfer:
360        (++) Blocking mode: The communication is performed in polling mode.
361             The HAL status of all data processing is returned by the same function
362             after finishing transfer.
363 
364 @endverbatim
365   * @{
366   */
367 /**
368  ****************************************************************************************
369  * @brief  During Flash erase/write operation, Disable external interrupts with a priority less than
370  *         or equal to base_priority in the system.
371  *
372  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
373  *                        information for the specified exFlash module.
374  * @param[in]  base_priority: Base Priority value to set.
375  *
376  * @retval ::HAL_OK: Operation is OK.
377  * @retval ::HAL_ERROR: Parameter error or operation not supported.
378  * @retval ::HAL_BUSY: Driver is busy.
379  * @retval ::HAL_TIMEOUT: Timeout occurred.
380  ****************************************************************************************
381  */
382 hal_status_t hal_exflash_operation_protection(exflash_handle_t *p_exflash, uint32_t base_priority);
383 
384 /**
385  ****************************************************************************************
386  * @brief  Write an amount of data with specified instruction and address to flash.
387  *
388  * @note   This function is used only in Indirect Write Mode. In secure mode, address alignment requires 4 bytes.
389  *
390  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
391  *                        information for the specified exFlash module.
392  * @param[in]  addr: Address to write data in flash, start at @ref EXFLASH_START_ADDR.
393  * @param[in]  p_data: Pointer to data buffer
394  * @param[in]  size: Size of buffer bytes
395  *
396  * @retval ::HAL_OK: Operation is OK.
397  * @retval ::HAL_ERROR: Parameter error or operation not supported.
398  * @retval ::HAL_BUSY: Driver is busy.
399  * @retval ::HAL_TIMEOUT: Timeout occurred.
400  ****************************************************************************************
401  */
402 hal_status_t hal_exflash_write(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size);
403 
404 /**
405  ****************************************************************************************
406  * @brief  Read an amount of data with specified instruction and address from flash.
407  *
408  * @note   This function is used only in non-encrypted Indirect Read Mode.
409  *
410  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
411  *                        information for the specified exFlash module.
412  * @param[in]  addr: Address to read data in flash, start at @ref EXFLASH_START_ADDR.
413  * @param[out] p_data: Pointer to data buffer
414  * @param[in]  size: Size of buffer bytes
415  *
416  * @retval ::HAL_OK: Operation is OK.
417  * @retval ::HAL_ERROR: Parameter error or operation not supported.
418  * @retval ::HAL_BUSY: Driver is busy.
419  * @retval ::HAL_TIMEOUT: Timeout occurred.
420  ****************************************************************************************
421  */
422 hal_status_t hal_exflash_read(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size);
423 
424 #if defined(GR5515_D)
425 
426 /**
427  ****************************************************************************************
428  * @brief  [High speed]Read an amount of data with specified instruction and address from flash.
429  *
430  * @note   This function is used only in non-encrypted Indirect Read Mode.
431  *          Data content needs to be processed in 4-byte reverse order.
432  *          And all parameters need to be aligned with 4 bytes.
433  *
434  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
435  *                        information for the specified exFlash module.
436  * @param[in]  addr: Address to read data in flash, start at @ref EXFLASH_START_ADDR.(Aligned with 4 bytes)
437  * @param[out] p_data: Pointer to data buffer.(Pointer aligned with 4 bytes)
438  * @param[in]  size: Size of buffer bytes.number of bytes to read.(A multiple of 4)
439  *
440  * @retval ::HAL_OK: Operation is OK.
441  * @retval ::HAL_ERROR: Parameter error or operation not supported.
442  * @retval ::HAL_BUSY: Driver is busy.
443  * @retval ::HAL_TIMEOUT: Timeout occurred.
444  ****************************************************************************************
445  */
446 hal_status_t hal_exflash_read_align_word(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size);
447 
448 #endif
449 
450 /**
451  ****************************************************************************************
452  * @brief  Erase flash region.
453  *
454  * @note   All sectors that have address in range of [addr, addr+len] will be erased. If addr is not sector aligned,
455  *         preceding data on the sector that addr belongs to will also be erased. If (addr + size) is not sector
456  *         aligned, the whole sector will also be erased. If erase_type is @ref EXFLASH_ERASE_CHIP , all data in flash
457  *         will be erased ignored addr and size.
458  *
459  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
460  *                        information for the specified exFlash module.
461  * @param[in]  erase_type: Erase flash with page/sector/chip.
462  *                    @arg @ref EXFLASH_ERASE_SECTOR
463  *                    @arg @ref EXFLASH_ERASE_CHIP
464  * @param[in]  addr: Address to erased data in flash, start at @ref EXFLASH_START_ADDR.
465  * @param[in]  size: Size of erased bytes.
466  *
467  * @retval ::HAL_OK: Operation is OK.
468  * @retval ::HAL_ERROR: Parameter error or operation not supported.
469  * @retval ::HAL_BUSY: Driver is busy.
470  * @retval ::HAL_TIMEOUT: Timeout occurred.
471  ****************************************************************************************
472  */
473 hal_status_t hal_exflash_erase(exflash_handle_t *p_exflash, uint32_t erase_type, uint32_t addr, uint32_t size);
474 
475 /**
476  ****************************************************************************************
477  * @brief  Suspend flash pragram/erase.
478  *
479  * @note   The Suspend instruction interrupts a Page Program, Sector Erase, or Block Erase operation to allow access
480  *         to the memory array. After the program or erase operation has entered the suspended state, the memory
481  *         array can be read except for the page being programmed or the sector or block being erased. This function
482  *         is only used in XIP mode.
483  *
484  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
485  *                        information for the specified exFlash module.
486  *
487  * @retval ::HAL_OK: Operation is OK.
488  * @retval ::HAL_ERROR: Parameter error or operation not supported.
489  * @retval ::HAL_BUSY: Driver is busy.
490  * @retval ::HAL_TIMEOUT: Timeout occurred.
491  ****************************************************************************************
492  */
493 hal_status_t hal_exflash_suspend(exflash_handle_t *p_exflash);
494 
495 /**
496  ****************************************************************************************
497  * @brief  Resume flash pragram/erase.
498  *
499  * @note   The Resume instruction resumes a suspended Page Program, Sector Erase, or Block Erase operation.
500  *         Before issuing the Resume instruction to restart a suspended erase operation, make sure that there is no
501  *         Page Program operation in progress. This function is only used in XIP mode.
502  *
503  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
504  *                        information for the specified exFlash module.
505  *
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 hal_status_t hal_exflash_resume(exflash_handle_t *p_exflash);
513 
514 /**
515  ****************************************************************************************
516  * @brief  Lock area of flash to be software protected against Write and Erase operation.
517  *
518  * @note   Locked area only to be read.
519  *
520  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
521  *                        information for the specified exFlash module.
522  * @param[in]  lock_type Area need to lock
523  *
524  * @retval ::HAL_OK: Operation is OK.
525  * @retval ::HAL_ERROR: Parameter error or operation not supported.
526  * @retval ::HAL_BUSY: Driver is busy.
527  * @retval ::HAL_TIMEOUT: Timeout occurred.
528  ****************************************************************************************
529  */
530 hal_status_t hal_exflash_lock(exflash_handle_t *p_exflash, uint32_t lock_type);
531 
532 /**
533  ****************************************************************************************
534  * @brief  Unlock write/erase protected in flash.
535  *
536  * @note   This function will unlock all chip.
537  *
538  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
539  *                        information for the specified exFlash module.
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 hal_status_t hal_exflash_unlock(exflash_handle_t *p_exflash);
548 
549 /**
550  ****************************************************************************************
551  * @brief  the exFlash will go to the Deep Power-Down Mode.
552  *
553  * @note   This function is used only in Indirect Write Mode.
554  *
555  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
556  *                        information for the specified exFlash module.
557  *
558  * @retval ::HAL_OK: Operation is OK.
559  * @retval ::HAL_ERROR: Parameter error or operation not supported.
560  * @retval ::HAL_BUSY: Driver is busy.
561  * @retval ::HAL_TIMEOUT: Timeout occurred.
562  ****************************************************************************************
563  */
564 hal_status_t hal_exflash_deepsleep(exflash_handle_t *p_exflash);
565 
566 /**
567  ****************************************************************************************
568  * @brief  exFlash will be released from Deep Power-Down Mode.
569  *
570  * @note   This function is used only in Indirect Write Mode.
571  *
572  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
573  *                        information for the specified exFlash module.
574  *
575  * @retval ::HAL_OK: Operation is OK.
576  * @retval ::HAL_ERROR: Parameter error or operation not supported.
577  * @retval ::HAL_BUSY: Driver is busy.
578  * @retval ::HAL_TIMEOUT: Timeout occurred.
579  ****************************************************************************************
580  */
581 hal_status_t hal_exflash_wakeup(exflash_handle_t *p_exflash);
582 
583 /**
584  ****************************************************************************************
585  * @brief  Reset exFlash. exFlash will return to its default power-on state and lose all
586  *         the current volatile settings.
587  *
588  * @note   This function is used only in Indirect Write Mode.
589  *
590  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
591  *                        information for the specified exFlash module.
592  *
593  * @retval ::HAL_OK: Operation is OK.
594  * @retval ::HAL_ERROR: Parameter error or operation not supported.
595  * @retval ::HAL_BUSY: Driver is busy.
596  * @retval ::HAL_TIMEOUT: Timeout occurred.
597  ****************************************************************************************
598  */
599 hal_status_t hal_exflash_reset(exflash_handle_t *p_exflash);
600 
601 #if defined(GR5515_D) && defined(ENCRYPT_ENABLE)
602 
603 /**
604  ****************************************************************************************
605  * @brief  Specify the offset address and encrypted KEY address read by XIP.
606  *
607  * @param[in]  p_exflash  Pointer to an exFlash handle which contains the configuration
608  *                        information for the specified exFlash module.
609  * @param[in]  read_offset  The value must be 0x0 and EXFLASH_ALIAS_OFFSET.
610  * @param[in]  key_addr  The value must be FWCODEKEY_BASE_ADDR(0xA00170E0) and AESKEY_BASE_ADDR(0xA0017060).
611  ****************************************************************************************
612  */
613 hal_status_t hal_exflash_encrypt_mode(exflash_handle_t *p_exflash, uint32_t read_offset, uint32_t key_addr);
614 
615 /**
616  ****************************************************************************************
617  * @brief  Expand write an amount of data with specified instruction and address to flash.
618  *
619  * @note   This function is used only in Indirect Write Mode. In secure mode, address alignment requires 4 bytes.
620  *          Can specify write data to data area or code area. Need to call first hal_exflash_encrypt_mode
621  *
622  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
623  *                        information for the specified exFlash module.
624  * @param[in]  addr: Address to write data in flash, start at @ref EXFLASH_START_ADDR.
625  * @param[in]  p_data: Pointer to data buffer
626  * @param[in]  size: Size of buffer bytes
627  *
628  * @retval ::HAL_OK: Operation is OK.
629  * @retval ::HAL_ERROR: Parameter error or operation not supported.
630  * @retval ::HAL_BUSY: Driver is busy.
631  * @retval ::HAL_TIMEOUT: Timeout occurred.
632  ****************************************************************************************
633  */
634 hal_status_t hal_exflash_write_expand(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size);
635 
636 /**
637  ****************************************************************************************
638  * @brief  Expand read an amount of data with specified instruction and address from flash.
639  *
640  * @note   This function is used only in non-encrypted Indirect Read Mode.
641  *          Can specify read data from data area or code area. Need to call first hal_exflash_encrypt_mode
642  *
643  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
644  *                        information for the specified exFlash module.
645  * @param[in]  addr: Address to read data in flash, start at @ref EXFLASH_START_ADDR.
646  * @param[out] p_data: Pointer to data buffer
647  * @param[in]  size: Size of buffer bytes
648  *
649  * @retval ::HAL_OK: Operation is OK.
650  * @retval ::HAL_ERROR: Parameter error or operation not supported.
651  * @retval ::HAL_BUSY: Driver is busy.
652  * @retval ::HAL_TIMEOUT: Timeout occurred.
653  ****************************************************************************************
654  */
655 hal_status_t hal_exflash_read_expand(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size);
656 
657 #endif
658 
659 /** @} */
660 
661 /** @defgroup EXFLASH_Exported_Functions_Group3 Peripheral State and Errors functions
662   * @brief   exFlash control functions
663   *
664 @verbatim
665  ===============================================================================
666                       ##### Peripheral State and Errors functions #####
667  ===============================================================================
668     [..]
669     This subsection provides a set of functions allowing to control the exFlash.
670      (+) hal_exflash_get_state()API can be helpful to check in run-time the state of the exFlash peripheral.
671      (+) hal_exflash_get_error() check in run-time Errors occurring during communication.
672      (+) hal_exflash_set_timeout() set the timeout during internal process.
673 @endverbatim
674   * @{
675   */
676 
677 /**
678  ****************************************************************************************
679  * @brief  Return the exFlash handle state.
680  *
681  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
682  *                        information for the specified exFlash module.
683  *
684  * @retval ::HAL_EXFLASH_STATE_RESET: Peripheral not initialized.
685  * @retval ::HAL_EXFLASH_STATE_READY: Peripheral initialized and ready for use.
686  * @retval ::HAL_EXFLASH_STATE_BUSY: Peripheral in indirect mode and busy.
687  * @retval ::HAL_EXFLASH_STATE_BUSY_WRITE: Peripheral in indirect mode with transmission ongoing.
688  * @retval ::HAL_EXFLASH_STATE_BUSY_READ: Peripheral in indirect mode with reception ongoing.
689  * @retval ::HAL_EXFLASH_STATE_BUSY_ERASE: Peripheral in indirect mode with erase ongoing.
690  * @retval ::HAL_EXFLASH_STATE_ERROR: Peripheral in error.
691  ****************************************************************************************
692  */
693 hal_exflash_state_t hal_exflash_get_state(exflash_handle_t *p_exflash);
694 
695 /**
696  ****************************************************************************************
697  * @brief  Return the exFlash error code.
698  *
699  * @param[in]  p_exflash: Pointer to an exFlash handle which contains the configuration
700  *                        information for the specified exFlash module.
701  *
702  * @return exFlash error code in bitmap format
703  ****************************************************************************************
704  */
705 uint32_t hal_exflash_get_error(exflash_handle_t *p_exflash);
706 
707 /**
708  ****************************************************************************************
709  * @brief  Set the exFlash internal process timeout value.
710  *
711  * @param[in]  p_exflash  Pointer to an exFlash handle which contains the configuration
712  *                        information for the specified exFlash module.
713  * @param[in]  retry     Internal process repeat times value.
714  ****************************************************************************************
715  */
716 void hal_exflash_set_retry(exflash_handle_t *p_exflash, uint32_t retry);
717 
718 
719 /**
720   * @brief HAL exFlash operation function
721   */
722 typedef hal_status_t (*exflash_operation_func)(exflash_handle_t *p_exflash);
723 
724 /**
725  ****************************************************************************************
726  * @brief  Call user XIP Flash operation functon.
727  *
728  * @param[in]  p_exflash  Pointer to an exFlash handle which contains the configuration
729  *                        information for the specified exFlash module.
730  * @param[in]  exflash_operation_func  HAL exFlash operation function.
731  ****************************************************************************************
732  */
733 hal_status_t hal_exflash_operation(exflash_handle_t *p_exflash, exflash_operation_func p_func_exflash_operation);
734 /** @} */
735 
736 /** @} */
737 
738 #ifdef __cplusplus
739 }
740 #endif
741 
742 #endif /* __GR55xx_HAL_EXFLASH_H__ */
743 
744 /** @} */
745 
746 /** @} */
747 
748 /** @} */
749