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
34void 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
83void 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
174{
175 return FMC->DFBA;
176}
177
178
183void 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
197{
198 return (FMC->ISPSTS & 0x0FFFFF00ul);
199}
200
201
207void 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{
249 FMC_Write(FMC_CONFIG_BASE, u32Config[0]);
250 FMC_Write(FMC_CONFIG_BASE+4, u32Config[1]);
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
Mini55 series peripheral access layer header file. This file contains all the peripheral register's d...
#define FMC_ISPCTL_ISPFF_Msk
#define FMC_ISPCTL_BS_Msk
#define FMC_ISPCTL_ISPEN_Msk
#define FMC_ISPTRG_ISPGO_Msk
#define FMC_ISPCMD_PROGRAM
Definition: fmc.h:48
#define FMC_CONFIG_BASE
Definition: fmc.h:38
#define FMC_ISPCMD_READ_CID
Definition: fmc.h:50
#define FMC_ISPCMD_READ_PID
Definition: fmc.h:51
#define FMC_ISPCMD_READ
Definition: fmc.h:47
#define FMC_ISPCMD_VECMAP
Definition: fmc.h:53
#define FMC_ISPCMD_READ_UID
Definition: fmc.h:52
#define FMC_ISPCMD_PAGE_ERASE
Definition: fmc.h:49
void FMC_Close(void)
Disable all FMC functions.
Definition: fmc.c:34
int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
Execute ISP command to read User Configuration.
Definition: fmc.c:226
void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
This function will force re-map assigned flash page to CPU address 0x0.
Definition: fmc.c:183
uint32_t FMC_ReadCID(void)
Read company ID.
Definition: fmc.c:111
uint32_t FMC_GetVectorPageAddr(void)
Obtain the current vector page address setting.
Definition: fmc.c:196
uint32_t FMC_ReadUID(uint32_t u32Index)
This function reads one of the three UID.
Definition: fmc.c:157
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
uint32_t FMC_ReadDataFlashBaseAddr(void)
Get the base address of Data Flash if enabled.
Definition: fmc.c:173
#define FMC_DISABLE_CFG_UPDATE()
Definition: fmc.h:72
uint32_t FMC_Read(uint32_t u32Addr)
Execute ISP command to read a word from flash.
Definition: fmc.c:95
#define FMC_ENABLE_CFG_UPDATE()
Definition: fmc.h:71
void FMC_Write(uint32_t u32Addr, uint32_t u32Data)
Writes a word data to specified flash address.
Definition: fmc.c:207
uint32_t FMC_ReadPID(void)
Read product ID.
Definition: fmc.c:125
int32_t FMC_GetBootSource(void)
Get the current boot source.
Definition: fmc.c:71
int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
Execute ISP command to write User Configuration.
Definition: fmc.c:245
void FMC_Open(void)
Enable FMC ISP function.
Definition: fmc.c:83
uint32_t FMC_ReadUCID(uint32_t u32Index)
This function reads one of the four UCID.
Definition: fmc.c:140
#define FMC
Pointer to FMC register structure.