C++ class with float variables causes crash

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

C++ class with float variables causes crash

Post 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.
Attachments
float.zip
failure test case
(27.7 KiB) Downloaded 475 times
User avatar
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

Post by Giovanni »

Hi, I will give it a try again.

Giovanni
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: C++ class with float variables causes crash

Post 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;
}
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: C++ class with float variables causes crash

Post 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
Post Reply