| Nano102_112 Series BSP V3.03.002 The Board Support Package for Nano102_112 Series

fmc.c
Go to the documentation of this file.
1 /**************************************************************************/
13 //* Includes ------------------------------------------------------------------*/
14 #include <stdio.h>
15
16 #include "Nano1X2Series.h"
17
18
37 void FMC_Close(void)
38 {
39 FMC->ISPCON &= ~FMC_ISPCON_ISPEN_Msk;
40 }
41
42
51 int32_t FMC_Erase(uint32_t u32PageAddr)
52 {
53 FMC->ISPCMD = FMC_ISPCMD_PAGE_ERASE;
54 FMC->ISPADR = u32PageAddr;
55 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
56
57 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
58
59 if (FMC->ISPCON & FMC_ISPCON_ISPFF_Msk)
60 {
61 FMC->ISPCON |= FMC_ISPCON_ISPFF_Msk;
62 return -1;
63 }
64 return 0;
65 }
66
67
74 int32_t FMC_GetBootSource (void)
75 {
76 if (FMC->ISPCON & FMC_ISPCON_BS_Msk)
77 return 1;
78 else
79 return 0;
80 }
81
82
87 void FMC_Open(void)
88 {
89 FMC->ISPCON |= FMC_ISPCON_ISPEN_Msk;
90 }
91
92
99 uint32_t FMC_Read(uint32_t u32Addr)
100 {
101 FMC->ISPCMD = FMC_ISPCMD_READ;
102 FMC->ISPADR = u32Addr;
103 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
104
105 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
106
107 return FMC->ISPDAT;
108 }
109
110
115 uint32_t FMC_ReadCID(void)
116 {
117 FMC->ISPCMD = FMC_ISPCMD_READ_CID;
118 FMC->ISPADR = 0x0;
119 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
120 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
121 return FMC->ISPDAT;
122 }
123
124
129 uint32_t FMC_ReadPID(void)
130 {
131 FMC->ISPCMD = FMC_ISPCMD_READ_PID;
132 FMC->ISPADR = 0x04;
133 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
134 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
135 return FMC->ISPDAT;
136 }
137
138
144 uint32_t FMC_ReadUCID(uint32_t u32Index)
145 {
146 FMC->ISPCMD = FMC_ISPCMD_READ_UID;
147 FMC->ISPADR = (0x04 * u32Index) + 0x10;
148 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
149
150 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
151
152 return FMC->ISPDAT;
153 }
154
155
161 uint32_t FMC_ReadUID(uint32_t u32Index)
162 {
163 FMC->ISPCMD = FMC_ISPCMD_READ_UID;
164 FMC->ISPADR = 0x04 * u32Index;
165 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
166
167 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
168
169 return FMC->ISPDAT;
170 }
171
172
177 uint32_t FMC_ReadDataFlashBaseAddr(void)
178 {
179 return FMC->DFBADR;
180 }
181
182
188 void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
189 {
190 FMC->ISPCMD = FMC_ISPCMD_VECMAP;
191 FMC->ISPADR = u32PageAddr;
192 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
193 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
194 }
195
196
201 uint32_t FMC_GetVectorPageAddr(void)
202 {
203 return (FMC->ISPSTA & 0x0FFFFF00ul);
204 }
205
206
214 void FMC_Write(uint32_t u32Addr, uint32_t u32Data)
215 {
216 FMC->ISPCMD = FMC_ISPCMD_PROGRAM;
217 FMC->ISPADR = u32Addr;
218 FMC->ISPDAT = u32Data;
219 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
220 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
221 }
222
223
233 int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
234 {
235 u32Config[0] = FMC_Read(FMC_CONFIG_BASE);
236 if (u32Count < 2)
237 return 0;
238 u32Config[1] = FMC_Read(FMC_CONFIG_BASE+4);
239 return 0;
240 }
241
242
252 int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
253 {
254 FMC_ENABLE_CFG_UPDATE();
255 FMC_Erase(FMC_CONFIG_BASE);
256 FMC_Write(FMC_CONFIG_BASE, u32Config[0]);
257 FMC_Write(FMC_CONFIG_BASE+4, u32Config[1]);
258 FMC_DISABLE_CFG_UPDATE();
259 return 0;
260 }
261
262 /* end of group NANO1X2_FMC_EXPORTED_FUNCTIONS */
264 /* end of group NANO1X2_FMC_Driver */
266 /* end of group NANO1X2_Device_Driver */
268
269 /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
270
271
FMC_SetVectorPageAddr
void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
This function will force re-map assigned flash page to CPU address 0x0.
Definition: fmc.c:188
FMC_ReadUCID
uint32_t FMC_ReadUCID(uint32_t u32Index)
This function reads one of the four UCID.
Definition: fmc.c:144
FMC_ReadCID
uint32_t FMC_ReadCID(void)
Read company ID.
Definition: fmc.c:115
FMC_ISPCMD_PROGRAM
#define FMC_ISPCMD_PROGRAM
Definition: fmc.h:53
FMC_ISPTRG_ISPGO_Msk
#define FMC_ISPTRG_ISPGO_Msk
Definition: Nano1X2Series.h:2650
FMC_ISPCMD_READ_UID
#define FMC_ISPCMD_READ_UID
Definition: fmc.h:57
FMC_DISABLE_CFG_UPDATE
#define FMC_DISABLE_CFG_UPDATE()
Definition: fmc.h:80
FMC_ReadConfig
int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
Execute ISP command to read User Configuration.
Definition: fmc.c:233
FMC_Open
void FMC_Open(void)
Enable FMC ISP function.
Definition: fmc.c:87
FMC_ReadUID
uint32_t FMC_ReadUID(uint32_t u32Index)
This function reads one of the three UID.
Definition: fmc.c:161
FMC_Close
void FMC_Close(void)
Disable FMC ISP function.
Definition: fmc.c:37
FMC_ISPCON_BS_Msk
#define FMC_ISPCON_BS_Msk
Definition: Nano1X2Series.h:2620
Nano1X2Series.h
Nano102/112 peripheral access layer header file. This file contains all the peripheral register's def...
FMC_ENABLE_CFG_UPDATE
#define FMC_ENABLE_CFG_UPDATE()
Definition: fmc.h:79
FMC_ISPCMD_READ_PID
#define FMC_ISPCMD_READ_PID
Definition: fmc.h:56
FMC_GetBootSource
int32_t FMC_GetBootSource(void)
Get the current boot source.
Definition: fmc.c:74
FMC_ISPCON_ISPFF_Msk
#define FMC_ISPCON_ISPFF_Msk
Definition: Nano1X2Series.h:2632
FMC_ISPCMD_READ_CID
#define FMC_ISPCMD_READ_CID
Definition: fmc.h:55
FMC_ISPCMD_READ
#define FMC_ISPCMD_READ
Definition: fmc.h:52
FMC_ISPCON_ISPEN_Msk
#define FMC_ISPCON_ISPEN_Msk
Definition: Nano1X2Series.h:2617
FMC_ReadPID
uint32_t FMC_ReadPID(void)
Read product ID.
Definition: fmc.c:129
FMC_Write
void FMC_Write(uint32_t u32Addr, uint32_t u32Data)
Execute ISP command to program a word to flash.
Definition: fmc.c:214
FMC_CONFIG_BASE
#define FMC_CONFIG_BASE
Definition: fmc.h:44
FMC_GetVectorPageAddr
uint32_t FMC_GetVectorPageAddr(void)
Obtain the current vector page address setting.
Definition: fmc.c:201
FMC_Erase
int32_t FMC_Erase(uint32_t u32PageAddr)
Execute ISP command to erase a flash page. The page size is 512 bytes.
Definition: fmc.c:51
FMC
#define FMC
Pointer to FMC register structure.
Definition: Nano1X2Series.h:10665
FMC_ISPCMD_VECMAP
#define FMC_ISPCMD_VECMAP
Definition: fmc.h:58
FMC_Read
uint32_t FMC_Read(uint32_t u32Addr)
Execute ISP command to read a word from flash.
Definition: fmc.c:99
FMC_ReadDataFlashBaseAddr
uint32_t FMC_ReadDataFlashBaseAddr(void)
Get the base address of Data Flash if enabled.
Definition: fmc.c:177
FMC_ISPCMD_PAGE_ERASE
#define FMC_ISPCMD_PAGE_ERASE
Definition: fmc.h:54
FMC_WriteConfig
int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
Execute ISP command to write User Configuration.
Definition: fmc.c:252