From a2ce5dc436999bebc3172bd9a01914a96006b949 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sun, 2 Nov 2014 15:47:37 +0100 Subject: Force a hardfault on stack overflows to make the fault condition obvious once it occurs --- nuttx/arch/arm/src/armv7-m/up_stackcheck.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/nuttx/arch/arm/src/armv7-m/up_stackcheck.c b/nuttx/arch/arm/src/armv7-m/up_stackcheck.c index e8f02a863..eb4f93830 100644 --- a/nuttx/arch/arm/src/armv7-m/up_stackcheck.c +++ b/nuttx/arch/arm/src/armv7-m/up_stackcheck.c @@ -1,4 +1,9 @@ +#include +#include + +#include "up_arch.h" +#include "nvic.h" void __cyg_profile_func_enter(void *func, void *caller) __attribute__((naked, no_instrument_function)); void __cyg_profile_func_exit(void *func, void *caller) __attribute__((naked, no_instrument_function)); @@ -7,8 +12,21 @@ void __stack_overflow_trap(void) __attribute__((naked, no_instrument_function void __stack_overflow_trap(void) { - /* if we get here, the stack has overflowed */ - asm ( "b ."); + /* if we get here, the stack has overflowed */ + + /* force hard fault */ + uint32_t regval; + + /* Set up for the system reset, retaining the priority group from the + * the AIRCR register. + */ + + regval = getreg32(NVIC_INTCTRL); + regval |= NVIC_INTCTRL_NMIPENDSET; + putreg32(regval, NVIC_INTCTRL); + + /* trap */ + //asm ( "b ."); } void -- cgit v1.2.3