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

cpu/nrf52: add PWM implementation #9021

Merged
merged 2 commits into from
Aug 21, 2018

Conversation

SemjonWilke
Copy link
Member

This is an initial peripheral pwm implementation for nordic nrf52 cpu. This implementation provides all functions in pwm.h. It implements nordics hardware pwm. Also this PR adds nrf52dk board configs.

@PeterKietzmann PeterKietzmann added the Area: drivers Area: Device drivers label Jun 20, 2018
@PeterKietzmann PeterKietzmann self-requested a review June 20, 2018 07:04
Copy link
Member

@PeterKietzmann PeterKietzmann left a comment

Choose a reason for hiding this comment

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

@SemjonKerner thanks for your contribution. The code looks really good and basically works. Please see/clarify/adress my comments next to the code

* @{
*/
static const pwm_conf_t pwm_config[] = {
{ NRF_PWM0, { 23, 24, 25, 26 } }
Copy link
Member

Choose a reason for hiding this comment

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

P0.23 doesn't seem to work here. Does it on your board?

Copy link
Member Author

Choose a reason for hiding this comment

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

@PeterKietzmann Yes, it works for me on nrf52dk. Is it possible, that you are testing a different board with P0.23 already in use by another module?

Copy link
Member

Choose a reason for hiding this comment

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

To be honest, I don't remember. But in my opinion any board that provides the PWM feature and makes use of this periph_conf.h should work with the provided configuration of at least be documented.

Copy link
Member Author

@SemjonWilke SemjonWilke Aug 16, 2018

Choose a reason for hiding this comment

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

I'll double check that, but i am confident 23 works for me, because i mostly used that pin for debugging.

Copy link
Member

Choose a reason for hiding this comment

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

Would be great if you could check the manuals of the other nrf52 boards that we support. I think it's just 2-3...


DEBUG("PWM started\n");

return real_clk;
Copy link
Member

Choose a reason for hiding this comment

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

I assume this value has to be adapted in case of PWM_CENTER ?

init 0 1 10000 100
The pwm frequency is set to 10000

init 0 2 10000 100
The pwm frequency is set to 20000

However, frequency is 10k in both cases (as expected)

Copy link
Member Author

Choose a reason for hiding this comment

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

@PeterKietzmann i intend on dropping center mode support. I already checked that there is no support in center mode for other CPUs, also center mode is rearly used anyway. If center mode has no special relevance to you, i will just drop it.

Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with dropping that feature.

else {
pwm_seq[pwm][channel] = dev(pwm)->COUNTERTOP - value;
}

Copy link
Member

Choose a reason for hiding this comment

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

Can you please spend a note about the center mode here?

@SemjonWilke
Copy link
Member Author

@PeterKietzmann Okay, so i moved the pins and restricted the pwm pin configuration to both boards nrf52dk and nrf52840dk. I decided to use ifdefs, because it felt excessive to create new periph_conf files for both boards just to add 4 common pins each.
Also i dropped center mode.

typedef enum {
PWM_LEFT = PWM_MODE(0, 1), /**< left aligned PWM */
PWM_RIGHT = PWM_MODE(0, 0), /**< right aligned PWM */
PWM_CENTER = PWM_MODE(1, 1), /**< not supported */
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have a strong opinion about that. As i saw in other cpus (samd21,efm32) center mode is not supported but PWM_CENTER is set anyway. I did not question this design, but i think it gives easy access / guidance to anyone who wants to implement center mode in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Fine I leave it up to you. Please squash

Copy link
Member

@PeterKietzmann PeterKietzmann left a comment

Choose a reason for hiding this comment

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

ACK. Tested on a nrf52840dk board. Eventually address my last comment. Otherwise, please squash

@PeterKietzmann PeterKietzmann added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Aug 17, 2018
@PeterKietzmann
Copy link
Member

warning: Member PWM_NUMOF (macro definition) of file boards/common/nrf52xxxdk/include/periph_conf.h is not documented

@PeterKietzmann
Copy link
Member

@SemjonKerner still around? Please fix Mudrocks complaints. My ACK holds

@SemjonWilke
Copy link
Member Author

@PeterKietzmann murdock is green

@miri64 miri64 merged commit 69b2bae into RIOT-OS:master Aug 21, 2018
@SemjonWilke SemjonWilke deleted the driver_periph_pwm_nrf52 branch October 15, 2018 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants