Skip to content

!drivers/pwm: remove PWM_MULTICHAN option#18864

Open
raiden00pl wants to merge 1 commit into
apache:masterfrom
raiden00pl:pwm_refactor
Open

!drivers/pwm: remove PWM_MULTICHAN option#18864
raiden00pl wants to merge 1 commit into
apache:masterfrom
raiden00pl:pwm_refactor

Conversation

@raiden00pl
Copy link
Copy Markdown
Member

@raiden00pl raiden00pl commented May 11, 2026

Summary

BREAKING CHANGE: remove PWM_MULTICHAN option

PWM_MULTICHAN option is redundant, we can just set CONFIG_PWM_NCHANNELS > 1. This is the first step to simplify PWM implementation and make it more portable.

apps part apache/nuttx-apps#3475

Impact

simplify API, no functional changes. old CONFIG_PWM_MULTICHAN=n is now achieved with CONFIG_PWM_NCHANNELS = 1

Testing

CI

@raiden00pl raiden00pl marked this pull request as ready for review May 11, 2026 09:14
@raiden00pl raiden00pl added the breaking change This change requires a mitigation entry in the release notes. label May 11, 2026
@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture and removed breaking change This change requires a mitigation entry in the release notes. labels May 11, 2026
@github-actions github-actions Bot added Arch: xtensa Issues related to the Xtensa architecture Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Area: Audio Board: arm Board: risc-v Board: xtensa labels May 11, 2026
@raiden00pl
Copy link
Copy Markdown
Member Author

raiden00pl commented May 11, 2026

CI run with nuttx-apps branch is here: https://github.com/raiden00pl/manual-nuttx-ci/actions/runs/25676150035

@xiaoxiang781216
Copy link
Copy Markdown
Contributor

@raiden00pl please fix:

Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/at32/at32_pwm.c:2171:1: error: Too many blank lines
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/at32/at32_pwm.c:3307:79: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/efm32/efm32_pwm.c:366:79: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/efm32/efm32_pwm.c:406:85: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/ht32f4[91](https://github.com/apache/nuttx/actions/runs/25661234964/job/75322078800?pr=18864#step:3:92)x3/ht32f491x3_pwm.c:348:84: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_pwm.c:368:79: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kl/kl_pwm.c:334:79: error: Long line found
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/lpc17xx_40xx/lpc17_40_mcpwm.c:272:62: warning: Wrong column position of comment right of code
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/ra4/ra_pwm.c:559:81: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/s32k1xx/s32k1xx_pwm.c:363:79: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/stm32/stm32_pwm.c:3459:79: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/stm32f0l0g0/stm32_pwm.c:1099:82: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/stm32f0l0g0/stm32_pwm.c:1383:79: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/stm32f0l0g0/stm32_pwm.h:108:1: error: Too many blank lines
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/stm32f0l0g0/stm32_pwm.h:339:1: error: Too many blank lines
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/stm32f7/stm32_pwm.c:3035:79: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/stm32h5/stm32_pwm.c:19[94](https://github.com/apache/nuttx/actions/runs/25661234964/job/75322078800?pr=18864#step:3:95):1: error: Too many blank lines
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/stm32h5/stm32_pwm.c:3132:79: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/stm32h7/stm32_pwm.c:3135:79: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/stm32l4/stm32l4_pwm.c:3032:79: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/stm32l4/stm32l4_pwm.c:3156:1: error: Missing blank line before comment found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/tlsr82/tlsr82_pwm.c:337:81: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/risc-v/src/litex/litex_pwm.c:264:84: error: Long line found
Error: /home/runner/work/nuttx/nuttx/nuttx/boards/arm/nrf53/thingy53/src/nrf53_rgbled.c:44:1: error: Too many blank lines
Error: /home/runner/work/nuttx/nuttx/nuttx/boards/arm/nrf53/thingy53/src/nrf53_rgbled.c:52:1: error: Too many blank lines
Error: /home/runner/work/nuttx/nuttx/nuttx/boards/arm/nrf53/thingy53/src/nrf53_rgbled.c:[102](https://github.com/apache/nuttx/actions/runs/25661234964/job/75322078800?pr=18864#step:3:103):1: error: Too many blank lines
Warning: /home/runner/work/nuttx/nuttx/nuttx/boards/arm/stm32/common/src/stm32_xen1210.c:229:44: warning: Wrong column position of comment right of code
Error: /home/runner/work/nuttx/nuttx/nuttx/boards/arm/stm32/photon/src/stm32_rgbled.c:60:1: error: Too many blank lines

jerpelea
jerpelea previously approved these changes May 11, 2026
Copy link
Copy Markdown
Contributor

@michallenc michallenc left a comment

Choose a reason for hiding this comment

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

so far LGTM, I can test on SAMv7 later today.

acassis
acassis previously approved these changes May 11, 2026
@raiden00pl raiden00pl force-pushed the pwm_refactor branch 2 times, most recently from 4c46b05 to 95fef1f Compare May 12, 2026 07:27
michallenc
michallenc previously approved these changes May 12, 2026
Copy link
Copy Markdown
Contributor

@michallenc michallenc left a comment

Choose a reason for hiding this comment

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

Tested on SAMv7, all looks good.

pwminfo("TIM%u channel: %u duty: %08" PRIx32 "\n",
priv->timid, channel, duty);

#ifndef CONFIG_PWM_MULTICHAN
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we can change this to #if CONFIG_PWM_NCHAN == 1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

optimizing such a simple case is a matter for the compiler. when CONFIG_PWM_NCHANNELS=1 this code should be easy to optimise:

      for (i = 0; ret == OK && i < CONFIG_PWM_NCHANNELS; i++)
        {
          /* Break the loop if all following channels are not configured */

          if (info->channels[i].channel == -1)
            {
              break;
            }

          /* Set output if channel configured */

          if (info->channels[i].channel != 0)
            {
              ret = pwm_duty_update(dev, info->channels[i].channel,
                                    info->channels[i].duty);
            }
        }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds good!

Comment thread arch/arm/src/ht32f491x3/Kconfig
uint32_t ch2_pin; /* Channel 3 pin */
uint32_t ch3_pin; /* Channel 4 pin */
#ifndef CONFIG_PWM_MULTICHAN
uint8_t channel; /* Assigned channel */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For such things is it worth keeping the optimization by checking CONFIG_PWM_NCHAN > 1?

pwminfo("TIM%u channel: %u duty: %08" PRIx32 "\n",
priv->timid, channel, duty);

#ifndef CONFIG_PWM_MULTICHAN
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto

#endif

DEBUGASSERT(info->frequency > 0);
#ifndef CONFIG_PWM_MULTICHAN
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto

pwminfo("TIM%u channel: %u duty: %08" PRIx32 "\n",
priv->timid, channel, duty);

#ifndef CONFIG_PWM_MULTICHAN
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto

pwminfo("TIM%u channel: %u duty: %08" PRIx32 "\n",
priv->timid, channel, duty);

#ifndef CONFIG_PWM_MULTICHAN
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto

BREAKING CHANGE: remove PWM_MULTICHAN option

PWM_MULTICHAN option is redundant, we can just set CONFIG_PWM_NCHANNELS > 1.
At default CONFIG_PWM_NCHANNELS is set to 1, so the default behavior is preserved.
Access to single channel API is now `info->channels[0].XXX` instead of `info->XXX`

This is the first step to simplify PWM implementation and make it more portable.

Signed-off-by: raiden00pl <raiden00@railab.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: xtensa Issues related to the Xtensa architecture Area: Audio Board: arm Board: risc-v Board: xtensa Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants