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.

Committer:
AnnaBridge
Date:
Fri Feb 16 16:16:41 2018 +0000
Revision:
161:aa5281ff4a02
Child:
169:a7c7b631e539
mbed library. Release version 159.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 161:aa5281ff4a02 1 /******************************************************************************
AnnaBridge 161:aa5281ff4a02 2 * @file mpu_armv7.h
AnnaBridge 161:aa5281ff4a02 3 * @brief CMSIS MPU API for ARMv7 MPU
AnnaBridge 161:aa5281ff4a02 4 * @version V5.0.3
AnnaBridge 161:aa5281ff4a02 5 * @date 09. August 2017
AnnaBridge 161:aa5281ff4a02 6 ******************************************************************************/
AnnaBridge 161:aa5281ff4a02 7 /*
AnnaBridge 161:aa5281ff4a02 8 * Copyright (c) 2017 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
AnnaBridge 161:aa5281ff4a02 25 #ifndef ARM_MPU_ARMV7_H
AnnaBridge 161:aa5281ff4a02 26 #define ARM_MPU_ARMV7_H
AnnaBridge 161:aa5281ff4a02 27
AnnaBridge 161:aa5281ff4a02 28 #define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U)
AnnaBridge 161:aa5281ff4a02 29 #define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U)
AnnaBridge 161:aa5281ff4a02 30 #define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U)
AnnaBridge 161:aa5281ff4a02 31 #define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U)
AnnaBridge 161:aa5281ff4a02 32 #define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U)
AnnaBridge 161:aa5281ff4a02 33 #define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U)
AnnaBridge 161:aa5281ff4a02 34 #define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU)
AnnaBridge 161:aa5281ff4a02 35 #define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU)
AnnaBridge 161:aa5281ff4a02 36 #define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU)
AnnaBridge 161:aa5281ff4a02 37 #define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU)
AnnaBridge 161:aa5281ff4a02 38 #define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU)
AnnaBridge 161:aa5281ff4a02 39 #define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU)
AnnaBridge 161:aa5281ff4a02 40 #define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U)
AnnaBridge 161:aa5281ff4a02 41 #define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U)
AnnaBridge 161:aa5281ff4a02 42 #define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U)
AnnaBridge 161:aa5281ff4a02 43 #define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U)
AnnaBridge 161:aa5281ff4a02 44 #define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U)
AnnaBridge 161:aa5281ff4a02 45 #define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U)
AnnaBridge 161:aa5281ff4a02 46 #define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U)
AnnaBridge 161:aa5281ff4a02 47 #define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U)
AnnaBridge 161:aa5281ff4a02 48 #define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U)
AnnaBridge 161:aa5281ff4a02 49 #define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U)
AnnaBridge 161:aa5281ff4a02 50 #define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU)
AnnaBridge 161:aa5281ff4a02 51 #define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU)
AnnaBridge 161:aa5281ff4a02 52 #define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU)
AnnaBridge 161:aa5281ff4a02 53 #define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU)
AnnaBridge 161:aa5281ff4a02 54 #define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU)
AnnaBridge 161:aa5281ff4a02 55 #define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU)
AnnaBridge 161:aa5281ff4a02 56
AnnaBridge 161:aa5281ff4a02 57 #define ARM_MPU_AP_NONE 0U
AnnaBridge 161:aa5281ff4a02 58 #define ARM_MPU_AP_PRIV 1U
AnnaBridge 161:aa5281ff4a02 59 #define ARM_MPU_AP_URO 2U
AnnaBridge 161:aa5281ff4a02 60 #define ARM_MPU_AP_FULL 3U
AnnaBridge 161:aa5281ff4a02 61 #define ARM_MPU_AP_PRO 5U
AnnaBridge 161:aa5281ff4a02 62 #define ARM_MPU_AP_RO 6U
AnnaBridge 161:aa5281ff4a02 63
AnnaBridge 161:aa5281ff4a02 64 /** MPU Region Base Address Register Value
AnnaBridge 161:aa5281ff4a02 65 *
AnnaBridge 161:aa5281ff4a02 66 * \param Region The region to be configured, number 0 to 15.
AnnaBridge 161:aa5281ff4a02 67 * \param BaseAddress The base address for the region.
AnnaBridge 161:aa5281ff4a02 68 */
AnnaBridge 161:aa5281ff4a02 69 #define ARM_MPU_RBAR(Region, BaseAddress) \
AnnaBridge 161:aa5281ff4a02 70 (((BaseAddress) & MPU_RBAR_ADDR_Msk) | \
AnnaBridge 161:aa5281ff4a02 71 ((Region) & MPU_RBAR_REGION_Msk) | \
AnnaBridge 161:aa5281ff4a02 72 (MPU_RBAR_VALID_Msk))
AnnaBridge 161:aa5281ff4a02 73
AnnaBridge 161:aa5281ff4a02 74 /**
AnnaBridge 161:aa5281ff4a02 75 * MPU Region Attribut and Size Register Value
AnnaBridge 161:aa5281ff4a02 76 *
AnnaBridge 161:aa5281ff4a02 77 * \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
AnnaBridge 161:aa5281ff4a02 78 * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
AnnaBridge 161:aa5281ff4a02 79 * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
AnnaBridge 161:aa5281ff4a02 80 * \param IsShareable Region is shareable between multiple bus masters.
AnnaBridge 161:aa5281ff4a02 81 * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
AnnaBridge 161:aa5281ff4a02 82 * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
AnnaBridge 161:aa5281ff4a02 83 * \param SubRegionDisable Sub-region disable field.
AnnaBridge 161:aa5281ff4a02 84 * \param Size Region size of the region to be configured, for example 4K, 8K.
AnnaBridge 161:aa5281ff4a02 85 */
AnnaBridge 161:aa5281ff4a02 86 #define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \
AnnaBridge 161:aa5281ff4a02 87 ((((DisableExec ) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \
AnnaBridge 161:aa5281ff4a02 88 (((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \
AnnaBridge 161:aa5281ff4a02 89 (((TypeExtField ) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \
AnnaBridge 161:aa5281ff4a02 90 (((IsShareable ) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \
AnnaBridge 161:aa5281ff4a02 91 (((IsCacheable ) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \
AnnaBridge 161:aa5281ff4a02 92 (((IsBufferable ) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk) | \
AnnaBridge 161:aa5281ff4a02 93 (((SubRegionDisable) << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \
AnnaBridge 161:aa5281ff4a02 94 (((Size ) << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \
AnnaBridge 161:aa5281ff4a02 95 (MPU_RASR_ENABLE_Msk))
AnnaBridge 161:aa5281ff4a02 96
AnnaBridge 161:aa5281ff4a02 97
AnnaBridge 161:aa5281ff4a02 98 /**
AnnaBridge 161:aa5281ff4a02 99 * Struct for a single MPU Region
AnnaBridge 161:aa5281ff4a02 100 */
AnnaBridge 161:aa5281ff4a02 101 typedef struct _ARM_MPU_Region_t {
AnnaBridge 161:aa5281ff4a02 102 uint32_t RBAR; //!< The region base address register value (RBAR)
AnnaBridge 161:aa5281ff4a02 103 uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR
AnnaBridge 161:aa5281ff4a02 104 } ARM_MPU_Region_t;
AnnaBridge 161:aa5281ff4a02 105
AnnaBridge 161:aa5281ff4a02 106 /** Enable the MPU.
AnnaBridge 161:aa5281ff4a02 107 * \param MPU_Control Default access permissions for unconfigured regions.
AnnaBridge 161:aa5281ff4a02 108 */
AnnaBridge 161:aa5281ff4a02 109 __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
AnnaBridge 161:aa5281ff4a02 110 {
AnnaBridge 161:aa5281ff4a02 111 __DSB();
AnnaBridge 161:aa5281ff4a02 112 __ISB();
AnnaBridge 161:aa5281ff4a02 113 MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
AnnaBridge 161:aa5281ff4a02 114 #ifdef SCB_SHCSR_MEMFAULTENA_Msk
AnnaBridge 161:aa5281ff4a02 115 SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
AnnaBridge 161:aa5281ff4a02 116 #endif
AnnaBridge 161:aa5281ff4a02 117 }
AnnaBridge 161:aa5281ff4a02 118
AnnaBridge 161:aa5281ff4a02 119 /** Disable the MPU.
AnnaBridge 161:aa5281ff4a02 120 */
AnnaBridge 161:aa5281ff4a02 121 __STATIC_INLINE void ARM_MPU_Disable(void)
AnnaBridge 161:aa5281ff4a02 122 {
AnnaBridge 161:aa5281ff4a02 123 __DSB();
AnnaBridge 161:aa5281ff4a02 124 __ISB();
AnnaBridge 161:aa5281ff4a02 125 #ifdef SCB_SHCSR_MEMFAULTENA_Msk
AnnaBridge 161:aa5281ff4a02 126 SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
AnnaBridge 161:aa5281ff4a02 127 #endif
AnnaBridge 161:aa5281ff4a02 128 MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
AnnaBridge 161:aa5281ff4a02 129 }
AnnaBridge 161:aa5281ff4a02 130
AnnaBridge 161:aa5281ff4a02 131 /** Clear and disable the given MPU region.
AnnaBridge 161:aa5281ff4a02 132 * \param rnr Region number to be cleared.
AnnaBridge 161:aa5281ff4a02 133 */
AnnaBridge 161:aa5281ff4a02 134 __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
AnnaBridge 161:aa5281ff4a02 135 {
AnnaBridge 161:aa5281ff4a02 136 MPU->RNR = rnr;
AnnaBridge 161:aa5281ff4a02 137 MPU->RASR = 0U;
AnnaBridge 161:aa5281ff4a02 138 }
AnnaBridge 161:aa5281ff4a02 139
AnnaBridge 161:aa5281ff4a02 140 /** Configure an MPU region.
AnnaBridge 161:aa5281ff4a02 141 * \param rbar Value for RBAR register.
AnnaBridge 161:aa5281ff4a02 142 * \param rsar Value for RSAR register.
AnnaBridge 161:aa5281ff4a02 143 */
AnnaBridge 161:aa5281ff4a02 144 __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr)
AnnaBridge 161:aa5281ff4a02 145 {
AnnaBridge 161:aa5281ff4a02 146 MPU->RBAR = rbar;
AnnaBridge 161:aa5281ff4a02 147 MPU->RASR = rasr;
AnnaBridge 161:aa5281ff4a02 148 }
AnnaBridge 161:aa5281ff4a02 149
AnnaBridge 161:aa5281ff4a02 150 /** Configure the given MPU region.
AnnaBridge 161:aa5281ff4a02 151 * \param rnr Region number to be configured.
AnnaBridge 161:aa5281ff4a02 152 * \param rbar Value for RBAR register.
AnnaBridge 161:aa5281ff4a02 153 * \param rsar Value for RSAR register.
AnnaBridge 161:aa5281ff4a02 154 */
AnnaBridge 161:aa5281ff4a02 155 __STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr)
AnnaBridge 161:aa5281ff4a02 156 {
AnnaBridge 161:aa5281ff4a02 157 MPU->RNR = rnr;
AnnaBridge 161:aa5281ff4a02 158 MPU->RBAR = rbar;
AnnaBridge 161:aa5281ff4a02 159 MPU->RASR = rasr;
AnnaBridge 161:aa5281ff4a02 160 }
AnnaBridge 161:aa5281ff4a02 161
AnnaBridge 161:aa5281ff4a02 162 /** Memcopy with strictly ordered memory access, e.g. for register targets.
AnnaBridge 161:aa5281ff4a02 163 * \param dst Destination data is copied to.
AnnaBridge 161:aa5281ff4a02 164 * \param src Source data is copied from.
AnnaBridge 161:aa5281ff4a02 165 * \param len Amount of data words to be copied.
AnnaBridge 161:aa5281ff4a02 166 */
AnnaBridge 161:aa5281ff4a02 167 __STATIC_INLINE void orderedCpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len)
AnnaBridge 161:aa5281ff4a02 168 {
AnnaBridge 161:aa5281ff4a02 169 uint32_t i;
AnnaBridge 161:aa5281ff4a02 170 for (i = 0U; i < len; ++i)
AnnaBridge 161:aa5281ff4a02 171 {
AnnaBridge 161:aa5281ff4a02 172 dst[i] = src[i];
AnnaBridge 161:aa5281ff4a02 173 }
AnnaBridge 161:aa5281ff4a02 174 }
AnnaBridge 161:aa5281ff4a02 175
AnnaBridge 161:aa5281ff4a02 176 /** Load the given number of MPU regions from a table.
AnnaBridge 161:aa5281ff4a02 177 * \param table Pointer to the MPU configuration table.
AnnaBridge 161:aa5281ff4a02 178 * \param cnt Amount of regions to be configured.
AnnaBridge 161:aa5281ff4a02 179 */
AnnaBridge 161:aa5281ff4a02 180 __STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt)
AnnaBridge 161:aa5281ff4a02 181 {
AnnaBridge 161:aa5281ff4a02 182 static const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U;
AnnaBridge 161:aa5281ff4a02 183 if (cnt > MPU_TYPE_RALIASES) {
AnnaBridge 161:aa5281ff4a02 184 orderedCpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize);
AnnaBridge 161:aa5281ff4a02 185 ARM_MPU_Load(table+MPU_TYPE_RALIASES, cnt-MPU_TYPE_RALIASES);
AnnaBridge 161:aa5281ff4a02 186 } else {
AnnaBridge 161:aa5281ff4a02 187 orderedCpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize);
AnnaBridge 161:aa5281ff4a02 188 }
AnnaBridge 161:aa5281ff4a02 189 }
AnnaBridge 161:aa5281ff4a02 190
AnnaBridge 161:aa5281ff4a02 191 #endif