CRC计算单元始终调整为0

时间:2019-05-10 09:15:35

标签: c crc nucleo

我正在使用Nucleo L053R8的CRC32计算单元来计算数据缓冲区的校验和,其中数据流输入以字节为单位。 在ST提供的示例项目中,他们正在使用具有以下CRC处理程序配置的4字节长元素的数据缓冲区:

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。 可能是什么问题?

0 个答案:

没有答案