#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
int
main(void)
{
uint8_t byte0 = 0x00;
uint32_t crc0 = crc32(0L, Z_NULL, 0);
crc0 = crc32(crc0, &byte0, 1);
printf("CRC32 value of %" PRIu8 " is: %08" PRIx32 "\n", byte0, crc0);
}
输出结果为CRC32 value of 0 is: d202ef8d
,与多个在线计算器上的结果相同。
无论我在STM32上使用什么设置,似乎都无法得到相同的CRC值。我在ST的应用笔记中找到了一个流程图,说明了CRC硬件如何计算其值,但我不知道zlib是如何实现的。
有人知道它们是否兼容吗?
[编辑1]它们都使用相同的初始值和多项式。
[编辑2]由于它使用硬件,因此STM32代码相对不太重要。
...
/* Default values are used for init value and polynomial, see edit 1 */
CRC->CR |= CRC_CR_RESET;
CRC->DR = (uint8_t)0x00;
uint32_t crc = CRC->DR;
...