bt_enable() error: BUS FAULT Instruction bus error

Hi,

I am trying to implement a ble module in a fall detection application. I added a ble_service based on the BLE fundamentals course lesson 3, which works just fine alone, but when added to the project, the code apparently builds fine for both cores, but flashing gives me this:

*** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
*** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
[00:00:00.587,127] <inf> BLE_MODULE: Starting BLE module

[00:00:00.587,127] <inf> BLE_MODULE: Callbacks okay

[00:00:00.588,012] <err> os: ***** BUS FAULT *****
[00:00:00.588,012] <err> os:   Instruction bus error
[00:00:00.588,012] <err> os: r0/a1:  0x00000000  r1/a2:  0x0000003c  r2/a3:  0x00000000
[00:00:00.588,043] <err> os: r3/a4:  0x01460abb r12/ip:  0x48009808 r14/lr:  0x00001b97
[00:00:00.588,043] <err> os:  xpsr:  0x01000000
[00:00:00.588,043] <err> os: Faulting instruction address (r15/pc): 0x01460aba
[00:00:00.588,073] <err> os: >>> ZEPHYR FATAL ERROR 27: Unknown error on CPU 0
[00:00:00.588,104] <err> os: Current thread: 0x20000710 (unknown)
[00:00:00.672,302] <err> os: Halting system

Any idea?? 

Im attaching the project in this issue. 

Thanks!!

fall_detection.zip

Parents
  • Hi,

    Can you share your "west build" command?

    Do you use NCS v2.8.0?

    Can you provide full application log?

    Best regards,
    Dejan

  • Hi, Dejan!!

    I'm using 2.9.0.

    For shure, here they are:


    [00:00:00.455,322] <dbg> bmi270: write_config_file: writing config file max_fifo
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    [00:00:00.525,634] <inf> BLE_MODULE: Starting BLE module
    
    [00:00:00.525,634] <inf> BLE_MODULE: Callbacks okay
    
    [00:00:00.526,519] <err> os: ***** BUS FAULT *****
    [00:00:00.526,519] <err> os:   Instruction bus error
    [00:00:00.526,519] <err> os: r0/a1:  0x00000000  r1/a2:  0x0000003c  r2/a3:  0x00000000
    [00:00:00.526,550] <err> os: r3/a4:  0x01460abb r12/ip:  0x48019808 r14/lr:  0x00001b97
    [00:00:00.526,550] <err> os:  xpsr:  0x01000000
    [00:00:00.526,550] <err> os: Faulting instruction address (r15/pc): 0x01460aba
    [00:00:00.526,580] <err> os: >>> ZEPHYR FATAL ERROR 27: Unknown error on CPU 0
    [00:00:00.526,611] <err> os: Current thread: 0x20000710 (unknown)
    [00:00:00.610,778] <err> os: Halting system
    
    
    
    
    
    
    
    
    
    
    
    
     *  Executing task: nRF Connect: Build [pristine]: fall_detection/build 
    
    Building fall_detection
    west build --build-dir /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection --pristine --board nrf5340dk/nrf5340/cpuapp -- -DNCS_TOOLCHAIN_VERSION=NONE -DDTC_OVERLAY_FILE=nrf5340dk_nrf5340_cpuapp.overlay -DBOARD_ROOT=/Users/joaovitor/my_boards
    
    -- west build: generating a build system
    Loading Zephyr module(s) (Zephyr base): sysbuild_default
    -- Found Python3: /opt/nordic/ncs/toolchains/b8efef2ad5/opt/[email protected]/bin/python3.12 (found suitable version "3.12.4", minimum required is "3.8") found components: Interpreter 
    -- Cache files will be written to: /Users/joaovitor/Library/Caches/zephyr
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    CMake Warning at /opt/nordic/ncs/v2.9.0/zephyr/cmake/modules/boards.cmake:136 (message):
      BOARD_ROOT element without a 'boards' subdirectory:
    
      /Users/joaovitor/my_boards
    
      Hints:
    
        - if your board directory is '/foo/bar/boards/my_board' then add '/foo/bar' to BOARD_ROOT, not the entire board directory
        - if in doubt, use absolute paths
    Call Stack (most recent call first):
      cmake/modules/sysbuild_default.cmake:15 (include)
      /opt/nordic/ncs/v2.9.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:75 (include)
      /opt/nordic/ncs/v2.9.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
      /opt/nordic/ncs/v2.9.0/zephyr/share/sysbuild-package/cmake/SysbuildConfig.cmake:8 (include)
      template/CMakeLists.txt:10 (find_package)
    
    
    -- Board: nrf5340dk, qualifiers: nrf5340/cpuapp
    Parsing /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/Kconfig.sysbuild
    Loaded configuration '/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/_sysbuild/empty.conf'
    Merged configuration '/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/_sysbuild/empty.conf'
    Configuration saved to '/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/zephyr/.config'
    Kconfig header saved to '/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/_sysbuild/autoconf.h'
    -- 
       ************************************
       * Running CMake for fall_detection *
       ************************************
    
    Loading Zephyr default modules (Zephyr base).
    -- Application: /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection
    -- CMake version: 3.21.0
    -- Found Python3: /opt/nordic/ncs/toolchains/b8efef2ad5/bin/python (found suitable version "3.12.4", minimum required is "3.8") found components: Interpreter 
    -- Cache files will be written to: /Users/joaovitor/Library/Caches/zephyr
    -- Zephyr version: 3.7.99 (/opt/nordic/ncs/v2.9.0/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    CMake Warning at /opt/nordic/ncs/v2.9.0/zephyr/cmake/modules/boards.cmake:136 (message):
      BOARD_ROOT element without a 'boards' subdirectory:
    
      /Users/joaovitor/my_boards
    
      Hints:
    
        - if your board directory is '/foo/bar/boards/my_board' then add '/foo/bar' to BOARD_ROOT, not the entire board directory
        - if in doubt, use absolute paths
    Call Stack (most recent call first):
      /opt/nordic/ncs/v2.9.0/zephyr/cmake/modules/zephyr_default.cmake:133 (include)
      /opt/nordic/ncs/v2.9.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      /opt/nordic/ncs/v2.9.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
      CMakeLists.txt:2 (find_package)
    
    
    -- Board: nrf5340dk, qualifiers: nrf5340/cpuapp
    -- Found host-tools: zephyr 0.17.0 (/opt/nordic/ncs/toolchains/b8efef2ad5/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.17.0 (/opt/nordic/ncs/toolchains/b8efef2ad5/opt/zephyr-sdk)
    -- Found Dtc: /opt/nordic/ncs/toolchains/b8efef2ad5/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6") 
    -- Found BOARD.dts: /opt/nordic/ncs/v2.9.0/zephyr/boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpuapp.dts
    -- Found devicetree overlay: nrf5340dk_nrf5340_cpuapp.overlay
    -- Generated zephyr.dts: /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/fall_detection/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/fall_detection/zephyr/include/generated/zephyr/devicetree_generated.h
    -- Including generated dts.cmake file: /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/fall_detection/zephyr/dts.cmake
    Parsing /opt/nordic/ncs/v2.9.0/zephyr/Kconfig
    Loaded configuration '/opt/nordic/ncs/v2.9.0/zephyr/boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpuapp_defconfig'
    Merged configuration '/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/prj.conf'
    Merged configuration '/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/fall_detection/zephyr/.config.sysbuild'
    Configuration saved to '/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/fall_detection/zephyr/.config'
    Kconfig header saved to '/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/fall_detection/zephyr/include/generated/zephyr/autoconf.h'
    -- Found GnuLd: /opt/nordic/ncs/toolchains/b8efef2ad5/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd (found version "2.38") 
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /opt/nordic/ncs/toolchains/b8efef2ad5/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    CMake Warning at /opt/nordic/ncs/v2.9.0/zephyr/CMakeLists.txt:130 (message):
      The environment variable 'CPPFLAGS' was set to
      -I/opt/homebrew/opt/llvm/include, but Zephyr ignores flags from the
      environment.  Use 'cmake -DEXTRA_CPPFLAGS=-I/opt/homebrew/opt/llvm/include'
      instead.
    
    
    CMake Warning at /opt/nordic/ncs/v2.9.0/zephyr/CMakeLists.txt:130 (message):
      The environment variable 'LDFLAGS' was set to -L/opt/homebrew/opt/llvm/lib,
      but Zephyr ignores flags from the environment.  Use 'cmake
      -DEXTRA_LDFLAGS=-L/opt/homebrew/opt/llvm/lib' instead.
    
    
    -- libmetal version: 1.6.0 (/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection)
    -- Build type:  
    -- Host:    Darwin/arm64
    -- Target:  Generic/arm
    -- Machine: arm
    -- Looking for include file stdatomic.h
    -- Looking for include file stdatomic.h - found
    -- open-amp version: 1.6.1 (/opt/nordic/ncs/v2.9.0/modules/lib/open-amp/open-amp)
    -- Looking for include file fcntl.h
    -- Host:    Darwin/arm64
    -- Target:  Generic/arm
    -- Machine: arm
    -- C_FLAGS :  -Wall -Wextra
    -- Looking for include file fcntl.h - found
    -- Setting build type to 'MinSizeRel' as none was specified.
    -- Using ccache: /opt/nordic/ncs/toolchains/b8efef2ad5/bin/ccache
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/fall_detection
    -- 
       *******************************
       * Running CMake for ipc_radio *
       *******************************
    
    Loading Zephyr default modules (Zephyr base).
    -- Application: /opt/nordic/ncs/v2.9.0/nrf/applications/ipc_radio
    -- CMake version: 3.21.0
    -- Found Python3: /opt/nordic/ncs/toolchains/b8efef2ad5/bin/python (found suitable version "3.12.4", minimum required is "3.8") found components: Interpreter 
    -- Cache files will be written to: /Users/joaovitor/Library/Caches/zephyr
    -- Zephyr version: 3.7.99 (/opt/nordic/ncs/v2.9.0/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    CMake Warning at /opt/nordic/ncs/v2.9.0/zephyr/cmake/modules/boards.cmake:136 (message):
      BOARD_ROOT element without a 'boards' subdirectory:
    
      /Users/joaovitor/my_boards
    
      Hints:
    
        - if your board directory is '/foo/bar/boards/my_board' then add '/foo/bar' to BOARD_ROOT, not the entire board directory
        - if in doubt, use absolute paths
    Call Stack (most recent call first):
      /opt/nordic/ncs/v2.9.0/zephyr/cmake/modules/zephyr_default.cmake:133 (include)
      /opt/nordic/ncs/v2.9.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      /opt/nordic/ncs/v2.9.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
      CMakeLists.txt:9 (find_package)
    
    
    -- Board: nrf5340dk, qualifiers: nrf5340/cpunet
    -- Found host-tools: zephyr 0.17.0 (/opt/nordic/ncs/toolchains/b8efef2ad5/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.17.0 (/opt/nordic/ncs/toolchains/b8efef2ad5/opt/zephyr-sdk)
    -- Found Dtc: /opt/nordic/ncs/toolchains/b8efef2ad5/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6") 
    -- Found BOARD.dts: /opt/nordic/ncs/v2.9.0/zephyr/boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpunet.dts
    -- Generated zephyr.dts: /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/ipc_radio/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/ipc_radio/zephyr/include/generated/zephyr/devicetree_generated.h
    -- Including generated dts.cmake file: /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/ipc_radio/zephyr/dts.cmake
    Parsing /opt/nordic/ncs/v2.9.0/nrf/applications/ipc_radio/Kconfig
    Loaded configuration '/opt/nordic/ncs/v2.9.0/zephyr/boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpunet_defconfig'
    Merged configuration '/opt/nordic/ncs/v2.9.0/nrf/applications/ipc_radio/prj.conf'
    Merged configuration '/opt/nordic/ncs/v2.9.0/nrf/applications/ipc_radio/overlay-bt_hci_ipc.conf'
    Merged configuration '/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/ipc_radio/zephyr/.config.sysbuild'
    Configuration saved to '/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/ipc_radio/zephyr/.config'
    Kconfig header saved to '/Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/ipc_radio/zephyr/include/generated/zephyr/autoconf.h'
    -- Found GnuLd: /opt/nordic/ncs/toolchains/b8efef2ad5/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd (found version "2.38") 
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /opt/nordic/ncs/toolchains/b8efef2ad5/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    CMake Warning at /opt/nordic/ncs/v2.9.0/zephyr/CMakeLists.txt:130 (message):
      The environment variable 'CPPFLAGS' was set to
      -I/opt/homebrew/opt/llvm/include, but Zephyr ignores flags from the
      environment.  Use 'cmake -DEXTRA_CPPFLAGS=-I/opt/homebrew/opt/llvm/include'
      instead.
    
    
    CMake Warning at /opt/nordic/ncs/v2.9.0/zephyr/CMakeLists.txt:130 (message):
      The environment variable 'LDFLAGS' was set to -L/opt/homebrew/opt/llvm/lib,
      but Zephyr ignores flags from the environment.  Use 'cmake
      -DEXTRA_LDFLAGS=-L/opt/homebrew/opt/llvm/lib' instead.
    
    
    -- libmetal version: 1.6.0 (/opt/nordic/ncs/v2.9.0/nrf/applications/ipc_radio)
    -- Build type:  
    -- Host:    Darwin/arm64
    -- Target:  Generic/arm
    -- Machine: arm
    -- Looking for include file stdatomic.h
    -- Looking for include file stdatomic.h - found
    -- open-amp version: 1.6.1 (/opt/nordic/ncs/v2.9.0/modules/lib/open-amp/open-amp)
    -- Host:    Darwin/arm64
    -- Target:  Generic/arm
    -- Machine: arm
    -- C_FLAGS :  -Wall -Wextra
    -- Looking for include file fcntl.h
    -- Looking for include file fcntl.h - found
    -- Setting build type to 'MinSizeRel' as none was specified.
    -- Using ccache: /opt/nordic/ncs/toolchains/b8efef2ad5/bin/ccache
    CMake Warning at /opt/nordic/ncs/v2.9.0/zephyr/CMakeLists.txt:952 (message):
      No SOURCES given to Zephyr library: drivers__console
    
      Excluding target from build.
    
    
    CMake Warning at /opt/nordic/ncs/v2.9.0/zephyr/CMakeLists.txt:2133 (message):
      __ASSERT() statements are globally ENABLED
    
    
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/ipc_radio
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build
    -- west build: building application
    [1/237] Preparing syscall dependency handling
    
    [6/237] Generating include/generated/zephyr/version.h
    -- Zephyr version: 3.7.99 (/opt/nordic/ncs/v2.9.0/zephyr), build: v3.7.99-ncs2
    [237/237] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:      108560 B         1 MB     10.35%
                 RAM:       77156 B       448 KB     16.82%
            IDT_LIST:          0 GB        32 KB      0.00%
    Generating files from /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/fall_detection/zephyr/zephyr.elf for board: nrf5340dk
    [1/204] Preparing syscall dependency handling
    
    [6/204] Generating include/generated/zephyr/version.h
    -- Zephyr version: 3.7.99 (/opt/nordic/ncs/v2.9.0/zephyr), build: v3.7.99-ncs2
    [204/204] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:      168880 B       256 KB     64.42%
                 RAM:       46560 B        64 KB     71.04%
               SRAM1:          0 GB        64 KB      0.00%
            IDT_LIST:          0 GB        32 KB      0.00%
    Generating files from /Users/joaovitor/Documents/programming/Tiresias_applications/fall_detection/build/ipc_radio/zephyr/zephyr.elf for board: nrf5340dk
    [20/20] Generating ../merged_CPUNET.hex
     *  Terminal will be reused by tasks, press any key to close it. 
    
    

  • Hi,

    Thank you for additional details.

    Which exercise from the lesson 3 have you been using as a starting point?

    Can you provide more information about the changes that you implemented? 

    Best regards,
    Dejan

  • Hey,

    I've been using Ex1 of Lesson 3.

    First of all I've implemented it inside a directory (BLE) within src and shown the compiler with CMakeLists:

    cmake_minimum_required(VERSION 3.20.0)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    
    project(fall_detection)
    
    target_sources(app PRIVATE 
        src/main.c
        src/led/led.c
        src/fall_detection/fall_detection.c
        src/BLE/ble_service.c
    )
    
    # NORDIC SDK APP END
    zephyr_library_include_directories(.)
    

    Then I declared everything in a header file and implemented most of the original main function in a function called ble_service_init:

    int ble_service_init(void) {
    	int err;
    
    	LOG_INF("Starting BLE module\n");
    
    	// Register our custom callbacks 
    	bt_conn_cb_register(&connection_callbacks);
    
    	LOG_INF("Callbacks okay\n");
    
    	err = bt_enable(NULL);
    	if (err) {
    		LOG_ERR("Bluetooth init failed (err %d)", err);
    		return -1;
    	}
    	
    	LOG_INF("Bluetooth initialized");
    	
    	err = bt_le_adv_start(adv_param, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    	if (err) {
    		LOG_ERR("Advertising failed to start (err %d)", err);
    		return -1;
    	}
    
    	LOG_INF("Advertising successfully started");
    
    	return -1;
    }

    I call this function in main(). I also defined a ble_service_thread with lower priority only containing k_sleep for testing purposes. 

    I think that's all.. 

    João.

  • Hi Joao, (EDIT: targeted wrong person here at first)

    West is warning you about that the BOARD_ROOT. Perhaps remove that parameter so that you get rid of the warning. Never get used to warnings!

    I have no experience with this SoC which has 2 MCUs. Perhaps you have only flashed the application and missed flashing the BLE Controller part. You can read about that here:

    Working with nRF5340 DK

    And also here:

    nRF Connect SDK Tutorial - Part 1 - 2.2.1 Build a BLE example (nRF5340) - Nordic Q&A - Nordic DevZone - Nordic DevZone

    Perhaps you can consider to register your callbacks after you have initialized the Bluetooth module. But I doubt that it is the source of the error.

    When attaching source code, next time, please try not to include your generated binaries in it.

    Good luck with your project!

  • Hi João,

    Thank you for additional information.

    Can you try to add debug optimizations -DCONFIG_DEBUG_OPTIMIZATIONS=y and -DCONFIG_DEBUG_THREAD_INFO=y and try to use addr2line tool for checking where the error occurred? You could potentially also use Thread Analyzer for tracking thread information.

    Best regards,
    Dejan

Reply Children
Related