Skip to content

Commit 577cb8d

Browse files
pi-anladbridge
authored andcommitted
NRF5x: Fix config of LFCLK source / settings.
1 parent 5b47136 commit 577cb8d

File tree

7 files changed

+42
-18
lines changed

7 files changed

+42
-18
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/config/sdk_config.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8557,9 +8557,7 @@
85578557
// <1=> NRF_CLOCK_LF_SRC_XTAL
85588558
// <2=> NRF_CLOCK_LF_SRC_SYNTH
85598559

8560-
#ifndef NRF_SDH_CLOCK_LF_SRC
8561-
#define NRF_SDH_CLOCK_LF_SRC 1
8562-
#endif
8560+
#include "nrf5x_lf_clk_helper.h"
85638561

85648562
// <o> NRF_SDH_CLOCK_LF_RC_CTIV - SoftDevice calibration timer interval.
85658563
#ifndef NRF_SDH_CLOCK_LF_RC_CTIV

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/config/sdk_config.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8556,9 +8556,7 @@
85568556
// <1=> NRF_CLOCK_LF_SRC_XTAL
85578557
// <2=> NRF_CLOCK_LF_SRC_SYNTH
85588558

8559-
#ifndef NRF_SDH_CLOCK_LF_SRC
8560-
#define NRF_SDH_CLOCK_LF_SRC 1
8561-
#endif
8559+
#include "nrf5x_lf_clk_helper.h"
85628560

85638561
// <o> NRF_SDH_CLOCK_LF_RC_CTIV - SoftDevice calibration timer interval.
85648562
#ifndef NRF_SDH_CLOCK_LF_RC_CTIV

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S132_FULL/mbed_lib.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"SOFTDEVICE_PRESENT=1",
55
"S132",
66
"BLE_STACK_SUPPORT_REQD",
7-
"NRF_SDH_CLOCK_LF_SRC=1",
8-
"NRF_SDH_CLOCK_LF_RC_CTIV=0",
9-
"NRF_SDH_CLOCK_LF_RC_TEMP_CTIV=0",
107
"NRF_SDH_CLOCK_LF_XTAL_ACCURACY=7",
118
"NRF_SD_BLE_API_VERSION=5",
129
"NRF_SDH_ENABLED=1",

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S132_OTA/mbed_lib.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"SOFTDEVICE_PRESENT=1",
55
"S132",
66
"BLE_STACK_SUPPORT_REQD",
7-
"NRF_SDH_CLOCK_LF_SRC=1",
8-
"NRF_SDH_CLOCK_LF_RC_CTIV=0",
9-
"NRF_SDH_CLOCK_LF_RC_TEMP_CTIV=0",
107
"NRF_SDH_CLOCK_LF_XTAL_ACCURACY=7",
118
"NRF_SD_BLE_API_VERSION=5",
129
"NRF_SDH_ENABLED=1",

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S140_FULL/mbed_lib.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"SOFTDEVICE_PRESENT=1",
55
"S140",
66
"BLE_STACK_SUPPORT_REQD",
7-
"NRF_SDH_CLOCK_LF_SRC=1",
8-
"NRF_SDH_CLOCK_LF_RC_CTIV=0",
9-
"NRF_SDH_CLOCK_LF_RC_TEMP_CTIV=0",
107
"NRF_SDH_CLOCK_LF_XTAL_ACCURACY=7",
118
"NRF_SD_BLE_API_VERSION=5",
129
"NRF_SDH_ENABLED=1",

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S140_OTA/mbed_lib.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"SOFTDEVICE_PRESENT=1",
55
"S140",
66
"BLE_STACK_SUPPORT_REQD",
7-
"NRF_SDH_CLOCK_LF_SRC=1",
8-
"NRF_SDH_CLOCK_LF_RC_CTIV=0",
9-
"NRF_SDH_CLOCK_LF_RC_TEMP_CTIV=0",
107
"NRF_SDH_CLOCK_LF_XTAL_ACCURACY=7",
118
"NRF_SD_BLE_API_VERSION=5",
129
"NRF_SDH_ENABLED=1",

targets/TARGET_NORDIC/TARGET_NRF5x/nrf5x_lf_clk_helper.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,57 @@
4343
#warning No configuration for LF clock source. Xtal source will be used as a default configuration.
4444
#endif
4545

46+
#define DEFAULT_LFCLK_CONF_ACCURACY NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM
47+
48+
#ifdef NRF52
49+
#define MAX_LFCLK_CONF_RC_CTIV 32
50+
#else
51+
#define MAX_LFCLK_CONF_RC_CTIV 64
52+
#endif
53+
54+
#define MAX_LFCLK_CONF_RC_TEMP_CTIV 33
55+
56+
#define DEFAULT_LFCLK_CONF_RC_CTIV 16 // Check temperature every 16 * 250ms.
57+
#define DEFAULT_LFCLK_CONF_RC_TEMP_CTIV 1 // Only calibrate if temperature has changed.
4658

4759

4860
#define NRF_LF_SRC_XTAL 2
4961
#define NRF_LF_SRC_SYNTH 3
5062
#define NRF_LF_SRC_RC 4
5163

5264
#if MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_SYNTH
65+
#define NRF_SDH_CLOCK_LF_SRC NRF_CLOCK_LF_SRC_SYNTH
66+
#define NRF_SDH_CLOCK_LF_RC_CTIV 0 // Must be 0 if source is not NRF_CLOCK_LF_SRC_RC.
67+
#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 0 // Must be 0 if source is not NRF_CLOCK_LF_SRC_RC.
5368
#define CLOCK_LFCLKSRC_SRC_TO_USE (CLOCK_LFCLKSRC_SRC_Synth)
5469
#elif MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_XTAL
70+
#define NRF_SDH_CLOCK_LF_SRC NRF_CLOCK_LF_SRC_XTAL
71+
#define NRF_SDH_CLOCK_LF_RC_CTIV 0 // Must be 0 if source is not NRF_CLOCK_LF_SRC_RC.
72+
#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 0 // Must be 0 if source is not NRF_CLOCK_LF_SRC_RC.
5573
#define CLOCK_LFCLKSRC_SRC_TO_USE (CLOCK_LFCLKSRC_SRC_Xtal)
5674
#elif MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_RC
75+
#define NRF_SDH_CLOCK_LF_SRC NRF_CLOCK_LF_SRC_RC
76+
77+
#ifdef MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_TIMER_INTERVAL
78+
#define NRF_SDH_CLOCK_LF_RC_CTIV MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_TIMER_INTERVAL
79+
#else
80+
#define NRF_SDH_CLOCK_LF_RC_CTIV DEFAULT_LFCLK_CONF_RC_CTIV
81+
#endif
82+
83+
#ifdef MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_MODE_CONFIG
84+
#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_MODE_CONFIG
85+
#else
86+
#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV DEFAULT_LFCLK_CONF_RC_TEMP_CTIV
87+
#endif
88+
89+
#if (NRF_SDH_CLOCK_LF_RC_CTIV < 1) || (NRF_SDH_CLOCK_LF_RC_CTIV > MAX_LFCLK_CONF_RC_CTIV)
90+
#error Calibration timer interval out of range!
91+
#endif
92+
93+
#if (NRF_SDH_CLOCK_LF_RC_TEMP_CTIV < 0 ) || (NRF_SDH_CLOCK_LF_RC_TEMP_CTIV > 33)
94+
#error Number/mode of LF RC calibration intervals out of range!
95+
#endif
96+
5797
#define CLOCK_LFCLKSRC_SRC_TO_USE (CLOCK_LFCLKSRC_SRC_RC)
5898
#else
5999
#error Bad LFCLK configuration. Declare proper source through mbed configuration.

0 commit comments

Comments
 (0)