I am using the CRC32 calculation unit of Nucleo L053R8 to calculate a checksum of a data buffer where the data stream input is in bytes. In the exemple project provided by ST they are using a data buffer of 4-bytes length elements with the following configuration of the CRC handler:
CrcHandle.Instance = CRC;
CrcHandle.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;
CrcHandle.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
CrcHandle.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
CrcHandle.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
CrcHandle.InputDataFormat = CRC_INPUTDATA_FORMAT_WORDS;
and after initialisation the following function is used to calculate the CRC:
/**
* @brief Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
* starting with the previously computed CRC as initialization value.
* @param hcrc CRC handle
* @param pBuffer pointer to the input data buffer, exact input data format is
* provided by hcrc->InputDataFormat.
* @param BufferLength input data buffer length (number of bytes if pBuffer
* type is * uint8_t, number of half-words if pBuffer type is * uint16_t,
* number of words if pBuffer type is * uint32_t).
* @note By default, the API expects a uint32_t pointer as input buffer parameter.
* Input buffer pointers with other types simply need to be cast in uint32_t
* and the API will internally adjust its input data processing based on the
* handle field hcrc->InputDataFormat.
* @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
*/
uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
As my input data is of 1-byte length and I have my own polynomial and init value I have used the following configuration:
CrcHandle.Instance = CRC;
CrcHandle.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_DISABLE;
CrcHandle.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_DISABLE;
CrcHandle.Init.GeneratingPolynomial = 0x80032DB;
CrcHandle.Init.InitValue = 0x55555500;
CrcHandle.Init.CRCLength = CRC_POLYLENGTH_32B;
CrcHandle.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
CrcHandle.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
CrcHandle.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
And I have casted the input data to uint32_t However, The result is always 0 no matter the input data. What could be the problem ?