Page 1 of 1

C++ class with float variables causes crash

Posted: Tue Jan 31, 2012 1:32 am
by Badger
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.

Re: C++ class with float variables causes crash

Posted: Tue Jan 31, 2012 9:31 am
by Giovanni
Hi, I will give it a try again.

Giovanni

Re: C++ class with float variables causes crash

Posted: Tue Jan 31, 2012 9:46 am
by Badger
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

Posted: Thu Feb 02, 2012 10:09 am
by Badger
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