| NUC029FAE BSP V3.01.002 The Board Support Package for NUC029FAE

fmc.c
Go to the documentation of this file.
1 /**************************************************************************/
13 //* Includes ------------------------------------------------------------------*/
14 #include <stdio.h>
15 #include "NUC029FAE.h"
16
36 void FMC_SetBootSource (int32_t i32BootSrc)
37 {
38 if (i32BootSrc == 1)
39 FMC->ISPCON |= FMC_ISPCON_BS_Msk;
40 else
41 FMC->ISPCON &= ~FMC_ISPCON_BS_Msk;
42 }
43
44
48 void FMC_Close(void)
49 {
50 FMC->ISPCON &= ~FMC_ISPCON_ISPEN_Msk;
51 }
52
53
57 void FMC_DisableAPUpdate(void)
58 {
59 FMC->ISPCON &= ~FMC_ISPCON_APUEN_Msk;
60 }
61
62
66 void FMC_DisableConfigUpdate(void)
67 {
68 FMC->ISPCON &= ~FMC_ISPCON_CFGUEN_Msk;
69 }
70
71
75 void FMC_DisableLDUpdate(void)
76 {
77 FMC->ISPCON &= ~FMC_ISPCON_LDUEN_Msk;
78 }
79
80
84 void FMC_EnableAPUpdate(void)
85 {
86 FMC->ISPCON |= FMC_ISPCON_APUEN_Msk;
87 }
88
89
93 void FMC_EnableConfigUpdate(void)
94 {
95 FMC->ISPCON |= FMC_ISPCON_CFGUEN_Msk;
96 }
97
98
102 void FMC_EnableLDUpdate(void)
103 {
104 FMC->ISPCON |= FMC_ISPCON_LDUEN_Msk;
105 }
106
107
114 int32_t FMC_Erase(uint32_t u32PageAddr)
115 {
116 FMC->ISPCMD = FMC_ISPCMD_PAGE_ERASE;
117 FMC->ISPADR = u32PageAddr;
118 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
119
120 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
121
122 if (FMC->ISPCON & FMC_ISPCON_ISPFF_Msk)
123 {
124 FMC->ISPCON |= FMC_ISPCON_ISPFF_Msk;
125 return -1;
126 }
127 return 0;
128 }
129
130
136 int32_t FMC_GetBootSource (void)
137 {
138 if (FMC->ISPCON & FMC_ISPCON_BS_Msk)
139 return 1;
140 else
141 return 0;
142 }
143
144
148 void FMC_Open(void)
149 {
150 FMC->ISPCON |= FMC_ISPCON_ISPEN_Msk;
151 }
152
153
159 uint32_t FMC_Read(uint32_t u32Addr)
160 {
161 FMC->ISPCMD = FMC_ISPCMD_READ;
162 FMC->ISPADR = u32Addr;
163 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
164
165 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
166
167 return FMC->ISPDAT;
168 }
169
170
175 uint32_t FMC_ReadCID(void)
176 {
177 FMC->ISPCMD = FMC_ISPCMD_READ_CID;
178 FMC->ISPADR = 0x0;
179 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
180 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
181 return FMC->ISPDAT;
182 }
183
184
189 uint32_t FMC_ReadPID(void)
190 {
191 FMC->ISPCMD = FMC_ISPCMD_READ_PID;
192 FMC->ISPADR = 0x04;
193 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
194 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
195 return FMC->ISPDAT;
196 }
197
198
204 uint32_t FMC_ReadUCID(uint32_t u32Index)
205 {
206 FMC->ISPCMD = FMC_ISPCMD_READ_UID;
207 FMC->ISPADR = (0x04 * u32Index) + 0x10;
208 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
209
210 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
211
212 return FMC->ISPDAT;
213 }
214
215
221 uint32_t FMC_ReadUID(uint32_t u32Index)
222 {
223 FMC->ISPCMD = FMC_ISPCMD_READ_UID;
224 FMC->ISPADR = 0x04 * u32Index;
225 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
226
227 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
228
229 return FMC->ISPDAT;
230 }
231
232
237 uint32_t FMC_ReadDataFlashBaseAddr(void)
238 {
239 return FMC->DFBADR;
240 }
241
242
247 void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
248 {
249 FMC->ISPCMD = FMC_ISPCMD_VECMAP;
250 FMC->ISPADR = u32PageAddr;
251 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
252 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
253 }
254
255
261 void FMC_Write(uint32_t u32Addr, uint32_t u32Data)
262 {
263 FMC->ISPCMD = FMC_ISPCMD_PROGRAM;
264 FMC->ISPADR = u32Addr;
265 FMC->ISPDAT = u32Data;
266 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
267 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
268 }
269
270
278 int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
279 {
280 u32Config[0] = FMC_Read(FMC_CONFIG_BASE);
281 if (u32Count < 2)
282 return 0;
283 u32Config[1] = FMC_Read(FMC_CONFIG_BASE+4);
284 return 0;
285 }
286
287
295 int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
296 {
297 FMC_EnableConfigUpdate();
298 FMC_Erase(FMC_CONFIG_BASE);
299 FMC_Write(FMC_CONFIG_BASE, u32Config[0]);
300 FMC_Write(FMC_CONFIG_BASE+4, u32Config[1]);
301 FMC_DisableConfigUpdate();
302 return 0;
303 }
304
305 /* end of group NUC029FAE_FMC_EXPORTED_FUNCTIONS */
307 /* end of group NUC029FAE_FMC_Driver */
309 /* end of group NUC029FAE_Device_Driver */
311
312 /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
313
314
FMC_ISPCMD_READ_UID
#define FMC_ISPCMD_READ_UID
Definition: fmc.h:51
FMC_ISPCMD_PROGRAM
#define FMC_ISPCMD_PROGRAM
Definition: fmc.h:47
NUC029FAE.h
NUC029FAE peripheral access layer header file. This file contains all the peripheral register's defin...
FMC_ISPCMD_READ_PID
#define FMC_ISPCMD_READ_PID
Definition: fmc.h:50
FMC_EnableConfigUpdate
void FMC_EnableConfigUpdate(void)
Enable User Configuration update function.
Definition: fmc.c:93
FMC_Read
uint32_t FMC_Read(uint32_t u32Addr)
Read a word from specified flash address.
Definition: fmc.c:159
FMC_ReadUCID
uint32_t FMC_ReadUCID(uint32_t u32Index)
This function reads one of the four UCID.
Definition: fmc.c:204
FMC_Erase
int32_t FMC_Erase(uint32_t u32PageAddr)
Erase a page. The page size is 512 bytes.
Definition: fmc.c:114
FMC_DisableAPUpdate
void FMC_DisableAPUpdate(void)
Disable APROM update function.
Definition: fmc.c:57
FMC_Open
void FMC_Open(void)
Enable FMC ISP function.
Definition: fmc.c:148
FMC_ReadUID
uint32_t FMC_ReadUID(uint32_t u32Index)
This function reads one of the three UID.
Definition: fmc.c:221
FMC_ReadPID
uint32_t FMC_ReadPID(void)
Read product ID.
Definition: fmc.c:189
FMC_DisableLDUpdate
void FMC_DisableLDUpdate(void)
Disable LDROM update function.
Definition: fmc.c:75
FMC_EnableLDUpdate
void FMC_EnableLDUpdate(void)
Enable LDROM update function.
Definition: fmc.c:102
FMC_ReadConfig
int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
Read the User Configuration words.
Definition: fmc.c:278
FMC_DisableConfigUpdate
void FMC_DisableConfigUpdate(void)
Disable User Configuration update function.
Definition: fmc.c:66
FMC_SetVectorPageAddr
void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
This function will force re-map assigned flash page to CPU address 0x0.
Definition: fmc.c:247
FMC_CONFIG_BASE
#define FMC_CONFIG_BASE
Definition: fmc.h:37
FMC_EnableAPUpdate
void FMC_EnableAPUpdate(void)
Enable APROM update function.
Definition: fmc.c:84
FMC_ReadCID
uint32_t FMC_ReadCID(void)
Read company ID.
Definition: fmc.c:175
FMC_Write
void FMC_Write(uint32_t u32Addr, uint32_t u32Data)
Writes a word data to specified flash address.
Definition: fmc.c:261
FMC_ISPCMD_PAGE_ERASE
#define FMC_ISPCMD_PAGE_ERASE
Definition: fmc.h:48
FMC_SetBootSource
void FMC_SetBootSource(int32_t i32BootSrc)
Set boot source of next software reset.
Definition: fmc.c:36
FMC_ISPCMD_READ
#define FMC_ISPCMD_READ
Definition: fmc.h:46
FMC
#define FMC
Pointer to FMC register structure.
Definition: NUC029FAE.h:3243
FMC_Close
void FMC_Close(void)
Disable all FMC functions.
Definition: fmc.c:48
FMC_WriteConfig
int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
Write User Configuration.
Definition: fmc.c:295
FMC_ReadDataFlashBaseAddr
uint32_t FMC_ReadDataFlashBaseAddr(void)
Get the base address of Data Flash if enabled.
Definition: fmc.c:237
FMC_GetBootSource
int32_t FMC_GetBootSource(void)
get the current boot source
Definition: fmc.c:136
FMC_ISPCMD_VECMAP
#define FMC_ISPCMD_VECMAP
Definition: fmc.h:52
FMC_ISPCMD_READ_CID
#define FMC_ISPCMD_READ_CID
Definition: fmc.h:49