Page 1 of 1

STM32F4 Floating Point Operations do not work

Posted: Thu Jul 23, 2015 5:02 am
by IgorEE
Hi,

I'm hoping someone can help me out as two days have passed and I am not capable of solving the issue myself. Hopefully it is something simple.

I can not perform any operations using float values. They just don't work or produce completely wrong results. As an example, I added the following shell function to the standard STM32F4-Discovery-MEMS demo:

Code: Select all

static void cmd_float(BaseSequentialStream *chp, int argc, char *argv[]) {
  float res, res1, res2, res3;

  res = (float)2.2/(float)1.1;
  res1 = (float)2.3+(float)3.4;
  res2 = (float)3.3-(float)5.2;
  res3 = (float)3.4*(float)8.5;
  chprintf(chp, "Result of float division: %f\r\n", res);
  chprintf(chp, "Result of float addition: %f\r\n", res1);
  chprintf(chp, "Result of float subtraction: %f\r\n", res2);
  chprintf(chp, "Result of float multiplication: %f\r\n", res3);
}


and the output when calling this shell command is:
Result of float division: f
Result of float addition: f
Result of float subtraction: f
Result of float multiplication: f

Which is quite strange.
I tried setting USE_FPU in the Makefile to no,hard,softfp but nothing changes. Using just "soft" produces a compile error.

Can anyone shed some light on what needs to be done to use floats correctly? This is in ChibiStudio latest I believe, Chibios 2.6 branch.

Any help appreciated,
Thanks in advance,
-Igor

Re: STM32F4 Floating Point Operations do not work

Posted: Thu Jul 23, 2015 8:04 am
by Giovanni
hi,

chprintf() does not support float unless you enable it, see the definitions in the header. It is printing the f of %f.

Giovanni

Re: STM32F4 Floating Point Operations do not work

Posted: Thu Jul 23, 2015 2:33 pm
by IgorEE
Thanks Giovanni,

Got it!
-Igor