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

WIP: Fix ADC support for STM32L47x/L48x #191

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ejpcmac
Copy link

@ejpcmac ejpcmac commented Jan 24, 2021

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?

@MathiasKoch
Copy link
Collaborator

How does this PR differ from #309?

@ejpcmac
Copy link
Author

ejpcmac commented Jun 2, 2022

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.

@MathiasKoch
Copy link
Collaborator

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

@ejpcmac
Copy link
Author

ejpcmac commented Jun 2, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants