<?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 fsl_pwm integer conversion failure? in i.MX RT Crossover MCUs</title>
    <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/fsl-pwm-integer-conversion-failure/m-p/2338796#M36403</link>
    <description>&lt;P&gt;The processor is RT1064.&lt;/P&gt;&lt;P&gt;Release Name: MCUXpresso Software Development Kit (SDK)&lt;BR /&gt;Release Version: 25.12.00&lt;/P&gt;&lt;P&gt;In fsl_pwm.c line 790,&lt;/P&gt;&lt;P&gt;pulseCnt = pulseEndCnt - base-&amp;gt;SM[subModuleSync].INIT + 1U;&lt;/P&gt;&lt;P&gt;Each term is uint16_t.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When pulseEndCnt &amp;lt;&amp;nbsp;base-&amp;gt;SM[subModuleSync].INIT, the result can be negative as int32_t. pulseCnt(uint16_t) will take the result and upper two bytes would be truncated. What would be the proper casting to keep the intention?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Mar 2026 20:38:24 GMT</pubDate>
    <dc:creator>choix361</dc:creator>
    <dc:date>2026-03-24T20:38:24Z</dc:date>
    <item>
      <title>fsl_pwm integer conversion failure?</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/fsl-pwm-integer-conversion-failure/m-p/2338796#M36403</link>
      <description>&lt;P&gt;The processor is RT1064.&lt;/P&gt;&lt;P&gt;Release Name: MCUXpresso Software Development Kit (SDK)&lt;BR /&gt;Release Version: 25.12.00&lt;/P&gt;&lt;P&gt;In fsl_pwm.c line 790,&lt;/P&gt;&lt;P&gt;pulseCnt = pulseEndCnt - base-&amp;gt;SM[subModuleSync].INIT + 1U;&lt;/P&gt;&lt;P&gt;Each term is uint16_t.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When pulseEndCnt &amp;lt;&amp;nbsp;base-&amp;gt;SM[subModuleSync].INIT, the result can be negative as int32_t. pulseCnt(uint16_t) will take the result and upper two bytes would be truncated. What would be the proper casting to keep the intention?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2026 20:38:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/fsl-pwm-integer-conversion-failure/m-p/2338796#M36403</guid>
      <dc:creator>choix361</dc:creator>
      <dc:date>2026-03-24T20:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_pwm integer conversion failure?</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/fsl-pwm-integer-conversion-failure/m-p/2339141#M36406</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/192846"&gt;@choix361&lt;/a&gt;&amp;nbsp;，&lt;/P&gt;
&lt;P&gt;Thank you so much for your interest in our products and for using our community.&lt;/P&gt;
&lt;DIV id="tinyMceEditormayliu1_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;Please notes that RT1064 eFlexPWM count-related registers are defined as&amp;nbsp;signed 16-bit&amp;nbsp;values.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 749px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/380332iDE9457499BCB69EB/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I suggest you can try to do the arithmetic in&amp;nbsp;int32_t&amp;nbsp;, and only then convert to&amp;nbsp;uint16_t&amp;nbsp;after range checking.&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;P&gt;int32_t pulseCntCalc = (int32_t)(int16_t)pulseEndCnt - (int32_t)(int16_t)base-&amp;gt;SM[subModuleSync].INIT + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if(( pulseCntCalc &amp;lt; 0) || (pulseCntCalc &amp;gt; UINT16_MAX))&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;// you can print log and handle invalid range&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;else&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;pulseCnt = (uint16_t)pulseCntCalc;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;Wish it helps you&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;MayLiu&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2026 09:48:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/fsl-pwm-integer-conversion-failure/m-p/2339141#M36406</guid>
      <dc:creator>mayliu1</dc:creator>
      <dc:date>2026-03-25T09:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_pwm integer conversion failure?</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/fsl-pwm-integer-conversion-failure/m-p/2339483#M36409</link>
      <description>&lt;P&gt;if(( pulseCntCalc &amp;lt; 0) || (pulseCntCalc &amp;gt; UINT16_MAX))&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; // you can print log and handle invalid range&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I saw many cases fall into &lt;EM&gt;&lt;STRONG&gt;if statement&lt;/STRONG&gt;&lt;/EM&gt;. Is it ok to intentionally truncate the data here?&lt;/P&gt;&lt;P&gt;Or set PulseCnt to certain fixed value?&lt;/P&gt;&lt;P&gt;if((pulseCntCalc &amp;lt; 0) || (pulseCntCalc &amp;gt; UINT16_MAX))&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; //Intentionally truncate data&lt;BR /&gt;&amp;nbsp; &amp;nbsp; pulseCntCalc = pulseCntCalc &amp;amp; 0x0000FFFF;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; pulseCnt = (uint16_t)pulseCntCalc;&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2026 16:11:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/fsl-pwm-integer-conversion-failure/m-p/2339483#M36409</guid>
      <dc:creator>choix361</dc:creator>
      <dc:date>2026-03-25T16:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_pwm integer conversion failure?</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/fsl-pwm-integer-conversion-failure/m-p/2344885#M36452</link>
      <description>&lt;DIV&gt;I don’t recommend truncating the value. It’s better to first identify the root cause of why it exceeds the valid range.&lt;/DIV&gt;</description>
      <pubDate>Fri, 03 Apr 2026 02:59:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/fsl-pwm-integer-conversion-failure/m-p/2344885#M36452</guid>
      <dc:creator>mayliu1</dc:creator>
      <dc:date>2026-04-03T02:59:09Z</dc:date>
    </item>
  </channel>
</rss>

