From c0a6c7c6d4ac25c1e3a73002a678f3493fa43e71 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Sun, 5 Jun 2016 17:56:01 +0100 Subject: [PATCH] Better generation of heap section. With this change, the heap section occupy the whole space from the end of the bss section to the start of the stack section instead of taking a fixed size in RAM. This change allows applications to make a more efficient use of the RAM available and allows application to be compiled if the space between end of bss and start of stack is less than 2048 bytes. --- .../TARGET_MCU_NORDIC_32K/NRF51822.ld | 6 ++-- .../TARGET_MCU_NRF51_16K_S110/NRF51822.ld | 6 ++-- .../TARGET_MCU_NRF51_16K_S130/NRF51822.ld | 6 ++-- .../TOOLCHAIN_GCC_ARM/startup_NRF51822.S | 28 ++++++------------- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NORDIC_32K/NRF51822.ld b/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NORDIC_32K/NRF51822.ld index 0b9c664fc4..913b210847 100644 --- a/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NORDIC_32K/NRF51822.ld +++ b/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NORDIC_32K/NRF51822.ld @@ -124,18 +124,20 @@ SECTIONS __bss_end__ = .; } > RAM - .heap (COPY): + .heap (NOLOAD): { __end__ = .; end = __end__; + __HeapBase = .; *(.heap*) + . = ORIGIN(RAM) + LENGTH(RAM) - Stack_Size; __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_dummy (NOLOAD): { *(.stack*) } > RAM diff --git a/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S110/NRF51822.ld b/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S110/NRF51822.ld index cb472e5640..d0ed81d84e 100644 --- a/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S110/NRF51822.ld +++ b/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S110/NRF51822.ld @@ -124,18 +124,20 @@ SECTIONS __bss_end__ = .; } > RAM - .heap (COPY): + .heap (NOLOAD): { __end__ = .; end = __end__; + __HeapBase = .; *(.heap*) + . = ORIGIN(RAM) + LENGTH(RAM) - Stack_Size; __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_dummy (NOLOAD): { *(.stack*) } > RAM diff --git a/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S130/NRF51822.ld b/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S130/NRF51822.ld index c334dbb3cd..237ab15985 100644 --- a/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S130/NRF51822.ld +++ b/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S130/NRF51822.ld @@ -124,18 +124,20 @@ SECTIONS __bss_end__ = .; } > RAM - .heap (COPY): + .heap (NOLOAD): { __end__ = .; end = __end__; + __HeapBase = .; *(.heap*) + . = ORIGIN(RAM) + LENGTH(RAM) - Stack_Size; __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_dummy (NOLOAD): { *(.stack*) } > RAM diff --git a/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/startup_NRF51822.S b/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/startup_NRF51822.S index e5de3f95fb..7fb929dd26 100644 --- a/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/startup_NRF51822.S +++ b/hal/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/startup_NRF51822.S @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 2013, Nordic Semiconductor ASA All rights reserved. @@ -28,8 +28,8 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* -NOTE: Template files (including this one) are application specific and therefore +/* +NOTE: Template files (including this one) are application specific and therefore expected to be copied into the application project folder prior to its use! */ @@ -43,6 +43,7 @@ expected to be copied into the application project folder prior to its use! #else .equ Stack_Size, 2048 #endif + .globl Stack_Size .globl __StackTop .globl __StackLimit __StackLimit: @@ -53,21 +54,9 @@ __StackTop: .section .heap .align 3 -#ifdef __HEAP_SIZE - .equ Heap_Size, __HEAP_SIZE -#else - .equ Heap_Size, 2048 -#endif .globl __HeapBase .globl __HeapLimit -__HeapBase: - .if Heap_Size - .space Heap_Size - .endif - .size __HeapBase, . - __HeapBase -__HeapLimit: - .size __HeapLimit, . - __HeapLimit - + .section .Vectors .align 2 .globl __Vectors @@ -129,7 +118,7 @@ __Vectors: /* Reset Handler */ .equ NRF_POWER_RAMON_ADDRESS, 0x40000524 - .equ NRF_POWER_RAMON_RAMxON_ONMODE_Msk, 0x3 + .equ NRF_POWER_RAMON_RAMxON_ONMODE_Msk, 0x3 .text .thumb @@ -148,7 +137,7 @@ Reset_Handler: STR R2, [R0] /* Loop to copy data from read only memory to RAM. The ranges - * of copy from/to are specified by following symbols evaluated in + * of copy from/to are specified by following symbols evaluated in * linker script. * __etext: End of code section, i.e., begin of data sections to copy from. * __data_start__/__data_end__: RAM address range that data should be @@ -167,7 +156,7 @@ Reset_Handler: str r0, [r2,r3] bgt .LC1 .LC0: - + LDR R0, =SystemInit BLX R0 LDR R0, =_start @@ -259,4 +248,3 @@ Default_Handler: .end -