Supporting 2 Lis2 accelerometer variants in one overlay file

Hi,

I'm on NCS 1.4.2 and working on a custom hardware based on nrf52840dk. We have a Lis2Dh12 3 axis accelerometer on our board and our manufacturing team wants to substitute it for the lis2dw12 accelerometer. I know I can create multiple build configurations for the 2 different configurations but since we will have to support both in the field I would like to know if:

There is anyway to have one overlay and build configuration and for it to support both hardware variants i.e. the lis2dh12 and the lis2dw12.  They are similar devices and the application we use them for is supported by both accelerometers.  I've attached the relevant parts of my .overlay file 

/ {
	aliases {
		lis2dh12-1 = &acc_lis2dh_spi;
	};

};

&spi1 {
    status = "okay";
    compatible = "nordic,nrf-spi";
    sck-pin = <0x23>;
    mosi-pin = <0x24>;
    miso-pin = <0x25>;
    cs-gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
    
    acc_lis2dh_spi: lis2dh@0 {
        compatible = "st,lis2dh";
        reg = <0>;
        spi-max-frequency = <10000000>;
        irq-gpios = <&gpio1 2 1>;
        label = "LIS2DH";
    };
};

Parents
  • Hi,

    It would of course be simplest to have separate version for each, but if you want the exact same application on both boards, I believe you could perform the device_is_ready() check on both and choose the device which initialized correctly.

    In the overlay you would add a child node to spi1 for each sensor, and in prj.conf you would enable both sensors.

  • Thanks  

    I read on the Zephyr forum about a user supporting both the LIS2dh and the LIS3DH with the same device tree node. I tried this approach and the generated code works on both for basic functionality e.g. fall detection. Is there any drawbacks to this approach? I assume a big one is I couldn't access functionality specific to one of the chipsets using the same child node.

    &spi1 {
        status = "okay";
        compatible = "nordic,nrf-spi";
        sck-pin = <0x23>;
        mosi-pin = <0x24>;
        miso-pin = <0x25>;
        cs-gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
        
        acc_lis2dh_spi: lis2dh@0 {
            compatible = "st,lis2dh", "st,lis2dw12";
            reg = <0>;
            spi-max-frequency = <10000000>;
            irq-gpios = <&gpio1 2 1>;
            label = "LIS2DH";
        };
    };

Reply
  • Thanks  

    I read on the Zephyr forum about a user supporting both the LIS2dh and the LIS3DH with the same device tree node. I tried this approach and the generated code works on both for basic functionality e.g. fall detection. Is there any drawbacks to this approach? I assume a big one is I couldn't access functionality specific to one of the chipsets using the same child node.

    &spi1 {
        status = "okay";
        compatible = "nordic,nrf-spi";
        sck-pin = <0x23>;
        mosi-pin = <0x24>;
        miso-pin = <0x25>;
        cs-gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
        
        acc_lis2dh_spi: lis2dh@0 {
            compatible = "st,lis2dh", "st,lis2dw12";
            reg = <0>;
            spi-max-frequency = <10000000>;
            irq-gpios = <&gpio1 2 1>;
            label = "LIS2DH";
        };
    };

Children
Related