我正在为一个DSPIC33 EV128GM102编写一个自定义引导加载程序,它基本上运行良好,直到我在HEX文件中得到以下几行::020000 0402F8:10938、4000、F0500、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、000、0、85、0、0、0、0、0、2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 85,这些数据应从程序地址0x149C2(字节地址0x29 380)开始写入,但应改为它写在程序地址0x149c0。我已经通过了代码,所有的东西看起来都是正确的,直到它实际写入数据(我将在底部附加代码)。所以我有2个问题。首先,我是否遗漏了什么东西,或者在这个地址不可能开始双字写入操作?我想我可以从任何一个地址开始。其次,如果不可能,那么编译器为什么要从这个地址开始定位一个部分?有没有一种简单的方法来阻止它呢?这里是写函数。我正在通过地址0x149c2./*获取闪存位置的页面和偏移来写入*/ut1616t偏移=(Unt16-t)((地址)和0xFFFFU);U
ti1616T页=(UTI1616T)((地址& gt;& 16t)和0xFFFFU);/*设置指针到NVM位置开始编程*/NVMADRU=页;NVMADR= OffSE具有写入值*/tBLPAG=0xFA的锁存器;γ-Bug TynIn TBLWTL(0,LSW1);γ-BuuTiTiNi TBLWTH(0,MSW1);γ-BuuTiTnIn TBLWTL(2U,LSW2);α-Bug TynIn TBLWTH(2U,MSW2);NVMCON=Studio Word;SETION和SaveSub CPUIL IPL(SaveDay-IPL,7);荷载;荷载
以上来自于百度翻译
以下为原文
I am writing a custom bootloader for a dsPIC33EV128GM102 and it is mostly working fine until I get to the following lines in the hex file:
:020000040002F8
:109384004F05000000000000000000000000000085
Here, the data should be written starting at program address 0x149C2 (byte address 0x29380) but instead it writes it at program address 0x149C0. I've stepped through the code and everything looks right until it actually writes the data (I'll attach code at the bottom). So I have 2 questions. First, am I missing something or is it not possible to start a double word write operation at this address? I thought I could start at any even address. Second, If it's not possible then why does the compiler locate a section starting at this address? Is there a simple way to prevent it from doing this?
Here is the write function. I am passing the address of 0x149C2.
/* Get page and offset of Flash location to write */
uint16_t offset = (uint16_t)((address) & 0xFFFFu);
uint16_t page = (uint16_t)((address >> 16u) & 0xFFFFu);
/* Setup pointers to NVM location to start programming */
NVMADRU = page;
NVMADR = offset;
/* Load Latches with the write values */
TBLPAG = 0xFA;
__builtin_tblwtl(0, lsw1);
__builtin_tblwth(0, msw1);
__builtin_tblwtl(2u, lsw2);
__builtin_tblwth(2u, msw2);
NVMCON = PROGRAM_WORD;
SET_AND_SAVE_CPU_IPL(saved_ipl, 7);
__builtin_write_NVM();
RESTORE_CPU_IPL(saved_ipl);