Sprintf not working on bluepill

Hello!

Could someone please help me with sprintf on bluepill?
If i compile with mapel core sprintf works but not with st-core.

Searching on the internet suggests to put “-u _printf_float” into linker flags but it did not compile…

Robert

Here’s my configuration:

main.cpp:

#include <Arduino.h>

char displayString[10];

void setup()
{
    Serial.begin(115200);
} 
void loop()
{
    sprintf(displayString, "%f", 123.4);
    Serial.print(displayString);
    delay(200);
}

platformio.ini:

[env]
platform = ststm32

build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D USBD_VID=0x0483
-D USB_MANUFACTURER=“Unknown”
-D USB_PRODUCT=“"BLUEPILL_F103C8"”
-D HAL_PCD_MODULE_ENABLED

framework = arduino
board_build.core = st

[env:bluepill]

board = genericSTM32F103CB

Exactly, this must be a linker flag, i.e. -Wl, prefixed. Have you tried adding

-Wl,--undefined,_printf_float

as a new line to the build_flags in the platformio.ini?

Thank you very much!

I made a mistake with -Wl,-u _printf_float.

Why is that not the default in platformio?

Robert

The default in STM32Duino is also no floating-point printf. It also has to be specially activated. Flash space is precious on these smaller devices. Thus PlatformIO does the same and has maximum compatibility with its behavior.

Thank you very much!