diff --git a/hal/mpu/mbed_mpu_v7m.c b/hal/mpu/mbed_mpu_v7m.c index 96592ad625..5778e74739 100644 --- a/hal/mpu/mbed_mpu_v7m.c +++ b/hal/mpu/mbed_mpu_v7m.c @@ -20,7 +20,7 @@ #if ((__ARM_ARCH_7M__ == 1U) || (__ARM_ARCH_7EM__ == 1U) || (__ARM_ARCH_6M__ == 1U)) && \ defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) && \ - !defined(MBED_MPU_CUSTOM) && !MBED_CONF_PLATFORM_DISABLE_MPU + !defined(MBED_MPU_CUSTOM) #if !DEVICE_MPU #error "Device has v7m MPU but it is not enabled. Add 'MPU' to device_has in targets.json" diff --git a/hal/mpu/mbed_mpu_v8m.c b/hal/mpu/mbed_mpu_v8m.c index de0c362ba1..7304c149b9 100644 --- a/hal/mpu/mbed_mpu_v8m.c +++ b/hal/mpu/mbed_mpu_v8m.c @@ -20,7 +20,7 @@ #if ((__ARM_ARCH_8M_BASE__ == 1U) || (__ARM_ARCH_8M_MAIN__ == 1U)) && \ defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) && \ - !defined(MBED_MPU_CUSTOM) && !MBED_CONF_PLATFORM_DISABLE_MPU + !defined(MBED_MPU_CUSTOM) #if !DEVICE_MPU #error "Device has v8m MPU but it is not enabled. Add 'MPU' to device_has in targets.json" diff --git a/hal/mpu_api.h b/hal/mpu_api.h index 1979731b5c..5ce034779e 100644 --- a/hal/mpu_api.h +++ b/hal/mpu_api.h @@ -26,7 +26,7 @@ extern "C" { #endif -#if DEVICE_MPU && !MBED_CONF_PLATFORM_DISABLE_MPU +#if DEVICE_MPU /** * \defgroup hal_mpu MPU hal diff --git a/platform/mbed_lib.json b/platform/mbed_lib.json index 8dd22bddbd..247a41a7ae 100644 --- a/platform/mbed_lib.json +++ b/platform/mbed_lib.json @@ -129,9 +129,9 @@ "help": "Setting this to true enables auto-reboot on a fatal error.", "value": false }, - "disable-mpu": { - "help": "Disable the MPU to save rom.", - "value": false + "use-mpu": { + "help": "Use the MPU if available to fault execution from RAM and writes to ROM. Can be disabled to reduce image size.", + "value": true } }, "target_overrides": { diff --git a/platform/mbed_mpu_mgmt.c b/platform/mbed_mpu_mgmt.c index 2c5423a275..d34eb30aa5 100644 --- a/platform/mbed_mpu_mgmt.c +++ b/platform/mbed_mpu_mgmt.c @@ -16,12 +16,11 @@ #include "platform/mbed_mpu_mgmt.h" #include "platform/mbed_critical.h" -#include "platform/mbed_error.h" #include "platform/mbed_assert.h" #include "hal/mpu_api.h" #include -#if DEVICE_MPU && !MBED_CONF_PLATFORM_DISABLE_MPU +#if DEVICE_MPU && MBED_CONF_PLATFORM_USE_MPU static uint16_t mem_xn_lock; static uint16_t mem_wn_lock; diff --git a/platform/mbed_mpu_mgmt.h b/platform/mbed_mpu_mgmt.h index cc79feee35..6140c3110f 100644 --- a/platform/mbed_mpu_mgmt.h +++ b/platform/mbed_mpu_mgmt.h @@ -23,16 +23,17 @@ #ifndef MBED_MPU_MGMT_H #define MBED_MPU_MGMT_H -#include "hal/sleep_api.h" #include "mbed_toolchain.h" -#include "hal/ticker_api.h" +#include "hal/mpu_api.h" #include #ifdef __cplusplus extern "C" { #endif -#if DEVICE_MPU && !MBED_CONF_PLATFORM_DISABLE_MPU +#if (DEVICE_MPU && MBED_CONF_PLATFORM_USE_MPU) || defined(DOXYGEN_ONLY) + +#define mbed_mpu_manager_init() mbed_mpu_init() /** Lock ram execute never mode off * @@ -84,6 +85,8 @@ void mbed_mpu_manager_unlock_rom_write(void); #else +#define mbed_mpu_manager_init() (void)0 + #define mbed_mpu_manager_lock_ram_execution() (void)0 #define mbed_mpu_manager_unlock_ram_execution() (void)0 diff --git a/rtos/TARGET_CORTEX/mbed_boot.c b/rtos/TARGET_CORTEX/mbed_boot.c index 2e73d92a8e..b652649bc3 100644 --- a/rtos/TARGET_CORTEX/mbed_boot.c +++ b/rtos/TARGET_CORTEX/mbed_boot.c @@ -76,7 +76,7 @@ #include "mbed_toolchain.h" #include "mbed_boot.h" #include "mbed_error.h" -#include "mpu_api.h" +#include "mbed_mpu_mgmt.h" int main(void); static void mbed_cpy_nvic(void); @@ -87,7 +87,7 @@ uint32_t mbed_stack_isr_size = 0; void mbed_init(void) { - mbed_mpu_init(); + mbed_mpu_manager_init(); mbed_cpy_nvic(); mbed_sdk_init(); mbed_rtos_init();