Stm32 printf float variable

user3583807 picture user3583807 · Feb 5, 2015 · Viewed 14.1k times · Source

I want to log out from stm32f405 via usart. In my syscall.c file i realize function to print via usart:

int _write(int file, char *ptr, int len)
{
    int todo;
    for (todo = 0; todo < len; todo++)
    {
    usart_send_char( *ptr++ );
    }
    return len;
}

Function usart_send_char( *ptr++ ); work as expected. But when i call:

printf("%s, %d, %3.2f\r\n", "asd", 777, 13.2 );

I get: asd, 777, 0.00 The float variable not printed correctly.

Makefile:

PROCESSOR = -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16
CFLAGS += $(PROCESSOR) $(INCLUDES) $(STFLAGS) -Wall -fno-strict-aliasing $(C_PROFILE)
LDFLAGS = $(PROCESSOR) -Wl,-Map=$(PROG).map,--cref,--gc-sections

Used compilator:

Sourcery CodeBench Lite 2014.05-28

Where i am mistaken?

Answer

Frank Hunleth picture Frank Hunleth · Aug 24, 2015

I haven't used Sourcery Codebench gcc for STM32F4, but with the GCC ARM Embedded toolchain, floating point support in printf isn't enabled by default. To enable, add -u _printf_float to your LDFLAGS.