完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我试图通过覆盖一个程序指令来在DSSPICEV128GM102上为Bootloader编写一个修补程序。该指令目前是一个分支到无限循环和(0x3FFFF),而我只是试图将其更改为0x3FF8C。不知何故,总是有一个位是不正确的。当我告诉它写0x37 FF8C时,我读了它,新的值是0x33 FF8C。在尝试了第一个字节的许多不同的值之后,我发现如果我试图为命令字节写0x3f,我得到了想要的0x37,但是当我这样做时,跳转地址变为0xFF9C。例行程序在调试配置时工作正常,有人能帮助我吗?请参见下面的代码。*定义环地址(Uti32),0x2E6U定义FungPy值(unxFu8t)(0xFF8C)空隙FLASH PATCH55(空隙){/*检查在PC位置0x02e6的Flash中的相对分支地址。*/Unt1616t SaveDeIpl;UTI32×t ADR= Loopl地址;StIsIa和SaveSePcPuiIPL(SaveDay-IPL,7);TBLPAG=0U;如果有一个循环指令,则假定这是1.1.55*/yz f IFDEF *调试((LVAL=0xFFFF)和AMP;(HVAL=0x00 FF))。T值*/Unt1616t偏移=(Unt16-t)((ADR)& 0xFFFFU);UTI1616T页=(UTI1616T)((ADR & GT;16U)和0xFFFFU);/*设置指针到闪存位置*/NVMADRU=页;NVMADR=偏移;/*设置TBLPAG指向数据锁存寄存器*/TBLPAG=0xFA;/*设置NVM控制寄存器对于写操作*/NVMCON=Studio Word;/*写入数据到锁存器//OxBuffTiNIN TBLWTL(0,0xFFFF);γ-Bug TynIn TBLWTH(0,0xFFFF);γ-Bug TynIn TBLWTL(2,JUMPPY值);γ-Bug TynIn TBLWTH(2,0x00 37);/*开始写操作*/Y-BuuthTiNoWrnWiMe();/*等待写入完成* /(NVMCONBIT.W)CUPYIPIL(SaveDayIpl);}空隙FlldRead EdWord(UTIN 32×T ADR,UTIN 16LT LSW1,UTI1616T MSW1,UTI1616T LSW2,UIT1616 T MSW2){UIT88T SaveDePiIPL;/*获取页面和偏移值*/Unt1616t偏移=(UTI1616T)((ADR)& 0xFFFFU);UTI1616T页=(UTIN 16t)((ADR & GT;16U)和0;R==1U){}}XFFFUU);StIGH和SaveSub CPUIL IPL(SaveDay-IPL,7);/*保存IRQ优先级和禁用*中断,用于Flash写入*//*安装指针到闪存位置*/NVMADRU=页面;NVMADR=偏移;/*设置TBLPAG指向数据锁存寄存器*/TBLPAG=0xFA;/*设置NVM控制寄存器用于WRITE操作*/NVMCON=Studio Word;/*写入数据到锁存器//OxBuiTiNIN TBLWTL(0,LSW1);γ-Bug TynIn TBLWTH(0,MSW1);γ-Bug TynIn TBLWTL(2,LSW2);γ-Bug TynIn TBLWTH(2,MSW2);/*开始写操作*/Y-BuuthTiNoWrnWiMe();/*等待写入完成* /(NVMCONBITW.W==1U){RESTE.CPUIIPL(SaveDayIpl);/*恢复IRQ优先级级别*/}
以上来自于百度翻译 以下为原文 I am trying to write a patch for a bootloader on a dsPIC33EV128GM102 by overwriting a single program instruction. The instruction is currently a branch to an infinite loop and (0x37FFFF) and I am just trying to change it to 0x37FF8C. Somehow there is always a single bit that is incorrect. When I tell it to write 0x37FF8C I read it back and the new value is 0x33FF8C. After trying a number of different values for the first byte I figured out that if I tried to write 0x3F for the command byte I got the desired 0x37, but when I did that the jump address changed to 0xFF9C. To top it off the routine works as expected when in debug configuration. Can someone please help me? See the code below. #define LOOP_ADDRESS (uint32_t)0x2E6u #define JUMP_VALUE (int16_t)(0xFF8C) void FLASH_patch55(void) { /* Check relative branch address at PC location 0x02E6 in flash.*/ uint16_t saved_ipl; uint32_t adr = LOOP_ADDRESS; SET_AND_SAVE_CPU_IPL(saved_ipl, 7); TBLPAG = 0u; int16_t lval = __builtin_tblrdl(adr); int16_t hval = __builtin_tblrdh(adr); /* If there is a loop instruction there assume this is version 1.1.55 */ #ifdef __DEBUG if ((lval == 0xFFFF) && (hval == 0x00FF)) #else if ((lval == 0xFFFF) && (hval == 0x0037u)) #endif /* __DEBUG */ { /* Get page and offset values */ uint16_t offset = (uint16_t)((adr) & 0xFFFFu); uint16_t page = (uint16_t)((adr >> 16u) & 0xFFFFu); /* Setup pointers to flash memory location*/ NVMADRU = page; NVMADR = offset; /* Set TBLPAG to point to data latch registers */ TBLPAG = 0xFA; /* Set NVM Control register for write operation */ NVMCON = PROGRAM_WORD; /* Write data to latches */ __builtin_tblwtl(0, 0xFFFF); __builtin_tblwth(0, 0xFFFF); __builtin_tblwtl(2, JUMP_VALUE); __builtin_tblwth(2, 0x0037); /* Start write operation*/ __builtin_write_NVM(); /* Wait for write to complete */ while (NVMCONbits.WR == 1u) {} } RESTORE_CPU_IPL(saved_ipl); } void FLASH_WriteDWord(uint32_t adr, uint16_t lsw1, uint16_t msw1, uint16_t lsw2, uint16_t msw2) { uint8_t saved_ipl; /* Get page and offset values */ uint16_t offset = (uint16_t)((adr) & 0xFFFFu); uint16_t page = (uint16_t)((adr >> 16u) & 0xFFFFu); SET_AND_SAVE_CPU_IPL(saved_ipl, 7); /* Save irq priority level and disable * interrupts for flash write */ /* Setup pointers to flash memory location*/ NVMADRU = page; NVMADR = offset; /* Set TBLPAG to point to data latch registers */ TBLPAG = 0xFA; /* Set NVM Control register for write operation */ NVMCON = PROGRAM_WORD; /* Write data to latches */ __builtin_tblwtl(0, lsw1); __builtin_tblwth(0, msw1); __builtin_tblwtl(2, lsw2); __builtin_tblwth(2, msw2); /* Start write operation*/ __builtin_write_NVM(); /* Wait for write to complete */ while (NVMCONbits.WR == 1u) {} RESTORE_CPU_IPL(saved_ipl); /* Restore irq priority level */ } |
|
相关推荐
3个回答
|
|
带有ECC闪存的DSPIC部件不能用已实现的方法进行修补。DSPIC33 EV128GM102具有ECC闪存。您需要复制512个指令字(1536字节)的整个闪存页,其中需要修补的指令位于RAM中,擦除页,修补T。他指令然后把页面写回Flash。否则,当CPU获取指令或部分“校正”指令字时,将获得ECC错误陷阱。
以上来自于百度翻译 以下为原文 dsPIC parts with ECC flash memory cannot be patched with the method you have implemented. The dsPIC33EV128GM102 has ECC flash memory. You will need to copy the entire flash page of 512 instruction words (1536 bytes) where the instruction you need to patch is located in to RAM, erase the page, patch the instruction then write the page back to flash. Otherwise you will get an ECC error trap when the instruction is fetched by the CPU or a partly "corrected" instruction word. |
|
|
|
谢谢你的帮助。我回去看了一遍数据表,我看到在第5.2节的末尾有一个注释我错过了,但是它与参考手册的Flash编程部分第5.4.2.1节中的注释2冲突,这说明你可以被编程两次。我想,在这种情况下,数据表获胜了。除了在数据表中的数据之外,我还能在哪里找到更多关于ECC的文档吗?只是为了我自己的信息。再次感谢。
以上来自于百度翻译 以下为原文 Thanks for the help. I went back and looked at the data sheet again and I see there is a note at the end of section 5.2 that I missed, but it conflicts with note 2 at the end of section 5.4.2.1 in the flash programming section of the reference manual that says you can be programmed twice. I guess in this case the data sheet wins. Any idea where I could find some more documentation on ECC other than what's in the data sheet? Just for my own information. Thanks again. |
|
|
|
为什么不从这里开始HTTPS://En.维基百科?org/…rWrdyErrorMort修正和HealthPS://E.WiKiTo.Org/WiKi/EcCl内存?虽然后者侧重于RAM,原则也适用于Flash。
以上来自于百度翻译 以下为原文 Why not start here https://en.wikipedia.org/...rward_error_correction and here https://en.wikipedia.org/wiki/ECC_memory ? Although the latter focuses on RAMs, the principles apply to Flash as well. |
|
|
|
只有小组成员才能发言,加入小组>>
5204 浏览 9 评论
2016 浏览 8 评论
1942 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3188 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2244 浏览 5 评论
755浏览 1评论
641浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
550浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
654浏览 0评论
554浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-5 11:43 , Processed in 1.257895 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号