A customer reported an issue with C-compiler optimization with compiler version 5.1.10.
The attached project works fine with –o0 and –o1. With –o2, the PC does not reach main(). I found it stuck at the call to esmGroup3Notification() in startup function c_int00() in file HL_sys_startup.c. From the attached screenshot, CPU loads the ESM status register value to R12 from address pointed by R4. R4 should have the address of the ESM status register. Instead, it has a value of zero.
In the beginning of c_int_00(), R4 is initialized to 0xfffff520 which is the address of the ESM status register. R4 is changed to zero in the call to assembly function _coreInitRegisters_(). It seems that the compiler does not generate the correct code in this case. I am not sure if there is away for compiler to know what assembly code does. We advised the customer not to use –o2 for the time being. Would you please take a look at this and provide feedback? I think that the –o2 option should not be used when there are assembly code in the project. Would you please comment?
Thanks and regards,MotorController.zip
Zhaohong