-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fix Print::printf implementation #64
Conversation
Thanks! Only concern I have is that it will likely cause a stack overflow for constrained devices, nRF51 and nRF52810 etc.. I will test it and see. |
The code above maybe better, it uses a smaller buffer first, alloc if the buffer overflow. |
3992712
to
4e203bb
Compare
Follow up to #68 (comment) I have a working implementation now, if you are OK with the changes, I can open another PR to replace this one @h2zero --- a/builder/frameworks/arduino/nrf5.py
+++ b/builder/frameworks/arduino/nrf5.py
@@ -71,6 +71,8 @@ env.Append(
CPPPATH=[
join(FRAMEWORK_DIR, "cores", board.get("build.core")),
+ join(FRAMEWORK_DIR, "cores", board.get("build.core"),
+ "libc", "printf"),
join(FRAMEWORK_DIR, "cores", board.get("build.core"),
"nordic", "nrfx"),
join(FRAMEWORK_DIR, "cores", board.get("build.core"), --- a/cores/nRF5/Print.cpp
+++ b/cores/nRF5/Print.cpp
@@ -22,6 +22,7 @@
#include <string.h>
#include <math.h>
#include "Arduino.h"
+#include "printf.h"
#include "Print.h"
@@ -187,11 +188,16 @@ size_t Print::println(const Printable& x)
return n;
}
+extern "C" void streamOutput(char character, void* arg)
+{
+ (static_cast<Print *>(arg))->write(character);
+}
+
int Print::printf(const char* format, ...)
{
va_list va;
va_start(va, format);
- int ret = vprintf(format, va);
+ int ret = vfctprintf(&streamOutput, this, format, va);
va_end(va);
return ret;
} |
@tsl0922 That is probably the better solution, please open PR's for this. |
Done. This PR has been updated, PR for platform: h2zero/platform-n-able#3. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just need to fix a couple things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks!
Requirement: h2zero/platform-n-able#3.
Fixes #62.