floating point operations cause unaligned usage fault
Hello everybody,
I'm experiencing problems when using floating point operations on a cortex m3 processor (STM32F105 to be precise).
Debugging with the gdb tells me that a hard fault is generated inside the routine __mulsf3 which seems to be a part of the gcc soft floating point library. Here is the complete output from the gdb.
(gdb) info frame
Stack level 0, frame at 0x20004fc8:
pc = 0x80010a8 in HardFault_Handler (stm32f10x_
called by frame at 0x20004fe8
source language c.
Arglist at 0x20004fc8, args:
Locals at 0x20004fc8, Previous frame's sp is 0x20004fc8
(gdb) info frame 0x20004fe8
Stack frame at 0x20004fe8:
pc = 0x800110c in __mulsf3 (../../
called by frame at 0x20005000, caller of frame at 0x20004fe8
source language asm.
Arglist at 0x20004fe8, args:
Locals at 0x20004fe8, Previous frame's sp is 0x20004fe8
Examining the fautl status register of the cortex m3 tells me that the cause is "Unaligned access UsageFault":
Here is the complete output for the UsageFault status register:
(gdb) x /ht 0xe000ed2a
0xe000ed2a: 0000000100000000
Does anybody have an idea why this is happening? Is this likely to be a bug in the gcc or a related library, or is something going wrong during compilation of the program?
Here is the example program I'm using:
int main(void)
{
volatile uint32_t i;
volatile float x,y;
/* GPIOC Periph clock enable */
RCC_APB2Perip
/* Configure PC12 in output pushpull mode */
GPIO_
GPIO_
GPIO_
GPIO_Init(GPIOC, &GPIO_InitStruc
while (1)
{
/* Set PC12 */
GPIOC->BSRR = 1 << 1;
x = 2.5;
y = 0.2;
i = 1000000;
while(--i);
/* Reset PC12 */
GPIOC->BRR = 1 << 1;
y = y*x;
i = 2000000;
while(--i);
}
}
This the output during compilation:
$ make
.compiling
arm-none-eabi-gcc -Wall -fno-common -c -g -mcpu=cortex-m3 -mthumb -g -O0 -I./ -I./lib/ -I./lib/inc/ -I./lib/inc/../../ -DTRACE_LEVEL=4 -o obj/main.o main.c
arm-none-eabi-gcc -Wall -fno-common -c -g -mcpu=cortex-m3 -mthumb -g -O0 -I./ -I./lib/ -I./lib/inc/ -I./lib/inc/../../ -DTRACE_LEVEL=4 -o obj/system_
arm-none-eabi-gcc -Wall -fno-common -c -g -mcpu=cortex-m3 -mthumb -g -O0 -I./ -I./lib/ -I./lib/inc/ -I./lib/inc/../../ -DTRACE_LEVEL=4 -o obj/stm32f10x_it.o stm32f10x_it.c
.compiling libraries
arm-none-eabi-gcc -Wall -fno-common -c -g -mcpu=cortex-m3 -mthumb -g -O0 -I./ -I./lib/ -I./lib/inc/ -I./lib/inc/../../ -DTRACE_LEVEL=4 -o obj/stm32f10x_
arm-none-eabi-gcc -Wall -fno-common -c -g -mcpu=cortex-m3 -mthumb -g -O0 -I./ -I./lib/ -I./lib/inc/ -I./lib/inc/../../ -DTRACE_LEVEL=4 -o obj/stm32f10x_rcc.o ./lib/src/
..linking
arm-none-eabi-ld -g -v -nostartfiles -Map ./main.map -T./lib/
GNU ld (GNU Tools for ARM Embedded Processors) 2.23.2.20131129
arm-none-
arm-none-
...completed.
Regards,
Jürgen
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Joey Ye
- Solved:
- Last query:
- Last reply: