[PATCH rtems 4/9] cpu/armv7m: Add _ARMV7M_MPU_set_region function
Christian Mauderer
christian.mauderer at embedded-brains.de
Tue Nov 17 11:04:27 UTC 2020
Make the MPU function defined in the STM32H7 BSP available for all
ARMV7M BSPs.
Update #4180
---
bsps/arm/stm32h7/start/bspstarthooks.c | 48 +++----------------
.../cpu/arm/include/rtems/score/armv7m.h | 37 ++++++++++++++
2 files changed, 43 insertions(+), 42 deletions(-)
diff --git a/bsps/arm/stm32h7/start/bspstarthooks.c b/bsps/arm/stm32h7/start/bspstarthooks.c
index 565bd6876a..97745f0ee8 100644
--- a/bsps/arm/stm32h7/start/bspstarthooks.c
+++ b/bsps/arm/stm32h7/start/bspstarthooks.c
@@ -83,42 +83,6 @@ static void init_peripheral_clocks(void)
}
}
-static uint32_t get_region_size(uintptr_t size)
-{
- if ((size & (size - 1)) == 0) {
- return ARMV7M_MPU_RASR_SIZE(30 - __builtin_clz(size));
- } else {
- return ARMV7M_MPU_RASR_SIZE(31 - __builtin_clz(size));
- }
-}
-
-static void set_region(
- volatile ARMV7M_MPU *mpu,
- uint32_t region,
- uint32_t rasr,
- const void *begin,
- const void *end
-)
-{
- uintptr_t size;
- uint32_t rbar;
-
- RTEMS_OBFUSCATE_VARIABLE(begin);
- RTEMS_OBFUSCATE_VARIABLE(end);
- size = (uintptr_t) end - (uintptr_t) begin;
-
- if ( size > 0 ) {
- rbar = (uintptr_t) begin | region | ARMV7M_MPU_RBAR_VALID;
- rasr |= get_region_size(size);
- } else {
- rbar = region;
- rasr = 0;
- }
-
- mpu->rbar = rbar;
- mpu->rasr = rasr;
-}
-
static void init_mpu(void)
{
volatile ARMV7M_MPU *mpu;
@@ -136,7 +100,7 @@ static void init_mpu(void)
mpu->rasr = 0;
}
- set_region(
+ _ARMV7M_MPU_set_region(
mpu,
0,
ARMV7M_MPU_RASR_XN
@@ -146,7 +110,7 @@ static void init_mpu(void)
stm32h7_memory_sram_axi_begin,
stm32h7_memory_sram_axi_end
);
- set_region(
+ _ARMV7M_MPU_set_region(
mpu,
1,
ARMV7M_MPU_RASR_XN
@@ -156,7 +120,7 @@ static void init_mpu(void)
stm32h7_memory_sdram_1_begin,
stm32h7_memory_sdram_1_end
);
- set_region(
+ _ARMV7M_MPU_set_region(
mpu,
2,
ARMV7M_MPU_RASR_AP(0x5)
@@ -165,7 +129,7 @@ static void init_mpu(void)
bsp_section_start_begin,
bsp_section_text_end
);
- set_region(
+ _ARMV7M_MPU_set_region(
mpu,
3,
ARMV7M_MPU_RASR_XN
@@ -175,7 +139,7 @@ static void init_mpu(void)
bsp_section_rodata_begin,
bsp_section_rodata_end
);
- set_region(
+ _ARMV7M_MPU_set_region(
mpu,
4,
ARMV7M_MPU_RASR_XN
@@ -185,7 +149,7 @@ static void init_mpu(void)
bsp_section_nocache_begin,
bsp_section_nocachenoload_end
);
- set_region(
+ _ARMV7M_MPU_set_region(
mpu,
region - 1,
ARMV7M_MPU_RASR_XN | ARMV7M_MPU_RASR_ENABLE,
diff --git a/cpukit/score/cpu/arm/include/rtems/score/armv7m.h b/cpukit/score/cpu/arm/include/rtems/score/armv7m.h
index c701e1037c..cb126a49ba 100644
--- a/cpukit/score/cpu/arm/include/rtems/score/armv7m.h
+++ b/cpukit/score/cpu/arm/include/rtems/score/armv7m.h
@@ -611,6 +611,43 @@ void _ARMV7M_Supervisor_call( void );
void _ARMV7M_Clock_handler( void );
+static inline uint32_t _ARMV7M_MPU_get_region_size(uintptr_t size)
+{
+ if ((size & (size - 1)) == 0) {
+ return ARMV7M_MPU_RASR_SIZE(30 - __builtin_clz(size));
+ } else {
+ return ARMV7M_MPU_RASR_SIZE(31 - __builtin_clz(size));
+ }
+}
+
+static inline void _ARMV7M_MPU_set_region(
+ volatile ARMV7M_MPU *mpu,
+ uint32_t region,
+ uint32_t rasr,
+ const void *begin,
+ const void *end
+)
+{
+ uintptr_t size;
+ uint32_t rbar;
+
+ RTEMS_OBFUSCATE_VARIABLE(begin);
+ RTEMS_OBFUSCATE_VARIABLE(end);
+ size = (uintptr_t) end - (uintptr_t) begin;
+
+ if ( size > 0 ) {
+ rbar = (uintptr_t) begin | region | ARMV7M_MPU_RBAR_VALID;
+ rasr |= _ARMV7M_MPU_get_region_size(size);
+ } else {
+ rbar = region;
+ rasr = 0;
+ }
+
+ mpu->rbar = rbar;
+ mpu->rasr = rasr;
+}
+
+
#endif /* ASM */
#endif /* ARM_MULTILIB_ARCH_V7M */
--
2.26.2
More information about the devel
mailing list