This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Device Tree: 'reg' node property

Hello,

I need someone to shed some light on how to use the 'reg' node property because I am confused.com Confused.

On this page https://docs.zephyrproject.org/latest/guides/dts/intro.html 'reg' is described as follows,

reg

Information used to address the device. The value is specific to the device (i.e. is different depending on the compatible property).

The reg property is a sequence of (address, length) pairs. Each pair is called a “register block”. Here are some common patterns:

  • Devices accessed via memory-mapped I/O registers (like i2c@40003000): address is usually the base address of the I/O register space, and length is the number of bytes occupied by the registers.

  • I2C devices (like apds9960@39 and its siblings): address is a slave address on the I2C bus. There is no length value.

  • SPI devices: address is a chip select line number; there is no length.

However, looking zephyr.dts in the build folder of the example 'light intensity controller' in this tutorial nRF Connect SDK Tutorial - Part 2  NCS v1.3.0 I can see the 'reg' property used in a different way,

spi0: spi@8000 {
#address-cells = < 0x1 >;
#size-cells = < 0x0 >;
reg = < 0x8000 0x1000 >;
interrupts = < 0x8 0x1 >;
status = "disabled";
label = "SPI_0";
};

Can someone please explain what is going on here?

Thank you.

Kind regards

Mohamed

  • Learner said:
    Can both methods of accessing devices over SPI (memory-mapped and SPI devices) be used with zephyr RTOS?

    I am not sure what you mean by "accesing devices". But both methods can be used in Zephyr. Read this for more information. You should just set the reg field appropriately, and then you don't have to worry about it more in your main code. The underlying drivers will use the reg fields and handle everything for you.

    The sensor (e.g. the apds sensor) can be accessed from the code by using device_get_binding(<label>), where <label> is what you have set label equal to in the overlay/dts-file. E.g. this sensor is accessed by using device_get_binding("ADXL362").

    Learner said:
    I favour option 1b. Can you please help me with the steps I need to take to implement this?

    This question was about how to implement the sensor into your application and if you should create your own driver or not, and you decide to go for option b: "b. Easier way: Setup the SPI instance in your application, then add the communication protocol on-top."

    However, this question is out-of-scope for this ticket, which was about the reg node property. Could you open a new ticket and ask about this? In this way we keep DevZone more organized and it easier for future users to navigate. Thanks for your understanding Slight smile

    Learner said:
    So, sub-node adxl362@0 is an SPI device that is connected to spi3 and uses the pins defined below. Pin 8 is the CS for spi device adxl362@0 and pin 7 is the CS for spi device adxl372@1. Is this right? 

     Yes, you have understood it correctly.

    Best regards,

    Simon

  • Thank you Simon for providing answering my questions. 

    Learner said:
    I favour option 1b. Can you please help me with the steps I need to take to implement this?

    However, this question is out-of-scope for this ticket, which was about the reg node property. Could you open a new ticket and ask about this? In this way we keep DevZone more organized and it easier for future users to navigate. Thanks for your understanding Slight smile

    I fully understand your point. I have opened another ticket dedicated to the SPI device driver implementation.

    Kind regards

    Mohamed

Related