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

nRF51802 goes to hardfault on "sd_softdevice_enable" call

Hello everyone!

I'm trying to bring up project based on nRF51802 at custom board. I know this IC is not supported but there is no options to change it. I have downloaded  nRF5 SDK v12.3.0 and going to use softdevice S130 v2.0.1.

Since SDK has no templates or examples for Segger Embedded Studio, I started project from scratch leaning on examples for IAR. The problem is that device goes to hardfault, actually to some unexpected address and stuck there. Last normally executed instruction lays in softdevice memory region at 0x6B4 address. This happens upon executing "sd_softdevice_enable" function called from "softdevice_handler_init" functione given by SDK API. See pictures below.

Here is some code:

#define NRF_CLOCK_LFCLKSRC      {.source        = NRF_CLOCK_LF_SRC_XTAL,            \
                                 .rc_ctiv       = 0,                                \
                                 .rc_temp_ctiv  = 0,                                \
                                 .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM}
                                 

//---------------------------------------------------------------------------

static 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);

    ble_enable_params_t ble_enable_params;
    err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT,
                                                    PERIPHERAL_LINK_COUNT,
                                                    &ble_enable_params);
    APP_ERROR_CHECK(err_code);

    // Check the ram settings against the used number of links
    CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT);

    // Enable BLE stack.
#if (NRF_SD_BLE_API_VERSION == 3)
    ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_MAX_MTU_SIZE;
#endif
    err_code = softdevice_enable(&ble_enable_params);
    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 System events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}


//--------------------------------------------------------------------------------------------

void main(void) 
{
  int i;
  
  ble_stack_init();
  nrf_gpio_cfg_output( 2 );

  for (i = 0; i < 100; i++) {
    printf("Hello World %d!\n", i);
    nrf_gpio_pin_toggle( 2 );
  }
  do {
    i++;
  } while (1);
}

Also I was playing with differ from original clock settings, such as XTAL accuracy and even changed sourse to RC ocsillator. Device behaves in the same way.

Where did I go wrong? Any help will be apreciated.

 nordic-nrf51802.7z

Parents
  • Hello,

    Please include the CPU registers when the program as entered the fault handler at address 0x6B4.

    You can run the same code on nRF51802 as you can with 51822. However, the SDK examples are configured for the xxAC variant which has 32K  of RAM, not 16K. Did you adjust the linker settings so the 16K boundary is not exceeded?   

  • Thank you for response!

    Seems like I found possible reason - LFCK is not running, as function "nrf_drv_clock_lfclk_is_running" returns 0. 

    32768 kHz crystal connected to pins P0.26, P0.27 with 22pF filtering capacitors. I'm keep in searching why clock generation doesn't start.

    Also please see below CPU registers:

    Thank you for clarification regarding 51822 and 51802 interoperability. Yes, I have updated linker settings for 16 kB memory.

  • Expected behavior if the LF crystal fails to start is that the softdevice enable does not return (i.e., goes in an endless loop waiting for the clock signal to stabilize). It should not lead a fault exception. Assume you saw the same when you tried using the internal RC? 

    Could you upload your project here, or in a private support ticket so I can try to debug it here? 

Reply Children
Related