From 4aa2a8b95cafd064c2e75f5614ab057cc0e3a8e8 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Tue, 29 Jul 2014 18:07:33 -0400 Subject: [PATCH] aducrf101: Add stack pointer sampling, to help debug overflows --- cpu/arm/aducrf101/clock.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cpu/arm/aducrf101/clock.c b/cpu/arm/aducrf101/clock.c index 18e6f7dac..e1feab63f 100644 --- a/cpu/arm/aducrf101/clock.c +++ b/cpu/arm/aducrf101/clock.c @@ -43,9 +43,25 @@ static volatile clock_time_t current_clock = 0; static volatile unsigned long current_seconds = 0; static unsigned int second_countdown = CLOCK_SECOND; +#define SAMPLE_STACK_POINTER +#ifdef SAMPLE_STACK_POINTER +volatile uint32_t *__min_sampled_sp = (uint32_t *)0xFFFFFFFF; +#endif + void SysTick_Handler(void) { +#ifdef SAMPLE_STACK_POINTER + /* Take note of the lowest stack pointer we ever saw. + When compiling against newlib, the total free bytes of + RAM not ever used by heap or stack can be found via GDB: + (gdb) p (char *)__min_sampled_sp - (char *)_sbrk(0) + */ + uint32_t *sp = (uint32_t *)&sp; + if (sp < __min_sampled_sp) + __min_sampled_sp = sp; +#endif + current_clock++; if(etimer_pending()) { etimer_request_poll();