Trouble configuring project for BME 688 sensor and nrf52840

SDK version - v2.7.0

Project repository

Hi! I am a junior embedded systems software developer, and I just started working with Nordic's environment. This is my first time using an external library, and I’m having trouble with the BME68X sensor.

I began by creating a new application by copying the "BME68X Sensor Sample" and quickly realized that I needed to download the external library separately, which I did.

I proceeded to download the BME68X library and placed the relevant files in the location shown at the end of this post (see the CMakeLists.txt content). I also downloaded the BSEC static library. Then I built the project to check for any errors, and I encountered the following:


-- Configuring done
-- Generating done
-- Build files have been written to: /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build
-- west build: building application
ninja: error: '/opt/nordic/ncs/v2.7.0/modules/lib/bsec/src/cortex-m4/fpv4-sp-d16-hard/libalgobsec.a', needed by 'zephyr/zephyr_pre0.elf', missing and no known rule to make it
FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/f8037e9b83/bin/cmake --build /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build


I don’t fully understand how to include external pre-compiled libraries yet. Based on this example, it seems that I just need to add the location of the .a file and the directory of the other files using the library. So I added the following lines to my CMakeLists.txt:

add_library(mylibalgobsec STATIC IMPORTED GLOBAL)
set_target_properties(mylibalgobsec PROPERTIES IMPORTED_LOCATION {$LIB_DIR}/BSEC/algo/bsec_IAQ/bin/gcc/Cortex_M4/libalgobsec.a)
set_target_properties(mylibalgobsec PROPERTIES INTERFACE_INCLUDE_DIRECTORIES /opt/nordic/ncs/v2.7.0/modules/lib/bme68x/src/bme68x)
target_link_libraries(app PUBLIC mylibalgobsec)

However, I’m still getting the same error when building the application. Why do I need to use the location shown in the error?

I tried moving the files to that location, which resulted in different errors, but I’d like to understand what I’m doing wrong here first.

I apologize if this question seems basic—any help would be appreciated!

Parents
  • If I added the "libalgobsec.a" file to the location shown on the error message, but I still get this linking errors:

    -- Configuring done
    -- Generating done
    -- Build files have been written to: /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build
    [1/188] Preparing syscall dependency handling
    
    [6/188] Generating include/generated/version.h
    -- Zephyr version: 3.6.99 (/opt/nordic/ncs/v2.7.0/zephyr), build: v3.6.99-ncs2
    [183/188] Linking C executable zephyr/zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build/zephyr/zephyr_pre0.map 
    : && ccache /opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc  -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -fuse-ld=bfd  -T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/libarch__arm__core.a  zephyr/arch/arch/arm/core/cortex_m/libarch__arm__core__cortex_m.a  zephyr/arch/arch/arm/core/mpu/libarch__arm__core__mpu.a  zephyr/lib/libc/picolibc/liblib__libc__picolibc.a  zephyr/lib/libc/common/liblib__libc__common.a  zephyr/soc/soc/nrf52840/libsoc__nordic.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/flash/libdrivers__flash.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/i2c/libdrivers__i2c.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  zephyr/drivers/sensor/nordic/temp/libdrivers__sensor__nordic__temp.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/timer/libdrivers__timer.a  modules/nrf/drivers/sensor/bme68x_iaq/lib..__nrf__drivers__sensor__bme68x_iaq.a  /opt/nordic/ncs/v2.7.0/zephyr/../modules/lib/bsec/src/cortex-m4/fpv4-sp-d16-hard/libalgobsec.a  modules/nrf/drivers/hw_cc3xx/lib..__nrf__drivers__hw_cc3xx.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  modules/segger/libmodules__segger.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L"/opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v7e-m+fp/hard"  -L/Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build/zephyr  -lgcc  -lmylibalgobsec  zephyr/arch/common/libisr_tables.a  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -mfpu=fpv4-sp-d16  -mfloat-abi=hard  -mfp16-format=ieee  -mtp=soft  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -Wl,-no-pie  -DPICOLIBC_DOUBLE_PRINTF_SCANF  /opt/nordic/ncs/v2.7.0/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m4/hard-float/no-interrupts/libnrf_cc310_platform_0.9.19.a  --specs=picolibc.specs  -lc  -lgcc && cd /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build/zephyr && /opt/nordic/ncs/toolchains/f8037e9b83/Cellar/cmake/3.21.0/bin/cmake -E true
    /opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd:/opt/nordic/ncs/v2.7.0/zephyr/../modules/lib/bsec/src/cortex-m4/fpv4-sp-d16-hard/libalgobsec.a: file format not recognized; treating as linker script
    /opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd:/opt/nordic/ncs/v2.7.0/zephyr/../modules/lib/bsec/src/cortex-m4/fpv4-sp-d16-hard/libalgobsec.a:0: syntax error
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/f8037e9b83/bin/cmake --build /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build

    I believe this has to do with the compilated library's format, but I do not know how. 

  • I have not encountered this before but make sure you are using correct Cortex_M4 variant of libalgobsec.a that matches the floating-point configuration (hard vs. soft). For Cortex-M4 with hard float, ensure the path aligns with:

    /path/to/bsec_IAQ/bin/gcc/Cortex_M4/libalgobsec.a.

    Verify that the library was built with a compatible GCC version, it is possible that it is built with incompatible gcc version than the one this toolchain is using.

  • Hi Susheel Nuguru, I appreciate your time and response.

    I double checked and I am indeed using the variant of libalgobsec.a located in /path/to/bsec_IAQ/bin/gcc/Cortex_M4/libalgobsec.a.

    Could you please advise on how to compare the GCC version used to compile this library with the one my toolchain is using? I apologize if this is a very basic question, but I want to ensure compatibility.

  • Try reading the gcc version of the library

    readelf -p .comment /path/to/libalgobsec.a
    

    then do

    ncs/toolchain/ce3b5ff664/bin/arm-none-eabi-gcc --version

    you can see if those versions are compatible.

    Also use readelf to inspect the .ARM.attributes section of the library:

    readelf -A /path/to/libalgobsec.a

    Look for entries like Tag_CPU_name: "Cortex-M4" and Tag_ABI_VFP_args: VFP registers. If you see Tag_ABI_VFP_args: None, the library uses soft float, and it will be incompatible with hard-float configurations.

  • Hi Susheel, thanks again for your reply. 

    I am not sure why the file you mention (arm-none-eabi-gcc) is not in my /bin directory. This is the content of the folder when I run:

    ls ncs/toolchains/f8037e9b83/bin/

    For the installation, I followed these steps from the Nordic Developer Academy course.

    I tried downloading the Zephyr SDK bundle for macos, since It has the arm-none-eabi-gcc file you mention, but I am not exactly sure what to do with it.

  • My bad, the name is different in the toolchain, you will find this exe with little different name in this path

    toolchains/ce3b5ff664/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc                                                                                                                        

Reply
  • My bad, the name is different in the toolchain, you will find this exe with little different name in this path

    toolchains/ce3b5ff664/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc                                                                                                                        

Children
  • I see, thanks. When I run the command

    readelf -A /path/to/libalgobsec.a

    I can see many libraries, each of them containing many Tags, but none of them has the Tag_ABI_VFP_args tag. If the tag is missing, does it mean the library uses soft float? Here's an example of the output from only one object file inside libalgobsec.a

    File: libalgobsec.a(sortIdx.o)
    ELF Header:
      Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
      Class:                             ELF32
      Data:                              2's complement, little endian
      Version:                           1 (current)
      OS/ABI:                            UNIX - System V
      ABI Version:                       0
      Type:                              REL (Relocatable file)
      Machine:                           ARM
      Version:                           0x1
      Entry point address:               0x0
      Start of program headers:          0 (bytes into file)
      Start of section headers:          1000 (bytes into file)
      Flags:                             0x5000000, Version5 EABI
      Size of this header:               52 (bytes)
      Size of program headers:           0 (bytes)
      Number of program headers:         0
      Size of section headers:           40 (bytes)
      Number of section headers:         10
      Section header string table index: 9
    
    Section Headers:
      [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
      [ 0]                   NULL            00000000 000000 000000 00      0   0  0
      [ 1] .text             PROGBITS        00000000 000034 0001c0 00  AX  0   0  4
      [ 2] .rel.text         REL             00000000 000394 000008 08   I  7   1  4
      [ 3] .data             PROGBITS        00000000 0001f4 000000 00  WA  0   0  1
      [ 4] .bss              NOBITS          00000000 0001f4 000000 00  WA  0   0  1
      [ 5] .comment          PROGBITS        00000000 0001f4 00007a 01  MS  0   0  1
      [ 6] .ARM.attributes   ARM_ATTRIBUTES  00000000 00026e 00002e 00      0   0  1
      [ 7] .symtab           SYMTAB          00000000 00029c 0000b0 10      8   9  4
      [ 8] .strtab           STRTAB          00000000 00034c 000046 00      0   0  1
      [ 9] .shstrtab         STRTAB          00000000 00039c 000049 00      0   0  1
    Key to Flags:
      W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
      L (link order), O (extra OS processing required), G (group), T (TLS),
      C (compressed), x (unknown), o (OS specific), E (exclude),
      D (mbind), y (purecode), p (processor specific)
    
    There are no section groups in this file.
    
    There are no program headers in this file.
    
    There is no dynamic section in this file.
    
    Relocation section '.rel.text' at offset 0x394 contains 1 entry:
     Offset     Info    Type            Sym.Value  Sym. Name
    00000064  0000090a R_ARM_THM_CALL    00000000   __aeabi_fcmple
    
    There are no unwind sections in this file.
    
    Symbol table '.symtab' contains 11 entries:
       Num:    Value  Size Type    Bind   Vis      Ndx Name
         0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
         1: 00000000     0 FILE    LOCAL  DEFAULT  ABS sortIdx.c
         2: 00000000     0 SECTION LOCAL  DEFAULT    1 .text
         3: 00000000     0 SECTION LOCAL  DEFAULT    3 .data
         4: 00000000     0 SECTION LOCAL  DEFAULT    4 .bss
         5: 00000000     0 NOTYPE  LOCAL  DEFAULT    1 $t
         6: 00000001   254 FUNC    LOCAL  DEFAULT    1 ogtmbyichanvwdex[...]
         7: 00000000     0 SECTION LOCAL  DEFAULT    5 .comment
         8: 00000000     0 SECTION LOCAL  DEFAULT    6 .ARM.attributes
         9: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __aeabi_fcmple
        10: 00000101   192 FUNC    GLOBAL DEFAULT    1 insdmaxrflhpgwqy
    
    No version information found in this file.
    Attribute Section: aeabi
    File Attributes
      Tag_CPU_name: "7E-M"
      Tag_CPU_arch: v7E-M
      Tag_CPU_arch_profile: Microcontroller
      Tag_THUMB_ISA_use: Thumb-2
      Tag_ABI_PCS_wchar_t: 4
      Tag_ABI_FP_denormal: Needed
      Tag_ABI_FP_exceptions: Needed
      Tag_ABI_FP_number_model: IEEE 754
      Tag_ABI_align_needed: 8-byte
      Tag_ABI_align_preserved: 8-byte, except leaf SP
      Tag_ABI_enum_size: small
      Tag_ABI_optimization_goals: Aggressive Speed
      Tag_CPU_unaligned_access: v6

    I tried filtering the output to search for Tag_ABI_VFP

    readelf -A /path/to/libalgobsec.a | grep -i "Tag_ABI_VFP"

    But I did not get any matches among all the object files.

    Does this mean I would need to create my own library to use the sensor?

    P.D: The gcc info of the library is:
    GCC: (GNU Tools for Arm Embedded Processors 9-2019-q4-major) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]

    And the version of the compiler inside the toolchain is:
    arm-zephyr-eabi-gcc (Zephyr SDK 0.16.5-1) 12.2.0

    I appreciate your help during this process. 

  • If Tag_ABI_VFP_args tag is missing then it most likely means that the library is compiled with soft-float.
    There most likely seems to be ABI incompatibility when trying to link to the library.and then the option is to either get the library which is compatible or compile the library yourself.

  • Thank you very much for your help Susheel, I guess I will search for different options or to build a custom library.

Related