I am having trouble running softdevice_enable. Here is what happens:
After main(void) starts the code is:
log_init(); // WORKS clock_init(); // WORKS buttons_leds_init(&erase_bonds); // WORKS ble_stack_init(); // FAILURE results in infinite resets due to a weak error callback.
ble_stack_init is boilerplate code: void ble_stack_init(void) {
uint32_t err_code;
nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
// Initialize the SoftDevice handler module.
SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); // WORKS
// Fetch the start address of the application RAM.
uint32_t ram_start = 0;
err_code = softdevice_app_ram_start_get(&ram_start); // WORKS - ram_start is 0x200002000 as I think it should be
APP_ERROR_CHECK(err_code);
// Overwrite some of the default configurations for the BLE stack.
ble_cfg_t ble_cfg;
// Configure the maximum number of connections.
memset(&ble_cfg, 0, sizeof(ble_cfg));
ble_cfg.gap_cfg.role_count_cfg.periph_role_count = BLE_GAP_ROLE_COUNT_PERIPH_DEFAULT;
ble_cfg.gap_cfg.role_count_cfg.central_role_count = 0;
ble_cfg.gap_cfg.role_count_cfg.central_sec_count = 0;
err_code = sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, ram_start);
APP_ERROR_CHECK(err_code);
// Enable BLE stack.
err_code = softdevice_enable(&ram_start); // FAILS!!! - Analysis below
APP_ERROR_CHECK(err_code);
// Register with the SoftDevice handler module for BLE events.
err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
APP_ERROR_CHECK(err_code);
// Register with the SoftDevice handler module for BLE events.
err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
APP_ERROR_CHECK(err_code);
}
Okay, when soft_device_enable fails, this is what happens inside softdevice_enable:
uint32_t softdevice_enable(uint32_t * ram_start) { uint32_t err_code; uint32_t app_ram_base = *ram_start;
NRF_LOG_DEBUG("RAM start at 0x%x.\r\n", app_ram_base);
err_code = sd_ble_enable(&app_ram_base); // WORKS, but app_ram_base=0x20002060 which is NOT correct!
if (app_ram_base != *ram_start) // This is true because 0x20002060 != 0x20002000. This causes the failure!!!
{
NRF_LOG_WARNING("RAM start should be adjusted to 0x%x.\r\n", app_ram_base);
NRF_LOG_WARNING("RAM size should be adjusted to 0x%x.\r\n",
ram_end_address_get() - app_ram_base);
}
else if (err_code != NRF_SUCCESS)
{
NRF_LOG_ERROR("sd_ble_enable() returned unexpected value: 0x%x.\r\n", err_code);
}
return err_code;
}
==========
How do I fix this problem? Where should I look?