前言:
现代微控制器利用闪存代替EEPROM作为代码存储器,实现了代码存储器编程,而无需独立的程序员。
本文将介绍Nuvoton MCU的原理和使用代码存储器编程的多种方式,同时请注意,不同品牌可能对下面使用的技术术语有不同的定义
基本知识
ICE
ICE通过外部调试探针(如Nu-Link, ST-LINK, J-Link或其他东西)启用处理器核心寄存器和内存访问。它可以帮助开发人员在不影响目标电路功能的情况下跟踪微控制器的执行状态。ICE的通用接口是ARM调试接口架构规范中规定的串行线调试端口(SW-DP或SWD)和JTAG-DP。Nuvoton的芯片通常提供SWD作为ICE接口。
闪存控制器(FMC)
FMC是系统存储器和片上闪存之间的接口,它允许我们通过FMC寄存器访问闪存,该寄存器已经位于系统内存映射中。
闪存组织
Flash memory organizationNuvoton的大部分芯片都有三种不同的闪存,包括approm、LDROM和Data flash。一般来说,APROM用于存储提供给目标应用程序的程序,LDROM用于存储将在应用程序之前执行的引导加载程序。数据Flash与approm共享,由DFBA在配置位中确定,用户可以编程,并且可以通过ISP命令编程,不需要解锁approm的写权限。
Chip Booting Selection (CBS)
配置位中的CBS决定了芯片的启动方式,有四种启动方式,包括带IAP的LDROM、不带IAP的LDROM、带IAP的APROM和不带IAP的APROM。如果芯片启动没有IAP模式,approm和LDROM将只有一个出现在系统内存映射中,这意味着只能在CPU执行其中的代码时自行访问它们。
Memory map
在大多数Nuvoton的芯片中,Flash Memory Map与System Memory Map不同。Flash Memory Map用于FMC访问Flash。系统内存映射就是CPU所要查看的。闪存可以映射到系统内存映射中,映射地址是通过配置位中的芯片引导选择(CBS)设置的。例如,LDROM的Flash Memory Map从0x00100000开始,可以通过在CBS中选择Boot from LDROM without IAP mode来映射到System Memory Map中的0x00000000。
In-System Programming (ISP)FMC provide ISP Commands include read, erase, program, and vector remap. Accessing the FMC registers with corresponding commands and data via firmware or ICE can produce the flash memory programing. If you are doing APROM update by the firmware, it usually has a separate firmware called bootloader which located in LDROM to interact between FMC and the others peripheral such like UART, USB, CAN. In-Circuit Programming (ICP)ICP utilize the memory access feature of ICE, sending the ISP Commands direct to the FMC registers without firmware. It needs a programming tool (software) to handle the commands and data between host computer, debug probe and FMC registers. Nuvoton provide NuMicro ICP Programming Tool which can be download from their website. If you are using a brand-new chip, it’s supposed to to use the ICP to program your code. In-Application Programming (IAP)IAP brings more flexibility to the developers. If the IAP function is enabled by the CBS[0], the whole flash memory will appear in System Memory Map. This means CPU can executing the code in APROM, LDROM even the SRAM without rebooting the chip. IAP mode also let the APROM, LDROM even the SRAM able to map into a 512-byte of Vector Map Space. The Vector Map Space used for the Cortex-M Vector table which contains the reset value of the main stack pointer, the start addresse, and interrupt vector table. IAP brings more flexibility to the developers to customize the code executing location and the interrupt service routine.
Performing firmware updateNuMicro ICP Programming ToolNuMicro ISP Programming ToolISP bootloaderUARTUSBCANOpenOCD
参考代码
https://github.com/ZaleYu/OpenOCD-Nuvoton
|