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

ble_stack_init causing issues if other init functions are called after it

Hello,

nRF52840-DK

SDK 15.3.0

s140

OS: Ubuntu

IDE: SES

I have run into 2 init functions for separate features that have run into this issue. In main, when initializing functions the application will force a breakpoint if my init functions are below the ble_stack_function.

For myinit1 the result of having it called below ble_stack_init was, the debugger stopped at 0xA60 and the error was NRF_FAULT_ID_APP_MEMACC. I do not have as much information about myinit2.

I suspect it is a timer related issue as both of my inits use a timer, LFCLK, and HFCLK. What are the restrictions, and issue with call order and the ble_stack_init? I would like to better understand so I do not repeat the same mistake again.

main()
{
    myinit(); //This works only above ble_stack_init()
    ble_stack_init();
    //myinit() here will fail
}

ble_stack_init

/**@brief Function for initializing the BLE stack.
 *
 * @details Initializes the SoftDevice and the BLE event interrupt.
 */
static 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(APP_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);

    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}

myinit()

static void lfclk_config(void)
{
    NRF_CLOCK->LFCLKSRC             = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK->EVENTS_LFCLKSTARTED  = 0;
    NRF_CLOCK->TASKS_LFCLKSTART     = 1;
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
    {
        //Do nothing.
    }
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
}


myinit1(void)
{
    NRF_LOG_INFO("Initializing...");
    lfclk_config();
    uint32_t err_code;

    err_code = app_button_init((app_button_cfg_t *)mybutton,
                                   NUM_OF_BUTTONS,
                                   APP_TIMER_TICKS(10));
    APP_ERROR_CHECK(err_code);

    err_code = app_button_enable();
    APP_ERROR_CHECK(err_code);
}

void myinit2()
{
    // Configure output pin
    nrf_gpio_cfg_output(XCLK_PIN);
    nrf_gpio_pin_set(XCLK_PIN);

    // Start clock
    NRF_CLOCK->TASKS_HFCLKSTART = 1;
    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
    {
        // Wait for clock to start
    }
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;

}

Thank you,

Related