Skip to content

STM32: DAC Support #2208

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

Merged
merged 5 commits into from
Oct 10, 2019
Merged

STM32: DAC Support #2208

merged 5 commits into from
Oct 10, 2019

Conversation

hierophect
Copy link
Collaborator

This PR adds dual channel DAC support to STM32 boards that support the feature, such as the STM32F405 found on the Pyboard and Feather F405. Both channels can be used simultaneously.

@tannewt let me know if you'd like me to add a struct in here that tracks whether each channel is on, and de-inits the clock if both are turned off. I haven't seen a lot of meta-level tracking of what features are on or off on the common-hal layer so I wanted to check if you thought that was a good idea style wise.

Tested on a feather F405.

@hierophect hierophect requested review from tannewt and ladyada October 9, 2019 17:55
@hierophect hierophect added the stm label Oct 9, 2019
@hierophect
Copy link
Collaborator Author

hierophect commented Oct 9, 2019

@ladyada builds are failing due to obnoxious include issue with other boards than the 405, but they shouldn't prevent testing, so here's a binary.
firmware.bin.zip

@hierophect
Copy link
Collaborator Author

hierophect commented Oct 9, 2019

Ok, so the build is failing because the ST hal doesn't include empty defines for boards that don't support the DAC, like the F412 and F411. However, since there's no way to exclude the Analogio module specifically without also excluding analogin, I'm forced to add ugly #if defined(HAS_DAC) statements around everything.

If there's a more elegant way to somehow not included the entire incompatible AnalogOut module, please let me know.

@ladyada
Copy link
Member

ladyada commented Oct 9, 2019

i know that nrf52 has analogin but not analogout (it uses PWM out instead) so check that out!

@hierophect
Copy link
Collaborator Author

@ladyada well, in the NRF case, there's no files to include at all. For the Atmel case, it seems like you can have the DAC not be "available" on some chips, but the macros and structs are still defined, they just don't do anything. So I think this is the first time this has come up.

@dhalbert
Copy link
Collaborator

dhalbert commented Oct 9, 2019

The problem is that "stm32f4" is kind of not sufficiently fine-grained. We do have similar #if or #ifdef stuff to differentiate between SAMD21 and SAMD51 in the atmel-samd common-hal. So this is not unprecedented.

If you want to make it a little neater you could do something like:

#ifdef HAS_DAC
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
        const mcu_pin_obj_t *pin) {
    // regular impl
}
#else
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
        const mcu_pin_obj_t *pin) {    
    mp_raise_ValueError(translate("No DAC on chip"));
}

Is HAS_DAC yours or is it supplied by the STM libs? If it's yours, make it 0 or 1 so we can test via #if.

@hierophect
Copy link
Collaborator Author

@dhalbert I can make HAS_DAC 1 or 0, I agree that's more clear.

I guess there's nothing particularly wrong or unusual about having to use the preprocessor to reformat the file into a stub, but it just seems like this is something that ought to be handled further up the chain. Not exactly a high priority though.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Overall, looks really good. A couple replies but ok to merge as is too.

@hierophect hierophect merged commit 0ccab50 into adafruit:master Oct 10, 2019
@hierophect hierophect deleted the stm32-DAC branch October 10, 2019 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants