| MINI55_BSP V3.02.004 The Board Support Package for Mini55 Series MCU

fmc.c
Go to the documentation of this file.
1/**************************************************************************/
13//* Includes ------------------------------------------------------------------*/
14#include <stdio.h>
15#include "Mini55Series.h"
16
34 void FMC_Close(void)
35{
36 FMC->ISPCTL &= ~FMC_ISPCTL_ISPEN_Msk;
37}
38
39
48int32_t FMC_Erase(uint32_t u32PageAddr)
49{
50 FMC->ISPCMD = FMC_ISPCMD_PAGE_ERASE;
51 FMC->ISPADDR = u32PageAddr;
52 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
53
54 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
55
56 if (FMC->ISPCTL & FMC_ISPCTL_ISPFF_Msk)
57 {
58 FMC->ISPCTL |= FMC_ISPCTL_ISPFF_Msk;
59 return -1;
60 }
61 return 0;
62}
63
64
71int32_t FMC_GetBootSource (void)
72{
73 if (FMC->ISPCTL & FMC_ISPCTL_BS_Msk)
74 return 1;
75 else
76 return 0;
77}
78
79
83 void FMC_Open(void)
84{
85 FMC->ISPCTL |= FMC_ISPCTL_ISPEN_Msk;
86}
87
88
95uint32_t FMC_Read(uint32_t u32Addr)
96{
97 FMC->ISPCMD = FMC_ISPCMD_READ;
98 FMC->ISPADDR = u32Addr;
99 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
100
101 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
102
103 return FMC->ISPDAT;
104}
105
106
111uint32_t FMC_ReadCID(void)
112{
113 FMC->ISPCMD = FMC_ISPCMD_READ_CID;
114 FMC->ISPADDR = 0x0;
115 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
116 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
117 return FMC->ISPDAT;
118}
119
120
125uint32_t FMC_ReadPID(void)
126{
127 FMC->ISPCMD = FMC_ISPCMD_READ_PID;
128 FMC->ISPADDR = 0x04;
129 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
130 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
131 return FMC->ISPDAT;
132}
133
134
140uint32_t FMC_ReadUCID(uint32_t u32Index)
141{
142 FMC->ISPCMD = FMC_ISPCMD_READ_UID;
143 FMC->ISPADDR = (0x04 * u32Index) + 0x10;
144 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
145
146 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
147
148 return FMC->ISPDAT;
149}
150
151
157uint32_t FMC_ReadUID(uint32_t u32Index)
158{
159 FMC->ISPCMD = FMC_ISPCMD_READ_UID;
160 FMC->ISPADDR = 0x04 * u32Index;
161 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
162
163 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
164
165 return FMC->ISPDAT;
166}
167
168
173uint32_t FMC_ReadDataFlashBaseAddr(void)
174{
175 return FMC->DFBA;
176}
177
178
183 void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
184{
185 FMC->ISPCMD = FMC_ISPCMD_VECMAP;
186 FMC->ISPADDR = u32PageAddr;
187 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
188 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
189}
190
191
196uint32_t FMC_GetVectorPageAddr(void)
197{
198 return (FMC->ISPSTS & 0x0FFFFF00ul);
199}
200
201
207 void FMC_Write(uint32_t u32Addr, uint32_t u32Data)
208{
209 FMC->ISPCMD = FMC_ISPCMD_PROGRAM;
210 FMC->ISPADDR = u32Addr;
211 FMC->ISPDAT = u32Data;
212 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
213 while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;
214}
215
216
226int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
227{
228 u32Config[0] = FMC_Read(FMC_CONFIG_BASE);
229 if (u32Count < 2)
230 return 0;
231 u32Config[1] = FMC_Read(FMC_CONFIG_BASE+4);
232 return 0;
233}
234
235
245int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
246{
247 FMC_ENABLE_CFG_UPDATE();
248 FMC_Erase(FMC_CONFIG_BASE);
249 FMC_Write(FMC_CONFIG_BASE, u32Config[0]);
250 FMC_Write(FMC_CONFIG_BASE+4, u32Config[1]);
251 FMC_DISABLE_CFG_UPDATE();
252 return 0;
253}
254
255 /* end of group MINI55_FMC_EXPORTED_FUNCTIONS */
257 /* end of group MINI55_FMC_Driver */
259 /* end of group MINI55_Device_Driver */
261
262/*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/
263
264
Mini55Series.h
Mini55 series peripheral access layer header file. This file contains all the peripheral register's d...
FMC_ISPCTL_ISPFF_Msk
#define FMC_ISPCTL_ISPFF_Msk
Definition: Mini55Series.h:1439
FMC_ISPCTL_BS_Msk
#define FMC_ISPCTL_BS_Msk
Definition: Mini55Series.h:1427
FMC_ISPCTL_ISPEN_Msk
#define FMC_ISPCTL_ISPEN_Msk
Definition: Mini55Series.h:1424
FMC_ISPTRG_ISPGO_Msk
#define FMC_ISPTRG_ISPGO_Msk
Definition: Mini55Series.h:1451
FMC_ISPCMD_PROGRAM
#define FMC_ISPCMD_PROGRAM
Definition: fmc.h:48
FMC_CONFIG_BASE
#define FMC_CONFIG_BASE
Definition: fmc.h:38
FMC_ISPCMD_READ_CID
#define FMC_ISPCMD_READ_CID
Definition: fmc.h:50
FMC_ISPCMD_READ_PID
#define FMC_ISPCMD_READ_PID
Definition: fmc.h:51
FMC_ISPCMD_READ
#define FMC_ISPCMD_READ
Definition: fmc.h:47
FMC_ISPCMD_VECMAP
#define FMC_ISPCMD_VECMAP
Definition: fmc.h:53
FMC_ISPCMD_READ_UID
#define FMC_ISPCMD_READ_UID
Definition: fmc.h:52
FMC_ISPCMD_PAGE_ERASE
#define FMC_ISPCMD_PAGE_ERASE
Definition: fmc.h:49
FMC_Close
void FMC_Close(void)
Disable all FMC functions.
Definition: fmc.c:34
FMC_ReadConfig
int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
Execute ISP command to read User Configuration.
Definition: fmc.c:226
FMC_SetVectorPageAddr
void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
This function will force re-map assigned flash page to CPU address 0x0.
Definition: fmc.c:183
FMC_ReadCID
uint32_t FMC_ReadCID(void)
Read company ID.
Definition: fmc.c:111
FMC_GetVectorPageAddr
uint32_t FMC_GetVectorPageAddr(void)
Obtain the current vector page address setting.
Definition: fmc.c:196
FMC_ReadUID
uint32_t FMC_ReadUID(uint32_t u32Index)
This function reads one of the three UID.
Definition: fmc.c:157
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:48
FMC_ReadDataFlashBaseAddr
uint32_t FMC_ReadDataFlashBaseAddr(void)
Get the base address of Data Flash if enabled.
Definition: fmc.c:173
FMC_DISABLE_CFG_UPDATE
#define FMC_DISABLE_CFG_UPDATE()
Definition: fmc.h:72
FMC_Read
uint32_t FMC_Read(uint32_t u32Addr)
Execute ISP command to read a word from flash.
Definition: fmc.c:95
FMC_ENABLE_CFG_UPDATE
#define FMC_ENABLE_CFG_UPDATE()
Definition: fmc.h:71
FMC_Write
void FMC_Write(uint32_t u32Addr, uint32_t u32Data)
Writes a word data to specified flash address.
Definition: fmc.c:207
FMC_ReadPID
uint32_t FMC_ReadPID(void)
Read product ID.
Definition: fmc.c:125
FMC_GetBootSource
int32_t FMC_GetBootSource(void)
Get the current boot source.
Definition: fmc.c:71
FMC_WriteConfig
int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
Execute ISP command to write User Configuration.
Definition: fmc.c:245
FMC_Open
void FMC_Open(void)
Enable FMC ISP function.
Definition: fmc.c:83
FMC_ReadUCID
uint32_t FMC_ReadUCID(uint32_t u32Index)
This function reads one of the four UCID.
Definition: fmc.c:140
FMC
#define FMC
Pointer to FMC register structure.
Definition: Mini55Series.h:7019