Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "stm32_mpu.h"
Private define
#define ARRAY_ADDRESS_START
#define ARRAY_SIZE
#define ARRAY_REGION_NUMBER
Private variables
PrivilegedReadOnlyArray
uiTemp
MPU_Config()
MPU_AccessPermConfig()
Files
loading...
CodeScopeSTM32 Libraries and SamplesCORTEXM_MPUSrc/stm32_mpu.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file Cortex/CORTEXM_MPU/Src/stm32_mpu.c * @author MCD Application Team * @brief Access rights configuration using Cortex-M4 MPU regions. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "stm32_mpu.h" /** @addtogroup STM32F4xx_HAL_Examples * @{ *//* ... */ /** @addtogroup CORTEXM_MPU * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define ARRAY_ADDRESS_START (0x20002000UL) #define ARRAY_SIZE MPU_REGION_SIZE_32B #define ARRAY_REGION_NUMBER MPU_REGION_NUMBER3 Private define /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ #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 /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** * @brief Configures the main MPU regions. * @param None * @retval None *//* ... */ void MPU_Config(void) { MPU_Region_InitTypeDef MPU_InitStruct; /* Disable MPU */ HAL_MPU_Disable(); /* Configure RAM region as Region N�0, 8kB of size and R/W region */ 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); /* Configure FLASH region as REGION N�1, 1MB of size and R/W region */ MPU_InitStruct.BaseAddress = FLASH_ADDRESS_START; MPU_InitStruct.Size = FLASH_SIZE; MPU_InitStruct.Number = FLASH_REGION_NUMBER; HAL_MPU_ConfigRegion(&MPU_InitStruct); /* Configure Peripheral region as REGION N�2, 0.5GB of size, R/W and Execute Never region *//* ... */ 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); /* Enable MPU */ HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT); }{ ... } /** * @brief This function configure the access right using Cortex-M4 MPU regions. * @param None * @retval None *//* ... */ void MPU_AccessPermConfig(void) { MPU_Region_InitTypeDef MPU_InitStruct; /* Configure region for PrivilegedReadOnlyArray as REGION N�3, 32byte and R only in privileged mode *//* ... */ /* Disable MPU */ 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); /* Enable MPU */ HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT); /* Read from PrivilegedReadOnlyArray. This will not generate error */ uiTemp = PrivilegedReadOnlyArray[0]; /* Uncomment the following line to write to PrivilegedReadOnlyArray. This will generate error *//* ... */ PrivilegedReadOnlyArray[0] = 'e'; }{ ... } /** * @} *//* ... */ /** * @} *//* ... */