1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
30
31
37
38
39
40
42
43
46
47
49
50
51
52
53
54
55
56
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
92
93
94
95
96
97
98
99
100
101
102
103
108
109
110
111
112
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
139
140
141
142
145
146
/* ... */
#include "stm32_mpu.h"
/* ... */
/* ... */
Includes
#define ARRAY_ADDRESS_START (0x20002000UL)
#define ARRAY_SIZE MPU_REGION_SIZE_32B
#define ARRAY_REGION_NUMBER MPU_REGION_NUMBER3
Private define
#if defined ( __CC_ARM )
uint8_t PrivilegedReadOnlyArray[32] __attribute__((at(0x20002000)));
/* ... */
#elif defined ( __ICCARM__ )
#pragma location=0x20002000
__no_init uint8_t PrivilegedReadOnlyArray[32];
/* ... */
#elif defined ( __GNUC__ )
uint8_t PrivilegedReadOnlyArray[32] __attribute__((section(".ROarraySection")));
/* ... */
#endif
uint8_t uiTemp;
Private variables
/* ... */
void MPU_Config(void)
{
MPU_Region_InitTypeDef MPU_InitStruct;
HAL_MPU_Disable();
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = RAM_ADDRESS_START;
MPU_InitStruct.Size = RAM_SIZE;
MPU_InitStruct.AccessPermission = portMPU_REGION_READ_WRITE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.Number = RAM_REGION_NUMBER;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
MPU_InitStruct.BaseAddress = FLASH_ADDRESS_START;
MPU_InitStruct.Size = FLASH_SIZE;
MPU_InitStruct.Number = FLASH_REGION_NUMBER;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/* ... */
MPU_InitStruct.BaseAddress = PERIPH_ADDRESS_START;
MPU_InitStruct.Size = PERIPH_SIZE;
MPU_InitStruct.Number = PERIPH_REGION_NUMBER;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}{ ... }
/* ... */
void MPU_AccessPermConfig(void)
{
MPU_Region_InitTypeDef MPU_InitStruct;
/* ... */
HAL_MPU_Disable();
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = ARRAY_ADDRESS_START;
MPU_InitStruct.Size = ARRAY_SIZE;
MPU_InitStruct.AccessPermission = portMPU_REGION_PRIVILEGED_READ_ONLY;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.Number = ARRAY_REGION_NUMBER;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
uiTemp = PrivilegedReadOnlyArray[0];
/* ... */
PrivilegedReadOnlyArray[0] = 'e';
}{ ... }
/* ... */
/* ... */