diff --git a/Makefile.pseudomodules b/Makefile.pseudomodules index e90712cf7d74f7bd3f62a7a45a1051d1ada3349d..9e02789345f0f5ba206cdcb6d32c5bfdab52d3ff 100644 --- a/Makefile.pseudomodules +++ b/Makefile.pseudomodules @@ -34,6 +34,7 @@ PSEUDOMODULES += lwip_stats PSEUDOMODULES += lwip_tcp PSEUDOMODULES += lwip_udp PSEUDOMODULES += lwip_udplite +PSEUDOMODULES += mpu_stack_guard PSEUDOMODULES += netdev_default PSEUDOMODULES += netif PSEUDOMODULES += netstats diff --git a/cpu/cortexm_common/vectors_cortexm.c b/cpu/cortexm_common/vectors_cortexm.c index a5b5c38129f84f055a2454a6ed36e483b7921464..74e584cd274a38b736347e36707b03e3db622442 100644 --- a/cpu/cortexm_common/vectors_cortexm.c +++ b/cpu/cortexm_common/vectors_cortexm.c @@ -28,9 +28,14 @@ #include "cpu.h" #include "kernel_init.h" #include "board.h" +#include "mpu.h" #include "panic.h" #include "vectors_cortexm.h" +#ifndef SRAM_BASE +#define SRAM_BASE 0 +#endif + /** * @brief Memory markers, defined in the linker script * @{ @@ -48,6 +53,8 @@ extern uint32_t _sram; extern uint32_t _eram; /** @} */ +static const uintptr_t stack_base = (uintptr_t)&_sstack; + /** * @brief Allocation of the interrupt stack */ @@ -94,6 +101,18 @@ void reset_handler_default(void) *(dst++) = 0; } +#ifdef MODULE_MPU_STACK_GUARD + if (stack_base != SRAM_BASE) { + mpu_configure( + 0, /* MPU region 0 */ + stack_base + 31, /* Base Address (rounded up) */ + MPU_ATTR(1, AP_RO_RO, 0, 1, 0, 1, MPU_SIZE_32B) /* Attributes and Size */ + ); + + mpu_enable(); + } +#endif + post_startup(); /* initialize the board (which also initiates CPU initialization) */