]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/Core/src/Ref_MPU8.txt
Update Ref_PMU8.txt
[cmsis] / CMSIS / DoxyGen / Core / src / Ref_MPU8.txt
1 /**
2 \defgroup mpu8_functions  MPU Functions for Armv8-M
3 \brief Functions that relate to the Memory Protection Unit.
4 \details
5 The following functions support the optional Memory Protection Unit (MPU) that is available on the Cortex-M23, M33, M35P processor.
6
7 The MPU is used to prevent from illegal memory accesses that are typically caused by errors in an application software.
8
9 <b>Example:</b>
10 \code
11 void main() 
12 {
13   // Set Region 0 using Attr 0
14   ARM_MPU_SetMemAttr(0UL, ARM_MPU_ATTR(       /* Normal memory */
15     ARM_MPU_ATTR_MEMORY_(0UL, 1UL, 1UL, 1UL), /* Outer Write-Back transient with read and write allocate */
16     ARM_MPU_ATTR_MEMORY_(0UL, 0UL, 1UL, 1UL)  /* Inner Write-Through transient with read and write allocate */
17   ));
18   
19   ARM_MPU_SetRegion(0UL,
20     ARM_MPU_RBAR(0x08000000UL, ARM_MPU_SH_NON, 0UL, 1UL, 1UL),  /* Non-shareable, read/write, non-privileged, execute-never */
21     ARM_MPU_RLAR(0x080FFFFFUL, 0UL)                             /* 1MB memory block using Attr 0 */
22   );
23   
24   ARM_MPU_Enable(0);
25   
26   // Execute application code that is access protected by the MPU
27   
28   ARM_MPU_Disable();
29 }
30 \endcode
31
32 @{
33 */
34
35 /** \brief Attribute for device memory (outer only) */
36 #define ARM_MPU_ATTR_DEVICE                           ( 0U )
37
38 /** \brief Attribute for non-cacheable, normal memory */
39 #define ARM_MPU_ATTR_NON_CACHEABLE                    ( 4U )
40
41 /** \brief Attribute for normal memory (outer and inner)
42 * \param NT Non-Transient: Set to 1 for non-transient data.
43 * \param WB Write-Back: Set to 1 to use write-back update policy.
44 * \param RA Read Allocation: Set to 1 to use cache allocation on read miss.
45 * \param WA Write Allocation: Set to 1 to use cache allocation on write miss.
46 */
47 #define ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA)
48
49 /** \brief Device memory type non Gathering, non Re-ordering, non Early Write Acknowledgement */
50 #define ARM_MPU_ATTR_DEVICE_nGnRnE 
51
52 /** \brief Device memory type non Gathering, non Re-ordering, Early Write Acknowledgement */
53 #define ARM_MPU_ATTR_DEVICE_nGnRE
54
55 /** \brief Device memory type non Gathering, Re-ordering, Early Write Acknowledgement */
56 #define ARM_MPU_ATTR_DEVICE_nGRE
57
58 /** \brief Device memory type Gathering, Re-ordering, Early Write Acknowledgement */
59 #define ARM_MPU_ATTR_DEVICE_GRE
60
61 /** \brief Memory Attribute
62 * \param O Outer memory attributes
63 * \param I O == ARM_MPU_ATTR_DEVICE: Device memory attributes, else: Inner memory attributes
64 */
65 #define ARM_MPU_ATTR(O, I)
66
67 /** \brief Normal memory non-shareable  */
68 #define ARM_MPU_SH_NON
69
70 /** \brief Normal memory outer shareable  */
71 #define ARM_MPU_SH_OUTER
72
73 /** \brief Normal memory inner shareable  */
74 #define ARM_MPU_SH_INNER
75
76 /** \brief Memory access permissions
77 * \param RO Read-Only: Set to 1 for read-only memory.
78 * \param NP Non-Privileged: Set to 1 for non-privileged memory.
79 */
80 #define ARM_MPU_AP_(RO, NP)
81
82 /** \brief Region Base Address Register value
83 * \param BASE The base address bits [31:5] of a memory region. The value is zero extended. Effective address gets 32 byte aligned.
84 * \param SH Defines the Shareability domain for this memory region.
85 * \param RO Read-Only: Set to 1 for a read-only memory region.
86 * \param NP Non-Privileged: Set to 1 for a non-privileged memory region.
87 * \param XN eXecute Never: Set to 1 for a non-executable memory region.
88 */
89 #define ARM_MPU_RBAR(BASE, SH, RO, NP, XN) \
90   ((BASE & MPU_RBAR_BASE_Msk) | \
91   ((SH << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \
92   ((ARM_MPU_AP_(RO, NP) << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk) | \
93   ((XN << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk))
94
95 /** \brief Region Limit Address Register value
96 * \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended.
97 * \param IDX The attribute index to be associated with this memory region.
98 */
99 #define ARM_MPU_RLAR(LIMIT, IDX)
100
101 /**
102 * Struct for a single MPU Region
103 */
104 typedef struct {
105   uint32_t RBAR;                   /*!< Region Base Address Register value */
106   uint32_t RLAR;                   /*!< Region Limit Address Register value */
107 } ARM_MPU_Region_t;
108     
109 /** Enable the MPU.
110 * \param MPU_Control Default access permissions for unconfigured regions.
111 */
112 __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control);
113
114 /** Disable the MPU.
115 */
116 __STATIC_INLINE void ARM_MPU_Disable(void);
117
118 /** Enable the Non-secure MPU.
119 * \param MPU_Control Default access permissions for unconfigured regions.
120 */
121 __STATIC_INLINE ARM_MPU_Enable_NS(uint32_t MPU_Control);
122
123 /** Disable the Non-secure MPU.
124 */
125 __STATIC_INLINE void ARM_MPU_Disable_NS(void);
126
127 /** Set the memory attribute encoding to the given MPU.
128 * \param mpu Pointer to the MPU to be configured.
129 * \param idx The attribute index to be set [0-7]
130 * \param attr The attribute value to be set.
131 */
132 __STATIC_INLINE void ARM_MPU_SetMemAttrEx(MPU_Type* mpu, uint8_t idx, uint8_t attr);
133
134 /** Set the memory attribute encoding.
135 * \param idx The attribute index to be set [0-7]
136 * \param attr The attribute value to be set.
137 */
138 __STATIC_INLINE void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr);
139
140 /** Set the memory attribute encoding to the Non-secure MPU.
141 * \param idx The attribute index to be set [0-7]
142 * \param attr The attribute value to be set.
143 */
144 __STATIC_INLINE void ARM_MPU_SetMemAttr_NS(uint8_t idx, uint8_t attr);
145
146 /** Clear and disable the given MPU region of the given MPU.
147 * \param mpu Pointer to MPU to be used.
148 * \param rnr Region number to be cleared.
149 */
150 __STATIC_INLINE void ARM_MPU_ClrRegionEx(MPU_Type* mpu, uint32_t rnr);
151
152 /** Clear and disable the given MPU region.
153 * \param rnr Region number to be cleared.
154 */
155 __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr);
156
157 /** Clear and disable the given Non-secure MPU region.
158 * \param rnr Region number to be cleared.
159 */
160 __STATIC_INLINE void ARM_MPU_ClrRegion_NS(uint32_t rnr);
161
162 /** Configure the given MPU region of the given MPU.
163 * \param mpu Pointer to MPU to be used.
164 * \param rnr Region number to be configured.
165 * \param rbar Value for RBAR register.
166 * \param rlar Value for RLAR register.
167 */   
168 __STATIC_INLINE void ARM_MPU_SetRegionEx(MPU_Type* mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar);
169
170 /** Configure the given MPU region.
171 * \param rnr Region number to be configured.
172 * \param rbar Value for RBAR register.
173 * \param rlar Value for RLAR register.
174 */   
175 __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rlar);
176
177 /** Configure the given Non-secure MPU region.
178 * \param rnr Region number to be configured.
179 * \param rbar Value for RBAR register.
180 * \param rlar Value for RLAR register.
181 */   
182 __STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t rlar);
183
184 /** Memcopy with strictly ordered memory access, e.g. for register targets.
185 * \param dst Destination data is copied to.
186 * \param src Source data is copied from.
187 * \param len Amount of data words to be copied.
188 */
189 __STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len);
190
191 /** Load the given number of MPU regions from a table to the given MPU.
192 * \param mpu Pointer to the MPU registers to be used.
193 * \param rnr First region number to be configured.
194 * \param table Pointer to the MPU configuration table.
195 * \param cnt Amount of regions to be configured.
196 */
197 __STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type* mpu, uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt);
198
199 /** Load the given number of MPU regions from a table.
200 * \param rnr First region number to be configured.
201 * \param table Pointer to the MPU configuration table.
202 * \param cnt Amount of regions to be configured.
203 *
204 * <b>Example:</b>
205 * \code
206 * const ARM_MPU_Region_t mpuTable[1][4] = {
207 *   {
208 *     //                     BASE          SH              RO   NP   XN                         LIMIT         ATTR 
209 *     { .RBAR = ARM_MPU_RBAR(0x08000000UL, ARM_MPU_SH_NON, 0UL, 1UL, 0UL), .RLAR = ARM_MPU_RLAR(0x080FFFFFUL, 0UL) },
210 *     { .RBAR = ARM_MPU_RBAR(0x20000000UL, ARM_MPU_SH_NON, 0UL, 1UL, 1UL), .RLAR = ARM_MPU_RLAR(0x20007FFFUL, 0UL) },
211 *     { .RBAR = ARM_MPU_RBAR(0x40020000UL, ARM_MPU_SH_NON, 0UL, 1UL, 1UL), .RLAR = ARM_MPU_RLAR(0x40021FFFUL, 1UL) },
212 *     { .RBAR = ARM_MPU_RBAR(0x40022000UL, ARM_MPU_SH_NON, 0UL, 1UL, 1UL), .RLAR = ARM_MPU_RLAR(0x40022FFFUL, 1UL) }
213 *   }
214 * };
215 *  
216 * void UpdateMpu(uint32_t idx)
217 * {
218 *    ARM_MPU_Load(0, mpuTable[idx], 4);
219 * }
220 * \endcode
221 */
222 __STATIC_INLINE void ARM_MPU_Load(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt);
223
224 /** Load the given number of MPU regions from a table to the Non-secure MPU.
225 * \param rnr First region number to be configured.
226 * \param table Pointer to the MPU configuration table.
227 * \param cnt Amount of regions to be configured.
228 */
229 __STATIC_INLINE void ARM_MPU_Load_NS(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt);
230
231 /** @} */
232