Showing results for 
Search instead for 
Did you mean: 

Hard Fault after call to static library

Associate II

I'm using a BSEC static library for BME688 sensor. My application project builds fine. As soon as I reach the first BSEC function (which is provided by the "libalgobsec.a" static library), program goes to hard fault interrupt handler.

My best guess would be that stack/heap size is insufficient. I have tried increasing both from 0x200 (heap) and 0x400 (stack) to 0x1000 (both) then also 0x8000 (both) through my linker file. However I see no difference - program hits the hard fault handler as soon as program enters the "bme68x_bsec_update_subscription" function.

It's also worth noting that I used proper "libalgobsec.a" static library - the one under Cortex-M7 folder (since my MCU uses this core).

Maybe there are other reasons I should consider in this case? 

Under BSEC examples, I have found one Readme (in the appendix) file which states the algorithm inclusion process. I didn't follow the exact rules because (I think) they are meant for Arduino platform (and I'm using STM32 with PlatformIO in VS Code). However there are some flags that might be important and could affect this case. The only thing I did about compiler/linker flags is the inclusion of library libalgobsec.a"  and provided flags for hardware floating point arithmetic.

I'm using STM32F756xx microcontroller in combination with CubeMX code generator (generates linker file where I can set stack/heap size).


By inspecting CFSR register I found out that hard fault is being caused by "Invalid instruction set" event. However, if I use Thumb instruction set (using either `-mthumb` or `-mthumb-interwork` option for compiler, linker, and assembler) my application code compiles but BSEC function call causes hard fault. If I try to use ARM instruction set instead (using `-marm` option), application code won't compile, saying CPU doesn't support this instruction set.