Skip to content
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

print (stdio) linker errors. #1433

Closed
OzmoOzmo opened this issue May 9, 2023 · 3 comments
Closed

print (stdio) linker errors. #1433

OzmoOzmo opened this issue May 9, 2023 · 3 comments

Comments

@OzmoOzmo
Copy link

OzmoOzmo commented May 9, 2023

Hi - I am having linker errors - reduced to its most basic - the code below fails to compile in both Platformio and Arduino 2.0 IDE
Using latest version from git: Arduino boards manager reports it as V3.2.0

#include <stdio.h>
#include "pico/stdlib.h"
int main() {
stdio_init_all(); //compiles if this is omitted - but then pico will not actually send anything over usb/uart
printf("Hello") ;
}

Error: sketch_may9a/sketch_may9a.ino:5: undefined reference to 'stdio_init_all' collect2.exe: error: ld returned 1 exit status

I hack/fixed the issue for myself by including these missing? files from Pico SDK 1.5 in my src folder... Im not sure if there is other code or libs missing - but this allows the above to compile and run and print to Terminal from the pico.

files: stdio_uart.h, stdio_usb.h, stdio.c, stdio_uart.c, stdio_usb.c, stdlib.c

I need to use pico sdk - not arduino equivalents.
ps. Thanks for a great library.

@earlephilhower
Copy link
Owner

You can't use stdio_init_all, the USB port is owned by Serial in the Arduino core. Just use Serial.printf() or standard library printf and set the Tools->Debug Port->Serial to send all STDOUT to the USB (or UART) port.

@OzmoOzmo
Copy link
Author

OzmoOzmo commented May 14, 2023

"or standard library printf"

Thanks - but this just doesnt seem to work unfortunately.
All the rpi pico sdk examples need this line of code.
Without the call to "stdio_init_all(); " printf does nothing. No compiler error and printf calls without error

  • but nothing gets sent over usb serial & nothing is sent on Pin 1&2.

However when I call "stdio_init_all();" it works - Serial over UART and Pin 1&2.

However - the header is present - but the c files are not.
I can include it and the c file compiles - but will not link....
Unless I add these files to my project stdio.c, stdio_uart.c, stdio_usb.c, stdlib.c
(I also have to add in platformio.ini of course:
build_flags = -D PICO_STDIO_USB -D PICO_STDIO_UART
)
I'm not using Arduino ide - but I tested and found the same issue - printf does not send back to pc terminal.

Adding the .c files - Then it all works.

I am following a Course from Cornell Uni - and they do not use Arduino - only r-pi pico SDK calls
Also all the official ri-pico samples work perfectly with your great extension core - just the printf will not work.

Issue is fixed however by including the above files from official SDK.

This library/tool is the only one I found that does all 4 of:
-Pico Uploader using cmsis-dap
-Debugger using official rpi debug probe debugger
-Coding in RPI SDK
-All within Platformio/Visual Studio.

So thanks very much for this great addition to platformio and thanks very much for replying :)

@earlephilhower
Copy link
Owner

You need to set the debug port in the Tools->Debug Port->Serial or (Serial1/2) because ::printf is not Arduino standard (the Serial-type objects are used).

Under P.IO use -DDEBUG_RP2040_PORT=Serial (or Serial1/2 for UARTs).

earlephilhower added a commit that referenced this issue May 23, 2023
Warn the user that the Pico SDK STDIO calls (stdio_init_all, stdio_usb_init,
stdio_uart_init) are not supported or needed at compile time.  See multiple
issues #1433 #1347 #1273 #1251 and others.
earlephilhower added a commit that referenced this issue May 23, 2023
Warn the user that the Pico SDK STDIO calls (stdio_init_all, stdio_usb_init,
stdio_uart_init) are not supported or needed at compile time.  See multiple
issues #1433 #1347 #1273 #1251 and others.
earlephilhower added a commit that referenced this issue May 24, 2023
Warn the user that the Pico SDK STDIO calls (stdio_init_all, stdio_usb_init,
stdio_uart_init) are not supported or needed at compile time.  See multiple
issues #1433 #1347 #1273 #1251 and others.
earlephilhower added a commit that referenced this issue May 24, 2023
Warn the user that the Pico SDK STDIO calls (stdio_init_all, stdio_usb_init,
stdio_uart_init) are not supported or needed at compile time.  See multiple
issues #1433 #1347 #1273 #1251 and others.
earlephilhower added a commit that referenced this issue May 24, 2023
Warn the user that the Pico SDK STDIO calls (stdio_init_all, stdio_usb_init,
stdio_uart_init) are not supported or needed at compile time.  See multiple
issues #1433 #1347 #1273 #1251 and others.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants