This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSPM0G3507: CRC block calculation in 8 bit

Part Number: MSPM0G3507


Dear,

Does somebody has the equivalent code for the 8 bit version of:

extern uint16_t DL_CRC_calculateBlock16(CRC_Regs *crc, uint16_t seed, uint16_t *ptr, uint16_t size);

For sake of speed of the algorithm, I try to avoid making it myself.

Thank you!

John

  • Hi John,

    We do not offer an 8 bit version of DL_CRC_calculateBlock16(). You could develop one based on the existing functions located in dl_crc.c. If you review some example files in our SDK, you can see that when we calculate the CRC of an 8 bit value, we feed the 8 bit value into the CRC calculation using DL_CRC_feedData8() but use the 16 or 32 bit functions, DL_CRC_getResult16 and DL_CRC_getResult32(), to fetch the result. For examples of this you can look at the following in the SDK:

    [SDK Install Path]\mspm0_sdk_1_30_00_03\examples\nortos\LP_MSPM0G3507\bsl\secondary_bsl_uart -> function name: BSL_CI_calculateCRC()

    Additionally, an example from our motor control library (which looks like the API may be named incorrectly I'll add):

    [SDK Install Path]\mspm0_sdk_1_30_00_03\source\ti\motor_control_bldc_sensorless_foc\modules\hal\LP_MSPM0G3507\commInterface\uart_comm\source -> function name: CRC_calc16()

  • For sake of speed of the algorithm, I try to avoid making it myself.

    This doesn't sound reasonable. You can always check the disassembly and optimize your code for maximum performance. Writing everything in ASM is always an option.

    Here's my implementation (CRC-16/CCITT-FALSE):

    uint16_t HAL_CRC_Calculate(uint8_t *data, uint16_t len)
    {
    	/* Initialize the CRC register */
    	CRC->CRCSEED = 0x0000FFFFUL;
    
    	/* Move data into the CRC unit (byte writes!) */
    	while(len--)
    	{
    		*((uint8_t *)&CRC->CRCIN) = *data++;
    	}
    
    	/* Return the CRC code */
    	return (uint16_t)CRC->CRCOUT;
    }
    

    Notice that I'm taking the pointer of the 32-bit CRCIN register, casting it to an 8-bit pointer and then dereferencing that. You need to do it this way, because 32-bit writes would result in 32 bits being processed.

  • Thank you !!

    Helpfull!

  • Hi John, 

    Please mark a response as resolved if one or more responses here resolved your issue. This helps with internal tracking and helps guide other customers to the correct resolution to your issue.

    Thanks!