Search code examples
cuartdevice-treezephyr-rtosrppico

How to set up UART1 on PR Pico with Zephyr (Devicetree)?


So I try to use the UART1 interface on my RP Pico via Zephyr, but it wont work. My problem is, I do not know how to set up UART1 in the devicetree. UART0 is usabel by default and everything works fine with that. My plan is to communicate over UART0 with my computer, to show some messges and use it for debugging. This works fine so far, without problems. I want to use UART1 to communicate with a GPS sensor (the communication part works fine, I tried it with UART0). The only thing that doesn´t work is the set up for UART1...

In zephyrproject\zephyr\boards\arm\rpi_pico\rpi_pico-common.dtsi the UART0 is defined:

&uart0 {
    current-speed = <115200>;
    status = "okay";
    pinctrl-0 = <&uart0_default>;
    pinctrl-names = "default";
};

and in rpi_pico-pinctrl.dtsi

    uart0_default: uart0_default {
        group1 {
            pinmux = <UART0_TX_P0>;
        };
        group2 {
            pinmux = <UART0_RX_P1>;
            input-enable;
        };
    };

But why isn´t UART1 not predefined or better, how do I set up UART1 to use it in the same way as UART0?


Solution

  • you can simply add it yourself in the devicetree. Thanks to @sawdust in know now it is the enableing explicitly what is missing. The rp2040 has uart1 defined, but in your current device tree it is not connected with real PINs, so not enabled.

    (status = "okay" or disabled is the enableing i know ...)

    By looking into the datasheet of the Raspiberry Pico which is RP2040: https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf

    In Section: 1.4.3. GPIO Functions There is UART1 mentioned with GPIO Pins.

    Also there is mentioned which Pins you are interferring when using the 2nd UART.

    You can create an overlay file or use the "rpi_pico-pinctrl.dtsi" directly.

    tl;dr:

    With snippet:

    uart1_default: uart1_default {
        group1 {
            pinmux = <UART1_TX_P4>;
        };
        group2 {
            pinmux = <UART1_RX_P5>;
            input-enable;
        };
    };
    

    Valid Pins can be found in the file: rpi-pico-rp2040-pinctrl.h at: zephyr/include/zephyr/dt-bindings/pinctrl/rpi-pico-rp2040-pinctrl.h

    Of course one need also this piece of code:

    &uart1 {
    current-speed = <115200>;
    status = "okay";
    pinctrl-0 = <&uart1_default>;
    pinctrl-names = "default";
    };