Skip to content

Support region padding for MPU programming#146

Open
thejpster wants to merge 3 commits intorust-embedded:mainfrom
thejpster:support-padding
Open

Support region padding for MPU programming#146
thejpster wants to merge 3 commits intorust-embedded:mainfrom
thejpster:support-padding

Conversation

@thejpster
Copy link
Copy Markdown
Contributor

@thejpster thejpster commented Mar 6, 2026

Make it easier to set up the MPU

  • Add an API to get the various linker output sections (aarch32_rt::region)
  • Adjust link.x to allow for adjustable alignment of regions
  • Adjust link.x to allow for adjustable padding between stacks
  • Add an example that programs the MPU

The MPS3-AN536 padding is set at 64K, so that the normal build and the +d32 build end up with the same memory map (otherwise their output for the mpu_region example would be different).

* Add an API to get the various linker output sections (aarch32_rt::region)
* Adjust link.x to allow for adjustable alignment of regions
* Adjust link.x to allow for adjustable padding between stacks
* Add an example that programs the MPU
@thejpster thejpster changed the title Support region padding for MPU programming Support region padding for MPU programming (requires #127) Mar 6, 2026
@thejpster thejpster changed the title Support region padding for MPU programming (requires #127) Support region padding for MPU programming Mar 20, 2026
Copy link
Copy Markdown

@wt wt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything I didn't mention looks okay assuming all the magic numbers in the reference files are correct.

Comment on lines +49 to +60
pub fn iter() -> impl Iterator<Item = Region> {
[
Region::VectorTable,
Region::Text,
Region::Rodata,
Region::Bss,
Region::Data,
Region::Uninit,
]
.iter()
.cloned()
}
Copy link
Copy Markdown

@wt wt Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not comfortable that future additions to the Region enum will not get caught if they aren't added to this array. I think that it would be better to have a RegionIter type that implements iterator and makes sure that all the values are in the iterator with an exhaustive match on the current section.

Something like:

struct RegionIter {
    current: Region;
};

impl Iterator for RegionIter {
    type Item = Region;

    fn next(&mut self) -> Option<Self::Item> {
        let next = match self.current {
            Region::VectorTable => Region::Text,
            Region::Text => Region::Rodata,
            // etc...
            Region::Uninit => return None,
        }
        self.current = next
        Some(next)
    }
}

iter() should return this initialized RegionIter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants