完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
这是我最近见过的最奇怪的事情。对于一个Bootloader,我需要在保留的RAM中设置一个标志。当我通过代码设置标志时,我看到它在数据存储器窗口中按预期变化。但是每当有重置时,无论是通过软重置还是从调试器中,刚刚写入的值都会返回到之前的值!这在重置之后立即发生,在运行任何启动代码之前。更奇怪的是,当我交互式地在数据存储器窗口中设置RAM-例如仅仅输入新值或使用填充存储器命令-这个数据“粘住”,即在重置发生之后仍然存在。在“数据存储器”窗口中显示的也是控制器“看到的”,因此代码根据这个数据进行操作,因此不是“数据窗口”有问题。为了排除这种情况只发生在调试器中,我尝试了发布版本的构建,并在那里进行了相同的操作——标记没有通过重置来坚持我还尝试了不同的RAM位置和不同的电路板来解决芯片问题。帮助?硬件是带有ICD 3的PIC32 MZ2048 EFM,软件是MPLABX/XC32的最新版本。谢谢,克里斯
以上来自于百度翻译 以下为原文 This is about the oddest thing I have seen in a while. For a bootloader I am writing I need to set a flag in reserved RAM that survives a reset. When I step through the code setting the flag I see it changing in the Data Memory window as expected. But EVERY time there is a reset, either via softreset or from the debugger, the just written values turn back to what they were before! This happens IMMEDIATELY after reset, before running any startup code. What is even stranger, is that when I set the RAM in the Data Memory window interactively - for example just typing new values or using the fill memory command - this data "sticks" i.e. is still there after a reset happens. What is shown in the Data Memory window is also what the controller "sees", so the code behaves according to this data so it's not the Data Window that has a problem. To rule out this happening only in the debugger, I tried it with a release build and same thing there - the flag doesn't stick through reset. I have also tried different RAM locations and different boards to rule out a chip problem. I am at the end of my wits. Help? Hardware is PIC32MZ2048EFM with ICD 3 and software is most recent versions of MPLABX/XC32. Thanks, Chris |
|
相关推荐
7个回答
|
|
|
请参见XC32编译器用户指南中的持久属性。
以上来自于百度翻译 以下为原文 See the persistent attribute in the XC32 Compiler User's Guide. |
|
|
|
|
|
这并不奇怪。C需要标准来清除某些类型的变量。
以上来自于百度翻译 以下为原文 It is not strange. C is required by standard to clear certain types of variables. |
|
|
|
|
|
|
|
|
|
|
|
MKC:是的,这可能是一个现金回写问题,但是我也试着多次写相同的数据,在写操作和重置之间有很多指令,所以我不知道。执行任何启动之前的cTor。第二,我没有写数据被清除,而是恢复到它以前的值。这是奇怪的,并没有解释C.carlopallini自动变零点:谢谢,不知道。问题是,它把我的分配在一个固定的地址上弄乱了。例如,this:in t testflag_u.((.().flag_mem"),persistent))将解决标志值无法存活的问题,但不会在指定部分中分配变量,而是在.bss中的某个地方。有趣的是,它也使得所有的BSS被放置在KSGE1中,否则是在KSGE0中。如果没有“persistent”属性,它将在部分中分配,但是我仍然体验到标志值在重置后无法保存。我回到使用指向RAM地址的类型指针,而不使用属性和链接器脚本文件更改。但是我切换到KSG1地址,而不是以前使用的KSGE0地址,以及“棒”。所以这确实指向了一个缓存相关的问题。
以上来自于百度翻译 以下为原文 MKC: Yes, it could be a cash write back issue, but I also tried writing the same data several times and there is quite a few instructions between when the write happens and the reset so I don't know. NKurzman: First, I said it happens immediately after reset, on the first instruction at the reset vector before any startup is executed. Second, I didn't write that the data was cleared but that it reverted to its previous value. That IS strange, and not explained by the automatic zeroing of variables in C. carlopallini: Thank you, didn't know about it. Problem is, it messes up my allocation at a fixed address. For example, this: [size=-1]int testflag __attribute__((section(".flag_mem"), persistent)); will fix the problem of the flag value not surviving, but won't allocate the variable in the specified section but somewhere in .bss. Interestingly, it also causes all of .bss to be placed in KSEG1, otherwise it is in KSEG0. Without the 'persistent' attribute, it allocates it in the section but I still experience the flag value not surviving a reset. I went back to using a typed pointer to a RAM address, without using attributes and linker script file changes. But I switched to a KSEG1 address instead of the KSEG0 address I used before, and that "sticks". So that indeed points to a cache related problem. |
|
|
|
|
|
我猜,是的,这是一个缓存问题,PIC32已经为数据和代码分离缓存,所以执行代码不会强制将数据缓存写入内存。
以上来自于百度翻译 以下为原文 My guess, yes it is a cache problem, PIC32 has separated cache for data and code, so executing code will not force to write the data cache to memory. Check for plib functions handeling the cache |
|
|
|
|
|
一个有趣的问题。你能把可缓存地址转换成它的非缓存地址吗?
以上来自于百度翻译 以下为原文 An interesting issue. Can you convert the cachable address to its non cachable equivalent at write to that? |
|
|
|
|
|
尝试用连贯属性声明变量,例如,这将迫使编译器通过未缓存的kseg1地址空间访问变量。这是最安全的方法,但如果定期访问变量,可能会出现性能问题。或者您可以使用_u builtin_mips_cache(int op,const volatile void*addr)编译器内置程序在写入变量之后刷新缓存。(不太可能)重置是在写入变量和刷新缓存之间发生的。将变量声明为易失性也是有用的,以防止编译器将变量保存在寄存器中太长时间。但是,编辑:也可以将缓存配置为写入。如果你不想影响整个程序,设置起来要复杂得多。
以上来自于百度翻译 以下为原文 Try declaring the variable(s) with the coherent attribute e.g. unsigned __attribute__((coherent)) uVarName; This will force the compiler to access the variable through the un-cached kseg1 address space. This is the safest way, however may have performance problems if the variable is accessed regularly. Or you can use the __builtin_mips_cache (int op, const volatile void *addr) compiler builtin to flush the cache after writing the variable e.g. unsigned uVarName; uVarName=1; __builtin_mips_cache (0b11001, &uVarName); //op-code 0b11001 = Hit Writeback (0b110xx) D-Cache (0bxxx01) This is less safe, as it is always possible (although very unlikely) that the reset happens in-between writing the variable and flushing the cache. It may also be usefull to declare the variable as volatile, to prevent the compiler holding the variable in a register for too long. Edit: It is also possible to configure the cache to be write through, however this is a lot more complicate to set up if you on't want to impact the whole program. OT: I wish the effin forum wouldn't keep adding blank lines to code when editing a post >:-( |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475 浏览 0 评论
5794 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1125浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1098浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 15:02 , Processed in 1.032363 second(s), Total 84, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1804