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/sam3x8e: Add pwm implementation #3170

Merged
merged 1 commit into from
Jun 12, 2015

Conversation

A-Paul
Copy link
Member

@A-Paul A-Paul commented Jun 5, 2015

cpu/sam3x8e: Add pwm implementation.

As a starting contribution here's is my pwm driver code.

After an almost complete rewrite of the pwm channel handling, any number (up to 4) can be used and arbitrary mapping between physical and interface channel numbers can be defined in "periph_conf.h".
For now I stick with the "oldschool" style, using conditional preprocessor cascades. If all is working well it may be a good base for further optimization.
"periph_conf.h" has a sample output configuration which reflects pin assignment described here.

  • The application in "tests/peroph_pwm" is happy with the interface.
  • A scope shows a full range ratio sweep with precise 1kHz base frequency on all predfined channels.
  • pwm_stop() and pwm_poweroff() leave the ouputs with 0V and no modulation.
  • pwm_start() (and also pwm_poweroff()) continue operation where it was stopped.
  • (Re-)initializing at rutime with different resolution and frequency using pwm_init() works.
  • All required by interface description in drivers/include/periph/pwm.h

There is still room for coding improvements ( as always):

  • In "pwm_init()" I left two conditional blocks seperated as one ist writing in PWM and the other in GPIO registers. They may be melted together, and further optimized without affecting functionality.
  • ... your suggestions

I would be pleased if you spend some time and give me our feedback.

@miri64 miri64 modified the milestones: Release 2015.06, Release NEXT MAJOR Jun 5, 2015
@miri64 miri64 added Type: new feature The issue requests / The PR implemements a new feature for RIOT Platform: AVR Platform: This PR/issue effects AVR-based platforms Area: drivers Area: Device drivers labels Jun 5, 2015
@A-Paul A-Paul changed the title Sam3x8e periph pwm [WIP] cpu/sam3x8e: Add pwm implementation Jun 5, 2015
* @name PWM configuration
* @{
*/
#define MCK_DIV_LB_MAX (10U)
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 explain this value? Is there maybe a more self-explaining name? I'm wondering if it's reasonable to define this macro in the periph_conf

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the maximum binary logarithm for the divisor of the prescaled clocks (MCK/2^n -> MCK/1...MCK/1024). Hence the "LB" in the name.
And it seems reasonable to put it in "pwm.c".
There were several macros where I was unsure whether to place them in "pwm.c" or "periph_conf.h". I'm still not got the context of "periph_conf.h" completely.
Is it just board specific -desptite that the cpu ist on board also-, or belongs to peripheral devices on the microcontroller too?

Copy link
Member

Choose a reason for hiding this comment

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

Ok I'm fine with the position and also with the name of that macro. I will trust you :-). Well, the periph_conf is meant to abstract the RIOT-driver from hardware specifics in general. In most cases that contains board specific things like pin mappings, but could also contain microcontroller attributes. If you compare #3095, this approach might change a bit in the midterm future, but I suggest to implement to "old" or "common" structure.

@PeterKietzmann
Copy link
Member

@A-Paul congrats to your first PR :-) ! There are some comments inline. Just in general: 1) IMO it's not necessary to comment everything. Please unify the style and remove the "internal" comments from the doxygen. 2) Keep in mind that the driver should be usable for more or less any configuration in principle (pin, port, channel, ..). 3) When it comes to testing I need my board back :-)

@A-Paul
Copy link
Member Author

A-Paul commented Jun 8, 2015

Advice needed

Obviously I made some major mistakes with rebase before I sent the pull request. I would like to have a cleaner start when I begin committing requested changes.
Is it O.K. to sqash this whole beast down to one or two commits? Or will oher things be messed up doing this?

@miri64
Copy link
Member

miri64 commented Jun 8, 2015

As long as the commits stay thematically seperated is even desired to have as few commits as possible in a PR.

@PeterKietzmann
Copy link
Member

@A-Paul I think for now it's ok to do so if it simplifies things for you. I guess I'm the only one that looked at you PR right now

@PeterKietzmann
Copy link
Member

@A-Paul give me a sign when the PR can be tested!

#define PWM_NUMOF (1U)
#define PWM_0_EN (1)
#define PWM_MAX_VALUE (0xffff)
#define PWM_MAX_CHANNELS (8U)
Copy link
Member

Choose a reason for hiding this comment

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

Please change to max. four channels

@PeterKietzmann
Copy link
Member

I would suggest not to introduce doxygen comments from the driver implementation. @haukepetersen what's you opinion on that?

* TODO: Find out why simple assignment '=' isn't working although
* registers are Write only
*/
#if PWM_0_CHANNELS > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

same here!

@kaspar030
Copy link
Contributor

Looks OK generally, but please re-do everything that uses the preprocessor:

  • use structs to hold configuration
  • calculate offsets instead of using preprocessor to iterate over defines

@PeterKietzmann
Copy link
Member

@kaspar030 I discussed personally with @A-Paul today. He is at the beginning with RIOT and currently has some deadlines so we decided to merge this PR in the old and inefficient style when it's tested and do the rework when #3095 is merged and the first drivers had been adapted. Is this ok for you?

@haukepetersen
Copy link
Contributor

I am on the same page as @PeterKietzmann: I say lets merge this PWM driver in the current style for now (after all comments by @PeterKietzmann are addressed), and then lets adjust it once #3095 is merged.

@PeterKietzmann
Copy link
Member

I successfully tested the four implemented channels. Signals look good! @A-Paul please address the last small comments so we can merge this PR soon. If you are still interested then, I would suggest you to do a rework of the driver once #3095 is merged :-)

@A-Paul
Copy link
Member Author

A-Paul commented Jun 11, 2015

As arranged, I implemented and commited the last changes. And my tests are running as before.

Thank you @haukepetersen and @PeterKietzmann for showing thumbs up. As already mentioned I will put some effort in refactoring towards the new periph driver interface, so @kaspar030 can stop waving his fist. ;)

I intentionally didn't rebase and sqash for now. Please tell me if I should do it, or has to be done by the "elders of RIOT".

@PeterKietzmann
Copy link
Member

@A-Paul please do so! And please understand that there was no fist because we are the friendly OS for the IoT 😸 (<- you see?)

@PeterKietzmann PeterKietzmann removed the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label Jun 12, 2015
@PeterKietzmann PeterKietzmann changed the title [WIP] cpu/sam3x8e: Add pwm implementation cpu/sam3x8e: Add pwm implementation Jun 12, 2015
@PeterKietzmann
Copy link
Member

PS: after squashing I will put on Travis to see if compile tests are passing

@A-Paul A-Paul force-pushed the sam3x8e-periph-pwm branch from d7f41e8 to ba66a3d Compare June 12, 2015 09:17
@A-Paul
Copy link
Member Author

A-Paul commented Jun 12, 2015

Rebased and squashed.

@kaspar030
Copy link
Contributor

On 06/11/15 16:08, Hauke Petersen wrote:

lets adjust it once #3095 is merged.

fine with me.

@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 Jun 12, 2015
@PeterKietzmann
Copy link
Member

and go

PeterKietzmann added a commit that referenced this pull request Jun 12, 2015
cpu/sam3x8e: Add pwm implementation
@PeterKietzmann PeterKietzmann merged commit 9831245 into RIOT-OS:master Jun 12, 2015
@A-Paul A-Paul deleted the sam3x8e-periph-pwm branch June 15, 2015 16:42
@OlegHahm OlegHahm modified the milestone: Release 2015.12 Dec 18, 2015
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 Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants