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

What is the equivalent of S110's enum "NRF_CLOCK_LFCLKSRCS" in S140?

Hello, in S110 device's nrf_sdm.h, there is this enum "NRF_CLOCK_LFCLKSRCS" which is defined as:

enum NRF_CLOCK_LFCLKSRCS
{
  NRF_CLOCK_LFCLKSRC_SYNTH_250_PPM,                       /**< LFCLK Synthesized from HFCLK.                            */
  NRF_CLOCK_LFCLKSRC_XTAL_500_PPM,                        /**< LFCLK crystal oscillator 500 PPM accuracy.       */
  NRF_CLOCK_LFCLKSRC_XTAL_250_PPM,                        /**< LFCLK crystal oscillator 250 PPM accuracy.       */
  NRF_CLOCK_LFCLKSRC_XTAL_150_PPM,                        /**< LFCLK crystal oscillator 150 PPM accuracy.       */
  NRF_CLOCK_LFCLKSRC_XTAL_100_PPM,                        /**< LFCLK crystal oscillator 100 PPM accuracy.       */
  NRF_CLOCK_LFCLKSRC_XTAL_75_PPM,                         /**< LFCLK crystal oscillator 75 PPM accuracy.        */
  NRF_CLOCK_LFCLKSRC_XTAL_50_PPM,                         /**< LFCLK crystal oscillator 50 PPM accuracy.        */
  NRF_CLOCK_LFCLKSRC_XTAL_30_PPM,                         /**< LFCLK crystal oscillator 30 PPM accuracy.        */
  NRF_CLOCK_LFCLKSRC_XTAL_20_PPM,                         /**< LFCLK crystal oscillator 20 PPM accuracy.        */
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION,        /**< LFCLK RC oscillator, 250ms  calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_500MS_CALIBRATION,        /**< LFCLK RC oscillator, 500ms  calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_1000MS_CALIBRATION,       /**< LFCLK RC oscillator, 1000ms calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_2000MS_CALIBRATION,       /**< LFCLK RC oscillator, 2000ms calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION,       /**< LFCLK RC oscillator, 4000ms calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_8000MS_CALIBRATION,       /**< LFCLK RC oscillator, 8000ms calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_1000MS_CALIBRATION,  /**< LFCLK RC oscillator. Temperature checked every 1000ms, if changed above a threshold, a calibration is done.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_2000MS_CALIBRATION,  /**< LFCLK RC oscillator. Temperature checked every 2000ms, if changed above a threshold, a calibration is done.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_4000MS_CALIBRATION,  /**< LFCLK RC oscillator. Temperature checked every 4000ms, if changed above a threshold, a calibration is done.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_8000MS_CALIBRATION,  /**< LFCLK RC oscillator. Temperature checked every 8000ms, if changed above a threshold, a calibration is done.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_16000MS_CALIBRATION, /**< LFCLK RC oscillator. Temperature checked every 16000ms, if changed above a threshold, a calibration is done.*/
};

When migrating to S140 softdevice, this is nowhere to be found. By scanning through the migration manual I realized there are some name changes but this one isn't mentioned.

As I noted, I'm migrating a project from nrf51 to 52, and this enum isn't something I can simply discard. Here is the part of the code, a function where the enum is called:

uint32_t timeslot_init(nrf_clock_lfclksrc_t lfclksrc)
{
    if (m_framework_initialized)
{
    return NRF_ERROR_INVALID_STATE;
}

switch (lfclksrc)
{
    case NRF_CLOCK_LFCLKSRC_XTAL_100_PPM:
        m_lfclk_ppm = 100;
        break;
    case NRF_CLOCK_LFCLKSRC_XTAL_150_PPM:
        m_lfclk_ppm = 150;
        break;
    case NRF_CLOCK_LFCLKSRC_XTAL_20_PPM:
        m_lfclk_ppm = 20;
        break;
    case NRF_CLOCK_LFCLKSRC_XTAL_250_PPM:
        m_lfclk_ppm = 250;
        break;
    case NRF_CLOCK_LFCLKSRC_XTAL_30_PPM:
        m_lfclk_ppm = 30;
        break;
    case NRF_CLOCK_LFCLKSRC_XTAL_500_PPM:
        m_lfclk_ppm = 500;
        break;
    case NRF_CLOCK_LFCLKSRC_XTAL_50_PPM:
        m_lfclk_ppm = 50;
        break;
    case NRF_CLOCK_LFCLKSRC_XTAL_75_PPM:
        m_lfclk_ppm = 75;
        break;
    default: /* all RC-sources are 250 */
        m_lfclk_ppm = 250;
}

m_is_in_callback = false;
m_framework_initialized = true;

m_timeslot_length = TIMESLOT_SLOT_LENGTH_US;

return NRF_SUCCESS;
}

Since I don't have a low frequency clock source on my board (I could be wrong, it maybe the clock source which came with an nrf52 SoC, but what I'm sure of is that my board, when fully functional, use an external crystal clock source), I'm planning on replacing the switch case section with a fixed value, which may not be a good idea, and alternatively, I can go with the more preferable solution, which is find the "NRF_CLOCK_LFCLKSRCS" 's counterpart in S140, but where?

Can someone please help me?

Edit: rephrased completely the question and the content.

  • Hello Mitch996

    You can find a similar enum for the LF clock source in the nrf_sdm.h (Softdevice manager).

    As for clock source you have a few choices, crystal oscillator with external crystal, internal RC oscillator (normal and ultra-low power mode), synthesized from the HFCLK, and external clock source. See table 17, page 144 of the nRF52840 product specification.

    Best regards

    Jørn Frøysa

  • Yes Yoern, I have found that, but I'm not exactly sure that they are same in nature, since the name doesn't suggest so. One appears to emphasize on source, another, accuracy.

    Can they be used interchangeably?

  • The enum in SDK10 was two-fold. It set the clock source, and if a crystal was used defined the accuracy of it, if the RC was used it set the calibration time.

    In SDK13 it is no longer just an enum, but a struct called nrf_clock_lf_cfg_t where you set the different fields related to LFCLK configuration. If the source is a crystal oscillator you must also set the xtal_accuracy field, which is one of the entries of the XTAL_ACCURACY defines. If the RC oscillator is used the accuracy is always 250ppm (Normal mode) and the calibration time is now set with the rc_ctiv and rc_temp_ctiv fields.

    As your switch-case is concerned with the accuracy of the crystal, it should refer to the above mentioned defines if a crystal is used.

Related