当前位置:网站首页>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 .
边栏推荐
- [pytoch foundation] torch.stack() function analysis
- Mysql -count :count(1)、count(*)、count(列名)的区别
- Use Baidu PaddlePaddle easydl to complete garbage classification
- Arm TZ hardware support
- [MySQL series] - how much do you know about the index
- Chapter 2: encounter obstacles! Bypass WAF filtering! [SQL injection attack]
- flask 源码梗概
- SSM整合实例
- Correlation analysis between [machine learning] variables
- Is it reliable, reliable and safe to open an account with a low commission for funds in Galaxy Securities
猜你喜欢

Sign up now: July 29 recommendation system summit 2022

【HarmonyOS议题资料下载】HDD杭州站·线下沙龙专注应用创新 展现鸿蒙生态魅力

串口通信失败

idea中设置核心配置文件的模板

牛客刷题——Mysql系列

QT基础第一天 (1)QT,GUI(图形用户接口)开发

idea中debug时如何进入指定的用户方法体中?

APaaS低代码平台(一) | 把复杂留给自己,把简单留给用户

Leetcode linked list problem - 19. Delete the penultimate node of the linked list (learn the linked list with one question and one article)

微服务化解决文库下载业务问题实践
随机推荐
测试用例千万不能随便,记录由一个测试用例异常引起的思考
【问题篇】浏览器get请求带token
How to enter the specified user method body when debugging in idea?
NVIDIA canvas first experience~
[Oracle training] - deploy Ogg known as zero downtime migration
Google's new programming language is called carbon
2022 pole technology communication - anmou technology opens a new chapter of commercialization
Practice of microservice in solving Library Download business problems
Transaction rollback and record exception information at the same time
没有网络怎么配置传奇SF登陆器自动读取列表
我们从Crypto市场中学到的最艰难一课
[英雄星球七月集训LeetCode解题日报] 第26日 并查集
【问题篇】将集合[‘‘,‘‘]处理成(‘‘,‘‘)
Monitor MySQL based on MySQL exporter
JVM learning - memory structure - program counter & virtual machine stack & local method stack & heap & method area
Deployment of kubernetes
Sign up now: July 29 recommendation system summit 2022
立即报名:7 月 29 日推荐系统峰会 2022
Shell comprehensive application cases, archive files
leetcode 数组类