Mistake on this page?
Report an issue in GitHub or email us
mpu_api.h
1 
2 /** \addtogroup hal */
3 /** @{*/
4 /* mbed Microcontroller Library
5  * Copyright (c) 2018-2018 ARM Limited
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 #ifndef MBED_MPU_API_H
20 #define MBED_MPU_API_H
21 
22 #include "device.h"
23 #include <stdbool.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #if DEVICE_MPU
30 
31 /**
32  * \defgroup hal_mpu MPU hal
33  *
34  * The MPU hal provides a simple MPU API to enhance device security by preventing
35  * execution from ram.
36  *
37  * # Defined behavior
38  * * The function ::mbed_mpu_init is safe to call repeatedly - Verified by ::mpu_init_test
39  * * The function ::mbed_mpu_free disables MPU protection - Verified by ::mpu_free_test
40  * * Execution from RAM results in a fault when execute never is enabled.
41  * This RAM includes heap, stack, data and zero init - Verified by ::mpu_fault_test_data,
42  * ::mpu_fault_test_bss, ::mpu_fault_test_stack and ::mpu_fault_test_heap.
43  * * Writing to ROM results in a fault when write never is enabled - Not verified
44  *
45  * # Undefined behavior
46  * * Calling any function other than ::mbed_mpu_init before the initialization of the MPU.
47  *
48  * @see hal_mpu_tests
49  *
50  * @{
51  */
52 
53 /**
54  * \defgroup hal_mpu_tests MPU hal tests
55  * The MPU test validates proper implementation of the MPU hal.
56  *
57  * To run the MPU hal tests use the command:
58  *
59  * mbed test -t <toolchain> -m <target> -n tests-mbed_hal-mpu*
60  */
61 
62 
63 /**
64  * Initialize the MPU
65  *
66  * Initialize or re-initialize the memory protection unit.
67  * After initialization or re-initialization, ROM and RAM protection
68  * are both enabled.
69  */
70 void mbed_mpu_init(void);
71 
72 /**
73  * Enable or disable ROM MPU protection
74  *
75  * This function is used to mark all of ROM as read and execute only.
76  * When enabled writes to ROM cause a fault.
77  *
78  * By default writes to ROM are disabled.
79  *
80  * @param enable true to disable writes to ROM, false otherwise
81  */
82 void mbed_mpu_enable_rom_wn(bool enable);
83 
84 /**
85  * Enable or disable ram MPU protection
86  *
87  * This function is used to mark all of RAM as execute never.
88  * When enabled code is only allowed to execute from flash.
89  *
90  * By default execution from RAM is disabled.
91  *
92  * @param enable true to disable execution from RAM, false otherwise
93  */
94 void mbed_mpu_enable_ram_xn(bool enable);
95 
96 /** Deinitialize the MPU
97  *
98  * Powerdown the MPU in preparation for powerdown, reset or jumping to another application.
99  */
100 void mbed_mpu_free(void);
101 
102 /**@}*/
103 
104 #else
105 
106 #define mbed_mpu_init()
107 
108 #define mbed_mpu_enable_rom_wn(enable) (void)enable
109 
110 #define mbed_mpu_enable_ram_xn(enable) (void)enable
111 
112 #define mbed_mpu_free()
113 
114 #endif
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif
121 
122 /** @}*/
void mbed_mpu_enable_ram_xn(bool enable)
Enable or disable ram MPU protection.
void mbed_mpu_enable_rom_wn(bool enable)
Enable or disable ROM MPU protection.
void mbed_mpu_init(void)
Initialize the MPU.
void mbed_mpu_free(void)
Deinitialize the MPU.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.