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

BLE_ERROR_NOT_ENABLED with S120

Hi,

I'm using a lightly modified copy of the Multilink central S120 example code. When I get to ble_stack_init() the first thing it does is SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);

Unfortunately that gives me an error code of 4097 which is BLE_ERROR_NOT_ENABLED. The comment for that error says "sd_ble_enable has not been called". But in the example code sd_ble_enable() is after SOFTDEVICE_HANDLER_INIT() so of course it hasn't been called!

If I believe the error and move sd_ble_enable() before SOFTDEVICE_HANDLER_INIT() then sd_ble_enable() returns error code 2, which is NRF_ERROR_SOFTDEVICE_NOT_ENABLED!

What is going on here? Which one should go first, and why are there error codes for both of them not being called first?

  • What version of S120 and what version of the SDK are you building with and are you absolutely sure that the correct version of the SD is on the chip (and that you used the headers for that version when you built).

    I've been bitten by a mismatch between softdevice I thought I loaded, softdevice I actually loaded and softdevice headers built against more than once so it's worth absolutely verifying it.

  • It's definitely the right version. However I have found that the untouched multilink example does work, so it must be something I've changed. The only things I've really changed are that I'm using C++ instead of C (main is C++ now), and I'm using a different build system. As far as I can tell the build system does all the same things though.

  • Ok I did a lot of debugging on this, at some point the original BLE_ERROR_NOT_ENABLED error disappeared but I started having similar issues with device_manager_central.c

    I eventually narrowed this down to the -Os optimisation I was using (I naively assumed that it worked). Unfortunately it seems that -Os screws something up somewhere.

    If you take the multilink_central example and change -O3 to -Os in the settings it will crash indevice_manager_init().

    Kind of infuriating.

    Edit

    I found the cause of the original error - it was because I was using my own serial code, and I was initialising it before ble_stack_init(). If I move it after that function it works fine. No idea why, especially as the example code initialises the UART before ble_stack_init() but whatever...

  • To be clear, using -Os didn't clear up the BLE_ERROR_NOT_ENABLED in my original build, but I have since done some other change to the build file which has fixed it (no idea what) so I'm just sticking with my new build file.

  • -Os generally works - this is GCC? I use that for my release builds most of the time because it's smaller and generally pretty performant.

Related