nightek
(Adam Jensen)
March 3, 2021, 8:27pm
1
Dear mbed community!
I try to print floating point values with printf() therefore I created an mbed_app.json file like it is advised in this topic: https://forums.mbed.com/t/float-printf-doesnt-work-in-desktop-version/9164
here is the implementation:
and here is my test code:
The problem is that it doesn’t work, instead printing the floating point values it prints nothing:
My board is an ST Nucleo L432KC and I’m using the Platformio plugin with VS Code on Windows 10.
Could you help me what I’m doing wrong or what shall I do to make this work?
I really appriciate your help!
JohnnyK
(Jan Kamidra)
March 3, 2021, 8:51pm
2
Hello,
Nucleo-l432KC with MbedOS 6.8 with Online Compiler and result is OK.
Did you tried re-build/clean build?
BR, Jan
nightek
(Adam Jensen)
March 3, 2021, 9:01pm
3
Hi Jan,
Yes, I tried, sadly doesn’t work either.
hudakz
(Zoltan Hudak)
March 3, 2021, 10:00pm
4
Hello Adam,
Try to move the mbed_app.json
file into the src
(or .vscode
) folder. Maybe it helps.
Best regards, Zoltan
nightek
(Adam Jensen)
March 4, 2021, 12:16am
5
Hi Zoltan,
I tried your suggestions, but it didn’t work, if I move the json file from the root directory than it won’t override the default printf so the serial monitor prints %f instead of the floating point value.
hudakz
(Zoltan Hudak)
March 4, 2021, 4:30am
6
I have no experience with the Platformio neither with NUCLEO-L432KC so it was just a tip, which doesn’t seem to work
Have you tried the online compiler as suggested by Jan to check weather it works also for you?
Another alternative is to keep the default minimal printf library and enable floating point print with the following mbed_app.json
:
{
"target_overrides": {
"*": {
"target.printf_lib": "minimal-printf",
"platform.minimal-printf-enable-floating-point": true,
"platform.minimal-printf-set-floating-point-max-decimals": 2
}
}
}
1 Like
MACRUM
(Toyomasa Watarai)
March 4, 2021, 7:59am
7
Hi,
The target ST Nucleo L432KC MCU set “c_lib” to “small” configuration by default in the targets.json.
"MPU",
"SERIAL_ASYNCH",
"TRNG"
]
},
"MCU_STM32L432xC": {
"inherits": [
"MCU_STM32L4"
],
"public": false,
"c_lib": "small",
"extra_labels_add": [
"STM32L432xC"
],
"macros_add": [
"STM32L432xx"
]
},
"NUCLEO_L432KC": {
"inherits": [
"MCU_STM32L432xC"
Therefore, you have to set standard C library in your mbed_app.json.
{
"target_overrides": {
"*": {
"target.c_lib": "std",
"target.printf_lib": "std"
}
}
}
I hope this helps.
Toyo
1 Like
JohnnyK
(Jan Kamidra)
March 4, 2021, 4:02pm
9
BTW that is very interesting behavior… I have same result from MbedStudio and also from Online compiler, without changing the c_lib configuration.
BR, Jan
A million thanks! This worked for me.
"*": {
"target.printf_lib": "minimal-printf",
"platform.minimal-printf-enable-floating-point": true,
"platform.minimal-printf-set-floating-point-max-decimals": 3
},
Before :
the output in terminal — %f
after using this in my mbed_app.json : 1.500
thank you so much