Relation between clock and softdevice

I'am currently porting code from NRF51822 to NRF52805. In my old code I used the following line to initialize softdevice:

```
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);

```

I'm not sure if parameter `NRF_CLOCK_LFCLKSRC_XTAL_20_PPM` is correctly set, but it worked. The project was build against Nordic SDK 9.0.0.

---

On my new chip I am using Nordic SDK 17.1.0 with current patches. Here two functions for initialising softdevice exists: `nrf_sdh_enable_request` and `sd_softdevice_enable`.  

If I am using `nrf_sdh_enable_request` everything works fine. However startup time is relative high which isn't a big problem.

However I tested function `sd_softdevice_enable` where clock parameter must be entered. So I manually started high frequency clock (`while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)`) and started softdevice with following code:

```
nrf_clock_lf_cfg_t Config;
    
memset(&Config, 0, sizeof(Config));
Config.accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM;
Config.source = NRF_CLOCK_LF_SRC_SYNTH;                 
return sd_softdevice_enable(&Config, gErrorHandler);    // Old code: SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);
```

After that softdevice starts very fast. However my flash write function didn't work any more and hangs. I am using `nrf_fstorage.h` and `nrf_storage_sd.h`.

So what happend if some wrong parameter are given to `sd_softdevice_enable`?
Why are there two functions for enabling softdevice?
Does `sd_softdevice_enable` also starts a clock?

  • Hi Johannes, 
    First of all the nRF5 SDK is maintenance mode as we moved to nRF Connect SDK since 2020. For any new development we suggest to use nRF Connect SDK.

    Regarding your question, to set the LF clock you would need to looking to the sdkconfig.h file. Please look for 
    NRF_SDH_CLOCK_LF_SRC . Set it to 1 mean XTAL and 0 means RC. Please don't use NRF_CLOCK_LF_SRC_SYNTH because it's not tested for use with the softdevice. 

    You may need to check if NRFX_CLOCK_CONFIG_LF_SRC and CLOCK_CONFIG_LF_SRC are set to the same clock source or not. 

Related