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