Skip to content

Conversation

@silabs-bozont
Copy link

Hey!
I often find it useful to have a printf function in the Serial class, so I implemented it for this core too.
It's optional and turned off by default for all boards - but is explicitly enabled on the Nano Matter.
It can be turned on for any board with CONFIG_ARDUINO_SERIAL_PRINTF=y and the buffer size is also configurable.
Let me know what you think!

@mjs513
Copy link

mjs513 commented Dec 22, 2025

Hey!
I often find it useful to have a printf function in the Serial class, so I implemented it for this core too.
It's optional and turned off by default for all boards - but is explicitly enabled on the Nano Matter.
It can be turned on for any board with CONFIG_ARDUINO_SERIAL_PRINTF=y and the buffer size is also configurable.
Let me know what you think!

I will second that sentiment! Would expand that to all zephyr boards - probably add it to prj.conf.

Copy link
Collaborator

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to submit this pull request @silabs-bozont!

If this is to be done, it must be implemented in the Print class.

There is already a proposal for that here:
arduino/ArduinoCore-API#28

@per1234 per1234 self-assigned this Dec 22, 2025
@per1234 per1234 added the enhancement New feature or request label Dec 22, 2025
@per1234 per1234 closed this Dec 22, 2025
@per1234 per1234 added the wontfix This will not be worked on label Dec 22, 2025
@mjs513
Copy link

mjs513 commented Dec 22, 2025

@per1234
That issue has been open since 2019 - thats going on 7 years. Doesn't look like its ever going to be addressed. Maybe should be addressed here for zephyr boards and if ever addressed for other boards can be deleted for here or excluded from print class for zephyr?

Just a thought.

Also just read in post 2 from Paul

Didn't Massimo (@mbanzi) say very clearly, only 2 weeks ago on the developers mail list, that this would not be accepted?

so not sure what is up!

@KurtE
Copy link

KurtE commented Dec 22, 2025

@silabs-bozont - I totally agree with you on the desire to have printf.
I have a hacked up version that I use in my Zephyr test sketches.
https://github.com/KurtE/zephyr_test_sketches/blob/master/common/src/UARTDevice.cpp#L139-L146

Was going to mention that on the Teensy instead of needing a large buffer to use sprintf, instead:
Paul (PJRC) - uses vdprintf to do the actual output, and in the code he has a version of _write that he uses to redirect to
the Print object that called printf:

extern "C" {
__attribute__((weak))
int _write(int file, char *ptr, int len)
{
	if (file >= 0 && file <= 2) file = (int)&Serial;
	return ((class Print *)file)->write((uint8_t *)ptr, len);
}
}

It was also interesting that on MBED versions, we at times could cheat and use the macro:
REDIRECT_STDOUT_TO(Serial)
And then printf's would go to Serial (or whatever object you specified).

Other options is to use:
#include <LibPrintf.h>

If this is to be done, it must be implemented in the Print class.

There is already a proposal for that here: arduino/ArduinoCore-API#28

@per1234 - I personally think that Arduino should prune stuff out, like this, that are over N years old. Sort of similar that
Zephyr will close out PRs if no action has happened on them in so many months.

I know every so often I will go through some of my own PRs and Issues and close them out as detritus .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants