I am using ChibiOS 2.6.0 on a stm32f4-discovery board using gcc-4.7.2.
I'm trying to print a float using chprintf function, but for an unknown reason, it throws an unhandled_exception.
What i've done:
config/chconf.h
Code: Select all
#define CORTEX_USE_FPU TRUE
Makefile
Code: Select all
UDEFS = -DCHPRINTF_USE_FLOAT=TRUE
...
ifeq ($(USE_FPU),)
USE_FPU = yes
endif
src/main.c
Code: Select all
int main(void) {
...
chprintf(&SDU1, "%f\r\n", 0.1);
...
return 0;
}
But then, it crashes.
I manage to find where, it's in chprintf(), when it tries to call va_arg() in order to pop float/double arguments from the stack:
Partial disassembly of chprintf
Code: Select all
gdb> disassemble chprintf
0x0800488c <+492>: f7 d1 bne.n 0x800487e <chprintf+478>
0x0800488e <+494>: 1c e7 b.n 0x80046ca <chprintf+42>
0x08004890 <+496>: 04 9b ldr r3, [sp, #16]
0x08004892 <+498>: 03 f1 08 02 add.w r2, r3, #8
0x08004896 <+502>: 93 e8 03 00 ldmia.w r3, {r0, r1}
0x0800489a <+506>: 04 92 str r2, [sp, #16]
0x0800489c <+508>: fc f7 58 f9 bl 0x8000b50 <__truncdfsf2>
0x080048a0 <+512>: 05 90 str r0, [sp, #20]
0x080048a2 <+514>: dd ed 05 7a vldr s15, [sp, #20]
The second instruction in the call to __truncdfsf2 makes the uC crash.
Partial disassembly of __truncdfsf2
Code: Select all
gdb> disassemble __truncdfsf2
0x08000b50 <+0>: 78 47 c0 46 ; <UNDEFINED> instruction: 0x46c04778
0x08000b54 <+4>: 80 20 a0 e1 lsl r2, r0, #1
0x08000b58 <+8>: 07 32 52 e2 subs r3, r2, #1879048192 ; 0x70000000
0x08000b5c <+12>: 02 c6 53 22 subscs r12, r3, #2097152 ; 0x200000
0x08000b60 <+16>: 7f c5 7c 22 rsbscs r12, r12, #532676608 ; 0x1fc00000
When the uC executes lsl r2, r0, #1, it crashes (unhandled_exception).
Just before the exception is thrown.
Code: Select all
gdb> stepi
0x08000b54 in __truncdfsf2 ()
gdb> i r
r0 0xa0000000 -1610612736
r1 0x3ff19999 1072798105
r2 0x200007f8 536872952
r3 0x200007f0 536872944
r4 0x0 0
r5 0x20 32
r6 0x80052c2 134238914
r7 0x0 0
r8 0x20000e5c 536874588
r9 0x0 0
r10 0x200007a8 536872872
r11 0x0 0
r12 0x1 1
sp 0x20000790 0x20000790
lr 0x80048a1 134236321
pc 0x8000b54 0x8000b54 <__truncdfsf2+4>
xpsr 0x80000000 -2147483648
msp 0x20000400 0x20000400
psp 0x20000790 0x20000790
control 0x6 6 '\006'
faultmask 0x0 0 '\000'
basepri 0x0 0 '\000'
primask 0x0 0 '\000'
Exception...
Code: Select all
gdb> stepi
_unhandled_exception () at ../chibios/os/ports/GCC/ARMCMx/STM32F4xx/vectors.c:215
215 void _unhandled_exception(void) {
Any idea why?
I didn't try another gcc version, maybe i should, although i don't see why a lsl should fail... Maybe gdb is not disassembling correctly the instruction?