I used to be able to compile and run perfectly the following simple C code in MQX 3.8:
float f = (float)temperature / 32.0 * 0.125;
printf("temp: %3.1f\n", f);
However it hangs in MQX3.8.1, which I had to modify to work using the div_t data type:
div_t n = div(f,1);
printf("temp: %02d.%d\n", n.quot, n.rem);
The same happens to the sprintf() function.
I am not sure, but I have a feeling it has to do with the PSP_HAS_FPU being enabled?
Anyone can help?
To add to this, the regular operand '%' does not work with this compiler for some reasons.
I think I have solved this. Apparently the floating point support was set to "software floating point" by default. I changed it to hardware, recompiled, and it seems to work.
keith tang wrote:
I think I have solved this. Apparently the floating point support was set to "software floating point" by default. I changed it to hardware, recompiled, and it seems to work.
Not the correct solution. Unless you're using a 120/150MHz Kinetis or some other CPU with a hardware FPU, you shouldn't set it to hardware floating point. The correct solution is to put
#define MQX_INCLUDE_FLOATING_POINT_IO 1
in user_config.h and recompile your PSP. This will include floating point code in _io_printf() and _io_scanf(). I'm guessing that maybe they defaulted that to 0 starting in MQX 3.8.1 to keep default code size down.
Thanks for the reply, David.
The hardware does support hardware FPU. In the earlier version of MQX (3.7) the hardware FPU was not implemented, and therefore it was turned off. When I first updated to the latest MQX (3.8), I did not turn it on.