//

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

硬件信息

单片机 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

 

posted @ 2024-06-01 07:12  一只鱼在水杯里  阅读(336)  评论(0)    收藏  举报