libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
mpu.h
Go to the documentation of this file.
1
/*
2
* This file is part of the libopencm3 project.
3
*
4
* Copyright (C) 2013 Frantisek Burian <BuFran@seznam.cz>
5
*
6
* This library is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
/** @defgroup CM3_mpu_defines Cortex-M MPU Defines
21
*
22
* @brief <b>libopencm3 Cortex Memory Protection Unit</b>
23
*
24
* @ingroup CM3_defines
25
*
26
* @version 1.0.0
27
*
28
* LGPL License Terms @ref lgpl_license
29
*
30
* The MPU is available as an option in both ARMv6-M and ARMv7-M, but it has
31
* more features in v7, particularly in the available attributes.
32
*
33
* For more information see the ARM Architecture reference manuals.
34
*/
35
/**@{*/
36
37
#ifndef LIBOPENCM3_MPU_H
38
#define LIBOPENCM3_MPU_H
39
40
#include <
libopencm3/cm3/memorymap.h
>
41
#include <
libopencm3/cm3/common.h
>
42
43
/* --- SCB: Registers ------------------------------------------------------ */
44
/** @defgroup CM3_mpu_registers MPU Registers
45
* @ingroup CM3_mpu_defines
46
*
47
*@{*/
48
/** MPU_TYPE is always available, even if the MPU is not implemented */
49
#define MPU_TYPE MMIO32(MPU_BASE + 0x00)
/**< See also \ref CM3_mpu_type */
50
#define MPU_CTRL MMIO32(MPU_BASE + 0x04)
/**< See also \ref CM3_mpu_ctrl */
51
#define MPU_RNR MMIO32(MPU_BASE + 0x08)
/**< See also \ref CM3_mpu_rnr */
52
#define MPU_RBAR MMIO32(MPU_BASE + 0x0C)
/**< See also \ref CM3_mpu_rbar */
53
#define MPU_RASR MMIO32(MPU_BASE + 0x10)
/**< See also \ref CM3_mpu_rasr */
54
/**@}*/
55
56
/* --- MPU values ---------------------------------------------------------- */
57
58
/** @defgroup CM3_mpu_type MPU TYPE register fields
59
* @ingroup CM3_mpu_defines
60
* The MPU_TYPE register is always available, even if the MPU is not implemented.
61
* In that case, the DREGION field will read as 0.
62
*@{*/
63
#define MPU_TYPE_IREGION_LSB 16
64
#define MPU_TYPE_IREGION (0xFF << MPU_TYPE_IREGION_LSB)
/**< Number of protected instruction regions; always 0 on v6m/v7m */
65
#define MPU_TYPE_DREGION_LSB 8
66
#define MPU_TYPE_DREGION (0xFF << MPU_TYPE_DREGION_LSB)
/**< Number of protected data regions */
67
#define MPU_TYPE_SEPARATE (1<<0)
/**< Indicates if instruction regions are separate from data regions; always 0 on v6m/v7m */
68
/**@}*/
69
70
/** @defgroup CM3_mpu_ctrl MPU CTRL register fields
71
* @ingroup CM3_mpu_defines
72
* Defines for the Control Register.
73
*@{*/
74
#define MPU_CTRL_PRIVDEFENA (1<<2)
/**< Enable default map in privileged mode */
75
#define MPU_CTRL_HFNMIENA (1<<1)
/**< Enable MPU during hard fault, NMI, and FAULTMASK handlers */
76
#define MPU_CTRL_ENABLE (1<<0)
/**< MPU enable */
77
/**@}*/
78
79
/** @defgroup CM3_mpu_rnr MPU RNR register fields
80
* @ingroup CM3_mpu_defines
81
* Defines for the Region Number Register.
82
*@{*/
83
#define MPU_RNR_REGION_LSB 0
84
#define MPU_RNR_REGION (0xFF << MPU_RNR_REGION_LSB)
/**< Determines the region affected by RBAR and RASR */
85
/**@}*/
86
87
/** @defgroup CM3_mpu_rbar MPU RBAR register fields
88
* @ingroup CM3_mpu_defines
89
* Defines for the Region Base Address Register.
90
*@{*/
91
/** minimum size supported is by writing all ones to ADDR, then reading back */
92
#define MPU_RBAR_ADDR 0xFFFFFFE0
93
#define MPU_RBAR_VALID (1<<4)
/**< Use REGION to determine region to be accessed instead of MPU_RNR */
94
#define MPU_RBAR_REGION_LSB 0
95
#define MPU_RBAR_REGION (0xF << MPU_RBAR_REGION_LSB)
/**< Region to change if MPU_RBAR_VALID is set */
96
/**@}*/
97
98
/** @defgroup CM3_mpu_rasr MPU RASR register fields
99
* @ingroup CM3_mpu_defines
100
* Defines for the Region Attribute and Size Register.
101
*@{*/
102
#define MPU_RASR_ATTRS_LSB 16
103
#define MPU_RASR_ATTRS (0xFFFF << MPU_RASR_ATTRS_LSB)
/** Region attributes */
104
#define MPU_RASR_SRD_LSB 8
105
#define MPU_RASR_SRD (0xFF << MPU_RASR_SRD_LSB)
/**< Subregion disable bits */
106
#define MPU_RASR_SIZE_LSB 1
107
#define MPU_RASR_SIZE (0x1F << MPU_RASR_SIZE_LSB)
/**< Region size */
108
#define MPU_RASR_ENABLE (1 << 0)
/**< Region enable bit */
109
110
/** @defgroup mpu_rasr_attributes MPU RASR Attributes
111
* @ingroup CM3_mpu_rasr
112
* Not all attributes are available on v6m.
113
*
114
*@{*/
115
#define MPU_RASR_ATTR_XN (1 << 28)
/**< Execute never */
116
#define MPU_RASR_ATTR_AP (7 << 24)
/**< Access permissions mask */
117
#define MPU_RASR_ATTR_AP_PNO_UNO (0 << 24)
/**< Priv.: no, Unpriv.: no */
118
#define MPU_RASR_ATTR_AP_PRW_UNO (1 << 24)
/**< Priv.: RW, Unpriv.: no */
119
#define MPU_RASR_ATTR_AP_PRW_URO (2 << 24)
/**< Priv.: RW, Unpriv.: RO */
120
#define MPU_RASR_ATTR_AP_PRW_URW (3 << 24)
/**< Priv.: RW, Unpriv.: RW */
121
#define MPU_RASR_ATTR_AP_PRO_UNO (5 << 24)
/**< Priv.: RO, Unpriv.: no */
122
#define MPU_RASR_ATTR_AP_PRO_URO (6 << 24)
/**< Priv.: RO, Unpriv.: RO */
123
#define MPU_RASR_ATTR_TEX (7 << 19)
/**< Type extension (e.g., memory ordering) */
124
#define MPU_RASR_ATTR_S (1 << 18)
/**< Shareable */
125
#define MPU_RASR_ATTR_C (1 << 17)
/**< Cacheable */
126
#define MPU_RASR_ATTR_B (1 << 16)
/**< Bufferable */
127
#define MPU_RASR_ATTR_SCB (7 << 16)
/**< SCB mask */
128
/**@}*/
129
/**@}*/
130
131
/* --- MPU functions ------------------------------------------------------- */
132
133
BEGIN_DECLS
134
135
136
END_DECLS
137
138
/**@}*/
139
140
#endif
memorymap.h
common.h
END_DECLS
#define END_DECLS
Definition:
common.h:34
BEGIN_DECLS
#define BEGIN_DECLS
Definition:
common.h:33
include
libopencm3
cm3
mpu.h
Generated on Tue Mar 7 2023 16:12:17 for libopencm3 by
1.9.4