-
Notifications
You must be signed in to change notification settings - Fork 69
Added DAC with basic features #133
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
Added a modified version of #93, with most f the review requests added. That module is badly in need of being added. I understand it's not perfect, but it's good enough. I got rid of LSI/HSE support as requested, to avoid exposing the extra RCC regs, per the discussion. |
Could you please split the DAC and RTC implementations into two self-contained PRs? This will make it easier to keep track of these two features and increase the chances that somebody finds time to review one or both of them. |
The other PR showed no progress, and I accidentally committed the rtc file and modified rcc file since I use it in my projects. I would be thrilled if that were merged. I added most of your review changes to that PR, but don't know how to justify the unsafe blocks. Would you be willing to merge that PR if it were modified to reflect what I have in this one? How would you like to proceed? |
I would suggest you open a new PR that duplicates #93 with the RTC-related changes from here. Make sure all CI checks pass, then I'll review it and if it looks good, we can merge and close #93. And from this PR here, just remove all the RTC-related changes (by rewriting the history and force-pushing) so it contains only the DAC feature. And then the same procedure: Make sure the CI tests pass, the maintainers will review, and if everything looks good we'll merge it. Hope that clears it up. |
Done. RTC pr |
Any idea why it's failing CI? |
That error is related to the Github Action we are using (see https://github.com/actions-rs/clippy-check#limitations) and is not the reason clippy fails, so you can ignore it. The clippy error is:
Replace that line with:
|
Can anyone figure out why this line doesn't work, but its equivalent for right-hand work? It's probably bit arithmetic I'm missing. DacBits::TwelveL => self.regs.dhr12l1.modify(|_, w| unsafe { w.bits(val) }), |
Moved away from trait-based approach, since I don't think it's general enough to make it into EH. |
@ra-kete What is your intention/thoughts regarding this PR? We are thinking about merging the |
@eldruin I would like to merge the PR as soon as the remaining open review comments have been addressed. |
@ra-kete Sounds good, thanks. I will hold the merge in |
Ready for merge. This represents an improvement to the crate by adding missing functionality, with a simple API, and no breaking changes. |
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.
The one TODO about correctness is still there.
I would also recommend squashing the changes before merging.
@eldruin No worries, I will squash anyway when I merge. @David-OConnor Please don't just mark review comments as "resolved" without at least commenting why you think they can be ignored. |
I did a squash, and now the I marked the comments resolved when I asked you questions and you didn't respond to them. |
A squash is simply the act of collecting multiple commits into a single one, it shouldn't pull in other changes. If you can't make it work, please just reset back to the state before. I'll do the squash when merging.
Okay, there seems to be some communication issue here. I am not aware of any questions you asked me. Where did you ask me? I normally would expect such questions as comments under my review comments. |
Thanks - squash fixed! For the questions, they're in the review comments. |
I recommend merging, then fine-tuning in a separate PR. |
I think I already made clear my view that code we merge should be of high quality and production-ready. This crate has enough code that needs refactoring already, no reason to willingly add more. I don't see why we can't just fix the few known issues in this PR? None of them look very difficult to me. If you don't feel up to it, let me know. I can fix them myself in this PR. |
Please fix them yourself. |
I've updated the PR to the best of my knowledge. @strom-und-spiele, @David-OConnor, would be good if you could look at it again to ensure I didn't mess up any of the finer DAC details. |
LGTM. Apart form that: thanks @David-OConnor and @ra-kete for you work. |
Looks good! |
@strom-und-spiele Okay, sounds good! I'm all for keeping this functionality if we can verify it. I'll hold off merging until you have the results then. |
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.
I think this is missing a free()
method to give back ownership of the Pin
, see C-FREE
To build, the examples need a specific board. Right now the examples are only implemented for the STM32F3DISCOVERY. This board is equipped with a stm32f303xc, which is now the required feature.
Updated the required features for all examples that were still referencing Playtime for today is over. Couldn't make the current example work. This is the error I was stuck with last:
|
Good catch, I will add that. I think for this I'll have to make the @strom-und-spiele Looks like you're building in debug mode. Have you tried |
I'll be back in the office on Wednesday and will try to find out what the reason for the under voltage is.
according to the datasheet, a nnnxC device should have 256 KBytes of flash. So what is it, I'm missing here? ^^ |
So I hooked it up to the osci and I get the following with a freshly out-of-the-box STM32F3DISCOVERY and v_ref =3.3 (as in the example code)
changed v_ref to 2.915 and got:
Need to rush home now but will try the dropped patterns tomorrow. |
/// Set the DAC voltage. `v` is in Volts. | ||
pub fn set_voltage(&mut self, volts: f32) { | ||
let val = match self.bits { | ||
DacBits::EightR => ((volts / self.vref) * 255.) as u32, |
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.
Maybe there is a better, robust and explicit version (e.g. u32::try_from(...)
).
I'm not sure it is needed, though.
Seems like an u8 (256) bit overflow? |
sorry, I was in a rush and just c&p'ed the same phrase over and over. This is definitely an overflow issue. the implied question was whether the expected behavior is for the value to overflow. |
As If this overflow error is not preventable, e.g. value > v_ref, then |
Couldntt make the wave generation work on short notice. I advise merging without them. However I noticed that there was no way to actually trigger the software trigger, so I added it. |
} | ||
|
||
// Select and activate a trigger. See f303 Reference manual, section 16.5.4. | ||
pub fn set_trigger(&mut self, trigger: Trigger) { |
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.
I wonder if we need a "get_set_trigger
" function to check which trigger is set?
Not really needed, more like a nice to have.
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.
Unless we have a convincing use-case for it now, I would leave it out for simplicity. We can always add it later if it's actually needed.
@@ -1,5 +1,5 @@ | |||
[target.thumbv7em-none-eabihf] | |||
runner = "arm-none-eabi-gdb" | |||
runner = "arm-none-eabi-gdb -q -x openocd.gdb" |
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.
@strom-und-spiele Do you think it is a good idea to add a reference to a file that is not part of this repo?
IMO we probably shouldn't even specify GDB as a runner, as there are other options. But not sure what the intentions were when this was added.
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.
this was not intended.
let dac_pin = gpioa.pa4.into_analog(&mut gpioa.moder, &mut gpioa.pupdr); | ||
|
||
// Set up the DAC | ||
let reference_voltage = 2.915; |
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.
@strom-und-spiele Where is that voltage value coming from?
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.
Ah, I see you got that from experimentation. Is this a value we can expect to be the same on each user of an F3DISCOVERY? If not, I think we should document how a user can find there own correct value. There must be some way to measure/infer the VREF for a given board, no?
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.
I wasn't so sure either and checked the schematics of the stm32f3discovery again.
VREF is a stabilized version VDD.
VDD is directly connected via Jumper 3 to 3V
3V is powered by the 5V supply and adjusted by a BAT60JFILM which has a voltage drop that depends on the power being used, so it's roughly 3V. Less if your chip is running something more demanding.
I suggest
- replacing the 2.9… by a solid 3
- add to the docs the info that the ref value should be known by the schematics and can be roughly determined by setting
set_value
to 255 and measuring the output - add a hint to the docs in the example
I implemented/responded to all remaining review comments, except for the issue of handling invalid voltages/values. There is not much we can do at compile time. We could limit setting an 8-bit value to a So I propose making both |
While nothing stops us from using a twelve bit type I agree that uniformity is nicer here. |
The 12-bit left mode doesn't work; probably needs bit arith on the value word integer.
edit: Added triggers and (probably broken) tri wave and noise.