完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我真的不知道从哪里开始这一个,所以我会尽量给予尽可能多的相关信息。随意问更多的上下文。我使用和谐2.03b并编译1.43。我有这个函数被正确调用。当我通过“4”的DLC时,在第二个IF状态的评估之后,这个值被设置为“0”。我真的没有线索,我是新的PIC32。所以我把签名改为“int dLC”,问题就消失了。这样做的意义不大,所以我检查了装配。请参阅第一个附加屏幕截图(未命名。PNG)。当我走到下一行时,R5设置为0。看到第二个截图(捕获.pNG)。发生了什么事?我不了解什么?我该怎么修理呢?谢谢你,Jef
以上来自于百度翻译 以下为原文 Hi all, I really don't know where to start with this one so I'll try to give as much relevant information as possible. Feel free to ask more context. I'm using HARMony 2.03b and compile 1.43. I have this function which is called correctly. When I pass '4' for DLC this value gets set to '0' after the evaluation of the second if statement. bool CAN0_TransmitMessage(int address, uint8_t DLC, uint8_t* message) { if(isInConfigurationMode) { return false; } int count = 0; if ( (PLIB_CAN_ChannelEventGet(CAN_ID_1, TX_CHANNEL) & CAN_TX_CHANNEL_NOT_FULL) == CAN_TX_CHANNEL_NOT_FULL) { txMessage = PLIB_CAN_TransmitBufferGet(CAN_ID_1, TX_CHANNEL); DLC address is r05. I really have no clue and I am new to PIC32. So I changed the signature to take "int DLC" and the problem goes away. This made even less sense so I checked the assembly. See first attached screenshot (Untitled.png). When I step to the next line r5 is set to 0. See second screenshot (capture.png). What is going on? What am I not understanding? And how can I fix it? thanks in advance, Jef Attached Image(s) |
|
相关推荐
9个回答
|
|
优化是很难调试的。调试时设置编译器不优化。/ Ruben
以上来自于百度翻译 以下为原文 It is optimization that makes it hard to debug. Set compiler to no optimization while debugging. /Ruben |
|
|
|
我知道,但是事情不应该被优化。我的知识是生疏的。我想我只改变了X32 GCC优化级别,这样我就可以很容易地在这个项目上启动。这是生成的命令行:-g- ffunThans-我……/SRC / I……/SRC/StulySCOFIG/DEFAUTION-I…/SRC/Deal-“I”…/…/ /…/ Microchip / Hyn/V2Y03B/框架“I”/SRC/SyroSyCoNFIG/默认/框架“I”…/SRC/StulySCOFIG/DEBS/BSP“您认为这个代码是什么优化的?
以上来自于百度翻译 以下为原文 I know, but things shouldn't be optimized. My MPLAB knowledge is rusty. I think I only changed the x32-gcc optimization level so I could be sure to start easily on this project. This is the Generated Command Line: -g -ffunction-sections -I"../src" -I"../src/system_config/default" -I"../src/default" -I"../../../../../microchip/harmony/v2_03b/framework" -I"../src/system_config/default/framework" -I"../src/system_config/default/bsp" What does make you think this code is optimized? |
|
|
|
您所显示的代码不使用DLC。这意味着编译器可以重用内存来保存RAM,MPLABX也可能是问题所在。和ELF文件。当变量在范围内时,这会告诉MPLABX。
以上来自于百度翻译 以下为原文 The Code you show does not use DLC. This means the compiler can reuse its memory to save RAM. There is also issue of MplabX it may be the issue. and the ELF File. This tells MplabX when a variable is in scope. |
|
|
|
程序是否如预期的那样工作?如果是这样,它只是另一个调试器工件。在您发布的图片中没有修改R5的指令。我个人建议始终使用-O1进行调试,特别是如果您将要查看拆卸。在-O0中生成的代码太冗长,因此,O1不够有足够的攻击性,从而使程序流程变得模糊。
以上来自于百度翻译 以下为原文 Does the program work as expected? If so it's just another debugger artifact. There's no instructions modifying r5 in the pictures you posted. Personally I recommend always using -O1 for debugging, and especially if you are going to be looking at the disassembly. The code produced at -O0 is just far too verbose to follow, and -O1 isn't aggressive enough for the program flow to be obscured. |
|
|
|
前4个整数函数参数在寄存器(A0—A3)中传递,不管优化级别是什么(它是ABI规范的一部分)。编译器强烈希望使用寄存器A0—A3、V0、V1在内的任何功能,因为它们不需要保存。编译器一旦知道它不需要VALUS,就可以重新使用任何寄存器,因此这些寄存器是最先被篡改的,特别是在非叶函数中(它们当然是传递参数所必需的)。当然,不需要保存和还原从未使用过的值。在示例中,对于调用PLIPKAN ChannRealEngTeg()的函数调用中的第二个参数,需要R5(寄存器A1的别名),接收ValueTxIhanChank,假定为0。NG调试,将它们分配给函数条目上的静态易失性变量。
以上来自于百度翻译 以下为原文 The first 4 integer function parameters are passed in registers (a0-a3), no matter what the optimisation level (it's part of the ABI specification). The compiler strongly prefers to use registers a0-a3, v0,v1 inside functions wherever it can, as these don't need to be saved. The compiler is free to re-use any register once it knows it's valus is not required, so these are the first to be clobbered, especially in non-leaf functions (they are of course required for passing arguments). There is of course no need to save and restore values which are never used. In your example r5 (an alias for register a1) is needed for the second parameter in the function call to PLIB_CAN_ChannelEventGet(), receiving the value TX_CHANNEL, which I presume is 0. If you requre to know these values during debugging, assign them to static volatile variables on function entry. |
|
|
|
只是在旅行时快速回答。我现在无法访问代码,但是DLC在函数中被进一步使用。我将更新这个问题。其他答复我必须更详细地检查。谢谢你的洞察力。
以上来自于百度翻译 以下为原文 Just a quick reply while traveling. I have no access to the code now but DLC is used further down in the function. I will update the question. Other replies I have to check in more detail. Thanks for the insights. |
|
|
|
只是看看你发布的DISSSECUM,忽略它。这是毫无价值的。看到这个线程HTTP://www. MigCHIP.COM/FUMMS/M1001941.ASPX.在MPLAX的最新版本中,对于PIC32(至少对于MZ)来说,反汇编视图被破坏了。为了获得实际的拆卸,在ProjtProject对话框中的PIC32全局选项中检查“保持中间文件”。在项目名称下.xBug CONFIGNET\Debug EXTEX\一些数字(通常为1472)也可以看到这个http://www. McCys.com /论坛/ M1001170..ASPX 1001227创建一个.LST文件。
以上来自于百度翻译 以下为原文 Just actually looked at the dissassembly you posted. Ignore it. It is worthless. See this thread http://www.microchip.com/forums/m1001941.aspx The disassembly view is horrendoulsy broken for PIC32 (at least for MZ) in recent versions of MPLabX. To get actual disassembly, check 'Keep Intermediate Files' in the PIC32 global options in the project properties dialog. You will find the .s files under projectname.Xbuildconfig namedebug_extsome number (usually 1472) Also see this http://www.microchip.com/forums/m1001170.aspx#1001227 for creating a .lst file |
|
|
|
(Apollogise为双人邮递,不能用链接来编辑以前的帖子)。只需添加,请在请求帮助时至少发布整个功能。不只是一个微小的“钥匙孔”视图,你认为问题所在。当你得到函数的一个正确的反汇编列表时,应该有一个类似的东西:NN是一个小整数,在IF语句之前。这将A1的值保存到堆栈中。在实际使用之前,它可能无法恢复到同一个寄存器中,并且DeBug可能会丢失它的踪迹(几乎可以肯定的是监视窗口会,因为它将继续监视位置A1(R5))。您可以更好地利用“鼠标器”工具提示所赋予的值。或者,将函数参数分配给函数项上的变量,并在代码中使用变量,而不是参数。
以上来自于百度翻译 以下为原文 (Apollogise for double post, can't be arsed to edit previous post with links). Just to add, please post at least whole function when asking for help. Not just a tiny 'keyhole' view of where you think the problem is. When you get a decent disassembly listing of the function, there should be something like:- sw a1,nn(sp) where nn is some small integer, before the if statement. This saves the value of a1 to the stack. It may not be restored to the same register prior to actual use, and the de-bugger may lose track of it (almost certainly the watch window will, as it will keep watching the location a1(r5)). You may have better luck with the value that the 'mouseover' tooltip gives. Alternatively, assign the function parameter to a variable on function entry, and use the variable, not the parameter, in your code. |
|
|
|
首先,感谢您的所有见解。我目前正在与PIC32 MK1024GPE开发板一起工作。在字里行间,我有一种印象,那就是我不应该在MPLAB给我看的时候有盲目的命运。微芯片IDE不是一个好IDE。还有更好的选择吗?ANDELSM:代码不像预期的那样工作。我还没有弄清楚这个问题的根源。但在搜索过程中,我最终完成了这个任务。信任IDE完全消失了,我做了一些进一步的调试。最后得到了这个奇怪的结果。DLC被显示为0x00后的“PLIPK-Chan-ChannEngEngGET”线。它在“IF(DLC & Gt;8)”中显示为0x00,但在“TxMeave≫MGEID.DATAAGRONTHYTHORDECODEL=DLC”中显示为0x04。当我说所示的值时,我指的是鼠标上显示的值。上周我没有注意到,因为对我来说,事情已经被“IF(DLC & G.;8)”搞砸了。请注意,PLIB函数应该内联。完整的函数看起来是这样的。现在,我将继续尝试理解Simung123Eddies的最后答案:DLC在“while(计数和lt;dLC)”中显示为0x4f,但进入4次。这个IDE没有帮助我…
以上来自于百度翻译 以下为原文 First of all, thanks for all your insights. I'm currently working with the PIC32MK1024GPE Development Board. Reading between the lines I have the impression that I should not have blind fate in what MPLAB is showing me. Is the Microchip IDE not a good IDE. Are there better alternatives? @andersm: the code does not work as expected. I'm yet to figure out the root of this. But while searching I ended up with this. With trust in the IDE completely gone I did a little further debugging. And ended up with this strange result. DLC is shown as 0x00 after the "PLIB_CAN_ChannelEventGet" line. It is shown as 0x00 at the "if (DLC > 8)" but it is shown as 0x04 at "txMessage->msgEID.data_length_code = DLC;". When I say the value shown I mean the value shown on mouseover. I didn't notice that last week because to me things were already messed up at "if (DLC > 8)". Note that PLIB function should be inlined. PLIB_INLINE_API CAN_CHANNEL_EVENT PLIB_CAN_ChannelEventGet(CAN_MODULE_ID index, CAN_CHANNEL channel) The complete function looks like this. I will now continue and try to make sense of the last answers of simong123 bool CAN0_TransmitMessage(int address, uint8_t DLC, uint8_t* message) { if(isInConfigurationMode) { return false; } int count = 0; if ( (PLIB_CAN_ChannelEventGet(CAN_ID_1, TX_CHANNEL) & CAN_TX_CHANNEL_NOT_FULL) == CAN_TX_CHANNEL_NOT_FULL) { txMessage = PLIB_CAN_TransmitBufferGet(CAN_ID_1, TX_CHANNEL); // If MSB is set it is an extended identifier if(CHECK_BIT(address, 31)) { txMessage->msgSID.sid = (address>>18); txMessage->msgEID.eid = (0x3FFFF)&(address); txMessage->msgEID.ide = 1; } else { txMessage->msgSID.sid = address; txMessage->msgEID.eid = 0; txMessage->msgEID.ide = 0; } if (DLC > 8) { DLC = 8; } txMessage->msgEID.data_length_code = DLC; while(count < DLC) { txMessage->data[count++] = *message++; } //Update CAN module and then transmit data on the bus; PLIB_CAN_ChannelUpdate(CAN_ID_1, TX_CHANNEL); PLIB_CAN_TransmitChannelFlush(CAN_ID_1, TX_CHANNEL); return(true); } return (false); } Edit: DLC is shown as 0x4F at "while(count < DLC)" but enters the while 4 times. This IDE is not helping me... |
|
|
|
只有小组成员才能发言,加入小组>>
5243 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3208 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2258 浏览 5 评论
779浏览 1评论
672浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
598浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
680浏览 0评论
578浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 18:23 , Processed in 1.803507 second(s), Total 91, Slave 75 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号