<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: PWM with Zephyr on RT1020 in Zephyr Project</title>
    <link>https://community.nxp.com/t5/Zephyr-Project/PWM-with-Zephyr-on-RT1020/m-p/2372727#M691</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/261291"&gt;@Deepa-khatri2588&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for your interest in NXP MIMXRT series!&lt;/P&gt;
&lt;P&gt;The first thing I would correct is the PWM channel index. Your pinmux routes GPIO_AD_B0_06 to FLEXPWM2_PWMA3, which is channel A of submodule 3. In Zephyr’s pwm_mcux.c, channel 0 maps to kPWM_PwmA and channel 1 maps to kPWM_PwmB. Therefore your calls should use channel 0, not channel 1.&lt;/P&gt;
&lt;P&gt;Zephyr’s nxp,imx-pwm binding supports run-in-wait and run-in-debug, and the MCUX PWM driver maps these properties to pwm_config.enableWait and pwm_config.enableDebugMode. Please keep these properties in the flexpwm2_pwm3 node.&lt;BR /&gt;For runtime torque updates, keep the period and polarity unchanged and only update the pulse width. This allows the Zephyr MCUX driver to use PWM_UpdatePwmDutycycle() followed by PWM_SetPwmLdok(), instead of stopping and reconfiguring the submodule.&lt;/P&gt;
&lt;P&gt;If the PWM still stops only when the kernel becomes idle, this indicates the issue is related to WFI/WAIT-mode clock handling. CONFIG_PM=n disables Zephyr PM policy/device PM, but does not necessarily prevent the CPU idle path from executing WFI. As a diagnostic test, keep the CPU out of idle with a temporary high-priority busy thread. If the PWM then becomes stable, we should focus on the SoC WAIT-mode clock/CCM/GPC configuration or apply the i.MX RT low-power workaround path.&lt;/P&gt;
&lt;P&gt;Best regards,&lt;BR /&gt;Gavin&lt;/P&gt;</description>
    <pubDate>Fri, 29 May 2026 03:34:42 GMT</pubDate>
    <dc:creator>Gavin_Jia</dc:creator>
    <dc:date>2026-05-29T03:34:42Z</dc:date>
    <item>
      <title>PWM with Zephyr on RT1020</title>
      <link>https://community.nxp.com/t5/Zephyr-Project/PWM-with-Zephyr-on-RT1020/m-p/2372583#M690</link>
      <description>&lt;P&gt;I am working on a custom board based on the &lt;STRONG&gt;MIMXRT1021xxxxx&lt;/STRONG&gt; (using the NXP MCUXpresso SDK under Zephyr RTOS). I am migrating a high-performance motor tension reel application from a standard FreeRTOS SDK implementation over to Zephyr, and I am hitting a critical blocker regarding the &lt;STRONG&gt;FlexPWM2 (Submodule 3, Channel A)&lt;/STRONG&gt; peripheral clock behavior.&lt;/P&gt;&lt;H3&gt;The Problem:&lt;/H3&gt;&lt;P&gt;I am trying to command the torque dynamically&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;In &lt;STRONG&gt;FreeRTOS&lt;/STRONG&gt;, the application works perfectly: the module maintains a constant frequency/tension holding loop without dropping out.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;In &lt;STRONG&gt;Zephyr&lt;/STRONG&gt;, the moment all operating system threads fall into an idle or sleep state (causing the ARM Cortex-M7 core to execute a Wait-for-Interrupt WFI instruction), &lt;STRONG&gt;the entire register space for FlexPWM2 Submodule 3 drops to 0 or freezes.&lt;/STRONG&gt; The moment an event occurs or a thread wakes up, the registers temporarily recover, but the power/clock-saving "pauses" are completely breaking our motor control loop, resulting in a loss of torque and erratic brake behavior.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I have disabled the high-level OS Power Manager (CONFIG_PM=n), meaning the operating system isn't dynamically shutting down peripheral rails. It appears that the master clock source or the IPG peripheral clock tree feeding FlexPWM2 is automatically scaling down or clock-gating when the CPU idles.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;What is the definitive, ideal initialization sequence to ensure a FlexPWM sub-module's clock source remains strictly pinned &lt;STRONG&gt;ON&lt;/STRONG&gt; across all Run, Wait, and Doze states?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;How can we cleanly change the duty cycle dynamically at runtime without causing glitch pulses or desynchronizing the shadow register buffer transfers (LDOK / MCTRL)?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Is it possible to completely decouple the FlexPWM clock gating from the CPU core's sleep states on the RT1020, or do we have to resort to a hardware workaround like FlexIO?&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;H3&gt;Current Configuration Details:&lt;/H3&gt;&lt;H4&gt;1. prj.conf (Power Management disabled, Clocks forced open)&lt;/H4&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;I&lt;/SPAN&gt;&lt;/DIV&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;# Disable standard power management to keep peripheral clocks wide open&lt;/SPAN&gt;
&lt;SPAN class=""&gt;CONFIG_PM&lt;/SPAN&gt;=n
&lt;SPAN class=""&gt;CONFIG_PM_DEVICE&lt;/SPAN&gt;=n
&lt;SPAN class=""&gt;CONFIG_CLOCK_CONTROL&lt;/SPAN&gt;=y

&lt;SPAN class=""&gt;# Standard PWM Driver activation&lt;/SPAN&gt;
&lt;SPAN class=""&gt;CONFIG_PWM&lt;/SPAN&gt;=y&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;H4&gt;2. app.overlay (Devicetree Mapping with low-power overrides)&lt;/H4&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;BR /&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;PRE&gt;&amp;amp;iomuxc {
    pinmux_motor_pwm: pinmux_motor_pwm {
        group0 {
            /* Routes Pad 6 (GPIO_AD_B0_06) to FlexPWM2 Module 3 Channel A */
            pinmux = &amp;lt;&amp;amp;iomuxc_gpio_ad_b0_06_flexpwm2_pwma3&amp;gt;;
            drive-strength = "r0-6";
            slew-rate = "fast";
            bias-pull-up;
            nxp,speed = "150-mhz";
        };
    };
};

&amp;amp;flexpwm2_pwm3 {
    status = "okay";
    pinctrl-0 = &amp;lt;&amp;amp;pinmux_motor_pwm&amp;gt;;
    pinctrl-names = "default";
    clocks = &amp;lt;&amp;amp;ccm IMX_CCM_PWM_CLK 0 0&amp;gt;;
    
    /* Intended to force the counter to stay alive when CPU idles */
    run-in-wait;
    nxp,prescaler = &amp;lt;1&amp;gt;; 
};&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;H4&gt;3. Current Runtime Configuration (Using standard Zephyr API)&lt;/H4&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;C&lt;/SPAN&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;/* Initializing to safe zero-torque baseline on boot */&lt;/SPAN&gt;
pwm_set_cycles(pwm_dev, &lt;SPAN class=""&gt;1&lt;/SPAN&gt;, &lt;SPAN class=""&gt;12499&lt;/SPAN&gt;, &lt;SPAN class=""&gt;12499&lt;/SPAN&gt;, PWM_POLARITY_INVERTED);

&lt;SPAN class=""&gt;/* Dynamic Runtime Torque Shift via Web Callback */&lt;/SPAN&gt;
&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;void&lt;/SPAN&gt; &lt;SPAN class=""&gt;set_motor_torque&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;SPAN class=""&gt;int8_t&lt;/SPAN&gt; level)&lt;/SPAN&gt; &lt;/SPAN&gt;{
    &lt;SPAN class=""&gt;uint32_t&lt;/SPAN&gt; pulse = (level &amp;gt; &lt;SPAN class=""&gt;0&lt;/SPAN&gt;) ? &lt;SPAN class=""&gt;5500&lt;/SPAN&gt; : &lt;SPAN class=""&gt;12499&lt;/SPAN&gt;;
    
    &lt;SPAN class=""&gt;// This call works when threads are hot, but fails during OS idle pauses&lt;/SPAN&gt;
    pwm_set_cycles(pwm_dev, &lt;SPAN class=""&gt;1&lt;/SPAN&gt;, &lt;SPAN class=""&gt;12499&lt;/SPAN&gt;, pulse, PWM_POLARITY_INVERTED);
}&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;I have even attempted bare-metal register overrides targeting CCM_CCGR4 (setting bits 24-25 to 0x3 to force the clock gate open continuously) and manually strobing MCTRL |= (1 &amp;lt;&amp;lt; 3) for an immediate shadow latch, but reading the registers via volatile pointers still returns 0 whenever the kernel goes quiet.&lt;/P&gt;&lt;P&gt;Any insights on how to force the FlexPWM clock tree to remain active independently of the core state would be greatly appreciated!&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2026 17:44:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Zephyr-Project/PWM-with-Zephyr-on-RT1020/m-p/2372583#M690</guid>
      <dc:creator>Deepa-khatri2588</dc:creator>
      <dc:date>2026-05-28T17:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: PWM with Zephyr on RT1020</title>
      <link>https://community.nxp.com/t5/Zephyr-Project/PWM-with-Zephyr-on-RT1020/m-p/2372727#M691</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/261291"&gt;@Deepa-khatri2588&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for your interest in NXP MIMXRT series!&lt;/P&gt;
&lt;P&gt;The first thing I would correct is the PWM channel index. Your pinmux routes GPIO_AD_B0_06 to FLEXPWM2_PWMA3, which is channel A of submodule 3. In Zephyr’s pwm_mcux.c, channel 0 maps to kPWM_PwmA and channel 1 maps to kPWM_PwmB. Therefore your calls should use channel 0, not channel 1.&lt;/P&gt;
&lt;P&gt;Zephyr’s nxp,imx-pwm binding supports run-in-wait and run-in-debug, and the MCUX PWM driver maps these properties to pwm_config.enableWait and pwm_config.enableDebugMode. Please keep these properties in the flexpwm2_pwm3 node.&lt;BR /&gt;For runtime torque updates, keep the period and polarity unchanged and only update the pulse width. This allows the Zephyr MCUX driver to use PWM_UpdatePwmDutycycle() followed by PWM_SetPwmLdok(), instead of stopping and reconfiguring the submodule.&lt;/P&gt;
&lt;P&gt;If the PWM still stops only when the kernel becomes idle, this indicates the issue is related to WFI/WAIT-mode clock handling. CONFIG_PM=n disables Zephyr PM policy/device PM, but does not necessarily prevent the CPU idle path from executing WFI. As a diagnostic test, keep the CPU out of idle with a temporary high-priority busy thread. If the PWM then becomes stable, we should focus on the SoC WAIT-mode clock/CCM/GPC configuration or apply the i.MX RT low-power workaround path.&lt;/P&gt;
&lt;P&gt;Best regards,&lt;BR /&gt;Gavin&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2026 03:34:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Zephyr-Project/PWM-with-Zephyr-on-RT1020/m-p/2372727#M691</guid>
      <dc:creator>Gavin_Jia</dc:creator>
      <dc:date>2026-05-29T03:34:42Z</dc:date>
    </item>
  </channel>
</rss>

