refactor linker & startup for dynamic checking stack & heap usage.
- add syscall __sbrk() for malloc function - add dbgMemInfo() is visual format - FreeRTOS enable : configCHECK_FOR_STACK_OVERFLOW, configUSE_MALLOC_FAILED_HOOK, configUSE_TRACE_FACILITY, configUSE_STATS_FORMATTING_FUNCTIONS
This commit is contained in:
1 parent
f0c0cec1c2
commit
ecedd3d0e2
10 files changed
+141
-62
No files matched your search
+1
-1
@@ -47,7 +47,7 @@ feather52.build.variant=feather52
|
||||
feather52.build.variant_system_lib=
|
||||
feather52.build.extra_flags=-DNRF52 -DS132 -DNRF51_S132
|
||||
feather52.build.float_flags=-mfloat-abi=hard -mfpu=fpv4-sp-d16
|
||||
feather52.build.ldscript=armgcc_s132_nrf52832_xxaa.ld
|
||||
feather52.build.ldscript=feather52_s132.ld
|
||||
|
||||
feather52.build.nrfutil=nrfutil
|
||||
feather52.build.nrfutil.windows={runtime.platform.path}/tools/nrfutil-0.5.2/binaries/win32/nrfutil.exe
|
||||
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
/* Linker script to configure memory regions. */
|
||||
|
||||
SEARCH_DIR(.)
|
||||
GROUP(-lgcc -lc -lnosys)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x1c000, LENGTH = 0x64000
|
||||
|
||||
/* RAM (rwx) : ORIGIN = 0x20002080, LENGTH = 0xdf80 default ATTR SIZE of 0x580 */
|
||||
/* Increase Attr Table Size to 0x1000 */
|
||||
RAM (rwx) : ORIGIN = 0x20002B00, LENGTH = 0xD500
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.fs_data :
|
||||
{
|
||||
PROVIDE(__start_fs_data = .);
|
||||
KEEP(*(.fs_data))
|
||||
PROVIDE(__stop_fs_data = .);
|
||||
} > RAM
|
||||
} INSERT AFTER .data;
|
||||
|
||||
INCLUDE "nrf5x_common.ld"
|
||||
+82
-10
@@ -40,18 +40,17 @@
|
||||
#include "debug.h"
|
||||
|
||||
// defined in linker script
|
||||
extern unsigned char __end__[];
|
||||
extern uint32_t __data_start__[];
|
||||
extern uint32_t __data_end__[];
|
||||
|
||||
extern uint32_t __bss_start__[];
|
||||
extern uint32_t __bss_end__[];
|
||||
|
||||
extern unsigned char __HeapBase[];
|
||||
extern unsigned char __HeapLimit[];
|
||||
|
||||
int dbgHeapTotal(void)
|
||||
{
|
||||
return ((uint32_t) __HeapLimit) - ((uint32_t) __end__);
|
||||
}
|
||||
|
||||
int dbgHeapUsed(void)
|
||||
{
|
||||
return (mallinfo()).uordblks;
|
||||
}
|
||||
extern uint32_t __StackTop[];
|
||||
extern uint32_t __StackLimit[];
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -69,4 +68,77 @@ extern "C"
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
void vApplicationMallocFailedHook(void)
|
||||
{
|
||||
Serial.println("Failed to Malloc");
|
||||
}
|
||||
|
||||
void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
|
||||
{
|
||||
Serial.printf("%s Stack Overflow !!!", pcTaskName);
|
||||
}
|
||||
}
|
||||
|
||||
int dbgHeapTotal(void)
|
||||
{
|
||||
return ((uint32_t) __HeapLimit) - ((uint32_t) __HeapBase);
|
||||
}
|
||||
|
||||
int dbgHeapUsed(void)
|
||||
{
|
||||
return (mallinfo()).uordblks;
|
||||
}
|
||||
|
||||
static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint32_t used)
|
||||
{
|
||||
const int width = 21;
|
||||
|
||||
Serial.printf(" _____________________ 0x%08lX\n", top);
|
||||
Serial.printf("| |\n");
|
||||
|
||||
int lpad = (width-strlen(name))/2;
|
||||
int rpad = width - strlen(name) - lpad;
|
||||
Serial.printf("|%*c%s%*c|\n", lpad, ' ', name, rpad, ' ');
|
||||
|
||||
if ( used )
|
||||
{
|
||||
Serial.printf("| %d / %d (%02lu%%) |\n", used, top-bottom, (used*100)/ (top-bottom));
|
||||
}else
|
||||
{
|
||||
Serial.printf("| %d |\n",top-bottom);
|
||||
}
|
||||
|
||||
Serial.printf("|_____________________| 0x%08lX\n", bottom);
|
||||
}
|
||||
|
||||
void dbgMemInfo(void)
|
||||
{
|
||||
Serial.println(" Memory Map");
|
||||
|
||||
// Pritn SRAM used for Stack executed by S132 and ISR
|
||||
uint32_t stack_used = ((uint32_t) __StackTop) -((uint32_t) __StackLimit);
|
||||
printMemRegion("Stack", ((uint32_t) __StackTop), ((uint32_t) __StackLimit), 0);
|
||||
|
||||
// Print Heap usage overall (including memory malloced to tasks)
|
||||
printMemRegion("Heap", ((uint32_t) __HeapLimit), ((uint32_t) __HeapBase), dbgHeapUsed());
|
||||
|
||||
// DATA + BSS
|
||||
printMemRegion("Data & Bss", ((uint32_t) __bss_end__), ((uint32_t) __data_start__), 0);
|
||||
|
||||
// Print SRAM Used by SoftDevice
|
||||
printMemRegion("S132", (uint32_t) __data_start__, 0x20000000, 0);
|
||||
|
||||
Serial.println();
|
||||
|
||||
// Print Task list
|
||||
uint32_t tasknum = uxTaskGetNumberOfTasks();
|
||||
char* buf = (char*) rtos_malloc(tasknum*40); // 40 bytes per task
|
||||
|
||||
vTaskList(buf);
|
||||
|
||||
Serial.println("Task State Prio Stack Num");
|
||||
Serial.println("-----------------------------------");
|
||||
Serial.println(buf);
|
||||
rtos_free(buf);
|
||||
}
|
||||
@@ -47,4 +47,6 @@ static inline int dbgHeapFree(void)
|
||||
return dbgHeapTotal() - dbgHeapUsed();
|
||||
}
|
||||
|
||||
void dbgMemInfo(void);
|
||||
|
||||
#endif
|
||||
@@ -115,13 +115,13 @@
|
||||
/* Hook function related definitions. */
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 0
|
||||
#define configUSE_MALLOC_FAILED_HOOK 0
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 1
|
||||
#define configUSE_MALLOC_FAILED_HOOK 1
|
||||
|
||||
/* Run time and task stats gathering related definitions. */
|
||||
#define configGENERATE_RUN_TIME_STATS 0
|
||||
#define configUSE_TRACE_FACILITY 0
|
||||
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
|
||||
|
||||
/* Co-routine definitions. */
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
|
||||
+4
-4
@@ -29,12 +29,12 @@
|
||||
.syntax unified
|
||||
.arch armv7e-m
|
||||
|
||||
.section .stack
|
||||
/* .section .stack
|
||||
.align 3
|
||||
#ifdef __STACK_SIZE
|
||||
.equ Stack_Size, __STACK_SIZE
|
||||
#else
|
||||
.equ Stack_Size, 8192 /* Reduce could affect SD function */
|
||||
.equ Stack_Size, 8192
|
||||
#endif
|
||||
.globl __StackTop
|
||||
.globl __StackLimit
|
||||
@@ -49,7 +49,7 @@ __StackTop:
|
||||
#ifdef __HEAP_SIZE
|
||||
.equ Heap_Size, __HEAP_SIZE
|
||||
#else
|
||||
.equ Heap_Size, 25600 /* TODO Should be all space left */
|
||||
.equ Heap_Size, 25600
|
||||
#endif
|
||||
.globl __HeapBase
|
||||
.globl __HeapLimit
|
||||
@@ -60,7 +60,7 @@ __HeapBase:
|
||||
.size __HeapBase, . - __HeapBase
|
||||
__HeapLimit:
|
||||
.size __HeapLimit, . - __HeapLimit
|
||||
|
||||
*/
|
||||
.section .isr_vector
|
||||
.align 2
|
||||
.globl __isr_vector
|
||||
+12
-15
@@ -45,6 +45,14 @@ OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||
*/
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
__StackSize = 1024*3;
|
||||
|
||||
/* Set stack top to end of RAM, and stack limit move down by
|
||||
* size of stack_dummy section */
|
||||
PROVIDE(__StackTop = ORIGIN(RAM) + LENGTH(RAM));
|
||||
PROVIDE(__StackLimit = __StackTop - __StackSize);
|
||||
PROVIDE(__stack = __StackTop);
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
@@ -132,27 +140,16 @@ SECTIONS
|
||||
__bss_end__ = .;
|
||||
} > RAM
|
||||
|
||||
.heap (COPY):
|
||||
/*.heap (COPY):*/
|
||||
.heap :
|
||||
{
|
||||
__end__ = .;
|
||||
PROVIDE(end = .);
|
||||
__HeapBase = .;
|
||||
*(.heap*)
|
||||
. = ALIGN(__StackLimit);
|
||||
__HeapLimit = .;
|
||||
} > RAM
|
||||
|
||||
/* .stack_dummy section doesn't contains any symbols. It is only
|
||||
* used for linker to calculate size of stack sections, and assign
|
||||
* values to stack symbols later */
|
||||
.stack_dummy (COPY):
|
||||
{
|
||||
*(.stack*)
|
||||
} > RAM
|
||||
|
||||
/* Set stack top to end of RAM, and stack limit move down by
|
||||
* size of stack_dummy section */
|
||||
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
|
||||
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
|
||||
PROVIDE(__stack = __StackTop);
|
||||
|
||||
/* Check if data + heap + stack exceeds RAM limit */
|
||||
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
|
||||
@@ -2,8 +2,8 @@ name=Adafruit Feather52 Examples
|
||||
version=0.1.0
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Adafruit Bluefruit Feather52 Examples
|
||||
paragraph=Collection of examples for Bluefruit Feather52 Board
|
||||
sentence=Adafruit Bluefruit52 HW Examples
|
||||
paragraph=Collection of hardware examples for Bluefruit Feather52 Board
|
||||
category=Communication
|
||||
url=http://www.adafruit.com/
|
||||
architectures=nRF52
|
||||
+1
-1
@@ -82,7 +82,7 @@ recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU=
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-L{nrf.sdk.path}/components/toolchain/gcc/" "-L{nrf.sdk.path}/components/softdevice/s132/toolchain/armgcc/" "-T{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nano.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} -Wl,--start-group -lm "{build.path}/{archive_file}" -Wl,--end-group
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-L{build.variant.path}" "-L{build.core.path}" "-T{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nano.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} -Wl,--start-group -lm "{build.path}/{archive_file}" -Wl,--end-group
|
||||
|
||||
## Create output (bin file)
|
||||
#recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2bin.cmd}" {compiler.elf2bin.flags} {compiler.elf2bin.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
|
||||
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
/* Linker script to configure memory regions. */
|
||||
|
||||
SEARCH_DIR(.)
|
||||
GROUP(-lgcc -lc -lnosys)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x1c000, LENGTH = 0x64000
|
||||
|
||||
/* ATTR SIZE = 0x0580, mid bandwidth (central, prph, sec) = (0, 1, 0) */
|
||||
/* RAM (rwx) : ORIGIN = 0x20002080, LENGTH = 0xdf80 */
|
||||
|
||||
/* ATTR SIZE = 0x1000, mid bandwidth (central, prph, sec) = (0, 1, 0) */
|
||||
/* RAM (rwx) : ORIGIN = 0x20002B00, LENGTH = 0xD500 */
|
||||
|
||||
/* ATTR SIZE = 0x0B00, mid bandwidth (central, prph, sec) = (0, 1, 0) */
|
||||
RAM (rwx) : ORIGIN = 0x20002600, LENGTH = 0xDA00
|
||||
|
||||
/* ATTR SIZE = 0x0B00, mid bandwidth (central, prph, sec) = (4, 1, 4) */
|
||||
/*RAM (rwx) : ORIGIN = 0x20002600, LENGTH = 0xDA00*/
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.fs_data :
|
||||
{
|
||||
PROVIDE(__start_fs_data = .);
|
||||
KEEP(*(.fs_data))
|
||||
PROVIDE(__stop_fs_data = .);
|
||||
} > RAM
|
||||
} INSERT AFTER .data;
|
||||
|
||||
INCLUDE "nrf5x_common.ld"
|
||||
Reference in new issue
Block a user