05 Nutiny-Nuc029 FMC
05 Nutiny-Nuc029 FMC
05 Nutiny-Nuc029 FMC
June 2016
Agenda
• Flash Memory Map
• Flash Memory Features
• User Configuration - Config0
• Boot Selection
- In System Programming (ISP) – Bootloader Code Size limited to LDROM(8KB)
- In Application Programming (IAP) - Bootloader Code Size share with APROM
• Functions and Sample Code in BSP
• Sample Code
2
Flash Memory Map-Physical Address
Reserved
0x0030_0004
0x0030_0000
User Configuration
(8B) Config : chip related settings
Reserved
0x0010_1FFF
Loader ROM
(LDROM 8KB)
LDROM : User’s Bootloader
0x0010_0000
Reserved
APROM : Main Application
0x0001_FFFF
Dataflash
Data Flash is shared with APROM
DFBA
128KB
ApplicationROM
(APROM)
0x0000_0000
APROM 128KB
3
APROM & DataFlash
5
Flash Memory Features – (2)
• CRC-32 Checksum Calculation Function
• Update embedded flash memory
– In-System-Programming (ISP)
– In-Application-Programming (IAP)
6
Config0 – (1)
31 30 29 28 27 26 25 24
CWDTEN CWDTPDEN Reserved CGPFMFP CFOSC
23 22 21 20 19 18 17 16
15 14 13 12 11 10 9 8
7 6 5 4 3 2 1 0
7
Config0 – (2)
• CWDTEN: Watchdog Enable Bit
- 0 = Watchdog Timer Enabled and force Watchdog Timer clock source as OSC10K after chip powered on.
- 1 = Watchdog Timer Disabled after chip powered on.
• CWDTPDEN: Watchdog Clock Power-down Enable Bit
- 0 = OSC10K Watchdog Timer clock source is forced to be always enabled.
- 1 = OSC10K Watchdog Timer clock source is controlled by OSC10K_EN (PWRCON[3]) when chip enters
Power-down. Note: This bit only works at CWDTEN is set to 0
• CGPFMFP: GPF Multi-function Selection
- 0 = XT1_IN and XT1_OUT pin is configured as GPIO function.
- 1 = XT1_IN and XT1_OUT pin is used as external 4~24MHz crystal oscillator pin.
Note: XT1_IN, XT1_OUT multi-function can only be changed by CGPFMFP.
• CFOSC: CPU Clock Source Selection after Reset
- 000 = External 4~24 MHz high speed crystal oscillator clock.
- 111 = Internal RC 22.1184 MHz high speed oscillator clock.
- Others = Reserved.
The value of CFOSC will be load to HCLK_S (CLKSEL0[2:0]) in system register after any reset occurs.
8
Config0 – (3)
• CBODEN : Brown-out Detector Enable Bit
- 0 = Brown-out detect Enabled after powered on.
- 1 = Brown-out detect Disabled after powered on.
11
In System Programming (ISP)
• The purpose of ISP provides a facility way to update
application and data in APROM.
• ISP program resides in LDROM. User program runs in APROM.
• ISP Master (PC or NuMicro board) control ISP program
through UART/USB/I2C/SPI.
12
ISP Command
13
ISP Control Flow: 32-bit Programming Example
Start
Set ISPGO = 1
Check ISPFF = 1?
Add ISB instruction
End of ISP NO
NO Operation
Check ISPGO = 0 ?
?
YES
YES
Stop
32-bit Programming
14
Boot selection without IAP mode (Logical address)
Reserved
ApplicationROM
(APROM)
0x0000_0FFF
Loader ROM
(LDROM)
0x0000_0000
16
In Application Programming (IAP)
• Chip boots from LDROM with the IAP function enabled (CBS[1:0] = 00b),
the executable range of code includes all of LDROM and almost all of
APROM except for its first page. User cannot access the first page of
APROM by CPU because the first page of executable code range becomes
the mirror of the first page of LDROM as set by default. Meanwhile, the
address space of 8 KB LDROM is mapped to 0x0010_0000~0x0010_1FFF.
• When chip boots with the IAP function enabled, any other page within
the executable range of code can be mirrored to the first page of
executable code (0x0000_0000~0x0000_01FF) any time. User can change
the remap address of the first executing page by filling the target remap
address to ISPADR and then go through ISP procedure with the Vector
Page Re-map command. After changing the remap address, user can
check if the change is successful by reading the VECMAP field in the 17
ISPSTA register
In-Application-Program (IAP)
• System memory map
0x0000_0000 to 0x0000_01FF
0x0010_0000
Loader ROM
(LDROM 4KB)
0x0003_FFFF
Reserved
Data Flash
-
(0x0001_FFFF)
0x0000_0200
VECMAP (FMC_ISPSTS[20:9]) 0x0000_01FF
System Memory Vector
0x0000_0000
18
Sample Code Path
NUC029xEEBSPv3.00.001
SampleCode
FMC_IAP
Fmc_ap_main.uvproj
KEIL
19
Functions and Sample Code in BSP
• \SampleCode\StdDriver
- FMC_ExeInSRAM
- FMC_IAP
- FMC_RW
20
Functions and Sample Code in BSP
• fmc.h
- static __INLINE void FMC_Write (uint32_t u32addr, uint32_t u32data)
Program 32-bit data into specified address of flash
- static __INLINE uint32_t FMC_Read(uint32_t u32Addr)
Read 32-bit Data from specified address of flash
- static __INLINE int32_t FMC_Erase(uint32_t u32Addr)
Flash page erase
- static __INLINE void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
Set vector mapping address
21
Functions and Sample Code in BSP
• fmc.c
- void FMC_Open(void)
Enable FMC ISP function
- void FMC_SetBootSource(int32_t i32BootSrc)
Set boot source from LDROM or APROM after next software reset
- void FMC_EnableAPUpdate(void)
Enable APROM update function
22
Fmc_ap_main
int main() {
/* Unlock protected registers */
SYS_UnlockReg();
……
/* Enable FMC ISP function */
FMC_Open();
/* Enable IAP function */
if(SetIAPBoot() < 0) {
printf("Failed to set IAP boot mode!\n");
goto lexit;
}
/*Boot mode APROM+IAP/
printf(" Boot Mode ............................. ");
u32CBS = (FMC->ISPSTA & FMC_ISPSTA_CBS_Msk) >> FMC_ISPSTA_CBS_Pos;
printf("[%s]\n", acBootMode[u32CBS]);
24
Flash Page Erase Flow – 512 bytes
• The data changes from 0 to 1 (One way)
Start
Enable ISPEN
Set ISPGO = 1
Check ISPFF = 1?
Add ISB instruction
End of ISP NO
NO Operation
Check ISPGO = 0 ?
?
YES
YES
Stop 25
Flowchart – FMC R/W
Sample Code Path
NUC029xEEBSPv3.00.001
SampleCode
FMC_RW
fmc_rw.uvproj
KEIL
28
fmc_rw
int main()
{
uint32_t i, u32Data;
/* Enable FMC ISP function */
FMC_Open();
if(SetDataFlashBase(DATA_FLASH_TEST_BASE) < 0) {
printf("Failed to set Data Flash base address!\n");
goto lexit;
}
/* Read BS */
printf(" Boot Mode ............................. ");
if(FMC_GetBootSource() == 0)
printf("[APROM]\n");
else {
printf("[LDROM]\n");
printf(" WARNING: The driver sample code must execute in AP mode!\n");
goto lexit;
29
}
fmc_rw
/* Read User Configuration */
printf(" User Config 0 ......................... [0x%08x]\n", FMC_Read(FMC_CONFIG_BASE));
printf(" User Config 1 ......................... [0x%08x]\n", FMC_Read(FMC_CONFIG_BASE + 4));
/* Read Data Flash base address */
u32Data = FMC_ReadDataFlashBaseAddr();
printf(" Data Flash Base Address ............... [0x%08x]\n", u32Data);
FMC_EnableAPUpdate();
if(FlashTest(APROM_TEST_BASE, DATA_FLASH_TEST_BASE, TEST_PATTERN) < 0) {
printf("\n\nAPROM test failed!\n");
goto lexit;
}
FMC_DisableAPUpdate();
printf("\n\nData Flash test =>\n");
if(FlashTest(DATA_FLASH_TEST_BASE, DATA_FLASH_TEST_END, TEST_PATTERN) < 0) {
printf("\n\nUHB test failed!\n");
}
30
Thank you!