I would like to remove the STDIO printf functionality from my application, but I still need to use the serial components. I could not find a setting to disable this, although I tried a couple of them.
Hello Mike,
You can:
-
Either use
debug
rather thanprintf
to print debugging messages. For more info read
https://forums.mbed.com/t/printf-vs-debug -
Or disable the STDIO printf functionality by overriding the console as below:
...
FileHandle *mbed::mbed_override_console(int)
{
mbed_file_handle(STDOUT_FILENO)->enable_output(false);
return mbed_file_handle(STDOUT_FILENO);
}
int main()
{
printf("Hello\r\n"); //Won't be printed
...
- Or minimize it by defining the
MBED_MINIMAL_PRINTF
macro in thembed_app.json
file:
{
"macros": ["MBED_MINIMAL_PRINTF"]
}
Best regards,
Zoltan
Try using the below settings in mbed_app json.
“target.console-uart”: false,
“target.console-uart-flow-control”: null
Thanks,
Ajay
Thanks for the input!! I ended up using the target.console-uart option which turns off all the printf, stdio options, but doesn’t seem to block the inclusion of those libraries.
For debug messages you can also call the global debug
function. It works like the global printf
but it is automatically optimized away (no debug messages are printed) if you build the project using the release
profile:
debug("This message is optimized away (not printed) in release build");
Will this remove reference to stdio?
If I try to use UART pins that are connected to stdio, depending on boards, sometimes everything works, sometimes code doesn’t compile, and sometimes there will be weird issues.
I am not sure which version of the mbed-os you are using, however if you are not using the mbed os rtos you could use the more leaner newlib-nano library which does allows you to reduce the overall size your resulting binary. However you can not do many of the float related operations on calls like printf, sscanf and sprintf.
Thanks,
Ajay