3

I use gnu arm on eclipse ( lpc1769 m3 cortex ). I want to convert float value to string with sprintf but it doesnt work.

I add -u_printf_float to linker option but it is didnt work. How can ı solve ?

int main(void) {

    InitBoard();

        float flt = 1.1;
        char msg[256];
        sprintf(msg , "number is %.3f ", flt);
        while (1){

            KC_UART_sendstring(LPC_UART0, msg);

            delay_ms(500);
        }
}

that's my linker option

-T "C:\Users**username**\Eclipse-workspace\Test_1\ldscript\LPC17xx.ld" -Xlinker --gc-sections -L"C:\Users**username**\AppData\Roaming\xPacks@gnu-mcu-eclipse\arm-none-eabi-gcc\7.2.1-1.1.5.content\arm-none-eabi\lib\thumb\v7-m" -Wl,-Map,"Test_1.map" --specs=nano.specs -u_printf_float

Flamador
  • 43
  • 1
  • 8

1 Answers1

-4

When looking at the LPC1769 datasheet I don't see any FPU.

So if there is no FPU, how do you manage floats?

  • buy a new chip which has FPU
  • code without float
  • software FPU but note that your program will suffer from performance issues (speed, RAM)

Code without float

use divisor and dividend. Pi is just unsigned pi_x_1000000 = 3141593;

then if you want to compute something like a circle perimeter,

unsigned circumference = (pi_x_1000000 * 2 * radius) / 1000000;

Note: your chip might cost 12$, it is speed/RAM limited, and, depending and what you want to achieve with it, you might consider using other solution than the software FPU. In industry, we do not use floats because costs and performance issues.

Guillaume D
  • 2,202
  • 2
  • 10
  • 37
  • it's a Cortex M3, not M3F! – Guillaume D Jul 19 '19 at 13:27
  • what alternatives can i use ? – Flamador Jul 19 '19 at 13:33
  • 4
    If the micro controller doesn't have a FPU, it doesn't mean it can't do floating point operations. Floating-point operations can also be done in software. The compiler specifically supports the options `-mfloat-abi=soft` and `-mfloat-abi=softfp`. – Codo Jul 19 '19 at 13:39
  • 1
    ...and you don't need to change the code: the compiler will take care of it. – Codo Jul 19 '19 at 13:45
  • @GuillaumeD See https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html. It is softfp. – S.S. Anne Jul 19 '19 at 13:53
  • I think the ABI types are called *soft-float* and *hard-float*, but the command line paramters are called *soft*, *softfp* and *hard*. The referred page says: *Permissible values are: ‘soft’, ‘softfp’ and ‘hard’.* – Codo Jul 19 '19 at 13:56
  • "softfp" is for hybrid but if you don't have any FPU... hybrid means FPU and software.... https://embeddedartistry.com/blog/2017/10/9/r1q7pksku2q3gww9rpqef0dnskphtc – Guillaume D Jul 19 '19 at 13:57
  • read your link, in the link you gave me: " ‘softfp’ allows the generation of code using hardware floating-point instructions" – Guillaume D Jul 19 '19 at 14:00
  • ı try add -mfloat-abi=soft to linker option and no working, in the same way -mfloat-abi=softfp is no working. Is it true that I add them to linker options – Flamador Jul 19 '19 at 14:20
  • This answer doesn't seem to address the actual problem, and it is not clear to me why it is accepted. – Eugene Sh. Jul 19 '19 at 14:21
  • this answer is relevant because @Flamador was interested to use float but he didn't know about the cons of using floats in embedded systems. – Guillaume D Jul 19 '19 at 14:53
  • can absolutely emulate fpu in code – Alex E May 16 '23 at 23:55