Skip to content

STM32 ADC: Support differential mode #91141

@mrodgers-witekio

Description

@mrodgers-witekio

Is your feature request related to a problem? Please describe.

Differential mode is currently not supported in the adc_stm32.c driver. In adc_stm32_channel_setup:

	if (channel_cfg->differential) {
		LOG_ERR("Differential channels are not supported");
		return -EINVAL;
	}

Describe the solution you'd like

Support for differential mode specified in the usual devicetree bindings.

I had a quick look at what it would take to implement this, and there seems to be some added complication around differential mode (at least in the F3 part I'm looking at the reference manual for, not sure if the same applies to all STM32 series):

  1. Differential/single ended mode selection can only be performed while the ADC is disabled
  2. Calibration is performed separately for differential/single ended modes, so the driver needs to know during initialisation if any channels are using differential mode so that it can perform the correct calibration routine(s).

I think the simplest way to implement this would be to set the channel mode to differential during initialisation for any channels which have the zephyr,differential property in the devicetree. Then the driver knows during initialisation whether it should perform a differential/single ended calibration (or both). If the user calls channel_setup with a different single-ended/differential setting to the one configured during initialisation, it could just return an error like it does for differential mode currently.

Even better would be if it's possible to dynamically change between differential and single ended mode for a channel, but I don't really have a need for this and I'm not sure whether the hardware would support this well (ie. is it possible to disable the ADC, change the channel config and re-enable it without performing a full re-initialisation?)

I'm happy to give this a try and open a PR, if the proposed simpler option above sounds OK. If anyone knows whether the same constraints apply to differential mode on all STM32 series (that support differential mode) without me having to check all of the reference manuals, that would also be much appreciated!

Describe alternatives you've considered

see above

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions