当前位置:网站首页>Why does RTOS system use MPU?
Why does RTOS system use MPU?
2022-07-02 23:13:00 【strongerHuang】
Focus on + Star sign public Number , Don't miss the highlights
author | strongerHuang
WeChat official account | strongerHuang
Let's start with MPU,MPU There are many meanings , We often have :
MPU:Memory Protection Unit, Memory protection unit ( What this article describes );
MPU:Microprocessor Unit, Microprocessor ;
also , Maybe someone will talk to MPU-6050 These kinds of modules are linked together . therefore , Please don't MPU Confused. .
Why use MPU?
If you develop embedded projects , Due to memory overflow , Or memory failure and other reasons , It has caused great economic losses , Or cause a major accident , You can see why you use memory protection units (MPU) 了 .
Using memory protection unit in embedded system (MPU) It can find out the problems caused by memory in the early stage of development Bug, Save more development time .
meanwhile , Modify later in the project Bug, Or add features , It can reduce the time required to modify documents and test .
in other words , Use MPU, It will avoid changing a bug, And caused many problems bug The situation of (0 raw 1,1 All living things ).
MPU How to implement memory protection
In short, it is to protect all data that is not related to the code being executed .
take RTOS Mission A and B Come on :
Mission A and B Data should not be exchanged with each other , But there is a mistake , Mission A You may accidentally write tasks B Some data used occasionally , It won't affect the mission A The correct operation of . however , When tasks B When trying to use corrupted data , Mission B There may be unexpected failures .
If not configured MPU To stop the mission A Write tasks B The data of , The error may take a long time for developers to track . If the error is small , Or if the mission B This data is rarely used , It will be difficult to solve the problem bug. however , If used MPU, Then bug It will be discovered early .
In some architectures ,MPU It can even help you detect NULL Pointer reference , Because you can set up MPU Area to prevent non privileged code from accessing memory 0x0.
A well-designed set of MPU Area can protect important memory area very well , To prevent specific problems .
A good example is through MPU A buffer is placed at the end of the zone to prevent buffer overflow , You can also place the task stack in an area that no non privileged code can access . If you do , Then each task must use its own MPU One of the zones sets its own access to its own stack .
Use MPU The benefits of
Whether it's the operating system , Or bare metal systems , Without the ability to prevent malicious access to the wrong memory , There will be major security issues with the system , And minefields of security vulnerabilities .
Memory protection unit used (MPU) There are many advantages ,MPU You are usually allowed to run in privileged or non privileged mode , And use a set of “ Area ” To determine whether the currently executing code has access to code and data .
Each area is a contiguous block of memory , Has a set of permissions for that memory , Privileged and non privileged access . Compared to a subset of non privileged code , Privileged code often has access to most of the ( But not all ) Memory .
In the whole system runtime , These areas don't have to be the same .MPU Areas can be modified for each task , Each task can have its own unique region set , These areas are configured when the task moves to the running state .
This allows you to set access only to tasks that require code and data , utilize MPU The embedded operating system will manage the region and privilege level of each task during each context switch .
Setting up RTOS Two tasks have different memory protection areas :
The picture above , Everyone can understand it ?Flash And memory areas are protected separately .
Two global protected areas :Flash start 、RAM start ;
stay Flash in , Part of it is mission only 1 visit , This part cannot be accessed by the task ; meanwhile , stay Flash Another area , Mission only 2 visit , Can't be tasked 1 visit . If these two areas are visited by each other , Will generate MPU fault .
stay RAM Area , The same part of the area , One can only be read , One can only be written to , If you don't follow the agreement , It also produces MPU fault .
When not to use MPU?
There are usually two situations in which you don't need to use the MPU function :
A simple project
A performance critical project
The first 1 It's very simple : A very simple application is basically unnecessary to use MPU, Instead, it increases the complexity of the system . No memory protection ,RAM And peripherals MPU Area , You can find it at a glance bug.
The first 2 A high performance project , When context switches , Set memory protection , Stack those operations , It may affect the real-time performance of the system , This leads to system exception . This needs to be considered in combination with the actual situation of the project , Or not MPU function .
------------ END ------------
● special column 《 Embedded tools 》
● special column 《 Embedded development 》
● special column 《Keil course 》
● Embedded column selection tutorial
Pay attention to the reply of the official account “ Add group ” Join the technical exchange group according to the rules , reply “1024” See more .
Click on “ Read the original ” See more sharing .
边栏推荐
- Methods to solve the tampering of Chrome browser and edeg browser homepage
- Mask R-CNN
- QT qpprogressbar details
- Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
- 1px pixel compatibility of mobile terminal, 1px border
- 地平线2022年4月最新方案介绍
- Xshell configuration xforward forwarding Firefox browser
- 创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
- 4 special cases! Schools in area a adopt the re examination score line in area B!
- Webrtc audio and video capture and playback examples and mediastream media stream analysis
猜你喜欢
力扣刷题(2022-6-28)
ServletContext learning diary 1
Methods to solve the tampering of Chrome browser and edeg browser homepage
Niuke network: maximum submatrix
[chestnut sugar GIS] ArcScene - how to make elevation map with height
程序员版本的八荣八耻~
设置单击右键可以选择用VS Code打开文件
情感对话识别与生成简述
Use of recyclerview with viewbinding
Deep analysis of data storage in memory - C language
随机推荐
[favorite poems] OK, song
Easyclick, EC Quanlang network verification source code
4 special cases! Schools in area a adopt the re examination score line in area B!
容器化技术在嵌入式领域的应用
密码技术---密钥和SSL/TLS
[hardware] origin of standard resistance value
Li Kou brush questions (2022-6-28)
QT qpprogressbar details
移动端 1px 像素兼容性问题,实现1px 边框
密码技术---分组密码的模式
海思3559万能平台搭建:在截获的YUV图像上旋转操作
The motivation of AES Advanced Encryption Protocol
Chow-Liu Tree
Distributed monitoring system ZABBIX
Niuke network: maximum submatrix
剑指 Offer II 099. 最小路径之和-双百代码
数据标注典型案例,景联文科技如何助力企业搭建数据方案
Typical case of data annotation: how does jinglianwen technology help enterprises build data solutions
分布式监控系统zabbix
20220527_ Database process_ Statement retention