Skip to content

PWM with power management fix - #25

Merged
Aksel Mellbye (asmellby) merged 2 commits into
SiliconLabsSoftware:silabs/devfrom
Martinhoff-maker:pwm_pm_fix
Jul 7, 2026
Merged

Aksel Mellbye (asmellby) merged 2 commits into
SiliconLabsSoftware:silabs/devfrom
Martinhoff-maker:pwm_pm_fix

Conversation

@Martinhoff-maker

Copy link
Copy Markdown

Without this fix, when PM is enabled, clock_control_get_rate() for the PWM peripheral returns 32,768 Hz, which is incorrect because the PWM runs at the CPU frequency.

Moreover, this change applies proper PM device runtime management to prevent the CPU from entering sleep mode while a PWM is active.

This patch ensure that clock_control_get_rate function returns the
correct clock rate for the PWM peripheral. PWM is clocked from M4
processor clock.

Upstream-status: pending
Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
* 32.768 kHz when the sleeptimer system timer is selected, which breaks
* pwm_set() nsec-to-cycles conversion.
*/
*rate = SystemCoreClock;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use devicetree for this: DT_PROP(DT_NODELABEL(cpu0), clock_frequency)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

So we have a debate about that with Jérôme Pouiller (@jerome-pouiller), SystemCoreClock is actually the real Core clock value updated dynamically in Wiseconnect. But fair point, will use DT_PROP(DT_NODELABEL(cpu0), clock_frequency) for the moment to have consistency.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I thought this was in the PWM driver when I first reviewed, in which case it would be a violation of responsibility between drivers (PWM should use clock control only). Since this is in the clock driver, it's more OK since the clock driver is responsible for clocks, and should therefore be allowed to use that global as part of its HAL usage.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ok then let's still use SystemCoreClock for the moment (since this is with what i've tested).

This patch adds PM runtime management for the PWM peripheral. It allows
to block CPU from entering the sleep state when PWM is active.

Upstream-status: pending
Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
@Martinhoff-maker

Copy link
Copy Markdown
Author

v2: fix compliance check

data->pwm_channel_cfg[channel].is_chan_active = true;
}

if (pulse_cycles == 0 && data->pwm_channel_cfg[channel].is_chan_active == true) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor: is_chan_active is an essentially boolean type (bool) so the explicit comparison with true is redundant.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agree, I've to admit that I've reapplied the existing pattern in the function but that's a fair point. Will do that in another PR if that's ok for you.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sure

@asmellby
Aksel Mellbye (asmellby) merged commit 1650c70 into SiliconLabsSoftware:silabs/dev Jul 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants