Microchip
直播中

刘秀英

8年用户 1416经验值
私信 关注
[问答]

写入错误的地址

我正在为一个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);Uti1616T页=(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);

回帖(3)

王璨

2019-3-22 07:36:57
也许你错过了一些东西。我假设0x149c2(Word)等于0x9894(字节不是0x29 380)-这正是HEX记录中的内容。在引导加载程序的地址计算中有一些错误?

以上来自于百度翻译


      以下为原文

    Maybe you missed something.
I assume 0x149C2 (word) equals 0x29384 (byte - not 0x29380) - and this is exactly what's in the hex records given.
Some error in the address calculations of your boot loader ?
举报

陈秀英

2019-3-22 07:52:02
是的,我弄错了。它应该是写在字节0x29 38(或字0x149c2),实际上是写入字节0x29 830(或字0x149c0)。当我通过时,地址似乎进入了正确的寄存器。整个程序的其余部分(除了这一部分是唯一一个与第四字节对齐的部分)正在正确编写。

以上来自于百度翻译


      以下为原文

    Yes, my mistake.  It is supposed to be writing at byte 0x29384 (or word 0x149C2) and is in fact writing at byte 0x29830 (or word 0x149C0).  
 
The addresses seem to be going into the registers correctly when I step through.  And the entire rest of the program (except for this one section that is the only one aligned to the 4th byte) is writing correctly.  
举报

王焕树

2019-3-22 08:04:08
仍然在你的打字中交换数字。0x29 830应该是0x29 380。

以上来自于百度翻译


      以下为原文

   
Still getting digits swapped in your typing.
0x29830 should have been 0x29380
举报

更多回帖

发帖
×
20
完善资料,
赚取积分