Skip to content

Commit

Permalink
Merge pull request #7652 from andrewleech/nrf5x_config_lfclk
Browse files Browse the repository at this point in the history
NRF5x: Fix config of LFCLK source / settings.
  • Loading branch information
0xc0170 committed Aug 24, 2018
2 parents 781573a + 6293572 commit 2d33053
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8557,9 +8557,7 @@
// <1=> NRF_CLOCK_LF_SRC_XTAL
// <2=> NRF_CLOCK_LF_SRC_SYNTH

#ifndef NRF_SDH_CLOCK_LF_SRC
#define NRF_SDH_CLOCK_LF_SRC 1
#endif
#include "nrf5x_lf_clk_helper.h"

// <o> NRF_SDH_CLOCK_LF_RC_CTIV - SoftDevice calibration timer interval.
#ifndef NRF_SDH_CLOCK_LF_RC_CTIV
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8686,9 +8686,7 @@
// <1=> NRF_CLOCK_LF_SRC_XTAL
// <2=> NRF_CLOCK_LF_SRC_SYNTH

#ifndef NRF_SDH_CLOCK_LF_SRC
#define NRF_SDH_CLOCK_LF_SRC 1
#endif
#include "nrf5x_lf_clk_helper.h"

// <o> NRF_SDH_CLOCK_LF_RC_CTIV - SoftDevice calibration timer interval.
#ifndef NRF_SDH_CLOCK_LF_RC_CTIV
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"SOFTDEVICE_PRESENT=1",
"S132",
"BLE_STACK_SUPPORT_REQD",
"NRF_SDH_CLOCK_LF_SRC=1",
"NRF_SDH_CLOCK_LF_RC_CTIV=0",
"NRF_SDH_CLOCK_LF_RC_TEMP_CTIV=0",
"NRF_SDH_CLOCK_LF_XTAL_ACCURACY=7",
"NRF_SD_BLE_API_VERSION=5",
"NRF_SDH_ENABLED=1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"SOFTDEVICE_PRESENT=1",
"S132",
"BLE_STACK_SUPPORT_REQD",
"NRF_SDH_CLOCK_LF_SRC=1",
"NRF_SDH_CLOCK_LF_RC_CTIV=0",
"NRF_SDH_CLOCK_LF_RC_TEMP_CTIV=0",
"NRF_SDH_CLOCK_LF_XTAL_ACCURACY=7",
"NRF_SD_BLE_API_VERSION=5",
"NRF_SDH_ENABLED=1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"SOFTDEVICE_PRESENT=1",
"S140",
"BLE_STACK_SUPPORT_REQD",
"NRF_SDH_CLOCK_LF_SRC=1",
"NRF_SDH_CLOCK_LF_RC_CTIV=0",
"NRF_SDH_CLOCK_LF_RC_TEMP_CTIV=0",
"NRF_SDH_CLOCK_LF_XTAL_ACCURACY=7",
"NRF_SD_BLE_API_VERSION=5",
"NRF_SDH_ENABLED=1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"SOFTDEVICE_PRESENT=1",
"S140",
"BLE_STACK_SUPPORT_REQD",
"NRF_SDH_CLOCK_LF_SRC=1",
"NRF_SDH_CLOCK_LF_RC_CTIV=0",
"NRF_SDH_CLOCK_LF_RC_TEMP_CTIV=0",
"NRF_SDH_CLOCK_LF_XTAL_ACCURACY=7",
"NRF_SD_BLE_API_VERSION=5",
"NRF_SDH_ENABLED=1",
Expand Down
40 changes: 40 additions & 0 deletions targets/TARGET_NORDIC/TARGET_NRF5x/nrf5x_lf_clk_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,57 @@
#warning No configuration for LF clock source. Xtal source will be used as a default configuration.
#endif

#define DEFAULT_LFCLK_CONF_ACCURACY NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM

#ifdef NRF52
#define MAX_LFCLK_CONF_RC_CTIV 32
#else
#define MAX_LFCLK_CONF_RC_CTIV 64
#endif

#define MAX_LFCLK_CONF_RC_TEMP_CTIV 33

#define DEFAULT_LFCLK_CONF_RC_CTIV 16 // Check temperature every 16 * 250ms.
#define DEFAULT_LFCLK_CONF_RC_TEMP_CTIV 1 // Only calibrate if temperature has changed.


#define NRF_LF_SRC_XTAL 2
#define NRF_LF_SRC_SYNTH 3
#define NRF_LF_SRC_RC 4

#if MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_SYNTH
#define NRF_SDH_CLOCK_LF_SRC NRF_CLOCK_LF_SRC_SYNTH
#define NRF_SDH_CLOCK_LF_RC_CTIV 0 // Must be 0 if source is not NRF_CLOCK_LF_SRC_RC.
#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 0 // Must be 0 if source is not NRF_CLOCK_LF_SRC_RC.
#define CLOCK_LFCLKSRC_SRC_TO_USE (CLOCK_LFCLKSRC_SRC_Synth)
#elif MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_XTAL
#define NRF_SDH_CLOCK_LF_SRC NRF_CLOCK_LF_SRC_XTAL
#define NRF_SDH_CLOCK_LF_RC_CTIV 0 // Must be 0 if source is not NRF_CLOCK_LF_SRC_RC.
#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 0 // Must be 0 if source is not NRF_CLOCK_LF_SRC_RC.
#define CLOCK_LFCLKSRC_SRC_TO_USE (CLOCK_LFCLKSRC_SRC_Xtal)
#elif MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_RC
#define NRF_SDH_CLOCK_LF_SRC NRF_CLOCK_LF_SRC_RC

#ifdef MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_TIMER_INTERVAL
#define NRF_SDH_CLOCK_LF_RC_CTIV MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_TIMER_INTERVAL
#else
#define NRF_SDH_CLOCK_LF_RC_CTIV DEFAULT_LFCLK_CONF_RC_CTIV
#endif

#ifdef MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_MODE_CONFIG
#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_MODE_CONFIG
#else
#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV DEFAULT_LFCLK_CONF_RC_TEMP_CTIV
#endif

#if (NRF_SDH_CLOCK_LF_RC_CTIV < 1) || (NRF_SDH_CLOCK_LF_RC_CTIV > MAX_LFCLK_CONF_RC_CTIV)
#error Calibration timer interval out of range!
#endif

#if (NRF_SDH_CLOCK_LF_RC_TEMP_CTIV < 0 ) || (NRF_SDH_CLOCK_LF_RC_TEMP_CTIV > 33)
#error Number/mode of LF RC calibration intervals out of range!
#endif

#define CLOCK_LFCLKSRC_SRC_TO_USE (CLOCK_LFCLKSRC_SRC_RC)
#else
#error Bad LFCLK configuration. Declare proper source through mbed configuration.
Expand Down

0 comments on commit 2d33053

Please sign in to comment.