1)GD32程序测试
注:如果测试成功,两个灯常亮。
#include "gd32f4xx.h"
#include "gd32f450i_eval.h"
uint32_t val = 0, valcrc = 0;
int main(void)
{
val = (uint32_t)0xabcd1234;
/* initialize the LED1 and LED2, turn off them */
gd_eval_led_init(LED1);
gd_eval_led_init(LED2);
gd_eval_led_off(LED1);
gd_eval_led_off(LED2);
rcu_periph_clock_enable(RCU_CRC);
/* reset the CRC data register and calculate the CRC of the value */
crc_data_register_reset();
valcrc = crc_single_data_calculate(val);
if(0xf7018a40 == valcrc){
gd_eval_led_on(LED1);
gd_eval_led_on(LED2);
}
while (1){
}
}
2)自写代码测试
注:单片机的固定的计算多项式:0x4C11DB7,这个要写对
#include "gd32f4xx.h"
#include "gd32f450i_eval.h"
uint32_t val = 0, valcrc = 0;
uint32_t cal_crc(uint32_t *ptr, int len)
{
uint32_t xbit;
uint32_t data;
uint32_t crcTmp = 0xFFFFFFFF;
while (len--)
{
xbit = (uint32_t)1 << 31;
data = *ptr++;
for (int bits = 0; bits < 32; bits++)
{
if (crcTmp & 0x80000000)
{
crcTmp <<= 1;
crcTmp ^= 0x4C11DB7; //单片机的固定的计算多项式:0x4C11DB7,这个要写对
}
else
crcTmp <<= 1;
if (data & xbit)
crcTmp ^= 0x4C11DB7;
xbit >>= 1;
}
}
return crcTmp;
}
int main(void)
{
val = (uint32_t)0xabcd1234;
gd_eval_led_init(LED1);
gd_eval_led_init(LED2);
gd_eval_led_off(LED1);
gd_eval_led_off(LED2);
rcu_periph_clock_enable(RCU_CRC);
uint32_t tmp = cal_crc(&val,1);
if(0xf7018a40 == tmp)
{
gd_eval_led_on(LED1);
gd_eval_led_on(LED2);
}
while (1){
}
}
总结:经测试,GD32-CRC32bit测试合格,数据一致。
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_30143193/article/details/140037603
|