<?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: S32K312 CRC peripheral wrong result in S32K</title>
    <link>https://community.nxp.com/t5/S32K/S32K312-CRC-peripheral-wrong-result/m-p/1729921#M27405</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/206920"&gt;@atranzillo93&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ask you to please test your code with just a value to verify the behavior.&lt;/P&gt;&lt;P&gt;I made a simple test using the Crc_Ip_Example_S32K312 and made the necessary changes to calculate CRC based on the CRC-16-XMODEM algorithm. The test result is a match between the code result and the CRC calculator you shared.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My recommendation is to take a look at this example, which you might find useful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;B.R.&lt;/P&gt;&lt;P&gt;VaneB&lt;/P&gt;</description>
    <pubDate>Tue, 26 Sep 2023 20:33:12 GMT</pubDate>
    <dc:creator>VaneB</dc:creator>
    <dc:date>2023-09-26T20:33:12Z</dc:date>
    <item>
      <title>S32K312 CRC peripheral wrong result</title>
      <link>https://community.nxp.com/t5/S32K/S32K312-CRC-peripheral-wrong-result/m-p/1728928#M27367</link>
      <description>&lt;P&gt;Hi, I'm trying to use CRC peripheral on S32K312 EVB. I need to calculate CRC of data in Program Flash and compare it with a precomputed checksum.&lt;/P&gt;&lt;P&gt;I'm using a tool to calculate CRC based on CRC-16-XMODE algorithm.&lt;/P&gt;&lt;P&gt;First of all I switch-on peripheral with this setting:&lt;/P&gt;&lt;P&gt;MC_ME_Type * const crcModeEntryInstance = IP_MC_ME;&lt;BR /&gt;crcModeEntryInstance-&amp;gt;PRTN1_COFB3_CLKEN |= MC_ME_PRTN1_COFB3_CLKEN_REQ96_MASK;&amp;nbsp;&lt;BR /&gt;crcModeEntryInstance-&amp;gt;PRTN1_PUPD |= MC_ME_PRTN1_PUPD_PCUD_MASK;&lt;/P&gt;&lt;P&gt;crcModeEntryInstance-&amp;gt;CTL_KEY = 0x5AF0U;&lt;BR /&gt;crcModeEntryInstance-&amp;gt;CTL_KEY = 0xA50FU;&lt;BR /&gt;/* Poll partition update status */&lt;BR /&gt;while ((crcModeEntryInstance-&amp;gt;PRTN1_PUPD &amp;amp; MC_ME_PRTN1_PUPD_PCUD_MASK) != 0u) {}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, I configure CRC peripheral as indicated on datasheet:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="atranzillo93_0-1695644690475.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/242543iA3847D6487B35708/image-size/medium?v=v2&amp;amp;px=400" role="button" title="atranzillo93_0-1695644690475.png" alt="atranzillo93_0-1695644690475.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CRC_Type * const crcBaseAddr = IP_CRC;&lt;/P&gt;&lt;P&gt;crcBaseAddr-&amp;gt;CTRL &amp;amp;= ~CRC_CTRL_TCRC(1UL);&lt;BR /&gt;crcBaseAddr-&amp;gt;CTRL &amp;amp;= ~ CRC_CTRL_TOTR(1UL);&lt;BR /&gt;crcBaseAddr-&amp;gt;CTRL &amp;amp;= ~CRC_CTRL_TOT(1UL);&lt;BR /&gt;crcBaseAddr-&amp;gt;CTRL &amp;amp;= ~CRC_CTRL_FXOR(1UL);&lt;BR /&gt;crcBaseAddr-&amp;gt;GPOLY = CRC_GPOLY_LOW(0x1021U);&lt;BR /&gt;crcBaseAddr-&amp;gt;CTRL |= CRC_CTRL_WAS(1UL);&lt;BR /&gt;crcBaseAddr-&amp;gt;DATA &amp;amp;= ~((uint32_t)CRC_DATA_LL_MASK);&lt;BR /&gt;crcBaseAddr-&amp;gt;DATA &amp;amp;= ~((uint32_t)CRC_DATA_LU_MASK);&lt;BR /&gt;crcBaseAddr-&amp;gt;CTRL &amp;amp;= ~(CRC_CTRL_WAS_MASK);&lt;/P&gt;&lt;P&gt;Since computation on flash doesn't work, I wrote a small piece of code to calculate checksum on 4 bytes and reduce entropy.&lt;/P&gt;&lt;P&gt;uint8_t vector[4u] = {0x03u, 0x04u,0x06u,0x09u};&lt;/P&gt;&lt;P&gt;static uint8_t data = 0xFFu;&lt;BR /&gt;static uint16_t crc = 0u;&lt;/P&gt;&lt;P&gt;for(uint8_t k=0u;k&amp;lt;4u;k++)&lt;BR /&gt;{&lt;BR /&gt;data = vector[k];&lt;BR /&gt;crcBaseAddr-&amp;gt;DATA =CRC_DATA_LL(data);&lt;BR /&gt;NOP();&lt;BR /&gt;NOP();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;crc = (uint16_t)(crcBaseAddr-&amp;gt;DATA &amp;amp; CRC_DATA_LL_MASK);&lt;BR /&gt;crc = crc | (uint16_t)(crcBaseAddr-&amp;gt;DATA &amp;amp; CRC_DATA_LU_MASK);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result of CRC peripheral is &lt;STRONG&gt;E60F:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="atranzillo93_1-1695645172028.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/242544i328E6FA3EBBC486A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="atranzillo93_1-1695645172028.png" alt="atranzillo93_1-1695645172028.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, by using online calculator(as&amp;nbsp;&lt;A href="https://www.lddgo.net/en/encrypt/crc" target="_blank"&gt;https://www.lddgo.net/en/encrypt/crc&lt;/A&gt;) I get 7C93.&lt;/P&gt;&lt;P&gt;I tried to change algorith and use other CRC settings but there is no way to get correct result.&lt;/P&gt;&lt;P&gt;Can you help to find the problem?&lt;/P&gt;&lt;P&gt;Do you know about any issue related to the use of CRC peripheral on S32K3xx uC?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 12:33:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/S32K312-CRC-peripheral-wrong-result/m-p/1728928#M27367</guid>
      <dc:creator>atranzillo93</dc:creator>
      <dc:date>2023-09-25T12:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: S32K312 CRC peripheral wrong result</title>
      <link>https://community.nxp.com/t5/S32K/S32K312-CRC-peripheral-wrong-result/m-p/1729921#M27405</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/206920"&gt;@atranzillo93&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ask you to please test your code with just a value to verify the behavior.&lt;/P&gt;&lt;P&gt;I made a simple test using the Crc_Ip_Example_S32K312 and made the necessary changes to calculate CRC based on the CRC-16-XMODEM algorithm. The test result is a match between the code result and the CRC calculator you shared.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My recommendation is to take a look at this example, which you might find useful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;B.R.&lt;/P&gt;&lt;P&gt;VaneB&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 20:33:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/S32K312-CRC-peripheral-wrong-result/m-p/1729921#M27405</guid>
      <dc:creator>VaneB</dc:creator>
      <dc:date>2023-09-26T20:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: S32K312 CRC peripheral wrong result</title>
      <link>https://community.nxp.com/t5/S32K/S32K312-CRC-peripheral-wrong-result/m-p/1730188#M27415</link>
      <description>&lt;P&gt;Hi, VaneB, by using just a value(the first one of the array, 0x03), the result is correct. But then it is wrong, maybe there is some errors in DATA register filling?&lt;/P&gt;&lt;P&gt;I try to look at RTD example even if it seems to compute CRC in a different way.&lt;/P&gt;&lt;P&gt;Thanks a lot.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 06:26:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/S32K312-CRC-peripheral-wrong-result/m-p/1730188#M27415</guid>
      <dc:creator>atranzillo93</dc:creator>
      <dc:date>2023-09-27T06:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: S32K312 CRC peripheral wrong result</title>
      <link>https://community.nxp.com/t5/S32K/S32K312-CRC-peripheral-wrong-result/m-p/1730523#M27445</link>
      <description>&lt;P&gt;Thanks for noticing me to look at RTD deeply. I found the problem: the filling of DATA register.&lt;/P&gt;&lt;P&gt;The right way is the following:&lt;/P&gt;&lt;P&gt;*(volatile uint8_t *)&amp;amp;crcBaseAddr-&amp;gt;DATA = data;&lt;/P&gt;&lt;P&gt;In my code, instead I used this code:&lt;/P&gt;&lt;P&gt;crcBaseAddr-&amp;gt;DATA = CRC_DATA_LL((uint8_t)data);&lt;/P&gt;&lt;P&gt;By replacing code, the CRC is as expected.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 12:36:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/S32K312-CRC-peripheral-wrong-result/m-p/1730523#M27445</guid>
      <dc:creator>atranzillo93</dc:creator>
      <dc:date>2023-09-27T12:36:33Z</dc:date>
    </item>
  </channel>
</rss>

