This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI and S140 BLE controller conflict on nrf52840 dk using Zephyr

I have TWI sensor comms running fine in Zephyr on nrf52840_dk and separately Bluetooth controller in low latency mode using S140 softdevice also running fine in Zephyr on the nrf52840_dk.

When combined into one project, if the BT stack is enabled (even with no callbacks or API calls) then TWI transfers cause the processor to hard fault after only a few seconds. (From the debugging I have done it appears to fault when attempting to unready a thread.)


If TWI transfers are not called then BT works fine. If BT is not enabled then TWI transfers are fine. 

I understand that the Softdevice requires certain resources to be blocked or restricted but I have not been able to figure out what specific resources the TWI implementation is actually using to check if there is a conflict.

I have tried to switch to TWIM in case this is more robust but I then discovered that the Zephyr TWIM driver does not support bus recovery. 

Are you able to clarify if the Zephyr nrf TWI or TWIM drivers are expected to be compatible with enabling Softdevice Bluetooth controller on Zephyr? Then I would know to keep trying. 

Thanks 

  • I have now removed USB CDC initialization and now only log via RTT debug. So I now only have a BT stack and the TWI.
    I have also set the TWI priority to be the same as the main thread.

    With these changes Bluetooth advertising starts and TWI access works alongside bluetooth.
    A BT client can connect and subscribe to a characteristic.

    However, when bt_gatt_notify() or bt_gatt_notify_cb() are called (whilst the client is subscribed), a few msec later there is a fatal error.

    I have even tried putting the main thread into a while(1) loop after calling bt_gatt_notify(), but still a few msec later crash even though my code is literally doing nothing. 

    Here is the debug log showing the timing when bt_gatt_notify() is called and the exception.

    [00:00:22.843,475]<inf> main: About to call bt_gatt_notify_cb()
    [00:00:22.862,823]<inf> main: In ble_send_compressed_quaternion_olny
    [00:00:25.315,155]<err> os: ***** USAGE FAULT *****
    [00:00:25.315,185]<err> os:   Illegal use of the EPSR
    [00:00:25.315,185]<err> os: r0/a1:  0x00000000  r1/a2:  0xe000ed00  r2/a3:  0x20007eb4
    [00:00:25.315,185]<err> os: r3/a4:  0x00000000 r12/ip:  0x00000000 r14/lr:  0x000322e1
    [00:00:25.315,185]<err> os:  xpsr:  0x60000000
    [00:00:25.315,216]<err> os: Faulting instruction address (r15/pc): 0x00000000
    [00:00:25.315,216]<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
    [00:00:25.315,216]<err> os: Current thread: 0x2000716c (unknown)
    [00:00:27.911,712]<err> fatal_error: Resetting system

    Unfortunately with logging on the debugger now has nothing in the stack trace when it breaks on the fault so I can't see what function it is in except that with the while(1) test, it can't be a fault in my code after the bt_gatt_notify is called.

    Thanks

  • Hi,

    Are you able to clarify if the Zephyr nrf TWI or TWIM drivers are expected to be compatible with enabling Softdevice Bluetooth controller on Zephyr?

     Yes, they are expected to be compatible. 

    What tag/branch/commit are you using ?

    How have you configured the stack/heap ?

    Do you see any changes if you set the stack/heap like this ?

    # Heap and stacks
    CONFIG_HEAP_MEM_POOL_SIZE=16384
    CONFIG_MAIN_STACK_SIZE=8192
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    CONFIG_HW_STACK_PROTECTION=y

    Bluetooth controller in low latency mode

    Do you see any difference in behavior if you are not using low latency mode?

  • Brilliant!! Those config settings fixed it immediately. Thank you so much, that had me stuck for several days.

    This was using the zephyr version in nrf sdk 1.3.1.

Related