当前位置:网站首页>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
边栏推荐
- Shell process control (emphasis), if judgment, case statement, let usage, for ((initial value; loop control condition; variable change)) and for variable in value 1 value 2 value 3..., while loop
- SSH Remote Management
- DOM event flow event bubble event capture event delegate
- MongoDB 常用命令
- ALV program collection
- YOLOV3预备工作
- Common solutions for distributed ID - take one
- Flex layout principle and common parent elements
- 高效,可靠,安全的串口通讯开源方案
- STL common template library
猜你喜欢

Leetcode linked list problem - 203. remove the linked list elements (learn the linked list by one question and one article)

Common modules in ansible

我又发现了超赞的软硬件项目,全部开源

Knowledge points of Polymer Physics

No background, no education? Is it really hopeless for specialist testers to enter Internet factories?

Yolov3 preparatory work

NetCore MySql The user specified as a definer (‘admin‘@‘%‘) does not exist

Three implementation methods of thread and the usage of handler

如何从内存解析的角度理解“数组名实质是一个地址”?

IVR在voip电话系统的应用与价值
随机推荐
如何从内存解析的角度理解“数组名实质是一个地址”?
Getting started with ALV
【STM32系列汇总】博主的STM32实战快速进阶之路(持续更新)
家居vr全景展示制作提高客户转化
Thread三种实现方式 和 Handler的用法
Embedded development notes, practical knowledge sharing
FTP实验及概述
Mongodb common commands
Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
Circular structure practice
提升命令行效率的 Bash 快捷键 [完整版]
SSH远程管理
Map making of environmental impact assessment based on remote sensing interpretation and GIS technology
LNMP architecture
Use flutter to adjust a color filter for the picture of my little sister
C语言-指针进阶
Uniapp applet framework - a set of code, multi segment coverage
Ansible中常用的模块
TZC 1283: simple sorting - function method
OD-Paper【1】:Rich feature hierarchies for accurate object detection and semantic segmentation