Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update adc driver to support nRF54L15 #68692

Merged
merged 5 commits into from
May 15, 2024

Conversation

kl-cruz
Copy link
Collaborator

@kl-cruz kl-cruz commented Feb 7, 2024

No description provided.

@kl-cruz kl-cruz requested a review from carlescufi as a code owner February 7, 2024 13:31
@zephyrbot zephyrbot added area: Samples Samples area: ADC Analog-to-Digital Converter (ADC) platform: nRF Nordic nRFx labels Feb 7, 2024
@kl-cruz kl-cruz force-pushed the nrf54l15_saadc_support branch from 7e04c33 to 540cab8 Compare March 1, 2024 15:30
@MaureenHelm
Copy link
Member

Needs to be rebased.

@anangl please take a look

@kl-cruz
Copy link
Collaborator Author

kl-cruz commented Apr 12, 2024

Twister tests issues are not related to this PR. Bug raised: #71437

BUILD_ASSERT((NRF_SAADC_AIN0 == NRF_SAADC_INPUT_AIN0) &&
(NRF_SAADC_AIN1 == NRF_SAADC_INPUT_AIN1) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to change the indentation here.

Comment on lines 29 to 43
(NRF_SAADC_VDDHDIV5 == NRF_SAADC_INPUT_VDDHDIV5) &&
&& (NRF_SAADC_VDDHDIV5 == NRF_SAADC_INPUT_VDDHDIV5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this, I'd rather suggest to use the following below:

#if defined(SAADC_CH_PSELP_PSELP_VDD)
	     (NRF_SAADC_VDD == NRF_SAADC_INPUT_VDD) &&
#endif
	     1,

This way we'll limit the amount of changes.

case ADC_GAIN_1:
config.gain = NRF_SAADC_GAIN1;
break;
case ADC_GAIN_2:
config.gain = NRF_SAADC_GAIN2;
break;
#if defined(NRF_SAADC_GAIN4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined(NRF_SAADC_GAIN4)
#if defined(SAADC_CH_CONFIG_GAIN_Gain4)

@@ -6,7 +6,7 @@

#define ADC_CONTEXT_USES_KERNEL_TIMER
#include "adc_context.h"
#include <hal/nrf_saadc.h>
#include <nrfx_saadc.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is misleading. The nrfx_saadc driver is not used here.

Suggested change
#include <nrfx_saadc.h>
#include <haly/nrfy_saadc.h>

Regarding NRFX_SAADC_SAMPLES_TO_BYTES() macro, see the next comment.

Comment on lines 272 to 283
nrf_saadc_value_t *buffer;

#if (NRF_SAADC_8BIT_SAMPLE_WIDTH == 8)
if (nrfy_saadc_resolution_get(NRF_SAADC) == NRF_SAADC_RESOLUTION_8BIT) {
buffer = (uint8_t *)nrfy_saadc_buffer_pointer_get(NRF_SAADC) +
nrfy_saadc_amount_get(NRF_SAADC);
} else
#endif
{
buffer = (uint16_t *)nrfy_saadc_buffer_pointer_get(NRF_SAADC) +
nrfy_saadc_amount_get(NRF_SAADC);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, I'd suggest to add a function like:

static uint32_t samples_to_bytes(const struct adc_sequence *sequence,
				 uint16_t number_of_samples)
{
	if (NRF_SAADC_8BIT_SAMPLE_WIDTH == 8 && sequence->resolution == 8) {
		return number_of_samples;
	} else {
		return number_of_samples * 2;
	}
}

and use it here:

		nrf_saadc_value_t *buffer =
			(uint8_t *)nrf_saadc_buffer_pointer_get(NRF_SAADC) +
			samples_to_bytes(&ctx->sequence,
					 nrfy_saadc_amount_get(NRF_SAADC));

and in check_buffer_size():

	needed_buffer_size = samples_to_bytes(sequence, active_channels);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It makes the code more readable

/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2023 Nordic Semiconductor ASA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (c) 2023 Nordic Semiconductor ASA
* Copyright (c) 2024 Nordic Semiconductor ASA

/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2023 Karol Lasończyk <[email protected]>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (c) 2023 Karol Lasończyk <[email protected]>
* Copyright (c) 2024 Nordic Semiconductor ASA

: 1)));

tacq = (nrf_saadc_acqtime_t)(acq_time / MINIMUM_ACQ_TIME_IN_NS) - 1;
if ((tacq > SAADC_CH_CONFIG_TACQ_Max) || (acq_time < MINIMUM_ACQ_TIME_IN_NS)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ((tacq > SAADC_CH_CONFIG_TACQ_Max) || (acq_time < MINIMUM_ACQ_TIME_IN_NS)) {
if ((tacq > NRF_SAADC_ACQTIME_MAX) || (acq_time < MINIMUM_ACQ_TIME_IN_NS)) {

@MaureenHelm
Copy link
Member

Need to rebase and resolve conflicts

gmarull pushed a commit to gmarull/sdk-zephyr that referenced this pull request Apr 30, 2024
Simple enabling adc node.

Upstream PR: zephyrproject-rtos/zephyr#68692

Applied as noup because it can't be applied cleanly.

Signed-off-by: Karol Lasończyk <[email protected]>
(cherry picked from commit 88adda3b14f726645c0a3ebac6d6fab571144f11)
gmarull pushed a commit to gmarull/sdk-zephyr that referenced this pull request Apr 30, 2024
Simple enabling adc node.

Upstream PR: zephyrproject-rtos/zephyr#68692

Applied as noup because it can't be applied cleanly.

Signed-off-by: Karol Lasończyk <[email protected]>
(cherry picked from commit 88adda3b14f726645c0a3ebac6d6fab571144f11)
@kl-cruz kl-cruz dismissed stale reviews from nika-nordic and anangl via b2b09d5 May 8, 2024 06:34
@kl-cruz kl-cruz force-pushed the nrf54l15_saadc_support branch from f42e1eb to b2b09d5 Compare May 8, 2024 06:34
@@ -147,4 +147,7 @@
t-enter-dpd = <10000>;
t-exit-dpd = <35000>;
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
};

@@ -147,4 +147,7 @@
t-enter-dpd = <10000>;
t-exit-dpd = <35000>;
};

&adc {
status = "okay";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to enable adc at board level?
Can't this be moved to board overlay for individual tests/samples?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling it on board level is consistent with other Nordic DKs

rlubos pushed a commit to nrfconnect/sdk-zephyr that referenced this pull request May 8, 2024
kl-cruz added 2 commits May 10, 2024 09:45
Expands driver to cover nRF54L15 features like AIN as GPIO configuration,
new reference voltage, different set of supported gain options.

Signed-off-by: Karol Lasończyk <[email protected]>
Simple enabling adc node.

Signed-off-by: Karol Lasończyk <[email protected]>
@kl-cruz kl-cruz force-pushed the nrf54l15_saadc_support branch from b2b09d5 to d944384 Compare May 10, 2024 07:56
kl-cruz added 3 commits May 10, 2024 10:54
New file with ADC configuration for nRF54L15 PDK.

Signed-off-by: Karol Lasończyk <[email protected]>
New file to make test works.

Signed-off-by: Karol Lasończyk <[email protected]>
Expand supported list.

Signed-off-by: Karol Lasończyk <[email protected]>
@kl-cruz kl-cruz force-pushed the nrf54l15_saadc_support branch from d944384 to 3441974 Compare May 10, 2024 08:54
57300 pushed a commit to 57300/sdk-zephyr that referenced this pull request May 14, 2024
Copy link
Collaborator

@masz-nordic masz-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some additions in nrfx will be needed to tidy up in the future.

Comment on lines +21 to +30
static const uint8_t saadc_psels[NRF_SAADC_AIN7 + 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),
[NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1),
[NRF_SAADC_AIN4] = NRF_PIN_PORT_TO_PIN_NUMBER(11U, 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),
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to find a better solution for AIN lookup in the future, this does not scale well.

Comment on lines +107 to +121
nrf_saadc_acqtime_t tacq = 0;
uint16_t acq_time =
(acquisition_time == ADC_ACQ_TIME_DEFAULT
? DEFAULT_ACQ_TIME_IN_NS
: (ADC_ACQ_TIME_VALUE(acquisition_time) *
(ADC_ACQ_TIME_UNIT(acquisition_time) == ADC_ACQ_TIME_MICROSECONDS
? 1000
: 1)));

tacq = (nrf_saadc_acqtime_t)(acq_time / MINIMUM_ACQ_TIME_IN_NS) - 1;
if ((tacq > NRF_SAADC_ACQTIME_MAX) || (acq_time < MINIMUM_ACQ_TIME_IN_NS)) {
result = -EINVAL;
} else {
*p_tacq_val = tacq;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we need a function for that in HAL.


if (channel_id >= SAADC_CH_NUM) {
return -EINVAL;
}

switch (channel_cfg->gain) {
#if defined(SAADC_CH_CONFIG_GAIN_Gain1_6)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MDK use should be avoided, but I don't see a real alternative for now.

@fabiobaltieri fabiobaltieri merged commit 394e097 into zephyrproject-rtos:main May 15, 2024
22 checks passed
@kl-cruz kl-cruz deleted the nrf54l15_saadc_support branch June 4, 2024 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ADC Analog-to-Digital Converter (ADC) area: Samples Samples platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants