| Nano103 BSP V3.01.002 The Board Support Package for Nano103 Series

fmc.h
Go to the documentation of this file.
1 /**************************************************************************/
13 #ifndef __FMC_H__
14 #define __FMC_H__
15
16 #ifdef __cplusplus
17 extern "C"
18 {
19 #endif
20
35 /*---------------------------------------------------------------------------------------------------------*/
36 /* Define Base Address */
37 /*---------------------------------------------------------------------------------------------------------*/
38 #define FMC_APROM_BASE 0x00000000UL
39 #define FMC_APROM_END 0x00010000UL
40 #define FMC_LDROM_BASE 0x00100000UL
41 #define FMC_LDROM_END 0x00101200UL
42 #define FMC_CONFIG_BASE 0x00300000UL
43 #define FMC_KPROM_BASE 0x00301000UL
45 #define FMC_FLASH_PAGE_SIZE 0x200
46 #define FMC_PAGE_ADDR_MASK 0xFFFFFE00UL
48 #define FMC_LDROM_SIZE 0x1200
51 /*---------------------------------------------------------------------------------------------------------*/
52 /* ISPCMD constant definitions */
53 /*---------------------------------------------------------------------------------------------------------*/
54 #define FMC_ISPCMD_READ 0x00
55 #define FMC_ISPCMD_PROGRAM 0x21
56 #define FMC_ISPCMD_PAGE_ERASE 0x22
57 #define FMC_ISPCMD_READ_CID 0x0B
58 #define FMC_ISPCMD_READ_PID 0x0C
59 #define FMC_ISPCMD_READ_UID 0x04
60 #define FMC_ISPCMD_RUN_CKS 0x2D
61 #define FMC_ISPCMD_READ_CKS 0x0D
62 #define FMC_ISPCMD_RUN_ALL1 0x28
63 #define FMC_ISPCMD_READ_ALL1 0x08
64 #define FMC_ISPCMD_VECMAP 0x2E
66 #define IS_BOOT_FROM_APROM 0
67 #define IS_BOOT_FROM_LDROM 1
69 #define READ_ALLONE_YES 0xA11FFFFF
70 #define READ_ALLONE_NOT 0xA1100000
71 #define READ_ALLONE_CMD_FAIL 0xFFFFFFFF
74 /* end of group NANO103_FMC_EXPORTED_CONSTANTS */
75
76
81 /*---------------------------------------------------------------------------------------------------------*/
82 /* Macros */
83 /*---------------------------------------------------------------------------------------------------------*/
84
85 #define FMC_SET_APROM_BOOT() (FMC->ISPCTL &= ~FMC_ISPCTL_BS_Msk)
86 #define FMC_SET_LDROM_BOOT() (FMC->ISPCTL |= FMC_ISPCTL_BS_Msk)
87 #define FMC_ENABLE_AP_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_APUEN_Msk)
88 #define FMC_DISABLE_AP_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_APUEN_Msk)
89 #define FMC_ENABLE_CFG_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_CFGUEN_Msk)
90 #define FMC_DISABLE_CFG_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_CFGUEN_Msk)
91 #define FMC_ENABLE_LD_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_LDUEN_Msk)
92 #define FMC_DISABLE_LD_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_LDUEN_Msk)
93 #define FMC_DISABLE_ISP() (FMC->ISPCTL &= ~FMC_ISPCTL_ISPEN_Msk)
94 #define FMC_ENABLE_ISP() (FMC->ISPCTL |= FMC_ISPCTL_ISPEN_Msk)
95 #define FMC_GET_FAIL_FLAG() ((FMC->ISPCTL & FMC_ISPCTL_ISPFF_Msk) ? 1 : 0)
96 #define FMC_CLR_FAIL_FLAG() (FMC->ISPCTL |= FMC_ISPCTL_ISPFF_Msk)
98 /*---------------------------------------------------------------------------------------------------------*/
99 /* Functions */
100 /*---------------------------------------------------------------------------------------------------------*/
101
102 extern void FMC_Close(void);
103 extern int32_t FMC_Erase(uint32_t u32PageAddr);
104 extern int32_t FMC_GetBootSource(void);
105 extern void FMC_Open(void);
106 extern uint32_t FMC_Read(uint32_t u32Addr);
107 extern uint32_t FMC_ReadCID(void);
108 extern uint32_t FMC_ReadPID(void);
109 extern uint32_t FMC_ReadUCID(uint32_t u32Index);
110 extern uint32_t FMC_ReadUID(uint32_t u32Index);
111 extern uint32_t FMC_ReadDataFlashBaseAddr(void);
112 extern void FMC_SetVectorPageAddr(uint32_t u32PageAddr);
113 extern uint32_t FMC_GetVectorPageAddr(void);
114 extern void FMC_Write(uint32_t u32Addr, uint32_t u32Data);
115 extern int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count);
116 extern int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count);
117 extern int32_t FMC_GetChkSum(uint32_t u32Addr, uint32_t u32Count, uint32_t *u32ChkSum);
118 extern uint32_t FMC_CheckAllOne(uint32_t u32addr, uint32_t u32count);
119 extern int32_t FMC_SKey_Setup(uint32_t key[3], uint32_t kpmax, uint32_t kemax, int lock_CONFIG);
120 extern int32_t FMC_SKey_Compare(uint32_t key[3]);
121
122 /* end of group NANO103_FMC_EXPORTED_FUNCTIONS */
124 /* end of group NANO103_FMC_Driver */
126 /* end of group NANO103_Device_Driver */
128
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif // __FMC_H__
134
135 /*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/
FMC_ReadCID
uint32_t FMC_ReadCID(void)
Read company ID.
Definition: fmc.c:114
FMC_SKey_Compare
int32_t FMC_SKey_Compare(uint32_t key[3])
Execute security key comparison.
Definition: fmc.c:425
FMC_ReadUCID
uint32_t FMC_ReadUCID(uint32_t u32Index)
This function reads one of the four UCID.
Definition: fmc.c:143
FMC_Close
void FMC_Close(void)
Disable FMC ISP function.
Definition: fmc.c:37
FMC_SKey_Setup
int32_t FMC_SKey_Setup(uint32_t key[3], uint32_t kpmax, uint32_t kemax, int lock_CONFIG)
Setup security key.
Definition: fmc.c:364
FMC_WriteConfig
int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
Execute ISP command to write User Configuration.
Definition: fmc.c:251
FMC_CheckAllOne
uint32_t FMC_CheckAllOne(uint32_t u32addr, uint32_t u32count)
Run flash all one verification and get result.
Definition: fmc.c:310
FMC_SetVectorPageAddr
void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
This function will force re-map assigned flash page to CPU address 0x0.
Definition: fmc.c:187
FMC_Read
uint32_t FMC_Read(uint32_t u32Addr)
Execute ISP command to read a word from flash.
Definition: fmc.c:98
FMC_ReadConfig
int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
Execute ISP command to read User Configuration.
Definition: fmc.c:232
FMC_Write
void FMC_Write(uint32_t u32Addr, uint32_t u32Data)
Execute ISP command to program a word to flash.
Definition: fmc.c:213
FMC_Open
void FMC_Open(void)
Enable FMC ISP function.
Definition: fmc.c:86
FMC_Erase
int32_t FMC_Erase(uint32_t u32PageAddr)
Execute FMC_ISPCMD_PAGE_ERASE command to erase a flash page. The page size is 512 bytes.
Definition: fmc.c:51
FMC_GetChkSum
int32_t FMC_GetChkSum(uint32_t u32Addr, uint32_t u32Count, uint32_t *u32ChkSum)
Run CRC32 checksum calculation and get result.
Definition: fmc.c:272
FMC_ReadDataFlashBaseAddr
uint32_t FMC_ReadDataFlashBaseAddr(void)
Get the base address of Data Flash if enabled.
Definition: fmc.c:176
FMC_ReadUID
uint32_t FMC_ReadUID(uint32_t u32Index)
This function reads one of the three UID.
Definition: fmc.c:160
FMC_GetBootSource
int32_t FMC_GetBootSource(void)
Get the current boot source.
Definition: fmc.c:73
FMC_GetVectorPageAddr
uint32_t FMC_GetVectorPageAddr(void)
Obtain the current vector page address setting.
Definition: fmc.c:200
FMC_ReadPID
uint32_t FMC_ReadPID(void)
Read product ID.
Definition: fmc.c:128