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_STEVAL_3DP001V1/mpu_armv7.h@169:a7c7b631e539, 2018-06-22 (annotated)
- Committer:
- Anna Bridge
- Date:
- Fri Jun 22 15:38:59 2018 +0100
- Revision:
- 169:a7c7b631e539
- Parent:
- 163:e59c8e839560
mbed library. Release version 162
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 161:aa5281ff4a02 | 1 | /****************************************************************************** |
AnnaBridge | 161:aa5281ff4a02 | 2 | * @file mpu_armv7.h |
Anna Bridge |
169:a7c7b631e539 | 3 | * @brief CMSIS MPU API for Armv7-M MPU |
Anna Bridge |
169:a7c7b631e539 | 4 | * @version V5.0.4 |
Anna Bridge |
169:a7c7b631e539 | 5 | * @date 10. January 2018 |
AnnaBridge | 161:aa5281ff4a02 | 6 | ******************************************************************************/ |
AnnaBridge | 161:aa5281ff4a02 | 7 | /* |
Anna Bridge |
169:a7c7b631e539 | 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. |
AnnaBridge | 161:aa5281ff4a02 | 9 | * |
AnnaBridge | 161:aa5281ff4a02 | 10 | * SPDX-License-Identifier: Apache-2.0 |
AnnaBridge | 161:aa5281ff4a02 | 11 | * |
AnnaBridge | 161:aa5281ff4a02 | 12 | * Licensed under the Apache License, Version 2.0 (the License); you may |
AnnaBridge | 161:aa5281ff4a02 | 13 | * not use this file except in compliance with the License. |
AnnaBridge | 161:aa5281ff4a02 | 14 | * You may obtain a copy of the License at |
AnnaBridge | 161:aa5281ff4a02 | 15 | * |
AnnaBridge | 161:aa5281ff4a02 | 16 | * www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 161:aa5281ff4a02 | 17 | * |
AnnaBridge | 161:aa5281ff4a02 | 18 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 161:aa5281ff4a02 | 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
AnnaBridge | 161:aa5281ff4a02 | 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 161:aa5281ff4a02 | 21 | * See the License for the specific language governing permissions and |
AnnaBridge | 161:aa5281ff4a02 | 22 | * limitations under the License. |
AnnaBridge | 161:aa5281ff4a02 | 23 | */ |
AnnaBridge | 161:aa5281ff4a02 | 24 | |
Anna Bridge |
169:a7c7b631e539 | 25 | #if defined ( __ICCARM__ ) |
Anna Bridge |
169:a7c7b631e539 | 26 | #pragma system_include /* treat file as system include file for MISRA check */ |
Anna Bridge |
169:a7c7b631e539 | 27 | #elif defined (__clang__) |
Anna Bridge |
169:a7c7b631e539 | 28 | #pragma clang system_header /* treat file as system include file */ |
Anna Bridge |
169:a7c7b631e539 | 29 | #endif |
Anna Bridge |
169:a7c7b631e539 | 30 | |
AnnaBridge | 161:aa5281ff4a02 | 31 | #ifndef ARM_MPU_ARMV7_H |
AnnaBridge | 161:aa5281ff4a02 | 32 | #define ARM_MPU_ARMV7_H |
AnnaBridge | 161:aa5281ff4a02 | 33 | |
AnnaBridge | 161:aa5281ff4a02 | 34 | #define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) |
AnnaBridge | 161:aa5281ff4a02 | 35 | #define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) |
AnnaBridge | 161:aa5281ff4a02 | 36 | #define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) |
AnnaBridge | 161:aa5281ff4a02 | 37 | #define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) |
AnnaBridge | 161:aa5281ff4a02 | 38 | #define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) |
AnnaBridge | 161:aa5281ff4a02 | 39 | #define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) |
AnnaBridge | 161:aa5281ff4a02 | 40 | #define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) |
AnnaBridge | 161:aa5281ff4a02 | 41 | #define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) |
AnnaBridge | 161:aa5281ff4a02 | 42 | #define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) |
AnnaBridge | 161:aa5281ff4a02 | 43 | #define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) |
AnnaBridge | 161:aa5281ff4a02 | 44 | #define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) |
AnnaBridge | 161:aa5281ff4a02 | 45 | #define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) |
AnnaBridge | 161:aa5281ff4a02 | 46 | #define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) |
AnnaBridge | 161:aa5281ff4a02 | 47 | #define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) |
AnnaBridge | 161:aa5281ff4a02 | 48 | #define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) |
AnnaBridge | 161:aa5281ff4a02 | 49 | #define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) |
AnnaBridge | 161:aa5281ff4a02 | 50 | #define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) |
AnnaBridge | 161:aa5281ff4a02 | 51 | #define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) |
AnnaBridge | 161:aa5281ff4a02 | 52 | #define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) |
AnnaBridge | 161:aa5281ff4a02 | 53 | #define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) |
AnnaBridge | 161:aa5281ff4a02 | 54 | #define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) |
AnnaBridge | 161:aa5281ff4a02 | 55 | #define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) |
AnnaBridge | 161:aa5281ff4a02 | 56 | #define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) |
AnnaBridge | 161:aa5281ff4a02 | 57 | #define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) |
AnnaBridge | 161:aa5281ff4a02 | 58 | #define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) |
AnnaBridge | 161:aa5281ff4a02 | 59 | #define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) |
AnnaBridge | 161:aa5281ff4a02 | 60 | #define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) |
AnnaBridge | 161:aa5281ff4a02 | 61 | #define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) |
AnnaBridge | 161:aa5281ff4a02 | 62 | |
AnnaBridge | 161:aa5281ff4a02 | 63 | #define ARM_MPU_AP_NONE 0U |
AnnaBridge | 161:aa5281ff4a02 | 64 | #define ARM_MPU_AP_PRIV 1U |
AnnaBridge | 161:aa5281ff4a02 | 65 | #define ARM_MPU_AP_URO 2U |
AnnaBridge | 161:aa5281ff4a02 | 66 | #define ARM_MPU_AP_FULL 3U |
AnnaBridge | 161:aa5281ff4a02 | 67 | #define ARM_MPU_AP_PRO 5U |
AnnaBridge | 161:aa5281ff4a02 | 68 | #define ARM_MPU_AP_RO 6U |
AnnaBridge | 161:aa5281ff4a02 | 69 | |
AnnaBridge | 161:aa5281ff4a02 | 70 | /** MPU Region Base Address Register Value |
AnnaBridge | 161:aa5281ff4a02 | 71 | * |
AnnaBridge | 161:aa5281ff4a02 | 72 | * \param Region The region to be configured, number 0 to 15. |
AnnaBridge | 161:aa5281ff4a02 | 73 | * \param BaseAddress The base address for the region. |
AnnaBridge | 161:aa5281ff4a02 | 74 | */ |
AnnaBridge | 161:aa5281ff4a02 | 75 | #define ARM_MPU_RBAR(Region, BaseAddress) \ |
AnnaBridge | 161:aa5281ff4a02 | 76 | (((BaseAddress) & MPU_RBAR_ADDR_Msk) | \ |
AnnaBridge | 161:aa5281ff4a02 | 77 | ((Region) & MPU_RBAR_REGION_Msk) | \ |
AnnaBridge | 161:aa5281ff4a02 | 78 | (MPU_RBAR_VALID_Msk)) |
AnnaBridge | 161:aa5281ff4a02 | 79 | |
AnnaBridge | 161:aa5281ff4a02 | 80 | /** |
Anna Bridge |
169:a7c7b631e539 | 81 | * MPU Region Attribute and Size Register Value |
AnnaBridge | 161:aa5281ff4a02 | 82 | * |
AnnaBridge | 161:aa5281ff4a02 | 83 | * \param DisableExec Instruction access disable bit, 1= disable instruction fetches. |
AnnaBridge | 161:aa5281ff4a02 | 84 | * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. |
AnnaBridge | 161:aa5281ff4a02 | 85 | * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. |
AnnaBridge | 161:aa5281ff4a02 | 86 | * \param IsShareable Region is shareable between multiple bus masters. |
AnnaBridge | 161:aa5281ff4a02 | 87 | * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. |
AnnaBridge | 161:aa5281ff4a02 | 88 | * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. |
AnnaBridge | 161:aa5281ff4a02 | 89 | * \param SubRegionDisable Sub-region disable field. |
AnnaBridge | 161:aa5281ff4a02 | 90 | * \param Size Region size of the region to be configured, for example 4K, 8K. |
AnnaBridge | 161:aa5281ff4a02 | 91 | */ |
AnnaBridge | 161:aa5281ff4a02 | 92 | #define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \ |
AnnaBridge | 161:aa5281ff4a02 | 93 | ((((DisableExec ) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \ |
AnnaBridge | 161:aa5281ff4a02 | 94 | (((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \ |
AnnaBridge | 161:aa5281ff4a02 | 95 | (((TypeExtField ) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \ |
AnnaBridge | 161:aa5281ff4a02 | 96 | (((IsShareable ) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \ |
AnnaBridge | 161:aa5281ff4a02 | 97 | (((IsCacheable ) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \ |
AnnaBridge | 161:aa5281ff4a02 | 98 | (((IsBufferable ) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk) | \ |
AnnaBridge | 161:aa5281ff4a02 | 99 | (((SubRegionDisable) << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \ |
AnnaBridge | 161:aa5281ff4a02 | 100 | (((Size ) << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \ |
AnnaBridge | 161:aa5281ff4a02 | 101 | (MPU_RASR_ENABLE_Msk)) |
AnnaBridge | 161:aa5281ff4a02 | 102 | |
AnnaBridge | 161:aa5281ff4a02 | 103 | |
AnnaBridge | 161:aa5281ff4a02 | 104 | /** |
AnnaBridge | 161:aa5281ff4a02 | 105 | * Struct for a single MPU Region |
AnnaBridge | 161:aa5281ff4a02 | 106 | */ |
Anna Bridge |
169:a7c7b631e539 | 107 | typedef struct { |
AnnaBridge | 161:aa5281ff4a02 | 108 | uint32_t RBAR; //!< The region base address register value (RBAR) |
AnnaBridge | 161:aa5281ff4a02 | 109 | uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR |
AnnaBridge | 161:aa5281ff4a02 | 110 | } ARM_MPU_Region_t; |
AnnaBridge | 161:aa5281ff4a02 | 111 | |
AnnaBridge | 161:aa5281ff4a02 | 112 | /** Enable the MPU. |
AnnaBridge | 161:aa5281ff4a02 | 113 | * \param MPU_Control Default access permissions for unconfigured regions. |
AnnaBridge | 161:aa5281ff4a02 | 114 | */ |
AnnaBridge | 161:aa5281ff4a02 | 115 | __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) |
AnnaBridge | 161:aa5281ff4a02 | 116 | { |
AnnaBridge | 161:aa5281ff4a02 | 117 | __DSB(); |
AnnaBridge | 161:aa5281ff4a02 | 118 | __ISB(); |
AnnaBridge | 161:aa5281ff4a02 | 119 | MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; |
AnnaBridge | 161:aa5281ff4a02 | 120 | #ifdef SCB_SHCSR_MEMFAULTENA_Msk |
AnnaBridge | 161:aa5281ff4a02 | 121 | SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; |
AnnaBridge | 161:aa5281ff4a02 | 122 | #endif |
AnnaBridge | 161:aa5281ff4a02 | 123 | } |
AnnaBridge | 161:aa5281ff4a02 | 124 | |
AnnaBridge | 161:aa5281ff4a02 | 125 | /** Disable the MPU. |
AnnaBridge | 161:aa5281ff4a02 | 126 | */ |
AnnaBridge | 161:aa5281ff4a02 | 127 | __STATIC_INLINE void ARM_MPU_Disable(void) |
AnnaBridge | 161:aa5281ff4a02 | 128 | { |
AnnaBridge | 161:aa5281ff4a02 | 129 | __DSB(); |
AnnaBridge | 161:aa5281ff4a02 | 130 | __ISB(); |
AnnaBridge | 161:aa5281ff4a02 | 131 | #ifdef SCB_SHCSR_MEMFAULTENA_Msk |
AnnaBridge | 161:aa5281ff4a02 | 132 | SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; |
AnnaBridge | 161:aa5281ff4a02 | 133 | #endif |
AnnaBridge | 161:aa5281ff4a02 | 134 | MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; |
AnnaBridge | 161:aa5281ff4a02 | 135 | } |
AnnaBridge | 161:aa5281ff4a02 | 136 | |
AnnaBridge | 161:aa5281ff4a02 | 137 | /** Clear and disable the given MPU region. |
AnnaBridge | 161:aa5281ff4a02 | 138 | * \param rnr Region number to be cleared. |
AnnaBridge | 161:aa5281ff4a02 | 139 | */ |
AnnaBridge | 161:aa5281ff4a02 | 140 | __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) |
AnnaBridge | 161:aa5281ff4a02 | 141 | { |
AnnaBridge | 161:aa5281ff4a02 | 142 | MPU->RNR = rnr; |
AnnaBridge | 161:aa5281ff4a02 | 143 | MPU->RASR = 0U; |
AnnaBridge | 161:aa5281ff4a02 | 144 | } |
AnnaBridge | 161:aa5281ff4a02 | 145 | |
AnnaBridge | 161:aa5281ff4a02 | 146 | /** Configure an MPU region. |
AnnaBridge | 161:aa5281ff4a02 | 147 | * \param rbar Value for RBAR register. |
AnnaBridge | 161:aa5281ff4a02 | 148 | * \param rsar Value for RSAR register. |
AnnaBridge | 161:aa5281ff4a02 | 149 | */ |
AnnaBridge | 161:aa5281ff4a02 | 150 | __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr) |
AnnaBridge | 161:aa5281ff4a02 | 151 | { |
AnnaBridge | 161:aa5281ff4a02 | 152 | MPU->RBAR = rbar; |
AnnaBridge | 161:aa5281ff4a02 | 153 | MPU->RASR = rasr; |
AnnaBridge | 161:aa5281ff4a02 | 154 | } |
AnnaBridge | 161:aa5281ff4a02 | 155 | |
AnnaBridge | 161:aa5281ff4a02 | 156 | /** Configure the given MPU region. |
AnnaBridge | 161:aa5281ff4a02 | 157 | * \param rnr Region number to be configured. |
AnnaBridge | 161:aa5281ff4a02 | 158 | * \param rbar Value for RBAR register. |
AnnaBridge | 161:aa5281ff4a02 | 159 | * \param rsar Value for RSAR register. |
AnnaBridge | 161:aa5281ff4a02 | 160 | */ |
AnnaBridge | 161:aa5281ff4a02 | 161 | __STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr) |
AnnaBridge | 161:aa5281ff4a02 | 162 | { |
AnnaBridge | 161:aa5281ff4a02 | 163 | MPU->RNR = rnr; |
AnnaBridge | 161:aa5281ff4a02 | 164 | MPU->RBAR = rbar; |
AnnaBridge | 161:aa5281ff4a02 | 165 | MPU->RASR = rasr; |
AnnaBridge | 161:aa5281ff4a02 | 166 | } |
AnnaBridge | 161:aa5281ff4a02 | 167 | |
AnnaBridge | 161:aa5281ff4a02 | 168 | /** Memcopy with strictly ordered memory access, e.g. for register targets. |
AnnaBridge | 161:aa5281ff4a02 | 169 | * \param dst Destination data is copied to. |
AnnaBridge | 161:aa5281ff4a02 | 170 | * \param src Source data is copied from. |
AnnaBridge | 161:aa5281ff4a02 | 171 | * \param len Amount of data words to be copied. |
AnnaBridge | 161:aa5281ff4a02 | 172 | */ |
AnnaBridge | 161:aa5281ff4a02 | 173 | __STATIC_INLINE void orderedCpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) |
AnnaBridge | 161:aa5281ff4a02 | 174 | { |
AnnaBridge | 161:aa5281ff4a02 | 175 | uint32_t i; |
AnnaBridge | 161:aa5281ff4a02 | 176 | for (i = 0U; i < len; ++i) |
AnnaBridge | 161:aa5281ff4a02 | 177 | { |
AnnaBridge | 161:aa5281ff4a02 | 178 | dst[i] = src[i]; |
AnnaBridge | 161:aa5281ff4a02 | 179 | } |
AnnaBridge | 161:aa5281ff4a02 | 180 | } |
AnnaBridge | 161:aa5281ff4a02 | 181 | |
AnnaBridge | 161:aa5281ff4a02 | 182 | /** Load the given number of MPU regions from a table. |
AnnaBridge | 161:aa5281ff4a02 | 183 | * \param table Pointer to the MPU configuration table. |
AnnaBridge | 161:aa5281ff4a02 | 184 | * \param cnt Amount of regions to be configured. |
AnnaBridge | 161:aa5281ff4a02 | 185 | */ |
AnnaBridge | 161:aa5281ff4a02 | 186 | __STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt) |
AnnaBridge | 161:aa5281ff4a02 | 187 | { |
Anna Bridge |
169:a7c7b631e539 | 188 | const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U; |
Anna Bridge |
169:a7c7b631e539 | 189 | while (cnt > MPU_TYPE_RALIASES) { |
AnnaBridge | 161:aa5281ff4a02 | 190 | orderedCpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize); |
Anna Bridge |
169:a7c7b631e539 | 191 | table += MPU_TYPE_RALIASES; |
Anna Bridge |
169:a7c7b631e539 | 192 | cnt -= MPU_TYPE_RALIASES; |
AnnaBridge | 161:aa5281ff4a02 | 193 | } |
Anna Bridge |
169:a7c7b631e539 | 194 | orderedCpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize); |
AnnaBridge | 161:aa5281ff4a02 | 195 | } |
AnnaBridge | 161:aa5281ff4a02 | 196 | |
AnnaBridge | 161:aa5281ff4a02 | 197 | #endif |