| M480 BSP V3.05.001 The Board Support Package for M480 Series

fmc.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #ifndef __FMC_H__
10 #define __FMC_H__
11
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16
31 /*---------------------------------------------------------------------------------------------------------*/
32 /* Define Base Address */
33 /*---------------------------------------------------------------------------------------------------------*/
34 #define FMC_APROM_BASE 0x00000000UL
35 #define FMC_APROM_END 0x00080000UL
36 #define FMC_APROM_BANK0_END (FMC_APROM_END/2UL)
37 #define FMC_LDROM_BASE 0x00100000UL
38 #define FMC_LDROM_END 0x00101000UL
39 #define FMC_SPROM_BASE 0x00200000UL
40 #define FMC_SPROM_END 0x00201000UL
41 #define FMC_XOM_BASE 0x00200000UL
42 #define FMC_XOMR0_BASE 0x00200000UL
43 #define FMC_XOMR1_BASE 0x00200010UL
44 #define FMC_XOMR2_BASE 0x00200020UL
45 #define FMC_XOMR3_BASE 0x00200030UL
46 #define FMC_CONFIG_BASE 0x00300000UL
47 #define FMC_USER_CONFIG_0 0x00300000UL
48 #define FMC_USER_CONFIG_1 0x00300004UL
49 #define FMC_USER_CONFIG_2 0x00300008UL
50 #define FMC_KPROM_BASE 0x00301000UL
51 #define FMC_OTP_BASE 0x00310000UL
53 #define FMC_FLASH_PAGE_SIZE 0x1000UL
54 #define FMC_PAGE_ADDR_MASK 0xFFFFF000UL
55 #define FMC_MULTI_WORD_PROG_LEN 512
57 #define FMC_APROM_SIZE FMC_APROM_END
58 #define FMC_BANK_SIZE (FMC_APROM_SIZE/2UL)
59 #define FMC_LDROM_SIZE 0x1000UL
60 #define FMC_SPROM_SIZE 0x1000UL
61 #define FMC_OTP_ENTRY_CNT 256UL
63 /*---------------------------------------------------------------------------------------------------------*/
64 /* XOM region number constant definitions */
65 /*---------------------------------------------------------------------------------------------------------*/
66 #define XOMR0 0UL
67 #define XOMR1 1UL
68 #define XOMR2 2UL
69 #define XOMR3 3UL
71 /*---------------------------------------------------------------------------------------------------------*/
72 /* ISPCTL constant definitions */
73 /*---------------------------------------------------------------------------------------------------------*/
74 #define IS_BOOT_FROM_LDROM 0x1UL
75 #define IS_BOOT_FROM_APROM 0x0UL
77 /*---------------------------------------------------------------------------------------------------------*/
78 /* ISPCMD constant definitions */
79 /*---------------------------------------------------------------------------------------------------------*/
80 #define FMC_ISPCMD_READ 0x00UL
81 #define FMC_ISPCMD_READ_UID 0x04UL
82 #define FMC_ISPCMD_READ_ALL1 0x08UL
83 #define FMC_ISPCMD_READ_CID 0x0BUL
84 #define FMC_ISPCMD_READ_DID 0x0CUL
85 #define FMC_ISPCMD_READ_CKS 0x0DUL
86 #define FMC_ISPCMD_PROGRAM 0x21UL
87 #define FMC_ISPCMD_PAGE_ERASE 0x22UL
88 #define FMC_ISPCMD_BANK_ERASE 0x23UL
89 #define FMC_ISPCMD_BLOCK_ERASE 0x25UL
90 #define FMC_ISPCMD_PROGRAM_MUL 0x27UL
91 #define FMC_ISPCMD_RUN_ALL1 0x28UL
92 #define FMC_ISPCMD_RUN_CKS 0x2DUL
93 #define FMC_ISPCMD_VECMAP 0x2EUL
94 #define FMC_ISPCMD_READ_64 0x40UL
95 #define FMC_ISPCMD_PROGRAM_64 0x61UL
97 #define READ_ALLONE_YES 0xA11FFFFFUL
98 #define READ_ALLONE_NOT 0xA1100000UL
99 #define READ_ALLONE_CMD_FAIL 0xFFFFFFFFUL
102 /* end of group FMC_EXPORTED_CONSTANTS */
103
104
110 /*---------------------------------------------------------------------------------------------------------*/
111 /* Macros */
112 /*---------------------------------------------------------------------------------------------------------*/
113
114 #define FMC_SET_APROM_BOOT() (FMC->ISPCTL &= ~FMC_ISPCTL_BS_Msk)
115 #define FMC_SET_LDROM_BOOT() (FMC->ISPCTL |= FMC_ISPCTL_BS_Msk)
116 #define FMC_ENABLE_AP_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_APUEN_Msk)
117 #define FMC_DISABLE_AP_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_APUEN_Msk)
118 #define FMC_ENABLE_CFG_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_CFGUEN_Msk)
119 #define FMC_DISABLE_CFG_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_CFGUEN_Msk)
120 #define FMC_ENABLE_LD_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_LDUEN_Msk)
121 #define FMC_DISABLE_LD_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_LDUEN_Msk)
122 #define FMC_ENABLE_SP_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_SPUEN_Msk)
123 #define FMC_DISABLE_SP_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_SPUEN_Msk)
124 #define FMC_DISABLE_ISP() (FMC->ISPCTL &= ~FMC_ISPCTL_ISPEN_Msk)
125 #define FMC_ENABLE_ISP() (FMC->ISPCTL |= FMC_ISPCTL_ISPEN_Msk)
126 #define FMC_GET_FAIL_FLAG() ((FMC->ISPCTL & FMC_ISPCTL_ISPFF_Msk) ? 1UL : 0UL)
127 #define FMC_CLR_FAIL_FLAG() (FMC->ISPCTL |= FMC_ISPCTL_ISPFF_Msk)
129 /* end of group FMC_EXPORTED_MACROS */
130
131
136 /*---------------------------------------------------------------------------------------------------------*/
137 /* inline functions */
138 /*---------------------------------------------------------------------------------------------------------*/
139
140 __STATIC_INLINE uint32_t FMC_ReadCID(void);
141 __STATIC_INLINE uint32_t FMC_ReadPID(void);
142 __STATIC_INLINE uint32_t FMC_ReadUID(uint8_t u8Index);
143 __STATIC_INLINE uint32_t FMC_ReadUCID(uint32_t u32Index);
144 __STATIC_INLINE void FMC_SetVectorPageAddr(uint32_t u32PageAddr);
145 __STATIC_INLINE uint32_t FMC_GetVECMAP(void);
146
155 __STATIC_INLINE uint32_t FMC_GetVECMAP(void)
156 {
157 return (FMC->ISPSTS & FMC_ISPSTS_VECMAP_Msk);
158 }
159
166 __STATIC_INLINE uint32_t FMC_ReadCID(void)
167 {
168 FMC->ISPCMD = FMC_ISPCMD_READ_CID; /* Set ISP Command Code */
169 FMC->ISPADDR = 0x0u; /* Must keep 0x0 when read CID */
170 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk; /* Trigger to start ISP procedure */
171 #if ISBEN
172 __ISB();
173 #endif /* To make sure ISP/CPU be Synchronized */
174 while(FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) {} /* Waiting for ISP Done */
175
176 return FMC->ISPDAT;
177 }
178
185 __STATIC_INLINE uint32_t FMC_ReadPID(void)
186 {
187 FMC->ISPCMD = FMC_ISPCMD_READ_DID; /* Set ISP Command Code */
188 FMC->ISPADDR = 0x04u; /* Must keep 0x4 when read PID */
189 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk; /* Trigger to start ISP procedure */
190 #if ISBEN
191 __ISB();
192 #endif /* To make sure ISP/CPU be Synchronized */
193 while(FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) {} /* Waiting for ISP Done */
194
195 return FMC->ISPDAT;
196 }
197
204 __STATIC_INLINE uint32_t FMC_ReadUID(uint8_t u8Index)
205 {
206 FMC->ISPCMD = FMC_ISPCMD_READ_UID;
207 FMC->ISPADDR = ((uint32_t)u8Index << 2u);
208 FMC->ISPDAT = 0u;
209 FMC->ISPTRG = 0x1u;
210 #if ISBEN
211 __ISB();
212 #endif
213 while(FMC->ISPTRG) {}
214
215 return FMC->ISPDAT;
216 }
217
224 __STATIC_INLINE uint32_t FMC_ReadUCID(uint32_t u32Index)
225 {
226 FMC->ISPCMD = FMC_ISPCMD_READ_UID; /* Set ISP Command Code */
227 FMC->ISPADDR = (0x04u * u32Index) + 0x10u; /* The UCID is at offset 0x10 with word alignment. */
228 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk; /* Trigger to start ISP procedure */
229 #if ISBEN
230 __ISB();
231 #endif /* To make sure ISP/CPU be Synchronized */
232 while(FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) {} /* Waiting for ISP Done */
233
234 return FMC->ISPDAT;
235 }
236
245 __STATIC_INLINE void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
246 {
247 FMC->ISPCMD = FMC_ISPCMD_VECMAP; /* Set ISP Command Code */
248 FMC->ISPADDR = u32PageAddr; /* The address of specified page which will be map to address 0x0. It must be page alignment. */
249 FMC->ISPTRG = 0x1u; /* Trigger to start ISP procedure */
250 #if ISBEN
251 __ISB();
252 #endif /* To make sure ISP/CPU be Synchronized */
253 while(FMC->ISPTRG) {} /* Waiting for ISP Done */
254 }
255
256
257 /*---------------------------------------------------------------------------------------------------------*/
258 /* Functions */
259 /*---------------------------------------------------------------------------------------------------------*/
260
261 extern void FMC_Close(void);
262 extern int32_t FMC_ConfigXOM(uint32_t xom_num, uint32_t xom_base, uint8_t xom_page);
263 extern int32_t FMC_Erase(uint32_t u32PageAddr);
264 extern int32_t FMC_Erase_SPROM(void);
265 extern int32_t FMC_Erase_Block(uint32_t u32BlockAddr);
266 extern int32_t FMC_Erase_Bank(uint32_t u32BankAddr);
267 extern int32_t FMC_EraseXOM(uint32_t xom_num);
268 extern int32_t FMC_GetXOMState(uint32_t xom_num);
269 extern int32_t FMC_GetBootSource(void);
270 extern void FMC_Open(void);
271 extern uint32_t FMC_Read(uint32_t u32Addr);
272 extern int32_t FMC_Read_64(uint32_t u32addr, uint32_t * u32data0, uint32_t * u32data1);
273 extern uint32_t FMC_ReadDataFlashBaseAddr(void);
274 extern void FMC_SetBootSource(int32_t i32BootSrc);
275 extern void FMC_Write(uint32_t u32Addr, uint32_t u32Data);
276 extern int32_t FMC_Write8Bytes(uint32_t u32addr, uint32_t u32data0, uint32_t u32data1);
277 extern int32_t FMC_WriteMultiple(uint32_t u32Addr, uint32_t pu32Buf[], uint32_t u32Len);
278 extern int32_t FMC_Write_OTP(uint32_t otp_num, uint32_t low_word, uint32_t high_word);
279 extern int32_t FMC_Read_OTP(uint32_t otp_num, uint32_t *low_word, uint32_t *high_word);
280 extern int32_t FMC_Lock_OTP(uint32_t otp_num);
281 extern int32_t FMC_Is_OTP_Locked(uint32_t otp_num);
282 extern int32_t FMC_ReadConfig(uint32_t u32Config[], uint32_t u32Count);
283 extern int32_t FMC_WriteConfig(uint32_t u32Config[], uint32_t u32Count);
284 extern uint32_t FMC_GetChkSum(uint32_t u32addr, uint32_t u32count);
285 extern uint32_t FMC_CheckAllOne(uint32_t u32addr, uint32_t u32count);
286 extern int32_t FMC_SetSPKey(uint32_t key[3], uint32_t kpmax, uint32_t kemax, const int32_t lock_CONFIG, const int32_t lock_SPROM);
287 extern int32_t FMC_CompareSPKey(uint32_t key[3]);
288
289 /* end of group FMC_EXPORTED_FUNCTIONS */
291 /* end of group FMC_Driver */
293 /* end of group Standard_Driver */
295
296 #ifdef __cplusplus
297 }
298 #endif
299
300 #endif /* __FMC_H__ */
301
302 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
FMC_ISPSTS_VECMAP_Msk
#define FMC_ISPSTS_VECMAP_Msk
Definition: fmc_reg.h:1073
FMC_GetVECMAP
__STATIC_INLINE uint32_t FMC_GetVECMAP(void)
Get current vector mapping address.
Definition: fmc.h:155
FMC_ReadDataFlashBaseAddr
uint32_t FMC_ReadDataFlashBaseAddr(void)
Get the base address of Data Flash if enabled.
Definition: fmc.c:408
FMC_WriteConfig
int32_t FMC_WriteConfig(uint32_t u32Config[], uint32_t u32Count)
Execute ISP commands to erase then write User Configuration.
Definition: fmc.c:776
FMC_Erase_Bank
int32_t FMC_Erase_Bank(uint32_t u32BankAddr)
Execute FMC_ISPCMD_BANK_ERASE command to erase a flash block.
Definition: fmc.c:206
FMC_GetXOMState
int32_t FMC_GetXOMState(uint32_t xom_num)
Check the XOM is actived or not.
Definition: fmc.c:304
FMC_Close
void FMC_Close(void)
Disable FMC ISP function.
Definition: fmc.c:33
FMC_CheckAllOne
uint32_t FMC_CheckAllOne(uint32_t u32addr, uint32_t u32count)
Run flash all one verification and get result.
Definition: fmc.c:852
FMC_ReadCID
__STATIC_INLINE uint32_t FMC_ReadCID(void)
Read company ID.
Definition: fmc.h:166
FMC_ISPCMD_READ_UID
#define FMC_ISPCMD_READ_UID
Definition: fmc.h:81
FMC_ConfigXOM
int32_t FMC_ConfigXOM(uint32_t xom_num, uint32_t xom_base, uint8_t xom_page)
Config XOM Region.
Definition: fmc.c:51
FMC_Is_OTP_Locked
int32_t FMC_Is_OTP_Locked(uint32_t otp_num)
Check the OTP is locked or not.
Definition: fmc.c:707
FMC_Erase
int32_t FMC_Erase(uint32_t u32PageAddr)
Execute FMC_ISPCMD_PAGE_ERASE command to erase a flash page. The page size is 4096 bytes.
Definition: fmc.c:121
FMC_Lock_OTP
int32_t FMC_Lock_OTP(uint32_t otp_num)
Lock the specified OTP.
Definition: fmc.c:672
FMC_GetBootSource
int32_t FMC_GetBootSource(void)
Get the current boot source.
Definition: fmc.c:329
FMC_Open
void FMC_Open(void)
Enable FMC ISP function.
Definition: fmc.c:347
FMC_SetVectorPageAddr
__STATIC_INLINE void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
Set vector mapping address.
Definition: fmc.h:245
FMC_Write8Bytes
int32_t FMC_Write8Bytes(uint32_t u32addr, uint32_t u32data0, uint32_t u32data1)
Execute ISP FMC_ISPCMD_PROGRAM_64 to program a double-word to flash.
Definition: fmc.c:460
FMC_Read
uint32_t FMC_Read(uint32_t u32Addr)
Execute FMC_ISPCMD_READ command to read a word from flash.
Definition: fmc.c:359
FMC_GetChkSum
uint32_t FMC_GetChkSum(uint32_t u32addr, uint32_t u32count)
Run CRC32 checksum calculation and get result.
Definition: fmc.c:814
FMC_ISPCMD_READ_DID
#define FMC_ISPCMD_READ_DID
Definition: fmc.h:84
FMC_ISPCMD_VECMAP
#define FMC_ISPCMD_VECMAP
Definition: fmc.h:93
FMC_Erase_SPROM
int32_t FMC_Erase_SPROM(void)
Execute FMC_ISPCMD_PAGE_ERASE command to erase SPROM. The page size is 4096 bytes.
Definition: fmc.c:154
FMC_Erase_Block
int32_t FMC_Erase_Block(uint32_t u32BlockAddr)
Execute FMC_ISPCMD_BLOCK_ERASE command to erase a flash block. The block size is 4 pages.
Definition: fmc.c:181
FMC_Read_64
int32_t FMC_Read_64(uint32_t u32addr, uint32_t *u32data0, uint32_t *u32data1)
Execute FMC_ISPCMD_READ_64 command to read a double-word from flash.
Definition: fmc.c:379
FMC_SetSPKey
int32_t FMC_SetSPKey(uint32_t key[3], uint32_t kpmax, uint32_t kemax, const int32_t lock_CONFIG, const int32_t lock_SPROM)
Setup security key.
Definition: fmc.c:905
FMC
#define FMC
Definition: M480.h:391
FMC_Write
void FMC_Write(uint32_t u32Addr, uint32_t u32Data)
Execute ISP FMC_ISPCMD_PROGRAM to program a word to flash.
Definition: fmc.c:442
FMC_CompareSPKey
int32_t FMC_CompareSPKey(uint32_t key[3])
Execute security key comparison.
Definition: fmc.c:990
FMC_ISPTRG_ISPGO_Msk
#define FMC_ISPTRG_ISPGO_Msk
Definition: fmc_reg.h:1046
FMC_ReadUCID
__STATIC_INLINE uint32_t FMC_ReadUCID(uint32_t u32Index)
To read UCID.
Definition: fmc.h:224
FMC_Read_OTP
int32_t FMC_Read_OTP(uint32_t otp_num, uint32_t *low_word, uint32_t *high_word)
Read the 64-bits data from the specified OTP.
Definition: fmc.c:633
FMC_ISPCMD_READ_CID
#define FMC_ISPCMD_READ_CID
Definition: fmc.h:83
FMC_ReadUID
__STATIC_INLINE uint32_t FMC_ReadUID(uint8_t u8Index)
Read Unique ID.
Definition: fmc.h:204
FMC_WriteMultiple
int32_t FMC_WriteMultiple(uint32_t u32Addr, uint32_t pu32Buf[], uint32_t u32Len)
Program Multi-Word data into specified address of flash.
Definition: fmc.c:490
FMC_EraseXOM
int32_t FMC_EraseXOM(uint32_t xom_num)
Execute Erase XOM Region.
Definition: fmc.c:236
FMC_ReadPID
__STATIC_INLINE uint32_t FMC_ReadPID(void)
Read product ID.
Definition: fmc.h:185
FMC_ReadConfig
int32_t FMC_ReadConfig(uint32_t u32Config[], uint32_t u32Count)
Execute FMC_ISPCMD_READ command to read User Configuration.
Definition: fmc.c:749
FMC_SetBootSource
void FMC_SetBootSource(int32_t i32BootSrc)
Set boot source from LDROM or APROM after next software reset.
Definition: fmc.c:423
FMC_Write_OTP
int32_t FMC_Write_OTP(uint32_t otp_num, uint32_t low_word, uint32_t high_word)
Program a 64-bits data to the specified OTP.
Definition: fmc.c:580