Overlay file not working for `chosen`

I'm developing on an nRF52840 and want to use uart0 as a hardware UART. Therefore, I placed this in my overlay file:

/ {
    chosen {
        /delete-property/ zephyr,console;
        /delete-property/ zephyr,shell-uart;
        /delete-property/ zephyr,uart-mcumgr;
        /delete-property/ zephyr,bt-mon-uart;
        /delete-property/ zephyr,bt-c2h-uart;
	};
};

&pinctrl {
    uart0_default: uart0_default {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 28)>;
		};
		group2 {
			psels = <NRF_PSEL(UART_RX, 0, 30)>;
			bias-pull-up;
		};
	};

	uart0_sleep: uart0_sleep {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 28)>,
				<NRF_PSEL(UART_RX, 0, 30)>;
			low-power-enable;
		};
	};

	uart1_default: uart1_default {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 4)>;
            bias-pull-up;
		};
		group2 {
			psels = <NRF_PSEL(UART_RX, 0, 5)>;
			bias-pull-up;
		};
	};

	uart1_sleep: uart1_sleep {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 4)>,
				<NRF_PSEL(UART_RX, 0, 5)>;
			low-power-enable;
		};
	};
};


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

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

However, this line of code: `const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart0));` is causing the following error:

error: '__device_dts_ord_DT_CHOSEN_zephyr_console_ORD' undeclared here (not in a function)

84 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)

In addition, the VSCode Intellisense is suggesting that this part of the overlay is not doing anything:

/ {
    chosen {
        /delete-property/ zephyr,console;
        /delete-property/ zephyr,shell-uart;
        /delete-property/ zephyr,uart-mcumgr;
        /delete-property/ zephyr,bt-mon-uart;
        /delete-property/ zephyr,bt-c2h-uart;
	};
};

Why is this happening and how can I fix this error?

  • Hello Michael,

    Thank you for contacting DevZone at NordicSemi.

    error: '__device_dts_ord_DT_CHOSEN_zephyr_console_ORD' undeclared here (not in a function)

    Are you using the console? As you have deleted the zephyr,console property, you should also disable the console driver (which would try to get the zephyr,console from the dts and as it is not present, it would cause error)

    You can use

    CONFIG_CONSOLE=n

    In addition, the VSCode Intellisense is suggesting that this part of the overlay is not doing anything:

    Please build and check in the output/compiled dts. Also make sure to include the overlay in the build process.

    Please check ./build/zephyr/zephyr.dts and confirm that it matches as per your overlay.

    /BR, Naeem

Related