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 

Parents
  • 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

Reply
  • 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

Children
No Data
Related