Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
crc
crclib软件包使用
发布于 2024-05-29 00:11:21 浏览:393
订阅该版
最近在使用modbus的传感器,需要使用crc校验来防止数据跑飞。今天我试了一下crclib中的crc16_cyc_cal函数来校验。校验能正常运行,但是跑一段时间后就会爆栈。根据我多次测试,发现它每次都是执行该函数57次后爆栈(我的待处理数据每次是9个,爆栈的时候最后一个会丢,算起来每次都是处理了512个后爆栈)。我尝试过增加堆栈和数组大小,但还是会在执行57次后爆栈。源代码在未添加crc校验的时候可以一直获取数据并执行。孩子是真搞不懂了o(╥﹏╥)o 1.crc校验我是放在串口接收线程里的 ```c void serial_thread_entry(void *parameter) { char buffer[1024]={0}; int High; int Low; int i; u16 crc16_rst; //char crctest[7]={0x03,0x03,0x04,0x00,0xF6,0x02,0xF1}; //char buffer[]; while (1) { rt_sem_take(&sem,RT_WAITING_FOREVER); len = rt_device_read(u3_dev,0,&buffer,rx_len); crc16_rst=crc16_cyc_cal(0xffff,&buffer,len-2); High=(crc16_rst>>8)&0xFF; Low =crc16_rst&0xFF; if(High==buffer[len-1] && Low==buffer[len-2]) { if(buffer[0]==0x03) { temp1=((buffer[3]<< 8)|buffer[4])/10; temp2=((buffer[3]<< 8)|buffer[4])%10; humi1=((buffer[5]<< 8)|buffer[6])/10; humi2=((buffer[5]<< 8)|buffer[6])%10; } } // if(buffer[0]==0x03) // { // temp1=((buffer[3]<< 8)|buffer[4])/10; // temp2=((buffer[3]<< 8)|buffer[4])%10; // humi1=((buffer[5]<< 8)|buffer[6])/10; // humi2=((buffer[5]<< 8)|buffer[6])%10; // } //buffer[len]='\0'; // rt_kprintf("%s",buffer); // rt_kprintf("%d",len); for(i = 0; i < len; i++) { rt_kprintf("%02X ", buffer[i]); } rt_kprintf("crc16_ex_cal result = 0x%02X,0x%02X\n",High,Low); // memset(buffer, 0, sizeof (buffer)); // rt_kprintf("cbufferrc16_ex_cal result = 0x%02X,0x%02X\n",buffer[len-1],buffer[len-2]); // rt_kprintf("temp=%d.%d,humi=%d.%d\r\n",temp1,temp2,humi1,humi2); } } ``` 2.爆栈情况 ``` \ | / - RT - Thread Operating System / | \ 5.0.2 build May 28 2024 18:40:34 2006 - 2022 Copyright by RT-Thread team [I/sal.skt] Socket Abstraction Layer initialize success. [I/at.clnt] AT client(V1.3.1) on device uart2 initialize success. msh />[I/at.dev.esp] esp0 device wifi is disconnect. [I/at.dev.esp] esp0 device wifi is disconnect. [I/at.dev.esp] esp0 device wifi is connected. [I/at.dev.esp] esp0 device network initialize successfully. [D/mqtt.sample] inter mqtt_connect_callback! [D/mqtt] ipv4 address port: 1883 [D/mqtt] HOST = 'iot-06z00jmmozgvese.mqtt.iothub.aliyuncs.com' 903 03 04 00 EE 02 6C B8 8B crc16_ex_cal result = 0x8B,0xB8 [I/mqtt] MQTT server connect success. [I/mqtt] Subscribe #0 /sys/k01ps5LTTA2/Device_01/thing/event/property/set OK! [D/mqtt.sample] inter mqtt_online_callback! 903 03 04 00 EE 02 6C B8 8B crc16_ex_cal result = 0x8B,0xB8 903 03 04 00 EE 02 6B F9 49 crc16_ex_cal result = 0x49,0xF9 903 03 04 00 EF 02 6C E9 4B crc16_ex_cal result = 0x4B,0xE9 903 03 04 00 EF 02 6D 28 8B crc16_ex_cal result = 0x8B,0x28 903 03 04 00 EE 02 6D 79 4B crc16_ex_cal result = 0x4B,0x79 903 03 04 00 EF 02 6B A8 89 crc16_ex_cal result = 0x89,0xA8 903 03 04 00 EF 02 6F A9 4A crc16_ex_cal result = 0x4A,0xA9 903 03 04 00 EE 02 6D 79 4B crc16_ex_cal result = 0x4B,0x79 903 03 04 00 EE 02 6E 39 4A crc16_ex_cal result = 0x4A,0x39 903 03 04 00 EE 02 6D 79 4B crc16_ex_cal result = 0x4B,0x79 903 03 04 00 EE 02 6E 39 4A crc16_ex_cal result = 0x4A,0x39 903 03 04 00 EE 02 6E 39 4A crc16_ex_cal result = 0x4A,0x39 903 03 04 00 EE 02 6E 39 4A crc16_ex_cal result = 0x4A,0x39 903 03 04 00 EE 02 6C B8 8B crc16_ex_cal result = 0x8B,0xB8 903 03 04 00 EE 02 6E 39 4A crc16_ex_cal result = 0x4A,0x39 903 03 04 00 EF 02 6C E9 4B crc16_ex_cal result = 0x4B,0xE9 903 03 04 00 EE 02 6E 39 4A crc16_ex_cal result = 0x4A,0x39 903 03 04 00 EE 02 6B F9 49 crc16_ex_cal result = 0x49,0xF9 903 03 04 00 EE 02 6F F8 8A crc16_ex_cal result = 0x8A,0xF8 903 03 04 00 EE 02 6D 79 4B crc16_ex_cal result = 0x4B,0x79 903 03 04 00 EE 02 6C B8 8B crc16_ex_cal result = 0x8B,0xB8 903 03 04 00 EE 02 6E 39 4A crc16_ex_cal result = 0x4A,0x39 903 03 04 00 EE 02 6E 39 4A crc16_ex_cal result = 0x4A,0x39 903 03 04 00 EE 02 6C B8 8B crc16_ex_cal result = 0x8B,0xB8 903 03 04 00 EE 02 6C B8 8B crc16_ex_cal result = 0x8B,0xB8 903 03 04 00 EE 02 6F F8 8A crc16_ex_cal result = 0x8A,0xF8 903 03 04 00 EE 02 6D 79 4B crc16_ex_cal result = 0x4B,0x79 903 03 04 00 EE 02 6F F8 8A crc16_ex_cal result = 0x8A,0xF8 903 03 04 00 EE 02 6D 79 4B crc16_ex_cal result = 0x4B,0x79 903 03 04 00 EE 02 6E 39 4A crc16_ex_cal result = 0x4A,0x39 903 03 04 00 EF 02 6E 68 8A crc16_ex_cal result = 0x8A,0x68 903 03 04 00 EE 02 6D 79 4B crc16_ex_cal result = 0x4B,0x79 903 03 04 00 EF 02 6E 68 8A crc16_ex_cal result = 0x8A,0x68 903 03 04 00 EF 02 6D 28 8B crc16_ex_cal result = 0x8B,0x28 903 03 04 00 EE 02 6D 79 4B crc16_ex_cal result = 0x4B,0x79 903 03 04 00 EF 02 6D 28 8B crc16_ex_cal result = 0x8B,0x28 903 03 04 00 EF 02 6C E9 4B crc16_ex_cal result = 0x4B,0xE9 903 03 04 00 EF 02 6D 28 8B crc16_ex_cal result = 0x8B,0x28 903 03 04 00 EE 02 6A 38 89 crc16_ex_cal result = 0x89,0x38 903 03 04 00 EE 02 6A 38 89 crc16_ex_cal result = 0x89,0x38 903 03 04 00 EE 02 6B F9 49 crc16_ex_cal result = 0x49,0xF9 903 03 04 00 EF 02 68 E8 88 crc16_ex_cal result = 0x88,0xE8 903 03 04 00 EF 02 68 E8 88 crc16_ex_cal result = 0x88,0xE8 903 03 04 00 EE 02 6A 38 89 crc16_ex_cal result = 0x89,0x38 903 03 04 00 EF 02 6A 69 49 crc16_ex_cal result = 0x49,0x69 903 03 04 00 EE 02 6A 38 89 crc16_ex_cal result = 0x89,0x38 903 03 04 00 EE 02 69 78 88 crc16_ex_cal result = 0x88,0x78 903 03 04 00 EF 02 6B A8 89 crc16_ex_cal result = 0x89,0xA8 903 03 04 00 EF 02 6B A8 89 crc16_ex_cal result = 0x89,0xA8 903 03 04 00 EE 02 68 B9 48 crc16_ex_cal result = 0x48,0xB9 903 03 04 00 EF 02 6A 69 49 crc16_ex_cal result = 0x49,0x69 903 03 04 00 EF 02 6C E9 4B crc16_ex_cal result = 0x4B,0xE9 903 03 04 00 EE 02 6B F9 49 crc16_ex_cal result = 0x49,0xF9 903 03 04 00 EE 02 6B F9 49 crc16_ex_cal result = 0x49,0xF9 903 03 04 00 EE 02 6B F9 49 crc16_ex_cal result = 0x49,0xF9 803 03 04 00 EF 02 6D 28 crc16_ex_cal result = 0xE9,0x88 psr: 0x01000000 r00: 0x0000ffff r01: 0x20020001 r02: 0x000000aa r03: 0x20020000 r04: 0x00017c90 r05: 0x0000e6aa r06: 0x00000076 r07: 0x20008348 r08: 0xdeadbeef r09: 0xdeadbeef r10: 0xdeadbeef r11: 0xdeadbeef r12: 0x00000000 lr: 0x08020ecb pc: 0x0801a568 hard fault on thread: u3_recv rt_thread_ thread pri status sp stack size max used left tick error ---------- -------- --- ------- ---------- ---------- ------ ---------- --- 0x20009adc JTH-2D1 16 suspend 0x000000c8 0x00000100 84% 0x00000005 EINTRPT 0x20008a38 cloud 16 suspend 0x0000035c 0x00001000 30% 0x0000002c EINTRPT 0x20008594 screen 16 suspend 0x00000170 0x00000400 68% 0x00000018 EINTRPT 0x20007cf0 u3_recv 10 running 0x000002cc 0x00000800 39% 0x00000019 OK 0x20006834 mqtt0 10 suspend 0x00000228 0x00001000 33% 0x00000002 OK 0x20004fe8 at_clnt 9 suspend 0x00000114 0x00000600 67% 0x00000003 EINTRPT 0x20003b08 tshell 20 suspend 0x000000ec 0x00001000 06% 0x00000009 EINTRPT 0x20002ff4 sys work 23 suspend 0x00000110 0x00000800 62% 0x00000004 OK 0x20000e5c tidle0 31 ready 0x00000074 0x00000100 78% 0x00000001 OK 0x20001178 timer 4 suspend 0x00000080 0x00000200 37% 0x00000009 OK bus fault: SCB_CFSR_BFSR:0x82 PRECISERR SCB->BFAR:20020000 ```
查看更多
2
个回答
默认排序
按发布时间排序
红枫
认证专家
2024-05-29
这家伙很懒,什么也没写!
串口接收少了个字节引起的问题,和crc校验计算关系不大。最后一帧数据的crc计算结果也是正确的,“03 03 04 00 EF 02”crc计算结果:88E9。异常多半是其它原因引起的。少字节导致校验检查不通过,进一步引发了异常,从这个方向查查原因吧!bus fault,ram访问越界了吧!另外检验帧的算法可以使用将整个帧进行crc计算结果为0。
yywxh
2024-05-31
这家伙很懒,什么也没写!
len小于2时会出错吧
撰写答案
登录
注册新账号
关注者
0
被浏览
393
关于作者
MC_xiong_ge
这家伙很懒,什么也没写!
提问
1
回答
0
被采纳
0
关注TA
发私信
相关问题
1
CRC校验,系统崩溃
2
CRYPTO中的CRC设备,CRC16计算结果有问题
3
使用硬件CRC后 没有找到drv_crc.c 这样的驱动文件
4
qboot生成的bootloader内部CRC校验与打包器固件crc计算值不一致
5
使用hwcrypto CRC校验的问提
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
【RT-Thread】【ci】【scons】将ci.attachconfig.yml和scons结合使用
2
Rt-thread中OTA下载后,bootloader不搬程序
3
ulog 日志 LOG_HEX 输出时间改为本地日期时间
4
在RT-Thread Studio中构建前执行python命令
5
研究一了一段时间RTT,直接标准版上手太难,想用nano,但又舍不得组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
I2C_IIC
ESP8266
UART
WIZnet_W5500
ota在线升级
cubemx
PWM
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
xusiwei1236
8
个答案
2
次被采纳
踩姑娘的小蘑菇
1
个答案
2
次被采纳
用户名由3_15位
9
个答案
1
次被采纳
bernard
4
个答案
1
次被采纳
RTT_逍遥
3
个答案
1
次被采纳
本月文章贡献
聚散无由
2
篇文章
15
次点赞
catcatbing
2
篇文章
5
次点赞
Wade
2
篇文章
4
次点赞
Ghost_Girls
1
篇文章
7
次点赞
xiaorui
1
篇文章
2
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部