@@ -47,7 +47,7 @@ void mbed_mpu_init()
47
47
48
48
// Reset all mapping
49
49
for (uint32_t i = 0 ; i < regions ; i ++ ) {
50
- ARM_MPU_ClrRegionEx ( MPU , i );
50
+ ARM_MPU_ClrRegion ( i );
51
51
}
52
52
53
53
/*
@@ -64,61 +64,67 @@ void mbed_mpu_init()
64
64
* 0xE0000000 - 0xFFFFFFFF System No
65
65
*/
66
66
67
- uint32_t region ;
68
- uint8_t outer ;
69
- uint8_t inner ;
70
-
71
- region = 0 ;
72
- MPU -> RNR = region ;
73
- outer = 0xA ; // Write-Through, Non-transient, Read-allocate
74
- inner = 0xA ; // Write-Through, Non-transient, Read-allocate
75
- ARM_MPU_SetMemAttrEx (MPU , region , (outer << 4 ) | (inner << 0 ));
76
- MPU -> RBAR = (0x00000000 & MPU_RBAR_BASE_Msk ) | // Start address is 0x00000000
77
- (0 << MPU_RBAR_SH_Pos ) | // Not shareable
78
- (3 << MPU_RBAR_AP_Pos ) | // RO allowed by all privilege levels
79
- (0 << MPU_RBAR_XN_Pos ); // Execute Never disabled
80
- MPU -> RLAR = (0x1FFFFFFF & MPU_RLAR_LIMIT_Msk ) | // Last address is 0x1FFFFFFF
81
- (region << MPU_RLAR_AttrIndx_Pos ) | // Attribute index - configured to be the same as the region number
82
- (1 << MPU_RLAR_EN_Pos ); // Region enabled
83
-
84
- region = 1 ;
85
- MPU -> RNR = region ;
86
- outer = 0xF ; // Write-Back, Non-transient, Read-allocate, Write-allocate
87
- outer = 0xF ; // Write-Back, Non-transient, Read-allocate, Write-allocate
88
- ARM_MPU_SetMemAttrEx (MPU , region , (outer << 4 ) | (inner << 0 ));
89
- MPU -> RBAR = (0x20000000 & MPU_RBAR_BASE_Msk ) | // Start address is 0x20000000
90
- (0 << MPU_RBAR_SH_Pos ) | // Not shareable
91
- (1 << MPU_RBAR_AP_Pos ) | // RW allowed by all privilege levels
92
- (1 << MPU_RBAR_XN_Pos ); // Execute Never enabled
93
- MPU -> RLAR = (0x3FFFFFFF & MPU_RLAR_LIMIT_Msk ) | // Last address is 0x3FFFFFFF
94
- (region << MPU_RLAR_AttrIndx_Pos ) | // Attribute index - configured to be the same as the region number
95
- (1 << MPU_RLAR_EN_Pos ); // Region enabled
96
-
97
- region = 2 ;
98
- MPU -> RNR = region ;
99
- outer = 0xF ; // Write-Back, Non-transient, Read-allocate, Write-allocate
100
- outer = 0xF ; // Write-Back, Non-transient, Read-allocate, Write-allocate
101
- ARM_MPU_SetMemAttrEx (MPU , region , (outer << 4 ) | (inner << 0 ));
102
- MPU -> RBAR = (0x60000000 & MPU_RBAR_BASE_Msk ) | // Start address is 0x60000000
103
- (0 << MPU_RBAR_SH_Pos ) | // Not shareable
104
- (1 << MPU_RBAR_AP_Pos ) | // RW allowed by all privilege levels
105
- (1 << MPU_RBAR_XN_Pos ); // Execute Never enabled
106
- MPU -> RLAR = (0x7FFFFFFF & MPU_RLAR_LIMIT_Msk ) | // Last address is 0x7FFFFFFF
107
- (region << MPU_RLAR_AttrIndx_Pos ) | // Attribute index - configured to be the same as the region number
108
- (1 << MPU_RLAR_EN_Pos ); // Region enabled
109
-
110
- region = 3 ;
111
- MPU -> RNR = region ;
112
- outer = 0xA ; // Write-Through, Non-transient, Read-allocate
113
- inner = 0xA ; // Write-Through, Non-transient, Read-allocate
114
- ARM_MPU_SetMemAttrEx (MPU , region , (outer << 4 ) | (inner << 0 ));
115
- MPU -> RBAR = (0x80000000 & MPU_RBAR_BASE_Msk ) | // Start address is 0x80000000
116
- (0 << MPU_RBAR_SH_Pos ) | // Not shareable
117
- (1 << MPU_RBAR_AP_Pos ) | // RW allowed by all privilege levels
118
- (1 << MPU_RBAR_XN_Pos ); // Execute Never enabled
119
- MPU -> RLAR = (0x9FFFFFFF & MPU_RLAR_LIMIT_Msk ) | // Last address is 0x9FFFFFFF
120
- (region << MPU_RLAR_AttrIndx_Pos ) | // Attribute index - configured to be the same as the region number
121
- (1 << MPU_RLAR_EN_Pos ); // Region enabled
67
+ const uint8_t WTRA = ARM_MPU_ATTR_MEMORY_ (1 , 0 , 1 , 0 ); // Non-transient, Write-Through, Read-allocate, Not Write-allocate
68
+ const uint8_t WBWARA = ARM_MPU_ATTR_MEMORY_ (1 , 1 , 1 , 1 ); // Non-transient, Write-Back, Read-allocate, Write-allocate
69
+ enum {
70
+ AttrIndex_WTRA ,
71
+ AttrIndex_WBWARA ,
72
+ };
73
+
74
+ ARM_MPU_SetMemAttr (AttrIndex_WTRA , ARM_MPU_ATTR (WTRA , WTRA ));
75
+ ARM_MPU_SetMemAttr (AttrIndex_WBWARA , ARM_MPU_ATTR (WBWARA , WBWARA ));
76
+
77
+ ARM_MPU_SetRegion (
78
+ 0 , // Region
79
+ ARM_MPU_RBAR (
80
+ 0x00000000 , // Base
81
+ ARM_MPU_SH_NON , // Non-shareable
82
+ 1 , // Read-Only
83
+ 1 , // Non-Privileged
84
+ 0 ), // Execute Never disabled
85
+ ARM_MPU_RLAR (
86
+ 0x1FFFFFFF , // Limit
87
+ AttrIndex_WTRA ) // Attribute index - Write-Through, Read-allocate
88
+ );
89
+
90
+ ARM_MPU_SetRegion (
91
+ 1 , // Region
92
+ ARM_MPU_RBAR (
93
+ 0x20000000 , // Base
94
+ ARM_MPU_SH_NON , // Non-shareable
95
+ 0 , // Read-Write
96
+ 1 , // Non-Privileged
97
+ 1 ), // Execute Never enabled
98
+ ARM_MPU_RLAR (
99
+ 0x3FFFFFFF , // Limit
100
+ AttrIndex_WBWARA ) // Attribute index - Write-Back, Write-allocate
101
+ );
102
+
103
+ ARM_MPU_SetRegion (
104
+ 2 , // Region
105
+ ARM_MPU_RBAR (
106
+ 0x60000000 , // Base
107
+ ARM_MPU_SH_NON , // Non-shareable
108
+ 0 , // Read-Write
109
+ 1 , // Non-Privileged
110
+ 1 ), // Execute Never enabled
111
+ ARM_MPU_RLAR (
112
+ 0x7FFFFFFF , // Limit
113
+ AttrIndex_WBWARA ) // Attribute index - Write-Back, Write-allocate
114
+ );
115
+
116
+ ARM_MPU_SetRegion (
117
+ 3 , // Region
118
+ ARM_MPU_RBAR (
119
+ 0x80000000 , // Base
120
+ ARM_MPU_SH_NON , // Non-shareable
121
+ 0 , // Read-Write
122
+ 1 , // Non-Privileged
123
+ 1 ), // Execute Never enabled
124
+ ARM_MPU_RLAR (
125
+ 0x9FFFFFFF , // Limit
126
+ AttrIndex_WTRA ) // Attribute index - Write-Through, Read-allocate
127
+ );
122
128
123
129
// Enable the MPU
124
130
MPU -> CTRL =
0 commit comments