Dynamically change devicetree configuration for UART in firmware

Hi,

In the nRF Connect SDK, is it possible to dynamically change devicetree overlay configurations in firmware?

Say for example, UART1 is defined in the devicetree overlay as:

&uart1 {
    compatible = "nordic,nrf-uarte";
    status = "okay";
    current-speed = <115200>;
    pinctrl-0 = <&uart1_default>;
    pinctrl-1 = <&uart1_sleep>;
    pinctrl-names = "default", "sleep";
};

Would it be possible to change the baud rate and pin configuration in my firmware application code?
Thanks in advance.
Parents
  • Hello,

    If you only wanted to change the pins, you could add another pinctrl instance, e.g.:

    pinctrl-2 = <&uart_default_2>;

    and define that as you like, and switch between the two different pinctrl instances during runtime, pretty much like it already does when it goes from active (default) to sleep. However, you see that the baudrate is not defined in pinctrl. It is defined in the uart instance itself. So therefore it is not possible to change between different baudrates during runtime while using devicetree. 

    If you specifically need to change between different baudrates on the same UART instance, I suggest you check out the nrfx driver for UART. This is a driver that interacts more directly with the UART registers, and not through the zephyr API. So there you are free to change baudrates and GPIOs as you like. 

    Please see my colleague, Jørgen's, reply in this ticket:

     NRF5340 - Reprogram UART baudrate at runtime 

    Best regards,

    Edvin

Reply
  • Hello,

    If you only wanted to change the pins, you could add another pinctrl instance, e.g.:

    pinctrl-2 = <&uart_default_2>;

    and define that as you like, and switch between the two different pinctrl instances during runtime, pretty much like it already does when it goes from active (default) to sleep. However, you see that the baudrate is not defined in pinctrl. It is defined in the uart instance itself. So therefore it is not possible to change between different baudrates during runtime while using devicetree. 

    If you specifically need to change between different baudrates on the same UART instance, I suggest you check out the nrfx driver for UART. This is a driver that interacts more directly with the UART registers, and not through the zephyr API. So there you are free to change baudrates and GPIOs as you like. 

    Please see my colleague, Jørgen's, reply in this ticket:

     NRF5340 - Reprogram UART baudrate at runtime 

    Best regards,

    Edvin

Children
No Data
Related