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

[stm32f4] [adc] feat: Add async single adc readings #3742

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Christopher-06
Copy link

In contrast to the ADC implementations of other series, the STM32F4 series does not yet have an API definition for the asynchronous reading of a single channel. Instead, only the read_blocking() method was available.

In this PR, the API was extended to include an asynchronous read() method. Internal refactorings were also carried out in order to standardize the logic for setting registers and avoid redundant code. The implementation is based on the ADC implementations of other series in embassy_stm32/adc/.

The new method allows asynchronous single conversions to be performed and the ADC to be operated asynchronously in discontinuous mode. This is particularly useful for sporadic queries of an ADC channel, as the read() approach is simpler and more efficient than using a ring buffer DMA transfer.

In addition, the ADC example for the STM32F4 series has been updated. It now demonstrates the use of the read_blocking() method at the beginning and shows the asynchronous use with the new read() method in the infinite loop. This makes it easier to understand the interface and its practical use.

embassy-stm32/src/adc/v2.rs Outdated Show resolved Hide resolved
@Christopher-06
Copy link
Author

My mistake - I have now added the waker and activated/deactivated the interrupt accordingly. In my tests with a fast clock and the STM32F446, the single conversion was probably so fast that the ADC reading was already available at this point. However, this should now work universally. Thanks and have a nice day @Dirbaio!

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