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

Add ADC usage (for stm32f303 devices) #47

Merged
merged 32 commits into from Jul 19, 2020
Merged

Conversation

strom-und-spiele
Copy link
Collaborator

@strom-und-spiele strom-und-spiele commented Dec 29, 2019

Close #20

Copy link
Member

@Sh3Rm4n Sh3Rm4n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These requests are mostly styling requests. I'll hope this is ok :)

I did not try to run it on hardware yet or looked the logic side of this PR.

But thanks for taking action and providing a ADC implementation. Looks good so
far at first glance. 👍

Cargo.toml Outdated Show resolved Hide resolved
examples/adc.rs Outdated Show resolved Hide resolved
src/adc.rs Outdated Show resolved Hide resolved
src/adc.rs Show resolved Hide resolved
src/adc.rs Show resolved Hide resolved
src/adc.rs Outdated Show resolved Hide resolved
src/adc.rs Outdated Show resolved Hide resolved
src/adc.rs Outdated Show resolved Hide resolved
src/adc.rs Outdated Show resolved Hide resolved
@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Jan 5, 2020

Sadly not much of the ADC registers are documented in stm32-rs. Maybe we could submit a PR, which improves the situation. This would allow using variants, which provide nice type safety.

src/adc.rs Outdated Show resolved Hide resolved
@strom-und-spiele
Copy link
Collaborator Author

Thanks for the review I'll try to patch it the next days.

@strom-und-spiele
Copy link
Collaborator Author

@Sh3Rm4n wrote:

Sadly not much of the ADC registers are documented in stm32-rs. Maybe we could submit a PR, which improves the situation. This would allow using variants, which provide nice type safety.

I was under the impression that the variant usage here is a type safe way to discriminate between say the stm32f303xB/C/D/E and the stm32f303x6/8 variants.
Or are you suggesting to add the discriminating definitions also to the stm32-rs package? (for as far as I understand it, the different handling of the variants is still needed here.)

@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Jan 10, 2020

In this case, stm32-rs does not make a distinction between stm32f303xB/C/D/E and the stm32f303x6/8, as it's code is generated from an svd file for the stm32f303 family, IIRC.

I meant, that I wished more ADC peripherals / registers are documented, so we could use the "variant" methods for the ADC registers. This makes the code more clean and makes the intention clearer, when manipulating the register values. And it provides more type safety.

The ADC registers are mostly documented, as we can see here.

But it's not worth the effort to use the variants, when there are not documented for the other stm32f3xx devices, yet.

... I justed noticed, that every ADC register is already documented? I don't remeber if this was already the case, when I last looked. Then this should allow us to use variant for all stm32f3xx controllers.

So there is no need to make an PR at stm32-rs, as this is already done.

I'm pretty busy right now, however I can have a look at this PR sometime this
weekend. :)

src/adc.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Mar 7, 2020

With the release of stm32f3 - v0.10.0, we could now take advantage of the type systems, as ADC is now fully documented! :) chkmode for example

src/adc.rs Outdated Show resolved Hide resolved
@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Mar 8, 2020

Updated PR comment to link to the issue directly :)

@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Mar 12, 2020

Reminder (for later doesn't have to be implemented in this PR)

The current implementation does not consider using the otther ADC prescaler: (the one below)

img-2020-03-12-232314

This is a bit more complicated to implement. On the stm32f303b/c it does use PLLCLK, which does seem more common. On the other hand the stm32f303d/e does use the HSI directly.

Hoowever, inspecting this more carefully, this seems like a drawing error, as the Clock Mux on the stm32f303d/e has an HSI input, where nothing is connected to.

@strom-und-spiele
Copy link
Collaborator Author

The current implementation does not consider using the other ADC prescaler[…] This is a bit more complicated to implement.

Yes, I skipped this deliberately as I came to the same conclusion as you did ;)

Copy link
Member

@Sh3Rm4n Sh3Rm4n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove 36e02c6 and 7c7f8b4. I assume these are from #38, so i like to keep them there :)

@strom-und-spiele
Copy link
Collaborator Author

Could you remove 36e02c6 and 7c7f8b4. I assume these are from #38, so i like to keep them there :)

I have no clue how to do this without doing nasty stuff.
As those changes are already merged into master is it ok to just ignore this fauxpas?

@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Mar 16, 2020

Have a look at git rebase. Pretty useful subcommand. Though the interesting part enfoldes, when you use `git rebase --interactive <commit hash you want to rebase to.

There you have the option to remove commits, change the message of the commits, reorder commits and more. Here is another official article about rewriting the git history.

Remember, you have to force push to the branch, when changing the commit history. I suggest using --force-with-lease as the safer alternative to --force

Hope this helps :)

As those changes are already merged into master is it ok to just ignore this fauxpas?

I assume that they would be ignored, but they still show up in the "files changed" part, so I'm not really sure about this.

@strom-und-spiele
Copy link
Collaborator Author

Huge thanks to @Sh3Rm4n for reviewing and teaching me about rebasing.

Sh3Rm4n
Sh3Rm4n previously requested changes Apr 6, 2020
Copy link
Member

@Sh3Rm4n Sh3Rm4n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me overall. Seems to finally come along.

Currently, I have no way to test it, so I trust you that it is working :)
Maybe i'' catch some time in the next days and try it out myself.

src/lib.rs Outdated Show resolved Hide resolved
src/adc.rs Outdated Show resolved Hide resolved
@strom-und-spiele
Copy link
Collaborator Author

strom-und-spiele commented Apr 7, 2020

@#47 (comment) Thanks for catching that typo (again) is fixed in bedfa0f
the code does not fit the issue though - did you mean something else? /edit got it

@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Apr 12, 2020

Hey I tested your example yesterday and it worked for me on my f3 discovery board! :)

I did write down some notes for review but this is still in progress.

However two things that came to my mind:

Can you be more explicit, that the pa0 you are using in the example is the user button on the discovery board. It is pretty clever to use it, btw. That means that every one who owns a discovery board can test the example immediately.

And the user should now, that the ADC has a 12 bit resolution, so that the maximum expected value is 4095 :)

@strom-und-spiele
Copy link
Collaborator Author

strom-und-spiele commented Apr 12, 2020

Can you be more explicit, that the pa0 you are using in the example is the user button on the discovery board. It is pretty clever to use it, btw. That means that every one who owns a discovery board can test the example immediately.

And the user should now, that the ADC has a 12 bit resolution, so that the maximum expected value is 4095 :)

Thanks for the input - it made me think how much information to include in the output and in the comments. where to spread it and then I went down the rabbit hole of explaining how to properly convert adc values.
Not sure I like it that way but now we can talk about something…

@strom-und-spiele strom-und-spiele mentioned this pull request Apr 18, 2020
@teskje
Copy link
Collaborator

teskje commented Jul 17, 2020

@strom-und-spiele What's the status on this PR? I haven't look at the code again, but from the comments here it looks like it's almost ready to merge. Would be great if we could get this over the finish line, ADC support is something I'd personally like to see too.

@strom-und-spiele
Copy link
Collaborator Author

I've been using it productively as a base for my ADC needs ever since.
I'll set aside some time on the weekend to rebase it and we can merge it (for stm32f303 only btw)

@teskje
Copy link
Collaborator

teskje commented Jul 17, 2020

Awesome! I'll give the code a quick review today then.

strom-und-spiele and others added 14 commits July 18, 2020 12:51
Co-Authored-By: Sh3Rm4n <f.vioel@gmail.com>
Skip rustfmt in the example when building the adc

The reader should check each line to make sure they understand what they
are passing.
i.e.
- use context sensitive read/write functions
- clear flag after usage
Clocksettings are checked during setup and as the setup can fail,
Option<adc> is returned now.
Note:
In fn calibrate,
`while self.rb.cr.read().adcal().is_not_complete() {}`
would be better than
`while !self.rb.cr.read().adcal().is_complete() {}`
However this seems to lack in our version of the PAC

In fn disable,
`self.rb.cr.modify(|_, w| w.aden().disable());`
would be better than
`self.rb.cr.modify(|_, w| w.aden().clear_bit());`
However this seems to lack in our version of the PAC
src/adc.rs Outdated Show resolved Hide resolved
src/adc.rs Outdated Show resolved Hide resolved
src/adc.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@teskje teskje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small things now :)

src/adc.rs Outdated Show resolved Hide resolved
This is the reset value of the ADC.
Now when running the example it is possible to get values other than 0
and 4095 by pressing the user button shortly.
@teskje teskje dismissed Sh3Rm4n’s stale review July 19, 2020 14:38

This has all been addressed.

@teskje teskje merged commit 2ea16b4 into stm32-rs:master Jul 19, 2020
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.

Support for ADCs
3 participants