Skip to content

Commit c503850

Browse files
lucien-nxpcfriedt
authored andcommitted
boards: nxp: rt1180: migrate mpu setting under board folder
- add NXP_BOARD_SPECIFIC_MPU_SETTINGS kconfig to provide a switch for developer if they want to use private mpu settings CONFIG_NXP_BOARD_SPECIFIC_MPU_SETTINGS==1 | NXP default setting CONFIG_NXP_BOARD_SPECIFIC_MPU_SETTINGS==0 | User specific - Use DT function to get memory base address and region size for cm7 - CM33 use dts to set mpu settings - Add REGION_CUSTOMED_MEMORY_SIZE macro provide a common mapping ways to map actual memory_size_kb to "region_size" - The settings of the unified memory on cm33/cm7 cores: ocram1/flexspi2 -> REGION_RAM_NOCACHE_ATTR ocram2/dtcm -> REGION_RAM_NOCACHE_ATTR flexspi/itcm -> REGION_FLASH_ATTR Signed-off-by: Lucien Zhao <[email protected]>
1 parent 8df937e commit c503850

File tree

20 files changed

+254
-102
lines changed

20 files changed

+254
-102
lines changed

arch/arm/core/mpu/arm_mpu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ static int mpu_configure_regions_from_dt(uint8_t *reg_index)
147147
region_conf = _BUILD_REGION_CONF(region[idx], REGION_IO_ATTR);
148148
break;
149149
#endif
150+
#ifdef REGION_DEVICE_ATTR
151+
case DT_MEM_ARM_MPU_DEVICE:
152+
region_conf = _BUILD_REGION_CONF(region[idx], REGION_DEVICE_ATTR);
153+
break;
154+
#endif
150155
#ifdef REGION_EXTMEM_ATTR
151156
case DT_MEM_ARM_MPU_EXTMEM:
152157
region_conf = _BUILD_REGION_CONF(region[idx], REGION_EXTMEM_ATTR);

boards/nxp/mimxrt1180_evk/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
#
2-
# Copyright 2024 NXP
2+
# Copyright 2024-2025 NXP
33
#
44
# SPDX-License-Identifier: Apache-2.0
55
#
66

77
zephyr_library()
88
zephyr_library_sources(board.c)
99

10+
if(CONFIG_SOC_MIMXRT1189_CM33)
11+
zephyr_linker_sources(DTCM_SECTION cm33/dtcm.ld)
12+
endif()
13+
14+
if(CONFIG_NXP_BOARD_SPECIFIC_MPU_SETTINGS)
15+
if(CONFIG_SOC_MIMXRT1189_CM7)
16+
zephyr_sources(cm7/mpu_regions.c)
17+
zephyr_linker_sources(DTCM_SECTION cm7/dtcm.ld)
18+
endif()
19+
endif()
20+
1021
if(CONFIG_NXP_IMXRT_BOOT_HEADER)
1122
if(NOT ((DEFINED CONFIG_BOARD_MIMXRT1180_EVK_MIMXRT1189_CM33)
1223
OR (DEFINED CONFIG_BOARD_MIMXRT1180_EVK_MIMXRT1189_CM7)))

boards/nxp/mimxrt1180_evk/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@ config CM7_FLEXSPI_OFFSET
2020
default 0x28000000
2121
help
2222
This is the FlexSPI offset for CM7.
23+
24+
config NXP_BOARD_SPECIFIC_MPU_SETTINGS
25+
bool "Use default MPU settings for NXP boards"
26+
default y if CPU_HAS_CUSTOM_FIXED_SOC_MPU_REGIONS
27+
help
28+
Enable this option to use the default MPU settings for NXP boards.
29+
This will configure the MPU regions according to the board's memory
30+
map and peripherals.

soc/nxp/imxrt/imxrt118x/m33/dtcm.ld renamed to boards/nxp/mimxrt1180_evk/cm33/dtcm.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 NXP
2+
* Copyright 2024-2025 NXP
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright 2024-2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
*(NonCacheable)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/devicetree.h>
8+
#include <zephyr/arch/arm/cortex_m/arm_mpu_mem_cfg.h>
9+
10+
#define MEMORY_REGION_SIZE_KB(SIZE) (SIZE / 1024)
11+
12+
#define ITCM_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(itcm), 0)
13+
#define DTCM_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(dtcm), 0)
14+
#define OCRAM1_SHM_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(ocram1), 0)
15+
#define OCRAM2_SHM_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(ocram2), 0)
16+
#define HYPER_RAM_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(flexspi2), 1)
17+
#define QSPI_FLASH_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(flexspi), 1)
18+
#define PERIPHERAL_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(peripheral), 0)
19+
20+
#define REGION_ITCM_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(itcm), 0)
21+
#define REGION_ITCM_SIZE \
22+
REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(ITCM_SIZE))
23+
#define REGION_DTCM_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(dtcm), 0)
24+
#define REGION_DTCM_SIZE \
25+
REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(DTCM_SIZE))
26+
#define REGION_OCRAM1_SHM_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(ocram1), 0)
27+
#define REGION_OCRAM1_SHM_SIZE \
28+
REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(OCRAM1_SHM_SIZE))
29+
#define REGION_OCRAM2_SHM_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(ocram2), 0)
30+
#define REGION_OCRAM2_SHM_SIZE \
31+
REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(OCRAM2_SHM_SIZE))
32+
#define REGION_HYPER_RAM_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(flexspi2), 1)
33+
#define REGION_HYPER_RAM_SIZE \
34+
REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(HYPER_RAM_SIZE))
35+
#define REGION_QSPI_FLASH_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(flexspi), 1)
36+
#define REGION_QSPI_FLASH_SIZE \
37+
REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(QSPI_FLASH_SIZE))
38+
#define REGION_PERIPHERAL_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(peripheral), 0)
39+
#define REGION_PERIPHERAL_SIZE \
40+
REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(PERIPHERAL_SIZE))
41+
42+
static const struct arm_mpu_region mpu_regions[] = {
43+
/*
44+
* Add "UNMAPPED" region to deny access to whole address space to
45+
* workaround speculative prefetch.
46+
* Refer to Arm errata 1013783-B for more details.
47+
*/
48+
MPU_REGION_ENTRY("UNMAPPED", 0,
49+
{REGION_4G | MPU_RASR_XN_Msk | P_NA_U_NA_Msk}),
50+
51+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(itcm), okay)
52+
MPU_REGION_ENTRY("ITCM", REGION_ITCM_BASE_ADDRESS,
53+
REGION_FLASH_ATTR(REGION_ITCM_SIZE)),
54+
#endif
55+
56+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(dtcm), okay)
57+
MPU_REGION_ENTRY("DTCM", REGION_DTCM_BASE_ADDRESS,
58+
REGION_RAM_NOCACHE_ATTR(REGION_DTCM_SIZE)),
59+
#endif
60+
61+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ocram1), okay)
62+
MPU_REGION_ENTRY("OCRAM1", REGION_OCRAM1_SHM_BASE_ADDRESS,
63+
REGION_RAM_ATTR(REGION_OCRAM1_SHM_SIZE)),
64+
#endif
65+
66+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ocram2), okay)
67+
MPU_REGION_ENTRY("OCRAM2", REGION_OCRAM2_SHM_BASE_ADDRESS,
68+
REGION_RAM_NOCACHE_ATTR(REGION_OCRAM2_SHM_SIZE)),
69+
#endif
70+
71+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(hyperram0), okay)
72+
MPU_REGION_ENTRY("HYPER_RAM", REGION_HYPER_RAM_BASE_ADDRESS,
73+
REGION_RAM_ATTR(REGION_HYPER_RAM_SIZE)),
74+
#endif
75+
76+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(w25q128jw), okay)
77+
MPU_REGION_ENTRY("QSPI_FLASH", REGION_QSPI_FLASH_BASE_ADDRESS,
78+
REGION_FLASH_ATTR(REGION_QSPI_FLASH_SIZE)),
79+
#endif
80+
81+
MPU_REGION_ENTRY("PERIPHERAL", REGION_PERIPHERAL_BASE_ADDRESS,
82+
REGION_PPB_ATTR(REGION_PERIPHERAL_SIZE)),
83+
};
84+
85+
const struct arm_mpu_config mpu_config = {
86+
.num_regions = ARRAY_SIZE(mpu_regions),
87+
.mpu_regions = mpu_regions,
88+
};

boards/nxp/mimxrt1180_evk/cm7_flash_boot.overlay

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
zephyr,code-partition = &slot1_partition;
1111
};
1212
};
13+
14+
&flexspi {
15+
status = "okay";
16+
};

boards/nxp/mimxrt1180_evk/mimxrt1180_evk.dtsi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,15 @@
181181
};
182182

183183
&flexspi {
184-
status = "okay";
184+
/*
185+
* If booting with XIP from FlexSPI flash, the flash memory will be initialized by the
186+
* bootloader in ROM.
187+
* If not configured by the ROM bootloader, the user must ensure the w25q128jw QSPI device
188+
* is enabled in the DTS, otherwise, the user must set 'status = "disabled";
189+
* Note: mpu_region.c uses the status property from the DTS to configure the
190+
* corresponding MPU settings.
191+
*/
192+
status = "disabled";
185193
ahb-prefetch;
186194
ahb-read-addr-opt;
187195
rx-clock-source = <1>;

boards/nxp/mimxrt1180_evk/mimxrt1180_evk_mimxrt1189_cm33.dts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@
3131
/* Winbond W957A8MFYA5K */
3232
device_type = "memory";
3333
reg = <0x14000000 DT_SIZE_M(8)>;
34+
zephyr,memory-attr = <DT_MEM_ARM(ATTR_MPU_RAM)>;
35+
/*
36+
* Currently, HyperRAM on this board must be accessed under XIP mode,
37+
* so that the ROM bootloader can initialize it by reading the XMCD configuration.
38+
* These XMCD configurations are stored in the default settings file
39+
* `xip/evkmimxrt1180_flexspi_nor_config.c`. (If modifications are needed,
40+
* please refer to the examples and the "System Boot" chapter in the
41+
* RT1180 Reference Manual.)
42+
* The CM33 core of the MIMXRT1180_EVK runs in XIP mode and uses the
43+
* HyperRAM space as the RAM region by default. Therefore, the status of the
44+
* full hyperram0 memory node is set to "okay" for cm33 core.
45+
* At this point, the CM7 core can also access the HyperRAM.
46+
* However, since the entire HyperRAM region is occupied in the CM33's DTS,
47+
* users can allocate the HyperRAM reasonably so that both cores (CM33 and CM7)
48+
* can use HyperRAM as their RAM region.
49+
*
50+
* If not configured by the ROM bootloader, the user must ensure the hyperram0
51+
* device is enabled in the DTS, otherwise, the user must set 'status = "disabled".
52+
* Note: mpu_region.c uses the status property from the DTS to configure the
53+
* corresponding MPU settings.
54+
*/
55+
status = "okay";
56+
};
57+
58+
qspi_flash: memory@38000000 {
59+
device_type = "memory";
60+
reg = <0x38000000 DT_SIZE_M(16)>;
61+
zephyr,memory-attr = <DT_MEM_ARM(ATTR_MPU_FLASH)>;
62+
status = "okay";
3463
};
3564
};
3665

@@ -114,3 +143,7 @@ temp_sensor: &tmpsns {
114143
&sai1 {
115144
status = "okay";
116145
};
146+
147+
&flexspi {
148+
status = "okay";
149+
};

boards/nxp/mimxrt1180_evk/mimxrt1180_evk_mimxrt1189_cm7.dts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,31 @@
2525
nxp,m7-partition = &slot1_partition;
2626
};
2727

28-
hyperram0: memory@04000000 {
28+
hyperram0: memory@4000000 {
2929
/* Winbond W957A8MFYA5K */
3030
device_type = "memory";
31-
reg = <0x04000000 DT_SIZE_M(8)>;
31+
reg = <0x4000000 DT_SIZE_M(8)>;
32+
/*
33+
* Currently, HyperRAM on this board must be accessed under XIP mode,
34+
* so that the ROM bootloader can initialize it by reading the XMCD configuration.
35+
* These XMCD configurations are stored in the default settings file
36+
* `xip/evkmimxrt1180_flexspi_nor_config.c`. (If modifications are needed,
37+
* please refer to the examples and the "System Boot" chapter in the
38+
* RT1180 Reference Manual.)
39+
* The CM33 core of the MIMXRT1180_EVK runs in XIP mode and uses the
40+
* HyperRAM space as the RAM region by default. Therefore, the status of the
41+
* full hyperram0 memory node is set to "okay" for cm33 core.
42+
* At this point, the CM7 core can also access the HyperRAM.
43+
* However, since the entire HyperRAM region is occupied in the CM33's DTS,
44+
* users can allocate the HyperRAM reasonably so that both cores (CM33 and CM7)
45+
* can use HyperRAM as their RAM region.
46+
*
47+
* If not configured by the ROM bootloader, the user must ensure the hyperram0
48+
* device is enabled in the DTS, otherwise, the user must set 'status = "disabled";
49+
* Note: mpu_region.c uses the status property from the DTS to configure the
50+
* corresponding MPU settings.
51+
*/
52+
status = "disabled";
3253
};
3354
};
3455

0 commit comments

Comments
 (0)