So this is a problem which has confused me for a few days. At first I thought it was related to the I2C crashes I was experiencing, but I've managed to separate the two issues. I have created a test case for the F4 discovery.
With main.cpp line 52 uncommented the system will crash. without it, it works fine.
It also seems that it works if the class is defined in the main.cpp file, rather than externally. I have tested on windows using gcc 4.6.2 and mac with the latest linaro gcc, on both the F4 discovery and my own board. The problem occurs with the latest chibios from the trunk.
I don't believe it is a problem with chprintf() because my own printf library has exactly the same fault.
C++ class with float variables causes crash
Moderators: RoccoMarco, lbednarz, tfAteba
C++ class with float variables causes crash
- Attachments
-
- float.zip
- failure test case
- (27.7 KiB) Downloaded 475 times
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: C++ class with float variables causes crash
Thanks Giovanni, I think this is a different problem to the previous printf one I posted about, in this case the problem seems to be triggered when using floats from an external class, not just because some sort of printf is used. For example, this main thread also crashes it:
Code: Select all
int main(void) {
halInit();
System::Init();
BlinkerThread blinker(200);
sdStart(&SD1, &serial_config);
AHRSDataGeneric d;
d.q[0] = 1.0f;
float Q = 1.0f;
while(true) {
float *q = d.getQuatern();
int b = (int)(q[0]*(float)23.232f);
if(b > 20) {
palSetPad(GPIOA, GPIOA_LED1);
} else {
palClearPad(GPIOA, GPIOA_LED1);
}
chThdSleepMilliseconds(1000);
}
return 0;
}Re: C++ class with float variables causes crash
Hmm, it seems that removing "-fsingle-precision-constant" allows the code to run. I need to investigate the implications of this!
edit: it wasn't that, I hadn't compiled properly. But disabling the FPU support entirely fixes the problem
edit: it wasn't that, I hadn't compiled properly. But disabling the FPU support entirely fixes the problem