Skip to content

Commit 9cdc396

Browse files
ananglmbolivar-nordic
authored andcommitted
[nrf fromtree] soc: nrf53: Add options for HFXO/LFXO load capacitance
Add Kconfig options that allow configuration of optional internal load capacitors for the high-frequency (HFXO) and low-frequency (LFXO) crystal oscillators in nRF5340. Default settings used for the new options are those that have been in effect so far, i.e. external load capacitors for HFXO and 6 pF internal capacitance for LFXO. This commit also adds missing SOC_ENABLE_LFXO option dependency on !TRUSTED_EXECUTION_NONSECURE. Upstream PR: zephyrproject-rtos/zephyr#35874 Signed-off-by: Andrzej Głąbek <[email protected]> (cherry picked from commit e45fa6b)
1 parent 0c1f3a4 commit 9cdc396

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

soc/arm/nordic_nrf/nrf53/Kconfig.soc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ config SOC_DCDC_NRF53X_HV
132132
help
133133
Enable nRF53 series System on Chip High Voltage DC/DC converter.
134134

135+
if !TRUSTED_EXECUTION_NONSECURE
136+
135137
config SOC_ENABLE_LFXO
136138
bool "Enable LFXO"
137139
default y
@@ -142,6 +144,49 @@ config SOC_ENABLE_LFXO
142144
to use the LFXO. Otherwise, XL1 and XL2 pins will behave as regular
143145
GPIOs.
144146

147+
choice SOC_LFXO_LOAD_CAPACITANCE
148+
prompt "LFXO load capacitance"
149+
depends on SOC_ENABLE_LFXO
150+
default SOC_LFXO_CAP_INT_6PF
151+
152+
config SOC_LFXO_CAP_EXTERNAL
153+
bool "Use external load capacitors"
154+
155+
config SOC_LFXO_CAP_INT_6PF
156+
bool "6 pF internal load capacitance"
157+
158+
config SOC_LFXO_CAP_INT_7PF
159+
bool "7 pF internal load capacitance"
160+
161+
config SOC_LFXO_CAP_INT_9PF
162+
bool "9 pF internal load capacitance"
163+
164+
endchoice
165+
166+
choice SOC_HFXO_LOAD_CAPACITANCE
167+
prompt "HFXO load capacitance"
168+
default SOC_HFXO_CAP_EXTERNAL
169+
170+
config SOC_HFXO_CAP_EXTERNAL
171+
bool "Use external load capacitors"
172+
173+
config SOC_HFXO_CAP_INTERNAL
174+
bool "Use internal load capacitors"
175+
176+
endchoice
177+
178+
config SOC_HFXO_CAP_INT_VALUE_X2
179+
int "Doubled value of HFXO internal load capacitors (in pF)"
180+
depends on SOC_HFXO_CAP_INTERNAL
181+
range 14 40
182+
help
183+
Internal capacitors ranging from 7.0 pF to 20.0 pF in 0.5 pF steps
184+
can be enabled on pins XC1 and XC2. This option specifies doubled
185+
capacitance value for the two capacitors. Set it to 14 to get 7.0 pF
186+
for each capacitor, 15 to get 7.5 pF, and so on.
187+
188+
endif # !TRUSTED_EXECUTION_NONSECURE
189+
145190
endif # SOC_NRF5340_CPUAPP
146191

147192

soc/arm/nordic_nrf/nrf53/soc.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,42 @@ static int nordicsemi_nrf53_init(const struct device *arg)
6464
#endif
6565

6666
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && \
67-
!defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) && \
68-
defined(CONFIG_SOC_ENABLE_LFXO)
67+
!defined(CONFIG_TRUSTED_EXECUTION_NONSECURE)
68+
#if defined(CONFIG_SOC_ENABLE_LFXO)
6969
nrf_oscillators_lfxo_cap_set(NRF_OSCILLATORS,
70-
NRF_OSCILLATORS_LFXO_CAP_6PF);
70+
IS_ENABLED(CONFIG_SOC_LFXO_CAP_INT_6PF) ?
71+
NRF_OSCILLATORS_LFXO_CAP_6PF :
72+
IS_ENABLED(CONFIG_SOC_LFXO_CAP_INT_7PF) ?
73+
NRF_OSCILLATORS_LFXO_CAP_7PF :
74+
IS_ENABLED(CONFIG_SOC_LFXO_CAP_INT_9PF) ?
75+
NRF_OSCILLATORS_LFXO_CAP_9PF :
76+
NRF_OSCILLATORS_LFXO_CAP_EXTERNAL);
77+
/* This can only be done from secure code. */
7178
nrf_gpio_pin_mcu_select(PIN_XL1, NRF_GPIO_PIN_MCUSEL_PERIPHERAL);
7279
nrf_gpio_pin_mcu_select(PIN_XL2, NRF_GPIO_PIN_MCUSEL_PERIPHERAL);
7380
#endif
81+
#if defined(CONFIG_SOC_HFXO_CAP_INTERNAL)
82+
/* This register is only accessible from secure code. */
83+
uint32_t xosc32mtrim = NRF_FICR->XOSC32MTRIM;
84+
/* As specified in the nRF5340 PS:
85+
* CAPVALUE = (((FICR->XOSC32MTRIM.SLOPE+56)*(CAPACITANCE*2-14))
86+
* +((FICR->XOSC32MTRIM.OFFSET-8)<<4)+32)>>6;
87+
* where CAPACITANCE is the desired capacitor value in pF, holding any
88+
* value between 7.0 pF and 20.0 pF in 0.5 pF steps.
89+
*/
90+
uint32_t slope = (xosc32mtrim & FICR_XOSC32MTRIM_SLOPE_Msk)
91+
>> FICR_XOSC32MTRIM_SLOPE_Pos;
92+
uint32_t offset = (xosc32mtrim & FICR_XOSC32MTRIM_OFFSET_Msk)
93+
>> FICR_XOSC32MTRIM_OFFSET_Pos;
94+
uint32_t capvalue =
95+
((slope + 56) * (CONFIG_SOC_HFXO_CAP_INT_VALUE_X2 - 14)
96+
+ ((offset - 8) << 4) + 32) >> 6;
97+
98+
nrf_oscillators_hfxo_cap_set(NRF_OSCILLATORS, true, capvalue);
99+
#else
100+
nrf_oscillators_hfxo_cap_set(NRF_OSCILLATORS, false, 0);
101+
#endif
102+
#endif /* defined(CONFIG_SOC_NRF5340_CPUAPP) && ... */
74103

75104
#if defined(CONFIG_SOC_DCDC_NRF53X_APP)
76105
nrf_regulators_dcdcen_set(NRF_REGULATORS, true);

0 commit comments

Comments
 (0)