当前位置:网站首页>Efficient, reliable and safe open source solution for serial communication
Efficient, reliable and safe open source solution for serial communication
2022-07-26 05:29:00 【Uncle wheat】
Hello everyone , I'm wheat .
In embedded development , Serial communication is often used . Facing different application scenarios , Different solutions are needed .
Today, let's talk about efficiency , reliable , A safe solution , Remember to see the end , There will be gains .
Common are serial port polling mode , Serial port interrupt mode , A serial port DMA Receive, transmit, etc ;
Using serial port Idle interrupt coordination DMA Ring buffer mode , It can efficiently receive messages with variable length
In the figure below, after the Yellow high-level time is idle , An idle event will be generated ,IDLE EVENT

because DMA Functions include HC and TC interrupt ;
HC(Harf Complete)DMA Transmission half success flag ;TC(Total Complete) DMA Transmission completion success flag ;
for instance ;
As shown in the figure below , There's a... Assigned here DMA buffer , Size is 12 byte , If from the address 1 Start receiving , There will be the following two situations ;
DMA Received a second message 6 Bytes When , Will trigger HC event ;
DMA Received The first 12 Bytes When , Will trigger TC event ;

In fact, I have practiced this idea before , But they didn't make good use of HC and TC event .
So I can't handle this situation , namely DMA The buffer is in ring mode (Circular) When , The problem of data coverage , Recently I saw a great open source project , The idea here is very good , I'll give you a detailed introduction .
Here is DMA HC/DMA TC/Idle Details of serial port reception by combination , As shown in the figure below ;

Again, briefly introduce the meaning of abbreviations ;
RRead ;Wwrite in ;IIdle signal ;HTHalf-Transfer complete DMA Buffer half transfer complete ;TCTransfer-Complete DMA Buffer all receive complete ;
Here is a brief introduction situation E Solutions for , The small picture on the far right of the picture above ;
Buffer size 20 grid , It is assumed that 20 byte , situation E Need to receive 30 Bytes , in other words ,10 Bytes may be overwritten ;
After the first four receptions , The serial port continues from Letter R Receive data to DMA buffer ;
receive 4 Byte time , Will trigger
TCevent , At this time, you can 4 Byte data processing ;
First step Because it's a ring pattern , So go back to the first byte , Continue to receive 10 byte , Trigger
HTevent , You can deal with 10 Bytes of data ;
The second step The third step , Continue to receive 10 byte , Trigger
TCevent , among , There has been a 4 Bytes are overwritten ( The following figure is shown in orange ), Because this part of the data has been processed before , therefore , Even coverage does not affect ;
The third step Step four , The above has been received 24 Bytes , So there are 6 Bytes not received , Later reception will generate idle signal , And cover the previous data area , As shown in the figure below ;

therefore , It's not hard to find out , If only idle interrupts are used , The length of the received buffer is greater than the required data , There will be data coverage , And add DMA Of HT and TC interrupt , It perfectly solves such a problem ;
Except for that, of course , There are many excellent schemes , This project provides a large number of examples .
Project address :https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx

At present, this project mainly supports mainstream STM32 Testing on chip platform and some development boards DEMO, The details are as follows ;

The corresponding example program is as follows , In addition to bare metal programs , There is also a ring buffer to receive , Polling reception ,DMA+ Idle interrupts are based on RTOS Mode reception , It's rich , You can refer to it ;

The author in STM32F413-Nucleo The development board tests the program , Found that the optimization effect is very good ;
stay 115200 Baud rate of serial port , Send... Every second 1581 Bytes , about 142ms;
Don't use DMA,CPU load 14%;
Use DMA,CPU load 0%;
Last , This project is currently based on STM32CubeIDE Created , Remember to set up an environment . If you can't download , Official account back office reply 【 High efficiency serial port 】 Get project code .
Enjoy : )
Previous recommendation
Lightweight MCU command line interaction project , All open source
How to name the project version number ? It looks like a cow B
A trick to teach you to easily understand the potter chart
I also found excellent software and hardware projects , All open source
Built a lightweight Laboratory , It's delicious
边栏推荐
- 项目版本号怎么命名?看起来牛B
- 高频电子线路复习考试题及答案
- Redis 官方可视化工具,高颜值,功能真心强大!
- Common modules in ansible
- C语言-指针进阶
- Home VR panoramic display production to improve customer transformation
- Mongodb common commands
- OD-Paper【1】:Rich feature hierarchies for accurate object detection and semantic segmentation
- 提升命令行效率的 Bash 快捷键 [完整版]
- Trend of the times - the rise of cloud native databases
猜你喜欢

Basic methods of realizing licensing function in C language

动态内存管理及柔性数组

Getaverse,走向Web3的远方桥梁

Reason for pilot importerror: cannot import name 'pilot_ Version 'from' PIL ', how to install pilot < 7.0.0

Yolov3 preparatory work

Application and value of IVR in VoIP telephone system

mysql如果计算本月变动/本月增幅/同比变动/同比增幅?

没背景、没学历?专科测试员进入互联网大厂是不是真的没希望?

Attack and defense world flatscience

Leetcode linked list problem - 203. remove the linked list elements (learn the linked list by one question and one article)
随机推荐
没背景、没学历?专科测试员进入互联网大厂是不是真的没希望?
Week 6 Learning Representation: Word Embedding (symbolic →numeric)
代码审计之百家cms
学生如何申请免费IDEA
Qt编写物联网管理平台47-通用数据库设置
C language explanation series -- understanding of functions (3) formal parameters, arguments, nested calls and chain access
Flex layout principle and common parent elements
Webassembly 01 basic information
No background, no education? Is it really hopeless for specialist testers to enter Internet factories?
mysql如果计算本月变动/本月增幅/同比变动/同比增幅?
Bash shortcut key to improve command line efficiency [Full Version]
C language - Advanced pointer
项目版本号怎么命名?看起来牛B
又一开源神器,值得收藏学习!
OD-Paper【2】:Fast R-CNN
Hack the box -sql injection fundamentals module detailed Chinese tutorial
jupyter notebook快捷键
NetCore MySql The user specified as a definer (‘admin‘@‘%‘) does not exist
no networks found in /etc/cni/net.d
Recommended reading: how can testers get familiar with new businesses quickly?