1 简述在APROM上执行源代码, 更新LDROM内存, 再读回做确认 1.1 环境需求设定l M051系列芯片 x 1 l 此示例需在APROM上运行 1.2 芯片设定l HCLK =外部晶振 (4~24MHz) l FMC设定: n 使能ISP功能与LDROM更新功能 (LDUEN = 1) 1.3 示例目录l App_Src 示例主程序 l Lib_Src M051系列启动文件(*.s) 以及FMC的源代码 l Lib_Inc Lib_Src源代码的头文件以及M051系列寄存器的定义 2 程序介绍 2.1 Main 函数初始化系统时钟以及FMC. 对地址0x10_0000 - 0x10_01FF做页擦除 (1页=512 bytes), 再对地址0x10_0000写入32-bit的数据. 最后, 再将地址0x10_0000的内存数据读回. 读回的数据应该要和写入的数据相同. uint32_tdata = 0x87654321 ; int32_tmain (void) { uint32_t add = 0x00100000 ; // LDROM基地址 UnlockReg(); // 关掉寄存器写保护 SYSCLK->PWRCON |=SYSCLK_PWRCON_XTL12M_EN_Msk; while(!(SYSCLK->CLKSTATUS &CLK_CLKSTATUS_HXT_STB)); SYSCLK->CLKSEL0 = 0; // 选择外部时钟作为系统时钟 FMC_Open(); // 使能ISP时钟,ISP功能,以及LDROM更新功能 FMC_Erase(add); // 擦除LDROM页 (Address 0x100000~0x1001FF) FMC_Write(add, 0x12505678); // 写数据0x12505678到LDROM(地址 0x100000) data=FMC_Read(add) ; // 读LDROM地址 (Address 0x100000) while(1) ; }
2.2 FMC_Open函数(ldrom.c)使能ISP时钟与功能,并且使能LDROM更新功能 voidFMC_Open(void) { SYSCLK->AHBCLK |= 4 ; // 使能ISP时钟 FMC->ISPCON |= FMC_ISPCON_ISPEN_Msk ; // 使能ISP功能 FMC->ISPCON |= FMC_ISPCON_LDUEN_Msk ; // 使能LDROM更新功能 }
2.3 FMC_Erase,FMC_Write, FMC_Read函数(ldrom.c)FMC_Erase, FMC_Write,FMC_Read分别为页擦除, 烧写, 以及读取内存三个函数. voidFMC_Erase(uint32_t u32addr) { FMC->ISPCMD = FMC_ISPCMD_PAGE_ERASE; // ISP命令:页擦除 FMC->ISPADR = u32addr ; FMC->ISPTRG = 0x1 ; while(FMC->ISPTRG) ; } voidFMC_Write(uint32_t u32addr, uint32_t u32data) { FMC->ISPCMD = FMC_ISPCMD_PROGRAM ; // ISP命令:字编程 FMC->ISPADR = u32addr ; FMC->ISPDAT = u32data ; FMC->ISPTRG = 0x1 ; while(FMC->ISPTRG) ; } uint32_tFMC_Read(uint32_t u32addr) { FMC->ISPCMD = FMC_ISPCMD_READ ; // ISP命令:字读取 FMC->ISPADR = u32addr ; FMC->ISPDAT = 0 ; FMC->ISPTRG = 0x1 ; while(FMC->ISPTRG) ; return FMC->ISPDAT ; }
3 运行结果对地址做写入数据0x12505678前,变量data的值设为:0x87654321 在完成写入后,读回LDROM地址0x10_0000的内容后,变量data变成了0x12505678,与写入值相同。
Important Notice Nuvoton products are not designed, intended,authorized or warranted for use as components in systems or equipment intendedfor surgical implantation, atomic energy control instruments, airplane orspaceship instruments, transportation instruments, traffic signal instruments,combustion control instruments, or for other applications intended to supportor sustain life. Furthermore, Nuvoton products are not intended forapplications wherein failure of Nuvoton products could result or lead to asituation wherein personal injury, death or severe property or environmentaldamage could occur. Nuvoton customers using or selling theseproducts for use in such applications do so at their own risk and agree tofully indemnify Nuvoton for any damages resulting from such improper use orsales. Please note that alldata and specifications are subject to change without notice. All thetrademarks of products and companies mentioned in this datasheet belong totheir respective owners.
|