首页 > 其他分享 >rt-thread AT组件偶尔死机的问题

rt-thread AT组件偶尔死机的问题

时间:2024-06-01 09:03:01浏览次数:9  
标签:rt __ handle thread uart 死机 UART FLAG HAL

硬件信息

单片机 STM32L431CCT6

4G模组  EC800K-CN

rtt版本:4.1.1

 

 

第一个问题

主频太低不行,比如使用外部晶振8M时会发现at命令的返回收到的数据不完整,是由于处理器太慢和rt-thread 系统处理工作较多导致,测试发现至少16M主频以上才能良好运行

 

第二个问题

频繁通过串口发送数据时经常死机,仿真调试发现死机在下面等待标志的地方,主频越低越容易发生,当主频高的时候几率很小

 1 static int stm32_putc(struct rt_serial_device *serial, char c)
 2 {
 3     struct stm32_uart *uart;
 4     RT_ASSERT(serial != RT_NULL);
 5 
 6     uart = rt_container_of(serial, struct stm32_uart, serial);
 7     UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC);
 8 #if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0) \
 9     || defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) \
10     || defined(SOC_SERIES_STM32G4)
11     uart->handle.Instance->TDR = c;
12 #else
13     uart->handle.Instance->DR = c;
14 #endif
15     while (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) == RESET);
16     return 1;
17 }

经过查找资料需要在一下isr中断处理函数中注释掉黄底部分,经过测试可以解决问题,

 1 static void uart_isr(struct rt_serial_device *serial)
 2 {
 3     struct stm32_uart *uart;
 4 #ifdef RT_SERIAL_USING_DMA
 5     rt_size_t recv_total_index, recv_len;
 6     rt_base_t level;
 7 #endif
 8 
 9     RT_ASSERT(serial != RT_NULL);
10     uart = rt_container_of(serial, struct stm32_uart, serial);
11 
12     /* UART in mode Receiver -------------------------------------------------*/
13     if ((__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) &&
14             (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_RXNE) != RESET))
15     {
16         rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
17     }
18 #ifdef RT_SERIAL_USING_DMA
19     else if ((uart->uart_dma_flag) && (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_IDLE) != RESET)
20              && (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_IDLE) != RESET))
21     {
22         level = rt_hw_interrupt_disable();
23         recv_total_index = serial->config.bufsz - __HAL_DMA_GET_COUNTER(&(uart->dma_rx.handle));
24         recv_len = recv_total_index - uart->dma_rx.last_index;
25         uart->dma_rx.last_index = recv_total_index;
26         rt_hw_interrupt_enable(level);
27 
28         if (recv_len)
29         {
30             rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_DMADONE | (recv_len << 8));
31         }
32         __HAL_UART_CLEAR_IDLEFLAG(&uart->handle);
33     }
34     else if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) != RESET)
35     {
36         if ((serial->parent.open_flag & RT_DEVICE_FLAG_DMA_TX) != 0)
37         {
38             HAL_UART_IRQHandler(&(uart->handle));
39         }
40         else
41         {
42             UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC);
43         }
44     }
45 #endif
46     else
47     {
48         if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_ORE) != RESET)
49         {
50             __HAL_UART_CLEAR_OREFLAG(&uart->handle);
51         }
52         if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_NE) != RESET)
53         {
54             __HAL_UART_CLEAR_NEFLAG(&uart->handle);
55         }
56         if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_FE) != RESET)
57         {
58             __HAL_UART_CLEAR_FEFLAG(&uart->handle);
59         }
60         if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_PE) != RESET)
61         {
62             __HAL_UART_CLEAR_PEFLAG(&uart->handle);
63         }
64 #if !defined(SOC_SERIES_STM32L4) && !defined(SOC_SERIES_STM32F7) && !defined(SOC_SERIES_STM32F0) \
65     && !defined(SOC_SERIES_STM32L0) && !defined(SOC_SERIES_STM32G0) && !defined(SOC_SERIES_STM32H7) \
66     && !defined(SOC_SERIES_STM32G4)
67         if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_LBD) != RESET)
68         {
69             UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_LBD);
70         }
71 #endif
72         if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_CTS) != RESET)
73         {
74             UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_CTS);
75         }
76         if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TXE) != RESET)
77         {
78             UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TXE);
79         }
80         if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) != RESET)
81         {
82             //UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC);
83         }
84         if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET)
85         {
86             UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_RXNE);
87         }
88     }
89 }

资料链接:    https://blog.csdn.net/gmq_syy/article/details/108381854

 

标签:rt,__,handle,thread,uart,死机,UART,FLAG,HAL
From: https://www.cnblogs.com/arthurly/p/18225519

相关文章

  • ci3+smarty模仿开发出dedecms标签
    1、创建块函数functionsmarty_block_b_info($arr,$content,$repeat){  if($repeat){    $ci=&get_instance();    $res=$ci->db->get('val',$arr['limit'])->result_array();    $str='';    ......
  • 在 Crystal Reports 中,我有一个参数字段 + 2 年
    在CrystalReports中,我有一个参数字段供用户输入签发日期(IssuedDate?)我试过DateAdd('yyyy',2,(IssuedDate?))我试过想要在CrystalReports中将用户输入的签发日期(IssuedDate)加上两年吗?提供的公式DateAdd('yyyy',2,(IssuedDate?))非常接近正确......
  • Ubuntu server 24 (Linux) Snort3 3.2.1.0 Guardian IPtables 联动实战 主动防御系统(
    一  Snort3安装配置,参考:Ubuntuserver24安装配置snort33.2.1.0网络入侵检测防御系统配置注册规则集-CSDN博客二  安装主动防御程序Guardian1下载,解压tarzxvfguardian-1.7.tar.gzcdguardian-1.7/2 配置#拷贝文件sudocpguardian.pl/usr/local/bin/......
  • 代码审计(工具Fortify 、Seay审计系统安装及漏洞验证)
    源代码审计代码安全测试简介    代码安全测试是从安全的角度对代码进行的安全测试评估。(白盒测试;可看到源代码)    结合丰富的安全知识、编程经验、测试技术,利用静态分析和人工审核的方法寻找代码在架构和编码上的安全缺陷,在代码形成软件产品前将业务软件的安......
  • const filePath = fileURLToPath(new URL('plopfile.js', import.meta.url)); 解释一
    这段代码的作用是获取当前文件所在目录下的plopfile.js文件的绝对路径。这里是逐步解释:import.meta.url:这是ESModules中的一个元属性,它提供了当前模块的绝对URL。在Node.js环境中,当你在一个模块文件中访问import.meta.url时,它会返回该模块文件的文件系统路径转换成的URL格......
  • 前端学习-Dart官方文档学习-005-控制流
    官方文档链接Loops循环forloopswhileanddowhileloopsbreakandcontinueBranching,likeifandswitchExceptions,liketry,catch,andthrowfor、for-in、forEachvarcallbacks=[];for(vari=0;i<2;i++){callbacks.add(()=>print(i));}//Th......
  • 反单引号在vue文件的alert中怎么换行
    在alert里面将dangerouslyUseHTMLString开启设置为true,这样子就可以使用html中的来进行换行了但是,message属性虽然支持传入HTML片段,但是在网站上动态渲染任意HTML是非常危险的,因为容易导致XSS攻击。因此在dangerouslyUseHTMLString打开的情况下,请确保message的内容......
  • ThreadLocal使用过程中要注意哪些事项
    在使用ThreadLocal过程中,需要注意以下几个关键事项以确保正确和高效地使用这一工具:内存泄漏预防:ThreadLocal变量在不再使用时应及时调用remove()方法清理,避免因为ThreadLocal对象的引用链没有断开而导致的内存泄漏。特别是在线程池环境中,线程会被复用,如果不清理,之前线程绑定......
  • Dart语言基础
    简介基于Dart语言,跨平台(移动端-Android-iOS/Web-各种浏览器/桌面-Windows-Mac/嵌入式平台-Linux-Fuchsia和高性能(GPU图形渲染技术)可达到120fps(胜任游戏)flutter中文文档Dart概述Dart强类型的,面向对象的编程语言运行方式一种是原生虚拟机,另一种是Dart转成js代码运行在浏览器Da......
  • nginx 搭建 rtmp
       1.解压nginx1.7.11.3Gryphon.zip->解压nginx-rtmp-module-master.zip将nginx-rtmp-module-master文件名修改为nginx-rtmp-module并移动到nginx1.7.11.3Gryphon在nginx1.7.11.3Gryphon/config里面新建文件nginx.conf内容如下: nginx.confworke......