当前位置:网站首页>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 .
边栏推荐
- 泛型与反射,看这篇就够了
- Stop slave is stuck -- the event of the transaction is not copied completely
- Lambda expression: an article takes you through
- 阿里云有奖体验:如何使用 PolarDB-X
- 剑指 Offer II 099. 最小路径之和-双百代码
- MySQL queries nearby data And sort by distance
- antd组件upload上传xlsx文件,并读取文件内容
- Redis expiration policy +conf record
- 为什么RTOS系统要使用MPU?
- SQL进阶语法
猜你喜欢

Introduction to the latest plan of horizon in April 2022
![[adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)](/img/a3/d8421ea1539eba08bf7a5a629d92e6.jpg)
[adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)

Motivation du Protocole de chiffrement avancé AES

程序员版本的八荣八耻~

LeetCode 968. Monitor binary tree

China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!

Win11自动关机设置在哪?Win11设置自动关机的两种方法

详解Promise使用

抖音实战~点赞数量弹框

Mask R-CNN
随机推荐
2016. maximum difference between incremental elements
Antd component upload uploads xlsx files and reads the contents of the files
Cryptographic technology -- key and ssl/tls
Webrtc audio and video capture and playback examples and mediastream media stream analysis
深度剖析数据在内存中的存储----C语言篇
Motivation du Protocole de chiffrement avancé AES
golang入门:for...range修改切片中元素的值的另类方法
为什么RTOS系统要使用MPU?
20220524_数据库过程_语句留档
FOC矢量控制及BLDC控制中的端电压、相电压、线电压等概念别还傻傻分不清楚
ADC of stm32
Minimum spanning tree
潘多拉 IOT 开发板学习(HAL 库)—— 实验4 串口通讯实验(学习笔记)
Numerical solution of partial differential equations with MATLAB
Construction of Hisilicon 3559 universal platform: draw a frame on the captured YUV image
Jerry's built-in short press and long press, no matter how long it is, it is a short press [chapter]
Detailed explanation and application of merging and sorting
The difference between new and make in golang
Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
Learning records of data analysis (II) -- simple use of response surface method and design expert