Problems using the nRF5340's P0.21 pin as a GPIO output

Hello,

I am developing an nRF5340 custom board by setting the pins as shown below.

- P0.19: UART_RX
- P0.20 : UART_TX
- P0.21: GPIO Output

I have a problem when trying to use the P0.21 pin as a GPIO output that used to be used as UART_CTS on the nRF5340DK.

When I add below code in app.overlay file and set GPIO values to 0 and 1, it always outputs 0.

&pinctrl {
    uart0_default: uart0_default {
        group1 {
            psels = <NRF_PSEL(UART_TX020)>;
        };
        group2 {
            psels = <NRF_PSEL(UART_RX019)>;
            bias-pull-up;
        };
    };
    uart0_sleep: uart0_sleep {
        group1 {
            psels = <NRF_PSEL(UART_TX020)>,
                <NRF_PSEL(UART_RX019)>;
            low-power-enable;
        };
    };
}

However, if the above code is removed from the app.overlay file and the nrf5340_cpuapp_common-pinctrl.dtsi file of the nRF Connect SDK is modified as above, it works fine.

I think it is not correct to modify the nrf5340_cpuapp_common-pinctrl.dtsi file.

Could you please let me know if there is a way to use P0.21 by modifying the app.overlay file?

Regards,
Seongbin

  • Hi,

    Could you try replacing the instances of uart0_default and uart0_sleep with some other name?
    For example, add _alt to the end.

    Remember to replace the names in the uart0 node as well:

    &uart0 {
        pinctrl-0 = <uart0_default_alt>;
        pinctrl-1 = <uart0_sleep_alt>;
    };

  • Hi ,

    Thank you for your reply.

    I tried adding the code below to app.overlay but I have the same problem.

    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            group1 {
                psels = <NRF_PSEL(UART_TX020)>;
            };
            group2 {
                psels = <NRF_PSEL(UART_RX019)>;
                bias-pull-up;
            };
        };
        uart0_sleep_alt: uart0_sleep_alt {
            group1 {
                psels = <NRF_PSEL(UART_TX020)>,
                    <NRF_PSEL(UART_RX019)>;
                low-power-enable;
            };
        };
    }
    &uart0 {
        pinctrl-0 = <uart0_default_alt>;
        pinctrl-1 = <uart0_sleep_alt>;
    };

    Regards,
    Seongbin

  • Could you try adding these two lines to your pinctrl node in the overlay?

    &pinctrl {
        /delete-node/ uart0_default;
        /delete-node/ uart0_sleep;
        uart0_default_alt: uart0_default_alt {

  • I tried adding the code below to app.overlay and my code but I have the same problem.

    in app.overlay :

    &pinctrl {
    
        /delete-node/ uart0_default;
        /delete-node/ uart0_sleep;
        
        uart0_default_alt: uart0_default_alt {
            group1 {
                psels = <NRF_PSEL(UART_TX, 0, 20)>;
            };
            group2 {
                psels = <NRF_PSEL(UART_RX, 0, 19)>;
                bias-pull-up;
            };
        };
    
        uart0_sleep_alt: uart0_sleep_alt {
            group1 {
                psels = <NRF_PSEL(UART_TX, 0, 20)>,
                    <NRF_PSEL(UART_RX, 0, 19)>;
    
                low-power-enable;
            };
        };
    };
    
    &uart0 {
        pinctrl-0 = <&uart0_default_alt>;
        pinctrl-1 = <&uart0_sleep_alt>;
    };

    in my code : 
    gpio_pin_configure_dt(&g_p0_21_gpio, GPIO_OUTPUT);
    gpio_pin_set_dt(&g_p0_21_gpio, 0 or 1);
     
  • Could I please see the build/zephyr/zephyr.dts file? Either attach the file, or copy it into a code block.

Related