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

nRF52 LF crystal initialization best practices

Hi all, I used SDK example as a reference on how to initialize LF clock.

The code is :

    err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);
    nrf_drv_clock_lfclk_request(NULL);

The nrf_drv_clock_lfclk_request(NULL) is asynchronous and in current example callback handler was not assigned for handling successful start. 
I have a few questions here.

1) What if LF hardware is broken? I suggest we need to check if LF actually started before running app code. Any code examples how to do this in most proper way?

2) Regarding 1) , is it safe enough to set LF crystal as a clock source for WDT?

3) If LF crystal clock started in bootloader, do I need to reinit it in app?

thanks

Parents
  • 1) you can add a while(nrf_drv_clock_lfclk_is_running()); after the request. This will make sure the app is not proceeding unless you are able to start the LF crystal.

    2)According to documentation: When started, the watchdog will automatically force the 32.768 kHz RC oscillator on as long as no other 32.768 kHz clock source is running and generating the 32.768 kHz system clock, see chapter CLOCK — Clock control.

    3) Yes. Not sure which sdk version you are using ,but you do not want to rely in the bootloader to do initialization for the application.

  • Thanks run_ar, 

    1) According to the code 

    bool nrf_drv_clock_lfclk_is_running(void)
    {
        ASSERT(m_clock_cb.module_initialized);
    
    #ifdef SOFTDEVICE_PRESENT
        if (nrf_sdh_is_enabled())
        {
            return true;
        }
    #endif // SOFTDEVICE_PRESENT
    
        return nrfx_clock_lfclk_is_running();
    }
    

    I suggest that if I receive NRF_SDH_EVT_STATE_ENABLED event after calling nrf_sdh_enable_request() the LF clock have to be enabled. So if I use softdevice I do not need to init LF clock manually. Does it make sense? 

    2) If I start LF clock (on crystal source) before starting WDT, the last will use crystal as a clock source? 

    2') If I start WDT before starting softdevice with NRF_SDH_CLOCK_LF_SRC == 1 (XTAL). Will WDT stay on RC clock source or switch to XTAL clock?

    3)clear

    thanks! 

  • 1) The SD will start the LF clock. Either the RC or the crystal depending on configuration.

    2.1) yes.

    2.2) It think it will continue to run from RC. So you should start the crystal first.

Reply Children
No Data
Related