-
Notifications
You must be signed in to change notification settings - Fork 69
Add ADC usage (for stm32f303
devices)
#47
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
Conversation
There was a problem hiding this 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. 👍
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. |
Thanks for the review I'll try to patch it the next days. |
@Sh3Rm4n wrote:
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. |
In this case, 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.
... 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 I'm pretty busy right now, however I can have a look at this PR sometime this |
With the release of stm32f3 - v0.10.0, we could now take advantage of the type systems, as ADC is now fully documented! :) |
Updated PR comment to link to the issue directly :) |
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) 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. |
Yes, I skipped this deliberately as I came to the same conclusion as you did ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 Hope this helps :)
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. |
Huge thanks to @Sh3Rm4n for reviewing and teaching me about rebasing. |
There was a problem hiding this 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.
@#47 (comment) Thanks for catching that typo (again) is fixed in bedfa0f |
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 :) |
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. |
@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. |
I've been using it productively as a base for my ADC needs ever since. |
Awesome! I'll give the code a quick review today then. |
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
There was a problem hiding this 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 :)
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.
Close #20