This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

compiler difference between uVision v4 and v5

I'm working with a Cortex-M3 part and I'm having an issue after upgrading from uVision version 4.70 to version 5.21. The micro is part of a sensor in which its main tasks are to toggle some DIO, read some analog voltages, do some processing, and output the data on a UART.

I have the following block of code running in a function:
unsigned char statusfield;
statusfield = 0;
statusfield = ((gv1 & 0x1) << 1) | (gv2 << 2);

gv1 and gv2 are globals, assigned in a different function and declared as follows:
volatile unsigned char gv1 = 0;
volatile unsigned char gv2 = 0;

When using v5.21, I have found that when I change the line above to:

statusfield = ((gv1 & 0x1) << 1) | ((gv2 & 0x1) << 2);

...then the content of the data output from the UART gets somewhat erratic. Using v4.70, the code change does not make any difference. The value in gv2 should only ever be 0 or 1, so the masking shouldn't make any difference and I was just doing it as good practice. Also, the value of statusfield is not related to the data that becomes erratic. I haven't tracked down what exactly is happening to make the data erratic, but I don't think that really matters since this seems like a compiler issue.

One other note. I've tried compiling with v5.21 and downloading to flash with v4.70 and visa versa and the problem seems to be isolated to the v5.21 compiler.

I've been getting around this issue by sticking with v4.70, but it would be nice to figure it out.

Thank you.