Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

core: serial: implement Serial.printf() #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
silabs-bozont wants to merge 1 commit into arduino:main from silabs-bozont:serial-printf

Conversation

@silabs-bozont
Copy link

@silabs-bozont silabs-bozont 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!

mjs513 and KurtE reacted with heart emoji
Copy link

mjs513 commented Dec 22, 2025
edited
Loading

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 added the wontfix This will not be worked on label Dec 22, 2025
Copy link

mjs513 commented Dec 22, 2025
edited
Loading

@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 reacted with thumbs up emoji

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 .

mjs513 reacted with thumbs up emoji

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

Reviewers

1 more reviewer

@per1234 per1234 per1234 left review comments

Reviewers whose approvals may not affect merge requirements

Labels

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /