earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 and RP2350 boards
GNU Lesser General Public License v2.1
2.03k stars 422 forks source link

print (stdio) linker errors. #1433

Closed OzmoOzmo closed 1 year ago

OzmoOzmo commented 1 year ago

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

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 commented 1 year ago

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 commented 1 year ago

"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

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 commented 1 year ago

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).