Adding another peripheral to the project

Hello dear fellow developers,

                             I am solving the problem of how to add another peripheral to the project.
 
I would like to know a universal procedure for adding any peripheral that is included in the development board (any development board from Nordic) to the project. I am mainly concerned with communication interfaces such as UART or I2C or SPI. I would like to be able to address the peripheral using the method const struct device *my_dev = DEVICE_DT_GET(DT_NODELABEL(mydev));

I believe that successfully enabling any peripheral requires adding that peripheral to the .dts file in the Config files/Devicetree folder.


I then release the peripheral by mentioning its name with & in the .dts file.

/*
 * Copyright (c) 2023 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/dts-v1/;
#include <nordic/nrf9161ns_laca.dtsi>
#include "nrf9161dk_nrf9161_common.dtsi"

/ {
	chosen {
		zephyr,flash = &flash0;
		zephyr,sram = &sram0_ns;
		zephyr,code-partition = &slot0_ns_partition;
		zephyr,console = &uart0;
		zephyr,shell-uart = &uart0;
	};
};

&uart0 {

	status = "okay";
	current-speed = <115200>;
};
&uart1 {

	status = "okay";
	current-speed = <115200>;
};



So, in general, adding a peripheral looks something like this:

&my_peripherial_name{

// parametres like status and typical parametrs for that peripherial
}
 
The next step should be to enable the peripheral in the .prj config file.
 
Is this my procedure correct?


Kind Regards
Jaroslav Havel
Parents
  • Hard to say yes or no here. Language is not precise enough.

    You ask initially about adding a peripherial but your DTS overlay only works for parametrising (changing) an existing peripherial defined in board or SOC device tree.

    Note that you can define your own peripherial in the DTS overlay, but syntax is different of course.

    Using your own peripherial can also require a DTS binding if there is no zephyr (or nordic) driver or if the driver does not exactly do what you wanted it to do. 

    Writing a procedure that covers all of these cases will be rather hard.

    Note that vs code build config can currently break if you had DTS syntax errors. I recommend using west build command line tool as workaround.

    Nitpick: A ton of (modern-ish) drivers auto enable if they find a compatible DTS entry, so you usually don't have to enable them in prj.conf manually.

Reply
  • Hard to say yes or no here. Language is not precise enough.

    You ask initially about adding a peripherial but your DTS overlay only works for parametrising (changing) an existing peripherial defined in board or SOC device tree.

    Note that you can define your own peripherial in the DTS overlay, but syntax is different of course.

    Using your own peripherial can also require a DTS binding if there is no zephyr (or nordic) driver or if the driver does not exactly do what you wanted it to do. 

    Writing a procedure that covers all of these cases will be rather hard.

    Note that vs code build config can currently break if you had DTS syntax errors. I recommend using west build command line tool as workaround.

    Nitpick: A ton of (modern-ish) drivers auto enable if they find a compatible DTS entry, so you usually don't have to enable them in prj.conf manually.

Children
No Data
Related