Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Build and Run with SEGGER Embedded Studio (SES) v6.20a on nRF5 SDK 17.1.0 and S140 7.2.0 on nRF52840

Hi DevZone,

I have recently updated:

  • nRF5 SDK to 17.1.0 from 15.3.0
  • S140 to 7.2.0 from 6.1.1
  • SES to v6.20a from 4.16

The SoftDevice now fails to initialize when using the "Build and Run" option with SES.

The code initializes without issue if I:

  • Use Programmer v2.3.3 from nRF Connect for Desktop v3.10.0
  • If I Power Cycle the hardware after each flash of the .hex files
  • If I "Build and Debug" with SES

Is this a known issue, and could it potentially be a timing issue?

Code that fails:

void ble_stack_init(void)
{
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err_code);

//    // NO OBSERVERS AT THIS POINT 
//    // Register a handler for BLE events.
//    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}

Specifically the call to nrf_sdh_enable_request() returns with error code NRF_ERROR_INVALID_STATE (0x00000008).

This should mean that the SoftDevice is already initialized when reading the documentation. However, preceding the nrf_sdh_enable_request() call with a nrf_sdh_is_enabled()

tells me that it is not.

Comparing with example projects:

I have compared to the example projects given in SDK 17.1.0, and the initialization code for the BLE stack seems unchanged between versions 17.1.0 and 15.3.0. 

Also, I have tried building and running the peripheral example from SDK 17.1.0 "usbd_ble_uart_freertos" both on our hardware and an nRF52840-DK, which fails with the same error code.

So, even with code directly from the SDK and on multiple hardware the issue is the same.

Thanks in advance.

Br. Casper

  • Hi Edvin,

    Migration Guides:

    I did look at migration guides from 15.3.0 to 16.0.0 and then from 16.0.0 to 17.0.2 of the SDK.

    RAM and FLASH:

    I have used the RAM and flash placements from the usbd_ble_uart_freertos example and that allowed the project to build after migration. However, I did not know that the RAM settings were dependent on the specific use case of S140.

    Error in my statement in the "Update" post:

    I thought that I had gotten an example from the SDK working without any issues, however I must have been tired as I simply did not get the LOG output with the errors... So I never had a working example project from the SDK.

    Sharing an example to run on a nRF52840-DK that reproduces the error:

    I have used the usbd_ble_uart_freertos example from SDK 17.1.0, and enabled all NRF logging for the SoftDevice, as well as added my own outputs to the ble_stack_init() function and added that to a .zip library.

    To get it to run, you should be able to go to:

    <SDK Location on your PC>\nRF5_SDK_17.1.0_ddde560\examples\peripheral\

    And unpack the .zip file. I built the version for pca10056, SES and S140 located here:

    <SDK Location on your PC>\nRF5_SDK_17.1.0_ddde560\examples\peripheral\usbd_ble_uart_freertos\pca10056\s140\ses

    As I wrote in the original post, the error only shows when using the "Build and Run" option in SEGGER Embedded Studio.

    From what I can see, it is Line 214 in nrf_sdh.c that returns NRF_ERROR_INVALID_STATE.

    Hope this is something you can work with.

    Br. Casper

    usbd_ble_uart_freertos.zip

    EDIT:
    To make it build I assume you also need to change a line in retarget.c like I had to.
    retarget.c line 100 changed to: 
    #if defined(__SES_VERSION) && (__SES_VERSION >= 34000) && !defined(__SEGGER_RTL_VERSION)

  • In my case, line 214 in nrf_sdh.c is:

    ret_code = sd_softdevice_enable(&clock_lf_cfg, app_error_fault_handler);

    Is that the case for you as well?

    Also, in my case, this returns NRF_SUCCESS when I compiled and ran your project. If you get something else, perhaps you can try to unzip the file that you just sent me into an unmodified SDK17.1.0, in case you changed something without being aware of it. See if it still returns NRF_ERROR_INVALID_STATE. 

    Note:

    It didn't compile right away, with some weird compiler error. When I used "Rebuild solution" it compiled without errors.

    Best regards,

    Edvin

  • Hi Edvin,

    I just unzipped a fresh SDK 17.1.0, deleted the existing usbd_ble_uart_freertos example and unzipped the file I sent you. Then I selected Build and Run after making sure the nRF52840-DK already holds the S140 v7.2.0 with nRF Connect.

    This is the output I get:

    <info> app: USBD BLE UART example started.

    <debug> nrf_sdh: State request: 0x00000000

    <debug> nrf_sdh: State change: 0x00000000

    <info> app: SDH Enable: 8

    <info> app: SDH Config: 0, Ram Start: 20002AE8

    <info> app: BLE Enable: 8

    <debug> nrf_sdh_freertos: Creating a SoftDevice task.

    <debug> nrf_sdh_freertos: Enter softdevice_task.

    However, I am noticing that you are using SES v5.64, and I am using SES v6.20a. I will try and investigate if a rollback of my IDE could solve the issue.

    Br. Casper

    EDIT: Did not answer your question 

    Edvin said:

    In my case, line 214 in nrf_sdh.c is:

    Fullscreen
    1
    ret_code = sd_softdevice_enable(&clock_lf_cfg, app_error_fault_handler);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    ret_code = sd_softdevice_enable(&clock_lf_cfg, app_error_fault_handler);

    Is that the case for you as well?

    Yes this is the same line for me.

  • Hi Edvin,

    I just installed SES v5.64

    I then erased the flash on the nRF52840-DK, and used nRF Connect for Desktop Programmer to write S140 v7.20 and the usbd_ble_uart_freertos example.

    The issue still persists for me though when using "Build and Run" with SES v5.64.

    I can still make the code run by using "Build and Debug" with SES v5.64 or by using "nRF Connect for Desktop Programmer" to flash the nRF52840-DK as before.

    Br. Casper

  • Did you try to use SES with a clean install of the SDK? Download and unzip the SDK, and unzip the file that you sent me into the very same location that you described in the unmodified SDK. 

Related