Skip to content

cpu/efm32: improve PWM driver - #22665

Queued
basilfx wants to merge 2 commits into
RIOT-OS:masterfrom
basilfx:feature/efm32_pwm_modes
Queued

cpu/efm32: improve PWM driver#22665
basilfx wants to merge 2 commits into
RIOT-OS:masterfrom
basilfx:feature/efm32_pwm_modes

Conversation

@basilfx

@basilfx basilfx commented Sep 5, 2026

Copy link
Copy Markdown
Member

Contribution description

Trying to fix the real problem on why this driver marks EFM32 as unsupported (the comment is wrong), I stumbled upon two things:

  • PWM_CENTER is actually supported (counting up-down-up)
  • PWM_RIGHT was inverted.

I guess that me from ten years ago did not understand this.

Testing procedure

I used the tests/periph/pwm application to test this, together with an STK3600 that maps a single PWM channel to the onboard LED. I then used a scope to verify the period and frequency, measured at the onboard LED.

> init 0 0 1000 4096
The pwm frequency is set to 1464
>
> set 0 0 1024
>
> init 0 1 1000 4096
The pwm frequency is set to 1464
>
> set 0 0 1024
>
> init 0 2 1000 4096
The pwm frequency is set to 1464
>
> set 0 0 1024
>

Without this PR, you will notice that the onboard led is brighter in PWM_RIGHT mode, because it is inverted. The scope screenshot for the unfixed PWM_RIGHT shows this.

The scope screenshots below will not tell you if left, right or center alignment is working correctly (I don't know how to measure this easily). But it will show you that the frequency and period remains correct (requested 1000 Hz, got ~1500 Hz).

PWM_LEFT @ 25% DS1Z_QuickPrint13
PWM_RIGHT (UNFIXED) @ 25% DS1Z_QuickPrint14
PWM_RIGHT (FIXED) @ 25% DS1Z_QuickPrint16
PWM_CENTER @ 25% DS1Z_QuickPrint15

Issues/PRs references

#22651 lead to this.

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

  • Claude Sonnet 5 helped me to understand, then I fixed it myself.

@basilfx basilfx added the AI: Ducky PR/Issue uses AI for asking questions, AI was not involved in final product. label Sep 5, 2026
@github-actions github-actions Bot added Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: cpu Area: CPU/MCU ports labels Sep 5, 2026
@basilfx basilfx added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 5, 2026
@basilfx basilfx changed the title Feature/efm32 pwm modes cpu/efm32: improve PWM driver Sep 5, 2026
@crasbe

crasbe commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

why this driver marks EFM32 as unsupported (the comment is wrong)

Wouldn't it make sense to correct this in this PR too? 🤔

@basilfx

basilfx commented Sep 5, 2026

Copy link
Copy Markdown
Member Author

why this driver marks EFM32 as unsupported (the comment is wrong)

Wouldn't it make sense to correct this in this PR too? 🤔

I have another PR incoming to clean this up, and for cryptoauthlib. That keeps this PR clean, the arch_efm32 PR and the incoming one.

@riot-ci

riot-ci commented Sep 5, 2026

Copy link
Copy Markdown

Murdock results

✔️ PASSED

5edac95 cpu/efm32: fix PWM_RIGHT being inverted

Success Failures Total Runtime
11285 0 11285 15m:05s

Artifacts

Comment thread cpu/efm32/periph/pwm.c Outdated
Center mode is actually supported, but counts from 0 -> TOP -> 0, so
the frequency needs to be adjusted for this.
@basilfx
basilfx force-pushed the feature/efm32_pwm_modes branch from 93228eb to 5edac95 Compare September 6, 2026 08:25
@crasbe
crasbe enabled auto-merge September 6, 2026 08:34
@crasbe
crasbe added this pull request to the merge queue Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Ducky PR/Issue uses AI for asking questions, AI was not involved in final product. Area: cpu Area: CPU/MCU ports 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: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants