完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我面临的问题是XC32编译器的优化。每当我写一个函数从寄存器读出某些东西时,XC32就优化(读取:移除)保存返回值的变量。范围选择输入u8pinstatus=(uint8_t)SYS_PORTS_BIT_REREAD(_SFR_BIT_RERERE_B VREG(索引)+((通道-通道-信道_信道_READ_BVREBVREG(索引)+((索引)+((信道)+((信道)+((信道)信道((信道-信道-信道-信道-信道_REREAD_BVVVRE)+(((索引)+(((索引)+((信道)+((信道)+((信道)+((信道)+((信道)+((信道)(((((信道)通道-信道)信道注意,它是一个内联函数。现在,当我将优化级别设置为1,XC32移除“u8pinstatus”变量并总是返回0。但如果我声明“u8pinstatus”为“volatile”,一切正常(这是预期的),但是随后我需要声明所有变量为volatile。因为我的包装器函数总是返回0。这不是一个好方法。我在配置编译器设置或其他方面做了什么错误或问题吗?**附加信息:**汇编代码与优化*:UIT88T U8TnIIdioRead选择(无效)!{0x9D0AA8C:Addiu SP,SP,- 24 0x9D00 AA90:SW RA,20(SP)!UIT88T U8PIN状态=0;!//读取引脚分配给范围选择输入!u8pinstatus=(uint8_t)SYS_PORTS_PinRead(PORTS_ID_0, 0x9D00AA94: ADDU A0,零,零0x9D00AA98: ADDIU A1,零, 3 0x9D00AA9C: JAL SYS_PORTS_PinRead 0x9D00AAA0: ADDIU A2,零, 8!RangeEx选择端口,RangeEx选择StPin!返回U8PIN状态;!}0x9D0AAA4:LW RA,20(SP)0x9D00 AAA8:JR RA 0x9DAAAAC: Audiu SP,SP,24 *汇编代码没有优化*:UIT88T U8TnIIdioRead选择(无效)!{0x9D0F98:Audiu SP,SP,-0x99D00 F99 C:SW RA,28(SP)0x9D00 F9A0:SW S8,24(SP)0x9D00 F9A4:ADUU S8,SP,0!UIT88T U8PoNoSt= 0;0x9D00 F9A8: SB零,16(S8)!!//读取引脚分配给范围选择输入!8pinstatus=(uint8_t)SYS_PORTS_Pin读取(PORTS_ID_0,0x9D00F9AC0x9D00F9AC00X9D00F9F9ACADDUA0:ADDU A0,零,零,零,零,3x9D00F9B0:ADDIU A1,零,3x9D00F9B4:ADDIU A2,零,8 0x9D00D00F9B8X9D00D00DD00F9B8:JAL SYS_PORTS_读0x9D00F9DD00F9BC:JALSYXXXX9DDD00F9分针针读0X9DD00F9D00F9)RangeEx选择端口,RangeEx选择StPin!返回U8PIN状态;0x9D00 F9C4:LBU V0,16(S8)!}0x9D00F9C8:ADDU SP,S8,零0x9D00F9CC:LW RA,28(SP)0x9D00F9D0:LW S8,24(SP)0x9D00F9D4:ADDIU SP,SP,320x9D00F9D8:JR RA 0x9D00F9DC:NOP
以上来自于百度翻译 以下为原文 I am facing a problem with XC32 compiler's optimization. Whenever I write a function to read something from register, XC32 optimizes (read: Removes) the variable which holds the return value. I have a wrapper function which reads a perticular pin of perticular port: uint8_t u8INT_DIO_ReadRangeSelect(void) { uint8_t u8pinstatus = 0; // Read pin assigned to Range Select input u8pinstatus = (uint8_t) SYS_PORTS_PinRead(PORTS_ID_0, RANGE_SELECT_PORT, RANGE_SELECT_PIN); return u8pinstatus; } Here `SYS_PORTS_PinRead` is a HARMony generated code and it just reads the port pin. Code for that is: ` return( _SFR_BIT_READ( _PORTS_READ_B_VREG(index) + ((channel-1) * 0x40), bitPos ) );` Note that, it's an inline function. Now, when I set Optimization level to 1, XC32 removes `u8pinstatus` variable and always returns 0. But if I declare `u8pinstatus` as `volatile`, everything works fine (which was expected). But then I need to declare all the variables volatile because all my wrapper functions are always returning 0. That's not a good way. am I doing something wrong or problem in configuring compiler settings or anything else? **Additional Info:** *Assembly code with optimization*: !uint8_t u8INT_DIO_ReadRangeSelect(void) !{ 0x9D00AA8C: ADDIU SP, SP, -24 0x9D00AA90: SW RA, 20(SP) ! uint8_t u8pinstatus = 0; ! ! // Read pin assigned to Range Select input ! u8pinstatus = (uint8_t) SYS_PORTS_PinRead(PORTS_ID_0, 0x9D00AA94: ADDU A0, ZERO, ZERO 0x9D00AA98: ADDIU A1, ZERO, 3 0x9D00AA9C: JAL SYS_PORTS_PinRead 0x9D00AAA0: ADDIU A2, ZERO, 8 ! RANGE_SELECT_PORT, RANGE_SELECT_PIN); ! return u8pinstatus; !} 0x9D00AAA4: LW RA, 20(SP) 0x9D00AAA8: JR RA 0x9D00AAAC: ADDIU SP, SP, 24 *Assembly code without optimization*: !uint8_t u8INT_DIO_ReadRangeSelect(void) !{ 0x9D00F998: ADDIU SP, SP, -32 0x9D00F99C: SW RA, 28(SP) 0x9D00F9A0: SW S8, 24(SP) 0x9D00F9A4: ADDU S8, SP, ZERO ! uint8_t u8pinstatus = 0; 0x9D00F9A8: SB ZERO, 16(S8) ! ! // Read pin assigned to Range Select input ! u8pinstatus = (uint8_t) SYS_PORTS_PinRead(PORTS_ID_0, 0x9D00F9AC: ADDU A0, ZERO, ZERO 0x9D00F9B0: ADDIU A1, ZERO, 3 0x9D00F9B4: ADDIU A2, ZERO, 8 0x9D00F9B8: JAL SYS_PORTS_PinRead 0x9D00F9BC: NOP 0x9D00F9C0: SB V0, 16(S8) ! RANGE_SELECT_PORT, RANGE_SELECT_PIN); ! return u8pinstatus; 0x9D00F9C4: LBU V0, 16(S8) !} 0x9D00F9C8: ADDU SP, S8, ZERO 0x9D00F9CC: LW RA, 28(SP) 0x9D00F9D0: LW S8, 24(SP) 0x9D00F9D4: ADDIU SP, SP, 32 0x9D00F9D8: JR RA 0x9D00F9DC: NOP |
|
相关推荐
6个回答
|
|
|
Yesyou writeuint8_t u8INT_DIO_ReadRangeSelect(void){uint8_t u8pinstatus=0;//Read pin分配给Range Select输入u8pinstatus=(uint8_t)SYS_PORTS_PinRead Read(PORTS_ID_0,RANGE_SELECT_PORT,RANGE_SELECT_PIN);return u8pinstatus;}优化器看到:uint8_t u8INT_DIO_ReadRangeSelect(void){re re re re re re re returnSYS_PORTS_PinRead(PORTS_ID_0,RANGE_SELECT_PORT,RANGE_SELECT_PIN);}现在应该是有效的,但是IDE是什么版本?V 3 - 3.10经常说的东西是0。是不是告诉你这是错的?V 3.15或高你在内衬它?这可以保持寄存器中的值,并且它可能无法显示。编译器是什么版本。最新的?不尝试V 1.42为什么不是宏而不是函数?
以上来自于百度翻译 以下为原文 Yes you write uint8_t u8INT_DIO_ReadRangeSelect(void) { uint8_t u8pinstatus = 0; // Read pin assigned to Range Select input u8pinstatus = (uint8_t) SYS_PORTS_PinRead(PORTS_ID_0, RANGE_SELECT_PORT, RANGE_SELECT_PIN); return u8pinstatus; } The Optimizer sees: uint8_t u8INT_DIO_ReadRangeSelect(void) { return SYS_PORTS_PinRead(PORTS_ID_0, RANGE_SELECT_PORT, RANGE_SELECT_PIN); } As it should Now it should be valid BUT what version is the IDE? V 3.00 - 3.10 often said thing are 0. Is it what is telling you it is wrong? V 3.15 or higher You in lined it? that may keep the value in a register and it may not be able to be displayed. And What version is the compiler. The Latest? No Try V 1.42 Why not a Macro rather than a function? |
|
|
|
|
|
看起来不像内联函数。通过JAL调用。优化的版本只删除了这些多余的指令:以及无用的S8操作。这没有什么不对。
以上来自于百度翻译 以下为原文 Doesn't look like inline function. Gets called through JAL. The optimized version just removes these redundant instructions: 0x9D00F9A8: SB ZERO, 16(S8) // function call here 0x9D00F9C0: SB V0, 16(S8) 0x9D00F9C4: LBU V0, 16(S8) along with useless S8 manipulations. Nothing is wrong with that. |
|
|
|
|
|
对不起的。。。我忘了添加版本信息。我使用的是MPLAB X IDE v3.26,我的PIC32MX570F512L(PIC32MX1/2/5初学者工具包)的XC32版本是1.40。
以上来自于百度翻译 以下为原文 Sorry... I forgot to add version information. I am using MPLAB X IDE v3.26 and XC32 version is 1.40 for my PIC32MX570F512L (PIC32MX1/2/5 Starter Kit) |
|
|
|
|
|
最新版本是V1.42.您如何确定代码不起作用?哪一张照片?
以上来自于百度翻译 以下为原文 The Latest Version is V1.42. How are you determining the code is not working? Which PIC? |
|
|
|
|
|
是的,没有问题,但是它对这个引脚的任何变化都没有反应。虽然PIN被配置为输入,所有其他设置都是正确的。当我添加“易失性”时,在我的代码中看到了我的PIN上的更改。如果我将输入应用为1:非易失性代码返回0,而“易失性”代码返回1,这就是一个例子。我正在做的所有登记记录都在发生。使用宏或声明所有变量易失性是不可行的。:
以上来自于百度翻译 以下为原文 Yes, No problem with that but it is not responding to any change on that pin. Though Pin is configured as input and all other settings are correct. When I add that "volatile", changes on my pin are seen in my code. If I apply input as 1: Non-volatile code returns 0 while "volatile" code returns 1 This is an example. It is happening for all the Register reads I am doing. It won't be feasible for me to use a Macro or declare all the variable volatile. :-( |
|
|
|
|
|
还有一个问题:你如何确定代码不起作用?如果您的方法是检查调试器中的变量,该变量在调用u8INT_DIO_ReadRangeSelect()之后保持返回值,或者如果您的方法是检查它是否根据函数调用的结果跳转到哪个分支,那么要小心!调试器告诉您的,可能不是现实的。如果涉及优化,有时会发生这种情况,尤其是内联函数。我被这愚弄了好几次,在我看来,指令经常被重排序(使用O1),以至于源代码指令顺序和二进制代码指令顺序被翻转或完全弄乱了。调试器显示0值,如果分支出现错误,则似乎跳入错误,这让我认为结果是错误的,但实际上不是。总体结果是正确的。尝试在没有调试器的情况下进行验证。例如,根据结果打开LED、写入日志文件、设置输出引脚,或者甚至使应用程序崩溃。g volatile变量insideu8INT_DIO_ReadRangeSelect,尝试在外部声明一个volatile变量,该变量保存返回值:volatile uint8_t._value_I_._like_to_.=u8INT_DIO_ReadRangeSelect();这不是解决办法,但可能有助于解决问题。
以上来自于百度翻译 以下为原文 There is still the question: How are you determining the code is not working? If your approach is to check the variable in the debugger, which holds the return value after calling u8INT_DIO_ReadRangeSelect(), or if your approach is to check into which if branch it jumps based on the result of the function call, then be careful! What the debugger tells you, might not be reality. This happens sometimes, if optimization is involved, in particular with inline functions. I got fooled a few times by this, and it seems to me that often instructions were reordered so heavily (with O1), that source code instruction order and binary code instruction order were flipped or completely messed up. The debugger showed 0 values, or seemed to jump into the wrong if branch, and that made me think the result is wrong, but actually it wasn't. The overall result was correct. Try to get a verification without the debugger. For example turn on an LED, write a log file, set an output pin, or even just crash your application, depending on the result. Maybe you should show the code, which calls u8INT_DIO_ReadRangeSelect() and describe, which approach you are using to tell that the return value is 0. Also instead of declaring a volatile variable inside u8INT_DIO_ReadRangeSelect, try to declare a volatile variable outside which holds the return value: volatile uint8_t return_value_I_would_like_to_see = u8INT_DIO_ReadRangeSelect(); And then check if this variable has the correct value. That's not a solution, but might help to track the problem. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
508 浏览 0 评论
5813 浏览 9 评论
2351 浏览 8 评论
2238 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3545 浏览 3 评论
1161浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1122浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
890浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
508浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-14 22:58 , Processed in 0.958957 second(s), Total 84, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2088