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

NRF52840 + SDK 13.0.0 (S140): MULTI-ROLE NOT WORKING & IAR COMPILER OPTIMIZATION ISSUES

Hi, I’m using nRF52840 with softdevice s140 and nRF5 SDK v13.0.0 and I’m having some issues regarding the optimization set up for the IAR Compiler (IAR Embedded Workbench v7.70.1). The application that I’m developing works as follows:

Pressing the Button 1 of the nRF52480-Preview-DK the device will work as peripheral, and pressing the Button 2 the device will work as central. The ble_stack_init() function looks like:

void ble_stack_init(void)

{

ret_code_t sErrCode;

ble_cfg_t   sBleCfg;

uint32_t u32RamStart = 0;



nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;



// Initialize the SoftDevice handler module.

SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);



// Fetch the start address of the application RAM.

sErrCode = softdevice_app_ram_start_get(&u32RamStart);

APP_ERROR_CHECK(sErrCode);



u32RamStart = 536880624;



memset(&sBleCfg, 0, sizeof(sBleCfg));

sBleCfg.gap_cfg.role_count_cfg.periph_role_count  = 1u;

sBleCfg.gap_cfg.role_count_cfg.central_role_count = 1u;

sBleCfg.gap_cfg.role_count_cfg.central_sec_count  = 0u;

sErrCode = sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &sBleCfg, u32RamStart);

APP_ERROR_CHECK(sErrCode);



sBleCfg.conn_cfg.params.gap_conn_cfg.conn_count     = 2;

sBleCfg.conn_cfg.params.gap_conn_cfg.event_length   = BLE_GAP_EVENT_LENGTH_DEFAULT;

sBleCfg.conn_cfg.conn_cfg_tag                       = APP_CONN_CFG_TAG;

sErrCode = sd_ble_cfg_set(BLE_CONN_CFG_GAP, &sBleCfg, u32RamStart);

APP_ERROR_CHECK(sErrCode);



// Enable BLE stack.

sErrCode = softdevice_enable(&u32RamStart);

APP_ERROR_CHECK(sErrCode);



// Subscribe for BLE events.

sErrCode = softdevice_ble_evt_handler_set(ble_fnBleEvtDispatch_vo);

APP_ERROR_CHECK(sErrCode);

}

My application is based on the experimental example of experimental_ble_app_blinky. The problem is that when the Optimization is set to HIGH, the program resets the SoC right after BLE advertising or scanning is started so it is impossible to trace back the origin of the error.

Furthermore, if the Optimization is set to NONE, the BLE advertising and scanning seems to work, but the program does not recognize the press of the buttons. It seems that there is a problem with the button library.

Has anyone faced the same kind of problem?

Thank you in advance.

  • Hi,

    • Are you using the APP_CONN_CFG_TAG tag when you start advertising? What value have you set it to? in advertising_start():

    err_code = sd_ble_gap_adv_start(&adv_params, APP_CONN_CFG_TAG);

    • Have you updated the Linker configuration file editor with your u32RamStart? :image description
  • First of all, thanks for your reply Sigurd. And yes, you were right indeed. I had just realized that the linker configuration was the root of the issue because the ram memory start address was not enough for my application configuration. Now buttons and advertising work correctly either with optimization high or none. However, the problem now is that the SoC keeps resetting (due to a "NRF_FAULT_ID_SD_ASSERT"') everytime it tries to start scanning. Any idea what could be happening???

  • The reason why the SoC is resetting is that this is the default behavior of the error-handler when an error is passed to the function APP_ERROR_CHECK(error_code). In order to find the function that is returning this error code you should debug the application. See this post about debugging.

    For IAR make sure that you are generating debug info (Project -> Options -> C/C++ Compiler -> Output and select Generate debug information.). Add the DEBUG as a Preprocessor flag(Project -> Options -> C/C++ Compiler->Preprocessor). Set optimization to None and place a breakpoint as described in the post I linked to.

Related