Hi all. I have two questions.
In the startup.c file, the stack pointer declaration _SP_INIT as char[], when I add LTO option with linker, there's a warning: "warning: type of '__SP_INIT' does not match original declaration", I want to disable it, and not know how?
And the second one is that, when compiled with O2, I found a locale variable is optimized out which used in asm instructions. So, my question is that, how to avoid this in ALL of source files generated by Processor Export?
could anybody give some suggestions?
I have been running into this for myself in the past too. I'll put together a more detailed response to you (should be able to provide that today).
But I don't see your second problem about that local variable optimized? Can you provide more details about this?
Thanks,
Erich
Thanks Erich.
The local variable optimized away when I removed the __attribute__(optimze("O0"))
As compare, I remove the comment, and it display as following
That's normal and expected with higher optimization settings. If you want to keep it, the usual way is to define the variable with 'volatile'.
hi Erich, I found local variable will optimized away even if volatile added, and GCC's version is arm-none-eabi-gcc 4.9.3.
an usage as follow:
#define CpuCriticalVar() uint8_t cpuSR
#define CpuEnterCritical() \
do { \
__asm volatile ( \
"MRS R0, PRIMASK\n\t" \
"CPSID I\n\t" \
"STRB R0, %[output]" \
: [output] "=m" (cpuSR) :: "r0"); \
} while(0)
#define CpuExitCritical() \
do{ \
__asm volatile ( \
"ldrb r0, %[input]\n\t" \
"msr PRIMASK,r0;\n\t" \
::[input] "m" (cpuSR) : "r0"); \
} while(0)
you would have to mark the cpuSR as volatile.
Erich, no effect even if volatile added, so you can try it with compile option -O2 and linked with LTO
I have documented how I have been fixing that warning message caused by -flto in GNU Link Time Optimization finds non-matching Declarations | MCU on Eclipse
I hope this is useful,
Erich
Erich, that doc helpful, thanks.
And the second question is that, are there bugs similar with optimized away within other modules generated by PE, e.g. UART, MSCAN, SPI. For I found another problem using UART, which runing ok with O0 compile option, and run to UnhandledInterrupt when UART transmit.
To know which interrupt is causing this, turn on 'one for every', see Oh my! An Interrupt… | MCU on Eclipse
I hope this helps,
Erich
Thanks Erich, that's great.