M471M/R1/S BSP V3.01.000
The Board Support Package for M4521
Macros | Functions
Collaboration diagram for FMC Exported Functions:

Macros

#define FMC_ENABLE_ISP()   (FMC->ISPCTL |= FMC_ISPCTL_ISPEN_Msk)
 Enable ISP Function. More...
 
#define FMC_DISABLE_ISP()   (FMC->ISPCTL &= ~FMC_ISPCTL_ISPEN_Msk)
 Disable ISP Function. More...
 
#define FMC_ENABLE_LD_UPDATE()   (FMC->ISPCTL |= FMC_ISPCTL_LDUEN_Msk)
 Enable LDROM Update Function. More...
 
#define FMC_DISABLE_LD_UPDATE()   (FMC->ISPCTL &= ~FMC_ISPCTL_LDUEN_Msk)
 Disable LDROM Update Function. More...
 
#define FMC_ENABLE_CFG_UPDATE()   (FMC->ISPCTL |= FMC_ISPCTL_CFGUEN_Msk)
 Enable User Configuration Update Function. More...
 
#define FMC_DISABLE_CFG_UPDATE()   (FMC->ISPCTL &= ~FMC_ISPCTL_CFGUEN_Msk)
 Disable User Configuration Update Function. More...
 
#define FMC_ENABLE_AP_UPDATE()   (FMC->ISPCTL |= FMC_ISPCTL_APUEN_Msk)
 Enable APROM Update Function. More...
 
#define FMC_DISABLE_AP_UPDATE()   (FMC->ISPCTL &= ~FMC_ISPCTL_APUEN_Msk)
 Disable APROM Update Function. More...
 
#define FMC_SELECT_NEXT_BOOT(x)   (FMC->ISPCTL = (FMC->ISPCTL & ~FMC_ISPCTL_BS_Msk) | ((x) << FMC_ISPCTL_BS_Pos))
 Next Booting Selection function. More...
 
#define FMC_GET_BOOT_STATUS()   ((FMC->ISPCTL & FMC_ISPCTL_BS_Msk)?1:0)
 Get MCU Booting Status. More...
 

Functions

static __INLINE void FMC_Write (uint32_t u32Addr, uint32_t u32Data)
 Program 32-bit data into specified address of flash. More...
 
static __INLINE void FMC_Write8 (uint32_t u32Addr, uint32_t u32Data0, uint32_t u32Data1)
 Program 64-bit data into specified address of flash. More...
 
static __INLINE uint32_t FMC_Read (uint32_t u32Addr)
 Read 32-bit Data from specified address of flash. More...
 
static __INLINE int32_t FMC_Erase (uint32_t u32Addr)
 Flash page erase. More...
 
static __INLINE uint32_t FMC_ReadUID (uint8_t u8Index)
 Read Unique ID. More...
 
static __INLINE uint32_t FMC_ReadCID (void)
 Read company ID. More...
 
static __INLINE uint32_t FMC_ReadPID (void)
 Read product ID. More...
 
static __INLINE uint32_t FMC_ReadUCID (uint32_t u32Index)
 To read UCID. More...
 
static __INLINE void FMC_SetVectorPageAddr (uint32_t u32PageAddr)
 Set vector mapping address. More...
 
static __INLINE uint32_t FMC_GetVECMAP (void)
 Get current vector mapping address. More...
 
static __INLINE uint32_t FMC_GetCheckSum (uint32_t u32Addr, int32_t i32Size)
 Get Flash Checksum. More...
 
static __INLINE void FMC_Write256 (uint32_t u32Addr, uint32_t *pu32Buf)
 Program Multi-Word data into specified address of flash. More...
 
void FMC_Open (void)
 Enable FMC ISP function. More...
 
void FMC_Close (void)
 Disable ISP Functions. More...
 
void FMC_EnableAPUpdate (void)
 Enable APROM update function. More...
 
void FMC_DisableAPUpdate (void)
 Disable APROM update function. More...
 
void FMC_EnableConfigUpdate (void)
 Enable User Configuration update function. More...
 
void FMC_DisableConfigUpdate (void)
 Disable User Configuration update function. More...
 
void FMC_EnableLDUpdate (void)
 Enable LDROM update function. More...
 
void FMC_DisableLDUpdate (void)
 Disable LDROM update function. More...
 
int32_t FMC_ReadConfig (uint32_t *u32Config, uint32_t u32Count)
 Read the User Configuration words. More...
 
int32_t FMC_WriteConfig (uint32_t *u32Config, uint32_t u32Count)
 Write User Configuration. More...
 
void FMC_SetBootSource (int32_t i32BootSrc)
 Set boot source from LDROM or APROM after next software reset. More...
 
int32_t FMC_GetBootSource (void)
 Get the current boot source. More...
 
uint32_t FMC_ReadDataFlashBaseAddr (void)
 Get the base address of Data Flash if enabled. More...
 
void FMC_EnableFreqOptimizeMode (uint32_t u32Mode)
 Enable Flash Access Frequency Optimization Mode. More...
 
void FMC_DisableFreqOptimizeMode (void)
 Disable Flash Access Frequency Optimization Mode. More...
 

Detailed Description

Macro Definition Documentation

◆ FMC_DISABLE_AP_UPDATE

#define FMC_DISABLE_AP_UPDATE ( )    (FMC->ISPCTL &= ~FMC_ISPCTL_APUEN_Msk)

Disable APROM Update Function.

Parameters
None
Returns
None

This function will clear APUEN bit of ISPCTL control register to disable APROM update function. Disable APROM Update Function

Definition at line 199 of file fmc.h.

◆ FMC_DISABLE_CFG_UPDATE

#define FMC_DISABLE_CFG_UPDATE ( )    (FMC->ISPCTL &= ~FMC_ISPCTL_CFGUEN_Msk)

Disable User Configuration Update Function.

Parameters
None
Returns
None

This function will clear CFGUEN bit of ISPCTL control register to disable User Configuration update function. Disable CONFIG Update Function

Definition at line 173 of file fmc.h.

◆ FMC_DISABLE_ISP

#define FMC_DISABLE_ISP ( )    (FMC->ISPCTL &= ~FMC_ISPCTL_ISPEN_Msk)

Disable ISP Function.

Parameters
None
Returns
None

This function will clear ISPEN bit of ISPCTL control register to disable ISP function. Disable ISP Function

Definition at line 123 of file fmc.h.

◆ FMC_DISABLE_LD_UPDATE

#define FMC_DISABLE_LD_UPDATE ( )    (FMC->ISPCTL &= ~FMC_ISPCTL_LDUEN_Msk)

Disable LDROM Update Function.

Parameters
None
Returns
None

This function will set ISPEN bit of ISPCTL control register to disable LDROM update function. Disable LDROM Update Function

Definition at line 148 of file fmc.h.

◆ FMC_ENABLE_AP_UPDATE

#define FMC_ENABLE_AP_UPDATE ( )    (FMC->ISPCTL |= FMC_ISPCTL_APUEN_Msk)

Enable APROM Update Function.

Parameters
None
Returns
None

This function will set APUEN bit of ISPCTL control register to enable APROM update function. User needs to set APUEN bit before they can update APROM in APROM boot mode. Enable APROM Update Function

Definition at line 187 of file fmc.h.

◆ FMC_ENABLE_CFG_UPDATE

#define FMC_ENABLE_CFG_UPDATE ( )    (FMC->ISPCTL |= FMC_ISPCTL_CFGUEN_Msk)

Enable User Configuration Update Function.

Parameters
None
Returns
None

This function will set CFGUEN bit of ISPCTL control register to enable User Configuration update function. User needs to set CFGUEN bit before they can update User Configuration area. Enable CONFIG Update Function

Definition at line 161 of file fmc.h.

◆ FMC_ENABLE_ISP

#define FMC_ENABLE_ISP ( )    (FMC->ISPCTL |= FMC_ISPCTL_ISPEN_Msk)

Enable ISP Function.

Parameters
None
Returns
None

This function will set ISPEN bit of ISPCTL control register to enable ISP function. Enable ISP Function

Definition at line 111 of file fmc.h.

◆ FMC_ENABLE_LD_UPDATE

#define FMC_ENABLE_LD_UPDATE ( )    (FMC->ISPCTL |= FMC_ISPCTL_LDUEN_Msk)

Enable LDROM Update Function.

Parameters
None
Returns
None

This function will set LDUEN bit of ISPCTL control register to enable LDROM update function. User needs to set LDUEN bit before they can update LDROM. Enable LDROM Update Function

Definition at line 136 of file fmc.h.

◆ FMC_GET_BOOT_STATUS

#define FMC_GET_BOOT_STATUS ( )    ((FMC->ISPCTL & FMC_ISPCTL_BS_Msk)?1:0)

Get MCU Booting Status.

Parameters
None
Returns
None

This function will get status of chip next booting from LDROM/APROM. Get MCU Booting Status

Definition at line 225 of file fmc.h.

◆ FMC_SELECT_NEXT_BOOT

#define FMC_SELECT_NEXT_BOOT (   x)    (FMC->ISPCTL = (FMC->ISPCTL & ~FMC_ISPCTL_BS_Msk) | ((x) << FMC_ISPCTL_BS_Pos))

Next Booting Selection function.

Parameters
[in]xBooting from APROM(0)/LDROM(1)
Returns
None

This function will set MCU next booting from LDROM/APROM.

Note
When use this macro, the Boot Loader booting selection MBS(CONFIG0[5]) must be set. Select Next Booting, x = 0 or 1

Definition at line 213 of file fmc.h.

Function Documentation

◆ FMC_Close()

void FMC_Close ( void  )

Disable ISP Functions.

Parameters
None
Returns
None

This function will clear ISPEN bit of ISPCTL to disable ISP function

Definition at line 60 of file fmc.c.

◆ FMC_DisableAPUpdate()

void FMC_DisableAPUpdate ( void  )

Disable APROM update function.

Parameters
None
Returns
None

Disable APROM update function will forbid APROM programming when boot form APROM. APROM update is default to be disable.

Definition at line 77 of file fmc.c.

◆ FMC_DisableConfigUpdate()

void FMC_DisableConfigUpdate ( void  )

Disable User Configuration update function.

Parameters
None
Returns
None

Disable User Configuration update function will forbid User Configuration programming. User Configuration update is default to be disable.

Definition at line 93 of file fmc.c.

◆ FMC_DisableFreqOptimizeMode()

void FMC_DisableFreqOptimizeMode ( void  )

Disable Flash Access Frequency Optimization Mode.

Parameters
None
Returns
None

This function will clear FOM bit fields of FTCTL register to disable flash access frequency optimization mode.

Note
The flash optimization mode (FOM) bits are write protect.

Definition at line 304 of file fmc.c.

◆ FMC_DisableLDUpdate()

void FMC_DisableLDUpdate ( void  )

Disable LDROM update function.

Parameters
None
Returns
None

Disable LDROM update function will forbid LDROM programming. LDROM update is default to be disable.

Definition at line 109 of file fmc.c.

◆ FMC_EnableAPUpdate()

void FMC_EnableAPUpdate ( void  )

Enable APROM update function.

Parameters
None
Returns
None

Enable APROM to be able to program when boot from APROM.

Definition at line 125 of file fmc.c.

◆ FMC_EnableConfigUpdate()

void FMC_EnableConfigUpdate ( void  )

Enable User Configuration update function.

Parameters
None
Returns
None

Enable User Configuration to be able to program.

Definition at line 141 of file fmc.c.

◆ FMC_EnableFreqOptimizeMode()

void FMC_EnableFreqOptimizeMode ( uint32_t  u32Mode)

Enable Flash Access Frequency Optimization Mode.

Parameters
[in]u32ModeOptimize flash access cycle mode
Returns
None

This function will set FOM bit fields of FTCTL register to set flash access frequency optimization mode.

Note
The flash optimization mode (FOM) bits are write protect.

Definition at line 286 of file fmc.c.

◆ FMC_EnableLDUpdate()

void FMC_EnableLDUpdate ( void  )

Enable LDROM update function.

Parameters
None
Returns
None

Enable LDROM to be able to program.

Definition at line 157 of file fmc.c.

◆ FMC_Erase()

static __INLINE int32_t FMC_Erase ( uint32_t  u32Addr)
static

Flash page erase.

Parameters
[in]u32AddrFlash address including APROM, LDROM, Data Flash, and CONFIG

To do flash page erase. The target address could be APROM, LDROM, Data Flash, or CONFIG. The page size is 2048 bytes.

Return values
0Success
-1Erase failed

Definition at line 335 of file fmc.h.

◆ FMC_GetBootSource()

int32_t FMC_GetBootSource ( void  )

Get the current boot source.

Parameters
None
Return values
0This chip is currently booting from APROM
1This chip is currently booting from LDROM
Note
This function only show the boot source. User need to read ISPSTA register to know if IAP mode supported or not in relative boot.

Definition at line 174 of file fmc.c.

◆ FMC_GetCheckSum()

static __INLINE uint32_t FMC_GetCheckSum ( uint32_t  u32Addr,
int32_t  i32Size 
)
static

Get Flash Checksum.

Parameters
[in]u32AddrSpecific flash start address
[in]i32SizeSpecific a size of Flash area
Returns
A checksum value of a flash block.

To get VECMAP value which is the page address for remapping to vector page (0x0).

Definition at line 551 of file fmc.h.

◆ FMC_GetVECMAP()

static __INLINE uint32_t FMC_GetVECMAP ( void  )
static

Get current vector mapping address.

Parameters
None
Returns
The current vector mapping address.

To get VECMAP value which is the page address for remapping to vector page (0x0).

Note
VECMAP only valid when new IAP function is enabled. (CBS = 10'b or 00'b)

Definition at line 535 of file fmc.h.

◆ FMC_Open()

void FMC_Open ( void  )

Enable FMC ISP function.

Parameters
None
Returns
None

ISPEN bit of ISPCTL must be set before we can use ISP commands. Therefore, To use all FMC function APIs, user needs to call FMC_Open() first to enable ISP functions.

Note
ISP functions are write-protected. user also needs to unlock it by calling SYS_UnlockReg() before using all ISP functions.

Definition at line 196 of file fmc.c.

◆ FMC_Read()

static __INLINE uint32_t FMC_Read ( uint32_t  u32Addr)
static

Read 32-bit Data from specified address of flash.

Parameters
[in]u32AddrFlash address include APROM, LDROM, Data Flash, and CONFIG
Returns
The data of specified address

To read word data from Flash include APROM, LDROM, Data Flash, and CONFIG.

Definition at line 303 of file fmc.h.

Here is the caller graph for this function:

◆ FMC_ReadCID()

static __INLINE uint32_t FMC_ReadCID ( void  )
static

Read company ID.

Parameters
None
Returns
The company ID (32-bit)

The company ID of Nuvoton is fixed to be 0xDA

Definition at line 406 of file fmc.h.

◆ FMC_ReadConfig()

int32_t FMC_ReadConfig ( uint32_t *  u32Config,
uint32_t  u32Count 
)

Read the User Configuration words.

Parameters
[out]u32ConfigThe word buffer to store the User Configuration data.
[in]u32CountThe word count to be read.
Return values
0Success
-1Failed

This function is used to read the settings of user configuration. if u32Count = 1, Only CONFIG0 will be returned to the buffer specified by u32Config. if u32Count = 2, Both CONFIG0 and CONFIG1 will be returned.

Definition at line 230 of file fmc.c.

Here is the call graph for this function:

◆ FMC_ReadDataFlashBaseAddr()

uint32_t FMC_ReadDataFlashBaseAddr ( void  )

Get the base address of Data Flash if enabled.

Parameters
None
Returns
The base address of Data Flash

This function is used to return the base address of Data Flash.

Definition at line 211 of file fmc.c.

◆ FMC_ReadPID()

static __INLINE uint32_t FMC_ReadPID ( void  )
static

Read product ID.

Parameters
None
Returns
The product ID (32-bit)

This function is used to read product ID.

Definition at line 438 of file fmc.h.

◆ FMC_ReadUCID()

static __INLINE uint32_t FMC_ReadUCID ( uint32_t  u32Index)
static

To read UCID.

Parameters
[in]u32IndexIndex of the UCID to read. u32Index must be 0, 1, 2, or 3.
Returns
The UCID of specified index

This function is used to read unique chip ID (UCID).

Definition at line 470 of file fmc.h.

◆ FMC_ReadUID()

static __INLINE uint32_t FMC_ReadUID ( uint8_t  u8Index)
static

Read Unique ID.

Parameters
[in]u8IndexUID index. 0 = UID[31:0], 1 = UID[63:32], 2 = UID[95:64]
Returns
The 32-bit unique ID data of specified UID index.

To read out 96-bit Unique ID.

Definition at line 373 of file fmc.h.

◆ FMC_SetBootSource()

void FMC_SetBootSource ( int32_t  i32BootSrc)

Set boot source from LDROM or APROM after next software reset.

Parameters
[in]i32BootSrc1: Boot from LDROM, 0: Boot from APROM
Returns
None

This function is used to switch APROM boot or LDROM boot. User need to call FMC_SetBootSource to select boot source first, then use CPU reset or System Reset Request to reset system.

Definition at line 41 of file fmc.c.

◆ FMC_SetVectorPageAddr()

static __INLINE void FMC_SetVectorPageAddr ( uint32_t  u32PageAddr)
static

Set vector mapping address.

Parameters
[in]u32PageAddrThe page address to remap to address 0x0. The address must be page alignment.
Returns
To set VECMAP to remap specified page address to 0x0.

This function is used to set VECMAP to map specified page to vector page (0x0).

Note
VECMAP only valid when new IAP function is enabled. (CBS = 10'b or 00'b)

Definition at line 505 of file fmc.h.

◆ FMC_Write()

static __INLINE void FMC_Write ( uint32_t  u32Addr,
uint32_t  u32Data 
)
static

Program 32-bit data into specified address of flash.

Parameters
[in]u32AddrFlash address include APROM, LDROM, Data Flash, and CONFIG
[in]u32Data32-bit Data to program
Returns
None

To program word data into Flash include APROM, LDROM, Data Flash, and CONFIG. The corresponding functions in CONFIG are listed in FMC section of Technical Reference Manual.

Definition at line 242 of file fmc.h.

Here is the caller graph for this function:

◆ FMC_Write256()

static __INLINE void FMC_Write256 ( uint32_t  u32Addr,
uint32_t *  pu32Buf 
)
static

Program Multi-Word data into specified address of flash.

Parameters
[in]u32AddrFlash address include APROM, LDROM, Data Flash, and CONFIG
[in]pu32BufA data pointer is point to a data buffer start address;
Returns
None

To program multi-words data into Flash include APROM, LDROM, Data Flash, and CONFIG. The corresponding functions in CONFIG are listed in FMC section of Technical Reference Manual.

Definition at line 587 of file fmc.h.

◆ FMC_Write8()

static __INLINE void FMC_Write8 ( uint32_t  u32Addr,
uint32_t  u32Data0,
uint32_t  u32Data1 
)
static

Program 64-bit data into specified address of flash.

Parameters
[in]u32AddrFlash address include APROM, LDROM, Data Flash, and CONFIG
[in]u32Data032-bit Data to program
[in]u32Data132-bit Data to program
Returns
None

To program two words data into Flash include APROM, LDROM, Data Flash, and CONFIG. The corresponding functions in CONFIG are listed in FMC section of Technical Reference Manual.

Definition at line 273 of file fmc.h.

◆ FMC_WriteConfig()

int32_t FMC_WriteConfig ( uint32_t *  u32Config,
uint32_t  u32Count 
)

Write User Configuration.

Parameters
[in]u32ConfigThe word buffer to store the User Configuration data.
[in]u32CountThe word count to program to User Configuration.
Return values
0Success
-1Failed

User must enable User Configuration update before writing it. User must erase User Configuration before writing it. User Configuration is also be page erase. User needs to backup necessary data before erase User Configuration.

Definition at line 255 of file fmc.c.

Here is the call graph for this function: