zephyr: ADC DMA fails on FRDM K64F

Describe the bug The adc_dma test, buildable using

west build -p always -b frdm_k64f -T tests/drivers/adc/adc_dma/drivers.adc-dma

fails since commit 6e21ebf2e03259db8ae216314ced9ed84eb3a0cd

It looks like perhaps the NXP specific changes made in this commit broke things.

Test output if helpful

*** Booting Zephyr OS build zephyr-v3.3.0-1492-ga57810dc3b1e ***
Running TESTSUITE adc_dma
===================================================================
START - test_adc_asynchronous_call

    Assertion failed at WEST_TOPDIR/zephyr/tests/drivers/adc/adc_dma/src/test_adc.c:308: test_task_asynchronous_call: (ret not equal to 0)
k_poll failed with error -11
 FAIL - test_adc_asynchronous_call in 1.015 seconds

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 23 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@hakehuang great news! So that means my PR works, and I will remove the draft label.

they want the dma to do multiply samples, not only one sample a time it is critial for their user case, any idea to provide such support as well

And my customer also maybe wants such a feature. I’ve opened a RFC to expand the ADC API to support this. If you could comment there that you need it it might get more interaction and decided sooner. You can find it here: https://github.com/zephyrproject-rtos/zephyr/issues/55783

@heinwessels , I will craete a PR for this fix, btw will you fix the interval_us issue, or you want to fix in as well?

I’ll create a fix for this one. It doesn’t seem to be blocking the CI, so I think it’s fine if it’s two seperate PRs.

Thanks!

Having a look at adc_mcux_adc16.c it seems like the dma_block.block_size is set bigger than it should be, which would explain the (INVALID_ADC_VALUE not equal to sample_value) error.

The potential problematic code is here: https://github.com/zephyrproject-rtos/zephyr/blob/1dce3c3ee2e9db41a0111709c337bafce1a45834/drivers/adc/adc_mcux_adc16.c#L275

When starting the DMA the bytes-to-transfer (called block_size) is set to sequence->buffer_size. And for the test, the buffer_size is set to the actual size of the buffer, which is much larger than it needs to be for this specific test, in this case 24.

IMO buffer_size is the size of the buffer, and should not be used. (only to check that it’s indeed big enough). Instead the block_size should be set to something like sizeof(sample).

In the STM32 driver we set it explictly to the number of channels samples multiplied by the size of each sample, and ignore the actual size of the buffer. https://github.com/zephyrproject-rtos/zephyr/blob/1dce3c3ee2e9db41a0111709c337bafce1a45834/drivers/adc/adc_stm32.c#L319

@hakehuang do you think this might be it?