当前位置:网站首页>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
边栏推荐
- 87. Disturb string
- 三本毕业,三年嵌入式软件的心路历程
- 【STM32系列汇总】博主的STM32实战快速进阶之路(持续更新)
- Chinese character style transfer --- learn the conversion and generation of one to many programmed Chinese characters through generation confrontation network
- Redis 官方可视化工具,高颜值,功能真心强大!
- C语言实现发牌功能基本方法
- 测试必备工具之Fiddler,你真的了解吗?
- 新人如何做好功能测试,学会这几项够用了
- Code audit CMS
- C language function
猜你喜欢

又一开源神器,值得收藏学习!

SSH远程管理

FPGA question brushing sequence detection

一招教你轻松看懂波特图

代码审计之百家cms

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

SAP report development steps

Trend of the times - the rise of cloud native databases

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

动态内存管理及柔性数组
随机推荐
Migrate the server and reconfigure the database (the database has no monitoring, and the monitoring starts with tns-12545, tns-12560, tns-00515 errors)
第二讲 初识SLAM
高分子物理试题库
SAP report development steps
It's enough for newcomers to learn how to do functional tests
ALV report flow diagram
代码审计之百家cms
No EGL Display 报错解决
Chinese character style transfer --- learn the conversion and generation of one to many programmed Chinese characters through generation confrontation network
Development to testing: a six-year road to automation from scratch
Simulation of future air pollution changes
Hack The Box - Web Requests Module详细讲解中文教程
NetCore MySql The user specified as a definer (‘admin‘@‘%‘) does not exist
Use flutter to adjust a color filter for the picture of my little sister
虚拟偶像代言产品出问题谁负责? 且听律师分析
MySQL optimization
Qt编写物联网管理平台47-通用数据库设置
新人如何做好功能测试,学会这几项够用了
【STM32系列汇总】博主的STM32实战快速进阶之路(持续更新)
Ansible中常用的模块