From 3e193cca2c2304fc6a3db751ee0ee733eeef4839 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Tue, 29 Jul 2014 18:06:43 -0400 Subject: [PATCH 1/3] aducrf101: Rearrange stack and heap to maximize available stack space Stack now starts at the top of RAM, heap starts after BSS, and they grow towards each other. --- cpu/arm/aducrf101/Common/GCC/ADuCRF101.ld | 7 +++++-- cpu/arm/aducrf101/Common/GCC/crt0.S | 11 ----------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/cpu/arm/aducrf101/Common/GCC/ADuCRF101.ld b/cpu/arm/aducrf101/Common/GCC/ADuCRF101.ld index 8d553a5f7..a6effb701 100644 --- a/cpu/arm/aducrf101/Common/GCC/ADuCRF101.ld +++ b/cpu/arm/aducrf101/Common/GCC/ADuCRF101.ld @@ -91,10 +91,8 @@ SECTIONS } > ram AT > flash .bss : { - /* Stack is in BSS */ . = ALIGN(8); __bss_start = .; - *(.bss.stack) *(.bss) *(.bss.*) *(COMMON) @@ -102,4 +100,9 @@ SECTIONS __bss_end = .; end = .; } > ram + + /* Heap grows up from "end" (after bss), and stack grows down from + the end of RAM. */ + . = ORIGIN(ram) + LENGTH(ram); + stack_end = .; } diff --git a/cpu/arm/aducrf101/Common/GCC/crt0.S b/cpu/arm/aducrf101/Common/GCC/crt0.S index 592f97902..04b868448 100644 --- a/cpu/arm/aducrf101/Common/GCC/crt0.S +++ b/cpu/arm/aducrf101/Common/GCC/crt0.S @@ -32,19 +32,8 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __STACK_SIZE -#define __STACK_SIZE 1024 -#endif - .equ SCB_VTOR, 0xE000ED08 -/* Stack */ - .section .bss.stack -stack_start: - .space __STACK_SIZE, 0 -stack_end: - .global stack_end - /* Vector table */ .macro handler name .long \name\() From 4aa2a8b95cafd064c2e75f5614ab057cc0e3a8e8 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Tue, 29 Jul 2014 18:07:33 -0400 Subject: [PATCH 2/3] 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(); From 9b76c2fb17cdce4af5707b068324dc0779e5b8c9 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Tue, 29 Jul 2014 18:08:49 -0400 Subject: [PATCH 3/3] aducrf101: Adjust default buffer sizes to fit better in available RAM --- platform/ev-aducrf101mkxz/contiki-conf.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/platform/ev-aducrf101mkxz/contiki-conf.h b/platform/ev-aducrf101mkxz/contiki-conf.h index 98cc0084f..7cdc5ea7f 100644 --- a/platform/ev-aducrf101mkxz/contiki-conf.h +++ b/platform/ev-aducrf101mkxz/contiki-conf.h @@ -89,11 +89,11 @@ #define XMAC_CONF_COMPOWER 0 #define CXMAC_CONF_COMPOWER 0 -#define COLLECT_NBR_TABLE_CONF_MAX_NEIGHBORS 32 +#define COLLECT_NBR_TABLE_CONF_MAX_NEIGHBORS 16 #endif /* WITH_UIP6 */ -#define QUEUEBUF_CONF_NUM 16 +#define QUEUEBUF_CONF_NUM 4 #define PACKETBUF_CONF_ATTRS_INLINE 1 @@ -109,7 +109,7 @@ #define ENERGEST_CONF_ON 0 #define AODV_COMPLIANCE -#define AODV_NUM_RT_ENTRIES 32 +#define AODV_NUM_RT_ENTRIES 16 #define WITH_ASCII 1 @@ -131,8 +131,8 @@ #define UIP_CONF_IPV6_RPL 1 #endif -#define NBR_TABLE_CONF_MAX_NEIGHBORS 30 -#define UIP_CONF_MAX_ROUTES 30 +#define NBR_TABLE_CONF_MAX_NEIGHBORS 16 +#define UIP_CONF_MAX_ROUTES 16 #define UIP_CONF_ND6_SEND_RA 0 #define UIP_CONF_ND6_REACHABLE_TIME 600000 @@ -146,7 +146,7 @@ #define UIP_CONF_ND6_MAX_PREFIXES 3 #define UIP_CONF_ND6_MAX_DEFROUTERS 2 #define UIP_CONF_IP_FORWARD 0 -#define UIP_CONF_BUFFER_SIZE 140 +#define UIP_CONF_BUFFER_SIZE 240 #define SICSLOWPAN_CONF_FRAG 1 #define SICSLOWPAN_CONF_MAXAGE 8