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

ADC STM32: Various fixes and enhancements #82955

Merged

Conversation

gautierg-st
Copy link
Contributor

@gautierg-st gautierg-st commented Dec 13, 2024

This PR contains various fixes and enhancements for the STM32 ADC driver:

  • Add a log message when an overrun error occurs (with indications how to prevent the error)
  • Simplify the oversampling function by adding a new property in device tree
  • Simplify the DMA enable function and add support for DMA for STM32H7A/H7B and F1 series

Fixes #79909

@zephyrbot zephyrbot added area: ADC Analog-to-Digital Converter (ADC) platform: STM32 ST Micro STM32 labels Dec 13, 2024
@gautierg-st gautierg-st force-pushed the adc_overrun_and_other_fixes branch from 79f099b to 59f8450 Compare December 13, 2024 10:42
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

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

A nice improvement. Few open comments, but otherwise LGTM

if (LL_ADC_IsActiveFlag_OVR(adc)) {
LL_ADC_ClearFlag_OVR(adc);
LOG_ERR("ADC overrun error occurred. Reduce clock source frequency, "
"increase prescaler value, or increase sampling times.");
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick:

Suggested change
"increase prescaler value, or increase sampling times.");
"increase prescaler value or increase sampling times.");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

drivers/adc/adc_stm32.c Show resolved Hide resolved
dts/bindings/adc/st,stm32-adc.yaml Outdated Show resolved Hide resolved
drivers/adc/adc_stm32.c Show resolved Hide resolved
Displays an error log message when an ADC overrun occurs.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
STM32F3 and H7 have multiple ADC versions difficult to differentiate.
Use clearer macros to make code more readable.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
@gautierg-st gautierg-st force-pushed the adc_overrun_and_other_fixes branch from 59f8450 to a21a2af Compare December 13, 2024 14:28
erwango
erwango previously approved these changes Dec 13, 2024
drivers/adc/adc_stm32.c Outdated Show resolved Hide resolved
include/zephyr/dt-bindings/adc/stm32_adc.h Outdated Show resolved Hide resolved
On STM32 ADC, there are currently two types of oversamplers (if present),
one with 8 available oversampling values, the other with 1024.
To simplify the driver, add the oversampler as a dts property.
Also add defines to avoid magic values in the dtsi.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Add ADC oversampler type to all ADC of all series.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Use the new oversampler property to simplify the management of the
ADC oversampling.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Remove specific cases for H7 and U5: group them together and only call a
single function. ADC3 of H72x/H73x and ADC4 of U5 are different from other
ADC of their series, and have dedicated functions in the LL for enabling
DMA, but they're doing the exact same operation as
LL_ADC_REG_SetDataTransferMode.

Incidentally, this change allows H7A/H7B to use the DMA (it seems to have
been missed before).

Last, this change enables the DMA support for F1x ADC.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
@gautierg-st
Copy link
Contributor Author

Also applied string enum to st,adc-clock-source property that I missed earlier

erwango
erwango previously approved these changes Dec 18, 2024
Adds an ADC DMA test for Nucleo F103RB board now that support for it is
added in the ADC driver.
Reading multiple channels in F1 is only possible with the DMA, hence the
necessity to have a dedicated twister test for it.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
STM32 sequencer property and clock source were defined using
arbitrary numbers. Use string instead.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
In all STM32 dtsi and board dts, update the st,adc-sequencer and the
st,adc-clock-source properties so they are strings.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>

fu dts: arm: st: use string instead of enum
…erty

Now that st,adc-sequencer and st,adc_clock-source use a string, update the
ADC driver.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>

fu drv adc update driver with string
Now that clock source and sequencer are defined with strings in device
tree, move the old defines directly in the driver

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Listify the content of the tables used for sequencer and oversampling.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
config->base is already defined as ADC_TypeDef so no there is no need to
cast it as such. Remove all occurrences throughout the file.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Copy link
Collaborator

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

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

Nice work!

@kartben kartben merged commit 2460e89 into zephyrproject-rtos:main Dec 18, 2024
24 checks passed
@benediktibk
Copy link
Collaborator

Could it be that there is an entry in the release notes/migration guide missing? Because changing the type of the properties to string is somewhat a breaking change. I just stumbled upon this. No big deal, but might be noteworthy in the documentation.

@kartben
Copy link
Collaborator

kartben commented Dec 23, 2024

Could it be that there is an entry in the release notes/migration guide missing? Because changing the type of the properties to string is somewhat a breaking change. I just stumbled upon this. No big deal, but might be noteworthy in the documentation.

+1. @gautierg-st please follow up on adding this to the migration guide.

@gautierg-st
Copy link
Contributor Author

Could it be that there is an entry in the release notes/migration guide missing? Because changing the type of the properties to string is somewhat a breaking change. I just stumbled upon this. No big deal, but might be noteworthy in the documentation.

+1. @gautierg-st please follow up on adding this to the migration guide.

Done here #85643

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) platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stm32h7: adc: sequence of more than 8 channels does not work
7 participants