Skip to content

Commit 770baa2

Browse files
committed
Rework MPU use option
Make the option positively named, and as it is a platform config option make sure it only affects platform code. HAL functions still remain available even if platform is told not to use them.
1 parent 2af6642 commit 770baa2

File tree

7 files changed

+15
-13
lines changed

7 files changed

+15
-13
lines changed

hal/mpu/mbed_mpu_v7m.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#if ((__ARM_ARCH_7M__ == 1U) || (__ARM_ARCH_7EM__ == 1U) || (__ARM_ARCH_6M__ == 1U)) && \
2222
defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) && \
23-
!defined(MBED_MPU_CUSTOM) && !MBED_CONF_PLATFORM_DISABLE_MPU
23+
!defined(MBED_MPU_CUSTOM)
2424

2525
#if !DEVICE_MPU
2626
#error "Device has v7m MPU but it is not enabled. Add 'MPU' to device_has in targets.json"

hal/mpu/mbed_mpu_v8m.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#if ((__ARM_ARCH_8M_BASE__ == 1U) || (__ARM_ARCH_8M_MAIN__ == 1U)) && \
2222
defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) && \
23-
!defined(MBED_MPU_CUSTOM) && !MBED_CONF_PLATFORM_DISABLE_MPU
23+
!defined(MBED_MPU_CUSTOM)
2424

2525
#if !DEVICE_MPU
2626
#error "Device has v8m MPU but it is not enabled. Add 'MPU' to device_has in targets.json"

hal/mpu_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
extern "C" {
2727
#endif
2828

29-
#if DEVICE_MPU && !MBED_CONF_PLATFORM_DISABLE_MPU
29+
#if DEVICE_MPU
3030

3131
/**
3232
* \defgroup hal_mpu MPU hal

platform/mbed_lib.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@
129129
"help": "Setting this to true enables auto-reboot on a fatal error.",
130130
"value": false
131131
},
132-
"disable-mpu": {
133-
"help": "Disable the MPU to save rom.",
134-
"value": false
132+
"use-mpu": {
133+
"help": "Use the MPU if available to fault execution from RAM and writes to ROM. Can be disabled to reduce image size.",
134+
"value": true
135135
}
136136
},
137137
"target_overrides": {

platform/mbed_mpu_mgmt.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
#include "platform/mbed_mpu_mgmt.h"
1818
#include "platform/mbed_critical.h"
19-
#include "platform/mbed_error.h"
2019
#include "platform/mbed_assert.h"
2120
#include "hal/mpu_api.h"
2221
#include <limits.h>
2322

24-
#if DEVICE_MPU && !MBED_CONF_PLATFORM_DISABLE_MPU
23+
#if DEVICE_MPU && MBED_CONF_PLATFORM_USE_MPU
2524

2625
static uint16_t mem_xn_lock;
2726
static uint16_t mem_wn_lock;

platform/mbed_mpu_mgmt.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323
#ifndef MBED_MPU_MGMT_H
2424
#define MBED_MPU_MGMT_H
2525

26-
#include "hal/sleep_api.h"
2726
#include "mbed_toolchain.h"
28-
#include "hal/ticker_api.h"
27+
#include "hal/mpu_api.h"
2928
#include <stdbool.h>
3029

3130
#ifdef __cplusplus
3231
extern "C" {
3332
#endif
3433

35-
#if DEVICE_MPU && !MBED_CONF_PLATFORM_DISABLE_MPU
34+
#if (DEVICE_MPU && MBED_CONF_PLATFORM_USE_MPU) || defined(DOXYGEN_ONLY)
35+
36+
#define mbed_mpu_manager_init() mbed_mpu_init()
3637

3738
/** Lock ram execute never mode off
3839
*
@@ -84,6 +85,8 @@ void mbed_mpu_manager_unlock_rom_write(void);
8485

8586
#else
8687

88+
#define mbed_mpu_manager_init() (void)0
89+
8790
#define mbed_mpu_manager_lock_ram_execution() (void)0
8891

8992
#define mbed_mpu_manager_unlock_ram_execution() (void)0

rtos/TARGET_CORTEX/mbed_boot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
#include "mbed_toolchain.h"
7878
#include "mbed_boot.h"
7979
#include "mbed_error.h"
80-
#include "mpu_api.h"
80+
#include "mbed_mpu_mgmt.h"
8181

8282
int main(void);
8383
static void mbed_cpy_nvic(void);
@@ -88,7 +88,7 @@ uint32_t mbed_stack_isr_size = 0;
8888

8989
void mbed_init(void)
9090
{
91-
mbed_mpu_init();
91+
mbed_mpu_manager_init();
9292
mbed_cpy_nvic();
9393
mbed_sdk_init();
9494
mbed_rtos_init();

0 commit comments

Comments
 (0)