//测试:故意做一个U8数组 它是10个成员 不是4的倍数 也就是U32以后会丢弃2个
uint8_t acrcBuffer[10] ={0,1,2,3,4,5,6,7,8,9};
uint32_t binlen = 10,bincrc = 0;
//CASE1:
printf("binlen/4 = %d\r\n",binlen/4);//也就是2啦!
printf("\n\r A=%08X B=%08X C=%08X\n\r",\
HAL_CRC_Calculate(&hcrc, (uint32_t *)acrcBuffer, binlen/4),\
HAL_CRC_Accumulate(&hcrc, (uint32_t *)acrcBuffer, binlen/4),\
Gcrc32((uint32_t *)acrcBuffer, binlen/4));
// A=9C08808D B=F50C3BD4 C=9C08808D
//结论:A C效果一样的!
//CASE2:
for(char cnt=0;cnt<8;cnt+=4)printf("0X%08X-",*(uint32_t *)&acrcBuffer[cnt]);
//0X03020100-0X07060504-
uint32_t CcrcBuffer[2] ={0X03020100,0X07060504};
printf("\n\r A=%08X B=%08X C=%08X\n\r",\
HAL_CRC_Calculate (&hcrc, CcrcBuffer, 2),\
HAL_CRC_Accumulate(&hcrc, CcrcBuffer, 2),\
Gcrc32(CcrcBuffer, 2));
//A=9C08808D B=6C68DE0C C=9C08808D
//结论:A C的结果都和CASE1一样 说明确实是内部U8转成了U32 每4个为一个单位
//CASE3
for(char cnt=0;cnt<binlen/4;cnt++)printf("0X%08X-",*(uint32_t *)&acrcBuffer[cnt]);
//0X03020100-0X04030201-
uint32_t bcrcBuffer[2] ={0X03020100,0X04030201};
printf("\n\r A=%08X B=%08X C=%08X\n\r",\
HAL_CRC_Calculate (&hcrc, bcrcBuffer, 2),\
HAL_CRC_Accumulate(&hcrc, bcrcBuffer, 2),\
Gcrc32(bcrcBuffer, 2));
// A=DACF3969 B=2AAF67E8 C=DACF3969
//结论:这是我故意写的错误的 它的U8转U32是一个一个转 不是4个一起转 它思路不对 没有模仿到真硬件
//CASE4:
//参考 https://blog.csdn.net/cp1300/article/details/48035667
uint32_t DcrcBuffer[8] ={0X00FFFFFF,0X01FFFFFF,0X02FFFFFF,0X03FFFFFF,0X04FFFFFF,0X05FFFFFF,0X06FFFFFF,0X07FFFFFF};
printf("\n\r --A=%08X B=%08X C=%08X\n\r",\
HAL_CRC_Calculate(&hcrc, (uint32_t *)DcrcBuffer, 8),\
HAL_CRC_Accumulate(&hcrc, (uint32_t *)DcrcBuffer, 8),\
Gcrc32((uint32_t *)DcrcBuffer, 8));
uint32_t EcrcBuffer[8] ={0XFFFFFF00,0XFFFFFF01,0XFFFFFF02,0XFFFFFF03,0XFFFFFF04,0XFFFFFF05,0XFFFFFF06,0XFFFFFF07};
printf("\n\r --A=%08X B=%08X C=%08X\n\r",\
HAL_CRC_Calculate(&hcrc, EcrcBuffer, 8),\
HAL_CRC_Accumulate(&hcrc,EcrcBuffer, 8),\
Gcrc32(EcrcBuffer, 8));
// --A=838D8595 B=4F8E0329 C=838D8595
// --A=C5794261 B=76FF21B7 C=C5794261
//结论 文章好像哟个结论 实际不对
//综合结论:CRC适合U32直接用,如果是U8的话就用CASE2 *(uint32_t *)&acrcBuffer[cnt]步进为4 他会丢弃%4个尾巴
/*
STM32硬件CRC测试-补充CRC性质
最新推荐文章于 2024-06-26 00:02:34 发布