Skip to content

Commit 171e575

Browse files
committed
Assert MPU regions, rather than error
As we build for a specific CPU, a runtime check for number of MPU regions in release builds is not worthwhile. Make it an assert only. Saves a little space in develop images, a lot in release.
1 parent 9e30001 commit 171e575

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

hal/mpu/mbed_mpu_v7m.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
#include "hal/mpu_api.h"
1717
#include "platform/mbed_assert.h"
18-
#include "platform/mbed_error.h"
1918
#include "cmsis.h"
2019

2120
#if ((__ARM_ARCH_7M__ == 1U) || (__ARM_ARCH_7EM__ == 1U) || (__ARM_ARCH_6M__ == 1U)) && \
@@ -48,9 +47,10 @@ void mbed_mpu_init()
4847
__DMB();
4948

5049
const uint32_t regions = (MPU->TYPE & MPU_TYPE_DREGION_Msk) >> MPU_TYPE_DREGION_Pos;
51-
if (regions < 4) {
52-
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_HAL, MBED_ERROR_CODE_EINVAL), "Device is not capable of supporting an MPU - remove DEVICE_MPU for device_has.");
53-
}
50+
51+
// Our MPU setup requires 4 regions - if this assert is hit, remove
52+
// DEVICE_MPU from device_has
53+
MBED_ASSERT(regions >= 4);
5454

5555
// Disable the MCU
5656
MPU->CTRL = 0;

hal/mpu/mbed_mpu_v8m.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
#include "hal/mpu_api.h"
1717
#include "platform/mbed_assert.h"
18-
#include "platform/mbed_error.h"
1918
#include "cmsis.h"
2019

2120
#if ((__ARM_ARCH_8M_BASE__ == 1U) || (__ARM_ARCH_8M_MAIN__ == 1U)) && \
@@ -38,9 +37,10 @@ void mbed_mpu_init()
3837
__DMB();
3938

4039
const uint32_t regions = (MPU->TYPE & MPU_TYPE_DREGION_Msk) >> MPU_TYPE_DREGION_Pos;
41-
if (regions < 4) {
42-
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_HAL, MBED_ERROR_CODE_EINVAL), "Device is not capable of supporting an MPU - remove DEVICE_MPU for device_has.");
43-
}
40+
41+
// Our MPU setup requires 4 regions - if this assert is hit, remove
42+
// DEVICE_MPU from device_has
43+
MBED_ASSERT(regions >= 4);
4444

4545
// Disable the MCU
4646
MPU->CTRL = 0;

0 commit comments

Comments
 (0)