|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Analog Devices, Inc. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/devicetree.h> |
| 8 | +#include <zephyr/storage/flash_map.h> |
| 9 | +#include <zephyr/arch/arm/cortex_m/arm_mpu_mem_cfg.h> |
| 10 | + |
| 11 | +/* |
| 12 | + * Define noncacheable flash region attributes using noncacheable SRAM memory |
| 13 | + * attribute index. |
| 14 | + */ |
| 15 | +#define MAX32_FLASH_NON_CACHEABLE(base, size) \ |
| 16 | + { \ |
| 17 | + .rbar = RO_Msk | NON_SHAREABLE_Msk, \ |
| 18 | + .mair_idx = MPU_MAIR_INDEX_SRAM_NOCACHE, \ |
| 19 | + .r_limit = REGION_LIMIT_ADDR(base, size), \ |
| 20 | + } |
| 21 | + |
| 22 | +#define MAX32_MPU_REGION(name, base, attr, size) MPU_REGION_ENTRY(name, (base), attr((base), size)) |
| 23 | + |
| 24 | +/* |
| 25 | + * The MPU regions are defined in the following way: |
| 26 | + * - Cacheable flash region |
| 27 | + * - Non-cacheable flash region, i.e., storage area at the end of the flash |
| 28 | + * - SRAM region |
| 29 | + * If the storage partition is not defined, the flash region spans the whole |
| 30 | + * flash. |
| 31 | + */ |
| 32 | +static const struct arm_mpu_region mpu_regions[] = { |
| 33 | +#if FIXED_PARTITION_EXISTS(storage_partition) |
| 34 | +#define STORAGE_ADDR (CONFIG_FLASH_BASE_ADDRESS + FIXED_PARTITION_OFFSET(storage_partition)) |
| 35 | +#define STORAGE_SIZE (FIXED_PARTITION_SIZE(storage_partition) >> 10) |
| 36 | + MAX32_MPU_REGION("FLASH", CONFIG_FLASH_BASE_ADDRESS, REGION_FLASH_ATTR, |
| 37 | + KB(CONFIG_FLASH_SIZE - STORAGE_SIZE)), |
| 38 | + MAX32_MPU_REGION("STORAGE", STORAGE_ADDR, MAX32_FLASH_NON_CACHEABLE, KB(STORAGE_SIZE)), |
| 39 | +#else |
| 40 | + MAX32_MPU_REGION("FLASH", CONFIG_FLASH_BASE_ADDRESS, REGION_FLASH_ATTR, |
| 41 | + KB(CONFIG_FLASH_SIZE)), |
| 42 | +#endif |
| 43 | + MAX32_MPU_REGION("SRAM", CONFIG_SRAM_BASE_ADDRESS, REGION_RAM_ATTR, KB(CONFIG_SRAM_SIZE)), |
| 44 | +}; |
| 45 | + |
| 46 | +const struct arm_mpu_config mpu_config = { |
| 47 | + .num_regions = ARRAY_SIZE(mpu_regions), |
| 48 | + .mpu_regions = mpu_regions, |
| 49 | +}; |
0 commit comments