This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 86635d82d6c45243760e225c9fe03541d4c34663 Author: Darryl Ring <[email protected]> AuthorDate: Fri Sep 11 11:57:34 2026 -0700 arch/arm/stm32h5: Enable MPU support This adds MPU initialization code based on the STM32U5. Unlike the STM32U5 code, though, this allows the MPU to be used outside of PROTECTED build mode. PROTECTED build mode is still not yet supported. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Darryl Ring <[email protected]> --- arch/arm/src/stm32h5/CMakeLists.txt | 4 +++ arch/arm/src/stm32h5/Make.defs | 4 +++ arch/arm/src/stm32h5/stm32_mpuinit.c | 67 ++++++++++++++++++++++++++++++++++++ arch/arm/src/stm32h5/stm32_mpuinit.h | 53 ++++++++++++++++++++++++++++ arch/arm/src/stm32h5/stm32_start.c | 13 +++++++ 5 files changed, 141 insertions(+) diff --git a/arch/arm/src/stm32h5/CMakeLists.txt b/arch/arm/src/stm32h5/CMakeLists.txt index 2ab0fa7a017..82956715775 100644 --- a/arch/arm/src/stm32h5/CMakeLists.txt +++ b/arch/arm/src/stm32h5/CMakeLists.txt @@ -128,6 +128,10 @@ if(CONFIG_STM32_IWDG) list(APPEND SRCS stm32_iwdg.c) endif() +if(CONFIG_ARM_MPU) + list(APPEND SRCS stm32_mpuinit.c) +endif() + # Required chip type specific files if(CONFIG_STM32_STM32H5XXXX) diff --git a/arch/arm/src/stm32h5/Make.defs b/arch/arm/src/stm32h5/Make.defs index 3eb4b7134a8..71151d5c466 100644 --- a/arch/arm/src/stm32h5/Make.defs +++ b/arch/arm/src/stm32h5/Make.defs @@ -131,6 +131,10 @@ ifeq ($(CONFIG_STM32_IWDG),y) CHIP_CSRCS += stm32_iwdg.c endif +ifeq ($(CONFIG_ARM_MPU),y) +CHIP_CSRCS += stm32_mpuinit.c +endif + ifeq ($(CONFIG_STM32_WWDG),y) CHIP_CSRCS += stm32_wwdg.c endif diff --git a/arch/arm/src/stm32h5/stm32_mpuinit.c b/arch/arm/src/stm32h5/stm32_mpuinit.c new file mode 100644 index 00000000000..e5d2da92e06 --- /dev/null +++ b/arch/arm/src/stm32h5/stm32_mpuinit.c @@ -0,0 +1,67 @@ +/**************************************************************************** + * arch/arm/src/stm32h5/stm32_mpuinit.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <sys/param.h> + +#include "mpu.h" +#include "stm32_mpuinit.h" + +#ifdef CONFIG_ARM_MPU + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_mpuinitialize + * + * Description: + * Configure the MPU. + * + * For FLAT build: + * - just reset and enable the MPU with the default background region. + * + ****************************************************************************/ + +void stm32_mpuinitialize(void) +{ + /* Show MPU information */ + + mpu_showtype(); + + /* Reset the MPU in case a bootloader left it configured */ + + mpu_reset(); + + /* Then enable the MPU */ + + mpu_control(true, false, true); +} + +#endif /* CONFIG_ARM_MPU */ diff --git a/arch/arm/src/stm32h5/stm32_mpuinit.h b/arch/arm/src/stm32h5/stm32_mpuinit.h new file mode 100644 index 00000000000..fc1cba96cdc --- /dev/null +++ b/arch/arm/src/stm32h5/stm32_mpuinit.h @@ -0,0 +1,53 @@ +/**************************************************************************** + * arch/arm/src/stm32h5/stm32_mpuinit.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 __ARCH_ARM_SRC_STM32H5_STM32_MPUINIT_H +#define __ARCH_ARM_SRC_STM32H5_STM32_MPUINIT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_mpuinitialize + * + * Description: + * Configure the MPU. + * + * For FLAT build: + * - just reset and enable the MPU with the default background region. + * + ****************************************************************************/ + +#ifdef CONFIG_ARM_MPU +void stm32_mpuinitialize(void); +#else +# define stm32_mpuinitialize() +#endif + +#endif /* __ARCH_ARM_SRC_STM32H5_STM32_MPUINIT_H */ diff --git a/arch/arm/src/stm32h5/stm32_start.c b/arch/arm/src/stm32h5/stm32_start.c index 62acdd78f69..d5384b05172 100644 --- a/arch/arm/src/stm32h5/stm32_start.c +++ b/arch/arm/src/stm32h5/stm32_start.c @@ -40,6 +40,10 @@ #include "stm32_gpio.h" #include "stm32_start.h" +#ifdef CONFIG_ARM_MPU +# include "stm32_mpuinit.h" +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -220,6 +224,15 @@ void __start(void) #endif showprogress('B'); + /* Configure the MPU to permit user-space access to its FLASH and RAM (for + * CONFIG_BUILD_PROTECTED) or to manage cache properties of external + * memory regions (in a flat build). + */ + +#ifdef CONFIG_ARM_MPU + stm32_mpuinitialize(); +#endif + /* Initialize onboard resources */ stm32_board_initialize();
