ld: region RAM overflowed with stack

I have a project in which I've started from the proximity app example code and added some UART stuff using app_uart.c. The linker is giving me this error immediately after building app_uart.c:

ld: region RAM overflowed with stack

Can this be true? The RAM is 8kB, right? Attaching linker scripts and a screenshot that shows everything included in the project.


  • Original linker script uploads helpfully denied by server. Renamed.



  • More detail from my map file:

    ... .bss 0x0000000020002e69 0x0 /Users/Eliot/dev/gcc-arm/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv6-m/libc.a(lib_a-strlen.o) .bss 0x0000000020002e69 0x0 /Users/Eliot/dev/gcc-arm/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv6-m/libc.a(lib_a-strncpy.o) .bss 0x0000000020002e69 0x0 /Users/Eliot/dev/gcc-arm/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv6-m/libc.a(lib_a-__call_atexit.o) .bss 0x0000000020002e69 0x0 /Users/Eliot/dev/gcc-arm/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv6-m/libc.a(lib_a-atexit.o) .bss 0x0000000020002e69 0x0 /Users/Eliot/dev/gcc-arm/bin/../lib/gcc/arm-none-eabi/4.7.4/armv6-m/crtend.o .bss 0x0000000020002e69 0x0 /Users/Eliot/dev/gcc-arm/bin/../lib/gcc/arm-none-eabi/4.7.4/armv6-m/crtn.o *(COMMON) 0x0000000020002e6c . = ALIGN (0x4) fill 0x0000000020002e69 0x3 00 0x0000000020002e6c bss_end = .

    .heap 0x0000000020002e70 0x800 0x0000000020002e70 end = . 0x0000000020002e70 end = end (.heap) .heap 0x0000000020002e70 0x800 ./lib/startup_nrf51.o 0x0000000020002e70 __HeapBase 0x0000000020003670 __HeapLimit = .

    .stack_dummy 0x0000000020002e70 0x800 (.stack) .stack 0x0000000020002e70 0x800 ./lib/startup_nrf51.o 0x0000000020004000 __StackTop = (ORIGIN (RAM) + 0x2000) 0x0000000020003800 __StackLimit = (__StackTop - SIZEOF (.stack_dummy)) 0x0000000020004000 PROVIDE (__stack, __StackTop) 0x0000000000000001 ASSERT ((__StackLimit >= __HeapLimit), region RAM overflowed with stack)

  • I had a similar problem.

    One thing I did was to decrease the heap size by changing the default heap size to 512 bytes from 2048 in gcc_startup_nrf51.S (saves 1.5k, I don't use malloc):

    #ifdef __HEAP_SIZE .equ Heap_Size, __HEAP_SIZE #else .equ Heap_Size, 512 // was 2048 #endif

    I also noticed that some C library functions (such as sprintf) pull in C library parts that use significant amounts of RAM.

    You could also try decreasing the stack size in the same file.

    To exactly see what's eating your RAM, you'd have to post your entire map file, or at least everything related to the .bss segment.

    Good luck!


  • Making the heap smaller did the trick. Thanks!

  • You may also have use in taking a look at this question. In particular, you can safely set the heap size to 0 if you don't use malloc and friends in your application; neither the SDK nor the softdevices use it.

    Also, a GCC-specific optimization is to use newlib-nano, by adding --specs=nano.specs to LDFLAGS. This requires GCC 4.7 or later.

    Edit: Add link.