Skip to content

[nrf fromtree] drivers: pwm: nrfx: Add option to glitch free 100% duty cycle #2948

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 2 commits into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions drivers/pwm/Kconfig.nrfx
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ config PWM_NRFX
select PINCTRL
help
Enable support for nrfx Hardware PWM driver for nRF52 MCU series.

config PWM_NRFX_NO_GLITCH_DUTY_100
bool "No glitches when using 100% duty"
depends on $(dt_compat_any_has_prop,$(DT_COMPAT_NORDIC_NRF_PWM),idleout-supported,True)
default y
help
Due to how IDLEOUT feature in PWM works it is possible to see a glitch on a channel
with 100% duty cycle when all other channels switches to 0% or 100%. Enabling this
option ensures that there are no glitches but it also means that 100% duty cycle
on any channels requires PWM peripheral to be active.
19 changes: 5 additions & 14 deletions drivers/pwm/pwm_nrfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@
/* Constantly active (duty 100%). */
/* This value is always greater than or equal to COUNTERTOP. */
compare_value = PWM_NRFX_CH_COMPARE_MASK;
needs_pwm = pwm_is_fast(config) ||
(IS_ENABLED(NRF_PWM_HAS_IDLEOUT) &&
IS_ENABLED(CONFIG_PWM_NRFX_NO_GLITCH_DUTY_100));
} else {

Check notice on line 246 in drivers/pwm/pwm_nrfx.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/pwm/pwm_nrfx.c:246 - needs_pwm = pwm_is_fast(config) || - (IS_ENABLED(NRF_PWM_HAS_IDLEOUT) && - IS_ENABLED(CONFIG_PWM_NRFX_NO_GLITCH_DUTY_100)); + needs_pwm = pwm_is_fast(config) || (IS_ENABLED(NRF_PWM_HAS_IDLEOUT) && + IS_ENABLED(CONFIG_PWM_NRFX_NO_GLITCH_DUTY_100));
/* PWM generation needed. Check if the requested period matches
* the one that is currently set, or the PWM peripheral can be
* reconfigured accordingly.
Expand Down Expand Up @@ -279,20 +282,8 @@
if (inverted) {
out_level ^= 1;
}
/* Output of fast PWM instance is directly connected to GPIO pads,
* thus it cannot controlled by GPIO. Use regular 0%/100% duty cycle
* playback instead.
*/
#ifdef PWM_NRFX_FAST_PRESENT
if (pwm_is_fast(config)) {
nrfx_pwm_simple_playback(&config->pwm, &config->seq, 1,
NRFX_PWM_FLAG_NO_EVT_FINISHED);
} else {
#else
{
#endif
nrf_gpio_pin_write(psel, out_level);
}

nrf_gpio_pin_write(psel, out_level);
}

data->pwm_needed &= ~BIT(channel);
Expand Down
5 changes: 5 additions & 0 deletions dts/bindings/pwm/nordic,nrf-pwm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ properties:
type: boolean
description: Set this to use center-aligned (up and down) counter mode.

idleout-supported:
type: boolean
description: |
Indicates if the PWM instance has the IDLEOUT register.

"#pwm-cells":
const: 3

Expand Down
5 changes: 5 additions & 0 deletions dts/vendor/nordic/nrf54h20.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@
clocks = <&hsfll120>;
power-domains = <&gpd NRF_GPD_FAST_ACTIVE1>;
#pwm-cells = <3>;
idleout-supported;
};

spis120: spi@8e5000 {
Expand Down Expand Up @@ -1008,6 +1009,7 @@
clocks = <&fll16m>;
power-domains = <&gpd NRF_GPD_SLOW_ACTIVE>;
#pwm-cells = <3>;
idleout-supported;
};

i2c130: i2c@9a5000 {
Expand Down Expand Up @@ -1141,6 +1143,7 @@
clocks = <&fll16m>;
power-domains = <&gpd NRF_GPD_SLOW_ACTIVE>;
#pwm-cells = <3>;
idleout-supported;
};

i2c132: i2c@9b5000 {
Expand Down Expand Up @@ -1274,6 +1277,7 @@
clocks = <&fll16m>;
#pwm-cells = <3>;
power-domains = <&gpd NRF_GPD_SLOW_ACTIVE>;
idleout-supported;
};

i2c134: i2c@9c5000 {
Expand Down Expand Up @@ -1407,6 +1411,7 @@
clocks = <&fll16m>;
#pwm-cells = <3>;
power-domains = <&gpd NRF_GPD_SLOW_ACTIVE>;
idleout-supported;
};

i2c136: i2c@9d5000 {
Expand Down
3 changes: 3 additions & 0 deletions dts/vendor/nordic/nrf54l20.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@
reg = <0xd2000 0x1000>;
interrupts = <210 NRF_DEFAULT_IRQ_PRIORITY>;
#pwm-cells = <3>;
idleout-supported;
};

pwm21: pwm@d3000 {
Expand All @@ -497,6 +498,7 @@
reg = <0xd3000 0x1000>;
interrupts = <211 NRF_DEFAULT_IRQ_PRIORITY>;
#pwm-cells = <3>;
idleout-supported;
};

pwm22: pwm@d4000 {
Expand All @@ -505,6 +507,7 @@
reg = <0xd4000 0x1000>;
interrupts = <212 NRF_DEFAULT_IRQ_PRIORITY>;
#pwm-cells = <3>;
idleout-supported;
};

adc: adc@d5000 {
Expand Down
3 changes: 3 additions & 0 deletions dts/vendor/nordic/nrf54l_05_10_15.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
reg = <0xd2000 0x1000>;
interrupts = <210 NRF_DEFAULT_IRQ_PRIORITY>;
#pwm-cells = <3>;
idleout-supported;
};

pwm21: pwm@d3000 {
Expand All @@ -487,6 +488,7 @@
reg = <0xd3000 0x1000>;
interrupts = <211 NRF_DEFAULT_IRQ_PRIORITY>;
#pwm-cells = <3>;
idleout-supported;
};

pwm22: pwm@d4000 {
Expand All @@ -495,6 +497,7 @@
reg = <0xd4000 0x1000>;
interrupts = <212 NRF_DEFAULT_IRQ_PRIORITY>;
#pwm-cells = <3>;
idleout-supported;
};

adc: adc@d5000 {
Expand Down
5 changes: 5 additions & 0 deletions dts/vendor/nordic/nrf9280.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
status = "disabled";
interrupts = <228 NRF_DEFAULT_IRQ_PRIORITY>;
#pwm-cells = <3>;
idleout-supported;
};

spi120: spi@8e6000 {
Expand Down Expand Up @@ -767,6 +768,7 @@
status = "disabled";
interrupts = <420 NRF_DEFAULT_IRQ_PRIORITY>;
#pwm-cells = <3>;
idleout-supported;
};

i2c130: i2c@9a5000 {
Expand Down Expand Up @@ -881,6 +883,7 @@
status = "disabled";
interrupts = <436 NRF_DEFAULT_IRQ_PRIORITY>;
#pwm-cells = <3>;
idleout-supported;
};

i2c132: i2c@9b5000 {
Expand Down Expand Up @@ -995,6 +998,7 @@
status = "disabled";
interrupts = <452 NRF_DEFAULT_IRQ_PRIORITY>;
#pwm-cells = <3>;
idleout-supported;
};

i2c134: i2c@9c5000 {
Expand Down Expand Up @@ -1109,6 +1113,7 @@
status = "disabled";
interrupts = <468 NRF_DEFAULT_IRQ_PRIORITY>;
#pwm-cells = <3>;
idleout-supported;
};

i2c136: i2c@9d5000 {
Expand Down
Loading