我正在使用 Nucleo L053R8 的 CRC32 计算单元来计算数据流输入以字节为单位的数据缓冲区的校验和。在 ST 提供的示例项目中,他们使用 4 字节长度元素的数据缓冲区,并具有以下 CRC 处理程序配置:
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;
初始化后,以下函数用于计算 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)
由于我的输入数据长度为 1 字节,并且我有自己的多项式和初始值,因此我使用了以下配置:
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;
而且我已将输入数据转换为 uint32_t 但是,无论输入数据如何,结果始终为 0。可能是什么问题呢 ?