BSEC Sensor Library

For posterity, here’s my solution.

I have multiple particle projects I build on a regular basis. So I went ahead and make a .sh to remember how to link in the BSEC lib whenever I build this thing. I also use gcc 7 and have a bunch of minor firmware fixes to make it work. Gcc 8 is almost there, but I need to find some time again to play with it. Gotta have those lambda capture initialization expressions!

My take on your steps:

  1. Same.
  2. Just download the newest BSEC from bosch at the OP url and copy the /API and /algo/bin/Normal_version/gcc/Cortex_M3 folders into folders project’s /lib folder, like /lib/BME680_driver and lib/BSEC_1472.
    Location is actually unimportant, but for your sanity, you should organize your stuff.
  3. Already copied in the gcc/Cortex_M3 folder, no-op.
  4. I guess you need to make MODULAR=y, but I don’t know why it wouldn’t just always be y?

Here’s how to structure your folders for this solution

.
├── CMakeLists.txt // because I develop with CLion
├── lib
│   ├── BME680_driver
│   └── BSEC_1472
├── project.properties // just names the project and maybe makes the particle make work
└── src
    ├── build.mk
    ├── main_loop_file.cpp
    ├── other_project_subdirectories
    └── for_good_organization

Your build.mk needs to be just right or stuff doesn’t work. Here’s the first bit of mine, in case it helps you. These makefiles are a pain in the glutes to get figured out.

# From https://docs.particle.io/faq/particle-tools/local-build/photon/#including-additional-header-directories
# Standard behavior must be included here (So says particle)
INCLUDE_DIRS += $(SOURCE_PATH)/$(USRSRC)  # add user sources to include path
CPPSRC += $(call target_files,$(USRSRC_SLASH),*.cpp)
CSRC += $(call target_files,$(USRSRC_SLASH),*.c)

APPSOURCES=$(call target_files,$(USRSRC_SLASH),*.cpp)
APPSOURCES+=$(call target_files,$(USRSRC_SLASH),*.c)

# Project-specific stuff goes after the Particle boilerplate above.

$(info ************ Variables)
$(info ************** PROJECT_ROOT: ${PROJECT_ROOT})
$(info ************** SOURCE_PATH: ${SOURCE_PATH})
$(info ************** USRSRC: ${USRSRC})


########## Libraries

$(info ************)
$(info ************ Libraries)

$(info ************)
$(info ************ Bosch BME 680 driver)
bme680_dir = $(SOURCE_PATH)lib/BME680_driver/
$(info ************** include dir:  $(bme680_dir))
INCLUDE_DIRS += $(bme680_dir)
CPPSRC += $(call target_files,$(bme680_dir),*.cpp)
APPSOURCES += $(call target_files,$(bme680_dir),*.cpp)
$(info ************)

$(info ************)
$(info ************ BSEC version 1.4.7.2, 20190122)
bsec_lib = ${SOURCE_PATH}lib/BSEC_1472/libalgobsec.a
bsec_dir = ${SOURCE_PATH}lib/BSEC_1472/
$(info ************** include dir:  $(bsec_dir))
$(info ************** algo library: $(bsec_lib))
INCLUDE_DIRS += $(bsec_dir)
LIB_DEPS += $(bsec_lib)
$(info ************)

Then you just need a way to invoke the build. Here’s my script:

#!/bin/zsh
set -e

pushd ~/firmware/main
LDFLAGS="-Wl,--whole-archive /home/username/code/photon/project_base_dir/lib/BSEC_1472/libalgobsec.a -Wl,--no-whole-archive" \
        make PLATFORM=photon v=1 GCC_ARM_PATH="/home/username/arm-gcc-7/bin/"  APPDIR=/home/username/code/photon/project_base_dir 

The variable expansion in build.mk is really important. Some stuff ends up copied to one place, while some other stuff is sourced from your source dir while particle’s make runs. This should get you pretty close, and does not rely on particle library semantics. po-util is still a good first stop, but I needed more control and getting a build.mk recipe that works is about as much control as I can get.