From 2af6642f683206c3a94cc0e38eff3403cebd67f3 Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Mon, 10 Dec 2018 14:26:13 -0600 Subject: [PATCH] Add a platform config to disable the MPU Add the platform config DISABLE_MPU to allow the MPU to be disabled from an application. --- hal/mpu/mbed_mpu_v7m.c | 2 +- hal/mpu/mbed_mpu_v8m.c | 2 +- hal/mpu_api.h | 2 +- platform/mbed_lib.json | 4 ++++ platform/mbed_mpu_mgmt.c | 2 +- platform/mbed_mpu_mgmt.h | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/hal/mpu/mbed_mpu_v7m.c b/hal/mpu/mbed_mpu_v7m.c index 5778e74739..96592ad625 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) + !defined(MBED_MPU_CUSTOM) && !MBED_CONF_PLATFORM_DISABLE_MPU #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 7304c149b9..de0c362ba1 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) + !defined(MBED_MPU_CUSTOM) && !MBED_CONF_PLATFORM_DISABLE_MPU #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 5ce034779e..1979731b5c 100644 --- a/hal/mpu_api.h +++ b/hal/mpu_api.h @@ -26,7 +26,7 @@ extern "C" { #endif -#if DEVICE_MPU +#if DEVICE_MPU && !MBED_CONF_PLATFORM_DISABLE_MPU /** * \defgroup hal_mpu MPU hal diff --git a/platform/mbed_lib.json b/platform/mbed_lib.json index 821df0b672..8dd22bddbd 100644 --- a/platform/mbed_lib.json +++ b/platform/mbed_lib.json @@ -128,6 +128,10 @@ "fatal-error-auto-reboot-enabled": { "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 } }, "target_overrides": { diff --git a/platform/mbed_mpu_mgmt.c b/platform/mbed_mpu_mgmt.c index 7a067a4281..2c5423a275 100644 --- a/platform/mbed_mpu_mgmt.c +++ b/platform/mbed_mpu_mgmt.c @@ -21,7 +21,7 @@ #include "hal/mpu_api.h" #include -#if DEVICE_MPU +#if DEVICE_MPU && !MBED_CONF_PLATFORM_DISABLE_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 8b1e422f58..cc79feee35 100644 --- a/platform/mbed_mpu_mgmt.h +++ b/platform/mbed_mpu_mgmt.h @@ -32,7 +32,7 @@ extern "C" { #endif -#if DEVICE_MPU +#if DEVICE_MPU && !MBED_CONF_PLATFORM_DISABLE_MPU /** Lock ram execute never mode off *