diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index dc49f39135..c9bae5788d 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -209,6 +209,7 @@ config ARCH_CHIP_NRF52 bool "Nordic NRF52" select ARCH_CORTEXM4 select ARCH_HAVE_TICKLESS + select ARMV7M_HAVE_STACKCHECK #select ARCH_HAVE_MPU #select ARM_HAVE_MPU_UNIFIED select ARCH_HAVE_SPI_BITORDER diff --git a/arch/arm/src/nrf52/Make.defs b/arch/arm/src/nrf52/Make.defs index 7cb854384f..9409876370 100644 --- a/arch/arm/src/nrf52/Make.defs +++ b/arch/arm/src/nrf52/Make.defs @@ -80,6 +80,10 @@ ifeq ($(CONFIG_STACK_COLORATION),y) CMN_CSRCS += arm_checkstack.c endif +ifeq ($(CONFIG_ARMV7M_STACKCHECK),y) +CMN_CSRCS += arm_stackcheck.c +endif + ifeq ($(CONFIG_ARCH_FPU),y) CMN_ASRCS += arm_fpu.S CMN_CSRCS += arm_copyarmstate.c diff --git a/arch/arm/src/nrf52/nrf52_start.c b/arch/arm/src/nrf52/nrf52_start.c index 328f308fa0..d52fb97a63 100644 --- a/arch/arm/src/nrf52/nrf52_start.c +++ b/arch/arm/src/nrf52/nrf52_start.c @@ -81,6 +81,12 @@ * Private Functions ****************************************************************************/ +#ifdef CONFIG_ARMV7M_STACKCHECK +/* we need to get r10 set before we can allow instrumentation calls */ + +void __start(void) __attribute__ ((no_instrument_function)); +#endif + #ifdef CONFIG_STACK_COLORATION static void go_nx_start(void *pv, unsigned int nbytes) __attribute__ ((naked, no_instrument_function, noreturn)); @@ -231,6 +237,13 @@ void __start(void) const uint32_t *src; uint32_t *dest; +#ifdef CONFIG_ARMV7M_STACKCHECK + /* Set the stack limit before we attempt to call any functions */ + + __asm__ volatile("sub r10, sp, %0" : : + "r"(CONFIG_IDLETHREAD_STACKSIZE - 64) :); +#endif + /* Make sure that interrupts are disabled */ __asm__ __volatile__ ("\tcpsid i\n");