From c2b3a517f620111be2c634bea61821cced866d5e Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Thu, 15 Aug 2024 11:20:48 -0500 Subject: [PATCH] bsps/stm32h7: Honor the intent of the MPU alignment option Currently, if a BSP is built without MPU alignment enforcement, the MPU is still enabled and can produce a non-functional binary since code can be mixed with data within a memory region and memory regions are marked as read-only or no-execute based on section addresses and sizes leading to overlapping regions being defined which causes the later-defined region to take precedence. This change disables the MPU when alignment is not enforced, allowing the binary to function. --- .../stm32h7/boards/stm/nucleo-h743zi/stm32h7-bspstarthooks.c | 2 ++ .../stm32h7/boards/stm/nucleo-h755zi/stm32h7-bspstarthooks.c | 2 ++ .../stm32h7/boards/stm/stm32h743i-eval/stm32h7-bspstarthooks.c | 2 ++ .../stm32h7/boards/stm/stm32h747i-disco/stm32h7-bspstarthooks.c | 2 ++ .../stm32h7/boards/stm/stm32h757i-eval/stm32h7-bspstarthooks.c | 2 ++ .../stm32h7/boards/stm/stm32h7b3i-dk/stm32h7-bspstarthooks.c | 2 ++ 6 files changed, 12 insertions(+) diff --git a/bsps/arm/stm32h7/boards/stm/nucleo-h743zi/stm32h7-bspstarthooks.c b/bsps/arm/stm32h7/boards/stm/nucleo-h743zi/stm32h7-bspstarthooks.c index 5b2f57b205..c6824be6ea 100644 --- a/bsps/arm/stm32h7/boards/stm/nucleo-h743zi/stm32h7-bspstarthooks.c +++ b/bsps/arm/stm32h7/boards/stm/nucleo-h743zi/stm32h7-bspstarthooks.c @@ -62,8 +62,10 @@ void bsp_start_hook_0(void) SCB_EnableDCache(); } +#ifdef STM32H7_ENABLE_MPU_ALIGNMENT _ARMV7M_MPU_Setup(ARMV7M_MPU_CTRL_DEFAULT, stm32h7_config_mpu_region, stm32h7_config_mpu_region_count); #endif +#endif } void bsp_start_hook_1(void) diff --git a/bsps/arm/stm32h7/boards/stm/nucleo-h755zi/stm32h7-bspstarthooks.c b/bsps/arm/stm32h7/boards/stm/nucleo-h755zi/stm32h7-bspstarthooks.c index 5b2f57b205..c6824be6ea 100644 --- a/bsps/arm/stm32h7/boards/stm/nucleo-h755zi/stm32h7-bspstarthooks.c +++ b/bsps/arm/stm32h7/boards/stm/nucleo-h755zi/stm32h7-bspstarthooks.c @@ -62,8 +62,10 @@ void bsp_start_hook_0(void) SCB_EnableDCache(); } +#ifdef STM32H7_ENABLE_MPU_ALIGNMENT _ARMV7M_MPU_Setup(ARMV7M_MPU_CTRL_DEFAULT, stm32h7_config_mpu_region, stm32h7_config_mpu_region_count); #endif +#endif } void bsp_start_hook_1(void) diff --git a/bsps/arm/stm32h7/boards/stm/stm32h743i-eval/stm32h7-bspstarthooks.c b/bsps/arm/stm32h7/boards/stm/stm32h743i-eval/stm32h7-bspstarthooks.c index 450c916346..8207f47f7f 100644 --- a/bsps/arm/stm32h7/boards/stm/stm32h743i-eval/stm32h7-bspstarthooks.c +++ b/bsps/arm/stm32h7/boards/stm/stm32h743i-eval/stm32h7-bspstarthooks.c @@ -63,8 +63,10 @@ void bsp_start_hook_0(void) SCB_EnableDCache(); } +#ifdef STM32H7_ENABLE_MPU_ALIGNMENT _ARMV7M_MPU_Setup(ARMV7M_MPU_CTRL_DEFAULT, stm32h7_config_mpu_region, stm32h7_config_mpu_region_count); #endif +#endif } void bsp_start_hook_1(void) diff --git a/bsps/arm/stm32h7/boards/stm/stm32h747i-disco/stm32h7-bspstarthooks.c b/bsps/arm/stm32h7/boards/stm/stm32h747i-disco/stm32h7-bspstarthooks.c index 450c916346..8207f47f7f 100644 --- a/bsps/arm/stm32h7/boards/stm/stm32h747i-disco/stm32h7-bspstarthooks.c +++ b/bsps/arm/stm32h7/boards/stm/stm32h747i-disco/stm32h7-bspstarthooks.c @@ -63,8 +63,10 @@ void bsp_start_hook_0(void) SCB_EnableDCache(); } +#ifdef STM32H7_ENABLE_MPU_ALIGNMENT _ARMV7M_MPU_Setup(ARMV7M_MPU_CTRL_DEFAULT, stm32h7_config_mpu_region, stm32h7_config_mpu_region_count); #endif +#endif } void bsp_start_hook_1(void) diff --git a/bsps/arm/stm32h7/boards/stm/stm32h757i-eval/stm32h7-bspstarthooks.c b/bsps/arm/stm32h7/boards/stm/stm32h757i-eval/stm32h7-bspstarthooks.c index a5d495f521..42c89cd90e 100644 --- a/bsps/arm/stm32h7/boards/stm/stm32h757i-eval/stm32h7-bspstarthooks.c +++ b/bsps/arm/stm32h7/boards/stm/stm32h757i-eval/stm32h7-bspstarthooks.c @@ -79,8 +79,10 @@ void bsp_start_hook_0(void) SCB_EnableDCache(); } +#ifdef STM32H7_ENABLE_MPU_ALIGNMENT _ARMV7M_MPU_Setup(ARMV7M_MPU_CTRL_DEFAULT, stm32h7_config_mpu_region, stm32h7_config_mpu_region_count); #endif +#endif } void bsp_start_hook_1(void) diff --git a/bsps/arm/stm32h7/boards/stm/stm32h7b3i-dk/stm32h7-bspstarthooks.c b/bsps/arm/stm32h7/boards/stm/stm32h7b3i-dk/stm32h7-bspstarthooks.c index 450c916346..8207f47f7f 100644 --- a/bsps/arm/stm32h7/boards/stm/stm32h7b3i-dk/stm32h7-bspstarthooks.c +++ b/bsps/arm/stm32h7/boards/stm/stm32h7b3i-dk/stm32h7-bspstarthooks.c @@ -63,8 +63,10 @@ void bsp_start_hook_0(void) SCB_EnableDCache(); } +#ifdef STM32H7_ENABLE_MPU_ALIGNMENT _ARMV7M_MPU_Setup(ARMV7M_MPU_CTRL_DEFAULT, stm32h7_config_mpu_region, stm32h7_config_mpu_region_count); #endif +#endif } void bsp_start_hook_1(void)