CMSIS __set_MSP causes generation of undefined instruction when -Os
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
Invalid
|
Undecided
|
Martin Velek |
Bug Description
Hello,
the arm-none-eabi-gcc generates undefined instruction in function IAP when compiled with Os. This function is part of the Bootloader application and enables to update the Cortex-m3 LPC1788 internal Flash. The __set_* functions come from the ARM CMSIS.
I need to switch the MSP as the current SP and adjust the value for safety reason before calling the IAP_internal_* functions. Compiler, Linker commands and Linker script are attached.
The IAP_internal_* functions must be in a special input section otherwise the linker will "garbage" them even with the "used" attribute.
#include <stdint.h>
void IAP(int flash_image) __attribute__ ((section (".rom.
void IAP_internal_
void IAP_internal(void) __attribute__ ((section (".text.
void IAP_internal(void)
{
while(1);
}
void IAP_internal_
{
while(1);
}
#define BOOTLOADER_ADDRESS ((uintptr_
void IAP(int flash_image)
{
if(0 == flash_image)
{
__set_
__set_
IAP_internal_
}
else
{
__set_
__set_
IAP_internal();
}
}
Disassembly of section .bootloader:
00003fc0 <IAP>:
3fc0: b908 cbnz r0, 3fc6 <IAP+0x6>
3fc2: 6803 ldr r3, [r0, #0]
3fc4: e001 b.n 3fca <IAP+0xa>
3fc6: 2300 movs r3, #0
3fc8: 681b ldr r3, [r3, #0]
3fca: deff udf #255 ; 0xff
Hi Martin,
It seems like you did not include the right CMSIS header file. The definition of __set_MSP, as well as other CMSIS functionality, depends on it. Without '-Wimplicit- function- declaration' GCC will silently accept any undefined intrinsic and any O2 or higher optimization will translate it to an undefined instruction.
Best Regards.