Drive Strength of UART pins

 I need to use High Drive Strength of pin used as TX of UART. How may it be done using zephyr ?

Parents Reply
  • I think it should be enough setting it in the overlay, then I think the uart driver will set the drive through uart_nrfx_uarte.c-->pinctrl_apply_state()-->pinctrl_configure_pins() at boot.

    Try reading the PIN_CNF-->DRIVE register after booting up and see if it's set correctly. You can read it from main() or just through nrfjprog.

    For example if you're reading GPIO pin 0 (nonsecure), you read from address 0x40842500 (nonsecure) + 0x200 + (0 (P0.0) × 0x4) = 0x40842700

    nrfjprog --memrd 0x40842700 --n 4

    Best regards,

    Simon

Children
  • Add the following to an overlay file nrf9160dk_nrf9160_ns.overlay:

    &pinctrl {
        uart0_default: uart0_default {
            group1 {
                psels = <NRF_PSEL(UART_TX, 0, 29)>,
                    <NRF_PSEL(UART_RTS, 0, 27)>;
                    nordic,drive-mode = <NRF_DRIVE_H0H1>;
            };
            group2 {
                psels = <NRF_PSEL(UART_RX, 0, 28)>,
                    <NRF_PSEL(UART_CTS, 0, 26)>;
                bias-pull-up;
                nordic,drive-mode = <NRF_DRIVE_H0H1>;
            };
        };
    };
    

    I tested this with the hello world sample attached below:

    hello_world_high_drive.zip

    I built it with NCS v2.0.0 and the board nrf9160dk_nrf9160_ns. After flashing it to the board, I read the PIN_CNF of P0.29 (uart TX), and got the following result:

    @$ nrfjprog --memrd 0x40842774 --n 4
    0x40842774: 00000303                              |....|
    

    0x303 is 0011 0000 0011 in binary, and if you look at PIN_CNF, you can see that 11 (3 in decimal) on position 8 and 9 corresponds to H0H1:

    Best regards,

    Simon

  • Hi.. I need same again but without using pinctrl. I need to use following style to set drive strentgh.

    &uart2{
        current-speed = < 115200 >;
        tx-pin = <2>;
        rx-pin = <3>;
        status = "okay";
    };
    How , may it be done ?
    Meanwhile, I temporarily added following  function and called it in uart_init() function by manually writing Pin Number as below:
    NRF_STATIC_INLINE void nrf_gpio_cfg_output_strong(uint32_t pin_number)
    {
        nrf_gpio_cfg(
            pin_number,
            NRF_GPIO_PIN_DIR_OUTPUT,
            NRF_GPIO_PIN_INPUT_DISCONNECT,
            NRF_GPIO_PIN_NOPULL,
            NRF_GPIO_PIN_H0H1,
            NRF_GPIO_PIN_NOSENSE);
    }
    void uart_init()
    {
      ... 
      nrf_gpio_cfg_output_strong(2); // used Tx pin of UART2
      ......
    }
    Though above method worked very well, but is not recommendable, because Pin Number got fixed. How to get Pin Number as set in overlay file instead of fixed, I don't know ?
Related