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:

I modified the Thingy91 board file thingy91_nrf9160_common.dts:

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

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:

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()), 

    but there are some issues with the driver.

    Could you try to swap

    with

    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.

Reply
  • 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.

Children
  • I attached the project and board files so you can try it.  Quick recap: it's based on the Thingy91 and Asset Tracker app. I don't need the env or light sensors or the UI stuff.  Swapping the ADXL3x2s for a LIS2DW12.

    asset_tracker_20200920.zip

    thingy91_nrf9160_20200921.zip

  • Hi, Simon. Did you find anything?

  • I got rid of the "undefined reference" by doing what I suggested earlier. Be aware that I said you should change zephyr\drivers\sensor\lis2dw12\lis2dw12_spi.c and not zephyr\drivers\sensor\lis2dw12\lis2dw12.c.

    However, when I fixed that issue, many DTS related errors showed up.

    I see that you are using the compatible string "stm,lis2dw12", but I could not find any bindings for it under zephyr\dts\bindings\sensor. The bindigs defines what should be included in a DTS node where this compatible is used. Read about it here.

    Why don't you just use the already present "st,lis2dw12"? If for some reason you want to create your own, you should create a new a yaml file similar to this one: zephyr\dts\bindings\sensor\st,lis2dw12-spi.yaml.

    By the way, it is good practice to create a new board folder for you custom board, and not modify existing ones. The naming convention should be <board name>_<chip name>, e.g. myboard_nrf9160. Take a look at 2. Using a custom board with NCS for instructions how to do this.

    Best regards,

    Simon

  • 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