-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cpu/cortex-m: turn MPU support into a feature #13391
Conversation
cpu/cortexm_common/Makefile.features
Outdated
ifneq ($(CPU_ARCH),cortex-m0) | ||
FEATURES_PROVIDED += cortexm_mpu | ||
endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Wikipedia, the MPU is always optional. It's up to the chip vendor whether to include it or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmok. Do all our non-cm0 CPUs have an MCU?
I'll add a check to the mpu test application.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a check. Seems like all our non-Cortex-M0 boards have an MPU, or at leastm __MPU_PRESENT
set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either __MPU_PRESENT
is not undefined, or all our Cortex-M boards do have the optional MPU, even the CM0. @aabadie Could you verify the test succeeds e.g., on a stm32f031k6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aabadie could you take a look at this? I don't have a M0 board...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried on nucleo-f072rb, which is an M0, and the tests/mpu_stack_guard
is correctly skipped by the build system.
The problem here is that, according to the __MPU_PRESENT macro in vendor files, stm32f1 and also some stm32f3 (so not all) CPUs doesn't provide an MPU. It's also unclear if stm32l0 provides an MPU or not (I'm wondering if the vendor files were manually altered for this family).
So, as suggested by @benpicco, I think this feature should be provided by default less widely. Maybe just for M4/M7 by default, and enable on a case-by-case basis for other CPU families (M0/M0plus,M3).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked the data sheets, neither samd2x nor saml2x (cm0p) implement an MPU.
a38de2d
to
8b79ccc
Compare
tests/mpu_stack_guard/Makefile.ci
Outdated
@@ -1,3 +1,4 @@ | |||
BOARD_INSUFFICIENT_MEMORY := \ | |||
nucleo-f031k6 \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This board (and stm32f030f4-demo) is already excluded by the FEATURES_REQUIRED += cortexm_mpu
and should already be marked as unsupported by the CI. Why do you add it here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, seems like the feature guard doesn't work:
[kaspar@ng riot.tmp/tests/mpu_stack_guard (mpu_feature)]$ make info-boards-supported | grep -o nucleo-f031k6
nucleo-f031k6
[kaspar@ng riot.tmp/tests/mpu_stack_guard (mpu_feature)]$
[kaspar@ng riot.tmp/tests/mpu_stack_guard (mpu_feature)]$ BOARD=nucleo-f031k6 make info-debug-variable-CPU_ARCH
cortex-m0
[kaspar@ng riot.tmp/tests/mpu_stack_guard (mpu_feature)]$
Seems like CPU_ARCH is not available in Makefile.features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can cut this part out of #13236 if it also helps here.
That would be awesome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it is: #13392 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a bunch.
[kaspar@ng riot.tmp/tests/mpu_stack_guard (mpu_feature)]$ make info-boards-supported | grep -o nucleo-f031k6
[kaspar@ng riot.tmp/tests/mpu_stack_guard (mpu_feature)]$
So this needs a rebase now. |
8b79ccc
to
5a9fff6
Compare
Done. Removed an unrelated ssp change, and renamed the WIP commit. |
5a9fff6
to
d77ea67
Compare
|
Hmm,
|
Agreed, but the way our build configuration is modeled, there's no way to print the tree of dependencies (board -> cpu -> cpu_fam -> cpu_arch), and there are many layers of includes with non-standard names. I can do the manual equivalent of Doing it "the right way" will take maybe a day? We'd have to go through all ~180 board Makefiles, figure out which CPU family they're in, try to find commonalities, build, refine. |
I see no contradiction 😉
I'm not advocating for a complete list, just adding |
Makes sense. Which ones are those? |
stm32f4 (checked the smallest member of the family), stm32l4 (dito), nrf51, nrf52, samd5x, cc26x2_cc13x2, lm4f120, sam3, saml1x, cc2538 |
Done. Removed nrf51, they don't have an MPU. |
The Data Sheet has a chapter about an MPU though. |
Hm, maybe it is non-standard. The CMSIS headers define
Seems like "MPU" is what Nordic calls flash protection:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could FEATURES_PROVIDED += cortexm_mpu
be also added to stm32f1
, stm32f2
and stm32l1
?
(initially iotlab-*, nucleo-l152re and nucleo-207zg were whitelisted in the test).
Added the stm32f2 and l1. The others don't define __MPU_PRESENT. |
Did you forget to push ? |
yup :) |
There are some missing that where whitelisted before and actually work. Will add them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK and go!
Contribution description
This turns the MPU of Cortex-M into a feature.
Testing procedure
Issues/PRs references