S32K312 CRC peripheral wrong result

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K312 CRC peripheral wrong result

686 Views
atranzillo93
Contributor III

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.

I'm using a tool to calculate CRC based on CRC-16-XMODE algorithm.

First of all I switch-on peripheral with this setting:

MC_ME_Type * const crcModeEntryInstance = IP_MC_ME;
crcModeEntryInstance->PRTN1_COFB3_CLKEN |= MC_ME_PRTN1_COFB3_CLKEN_REQ96_MASK; 
crcModeEntryInstance->PRTN1_PUPD |= MC_ME_PRTN1_PUPD_PCUD_MASK;

crcModeEntryInstance->CTL_KEY = 0x5AF0U;
crcModeEntryInstance->CTL_KEY = 0xA50FU;
/* Poll partition update status */
while ((crcModeEntryInstance->PRTN1_PUPD & MC_ME_PRTN1_PUPD_PCUD_MASK) != 0u) {}

 

Then, I configure CRC peripheral as indicated on datasheet:

atranzillo93_0-1695644690475.png

 

CRC_Type * const crcBaseAddr = IP_CRC;

crcBaseAddr->CTRL &= ~CRC_CTRL_TCRC(1UL);
crcBaseAddr->CTRL &= ~ CRC_CTRL_TOTR(1UL);
crcBaseAddr->CTRL &= ~CRC_CTRL_TOT(1UL);
crcBaseAddr->CTRL &= ~CRC_CTRL_FXOR(1UL);
crcBaseAddr->GPOLY = CRC_GPOLY_LOW(0x1021U);
crcBaseAddr->CTRL |= CRC_CTRL_WAS(1UL);
crcBaseAddr->DATA &= ~((uint32_t)CRC_DATA_LL_MASK);
crcBaseAddr->DATA &= ~((uint32_t)CRC_DATA_LU_MASK);
crcBaseAddr->CTRL &= ~(CRC_CTRL_WAS_MASK);

Since computation on flash doesn't work, I wrote a small piece of code to calculate checksum on 4 bytes and reduce entropy.

uint8_t vector[4u] = {0x03u, 0x04u,0x06u,0x09u};

static uint8_t data = 0xFFu;
static uint16_t crc = 0u;

for(uint8_t k=0u;k<4u;k++)
{
data = vector[k];
crcBaseAddr->DATA =CRC_DATA_LL(data);
NOP();
NOP();
}

crc = (uint16_t)(crcBaseAddr->DATA & CRC_DATA_LL_MASK);
crc = crc | (uint16_t)(crcBaseAddr->DATA & CRC_DATA_LU_MASK);

 

Result of CRC peripheral is E60F:

atranzillo93_1-1695645172028.png

 

However, by using online calculator(as https://www.lddgo.net/en/encrypt/crc) I get 7C93.

I tried to change algorith and use other CRC settings but there is no way to get correct result.

Can you help to find the problem?

Do you know about any issue related to the use of CRC peripheral on S32K3xx uC?

0 Kudos
Reply
3 Replies

633 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @atranzillo93 

I ask you to please test your code with just a value to verify the behavior.

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. 

My recommendation is to take a look at this example, which you might find useful.

 

B.R.

VaneB

0 Kudos
Reply

600 Views
atranzillo93
Contributor III

Thanks for noticing me to look at RTD deeply. I found the problem: the filling of DATA register.

The right way is the following:

*(volatile uint8_t *)&crcBaseAddr->DATA = data;

In my code, instead I used this code:

crcBaseAddr->DATA = CRC_DATA_LL((uint8_t)data);

By replacing code, the CRC is as expected.

613 Views
atranzillo93
Contributor III

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?

I try to look at RTD example even if it seems to compute CRC in a different way.

Thanks a lot. 

0 Kudos
Reply