You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@mynewt.apache.org by "sjanc (via GitHub)" <gi...@apache.org> on 2026/07/06 11:39:53 UTC
Re: [PR] hw/mpu: Add link table configuration of MPU [mynewt-core]
sjanc commented on code in PR #3690:
URL: https://github.com/apache/mynewt-core/pull/3690#discussion_r3528529217
##########
hw/cmsis-core/include/arm_mpu.h:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef ARM_MPU_H
+#define ARM_MPU_H
+
+#include <os/mynewt.h>
+#include <os/link_tables.h>
+
+#if __MPU_PRESENT
+#if (__CORTEX_M == 0) || (__CORTEX_M == 3) || (__CORTEX_M == 4) || (__CORTEX_M == 7)
+
+LINK_TABLE(ARM_MPU_Region_t, mpu_regions);
+
+#define MPU_ARM_V7_REGION(name, address, rasr) \
+ LINK_TABLE_ELEMENT(mpu_regions, name) = { \
+ .RBAR = address | MPU_RBAR_VALID_Msk, \
+ .RASR = rasr, \
+ };
+
+#elif (__CORTEX_M == 23) || (__CORTEX_M == 33) || (__CORTEX_M == 34) || \
Review Comment:
if this is nop for those CPUs I'd just remove this rather than having empty elif
##########
hw/cmsis-core/src/arm_mpu.c:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <os/os.h>
+#include <os/link_tables.h>
+#include <arm_mpu.h>
+
+#ifndef __CORTEX_M
+#error "Macro __CORTEX_M not defined; must define cortex-m type!"
+#endif
+
+#if __MPU_PRESENT
+#if (__CORTEX_M == 0) || (__CORTEX_M == 3) || (__CORTEX_M == 4) || (__CORTEX_M == 7)
+
+void
+arm_mpu_init(void)
+{
+ ARM_MPU_Region_t regions[8] = { 0 };
+ size_t size = min(ARRAY_SIZE(regions), mpu_regions_size());
+
+ ARM_MPU_Disable();
+
+ for (size_t i = 0; i < size; ++i) {
+ regions[i].RBAR = (mpu_regions[i].RBAR & ~MPU_RBAR_REGION_Msk) | i;
+ regions[i].RASR = mpu_regions[i].RASR;
+ }
+
+ ARM_MPU_Load(regions, size);
+
+ ARM_MPU_Enable(MPU_CTRL_PRIVDEFENA_Msk);
+}
+#elif (__CORTEX_M == 23) || (__CORTEX_M == 33) || (__CORTEX_M == 34) || \
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org