STM32F4 Floating Point Operations do not work

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
IgorEE
Posts: 21
Joined: Fri Nov 14, 2014 4:40 pm

STM32F4 Floating Point Operations do not work

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 Floating Point Operations do not work

Post 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
IgorEE
Posts: 21
Joined: Fri Nov 14, 2014 4:40 pm

Re: STM32F4 Floating Point Operations do not work

Post by IgorEE »

Thanks Giovanni,

Got it!
-Igor
Post Reply