How to enable both physical uart0 and ble nus service uart

Hi, I'm using nrf52810 ,nrf connect, zephyr, vscode extension. I’m having trouble using both UART0 and the NUS UART service.  Here’s a snippet from my overlay file:

/ {
    chosen {
        nordic,nus-uart = &uart0;
    };
};
&uart0 {
    compatible = "nordic,nrf-uarte";
    current-speed = <115200>;
    status = "okay";
    pinctrl-0 = <&uart0_default>;
    pinctrl-1 = <&uart0_sleep>;
    pinctrl-names = "default", "sleep";
};

I previously tested this code on an NRF52840, which has two physical UARTs (UART0 and UART1), where NUS used UART0 and the physical UART was set to UART1.

How can I bind the NUS UART service to something other than UART0? When both are on the same UART peripheral, the code doesn’t work.

Is it possible to create a "dummy UART1" in the DTS file since the NUS service doesn’t use a hardware UART peripheral?

br

Teijo
  • Hi Teijo,

    Since the nRF52810 has only one UART, you can't use both UART0 and NUS on the same peripheral. Try this in your DTS:

    dts

    / {
    chosen {
    nordic,nus-uart = &uart1;
    };
    };

    &uart0 {
    status = "okay";
    };

    &uart1 {
    status = "disabled"; // Dummy UART for NUS
    };
    This lets NUS use a "dummy" UART without conflicting with UART0.

    Hope that helps!

    monkey mart

  • Thank you for the answer.

    I added this definition (without an @base address) to the nrf52810.dtsi file, and it still compiles fine:

    uart1: uart_dummy {
                status = "disabled";
    };
    Overlay file:
    / {
        chosen {
            nordic,nus-uart = &uart1;
        };
    };
    prj file: 
    CONFIG_UART_ASYNC_API=y
    CONFIG_NRFX_UARTE0=n
    #CONFIG_NRFX_UARTE1=n
    CONFIG_SERIAL=y

    In the uart_peripheral example, CONFIG_NRFX_UARTE0 was set to y. I tried setting CONFIG_NRFX_UARTE1=y.

    Can you provide advice on these configurations?

    I get a compilation error related to this line:

    static const struct device *uart = DEVICE_DT_GET(DT_CHOSEN(nordic_nus_uart));
    C:/ncs/v2.5.0/zephyr/include/zephyr/device.h:85:41: error: '__device_dts_ord_65' undeclared here (not in a function); did you mean '__device_dts_ord_15'?
    85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
    | ^~~~~~~~~
    C:/ncs/v2.5.0/zephyr/include/zephyr/toolchain/common.h:132:26: note: in definition of macro '_DO_CONCAT'
    132 | #define _DO_CONCAT(x, y) x ## y
    | ^
    C:/ncs/v2.5.0/zephyr/include/zephyr/device.h:85:33: note: in expansion of macro '_CONCAT'
    85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
    | ^~~~~~~
    C:/ncs/v2.5.0/zephyr/include/zephyr/device.h:211:37: note: in expansion of macro 'DEVICE_NAME_GET'
    211 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
    | ^~~~~~~~~~~~~~~
    C:/ncs/v2.5.0/zephyr/include/zephyr/device.h:228:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
    228 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
    | ^~~~~~~~~~~~~~~~~~
    C:/sw/ble/peripheral_uart_issue/src/main.c:63:36: note: in expansion of macro 'DEVICE_DT_GET'
    63 | static const struct device *uart = DEVICE_DT_GET(DT_CHOSEN(nordic_nus_uart));
    | ^~~~~~~~~~~~~~~~~~
    Any help is appreciate.
    br
    Teijo
  • Hi Teijo,

    The problem is that nRF52810 has only one hardware UART and it's not possible to use the UART peripheral together for multiple stuff. 

    You suggestion of using a dummy UART (say, uart1) for the NUS in the dts file could help (though I have not tried it here). You could maybe set it's status as disabled in the dts so that it does not attempt to assign a physical pin to it. I see that you have tried this and you get errors. Could you share your overlay file?

    Another idea would be to maybe try time-sharing the UART0 and NUS.

    Regards,

    Priyanka

Related