当前位置:网站首页>Troubleshooting the cause of the crash when STM32 serial port dam receives 253 bytes
Troubleshooting the cause of the crash when STM32 serial port dam receives 253 bytes
2022-07-02 23:09:00 【ydgd118】
I made a plan a few days ago , It's about STM32 adopt M5311 Connect MQTT How to communicate with the server . After all parameters are tested , adopt MQTT The server sent a 300bytes Device parameter configuration instructions , As a result, it crashed directly . After many tests , The problem phenomenon is specifically determined as MQTT Server send 253 Bytes can be normal , Send greater than 254 Byte above STM32 Must crash .
To locate the cause of the problem , So separate tests . Test first STM32 Serial port communication , A serial port DMA To receive the 500 Bytes are also normal . Then test it separately M5311, Serial port sent 300 Bytes are also normal . It's depressing , It's OK for both of them to be alone , Why did they crash together .
- First, it is suspected that the serial port receiving cache is not enough , So I checked , yes 1000 byte , More than enough !
- It is doubted that it is serial port ORE Overflow causes crash , As a result, the program tracked for a long time , That's all right. , It is wronged .
- Check the serial port waveform , Find out STM32 It seems that the baud rate is a little lower , But they can recognize each other , It should be within the error range . Adjust the baud rate a little , The problem is still loud .
- Doubt again DMA error , Program tracking inspection , That's right .
- There is no way out , Then trace the serial port interrupt function . In all if–else Print statements are added in , All the way down , It is found that the serial port interrupt processing is also very perfect . It is also wronged .
- After the serial port interrupt processing is completed , Is the server instruction parsing function , Finally check it . Actually, the problem is caused by it ! After receiving serial port data , It first moves the data to another cache array , Then open the DMA Receive the next batch of data . The problem lies in moving , Used for loop , And the loop variable used is uint8_t, But the judgment condition for exiting the cycle is beyond 255 Of , That is, it inadvertently becomes a dead cycle . So it crashed .
/******************************************************************** Letter Count name :void Data_Transfer_To_Cache(void) function : Data is cached to another array , Then open it again immediately DMA Receive Parameters : nothing Return value : nothing ***********************************************************************/
uint8_t Data_Transfer_To_Cache(void)
{
// First, transfer it immediately , Then open the DMA receive , Then judge
uint8_t data_err = 0;
Clear_Tmp_Sz();
if(UART3_Rx_len<TP_LENGTH)// Prevent the array from accidentally crossing the bounds
{
for(uint16_t i=0;i<UART3_Rx_len;i++)
{
tmp_rx_sz[i] = UART3_Rx_buffer[i];
}
tmp_i = UART3_Rx_len;
}
else
{
data_err = 1;
}
DMA_UART3_Start();// Clear receive cache , open DMA Continue to receive
// printf("\r\n%s\r\n",tmp_rx_sz);
if(data_err)
{
printf(" Data out of cache !\r\n");
return 0;
}
else
{
return 1;
}
}
This function is responsible for moving bricks , Among them for(uint8_t i=0; i<UART3_Rx_len; i++) loop , stay UART3_Rx_len Greater than 255 When , It's a cycle . This is directly from the previous project copy Over here , I didn't consider this at all i There will be problems .
It took 2 Days time , I checked everything from hardware to software , Even the serial port waveform has been checked , A small problem wastes a lot of time , It's a lesson . I hope you can take a warning , Later transplantation copy Code carefully , Or simply write code for this loop ,i Variables are always used uint32_t type , It's impossible to get out .
边栏推荐
- Motivation du Protocole de chiffrement avancé AES
- Cryptographic technology -- key and ssl/tls
- Jerry's built-in shutdown current is 1.2ua, and then it can't be turned on by long pressing [chapter]
- Webrtc audio and video capture and playback examples and mediastream media stream analysis
- SQL advanced syntax
- Learning records of data analysis (II) -- simple use of response surface method and design expert
- STM32之ADC
- 首批 | 腾讯云完成国内首个云原生安全成熟度评估
- [chestnut sugar GIS] ArcScene - how to make elevation map with height
- Brief introduction of emotional dialogue recognition and generation
猜你喜欢
程序员版本的八荣八耻~
WebRTC音视频采集和播放示例及MediaStream媒体流解析
Jinglianwen technology's low price strategy helps AI enterprises reduce model training costs
BBR 遭遇 CUBIC
海思3559万能平台搭建:在截获的YUV图像上旋转操作
Chow-Liu Tree
Typical case of data annotation: how does jinglianwen technology help enterprises build data solutions
boot actuator - prometheus使用
最小生成树 Minimum Spanning Tree
Start from the bottom structure to learn the customization and testing of FPGA --- Xilinx ROM IP
随机推荐
Methods to solve the tampering of Chrome browser and edeg browser homepage
LeetCode 968. 监控二叉树
Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
Jerry's fast touch does not respond [chapter]
Qt QProgressBar详解
【喜欢的诗词】好了歌
Prometheus deployment
剑指 Offer II 099. 最小路径之和-双百代码
Start from the bottom structure to learn the customization and testing of FPGA --- Xilinx ROM IP
地平线2022年4月最新方案介绍
Boot actuator - Prometheus use
数据标注典型案例,景联文科技如何助力企业搭建数据方案
分布式监控系统zabbix
C#中Linq用法汇集
[Solved] Splunk: Cannot get username when all users are selected“
Odoo13 build a hospital HRP environment (detailed steps)
AES高級加密協議的動機闡述
xshell配置xforward转发火狐浏览器
从2022年Q1财报看携程的韧性和远景
Typical case of data annotation: how does jinglianwen technology help enterprises build data solutions