当前位置:网站首页>Serial port communication failure
Serial port communication failure
2022-07-26 21:14:00 【Four seasons sail】
1. DMA Failure causes serial communication failure
1.1 background
Android The application layer passes through write Methods write serial port and MCU signal communication , If not received MCU Of ack Then rewrite the previously written information , Until received MCU Of ack;
bug Phenomenon is :Android The application layer has not received ack And constantly rewrite ,2 Minutes later write Method stuck .
1.2 analysis
After source code analysis , Think serial Layer of write Function may cause sleep , One of the buffer spaces is 4096 byte , The upper level passes through log Statistical discovery of the sent data , When data is sent accumulatively 4102 Bytes will get stuck .
Add log Reproduce and analyze , give the result as follows :

according to log You know , stay write When the method gets stuck, the last batch log Show uart_write The return value of the method is 0, If the upper application is blocking access , It will call schedule Method hibernate the current process, that is, the upper intuitive feeling is stuck .
Reference resources log Analyze the source code to know ,serial The ring buffer space of layer is full, resulting in bug Appearance ,serial Layer data to hardware TX_FIFO By DMA To carry , So preliminary estimates DMA There is a problem , towards SoC After consulting the manufacturer, the other party indicated , The SoC Of DMA There are some flaws .
Continue to add log Find out , exactly DMA There is a failure of not handling data , give the result as follows :

2. close DMA After that, the serial communication fails
2.1 background
Since last shutdown DMA in the future , In a specific scenario, the serial port communication with high frequency fails , The basic process is MCU to SoC Send a message , Then a frame of message will be lost , Which leads to Android Application upper layer verification failed , Judge communication failure .
For various reasons MCU The end shields the retransmission mechanism for this situation , So we need to SoC Look for reasons and solutions .
One noteworthy phenomenon is : The application layer finds , When the data read at one time is 32 Byte time , The next frame of data will be lost .
2.2 analysis
SoC Serial port hardware RX_FIFO Space, too 32 byte , The threshold set in the driver code is 16 byte , namely RX_FIFO In more than 16 Byte will trigger interrupt , remind CPU Transport data to tty layer , Combined with the phenomenon found in the application layer , The preliminary conclusion is RX_FIFO overflow .
SoC The serial port controller of has overflow flag bit , Add log Print , When communication failure is finally confirmed RX_FIFO It does overflow .
The basic judgment is UART Hardware interrupt priority is too low, resulting in delayed interrupt response , Which leads to RX_FIFO overflow .
2.3 terms of settlement
2.3.1 Adjust the threshold
Adjust the threshold of triggering serial port interrupt , There is some improvement after adjustment , But the frequency of overflow is still high , So this method pass fall .
2.3.2 Modify interrupt priority
Modifying interrupt priority has a wide range of influence , And SoC The manufacturer does not recommend modifying the interrupt priority , It is suggested to modify the interruption of kinship , So this method pass fall .
2.3.3 Modify interrupt affinity .
Mode one :
//1. Check the number corresponding to the interrupt
cat /proc/interrupts
······
59: 205 0 GIC 21e8000.serial
//2. Change the interrupt affinity of serial port from CPU0 Change to CPU1
echo 2 > /proc/irq/59/smp_affi nity
// Decimal system 2 Corresponding binary 0010, If you want to change to CPU2, You need to write 0100 Decimal system 4, however IMX6D Only 2 individual CPU The core , So set 4 It's invalid ( Don't take effect )Mode two :
Call in driver code irq_set_affinity() Bind the serial port interrupt to a CPU At the heart of it .
retval = request_irq(sport->port.irq, imx_int, 0,
dev_name(port->dev), sport);
irq_set_affinity(sport->port.irq, cpumask_of(2));By adjusting the interruption of kinship, it can only have a certain improvement , You can't 100% Solve this problem .
2.3.4 Add flow control
Flow control is divided into software flow control and hardware flow control , Personally, I prefer hardware flow control .
边栏推荐
- Buu brush inscription - WANGDING cup column 2
- 和月薪3W的字节程序员聊过后,才知道自己一直在打杂...
- 游览器——游览器游览器缓存
- 2022-7-26 the seventh group of abstractions and interfaces
- About: get the domain controller of the current client login
- Installation and configuration of [basic services] [database] Clickhouse
- Shell function, system function, basename [string / pathname] [suffix] can be understood as taking the file name in the path, dirname file absolute path, and user-defined function
- New features of ES6
- Sprinboot interview questions
- [MySQL series] - how much do you know about the index
猜你喜欢
![[MySQL series] - how much do you know about the index](/img/d7/5045a846580be106e2bf16d7b30581.png)
[MySQL series] - how much do you know about the index

How to block the legendary GEE engine version? Close player account tutorial through script + engine

08_ue4进阶_开始结束暂停菜单等ui

Shell comprehensive application cases, archive files
![Installation and configuration of [basic services] [database] Clickhouse](/img/fe/5c24e4c3dc17a6a96985e4fe97024e.png)
Installation and configuration of [basic services] [database] Clickhouse

【虚拟机数据恢复】意外断电导致XenServer虚拟机不可用的数据恢复
Monitor MySQL based on MySQL exporter

串口通信失败

Buu brush inscription 2

idea中设置核心配置文件的模板
随机推荐
How to create a static object variable of its own class?
[virtual machine data recovery] data recovery of XenServer virtual machine unavailable due to unexpected power failure
Leetcode hash table class
SSM整合实例
How to block the legendary GEE engine version? Close player account tutorial through script + engine
Beginner experience of safety testing
New features of ES6
Go+mysql+redis+vue3 simple chat room, bullet 5: synchronize messages to MySQL using message queues and scheduled tasks
[problem] process the set [','] into (',')
Sign up now: July 29 recommendation system summit 2022
使用 LSTM 进行多变量时间序列预测--问题汇总
LeetCode_ Backtracking_ Medium_ 216. Combined sum III
如何借助自动化工具落地DevOps|含低代码与DevOps应用实践
没有网络怎么配置传奇SF登陆器自动读取列表
We were tossed all night by a Kong performance bug
【问题篇】将集合[‘‘,‘‘]处理成(‘‘,‘‘)
AI technology, simplifying the complex world | teatalk online application practical series, issue 2
flask 源码梗概
Increased uncertainty in BTC and eth due to the approaching interest rate hike? The US economy will face more pain
Devsecops, speed and security