stm32l4xx-hal icon indicating copy to clipboard operation
stm32l4xx-hal copied to clipboard

WIP: Fix ADC support for STM32L47x/L48x

Open ejpcmac opened this issue 4 years ago • 4 comments

Rationale

The current ADC implementation does not support STM32L47x and STM43L78x families. On MCUs from these families, you need to set a bit in the GPIOx_ASCR register to connect the pin to the ADC internally. This pull request adds support for these families.

Current issues

This PR does not feature-gate the use of the GPIOx_ASCR register, thus making the fix incompatible with other MCUs. The current feature-gating schema is not adapted for such cases, as stated in #29.

Design questions

To allow pin connection to the ADC, I have added an AnalogPin trait with connect_adc and disconnect_adc functions that I call in the ADC implementation. Do you think it is the way to go, or should I modify the registers directly in the ADC implementation code?

ejpcmac avatar Jan 24 '21 15:01 ejpcmac

How does this PR differ from https://github.com/stm32-rs/stm32l4xx-hal/pull/309?

MathiasKoch avatar Jun 02 '22 07:06 MathiasKoch

Hello @MathiasKoch, it seems we are trying to do the same thing indeed. I had originally opened this PR on top of stm32l4xx-hal 0.2.0, but could not merge at the time because the device-specific features where incompatible.

I needed this again for a project yesterday evening, so I’ve just quicly ported my changes to the latest version. Now, we can feature-gate it appropriately, but there are still some hacks to remove.

I’ll also take a look tonight on the other PR to see how it’s done there.

ejpcmac avatar Jun 02 '22 07:06 ejpcmac

I think the problem is that it is missing a new release of stm32-rs?

MathiasKoch avatar Jun 02 '22 07:06 MathiasKoch

Mmm, not on my side: I’ve been able to get it working yesterday with my code on a STM32L476RG. But indeed if the register is missing for other devices that need this, we’ll need it. I’ll try to build tonight for every variant.

Just looked at the code: the main difference is that in the other PR, the routing of the pin to the ADC is done inside into_analog, and not removed, where in mine it’s done just before the conversion, and de-configured just after the conversion.

I’ll need to check in the Reference Manual why I did it this way, but I assume that if the hardware is designed with this additional option, there is a reason.

ejpcmac avatar Jun 02 '22 07:06 ejpcmac