为了以后项目升级方便的需要,在原始程序添加CanBoot下载功能;
1、 把Bootloader安排在高地址区间 (比如0xEE00~0xFFAF),然后固化NVC寄存器的值,将这块Flash区域保护起来;
2、中断向量的搬移,将原来0xFFC0所对应的中断向量搬移到0xEDC0;
Bootloader的代码无非就是启动、查找用户程序入口,跳转至用户程序,从用户程序跳转至bootloader,与上位机通信(UART或者CAN),擦除Flash,写入Flash等功能;
具体操作就是修改两部分;
1、修改Project.prm文件,重新划分分区。我划分的分区如下所示:
SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
Z_RAM = READ_WRITE 0x0080 TO 0x00FF;
RAM = READ_WRITE 0x0100 TO 0x107F;
APP_ROM_ENTRY = READ_ONLY 0xEDB0 TO 0xEDBF;
APP_ROM = READ_ONLY 0x1900 TO 0xEB00;
DATA_ROM = READ_ONLY 0xEB00 TO 0xEDAF;
APP_ROM1 = READ_ONLY 0x1080 TO 0x13FF;
BOOT_ROM = READ_ONLY 0xEE00 TO 0xF8FF;
BOOT_ROM1 = READ_ONLY 0xF900 TO 0xFFAD;
EEPROM = READ_ONLY 0x1400 TO 0x17FF;
/* INTVECTS = READ_ONLY 0xFFC0 TO 0xFFFF; Reserved for Interrupt Vectors */
/* INTVECTS_REL = READ_ONLY 0xEDC0 TO 0xEDFF; Reserved for Relocated Interrupt Vectors */
END
2、修改中断向量表,如下所示:
#include "Interrupt.h"
#if (0 == DEBUG_ON)
const char NVPROT_INIT@0xFFBD = 0xFC; //4.5K保护0xEE00~0xFFFF
const char NVOPT_INIT@0xFFBF = 0x20; //中断向量重映射
#endif
extern void _Startup(void);
#pragma CODE_SEG APP_ENTRY
void AppEntry(void)
{
_Startup();
}
#pragma CODE_SEG DEFAULT
extern void ISR_RTC(void);
extern void ISR_Key(void);
void DummyISR(void)
{
for(;;);
}
/*** 重定向的中断向量表 ***/
#if (0 == DEBUG_ON)
const void (* const _VectRedirection[])( ) @0xEDC0 =
#else
const void (* const _VectRedirection[])( ) @0xFFC0 =
#endif
{
DummyISR, // 0xFFC0:ACMP2
DummyISR, // 0xFFC2:ACMP1
DummyISR, // 0xFFC4:MSCAN Transmit
DummyISR, // 0xFFC6:MSCAN Receive
DummyISR, // 0xFFC8:MSCAN Errors
DummyISR, // 0xFFCA:MSCAN Wake Up
ISR_RTC, // 0xFFCC:RTC
DummyISR, // 0xFFCE:IIC
DummyISR, // 0xFFD0:ADC Conversion
ISR_Key, // 0xFFD2:Port A,B,D Pin
DummyISR, // 0xFFD4:SCI2 Transmit
DummyISR, // 0xFFD6:SCI2 Receive
DummyISR, // 0xFFD8:SCI2 Error
DummyISR, // 0xFFDA:SCI1 Transmit
DummyISR, // 0xFFDC:SCI1 Receive
DummyISR, // 0xFFDE:SCI1 Error
DummyISR, // 0xFFE0:SPI
DummyISR, // 0xFFE2:TPM2 Overflow
DummyISR, // 0xFFE4:TPM2 Channel 1
DummyISR, // 0xFFE6:TPM2 Channel 0
DummyISR, // 0xFFE8:TPM1 Overflow
DummyISR, // 0xFFEA:TPM1 Channel 5
DummyISR, // 0xFFEC:TPM1 Channel 4
DummyISR, // 0xFFEE:TPM1 Channel 3
DummyISR, // 0xFFF0:TPM1 Channel 2
DummyISR, // 0xFFF2:TPM1 Channel 1
DummyISR, // 0xFFF4:TPM1 Channel 0
DummyISR, // 0xFFF6:MCG Loss of Lock
DummyISR, // 0xFFF8:Low Voltage Detect
DummyISR, // 0xFFFA:IRQ
DummyISR, // 0xFFFC:SWI
// _Startup, // 0xFFFE:Reset Cannot be redirected
};
下载并修改BootLoader,此处注意BootLoader下载程序时首先要对dz60进行复位,要根据dz60的供电电源电压设置复位电压,否则可能导致单片机一直处于复位状态。
上一篇:Nordic52810入门篇 - 实时时钟(RTC)
下一篇:NRF52840学习历程(六)RTC 实时计数器(滴答定时器)
推荐阅读最新更新时间:2024-11-04 18:50