From 7f988cbd945dee9614c67ad106fbef59dc407dce Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Mon, 30 Sep 2024 16:05:34 +0200 Subject: [PATCH 1/3] dts: nordic: refactor bindings helper symbols for SAADC Split header files containing symbols denoting SAADC inputs so that only supported inputs can be used for given device. Signed-off-by: Nikodem Kastelik --- drivers/adc/adc_nrfx_saadc.c | 3 ++- dts/arm/nordic/nrf51822.dtsi | 1 + dts/arm/nordic/nrf52805.dtsi | 1 + dts/arm/nordic/nrf52810.dtsi | 1 + dts/arm/nordic/nrf52811.dtsi | 1 + dts/arm/nordic/nrf52832.dtsi | 1 + dts/arm/nordic/nrf52833.dtsi | 1 + dts/arm/nordic/nrf52840.dtsi | 1 + dts/arm/nordic/nrf5340_cpuapp.dtsi | 1 + dts/arm/nordic/nrf5340_cpuappns.dtsi | 1 + dts/arm/nordic/nrf91.dtsi | 1 + dts/arm/nordic/nrf91ns.dtsi | 1 + dts/common/nordic/nrf54h20.dtsi | 1 + dts/common/nordic/nrf54l15.dtsi | 1 + dts/common/nordic/nrf54l20.dtsi | 1 + dts/common/nordic/nrf9280.dtsi | 2 +- dts/common/nordic/nrf_common.dtsi | 1 - include/zephyr/dt-bindings/adc/nrf-adc.h | 11 ----------- .../zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h | 15 +++++++++++++++ include/zephyr/dt-bindings/adc/nrf-saadc-v2.h | 14 ++++++++++++++ include/zephyr/dt-bindings/adc/nrf-saadc-v3.h | 14 ++++++++++++++ include/zephyr/dt-bindings/adc/nrf-saadc.h | 19 +++++++++++++++++++ 22 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h create mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc-v2.h create mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc-v3.h create mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc.h diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index 132e8e78c3ed00..ba4d3e8364f373 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -7,7 +7,8 @@ #define ADC_CONTEXT_USES_KERNEL_TIMER #include "adc_context.h" #include -#include +#include +#include #include #define LOG_LEVEL CONFIG_ADC_LOG_LEVEL diff --git a/dts/arm/nordic/nrf51822.dtsi b/dts/arm/nordic/nrf51822.dtsi index 11cc9eff2f9e81..a11677ad93450f 100644 --- a/dts/arm/nordic/nrf51822.dtsi +++ b/dts/arm/nordic/nrf51822.dtsi @@ -2,6 +2,7 @@ #include #include +#include / { chosen { diff --git a/dts/arm/nordic/nrf52805.dtsi b/dts/arm/nordic/nrf52805.dtsi index c8fafe99154b5b..fbf89434690d8f 100644 --- a/dts/arm/nordic/nrf52805.dtsi +++ b/dts/arm/nordic/nrf52805.dtsi @@ -6,6 +6,7 @@ #include #include +#include #include / { diff --git a/dts/arm/nordic/nrf52810.dtsi b/dts/arm/nordic/nrf52810.dtsi index 73aa5a0da0c7a6..a98e392d7f0cd8 100644 --- a/dts/arm/nordic/nrf52810.dtsi +++ b/dts/arm/nordic/nrf52810.dtsi @@ -2,6 +2,7 @@ #include #include +#include #include / { diff --git a/dts/arm/nordic/nrf52811.dtsi b/dts/arm/nordic/nrf52811.dtsi index 8479950d17a56f..f980f165fdc470 100644 --- a/dts/arm/nordic/nrf52811.dtsi +++ b/dts/arm/nordic/nrf52811.dtsi @@ -6,6 +6,7 @@ #include #include +#include #include / { diff --git a/dts/arm/nordic/nrf52832.dtsi b/dts/arm/nordic/nrf52832.dtsi index 30fb92f71aa5f2..4b65dd75048a7b 100644 --- a/dts/arm/nordic/nrf52832.dtsi +++ b/dts/arm/nordic/nrf52832.dtsi @@ -2,6 +2,7 @@ #include #include +#include #include / { diff --git a/dts/arm/nordic/nrf52833.dtsi b/dts/arm/nordic/nrf52833.dtsi index 8ca66986111de3..6e88524cd5a9f2 100644 --- a/dts/arm/nordic/nrf52833.dtsi +++ b/dts/arm/nordic/nrf52833.dtsi @@ -6,6 +6,7 @@ #include #include +#include #include / { diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index 4c52ff127b57f4..af7678eae96225 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -2,6 +2,7 @@ #include #include +#include #include / { diff --git a/dts/arm/nordic/nrf5340_cpuapp.dtsi b/dts/arm/nordic/nrf5340_cpuapp.dtsi index e40f6241d9113c..c02f939a7faf1c 100644 --- a/dts/arm/nordic/nrf5340_cpuapp.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp.dtsi @@ -6,6 +6,7 @@ #include #include +#include / { cpus { diff --git a/dts/arm/nordic/nrf5340_cpuappns.dtsi b/dts/arm/nordic/nrf5340_cpuappns.dtsi index 6df1be54b34848..a65b24ac818943 100644 --- a/dts/arm/nordic/nrf5340_cpuappns.dtsi +++ b/dts/arm/nordic/nrf5340_cpuappns.dtsi @@ -8,6 +8,7 @@ #include #include +#include / { cpus { diff --git a/dts/arm/nordic/nrf91.dtsi b/dts/arm/nordic/nrf91.dtsi index 78502d3f08631a..9a64ed92229486 100644 --- a/dts/arm/nordic/nrf91.dtsi +++ b/dts/arm/nordic/nrf91.dtsi @@ -6,6 +6,7 @@ #include #include +#include / { cpus { diff --git a/dts/arm/nordic/nrf91ns.dtsi b/dts/arm/nordic/nrf91ns.dtsi index 13a82c442e076f..e44bbcde0a4335 100644 --- a/dts/arm/nordic/nrf91ns.dtsi +++ b/dts/arm/nordic/nrf91ns.dtsi @@ -6,6 +6,7 @@ #include #include +#include / { cpus { diff --git a/dts/common/nordic/nrf54h20.dtsi b/dts/common/nordic/nrf54h20.dtsi index de006cd9cf690e..570b5040b6d1cc 100644 --- a/dts/common/nordic/nrf54h20.dtsi +++ b/dts/common/nordic/nrf54h20.dtsi @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff --git a/dts/common/nordic/nrf54l15.dtsi b/dts/common/nordic/nrf54l15.dtsi index ad80b332fba5aa..535b4b05e3e982 100644 --- a/dts/common/nordic/nrf54l15.dtsi +++ b/dts/common/nordic/nrf54l15.dtsi @@ -6,6 +6,7 @@ #include #include +#include #include /delete-node/ &sw_pwm; diff --git a/dts/common/nordic/nrf54l20.dtsi b/dts/common/nordic/nrf54l20.dtsi index ff2a2705279c5e..66790edbc894a1 100644 --- a/dts/common/nordic/nrf54l20.dtsi +++ b/dts/common/nordic/nrf54l20.dtsi @@ -6,6 +6,7 @@ #include #include +#include #include /delete-node/ &sw_pwm; diff --git a/dts/common/nordic/nrf9280.dtsi b/dts/common/nordic/nrf9280.dtsi index 3acd5268e752d8..5ece1c781183af 100644 --- a/dts/common/nordic/nrf9280.dtsi +++ b/dts/common/nordic/nrf9280.dtsi @@ -6,7 +6,7 @@ #include #include - +#include #include #include #include diff --git a/dts/common/nordic/nrf_common.dtsi b/dts/common/nordic/nrf_common.dtsi index cb2df6bcccd959..6293a82ed97605 100644 --- a/dts/common/nordic/nrf_common.dtsi +++ b/dts/common/nordic/nrf_common.dtsi @@ -5,7 +5,6 @@ */ #include -#include #include #include #include diff --git a/include/zephyr/dt-bindings/adc/nrf-adc.h b/include/zephyr/dt-bindings/adc/nrf-adc.h index 1d875b8eb354e7..62d9b7cc33f697 100644 --- a/include/zephyr/dt-bindings/adc/nrf-adc.h +++ b/include/zephyr/dt-bindings/adc/nrf-adc.h @@ -18,15 +18,4 @@ #define NRF_ADC_AIN6 BIT(6) #define NRF_ADC_AIN7 BIT(7) -#define NRF_SAADC_AIN0 1 -#define NRF_SAADC_AIN1 2 -#define NRF_SAADC_AIN2 3 -#define NRF_SAADC_AIN3 4 -#define NRF_SAADC_AIN4 5 -#define NRF_SAADC_AIN5 6 -#define NRF_SAADC_AIN6 7 -#define NRF_SAADC_AIN7 8 -#define NRF_SAADC_VDD 9 -#define NRF_SAADC_VDDHDIV5 13 - #endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_ADC_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h b/include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h new file mode 100644 index 00000000000000..19da4ff6020fbe --- /dev/null +++ b/include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h @@ -0,0 +1,15 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2024 Nordic Semiconductor ASA + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_NRF54L_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_NRF54L_H_ + +#include + +#define NRF_SAADC_AVDD 10 +#define NRF_SAADC_DVDD 11 + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_NRF54L_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc-v2.h b/include/zephyr/dt-bindings/adc/nrf-saadc-v2.h new file mode 100644 index 00000000000000..f5f72bec829ec4 --- /dev/null +++ b/include/zephyr/dt-bindings/adc/nrf-saadc-v2.h @@ -0,0 +1,14 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2024 Nordic Semiconductor ASA + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V2_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V2_H_ + +#include + +#define NRF_SAADC_VDD 9 + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V2_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc-v3.h b/include/zephyr/dt-bindings/adc/nrf-saadc-v3.h new file mode 100644 index 00000000000000..c51bab1a91ec46 --- /dev/null +++ b/include/zephyr/dt-bindings/adc/nrf-saadc-v3.h @@ -0,0 +1,14 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2024 Nordic Semiconductor ASA + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V3_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V3_H_ + +#include + +#define NRF_SAADC_VDDHDIV5 13 + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V3_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc.h b/include/zephyr/dt-bindings/adc/nrf-saadc.h new file mode 100644 index 00000000000000..4a3deb95cff993 --- /dev/null +++ b/include/zephyr/dt-bindings/adc/nrf-saadc.h @@ -0,0 +1,19 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2024 Nordic Semiconductor ASA + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_ + +#define NRF_SAADC_AIN0 1 +#define NRF_SAADC_AIN1 2 +#define NRF_SAADC_AIN2 3 +#define NRF_SAADC_AIN3 4 +#define NRF_SAADC_AIN4 5 +#define NRF_SAADC_AIN5 6 +#define NRF_SAADC_AIN6 7 +#define NRF_SAADC_AIN7 8 + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_ */ From 37292fb8238a88cfe11c6c2bb949953a70e156e8 Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Mon, 30 Sep 2024 16:08:42 +0200 Subject: [PATCH 2/3] drivers: adc: nrf: add support for nrf54l internal SAADC inputs SAADC peripheral for nRF54L Series allows to choose internal voltages as positive inputs. Signed-off-by: Nikodem Kastelik --- drivers/adc/adc_nrfx_saadc.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index ba4d3e8364f373..e4c37a1f736060 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -32,7 +32,7 @@ static const uint8_t saadc_psels[NRF_SAADC_AIN7 + 1] = { [NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), }; #elif defined(CONFIG_SOC_NRF54L15) -static const uint8_t saadc_psels[NRF_SAADC_AIN7 + 1] = { +static const uint32_t saadc_psels[NRF_SAADC_DVDD + 1] = { [NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), [NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), [NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), @@ -41,6 +41,9 @@ static const uint8_t saadc_psels[NRF_SAADC_AIN7 + 1] = { [NRF_SAADC_AIN5] = NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), [NRF_SAADC_AIN6] = NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1), [NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1), + [NRF_SAADC_VDD] = NRF_SAADC_INPUT_VDD, + [NRF_SAADC_AVDD] = NRF_SAADC_INPUT_AVDD, + [NRF_SAADC_DVDD] = NRF_SAADC_INPUT_DVDD, }; #endif @@ -274,13 +277,8 @@ static int adc_nrfx_channel_setup(const struct device *dev, m_data.single_ended_channels |= BIT(channel_cfg->channel_id); } - /* Keep the channel disabled in hardware (set positive input to - * NRF_SAADC_INPUT_DISABLED) until it is selected to be included - * in a sampling sequence. - */ - #if (NRF_SAADC_HAS_AIN_AS_PIN) - if ((channel_cfg->input_positive > NRF_SAADC_AIN7) || + if ((channel_cfg->input_positive >= ARRAY_SIZE(saadc_psels)) || (channel_cfg->input_positive < NRF_SAADC_AIN0)) { return -EINVAL; } @@ -295,17 +293,18 @@ static int adc_nrfx_channel_setup(const struct device *dev, } else { input_negative = NRF_SAADC_INPUT_DISABLED; } - +#endif /* Store the positive input selection in a dedicated array, * to get it later when the channel is selected for a sampling * and to mark the channel as configured (ready to be selected). */ - m_data.positive_inputs[channel_id] = saadc_psels[channel_cfg->input_positive]; -#else m_data.positive_inputs[channel_id] = channel_cfg->input_positive; -#endif nrf_saadc_channel_init(NRF_SAADC, channel_id, &config); + /* Keep the channel disabled in hardware (set positive input to + * NRF_SAADC_INPUT_DISABLED) until it is selected to be included + * in a sampling sequence. + */ nrf_saadc_channel_input_set(NRF_SAADC, channel_id, NRF_SAADC_INPUT_DISABLED, @@ -532,7 +531,12 @@ static int start_read(const struct device *dev, nrf_saadc_channel_pos_input_set( NRF_SAADC, channel_id, - m_data.positive_inputs[channel_id]); +#if NRF_SAADC_HAS_AIN_AS_PIN + saadc_psels[m_data.positive_inputs[channel_id]] +#else + m_data.positive_inputs[channel_id] +#endif + ); ++active_channels; } else { nrf_saadc_burst_set( From a3d5e0ebc9c4b15601c403e0867a39045eff1bfe Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Mon, 30 Sep 2024 16:16:03 +0200 Subject: [PATCH 3/3] samples: drivers: adc: add support for internal nRF54L SAADC inputs SAADC peripheral for nRF54L Series allows to choose internal voltages as positive inputs and samples shall showcase that. Signed-off-by: Nikodem Kastelik --- .../adc_dt/boards/nrf54l15dk_nrf54l15_cpuapp.overlay | 12 +++++++++++- .../boards/nrf54l15dk_nrf54l15_cpuapp.overlay | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/samples/drivers/adc/adc_dt/boards/nrf54l15dk_nrf54l15_cpuapp.overlay b/samples/drivers/adc/adc_dt/boards/nrf54l15dk_nrf54l15_cpuapp.overlay index f185624f9b933f..6273756c993eb6 100644 --- a/samples/drivers/adc/adc_dt/boards/nrf54l15dk_nrf54l15_cpuapp.overlay +++ b/samples/drivers/adc/adc_dt/boards/nrf54l15dk_nrf54l15_cpuapp.overlay @@ -6,7 +6,7 @@ / { zephyr,user { - io-channels = <&adc 0>, <&adc 1>, <&adc 7>; + io-channels = <&adc 0>, <&adc 1>, <&adc 2>, <&adc 7>; }; }; @@ -33,6 +33,16 @@ zephyr,oversampling = <8>; }; + channel@2 { + reg = <2>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; + zephyr,resolution = <12>; + zephyr,oversampling = <8>; + }; + channel@7 { reg = <7>; zephyr,gain = "ADC_GAIN_1"; diff --git a/samples/drivers/adc/adc_sequence/boards/nrf54l15dk_nrf54l15_cpuapp.overlay b/samples/drivers/adc/adc_sequence/boards/nrf54l15dk_nrf54l15_cpuapp.overlay index a0639a405c4050..7fedbe52ad2fc5 100644 --- a/samples/drivers/adc/adc_sequence/boards/nrf54l15dk_nrf54l15_cpuapp.overlay +++ b/samples/drivers/adc/adc_sequence/boards/nrf54l15dk_nrf54l15_cpuapp.overlay @@ -6,7 +6,7 @@ / { zephyr,user { - io-channels = <&adc 0>, <&adc 1>, <&adc 7>; + io-channels = <&adc 0>, <&adc 1>, <&adc 2>, <&adc 7>; }; }; @@ -39,6 +39,16 @@ zephyr,oversampling = <8>; }; + channel@2 { + reg = <2>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* 0.9 V internal */ + zephyr,resolution = <12>; + zephyr,oversampling = <8>; + }; + channel@7 { reg = <7>; zephyr,gain = "ADC_GAIN_1";