RP2040 STDIO over UART: Non-default GPIO

RP2040 STDIO over UART: Non-default GPIO

Like many of us, I started working with the Pico using STDIO over USB following some of the early Raspberry PI examples. It made sense and I was using a Raspberry PI to flash and debug my Pico, so I wasn’t worried about blowing up my Mac. It wasn’t a perfect setup but I could live with the 2 seconds that the USB takes to establish on boot and often put a small delay before allowing my code to blossom into full glory.

With the Raspberry PI Debug Probe and better support for compilation direct on PC and Mac, I am moving away from using the Raspberry Pi as my build server. Stopping using STDIO over USB to using STDIO over UART through the RPI Debug Probe. This is of course is as easy as just switching two lines in the CMake file:

pico_enable_stdio_usb(${NAME} 0)
pico_enable_stdio_uart(${NAME} 1)

Well, it would be if I had not chosen to put LEDs, switches and I2C devices on GPIO 0 and GPIO 1 in my projects. STDIO over UART uses UART0 and the default GPIO PADs of 0 and 1. This isn’t a problem though as we can easily move to a non-standard GPIO PADs by adding a couple of definitions in the CMake file.

target_compile_definitions(${NAME} PRIVATE
PICO_DEFAULT_UART_RX_PIN=16
PICO_DEFAULT_UART_TX_PIN=17
)

Here I move to use GPIO16 and 17 on the opposite corner of the Pico, more convenient for me as closer to the SWD port.

You can’t move to use absolutely any GPIO Pad but only those that are supported for the UART0 function. Check out the Raspberry PI Pico pinout to confirm.

I’ve put a small demo project repo which shows how to set the GPIO Pads for STDIO.

Leave a comment