CRC_8 for Kinetis K60?

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

CRC_8 for Kinetis K60?

Jump to solution
3,159 Views
DangerMouse
Contributor II

Hi,

 

I am trying to implement  SAE J1850 crc_8 using CRC Module in K60.

 

The CRC Module generates crc_16/32-bit codes but crc_8 is required.

I'm thinking this should not be a problem but am not having any success

getting expected output.

 

Input data:                                                            0xFFFFFFFF

Expected output (complemented):                 0x0074

Actual output (complemented):                       0x30FF

 

I do not have alot of experience with CRC and maybe am interpreting the

calculation incorrectly or need an extra logical to perform on the CRC output.

 

Here is the complete code; any of you guys with experience using CRC got any suggestions?

 

 

void Main_task(uint_32 initial_data)
{
    
        uint_32 result=0;
        
        /* Enable CRC module */
        SIM_SCGC6 |= SIM_SCGC6_CRC_MASK;
        
        /* Configure CRC_CTRL for 16-bit and complement read */
        CRC_BASE_PTR->CTRL    =     CRC_CTRL_FXOR_MASK;
        CRC_BASE_PTR->CTRL    &=     ~CRC_CTRL_TCRC_MASK;
        
        /* Write SAEJ1850 polynomial to CRC_GPOLY register - SAE J1850 CRC: X8 + X4 + X3 + X2 + 1 */
        CRC_BASE_PTR->GPOLY_ACCESS16BIT.GPOLYL    =    0x11D;
        
        /* Configure CRC_CTRL for seed */
        CRC_BASE_PTR->CTRL    |=     (CRC_CTRL_WAS_MASK);
        
        /* Seed CRC with all ones */
        //CRC_BASE_PTR->ACCESS16BIT.CRCH    =    0x0000;
        CRC_BASE_PTR->ACCESS16BIT.CRCL    =    0xFFFF;
        
        /* Clear seed bit to start writing data values */
        CRC_BASE_PTR->CTRL    &=     (~CRC_CTRL_WAS_MASK);
        
        /* Write data to CRC data register */    
        CRC_BASE_PTR->CRC                =    0xFFFFFFFF;        /* Data */
        CRC_BASE_PTR->ACCESS8BIT.CRCLU     =    0x00;;            /* Zeros padding */
        
        /* Output complement of remainder */
        printf("CRC byte:\t%X   \n", (uint_16) CRC_BASE_PTR->ACCESS16BIT.CRCL);
        
        /* Output remainder */
        CRC_BASE_PTR->CTRL    &=     (~CRC_CTRL_FXOR_MASK);
        printf("CRC byte:\t%X   \n", (uint_16) CRC_BASE_PTR->ACCESS16BIT.CRCL);
        
        //_mqx_exit(0);
}

0 Kudos
1 Solution
1,665 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Yes, this module just supports CRC-16/32 . No support for 8 bit calculations.


Hope that helps,

Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
7 Replies
1,665 Views
Hab
Contributor III

IDK if this will help you, but I hope it does.

 

If you are trying to calculate CRC 8 here is a great website:

http://smbus.org/faq/crc8Applet.htm

 

If this is the CRC 8 you require, then here is code to make it happen...  Code should be easy to implement, but if you have any questions on how to use it no problem.

 

/*************************************************************************

* Function Name: init_crc8

* Parameters: void

* Return: Loads a static array and sets a static variable flag

*

* Description: Loads a CRC8 polynomial checksum array (256 bytes). Sets the static

* value to indicate the array is loaded.

* STEP 1: Load the array x^8 + x^2 + x + 1

* STEP 2: Set the static varible that the array has been loaded

*************************************************************************/

void

init_crc8()

{

inti,j;

 

unsignedcharcrc;

 

// STEP 1if(!MadeTable)

{

for(i=0; i<256; i++)

{

crc = i;

for(j=0; j<8; j++)

crc = (crc << 1) ^ ((crc & 0x80) ? DI : 0);

crc8_table[i] = crc & 0xFF;

}

// STEP 2

MadeTable =

true;

}

}

// END OF init_crc8

 

 

 

 

/*************************************************************************

* Function Name: crc8

* Parameters: unsigned char *, unsigned char

* Return: Loads a static array and sets a static variable flag

*

* Description: For a byte array whose accumulated crc value is stored in *crc, computes

* resultant crc obtained by appending m to the byte array. Note, befor calling the crc must

* be first set to 0.

* STEP 1: Check if table loaded - if not load

* STEP 2: Calculate the present checksum via use of crc table

*************************************************************************/

void

crc8(unsignedchar*crc, unsignedcharm)

{

// STEP 1if(!MadeTable)

init_crc8();

// STEP 2

*crc = crc8_table[(*crc) ^ m];

*crc &= 0xFF;

}

// END OF crc8

0 Kudos
1,665 Views
DangerMouse
Contributor II

Hi Hab,

 

Thanks for that info.  I am looking at using a hardware solution however, by using the

Kinetis CRC Module. The Kinetis K60 CRC module generates 16/32-bit CRC's and that is fine

but i want to generate an 8-bit CRC. I think this should be possible although i'm not sure.

 

I already have a working software solution but would like the use of the hardware module if i can

get it going.  The code i have posted is using the polynomial required and complementing the remainder output

after CRC checksumming.  The output generated however is not the value required.

 

Possible reasons for problem:

  1. An 8-bit CRC cannot be generated by the Kinetis CRC module
  2. An 8-bit CRC can be generated but requires addtional software logic
  3. I am interpreting the CRC calculation incorrectly
  4. ?

 

If anyone has any ideas or is familiar with SAEJ1850 CRC please adivse

0 Kudos
1,665 Views
panpwr
Contributor IV

Hello All,

I also need the functionality of CRC 8 in K60, using MQX. I am not using Processor Expert, since I am Keil's uVision4 user.

Any suggestion for how to generate CRC_8 while using the advantages of the Kinetis CRC module?

BTW, I found the following command in MQX userguide:

_mem_sum_ip - Gets the one’s complement checksum over the block of memory.

However, it seems to be generating CRC16 only.

Thanks,

Lior.

0 Kudos
1,666 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Yes, this module just supports CRC-16/32 . No support for 8 bit calculations.


Hope that helps,

Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,665 Views
tim_povall
Contributor II

8-bit CRC actually is possible with a 16 or 32-bit CRC module.

 

You can convert the 8-bit polynomial into 16-bit by shifting 8 bits to the left, and then to get a 8-bit result do the same to the resulting 16-bit CRC. Similarly, with 32-bit you would need to shift 24 bits to the left.

See my more detailed answer to a similar question here: https://community.nxp.com/thread/502067 

0 Kudos
1,665 Views
egoodii
Senior Contributor III

CRC_8 is just a simple lookup in a 256-byte ROM array -- hard to be much simpler in execution speed than CRCresult=CRCtab[CRCold^new_data];

0 Kudos
1,665 Views
p_vagnoni
Contributor III

Hello to all,

I am ising the CRC module on Kinetis K60 and it works. I am not working with MQX but "only" with Processor Expert. After the initialization I only use this siple code to check all my flash program (form 0x00000000 to 0x0003F000):



CRC.jpg

Note that i am usign the CRC8 (CRC1_GetCRC8 function) only because we compare it with anoter CRC Generation code based on 8bit calculating. With Processor Expert is also available a CRC Block calculation.

Bye,

Paolo

0 Kudos