Skip to content

Commit e4dcd5d

Browse files
erwangowearyzen
authored andcommitted
soc: st: stm32n6: Provide static mpu regions for !XIP
In !XIP case, provide RAM_RO and RAM_RW regions with their respective MPU configurations. Signed-off-by: Erwan Gouriou <[email protected]> Co-authored-by: Sudan Landge <[email protected]>
1 parent 8e6b779 commit e4dcd5d

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

soc/st/stm32/stm32n6x/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ zephyr_sources_ifdef(CONFIG_STM32N6_NPU
1111

1212
zephyr_include_directories(.)
1313

14+
if(CONFIG_CPU_HAS_CUSTOM_FIXED_SOC_MPU_REGIONS)
15+
zephyr_linker_sources(SECTIONS mpu_regions.ld)
16+
zephyr_sources(mpu_regions.c)
17+
endif()
18+
1419
set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "")
1520

1621
zephyr_linker_sources_ifdef(CONFIG_BOOTLOADER_MCUBOOT SECTIONS ram_check.ld)

soc/st/stm32/stm32n6x/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ config SOC_SERIES_STM32N6X
2222
select BUILD_OUTPUT_BIN
2323
# MPU_GAP_FILLING is default when !USERSPACE, select it in the other case as well.
2424
select MPU_GAP_FILLING if USERSPACE
25+
select CPU_HAS_CUSTOM_FIXED_SOC_MPU_REGIONS if USERSPACE && !XIP
2526

2627
config STM32N6_BOOT_SERIAL
2728
bool "Serial boot target (USB)"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright The Zephyr Project Contributors
3+
* Copyright (c) 2025 STMicroelectronics
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include <zephyr/linker/linker-defs.h>
9+
#include <zephyr/arch/arm/mpu/arm_mpu.h>
10+
11+
extern const uint32_t __rom_region_limit[];
12+
extern const uint32_t __image_ram_limit[];
13+
14+
static const struct arm_mpu_region mpu_regions[] = {
15+
{
16+
.base = (uint32_t)__rom_region_start,
17+
.name = "SRAM_RO",
18+
.attr = {
19+
.rbar = RO_Msk | NON_SHAREABLE_Msk,
20+
.mair_idx = MPU_MAIR_INDEX_FLASH,
21+
.pxn = !PRIV_EXEC_NEVER,
22+
.r_limit = (uint32_t)__rom_region_limit,
23+
},
24+
},
25+
{
26+
.base = (uint32_t)_image_ram_start,
27+
.name = "SRAM_RW",
28+
.attr = {
29+
.rbar = NOT_EXEC | P_RW_U_NA_Msk | NON_SHAREABLE_Msk,
30+
.mair_idx = MPU_MAIR_INDEX_SRAM,
31+
.pxn = !PRIV_EXEC_NEVER,
32+
.r_limit = (uint32_t)__image_ram_limit,
33+
},
34+
}
35+
};
36+
37+
const struct arm_mpu_config mpu_config = {
38+
.num_regions = ARRAY_SIZE(mpu_regions),
39+
.mpu_regions = mpu_regions,
40+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright The Zephyr Project Contributors
3+
* Copyright (c) 2025 STMicroelectronics
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
/** \brief MPU Region Base Address Register Definitions */
9+
#define MPU_RBAR_BASE_Pos 5 /*!< MPU RBAR: BASE Position */
10+
#define MPU_RBAR_BASE_Msk (0x7FFFFFF << MPU_RBAR_BASE_Pos) /*!< MPU RBAR: BASE Mask */
11+
12+
/** \brief MPU Region Limit Address Register Definitions */
13+
#define MPU_RLAR_LIMIT_Pos 5 /*!< MPU RLAR: LIMIT Position */
14+
#define MPU_RLAR_LIMIT_Msk (0x7FFFFFF << MPU_RLAR_LIMIT_Pos) /*!< MPU RLAR: LIMIT Mask */
15+
16+
#define REGION_LIMIT_ADDR(base, size) (((base & MPU_RBAR_BASE_Msk) + size - 1) & MPU_RLAR_LIMIT_Msk)
17+
18+
PROVIDE(__rom_region_limit = REGION_LIMIT_ADDR(__rom_region_start, __rom_region_size));
19+
PROVIDE(__image_ram_limit = REGION_LIMIT_ADDR(_image_ram_start, (CONFIG_SRAM_SIZE * 1024)));

0 commit comments

Comments
 (0)