S32K344/S32K388 MPU Setting Check I'm trying to create a generic, default MPU configuration for the S32K344 and S32K388. I have a basic proposal here, but I would love some confirmation that this looks like it covers everything - especially the register sections - correctly. The types here aren't super important - hopefully you can tell the matching types based on the names. The only odd one is "u4" which is just a wrapper for validating a unsigned 4-bit integer /// S32K344 core-local memories and peripheral windows, using regions 0 through 5. /// /// Geometry: S32K3xx_memory_map.xlsx, Memories sheet, S32K344 column. /// Attributes: S32K3xx RM rev. 12, sections 3.7, 3.9, and 5.2. pub const S32K344_BASE_REGIONS: [MpuRegionConfig; 6] = [ MpuRegionConfig { region: u4::new(0), base_addr: 0x0000_0000, // ITCM: 64 KiB size_log2: 16, access: AccessPermission::ReadWrite, memory_type: MemoryType::NonCacheable, shareable: false, execute_never: false, subregion_disable: 0, }, MpuRegionConfig { region: u4::new(1), base_addr: 0x2000_0000, // DTCM: 128 KiB size_log2: 17, access: AccessPermission::ReadWrite, memory_type: MemoryType::NonCacheable, shareable: false, execute_never: true, subregion_disable: 0, }, MpuRegionConfig { region: u4::new(2), base_addr: 0x2040_0000, // SRAM: 320 KiB size_log2: 19, // 512 KiB envelope; enable five 64 KiB subregions access: AccessPermission::ReadWrite, memory_type: MemoryType::WriteBackReadWriteAllocate, shareable: false, execute_never: true, subregion_disable: 0b1110_0000, }, MpuRegionConfig { region: u4::new(3), base_addr: 0x4000_0000, // AIPS0/1/2: 6 MiB size_log2: 23, // 8 MiB envelope; enable six 1 MiB subregions access: AccessPermission::ReadWrite, memory_type: MemoryType::SharedDevice, shareable: true, execute_never: true, subregion_disable: 0b1100_0000, }, MpuRegionConfig { region: u4::new(4), base_addr: 0x0040_0000, // Program flash: 4 MiB size_log2: 22, access: AccessPermission::ReadOnly, memory_type: MemoryType::WriteThrough, shareable: false, execute_never: false, subregion_disable: 0, }, MpuRegionConfig { region: u4::new(5), base_addr: 0x1000_0000, // Data flash: 128 KiB size_log2: 17, access: AccessPermission::ReadOnly, memory_type: MemoryType::NonCacheable, shareable: false, execute_never: true, subregion_disable: 0, }, ]; /// S32K388 core-local memories and peripheral windows, using regions 0 through 6 /// /// Geometry: S32K3xx_memory_map.xlsx /// Each core sees its own 32 KiB ITCM and 64 KiB DTCM at the same local addresses pub const S32K388_BASE_REGIONS: [MpuRegionConfig; 7] = [ MpuRegionConfig { region: u4::new(0), base_addr: 0x0000_0000, // ITCM: 32 KiB per core size_log2: 15, access: AccessPermission::ReadWrite, memory_type: MemoryType::NonCacheable, shareable: false, execute_never: false, subregion_disable: 0, }, MpuRegionConfig { region: u4::new(1), base_addr: 0x2000_0000, // DTCM: 64 KiB per core size_log2: 16, access: AccessPermission::ReadWrite, memory_type: MemoryType::NonCacheable, shareable: false, execute_never: true, subregion_disable: 0, }, MpuRegionConfig { region: u4::new(2), base_addr: 0x2040_0000, // SRAM: 768 KiB size_log2: 20, // 1 MiB envelope; enable six 128 KiB subregions. access: AccessPermission::ReadWrite, memory_type: MemoryType::WriteBackReadWriteAllocate, shareable: false, execute_never: true, subregion_disable: 0b1100_0000, }, MpuRegionConfig { region: u4::new(3), base_addr: 0x4000_0000, // AIPS0/1/2: 6 MiB size_log2: 23, // 8 MiB envelope; enable six 1 MiB subregions. access: AccessPermission::ReadWrite, memory_type: MemoryType::SharedDevice, shareable: true, execute_never: true, subregion_disable: 0b1100_0000, }, MpuRegionConfig { region: u4::new(4), // Program flash: 8 MiB at 0x0040_0000 is not aligned to 8 MiB. // Enable subregions 2..=5 of a 16 MiB envelope, mapping exactly // 0x0040_0000..0x00C0_0000 (end exclusive). base_addr: 0x0000_0000, size_log2: 24, access: AccessPermission::ReadOnly, memory_type: MemoryType::WriteThrough, shareable: false, execute_never: false, subregion_disable: 0b1100_0011, }, MpuRegionConfig { region: u4::new(5), base_addr: 0x1000_0000, // Data flash: 128 KiB size_log2: 17, access: AccessPermission::ReadOnly, memory_type: MemoryType::NonCacheable, shareable: false, execute_never: true, subregion_disable: 0, }, MpuRegionConfig { region: u4::new(6), base_addr: 0x4400_0000, // AES_ACCEL: 1 KiB, outside AIPS0/1/2 size_log2: 10, access: AccessPermission::ReadWrite, memory_type: MemoryType::SharedDevice, shareable: true, execute_never: true, subregion_disable: 0, }, ]; Thanks in advanced for the help! Re: S32K344/S32K388 MPU Setting Check Hi @kscz
The proposed MPU configuration looks good overall, including the region sizes, alignment, and subregion configuration.
The main remaining point is to ensure that all required peripheral and PPB/system-register areas are properly covered with the appropriate Device, read/write, and execute-never attributes. If a default-deny region is used, it must have lower priority than the explicitly permitted regions.
BR, VaneB Re: S32K344/S32K388 MPU Setting Check Thank you for the check! Re: S32K344/S32K388 MPU Setting Check Hi @kscz
Yes, you are correct. The AIPS regions you have configured look appropriate for covering the address space, and I do not see another peripheral region that would need to be added.
Your understanding of the PPB/system-register area is also correct. Since accesses to the PPB use the default system address map, you do not need to add a separate MPU region for it.
My previous comment was intended more as a general note to use the appropriate Device, read/write, and execute-never attributes for peripheral regions. I did not mean to imply that I had identified a missing region in your configuration.
From this perspective, your current configuration looks good. Re: S32K344/S32K388 MPU Setting Check I'm a little perplexed by your response! "The main remaining point is to ensure that all required peripheral and PPB/system-register areas are properly covered with the appropriate Device, read/write, and execute-never attributes." Am I missing any regions for peripherals? I was hoping for confirmation that the 3 AIPS regions I covered in this configuration was enough that I had correctly covered *all* the peripherals! In a similar vein, I was hoping that you could confirm there were no other regions I'd missed in general. Things like the PPB/system-register areas are exempted from the MPU configuration, no? At least that's my understanding of B3.5.1 of the ARMv7-M architecture reference: > Accesses to the Private Peripheral Bus (PPB) always use the default system address map. > Exception vector reads from the Vector Address Table always use the default system address map. Let me know I've misunderstood something or if this configuration actually looks incomplete!
View full article