Skip to content

drivers: adc: nrfx_saadc: Add support for DMM #90751

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jaz1-nordic
Copy link
Collaborator

Add support for DMM which manages cache and dedicated memory spaces.

Based on #89469, only the last commit is in scope of this PR.

@github-actions github-actions bot added platform: nRF Nordic nRFx area: Samples Samples area: ADC Analog-to-Digital Converter (ADC) labels May 28, 2025
@github-actions github-actions bot requested review from anangl, kartben, kl-cruz and nashif May 28, 2025 15:05
Copy link

github-actions bot commented May 28, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff

All manifest checks OK

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions github-actions bot added manifest manifest-hal_nordic DNM (manifest) This PR should not be merged (controlled by action-manifest) labels May 28, 2025
@jaz1-nordic jaz1-nordic force-pushed the nrfx-7601_saadc_dmm_support branch 4 times, most recently from a622b40 to faa7caf Compare June 4, 2025 13:06
@jaz1-nordic jaz1-nordic force-pushed the nrfx-7601_saadc_dmm_support branch from faa7caf to 43b7d0b Compare June 9, 2025 12:56
@github-actions github-actions bot removed manifest manifest-hal_nordic DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Jun 9, 2025
kl-cruz
kl-cruz previously approved these changes Jun 12, 2025
@jaz1-nordic jaz1-nordic force-pushed the nrfx-7601_saadc_dmm_support branch from 43b7d0b to 6a5a5c3 Compare June 16, 2025 13:36
@github-actions github-actions bot requested a review from hubertmis June 16, 2025 13:37
@jaz1-nordic jaz1-nordic force-pushed the nrfx-7601_saadc_dmm_support branch 2 times, most recently from 8732416 to d519bd8 Compare June 17, 2025 09:44
@jaz1-nordic jaz1-nordic force-pushed the nrfx-7601_saadc_dmm_support branch 2 times, most recently from d2e83b2 to 76b5fc3 Compare June 18, 2025 11:50
@masz-nordic masz-nordic force-pushed the nrfx-7601_saadc_dmm_support branch from 76b5fc3 to 9cb6a97 Compare June 18, 2025 13:35
@masz-nordic masz-nordic requested a review from kl-cruz June 23, 2025 09:48
(void **)&m_data.samples_buffer);
if (error != 0) {
LOG_ERR("DMM buffer allocation failed err=%d", error);
dmm_buffer_in_release(
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to call in_release if allocation with in_prepare failed.

in_release to be called only after successful in_prepare and input buffer filled by peripheral DMA, indicated by hardware event

(void **)&m_data.samples_buffer);
if (error != 0) {
LOG_ERR("DMM buffer allocation failed err=%d", error);
dmm_buffer_in_release(m_data.mem_reg,
Copy link
Collaborator

Choose a reason for hiding this comment

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

not needed - as explained in comment above

if (has_single_ended(&m_data.ctx.sequence)) {
correct_single_ended(&m_data.ctx.sequence);
correct_single_ended(&m_data.ctx.sequence, event->data.done.p_buffer);
Copy link
Collaborator

Choose a reason for hiding this comment

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

correct_single_ended should be called on m_data.user_buffer after dma_buffer_in_release call.

User shall not access buffer contents before dmm_buffer_in_release to make sure data cache is correctly handled. Otherwise there is a risk of modifying cached contents and losing them during dmm_buffer_in_release

uint8_t active_channel_cnt;

#if defined(ADC_BUFFER_IN_RAM)
void *mem_reg;
void *samples_buffer;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think holding this pointer in static control block is redundant. This pointer can be obtained as local variable in adc_context_update_buffer_pointer and start_read . Then this pointer is provided to nrfx via nrfx_saadc_buffer_set which provides it back in IRQ context via event->data.done.p_buffer

Copy link
Collaborator

Choose a reason for hiding this comment

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

comment about potential removal of samples_buffer is still valid: https://github.com/zephyrproject-rtos/zephyr/pull/90751/files#r2161217660

Add support for DMM which manages cache and dedicated memory spaces.

Signed-off-by: Jakub Zymelka <[email protected]>
@masz-nordic masz-nordic force-pushed the nrfx-7601_saadc_dmm_support branch from 9cb6a97 to 7740772 Compare July 3, 2025 08:26
@masz-nordic masz-nordic requested a review from nika-nordic July 3, 2025 08:26
Copy link

sonarqubecloud bot commented Jul 3, 2025

if (has_single_ended(&m_data.ctx.sequence)) {
correct_single_ended(&m_data.ctx.sequence);
correct_single_ended(&m_data.ctx.sequence, m_data.user_buffer);
Copy link
Collaborator

Choose a reason for hiding this comment

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

buffer managed by dmm cannot be accessed before dmm_buffer_in_release - should be moved after dmm_buffer_in_release

uint8_t active_channel_cnt;

#if defined(ADC_BUFFER_IN_RAM)
void *mem_reg;
void *samples_buffer;
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment about potential removal of samples_buffer is still valid: https://github.com/zephyrproject-rtos/zephyr/pull/90751/files#r2161217660

};

static struct driver_data m_data = {
ADC_CONTEXT_INIT_TIMER(m_data, ctx),
ADC_CONTEXT_INIT_LOCK(m_data, ctx),
ADC_CONTEXT_INIT_SYNC(m_data, ctx),
#if defined(ADC_BUFFER_IN_RAM)
.samples_buffer = adc_samples_buffer,
#if defined(CONFIG_HAS_NORDIC_DMM)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this conditional is redundant - DMM_DEV_TO_REG will return NULL if there is no memory-region prop present

LOG_ERR("DMM buffer allocation failed err=%d", error);
adc_context_complete(ctx, -EIO);
}
#if !defined(CONFIG_HAS_NORDIC_DMM)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this is spurious and will cause missing buffer update on H20 in case of sequence composed of several samplings

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.

4 participants