| NUC472_NUC442_BSP V3.03.003 The Board Support Package for NUC472/NUC442

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 0x00080000UL
40#define FMC_LDROM_BASE 0x00100000UL
41#define FMC_LDROM_END 0x00104000UL
42#define FMC_CONFIG_BASE 0x00300000UL
44#define FMC_FLASH_PAGE_SIZE 0x800
45#define FMC_LDROM_SIZE 0x4000
47/*---------------------------------------------------------------------------------------------------------*/
48/* ISPCMD constant definitions */
49/*---------------------------------------------------------------------------------------------------------*/
50#define FMC_ISPCMD_READ 0x00
51#define FMC_ISPCMD_READ_64 0x40
52#define FMC_ISPCMD_PROGRAM 0x21
53#define FMC_ISPCMD_WRITE 0x21
54#define FMC_ISPCMD_WRITE_64 0x61
55#define FMC_ISPCMD_PAGE_ERASE 0x22
56#define FMC_ISPCMD_READ_CID 0x0B
57#define FMC_ISPCMD_READ_PID 0x0C
58#define FMC_ISPCMD_READ_UID 0x04
59#define ISP_ISPCMD_MULTI_WRITE 0x27
60#define FMC_ISPCMD_VECMAP 0x2E
62#define IS_BOOT_FROM_APROM 0
63#define IS_BOOT_FROM_LDROM 1
65#define FMC_TIMEOUT_READ ((SystemCoreClock/10))
66#define FMC_TIMEOUT_WRITE ((SystemCoreClock/10))
67#define FMC_TIMEOUT_ERASE ((SystemCoreClock/10)*2) /* end of group NUC472_442_FMC_EXPORTED_CONSTANTS */
70
71
72
78/*---------------------------------------------------------------------------------------------------------*/
79/* Macros */
80/*---------------------------------------------------------------------------------------------------------*/
81
88#define FMC_SET_APROM_BOOT() (FMC->ISPCTL &= ~FMC_ISPCTL_BS_Msk)
89
96#define FMC_SET_LDROM_BOOT() (FMC->ISPCTL |= FMC_ISPCTL_BS_Msk)
97
104#define FMC_ENABLE_AP_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_APUEN_Msk)
105
112#define FMC_DISABLE_AP_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_APUEN_Msk)
113
120#define FMC_ENABLE_CFG_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_CFGUEN_Msk)
121
128#define FMC_DISABLE_CFG_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_CFGUEN_Msk)
129
136#define FMC_ENABLE_LD_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_LDUEN_Msk)
137
144#define FMC_DISABLE_LD_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_LDUEN_Msk)
145
152#define FMC_ENABLE_ISP() (FMC->ISPCTL |= FMC_ISPCTL_ISPEN_Msk)
160#define FMC_DISABLE_ISP() (FMC->ISPCTL &= ~FMC_ISPCTL_ISPEN_Msk)
161
168#define FMC_GET_FAIL_FLAG() ((FMC->ISPSTS & FMC_ISPSTS_ISPFF_Msk) ? 1 : 0)
169
176#define FMC_CLR_FAIL_FLAG() (FMC->ISPSTS |= FMC_ISPSTS_ISPFF_Msk)
179/*---------------------------------------------------------------------------------------------------------*/
180/* Global variables */
181/*---------------------------------------------------------------------------------------------------------*/
182 extern int32_t g_FMC_i32ErrCode;
183
184
185/*---------------------------------------------------------------------------------------------------------*/
186/* Functions */
187/*---------------------------------------------------------------------------------------------------------*/
188
189 extern void FMC_Close(void);
190 extern int32_t FMC_Erase(uint32_t u32PageAddr);
191 extern int32_t FMC_GetBootSource(void);
192 extern void FMC_Open(void);
193 extern uint32_t FMC_Read(uint32_t u32Addr);
194 extern int32_t FMC_Read_64(uint32_t u32Addr, uint32_t *u32Data0, uint32_t *u32Data1);
195 extern uint32_t FMC_ReadCID(void);
196 extern uint32_t FMC_ReadPID(void);
197 extern uint32_t FMC_ReadUCID(uint32_t u32Index);
198 extern uint32_t FMC_ReadUID(uint32_t u32Index);
199 extern uint32_t FMC_ReadDataFlashBaseAddr(void);
200 extern int32_t FMC_SetVectorPageAddr(uint32_t u32PageAddr);
201 extern uint32_t FMC_GetVectorPageAddr(void);
202 extern int32_t FMC_Write(uint32_t u32Addr, uint32_t u32Data);
203 extern int32_t FMC_Write_64(uint32_t u32Addr, uint32_t u32Data0, uint32_t u32Data1);
204 extern int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count);
205 extern int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count);
206 extern uint32_t FMC_CRC8(uint32_t au32Data[], int i32Count);
207
208 /* end of group NUC472_442_FMC_EXPORTED_FUNCTIONS */
210 /* end of group NUC472_442_FMC_Driver */
212 /* end of group NUC472_442_Device_Driver */
214
215#ifdef __cplusplus
216}
217#endif
218
219#endif
220
221/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
FMC_Close
void FMC_Close(void)
Disable FMC ISP function.
Definition: fmc.c:37
FMC_Write_64
int32_t FMC_Write_64(uint32_t u32Addr, uint32_t u32Data0, uint32_t u32Data1)
Execute ISP 64-bits write command to program two words to flash.
Definition: fmc.c:374
g_FMC_i32ErrCode
int32_t g_FMC_i32ErrCode
Definition: fmc.c:31
FMC_ReadConfig
int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
Read the User Configuration words.
Definition: fmc.c:446
FMC_ReadCID
uint32_t FMC_ReadCID(void)
Read company ID.
Definition: fmc.c:175
FMC_GetVectorPageAddr
uint32_t FMC_GetVectorPageAddr(void)
Obtain the current vector page address setting.
Definition: fmc.c:319
FMC_ReadUID
uint32_t FMC_ReadUID(uint32_t u32Index)
This function reads one of the three UID.
Definition: fmc.c:260
FMC_Erase
int32_t FMC_Erase(uint32_t u32PageAddr)
Erase a page. The page size is 2048 bytes.
Definition: fmc.c:53
FMC_ReadDataFlashBaseAddr
uint32_t FMC_ReadDataFlashBaseAddr(void)
Get the base address of Data Flash if enabled.
Definition: fmc.c:282
FMC_Write
int32_t FMC_Write(uint32_t u32Addr, uint32_t u32Data)
Execute ISP command to program a word to flash.
Definition: fmc.c:337
FMC_Read
uint32_t FMC_Read(uint32_t u32Addr)
Execute ISP command to read a word from flash.
Definition: fmc.c:113
FMC_ReadPID
uint32_t FMC_ReadPID(void)
Read product ID.
Definition: fmc.c:206
FMC_CRC8
uint32_t FMC_CRC8(uint32_t au32Data[], int i32Count)
CRC8 Calculator.
Definition: fmc.c:407
FMC_GetBootSource
int32_t FMC_GetBootSource(void)
Get the current boot source.
Definition: fmc.c:84
FMC_WriteConfig
int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
Write User Configuration.
Definition: fmc.c:473
FMC_Read_64
int32_t FMC_Read_64(uint32_t u32Addr, uint32_t *u32Data0, uint32_t *u32Data1)
Execute ISP 64-bits read command to read two words from flash.
Definition: fmc.c:143
FMC_SetVectorPageAddr
int32_t FMC_SetVectorPageAddr(uint32_t u32PageAddr)
This function will force re-map assigned flash page to CPU address 0x0.
Definition: fmc.c:297
FMC_Open
void FMC_Open(void)
Enable FMC ISP function.
Definition: fmc.c:97
FMC_ReadUCID
uint32_t FMC_ReadUCID(uint32_t u32Index)
This function reads one of the four UCID.
Definition: fmc.c:233