What's the secret to getting printf working in my code?

I’m using a debug probe to download my code, VS Code with a terminal emulator monitoring for output. I’ve tried every channel it offered, although the actual USB C cable connected to the PicoCalc (NOT the micro USB connected to the debug probe) is the one I’d expect output on.

I have this boilerplate at the top of main

    stdio_init_all();
    uart_init(uart0, 115200);
    uart_set_format(uart0, 8, 1, UART_PARITY_NONE); // 8-N-1
    uart_set_fifo_enabled(uart0, false);

and I have this in my CMakeLists.txt

pico_enable_stdio_uart(my program 0)
pico_enable_stdio_usb(my program 1)

If I try to disable stdio_usb in particular I get weird compile and/or link errors.

What am I missing?

Thanks,

-Dave

Of course I figured it out right after I posted. Only code I needed was stdio_init_all, not the uart init stuff, and I had to set pico_enable_stdio_uart to 1 as well.

If I disable stdio_usb, I get weird include errors like

fatal error: hardware/flash.h: No such file or directory

4 | #include <hardware/flash.h>

I used some sort of VS code plugin to bootstrap my pico CMakeLists.txt since CMake syntax is utterly cryptic to me and I just want it to work.

I assume the issue above is because enabling stdio_usb has some side effects on the standard include paths or some such. I can’t even figure out how to set CFLAGS etc with CMake (I have used Make on and off since the 80’s, and have a lot of experience with build systems in general, having written a few of my own, but I just haven’t figured out CMake yet and its documentation isn’t… the best)

I feel your pain.

Read 2.4. Directory Structure in the Raspberry Pi Pico-series C/C++ SDK documentation.

I wish I found this sooner myself. I too “get” make, but I am slowly learning this dang-fangled CMake.

1 Like

Thanks.

Just needed to explicitly add hardware_flash and hardware_gpio to my target_link_libraries command.

-Dave

1 Like