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

Enhance the ADC functionality on the STM32 devices to all available ADC channels #32288

Closed
zpm1066 opened this issue Feb 14, 2021 · 6 comments
Closed
Assignees
Labels
area: ADC Analog-to-Digital Converter (ADC) Enhancement Changes/Updates/Additions to existing features platform: STM32 ST Micro STM32

Comments

@zpm1066
Copy link

zpm1066 commented Feb 14, 2021

Is your enhancement proposal related to a problem? Please describe.
Recently I’ve been testing out ADC & PWM functionality on the nRF52840 & STM32 (blackpill_f411ce) boards under Zephyr, as part of an effort to move projects over from Arduino framework to Zephyr.

I’m finding that the current ADC support in Zephyr for the STM32 boards is quite limited. From my debug sessions, it appears that only one or two ADC channels are currently supported on the STM32. On the blackpill_f411ce (stm32f411ce), only one ADC channel on pin PA1 is currently supported.

Zephyr does support multiple ADC channels on other boards, for example, with the Particle Xenon (nRF52840), I’m able to access all 6 ADC channels without any issues.

As the STM32 devices are very popular and used extensively, it would be very useful to have full channel support.

Describe the solution you'd like
Extend ADC channel support on the STM32 (blackpill_f411ce and other) from the current one or two channels to all the available ADC channels.

Describe alternatives you've considered
The current temporary fallback has been to use the Arduino Framework with the STM32 blackpill_f411ce to access the available ADC channels. I certainly would prefer to use Zephyr.

Additional context
Add any other context or graphics (drag-and-drop an image) about the feature request here.

@zpm1066 zpm1066 added the Enhancement Changes/Updates/Additions to existing features label Feb 14, 2021
@erwango erwango added platform: STM32 ST Micro STM32 area: ADC Analog-to-Digital Converter (ADC) labels Feb 15, 2021
@zpm1066
Copy link
Author

zpm1066 commented Feb 18, 2021

From my debugging on the blackpill_f411ce (stm32f411ce), the STM32 code states that PWM works only for 1 or 2 channels.
Sounds like a work in progress. It's surprising since PWM would be used often by most folks and the STM32 is a very popular MCU.

Under the Arduino Framework, all ADC channels are accessible on the blackpill_f411ce, and also there is no channel usage limitation on nRF52840 under Zephyr.

@StefJar
Copy link

StefJar commented Apr 21, 2021

hey guys
I needed to get some work around done
this is a work around for the internal channels
#34458

problem with the current stm32 adc drv:

  • internal channels are overlapping with the external ones
  • example: channel 17 at stm32f412 = external or VRef

Idea:

  • there is no adc channel muxer yet but we might need some
  • we don't like to rewrite the whole driver
  • we change the dts binding, so the user can mux the channel
  • the driver takes the #define generated by the dts compiler and do the channel muxing

example:

soc {
	pinctrl: pin-controller@40020000 {			
		// adc
		// PC1 ADC_VBAT -> ADC1_IN11
		// PC3 ADC_ICHARG -> ADC1_IN13
		adc_VBat: adc_VBat {
			pinmux = <STM32_PINMUX('C', 1, ANALOG)>;
		};
		adc_ICharg: adc_ICharg {
			pinmux = <STM32_PINMUX('C', 3, ANALOG)>;
		};
	};
};
zephyr,user {
	// PC1 ADC_VBAT -> ADC1_IN11
	// PC3 ADC_ICHARG -> ADC1_IN13
	// VREF -> adc channel 17
	io-channels = <&adc1 11>, <&adc1 13>, <&adc1 17>;
};

// adc
&adc1 {
	pinctrl-0 = <&adc_VBat &adc_ICharg>;
	ch17-internal;
	status = "okay";
};

I am sure that this principle can be easily extend over different stm32 MCUs.

@erwango erwango added this to the v2.7.0 milestone Jun 7, 2021
@cfriedt cfriedt added priority: low Low impact/importance bug and removed priority: low Low impact/importance bug labels Jul 12, 2021
@mcscholtz
Copy link
Contributor

mcscholtz commented Aug 10, 2021

This is critical for my project so I added the ability to use a shared IRQ on the stm32f4x, so that all 3 channels can be used.

Please see the PR here: #37585

This is my first contribution so feedback would be great. Thanks!

Edit: My PR is for using multiple ADC devices (e.g adc1, adc2, adc3) with 1 shared interrupt for all the adc's. But I will be looking into using multiple channels on a single adc once this PR is accepted.

@mtahirbutt
Copy link
Contributor

sir is there any progress of using multiple channels with adc_sequence struct. I am trying to use two channels but get -1 in the output result. I am using stm32l475 MCU with disco_l475 board.

@erwango
Copy link
Member

erwango commented Jun 29, 2022

This is critical for my project so I added the ability to use a shared IRQ on the stm32f4x, so that all 3 channels can be used.
Please see the PR here: #37585

This was closed by #41497

@erwango
Copy link
Member

erwango commented Dec 14, 2022

Closing in favor of #39640.
For people interested in ADC+DMA:
#52965
Don't hesitate to test and provide feedback in directly in PR

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) Enhancement Changes/Updates/Additions to existing features platform: STM32 ST Micro STM32
Projects
None yet
Development

No branches or pull requests

7 participants