| Mini51 BSP V3.02.002 The Board Support Package for Mini51 Series

fmc.c
Go to the documentation of this file.
1 /**************************************************************************/
13 //* Includes ------------------------------------------------------------------*/
14 #include <stdio.h>
15 #include "Mini51Series.h"
16
34 void FMC_Close(void)
35 {
36 FMC->ISPCON &= ~FMC_ISPCON_ISPEN_Msk;
37 }
38
39
46 int32_t FMC_Erase(uint32_t u32PageAddr)
47 {
48 FMC->ISPCMD = FMC_ISPCMD_PAGE_ERASE;
49 FMC->ISPADR = u32PageAddr;
50 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
51
52 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
53
54 if (FMC->ISPCON & FMC_ISPCON_ISPFF_Msk)
55 {
56 FMC->ISPCON |= FMC_ISPCON_ISPFF_Msk;
57 return -1;
58 }
59 return 0;
60 }
61
62
68 int32_t FMC_GetBootSource (void)
69 {
70 if (FMC->ISPCON & FMC_ISPCON_BS_Msk)
71 return 1;
72 else
73 return 0;
74 }
75
76
80 void FMC_Open(void)
81 {
82 FMC->ISPCON |= FMC_ISPCON_ISPEN_Msk;
83 }
84
85
91 uint32_t FMC_Read(uint32_t u32Addr)
92 {
93 FMC->ISPCMD = FMC_ISPCMD_READ;
94 FMC->ISPADR = u32Addr;
95 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
96
97 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
98
99 return FMC->ISPDAT;
100 }
101
102
107 uint32_t FMC_ReadCID(void)
108 {
109 FMC->ISPCMD = FMC_ISPCMD_READ_CID;
110 FMC->ISPADR = 0x0;
111 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
112 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
113 return FMC->ISPDAT;
114 }
115
116
121 uint32_t FMC_ReadPID(void)
122 {
123 FMC->ISPCMD = FMC_ISPCMD_READ_PID;
124 FMC->ISPADR = 0x04;
125 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
126 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
127 return FMC->ISPDAT;
128 }
129
130
136 uint32_t FMC_ReadUCID(uint32_t u32Index)
137 {
138 FMC->ISPCMD = FMC_ISPCMD_READ_UID;
139 FMC->ISPADR = (0x04 * u32Index) + 0x10;
140 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
141
142 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
143
144 return FMC->ISPDAT;
145 }
146
147
153 uint32_t FMC_ReadUID(uint32_t u32Index)
154 {
155 FMC->ISPCMD = FMC_ISPCMD_READ_UID;
156 FMC->ISPADR = 0x04 * u32Index;
157 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
158
159 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
160
161 return FMC->ISPDAT;
162 }
163
164
169 uint32_t FMC_ReadDataFlashBaseAddr(void)
170 {
171 return FMC->DFBADR;
172 }
173
174
179 void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
180 {
181 FMC->ISPCMD = FMC_ISPCMD_VECMAP;
182 FMC->ISPADR = u32PageAddr;
183 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
184 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
185 }
186
187
192 uint32_t FMC_GetVectorPageAddr(void)
193 {
194 return (FMC->ISPSTA & 0x0FFFFF00ul);
195 }
196
197
203 void FMC_Write(uint32_t u32Addr, uint32_t u32Data)
204 {
205 FMC->ISPCMD = FMC_ISPCMD_PROGRAM;
206 FMC->ISPADR = u32Addr;
207 FMC->ISPDAT = u32Data;
208 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
209 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
210 }
211
212
220 int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
221 {
222 u32Config[0] = FMC_Read(FMC_CONFIG_BASE);
223 if (u32Count < 2)
224 return 0;
225 u32Config[1] = FMC_Read(FMC_CONFIG_BASE+4);
226 return 0;
227 }
228
229
237 int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
238 {
239 FMC_ENABLE_CFG_UPDATE();
240 FMC_Erase(FMC_CONFIG_BASE);
241 FMC_Write(FMC_CONFIG_BASE, u32Config[0]);
242 FMC_Write(FMC_CONFIG_BASE+4, u32Config[1]);
243 FMC_DISABLE_CFG_UPDATE();
244 return 0;
245 }
246
247 /* end of group MINI51_FMC_EXPORTED_FUNCTIONS */
249 /* end of group MINI51_FMC_Driver */
251 /* end of group MINI51_Device_Driver */
253
254 /*** (C) COPYRIGHT 2013~2015 Nuvoton Technology Corp. ***/
255
256
FMC_ReadUID
uint32_t FMC_ReadUID(uint32_t u32Index)
This function reads one of the three UID.
Definition: fmc.c:153
FMC_Open
void FMC_Open(void)
Enable FMC ISP function.
Definition: fmc.c:80
FMC_ReadPID
uint32_t FMC_ReadPID(void)
Read product ID.
Definition: fmc.c:121
FMC_CONFIG_BASE
#define FMC_CONFIG_BASE
Definition: fmc.h:37
Mini51Series.h
Mini51 series peripheral access layer header file. This file contains all the peripheral register's d...
FMC_GetBootSource
int32_t FMC_GetBootSource(void)
get the current boot source
Definition: fmc.c:68
FMC_ISPCMD_VECMAP
#define FMC_ISPCMD_VECMAP
Definition: fmc.h:52
FMC_WriteConfig
int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
Write User Configuration.
Definition: fmc.c:237
FMC_ISPCMD_READ_PID
#define FMC_ISPCMD_READ_PID
Definition: fmc.h:50
FMC_Erase
int32_t FMC_Erase(uint32_t u32PageAddr)
Erase a page. The page size is 512 bytes.
Definition: fmc.c:46
FMC_ISPCMD_PAGE_ERASE
#define FMC_ISPCMD_PAGE_ERASE
Definition: fmc.h:48
FMC_SetVectorPageAddr
void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
This function will force re-map assigned flash page to CPU address 0x0.
Definition: fmc.c:179
FMC_ISPCMD_READ
#define FMC_ISPCMD_READ
Definition: fmc.h:46
FMC_ReadUCID
uint32_t FMC_ReadUCID(uint32_t u32Index)
This function reads one of the four UCID.
Definition: fmc.c:136
FMC_Close
void FMC_Close(void)
Disable all FMC functions.
Definition: fmc.c:34
FMC_ISPCON_ISPEN_Msk
#define FMC_ISPCON_ISPEN_Msk
Definition: Mini51Series.h:1899
FMC_ISPCMD_READ_CID
#define FMC_ISPCMD_READ_CID
Definition: fmc.h:49
FMC_Write
void FMC_Write(uint32_t u32Addr, uint32_t u32Data)
Writes a word data to specified flash address.
Definition: fmc.c:203
FMC_ISPCON_BS_Msk
#define FMC_ISPCON_BS_Msk
Definition: Mini51Series.h:1902
FMC_ReadCID
uint32_t FMC_ReadCID(void)
Read company ID.
Definition: fmc.c:107
FMC_ISPCON_ISPFF_Msk
#define FMC_ISPCON_ISPFF_Msk
Definition: Mini51Series.h:1914
FMC_ISPCMD_READ_UID
#define FMC_ISPCMD_READ_UID
Definition: fmc.h:51
FMC_ReadConfig
int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
Read the User Configuration words.
Definition: fmc.c:220
FMC_DISABLE_CFG_UPDATE
#define FMC_DISABLE_CFG_UPDATE()
Definition: fmc.h:64
FMC_GetVectorPageAddr
uint32_t FMC_GetVectorPageAddr(void)
Obtain the current vector page address setting.
Definition: fmc.c:192
FMC
#define FMC
Pointer to FMC register structure.
Definition: Mini51Series.h:9946
FMC_ReadDataFlashBaseAddr
uint32_t FMC_ReadDataFlashBaseAddr(void)
Get the base address of Data Flash if enabled.
Definition: fmc.c:169
FMC_Read
uint32_t FMC_Read(uint32_t u32Addr)
Read a word from specified flash address.
Definition: fmc.c:91
FMC_ISPCMD_PROGRAM
#define FMC_ISPCMD_PROGRAM
Definition: fmc.h:47
FMC_ISPTRG_ISPGO_Msk
#define FMC_ISPTRG_ISPGO_Msk
Definition: Mini51Series.h:1926
FMC_ENABLE_CFG_UPDATE
#define FMC_ENABLE_CFG_UPDATE()
Definition: fmc.h:69