nRF5340 Peripheral BLE connections always fail with reason 0x3e (62)

I solved this but the solution wasn't obvious and it didn't show up on google so I'm going to leave a quick writeup here.

nRF Connect SDK 1.7.1 on windows and linux

We have a custom board using the nRF5340 module from ublox (Nora-B1) testing using the stock peripheral_uart application. Board target nrf5340dk_nrf5340_cpuapp. It builds correctly for both cores and flashes, but hangs on startup.  'west attach' shows it looping waiting on the external crystal to come up, but we don't have an external crystal on this board.

I created <app>/boards/nrf5340dk_nrf5340_cpuapp.conf with the line CONFIG_SOC_ENABLE_LFXO=n, and did the same for hci_rpmsg/boards/nrf5340dk_nrf5340_cpunet.conf.  I also enabled the RTT debug overlays for both processors. The board started up, and "NORDIC_UART_SERVICE" showed up in the nRF Connect app.  Whenever I tried to connect to it, i was immediately disconnected.  debug log showed:

[00:00:40.568,634] <inf> peripheral_uart: Connected 55:54:83:BC:F7:2A (random)
...
[00:00:40.793,273] <dbg> bt_hci_core.hci_disconn_complete_prio: status 0x00 handle 15 reason 0x3e
[00:00:40.793,273] <dbg> bt_hci_core.hci_disconn_complete: status 0x00 handle 15 reason 0x3e
...
[00:00:40.793,273] <inf> peripheral_uart: Disconnected: 55:54:83:BC:F7:2A (random) (reason 62)

The configuration is misleading: While CONFIG_SOC_ENABLE_LFXO=n does skip the wait for the external crystal it does NOT correctly set the low frequency clock source.  The result is firmware that boots and advertises but cannot be connected to.

You have to use CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y in both your app and the stock hci_rpmsg configuration overlays. Or create a full board definition from scratch, but there's a bunch of pitfalls related to the tfm build process expecting specific boards so watch out if you go that route.

I hope this helps somebody!  Took me a few days to figure out because it ends up half-working so I was chasing my tail looking for potential signal problems with the external antenna.

  • Two things would make this easier to debug. The first would be changing the loop that waits on the external crystal to have a max count, and fail out with a console/debug log error saying the 32khz crystal isn't working. Currently the SDK behavior is to spin forever with no messages. 

    The second would be to log an error if the 32khz clock isn't running when we expect it to be, again with a brief and searchable message.  something like <err> 32KHZ clock not running - check K32SRC.

    Making documentation on the startup sequence more discoverable might help as well.  The quickstart assumes you're using the DK and doesn't discuss the details in depth, then the Board Porting Guide only mentions the system clock.  The 32K clock may only be mentioned indirectly ("configure a tick source"?) and not expanded on.

    Searching for CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC only finds hits on the Kconfig pages, so you have to know what you're looking for before you can find it.

    This applies to some other parts of the initial bringup, such as fixed-purpose pins (NFC, LFXO) and that there's extra steps involved to configure them as GPIO aside from just setting them in the device tree.  Searching for that issue finds many threads of people confused why some pins don't work, and all getting the same answer.  There's a devicetree validator as part of the build process already, perhaps it could flag an error on trivial conflicts such as using pin0.00/0.01 while having CONFIG_SOC_ENABLE_LFXO=y?

  • Thank you for the suggestions. I agree with your points and have made an internal feature request for it.

  • I have to let my hair grow back from pulling it all out before finding your post! 

    I ad that configured for the app but had no idea it needed to be there for the net as well.  

    :( 

  • Sorry.  What were you trying to search for before finding it? I can add keywords to the original post to make it more discoverable.

  • Out of Tree Board: this is the symptom


    bt_enable() fails with the following:

    E: Endpoint binding failed with -11
    E: HCI driver open failed (-11)

    I need to go close the ticket I just opened.  I'm so glad I found this post. 
    Thank you!!

Related