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

drivers: adc: stm32: dma support #52965

Merged
merged 5 commits into from
Mar 20, 2023

Conversation

heinwessels
Copy link
Contributor

@heinwessels heinwessels commented Dec 12, 2022

The STM32 ADC already supports sampling multiple channels in one sequence. This nwo PR allows those channels to be read in one go using the DMA.

Support for multiple channel sampling for the STM32 was originally part of this PR, but split off in #53534.

Currently dependent on #54156 for a final check

Notes:

  • Currently only tested with STM32H743zi. With only this PR only ADC1 is supported. This PR drivers: dma: stm32: bdma support for H7 #53184 enables the bdma which will add support for running ADC3 through DMA as well.
  • This PR is porting ADC DMA support from a Zephyr 2.6 fork, which has been running on many devices for combined hundreds of hours with the MCUs under heavy load.
  • Does not support DMA driven continious sampling, and is considered out-of-scope for this PR because it can already be mimicked with ADC_ACTION_REPEAT. Adding continous sampling will require changes to adc_context, which has an open discussion here: New ADC Interface for Continuous Sampling #48478

@heinwessels heinwessels marked this pull request as draft December 12, 2022 09:43
@zephyrbot zephyrbot added area: ADC Analog-to-Digital Converter (ADC) area: DMA Direct Memory Access platform: STM32 ST Micro STM32 labels Dec 12, 2022
@heinwessels heinwessels changed the title drivers: adc: stm32 dma support drivers: adc: stm32: dma support for multiple channels Dec 13, 2022
@heinwessels heinwessels force-pushed the stm32-adc-dma branch 5 times, most recently from 0d6b094 to 9448087 Compare December 14, 2022 12:57
@heinwessels heinwessels marked this pull request as ready for review December 14, 2022 13:02
@heinwessels heinwessels force-pushed the stm32-adc-dma branch 6 times, most recently from 54a2f83 to a429f48 Compare December 15, 2022 09:05
This test contained NXP specific functions, for example
the counter trigger, which is not required for all ADC DMA implementations.

Also moved NXP specific kconfigs to appropriate board files

Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
@heinwessels
Copy link
Contributor Author

I added an addtional commit to remove CONFIG_TEST_USERSPACE from the adc_dma tests, because I don't think it's compatible with having buffers in memory which is not defined by ZTEST_BMEM. And it doesn't seem required either.

These test uses DMA which sometimes require buffers to be placed
in custom specific section. This is not compatible with ztest
userspace, which requires variables to be placed in a specific
partition.

Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
Adds nucleo_h732zi ADC DMA unit tests with multiple channels.

The STM32 ADC DMA driver requires the buffers to be placed
in a non-cacheable memory region as defined by the DMA.
Therefore this adds configurability to the test to change
the region the buffer is placed in.

Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
Previously the contents of buffers after an ADC DMA read was
simply printed, but not verified with an zassert that the
value was updated.

This commit updates it to be similar to the adc_api test that
fills the buffer initially with a known value, which is then
used to ensure the ADC DMA functioned successfully.

Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
@erwango erwango added the DNM This PR should not be merged (Do Not Merge) label Mar 14, 2023
@erwango
Copy link
Member

erwango commented Mar 14, 2023

DNM until @FRASTM could have a chance to review (probably today)

@erwango erwango removed the DNM This PR should not be merged (Do Not Merge) label Mar 20, 2023
@carlescufi carlescufi merged commit 7e4de93 into zephyrproject-rtos:main Mar 20, 2023
heinwessels added a commit to fancom/zephyr that referenced this pull request Mar 21, 2023
STM32 ADC DMA support added in zephyrproject-rtos#52965 incorrectly assumed
that all ADC devices have a OVR flag. This commit changes
the driver to only account for it if it's found in the
LL drivers.

Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
carlescufi pushed a commit that referenced this pull request Mar 22, 2023
STM32 ADC DMA support added in #52965 incorrectly assumed
that all ADC devices have a OVR flag. This commit changes
the driver to only account for it if it's found in the
LL drivers.

Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
heinwessels added a commit to fancom/zephyr that referenced this pull request Mar 23, 2023
In zephyrproject-rtos#53184 a linker section for SRAM4 was added because it's
required for use with the STM32H7 BDMA. Now in zephyrproject-rtos#52965 support
was added for the ADC DMA which expects a similar linker section
which is non-cachable, but is limited to use SRAM4 to place it's
buffers. This commit gives the user more flexibility to use any
SRAM region to place buffers to use with ADC DMA.

The region SRAM0 isn't supported because it doesn't have the
"zephyr,memory-region" compatibility required to turn it into
a non-cacheable region, meaning it doesn't fit the mentioned
use case.

Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
@heinwessels heinwessels deleted the stm32-adc-dma branch March 27, 2023 09:24
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: DMA Direct Memory Access platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants