Merging examples together

I have some bare metal experience on other processors, but I am new to Nordic and Zephyr. I was wondering if there are there any good source materials that show the best practices on merging samples? Specifically I would like to create a solution that uses both Peripheral_UART and ICM42605... Pedometer which sends data over BLE.

I've found some older stuff to reference, but before I dive into it I want to make sure I am using the modern/best/easiest way possible with the newest SDK's and VSCode. 

  • Hi,

    With the two samples you mentioned you may be able to just add them together. It does not look like they conflict in any way. Just merge the overlay and prj.conf files from zephyr/samples/sensor/icm42605 with the same files from peripheral_uart. And copy over the functions etc from the main.c and add the main() functions together.

    For future, more complicated merging, you should look out for conflicts in configs and peripheral instances. For example, if the samples are using spi1 and i2c1. Those can not both be enabled, so then you would for example use i2c2 instead.
    Conflicting configs will give a warning when building that the config was assigned a value, but ended up with a different one. Then you can look the config up in the Kconfig reference to see its dependencies.

  • As you suggested combining peripheral_uart and icm42605 came together very nicely. It seems very close with the exception of: DEVICE_DT_GET_ONE. I understand this command is used to get the hardware device pointer.

    The ICM42605 code compiles DEVICE_DT_GET_ONE individually, but it doesn't work in the combined file.

    I had to make a small (ICM42605 settings) addition to the prj.conf file, but I'm not sure what needs to be done to the CMakeLists.txt file. I'm getting the following errors related to CMake.

    CMake Warning at C:/ncs/v2.4.2/zephyr/CMakeLists.txt:839 (message):
    No SOURCES given to Zephyr library: lib__libc__common

    Excluding target from build.
    CMake Warning at C:/ncs/v2.4.2/zephyr/CMakeLists.txt:1865 (message):
    __ASSERT() statements are globally ENABLED

    I included the entire Peripheral_uart/imc42605 combined project if that helps.

    peripheral_uart (2).zip

  • I haven't made any headway finding the cause of the problems I outlined. I am betting someone with more experience can probably spot my error?

  • Sorry for the delay. Seems like you forgot to copy the contents of the overlay file from the icm42605 sample. In the boards folder.

  • Thanks! That sorted it out. After a pristine build I get two warnings. Should I be concerned about either?

    CMake Warning at C:/ncs/v2.4.2/zephyr/CMakeLists.txt:839 (message): cmake [Ln, 839, Col 1]

    if(NOT "${allow_empty}")
    839:  message(WARNING "No SOURCES given to Zephyr library: ${zephyr_lib}\nExcluding target from build.")


    CMake Warning at C:/ncs/v2.4.2/zephyr/CMakeLists.txt:1865 (message): cmake [Ln, 1865, Col 1]

    1865:  message(WARNING "__ASSERT() statements are globally ENABLED")

Related