Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    Hard Fault after call to BSEC API

    Hard Fault after call to BSEC API

    lgacnik97
    Member

    I'm using the general use-case example by BSEC which I got from official github repository. 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).

    5 REPLIES 5

    BSTRobin
    Community Moderator
    Community Moderator

    Hi lgacnik97,

    Did you use BSEC2.4.0.0?
    We run latest BSEC2.4.0.0 on STM32F4(with CubeMX code generator) well. I can share my code to you if you need.
    My modification in startup_stm32f401xe.s:
    Stack_Size EQU 0x4000
    Heap_Size EQU 0x4000

    Hello Robin,

    Yes, the latest release, the BSEC 2.4.0.0. Note that I have posted in other question additional info, where I get hard fault because the "Undefined Instruction Set" even from the CFSR register. Besides the increased stack and heap size via linker script, I have ensured I'm using the `-mthumb` option for compiler, linker, and assembler, which uses the Thumb instruction set for CPU instructions - in case there is a problem with actual instruction set. Additionally, I have also tried the `-mthumb-interwork` option but the hard fault still happens. However, if I use `-marm` to use ARM instruction set, my code doesn't compile because CPU doesn't support this instruction set.

    The modifications you used for stack and heap in the startup file I cannot use. It looks like I'm using a different instruction set? You can also share your code, maybe I find something myself.

    I appended my startup and linker script.

    I just found out something. Instead of libalgobsec.a from Cortex-M7 folder I took libalgobsec.a from Cortex-M4F folder. Now the application runs through bsec_update_subscription() where it initially failed. Now I also see why it happens this way - because I'm using compiler options -mfloat-abi=hard and -mfpu=fpv5-sp-d16. Now I see that there is no FPU support for Cortex-M7-based BSEC algorithm. However, if I use setting -mfloat-abi=soft the code doesn't compile. Any ideas? How do you compile on your machine using software floating point arithmetic?

    Is it possible to use libalgobsec.a compiled static library for Cortex-M4 with FPU in with Cortex-M7 with CPU? If it compiles and builds without issues with the rest of the project, then I suppose it should be okay?

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist