The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_SDT51822B/TOOLCHAIN_IAR/mpu_armv7.h@171:3a7713b1edbc, 2018-11-08 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Nov 08 11:45:42 2018 +0000
- Revision:
- 171:3a7713b1edbc
mbed library. Release version 164
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 171:3a7713b1edbc | 1 | /****************************************************************************** |
AnnaBridge | 171:3a7713b1edbc | 2 | * @file mpu_armv7.h |
AnnaBridge | 171:3a7713b1edbc | 3 | * @brief CMSIS MPU API for Armv7-M MPU |
AnnaBridge | 171:3a7713b1edbc | 4 | * @version V5.0.5 |
AnnaBridge | 171:3a7713b1edbc | 5 | * @date 06. September 2018 |
AnnaBridge | 171:3a7713b1edbc | 6 | ******************************************************************************/ |
AnnaBridge | 171:3a7713b1edbc | 7 | /* |
AnnaBridge | 171:3a7713b1edbc | 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. |
AnnaBridge | 171:3a7713b1edbc | 9 | * |
AnnaBridge | 171:3a7713b1edbc | 10 | * SPDX-License-Identifier: Apache-2.0 |
AnnaBridge | 171:3a7713b1edbc | 11 | * |
AnnaBridge | 171:3a7713b1edbc | 12 | * Licensed under the Apache License, Version 2.0 (the License); you may |
AnnaBridge | 171:3a7713b1edbc | 13 | * not use this file except in compliance with the License. |
AnnaBridge | 171:3a7713b1edbc | 14 | * You may obtain a copy of the License at |
AnnaBridge | 171:3a7713b1edbc | 15 | * |
AnnaBridge | 171:3a7713b1edbc | 16 | * www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 171:3a7713b1edbc | 17 | * |
AnnaBridge | 171:3a7713b1edbc | 18 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 171:3a7713b1edbc | 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
AnnaBridge | 171:3a7713b1edbc | 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 171:3a7713b1edbc | 21 | * See the License for the specific language governing permissions and |
AnnaBridge | 171:3a7713b1edbc | 22 | * limitations under the License. |
AnnaBridge | 171:3a7713b1edbc | 23 | */ |
AnnaBridge | 171:3a7713b1edbc | 24 | |
AnnaBridge | 171:3a7713b1edbc | 25 | #if defined ( __ICCARM__ ) |
AnnaBridge | 171:3a7713b1edbc | 26 | #pragma system_include /* treat file as system include file for MISRA check */ |
AnnaBridge | 171:3a7713b1edbc | 27 | #elif defined (__clang__) |
AnnaBridge | 171:3a7713b1edbc | 28 | #pragma clang system_header /* treat file as system include file */ |
AnnaBridge | 171:3a7713b1edbc | 29 | #endif |
AnnaBridge | 171:3a7713b1edbc | 30 | |
AnnaBridge | 171:3a7713b1edbc | 31 | #ifndef ARM_MPU_ARMV7_H |
AnnaBridge | 171:3a7713b1edbc | 32 | #define ARM_MPU_ARMV7_H |
AnnaBridge | 171:3a7713b1edbc | 33 | |
AnnaBridge | 171:3a7713b1edbc | 34 | #define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) ///!< MPU Region Size 32 Bytes |
AnnaBridge | 171:3a7713b1edbc | 35 | #define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) ///!< MPU Region Size 64 Bytes |
AnnaBridge | 171:3a7713b1edbc | 36 | #define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) ///!< MPU Region Size 128 Bytes |
AnnaBridge | 171:3a7713b1edbc | 37 | #define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) ///!< MPU Region Size 256 Bytes |
AnnaBridge | 171:3a7713b1edbc | 38 | #define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) ///!< MPU Region Size 512 Bytes |
AnnaBridge | 171:3a7713b1edbc | 39 | #define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) ///!< MPU Region Size 1 KByte |
AnnaBridge | 171:3a7713b1edbc | 40 | #define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) ///!< MPU Region Size 2 KBytes |
AnnaBridge | 171:3a7713b1edbc | 41 | #define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) ///!< MPU Region Size 4 KBytes |
AnnaBridge | 171:3a7713b1edbc | 42 | #define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) ///!< MPU Region Size 8 KBytes |
AnnaBridge | 171:3a7713b1edbc | 43 | #define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) ///!< MPU Region Size 16 KBytes |
AnnaBridge | 171:3a7713b1edbc | 44 | #define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) ///!< MPU Region Size 32 KBytes |
AnnaBridge | 171:3a7713b1edbc | 45 | #define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) ///!< MPU Region Size 64 KBytes |
AnnaBridge | 171:3a7713b1edbc | 46 | #define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) ///!< MPU Region Size 128 KBytes |
AnnaBridge | 171:3a7713b1edbc | 47 | #define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) ///!< MPU Region Size 256 KBytes |
AnnaBridge | 171:3a7713b1edbc | 48 | #define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) ///!< MPU Region Size 512 KBytes |
AnnaBridge | 171:3a7713b1edbc | 49 | #define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) ///!< MPU Region Size 1 MByte |
AnnaBridge | 171:3a7713b1edbc | 50 | #define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) ///!< MPU Region Size 2 MBytes |
AnnaBridge | 171:3a7713b1edbc | 51 | #define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) ///!< MPU Region Size 4 MBytes |
AnnaBridge | 171:3a7713b1edbc | 52 | #define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) ///!< MPU Region Size 8 MBytes |
AnnaBridge | 171:3a7713b1edbc | 53 | #define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) ///!< MPU Region Size 16 MBytes |
AnnaBridge | 171:3a7713b1edbc | 54 | #define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) ///!< MPU Region Size 32 MBytes |
AnnaBridge | 171:3a7713b1edbc | 55 | #define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) ///!< MPU Region Size 64 MBytes |
AnnaBridge | 171:3a7713b1edbc | 56 | #define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) ///!< MPU Region Size 128 MBytes |
AnnaBridge | 171:3a7713b1edbc | 57 | #define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) ///!< MPU Region Size 256 MBytes |
AnnaBridge | 171:3a7713b1edbc | 58 | #define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) ///!< MPU Region Size 512 MBytes |
AnnaBridge | 171:3a7713b1edbc | 59 | #define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) ///!< MPU Region Size 1 GByte |
AnnaBridge | 171:3a7713b1edbc | 60 | #define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) ///!< MPU Region Size 2 GBytes |
AnnaBridge | 171:3a7713b1edbc | 61 | #define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) ///!< MPU Region Size 4 GBytes |
AnnaBridge | 171:3a7713b1edbc | 62 | |
AnnaBridge | 171:3a7713b1edbc | 63 | #define ARM_MPU_AP_NONE 0U ///!< MPU Access Permission no access |
AnnaBridge | 171:3a7713b1edbc | 64 | #define ARM_MPU_AP_PRIV 1U ///!< MPU Access Permission privileged access only |
AnnaBridge | 171:3a7713b1edbc | 65 | #define ARM_MPU_AP_URO 2U ///!< MPU Access Permission unprivileged access read-only |
AnnaBridge | 171:3a7713b1edbc | 66 | #define ARM_MPU_AP_FULL 3U ///!< MPU Access Permission full access |
AnnaBridge | 171:3a7713b1edbc | 67 | #define ARM_MPU_AP_PRO 5U ///!< MPU Access Permission privileged access read-only |
AnnaBridge | 171:3a7713b1edbc | 68 | #define ARM_MPU_AP_RO 6U ///!< MPU Access Permission read-only access |
AnnaBridge | 171:3a7713b1edbc | 69 | |
AnnaBridge | 171:3a7713b1edbc | 70 | /** MPU Region Base Address Register Value |
AnnaBridge | 171:3a7713b1edbc | 71 | * |
AnnaBridge | 171:3a7713b1edbc | 72 | * \param Region The region to be configured, number 0 to 15. |
AnnaBridge | 171:3a7713b1edbc | 73 | * \param BaseAddress The base address for the region. |
AnnaBridge | 171:3a7713b1edbc | 74 | */ |
AnnaBridge | 171:3a7713b1edbc | 75 | #define ARM_MPU_RBAR(Region, BaseAddress) \ |
AnnaBridge | 171:3a7713b1edbc | 76 | (((BaseAddress) & MPU_RBAR_ADDR_Msk) | \ |
AnnaBridge | 171:3a7713b1edbc | 77 | ((Region) & MPU_RBAR_REGION_Msk) | \ |
AnnaBridge | 171:3a7713b1edbc | 78 | (MPU_RBAR_VALID_Msk)) |
AnnaBridge | 171:3a7713b1edbc | 79 | |
AnnaBridge | 171:3a7713b1edbc | 80 | /** |
AnnaBridge | 171:3a7713b1edbc | 81 | * MPU Memory Access Attributes |
AnnaBridge | 171:3a7713b1edbc | 82 | * |
AnnaBridge | 171:3a7713b1edbc | 83 | * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. |
AnnaBridge | 171:3a7713b1edbc | 84 | * \param IsShareable Region is shareable between multiple bus masters. |
AnnaBridge | 171:3a7713b1edbc | 85 | * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. |
AnnaBridge | 171:3a7713b1edbc | 86 | * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. |
AnnaBridge | 171:3a7713b1edbc | 87 | */ |
AnnaBridge | 171:3a7713b1edbc | 88 | #define ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable) \ |
AnnaBridge | 171:3a7713b1edbc | 89 | ((((TypeExtField) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \ |
AnnaBridge | 171:3a7713b1edbc | 90 | (((IsShareable) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \ |
AnnaBridge | 171:3a7713b1edbc | 91 | (((IsCacheable) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \ |
AnnaBridge | 171:3a7713b1edbc | 92 | (((IsBufferable) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk)) |
AnnaBridge | 171:3a7713b1edbc | 93 | |
AnnaBridge | 171:3a7713b1edbc | 94 | /** |
AnnaBridge | 171:3a7713b1edbc | 95 | * MPU Region Attribute and Size Register Value |
AnnaBridge | 171:3a7713b1edbc | 96 | * |
AnnaBridge | 171:3a7713b1edbc | 97 | * \param DisableExec Instruction access disable bit, 1= disable instruction fetches. |
AnnaBridge | 171:3a7713b1edbc | 98 | * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. |
AnnaBridge | 171:3a7713b1edbc | 99 | * \param AccessAttributes Memory access attribution, see \ref ARM_MPU_ACCESS_. |
AnnaBridge | 171:3a7713b1edbc | 100 | * \param SubRegionDisable Sub-region disable field. |
AnnaBridge | 171:3a7713b1edbc | 101 | * \param Size Region size of the region to be configured, for example 4K, 8K. |
AnnaBridge | 171:3a7713b1edbc | 102 | */ |
AnnaBridge | 171:3a7713b1edbc | 103 | #define ARM_MPU_RASR_EX(DisableExec, AccessPermission, AccessAttributes, SubRegionDisable, Size) \ |
AnnaBridge | 171:3a7713b1edbc | 104 | ((((DisableExec) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \ |
AnnaBridge | 171:3a7713b1edbc | 105 | (((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \ |
AnnaBridge | 171:3a7713b1edbc | 106 | (((AccessAttributes) & (MPU_RASR_TEX_Msk | MPU_RASR_S_Msk | MPU_RASR_C_Msk | MPU_RASR_B_Msk))) | \ |
AnnaBridge | 171:3a7713b1edbc | 107 | (((SubRegionDisable) << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \ |
AnnaBridge | 171:3a7713b1edbc | 108 | (((Size) << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \ |
AnnaBridge | 171:3a7713b1edbc | 109 | (((MPU_RASR_ENABLE_Msk)))) |
AnnaBridge | 171:3a7713b1edbc | 110 | |
AnnaBridge | 171:3a7713b1edbc | 111 | /** |
AnnaBridge | 171:3a7713b1edbc | 112 | * MPU Region Attribute and Size Register Value |
AnnaBridge | 171:3a7713b1edbc | 113 | * |
AnnaBridge | 171:3a7713b1edbc | 114 | * \param DisableExec Instruction access disable bit, 1= disable instruction fetches. |
AnnaBridge | 171:3a7713b1edbc | 115 | * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. |
AnnaBridge | 171:3a7713b1edbc | 116 | * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. |
AnnaBridge | 171:3a7713b1edbc | 117 | * \param IsShareable Region is shareable between multiple bus masters. |
AnnaBridge | 171:3a7713b1edbc | 118 | * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. |
AnnaBridge | 171:3a7713b1edbc | 119 | * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. |
AnnaBridge | 171:3a7713b1edbc | 120 | * \param SubRegionDisable Sub-region disable field. |
AnnaBridge | 171:3a7713b1edbc | 121 | * \param Size Region size of the region to be configured, for example 4K, 8K. |
AnnaBridge | 171:3a7713b1edbc | 122 | */ |
AnnaBridge | 171:3a7713b1edbc | 123 | #define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \ |
AnnaBridge | 171:3a7713b1edbc | 124 | ARM_MPU_RASR_EX(DisableExec, AccessPermission, ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable), SubRegionDisable, Size) |
AnnaBridge | 171:3a7713b1edbc | 125 | |
AnnaBridge | 171:3a7713b1edbc | 126 | /** |
AnnaBridge | 171:3a7713b1edbc | 127 | * MPU Memory Access Attribute for strongly ordered memory. |
AnnaBridge | 171:3a7713b1edbc | 128 | * - TEX: 000b |
AnnaBridge | 171:3a7713b1edbc | 129 | * - Shareable |
AnnaBridge | 171:3a7713b1edbc | 130 | * - Non-cacheable |
AnnaBridge | 171:3a7713b1edbc | 131 | * - Non-bufferable |
AnnaBridge | 171:3a7713b1edbc | 132 | */ |
AnnaBridge | 171:3a7713b1edbc | 133 | #define ARM_MPU_ACCESS_ORDERED ARM_MPU_ACCESS_(0U, 1U, 0U, 0U) |
AnnaBridge | 171:3a7713b1edbc | 134 | |
AnnaBridge | 171:3a7713b1edbc | 135 | /** |
AnnaBridge | 171:3a7713b1edbc | 136 | * MPU Memory Access Attribute for device memory. |
AnnaBridge | 171:3a7713b1edbc | 137 | * - TEX: 000b (if non-shareable) or 010b (if shareable) |
AnnaBridge | 171:3a7713b1edbc | 138 | * - Shareable or non-shareable |
AnnaBridge | 171:3a7713b1edbc | 139 | * - Non-cacheable |
AnnaBridge | 171:3a7713b1edbc | 140 | * - Bufferable (if shareable) or non-bufferable (if non-shareable) |
AnnaBridge | 171:3a7713b1edbc | 141 | * |
AnnaBridge | 171:3a7713b1edbc | 142 | * \param IsShareable Configures the device memory as shareable or non-shareable. |
AnnaBridge | 171:3a7713b1edbc | 143 | */ |
AnnaBridge | 171:3a7713b1edbc | 144 | #define ARM_MPU_ACCESS_DEVICE(IsShareable) ((IsShareable) ? ARM_MPU_ACCESS_(0U, 1U, 0U, 1U) : ARM_MPU_ACCESS_(2U, 0U, 0U, 0U)) |
AnnaBridge | 171:3a7713b1edbc | 145 | |
AnnaBridge | 171:3a7713b1edbc | 146 | /** |
AnnaBridge | 171:3a7713b1edbc | 147 | * MPU Memory Access Attribute for normal memory. |
AnnaBridge | 171:3a7713b1edbc | 148 | * - TEX: 1BBb (reflecting outer cacheability rules) |
AnnaBridge | 171:3a7713b1edbc | 149 | * - Shareable or non-shareable |
AnnaBridge | 171:3a7713b1edbc | 150 | * - Cacheable or non-cacheable (reflecting inner cacheability rules) |
AnnaBridge | 171:3a7713b1edbc | 151 | * - Bufferable or non-bufferable (reflecting inner cacheability rules) |
AnnaBridge | 171:3a7713b1edbc | 152 | * |
AnnaBridge | 171:3a7713b1edbc | 153 | * \param OuterCp Configures the outer cache policy. |
AnnaBridge | 171:3a7713b1edbc | 154 | * \param InnerCp Configures the inner cache policy. |
AnnaBridge | 171:3a7713b1edbc | 155 | * \param IsShareable Configures the memory as shareable or non-shareable. |
AnnaBridge | 171:3a7713b1edbc | 156 | */ |
AnnaBridge | 171:3a7713b1edbc | 157 | #define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) & 2U), ((InnerCp) & 1U)) |
AnnaBridge | 171:3a7713b1edbc | 158 | |
AnnaBridge | 171:3a7713b1edbc | 159 | /** |
AnnaBridge | 171:3a7713b1edbc | 160 | * MPU Memory Access Attribute non-cacheable policy. |
AnnaBridge | 171:3a7713b1edbc | 161 | */ |
AnnaBridge | 171:3a7713b1edbc | 162 | #define ARM_MPU_CACHEP_NOCACHE 0U |
AnnaBridge | 171:3a7713b1edbc | 163 | |
AnnaBridge | 171:3a7713b1edbc | 164 | /** |
AnnaBridge | 171:3a7713b1edbc | 165 | * MPU Memory Access Attribute write-back, write and read allocate policy. |
AnnaBridge | 171:3a7713b1edbc | 166 | */ |
AnnaBridge | 171:3a7713b1edbc | 167 | #define ARM_MPU_CACHEP_WB_WRA 1U |
AnnaBridge | 171:3a7713b1edbc | 168 | |
AnnaBridge | 171:3a7713b1edbc | 169 | /** |
AnnaBridge | 171:3a7713b1edbc | 170 | * MPU Memory Access Attribute write-through, no write allocate policy. |
AnnaBridge | 171:3a7713b1edbc | 171 | */ |
AnnaBridge | 171:3a7713b1edbc | 172 | #define ARM_MPU_CACHEP_WT_NWA 2U |
AnnaBridge | 171:3a7713b1edbc | 173 | |
AnnaBridge | 171:3a7713b1edbc | 174 | /** |
AnnaBridge | 171:3a7713b1edbc | 175 | * MPU Memory Access Attribute write-back, no write allocate policy. |
AnnaBridge | 171:3a7713b1edbc | 176 | */ |
AnnaBridge | 171:3a7713b1edbc | 177 | #define ARM_MPU_CACHEP_WB_NWA 3U |
AnnaBridge | 171:3a7713b1edbc | 178 | |
AnnaBridge | 171:3a7713b1edbc | 179 | |
AnnaBridge | 171:3a7713b1edbc | 180 | /** |
AnnaBridge | 171:3a7713b1edbc | 181 | * Struct for a single MPU Region |
AnnaBridge | 171:3a7713b1edbc | 182 | */ |
AnnaBridge | 171:3a7713b1edbc | 183 | typedef struct { |
AnnaBridge | 171:3a7713b1edbc | 184 | uint32_t RBAR; //!< The region base address register value (RBAR) |
AnnaBridge | 171:3a7713b1edbc | 185 | uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR |
AnnaBridge | 171:3a7713b1edbc | 186 | } ARM_MPU_Region_t; |
AnnaBridge | 171:3a7713b1edbc | 187 | |
AnnaBridge | 171:3a7713b1edbc | 188 | /** Enable the MPU. |
AnnaBridge | 171:3a7713b1edbc | 189 | * \param MPU_Control Default access permissions for unconfigured regions. |
AnnaBridge | 171:3a7713b1edbc | 190 | */ |
AnnaBridge | 171:3a7713b1edbc | 191 | __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) |
AnnaBridge | 171:3a7713b1edbc | 192 | { |
AnnaBridge | 171:3a7713b1edbc | 193 | __DSB(); |
AnnaBridge | 171:3a7713b1edbc | 194 | __ISB(); |
AnnaBridge | 171:3a7713b1edbc | 195 | MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; |
AnnaBridge | 171:3a7713b1edbc | 196 | #ifdef SCB_SHCSR_MEMFAULTENA_Msk |
AnnaBridge | 171:3a7713b1edbc | 197 | SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; |
AnnaBridge | 171:3a7713b1edbc | 198 | #endif |
AnnaBridge | 171:3a7713b1edbc | 199 | } |
AnnaBridge | 171:3a7713b1edbc | 200 | |
AnnaBridge | 171:3a7713b1edbc | 201 | /** Disable the MPU. |
AnnaBridge | 171:3a7713b1edbc | 202 | */ |
AnnaBridge | 171:3a7713b1edbc | 203 | __STATIC_INLINE void ARM_MPU_Disable(void) |
AnnaBridge | 171:3a7713b1edbc | 204 | { |
AnnaBridge | 171:3a7713b1edbc | 205 | __DSB(); |
AnnaBridge | 171:3a7713b1edbc | 206 | __ISB(); |
AnnaBridge | 171:3a7713b1edbc | 207 | #ifdef SCB_SHCSR_MEMFAULTENA_Msk |
AnnaBridge | 171:3a7713b1edbc | 208 | SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; |
AnnaBridge | 171:3a7713b1edbc | 209 | #endif |
AnnaBridge | 171:3a7713b1edbc | 210 | MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; |
AnnaBridge | 171:3a7713b1edbc | 211 | } |
AnnaBridge | 171:3a7713b1edbc | 212 | |
AnnaBridge | 171:3a7713b1edbc | 213 | /** Clear and disable the given MPU region. |
AnnaBridge | 171:3a7713b1edbc | 214 | * \param rnr Region number to be cleared. |
AnnaBridge | 171:3a7713b1edbc | 215 | */ |
AnnaBridge | 171:3a7713b1edbc | 216 | __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) |
AnnaBridge | 171:3a7713b1edbc | 217 | { |
AnnaBridge | 171:3a7713b1edbc | 218 | MPU->RNR = rnr; |
AnnaBridge | 171:3a7713b1edbc | 219 | MPU->RASR = 0U; |
AnnaBridge | 171:3a7713b1edbc | 220 | } |
AnnaBridge | 171:3a7713b1edbc | 221 | |
AnnaBridge | 171:3a7713b1edbc | 222 | /** Configure an MPU region. |
AnnaBridge | 171:3a7713b1edbc | 223 | * \param rbar Value for RBAR register. |
AnnaBridge | 171:3a7713b1edbc | 224 | * \param rsar Value for RSAR register. |
AnnaBridge | 171:3a7713b1edbc | 225 | */ |
AnnaBridge | 171:3a7713b1edbc | 226 | __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr) |
AnnaBridge | 171:3a7713b1edbc | 227 | { |
AnnaBridge | 171:3a7713b1edbc | 228 | MPU->RBAR = rbar; |
AnnaBridge | 171:3a7713b1edbc | 229 | MPU->RASR = rasr; |
AnnaBridge | 171:3a7713b1edbc | 230 | } |
AnnaBridge | 171:3a7713b1edbc | 231 | |
AnnaBridge | 171:3a7713b1edbc | 232 | /** Configure the given MPU region. |
AnnaBridge | 171:3a7713b1edbc | 233 | * \param rnr Region number to be configured. |
AnnaBridge | 171:3a7713b1edbc | 234 | * \param rbar Value for RBAR register. |
AnnaBridge | 171:3a7713b1edbc | 235 | * \param rsar Value for RSAR register. |
AnnaBridge | 171:3a7713b1edbc | 236 | */ |
AnnaBridge | 171:3a7713b1edbc | 237 | __STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr) |
AnnaBridge | 171:3a7713b1edbc | 238 | { |
AnnaBridge | 171:3a7713b1edbc | 239 | MPU->RNR = rnr; |
AnnaBridge | 171:3a7713b1edbc | 240 | MPU->RBAR = rbar; |
AnnaBridge | 171:3a7713b1edbc | 241 | MPU->RASR = rasr; |
AnnaBridge | 171:3a7713b1edbc | 242 | } |
AnnaBridge | 171:3a7713b1edbc | 243 | |
AnnaBridge | 171:3a7713b1edbc | 244 | /** Memcopy with strictly ordered memory access, e.g. for register targets. |
AnnaBridge | 171:3a7713b1edbc | 245 | * \param dst Destination data is copied to. |
AnnaBridge | 171:3a7713b1edbc | 246 | * \param src Source data is copied from. |
AnnaBridge | 171:3a7713b1edbc | 247 | * \param len Amount of data words to be copied. |
AnnaBridge | 171:3a7713b1edbc | 248 | */ |
AnnaBridge | 171:3a7713b1edbc | 249 | __STATIC_INLINE void orderedCpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) |
AnnaBridge | 171:3a7713b1edbc | 250 | { |
AnnaBridge | 171:3a7713b1edbc | 251 | uint32_t i; |
AnnaBridge | 171:3a7713b1edbc | 252 | for (i = 0U; i < len; ++i) |
AnnaBridge | 171:3a7713b1edbc | 253 | { |
AnnaBridge | 171:3a7713b1edbc | 254 | dst[i] = src[i]; |
AnnaBridge | 171:3a7713b1edbc | 255 | } |
AnnaBridge | 171:3a7713b1edbc | 256 | } |
AnnaBridge | 171:3a7713b1edbc | 257 | |
AnnaBridge | 171:3a7713b1edbc | 258 | /** Load the given number of MPU regions from a table. |
AnnaBridge | 171:3a7713b1edbc | 259 | * \param table Pointer to the MPU configuration table. |
AnnaBridge | 171:3a7713b1edbc | 260 | * \param cnt Amount of regions to be configured. |
AnnaBridge | 171:3a7713b1edbc | 261 | */ |
AnnaBridge | 171:3a7713b1edbc | 262 | __STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt) |
AnnaBridge | 171:3a7713b1edbc | 263 | { |
AnnaBridge | 171:3a7713b1edbc | 264 | const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U; |
AnnaBridge | 171:3a7713b1edbc | 265 | while (cnt > MPU_TYPE_RALIASES) { |
AnnaBridge | 171:3a7713b1edbc | 266 | orderedCpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize); |
AnnaBridge | 171:3a7713b1edbc | 267 | table += MPU_TYPE_RALIASES; |
AnnaBridge | 171:3a7713b1edbc | 268 | cnt -= MPU_TYPE_RALIASES; |
AnnaBridge | 171:3a7713b1edbc | 269 | } |
AnnaBridge | 171:3a7713b1edbc | 270 | orderedCpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize); |
AnnaBridge | 171:3a7713b1edbc | 271 | } |
AnnaBridge | 171:3a7713b1edbc | 272 | |
AnnaBridge | 171:3a7713b1edbc | 273 | #endif |