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

Asset Tracker - adding SPI sensor

Using: Windows 10, nRF Connect v3.5.0, SES v4.52, ncs v1.3.0, zephyr v2.3.0

I have a custom board based on the Thingy91 and the Asset Tracker application. There is also an LIS2DW12 present on SPI.  In prj.conf, I added these lines:

CONFIG_SENSOR=y
CONFIG_TEMP_USE_EXTERNAL=y
CONFIG_TEMP_USE_SIM=n
CONFIG_SENSOR_SIM=n
CONFIG_SPI=y
CONFIG_SPI_NRFX=y
CONFIG_SPI_3=y
CONFIG_ACCEL_USE_EXTERNAL=y
CONFIG_LIS2DW12=y
CONFIG_ACCEL_DEV_NAME="LIS2DW12"
CONFIG_LIS2DW12_ODR_1_6=y
CONFIG_LIS2DW12_ACCEL_RANGE_2G=y

I modified the Thingy91 board file thingy91_nrf9160_common.dts:

&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <16>;
	mosi-pin = <13>;
	miso-pin = <14>;
	cs-gpios = <&gpio0 15 GPIO_ACTIVE_LOW>;

	lis2dw12 {
		compatible = "stm,lis2dw12";
		label = "LIS2DW12";
		spi-max-frequency = <10000000>;
		int1-gpios = <&gpio0 17 GPIO_ACTIVE_HIGH>;
	};
};

In lis2dw12.c, I added these lines to the top:

#define DT_DRV_COMPAT stm_lis2dw12
#define LIS2DW12	DT_INST(0, stm_lis2dw12)

In SES, it builds quite far, but I get an error:

C:/engr/ncs/v1.3.0/zephyr/drivers/sensor/lis2dw12/lis2dw12.c:227: undefined reference to `lis2dw12_spi_init'

In lis2dw12.c, this section is grayed out:

#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
#include <drivers/spi.h>
#elif DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
#include <drivers/i2c.h>
#endif

Which means it never includes the spi.h file.  What am I missing?  Any ideas?

Parents
  • I see that you're getting undefined reference to lis2dw12_spi_init() on line 227, which means that the DTS overlay is ok (since

    DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) is true and it tries to access lis2dw12_spi_init()), 

    #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
    	lis2dw12_spi_init(dev);
    #elif DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
    	lis2dw12_i2c_init(dev);
    #else

    but there are some issues with the driver.

    Could you try to swap

    #define DT_DRV_COMPAT st_lis2dw12

    with

    #define DT_DRV_COMPAT stm_lis2dw12

    At the top of zephyr\drivers\sensor\lis2dw12\lis2dw12_spi.c?

    Best regards,

    Simon

  • In the third code block, the #define in lis2dw12.c is already that way (see above):

    #define DT_DRV_COMPAT stm_lis2dw12

    The fourth code block is all grayed out, not the function lis2dw12_spi_init().  This means DT_ANY_INST_ON_BUS_STATUS_OKAY is false.

  • I wasn't trying to create my own driver, it just wasn't obvious to me what the compatible name should be.  I'll try "st" instead of "stm".

    I intend to restore the original board files and use my own once I get further.  I was just having so many problems.  So I started from a known-good state and slowly introduced changes to minimize/eliminate errors. 

    Thanks.

  • Okay, I seeSlight smile  I probably should have warned you against modifying the DT_DRV_COMPAT of the driver at an earlier point. My apologies for that.

    But hopefully you're able to get it to work now.

    Best regards,

    Simon

  • I updated the compatible name in "thingy91_nrf9160_common.dts":

    &spi3 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	sck-pin = <16>;
    	mosi-pin = <13>;
    	miso-pin = <14>;
    	cs-gpios = <&gpio0 15 GPIO_ACTIVE_LOW>;
    
    	lis2dw12 {
    		compatible = "st,lis2dw12";
    		label = "LIS2DW12";
    		spi-max-frequency = <8000000>;
    		int1-gpios = <&gpio0 17 GPIO_ACTIVE_HIGH>;
    	};
    };
    

    While the project is loading, I get this error:

    <stdout>: Warning (avoid_unnecessary_addr_size): /soc/peripheral@40000000/spi@b000: unnecessary #address-cells/#size-cells without "ranges" or child "reg" property
    devicetree error: 'reg' is marked as required in 'properties:' in C:/engr/ncs/v1.3.0/zephyr/dts/bindings\sensor\st,lis2dw12-spi.yaml, but does not appear in <Node /soc/peripheral@40000000/spi@b000/lis2dw12 in 'thingy91_nrf9160ns.dts.pre.tmp'>

    I added "reg = <0>;" after the "spi-max-frequency" line (similar to the original ADXL3x2 sensors) and now I get this error while loading:

    <stdout>: ERROR (unit_address_vs_reg): /soc/peripheral@40000000/spi@b000/lis2dw12: node has a reg or ranges property, but no unit name

    Where would I even learn about which sensor fields are required and the required format, attributes, etc.?

    Does configuring a Thingy91 with a LIS2DW12 work for you? 

  • Could you try to apply this patch to the nrf repository: asset_tracker_thingy91_lis2dw12.patch

    I went against my own advice and modified the Thingy:91 board folder directly Stuck out tongue

    I'm not at the office until Monday and don't have access to a Thingy:91 until then, so I have not tested the example. But it builds successfully.

    Best regards,

    Simon

Reply Children
Related