gr55xx_hal_exflash.h
Go to the documentation of this file.
1
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_EXFLASH_H__
53 #define __GR55xx_HAL_EXFLASH_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_xqspi.h"
61 #include "gr55xx_hal_xqspi.h"
62 #include "gr55xx_hal_def.h"
63
64 /* Exported types ------------------------------------------------------------*/
76 typedef enum
77 {
78 HAL_EXFLASH_STATE_RESET = 0x00,
79 HAL_EXFLASH_STATE_READY = 0x01,
80 HAL_EXFLASH_STATE_BUSY = 0x02,
81 HAL_EXFLASH_STATE_BUSY_READ = 0x12,
82 HAL_EXFLASH_STATE_BUSY_WRITE = 0x22,
83 HAL_EXFLASH_STATE_BUSY_ERASE = 0x42,
84 HAL_EXFLASH_STATE_SUSPEND_WRITE = 0x21,
85 HAL_EXFLASH_STATE_SUSPEND_ERASE = 0x41,
86 HAL_EXFLASH_STATE_ERROR = 0x04
87 } hal_exflash_state_t;
88
92 typedef enum
93 {
94 HAL_EXFLASH_UNENCRYPTED = 0x00,
95 HAL_EXFLASH_ENCRYPTED = 0x01,
96 } hal_eflash_security;
97
113 typedef struct _exflash_handle
114 {
115 xqspi_handle_t *p_xqspi;
117 __IO uint32_t fw_mode;
119 __IO hal_lock_t lock;
121 __IO hal_exflash_state_t state;
123 __IO hal_eflash_security security;
125 __IO uint32_t flash_id;
127 __IO uint32_t flash_size;
129 __IO uint32_t count;
131 __IO uint32_t error_code;
133 uint32_t retry;
135 } exflash_handle_t;
152 typedef struct _hal_exflash_callback
153 {
154 void (*exflash_msp_init)(exflash_handle_t *p_exflash);
155 void (*exflash_msp_deinit)(exflash_handle_t *p_exflash);
156 } hal_exflash_callback_t;
157
167 /* Exported constants --------------------------------------------------------*/
175 #define HAL_EXFLASH_ERROR_NONE ((uint32_t)0x00000000)
176 #define HAL_EXFLASH_ERROR_TIMEOUT ((uint32_t)0x00000001)
177 #define HAL_EXFLASH_ERROR_TRANSFER ((uint32_t)0x00000002)
178 #define HAL_EXFLASH_ERROR_ID ((uint32_t)0x00000003)
179 #define HAL_EXFLASH_ERROR_QUAD ((uint32_t)0x00000004)
180 #define HAL_EXFLASH_ERROR_INVALID_PARAM ((uint32_t)0x00000008)
186 #define EXFLASH_ERASE_SECTOR 0
187 #define EXFLASH_ERASE_CHIP 1
193 #define EXFLASH_SIZE_PAGE_BYTES ((uint32_t)256)
194 #define EXFLASH_SIZE_SECTOR_BYTES ((uint32_t)4096)
195 #define EXFLASH_SIZE_CHIP_BYTES ((uint32_t)0x800000)
196 #define EXFLASH_START_ADDR FLASH_BASE
197 #define EXFLASH_SIZE (0x00800000UL)
198 #define EXFLASH_END_ADDR (EXFLASH_START_ADDR + EXFLASH_SIZE)
199 #define EXFLASH_ALIAS_OFFSET (0x02000000UL)
200 #define EXFLASH_ALIAS_ADDR (EXFLASH_START_ADDR + EXFLASH_ALIAS_OFFSET)
206 #define EXFLASH_LOCK_AREA_NONE 0
207 #define EXFLASH_LOCK_AREA_UPPER_1_8 1
208 #define EXFLASH_LOCK_AREA_UPPER_1_4 2
209 #define EXFLASH_LOCK_AREA_UPPER_1_2 3
210 #define EXFLASH_LOCK_AREA_LOWER_1_8 9
211 #define EXFLASH_LOCK_AREA_LOWER_1_4 10
212 #define EXFLASH_LOCK_AREA_LOWER_1_2 11
213 #define EXFLASH_LOCK_AREA_ALL 12
214 #define EXFLASH_LOCK_AREA_TOP_4K 17
215 #define EXFLASH_LOCK_AREA_TOP_8K 18
216 #define EXFLASH_LOCK_AREA_TOP_16K 19
217 #define EXFLASH_LOCK_AREA_TOP_32K 20
218 #define EXFLASH_LOCK_AREA_BOTTOM_4K 25
219 #define EXFLASH_LOCK_AREA_BOTTOM_8K 26
220 #define EXFLASH_LOCK_AREA_BOTTOM_16K 27
221 #define EXFLASH_LOCK_AREA_BOTTOM_32K 28
222 #define EXFLASH_LOCK_AREA_LOWER_7_8 33
223 #define EXFLASH_LOCK_AREA_LOWER_3_4 34
224 #define EXFLASH_LOCK_AREA_UPPER_7_8 41
225 #define EXFLASH_LOCK_AREA_UPPER_3_4 42
226 #define EXFLASH_LOCK_AREA_LOWER_127_128 49
227 #define EXFLASH_LOCK_AREA_LOWER_63_64 50
228 #define EXFLASH_LOCK_AREA_LOWER_31_32 51
229 #define EXFLASH_LOCK_AREA_LOWER_15_16 52
230 #define EXFLASH_LOCK_AREA_UPPER_127_128 57
231 #define EXFLASH_LOCK_AREA_UPPER_63_64 58
232 #define EXFLASH_LOCK_AREA_UPPER_31_32 59
233 #define EXFLASH_LOCK_AREA_UPPER_15_16 60
239 #define HAL_EXFLASH_RETRY_DEFAULT_VALUE ((uint32_t)400000)
244 /* Exported macro ------------------------------------------------------------*/
245
253 #define __HAL_EXFLASH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_EXFLASH_STATE_RESET)
254
258 #define __HAL_EXFLASH_POWER_ON() ll_xqspi_enable_exflash_power()
259
263 #define __HAL_EXFLASH_POWER_OFF() ll_xqspi_disable_exflash_power()
264
267 /* Private macros ------------------------------------------------------------*/
277 #define IS_EXFLASH_ERASE_TYPE(__TYPE__) (((__TYPE__) == EXFLASH_ERASE_SECTOR) || \
278 ((__TYPE__) == EXFLASH_ERASE_CHIP))
279
285 #define IS_EXFLASH_LOCK_AREA(__AREA__) (((__AREA__) == EXFLASH_LOCK_AREA_NONE) || \
286 ((__AREA__) == EXFLASH_LOCK_AREA_UPPER_1_8) || \
287 ((__AREA__) == EXFLASH_LOCK_AREA_UPPER_1_4) || \
288 ((__AREA__) == EXFLASH_LOCK_AREA_UPPER_1_2) || \
289 ((__AREA__) == EXFLASH_LOCK_AREA_LOWER_1_8) || \
290 ((__AREA__) == EXFLASH_LOCK_AREA_LOWER_1_4) || \
291 ((__AREA__) == EXFLASH_LOCK_AREA_LOWER_1_2) || \
292 ((__AREA__) == EXFLASH_LOCK_AREA_ALL) || \
293 ((__AREA__) == EXFLASH_LOCK_AREA_TOP_4K) || \
294 ((__AREA__) == EXFLASH_LOCK_AREA_TOP_8K) || \
295 ((__AREA__) == EXFLASH_LOCK_AREA_TOP_16K) || \
296 ((__AREA__) == EXFLASH_LOCK_AREA_TOP_32K) || \
297 ((__AREA__) == EXFLASH_LOCK_AREA_BOTTOM_4K) || \
298 ((__AREA__) == EXFLASH_LOCK_AREA_BOTTOM_8K) || \
299 ((__AREA__) == EXFLASH_LOCK_AREA_BOTTOM_16K) || \
300 ((__AREA__) == EXFLASH_LOCK_AREA_BOTTOM_32K) || \
301 ((__AREA__) == EXFLASH_LOCK_AREA_LOWER_7_8) || \
302 ((__AREA__) == EXFLASH_LOCK_AREA_LOWER_3_4) || \
303 ((__AREA__) == EXFLASH_LOCK_AREA_UPPER_7_8) || \
304 ((__AREA__) == EXFLASH_LOCK_AREA_UPPER_3_4) || \
305 ((__AREA__) == EXFLASH_LOCK_AREA_LOWER_127_128) || \
306 ((__AREA__) == EXFLASH_LOCK_AREA_LOWER_63_64) || \
307 ((__AREA__) == EXFLASH_LOCK_AREA_LOWER_31_32) || \
308 ((__AREA__) == EXFLASH_LOCK_AREA_LOWER_15_16) || \
309 ((__AREA__) == EXFLASH_LOCK_AREA_UPPER_127_128) || \
310 ((__AREA__) == EXFLASH_LOCK_AREA_UPPER_63_64) || \
311 ((__AREA__) == EXFLASH_LOCK_AREA_UPPER_31_32) || \
312 ((__AREA__) == EXFLASH_LOCK_AREA_UPPER_15_16))
313
318 /* Exported functions --------------------------------------------------------*/
356 hal_status_t hal_exflash_init(exflash_handle_t *p_exflash);
357
370 hal_status_t hal_exflash_deinit(exflash_handle_t *p_exflash);
371
382 void hal_exflash_msp_init(exflash_handle_t *p_exflash);
383
394 void hal_exflash_msp_deinit(exflash_handle_t *p_exflash);
395
432 hal_status_t hal_exflash_operation_protection(exflash_handle_t *p_exflash, uint32_t base_priority);
433
451 hal_status_t hal_exflash_write(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size);
452
470 hal_status_t hal_exflash_read(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size);
471
472 #if defined(GR5515_D)
473
493 hal_status_t hal_exflash_read_align_word(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size);
494
495 #endif
496
519 hal_status_t hal_exflash_erase(exflash_handle_t *p_exflash, uint32_t erase_type, uint32_t addr, uint32_t size);
520
538 hal_status_t hal_exflash_suspend(exflash_handle_t *p_exflash);
539
556 hal_status_t hal_exflash_resume(exflash_handle_t *p_exflash);
557
573 hal_status_t hal_exflash_lock(exflash_handle_t *p_exflash, uint32_t lock_type);
574
589 hal_status_t hal_exflash_unlock(exflash_handle_t *p_exflash);
590
605 hal_status_t hal_exflash_deepsleep(exflash_handle_t *p_exflash);
606
621 hal_status_t hal_exflash_wakeup(exflash_handle_t *p_exflash);
622
638 hal_status_t hal_exflash_reset(exflash_handle_t *p_exflash);
639
640 #if defined(GR5515_D) && defined(ENCRYPT_ENABLE)
641
651 hal_status_t hal_exflash_encrypt_mode(exflash_handle_t *p_exflash, uint32_t read_offset, uint32_t key_addr);
652
671 hal_status_t hal_exflash_write_expand(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size);
672
691 hal_status_t hal_exflash_read_expand(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size);
692
693
694
695 #endif
696
730 hal_exflash_state_t hal_exflash_get_state(exflash_handle_t *p_exflash);
731
741 uint32_t hal_exflash_get_error(exflash_handle_t *p_exflash);
742
751 void hal_exflash_set_retry(exflash_handle_t *p_exflash, uint32_t retry);
752
753
757 typedef hal_status_t (*exflash_operation_func)(exflash_handle_t *p_exflash);
758
767 hal_status_t hal_exflash_operation(exflash_handle_t *p_exflash, exflash_operation_func p_func_exflash_operation);
772 #ifdef __cplusplus
773 }
774 #endif
775
776 #endif /* __GR55xx_HAL_EXFLASH_H__ */
777
hal_exflash_msp_deinit
void hal_exflash_msp_deinit(exflash_handle_t *p_exflash)
De-initialize the exFlash MSP.
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
hal_exflash_suspend
hal_status_t hal_exflash_suspend(exflash_handle_t *p_exflash)
Suspend flash pragram/erase.
hal_exflash_deepsleep
hal_status_t hal_exflash_deepsleep(exflash_handle_t *p_exflash)
the exFlash will go to the Deep Power-Down Mode.
hal_exflash_lock
hal_status_t hal_exflash_lock(exflash_handle_t *p_exflash, uint32_t lock_type)
Lock area of flash to be software protected against Write and Erase operation.
hal_exflash_reset
hal_status_t hal_exflash_reset(exflash_handle_t *p_exflash)
Reset exFlash. exFlash will return to its default power-on state and lose all the current volatile se...
hal_exflash_get_error
uint32_t hal_exflash_get_error(exflash_handle_t *p_exflash)
Return the exFlash error code.
HAL_EXFLASH_STATE_RESET
@ HAL_EXFLASH_STATE_RESET
Definition: gr55xx_hal_exflash.h:78
_exflash_handle::count
__IO uint32_t count
Definition: gr55xx_hal_exflash.h:129
HAL_EXFLASH_STATE_ERROR
@ HAL_EXFLASH_STATE_ERROR
Definition: gr55xx_hal_exflash.h:86
hal_exflash_deinit
hal_status_t hal_exflash_deinit(exflash_handle_t *p_exflash)
De-initialize the exFlash peripheral.
exflash_handle_t
struct _exflash_handle exflash_handle_t
exFlash handle Structure definition
hal_exflash_msp_init
void hal_exflash_msp_init(exflash_handle_t *p_exflash)
Initialize the exFlash MSP.
_exflash_handle::retry
uint32_t retry
Definition: gr55xx_hal_exflash.h:133
exflash_operation_func
hal_status_t(* exflash_operation_func)(exflash_handle_t *p_exflash)
HAL exFlash operation function.
Definition: gr55xx_hal_exflash.h:757
hal_exflash_operation_protection
hal_status_t hal_exflash_operation_protection(exflash_handle_t *p_exflash, uint32_t base_priority)
During Flash erase/write operation, Disable external interrupts with a priority less than or equal to...
_exflash_handle::security
__IO hal_eflash_security security
Definition: gr55xx_hal_exflash.h:123
HAL_EXFLASH_STATE_BUSY_WRITE
@ HAL_EXFLASH_STATE_BUSY_WRITE
Definition: gr55xx_hal_exflash.h:82
hal_exflash_erase
hal_status_t hal_exflash_erase(exflash_handle_t *p_exflash, uint32_t erase_type, uint32_t addr, uint32_t size)
Erase flash region.
HAL_EXFLASH_ENCRYPTED
@ HAL_EXFLASH_ENCRYPTED
Definition: gr55xx_hal_exflash.h:95
HAL_EXFLASH_STATE_BUSY_READ
@ HAL_EXFLASH_STATE_BUSY_READ
Definition: gr55xx_hal_exflash.h:81
_xqspi_handle_t
XQSPI handle Structure definition.
Definition: gr55xx_hal_xqspi.h:130
hal_exflash_callback_t
struct _hal_exflash_callback hal_exflash_callback_t
HAL_EXFLASH Callback function definition.
_exflash_handle::state
__IO hal_exflash_state_t state
Definition: gr55xx_hal_exflash.h:121
hal_exflash_resume
hal_status_t hal_exflash_resume(exflash_handle_t *p_exflash)
Resume flash pragram/erase.
_exflash_handle::flash_size
__IO uint32_t flash_size
Definition: gr55xx_hal_exflash.h:127
hal_exflash_get_state
hal_exflash_state_t hal_exflash_get_state(exflash_handle_t *p_exflash)
Return the exFlash handle state.
_exflash_handle::p_xqspi
xqspi_handle_t * p_xqspi
Definition: gr55xx_hal_exflash.h:115
HAL_EXFLASH_STATE_READY
@ HAL_EXFLASH_STATE_READY
Definition: gr55xx_hal_exflash.h:79
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
hal_exflash_wakeup
hal_status_t hal_exflash_wakeup(exflash_handle_t *p_exflash)
exFlash will be released from Deep Power-Down Mode.
_hal_exflash_callback
HAL_EXFLASH Callback function definition.
Definition: gr55xx_hal_exflash.h:153
_exflash_handle::fw_mode
__IO uint32_t fw_mode
Definition: gr55xx_hal_exflash.h:117
gr55xx_hal_xqspi.h
Header file containing functions prototypes of XQSPI HAL library.
hal_exflash_init
hal_status_t hal_exflash_init(exflash_handle_t *p_exflash)
Initialize the exFlash according to the specified parameters in the exflash_init_t and initialize the...
hal_eflash_security
hal_eflash_security
HAL exFlash Security Enumerations definition.
Definition: gr55xx_hal_exflash.h:93
gr55xx_ll_xqspi.h
Header file containing functions prototypes of XQSPI LL library.
_exflash_handle
exFlash handle Structure definition
Definition: gr55xx_hal_exflash.h:114
_exflash_handle::error_code
__IO uint32_t error_code
Definition: gr55xx_hal_exflash.h:131
_hal_exflash_callback::exflash_msp_deinit
void(* exflash_msp_deinit)(exflash_handle_t *p_exflash)
Definition: gr55xx_hal_exflash.h:155
hal_exflash_read
hal_status_t hal_exflash_read(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size)
Read an amount of data with specified instruction and address from flash.
hal_exflash_operation
hal_status_t hal_exflash_operation(exflash_handle_t *p_exflash, exflash_operation_func p_func_exflash_operation)
Call user XIP Flash operation functon.
_hal_exflash_callback::exflash_msp_init
void(* exflash_msp_init)(exflash_handle_t *p_exflash)
Definition: gr55xx_hal_exflash.h:154
HAL_EXFLASH_STATE_SUSPEND_WRITE
@ HAL_EXFLASH_STATE_SUSPEND_WRITE
Definition: gr55xx_hal_exflash.h:84
_exflash_handle::lock
__IO hal_lock_t lock
Definition: gr55xx_hal_exflash.h:119
hal_exflash_state_t
hal_exflash_state_t
HAL exFlash State Enumerations definition.
Definition: gr55xx_hal_exflash.h:77
HAL_EXFLASH_STATE_BUSY
@ HAL_EXFLASH_STATE_BUSY
Definition: gr55xx_hal_exflash.h:80
hal_exflash_set_retry
void hal_exflash_set_retry(exflash_handle_t *p_exflash, uint32_t retry)
Set the exFlash internal process timeout value.
HAL_EXFLASH_UNENCRYPTED
@ HAL_EXFLASH_UNENCRYPTED
Definition: gr55xx_hal_exflash.h:94
_exflash_handle::flash_id
__IO uint32_t flash_id
Definition: gr55xx_hal_exflash.h:125
hal_exflash_write
hal_status_t hal_exflash_write(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size)
Write an amount of data with specified instruction and address to flash.
hal_exflash_unlock
hal_status_t hal_exflash_unlock(exflash_handle_t *p_exflash)
Unlock write/erase protected in flash.
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
HAL_EXFLASH_STATE_BUSY_ERASE
@ HAL_EXFLASH_STATE_BUSY_ERASE
Definition: gr55xx_hal_exflash.h:83
HAL_EXFLASH_STATE_SUSPEND_ERASE
@ HAL_EXFLASH_STATE_SUSPEND_ERASE
Definition: gr55xx_hal_exflash.h:85