Fixed dynamic allocation not working

* changed Mbed linker script for ST's
+ added small dynamic allocation test
This commit is contained in:
Steins7 2020-03-16 19:50:21 -04:00
parent c7ad1d1add
commit 904f92b6f7
3 changed files with 183 additions and 156 deletions

View File

@ -3,7 +3,7 @@
# --- control global project settings # --- control global project settings
# RELEASE=1 -> enable optimisation, then disable debug # RELEASE=1 -> enable optimisation, then disable debug
# RELEASE=0 -> disbale optimisation, then enable debug # RELEASE=0 -> disable optimisation, then enable debug
RELEASE=0 RELEASE=0
# --- project architecture # --- project architecture
@ -104,7 +104,7 @@ ${BIN}/%.elf : ${MAIN_OBJECT_FILES} ${COMMON_OBJECT_FILES}
@echo ${COMMON_OBJECT_FILES} @echo ${COMMON_OBJECT_FILES}
@echo @echo
${DIR_GUARD} ${DIR_GUARD}
${CC} ${CFLAGS} --verbose -o $@ ${filter-out %ld, $^} ${LIBRARIES} ${LDFLAGS} ${CC} ${CFLAGS} -o $@ ${filter-out %ld, $^} ${LIBRARIES} ${LDFLAGS}
${OBJDUMP} -h $@ ${OBJDUMP} -h $@
${SIZE} $@ ${SIZE} $@
@${SKIP_LINE} @${SKIP_LINE}

View File

@ -1,5 +1,6 @@
// standard headers // standard headers
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
// driver includes // driver includes
#include "drivers/rcc.h" #include "drivers/rcc.h"
@ -8,6 +9,8 @@
Clock_t sysclks; Clock_t sysclks;
#include "drivers/timer.h" #include "drivers/timer.h"
extern uint32_t end;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/* static variables */; /* static variables */;
int val = 0; //debug led int val = 0; //debug led
@ -35,6 +38,13 @@ int main(void) {
timer_tick_init(TIM2, 1000, timeout_cb); timer_tick_init(TIM2, 1000, timeout_cb);
timer_start(TIM2); timer_start(TIM2);
uint32_t test = (uint32_t)(&end);
test++;
int* tab = (int*)malloc(10*sizeof(int));
for(int i=0; i<10; ++i) {
tab[i] = i;
}
// main loop // main loop
for(;;); for(;;);

View File

@ -1,160 +1,177 @@
/* Linker script to configure memory regions. */ /**
/* 0xEC reserved for vectors - 8byte aligned = 0xF0 */ ******************************************************************************
* @file LinkerScript.ld
* @author Auto-generated by STM32CubeIDE
STACK_SIZE = 0x400; * @brief Linker script for STM32F103C8Tx Device from STM32F1 series
* 64Kbytes FLASH
MEMORY * 20Kbytes RAM
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
RAM (rwx) : ORIGIN = 0x200000F0, LENGTH = 10K - (0xEC+0x4)
}
/* Linker script to place sections and symbol values. Should be used together
* with other linker script that defines memory regions FLASH and RAM.
* It references following symbols, which must be defined in code:
* Reset_Handler : Entry of reset handler
* *
* It defines following symbols, which code can use without definition: * Set heap size, stack size and stack location according
* __exidx_start * to application requirements.
* __exidx_end *
* __etext * Set memory bank area and size if external memory is used
* __data_start__ ******************************************************************************
* __preinit_array_start * @attention
* __preinit_array_end *
* __init_array_start * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* __init_array_end * All rights reserved.</center></h2>
* __fini_array_start *
* __fini_array_end * This software component is licensed by ST under BSD 3-Clause license,
* __data_end__ * the "License"; You may not use this file except in compliance with the
* __bss_start__ * License. You may obtain a copy of the License at:
* __bss_end__ * opensource.org/licenses/BSD-3-Clause
* __end__ *
* end ******************************************************************************
* __HeapLimit
* __StackLimit
* __StackTop
* __stack
* _estack
*/ */
/* Entry Point */
ENTRY(Reset_Handler) ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 64K
}
/* Sections */
SECTIONS SECTIONS
{ {
/* The startup code into "FLASH" Rom type memory */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data into "FLASH" Rom type memory */
.text : .text :
{ {
KEEP(*(.isr_vector)) . = ALIGN(4);
*(.text*) *(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init)) KEEP (*(.init))
KEEP (*(.fini)) KEEP (*(.fini))
/* .ctors */ . = ALIGN(4);
*crtbegin.o(.ctors) _etext = .; /* define a global symbols at end of code */
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
/* .dtors */
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)
*(.rodata*)
KEEP(*(.eh_frame*))
} >FLASH } >FLASH
.ARM.extab : /* Constant data into "FLASH" Rom type memory */
.rodata :
{ {
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : {
. = ALIGN(4);
*(.ARM.extab* .gnu.linkonce.armextab.*) *(.ARM.extab* .gnu.linkonce.armextab.*)
. = ALIGN(4);
} >FLASH } >FLASH
.ARM : {
. = ALIGN(4);
__exidx_start = .; __exidx_start = .;
.ARM.exidx : *(.ARM.exidx*)
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .; __exidx_end = .;
. = ALIGN(4);
} >FLASH
__etext = .; .preinit_array :
_sidata = .;
.data : AT (__etext)
{ {
__data_start__ = .; . = ALIGN(4);
_sdata = .;
*(vtable)
*(.data*)
. = ALIGN(8);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .); PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array)) KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .); PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
} >FLASH
. = ALIGN(8); .init_array :
/* init data */ {
. = ALIGN(4);
PROVIDE_HIDDEN (__init_array_start = .); PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*))) KEEP (*(SORT(.init_array.*)))
KEEP(*(.init_array)) KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .); PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
} >FLASH
.fini_array :
. = ALIGN(8); {
/* finit data */ . = ALIGN(4);
PROVIDE_HIDDEN (__fini_array_start = .); PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*))) KEEP (*(SORT(.fini_array.*)))
KEEP(*(.fini_array)) KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .); PROVIDE_HIDDEN (__fini_array_end = .);
. = ALIGN(4);
} >FLASH
KEEP(*(.jcr*)) /* Used by the startup to initialize data */
. = ALIGN(8); _sidata = LOADADDR(.data);
/* All data end */
__data_end__ = .;
_edata = .;
} > RAM /* Initialized data sections into "RAM" Ram type memory */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
/* Uninitialized data section into "RAM" Ram type memory */
. = ALIGN(4);
.bss : .bss :
{ {
. = ALIGN(8); /* This is used by the startup in order to initialize the .bss section */
__bss_start__ = .; _sbss = .; /* define a global symbol at bss start */
_sbss = .; __bss_start__ = _sbss;
*(.bss)
*(.bss*) *(.bss*)
*(COMMON) *(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
/* User_heap_stack section, used to check that there is enough "RAM" Ram type
* memory left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8); . = ALIGN(8);
__bss_end__ = .;
_ebss = .;
} >RAM } >RAM
.heap (COPY): /* Remove information from the compiler libraries */
/DISCARD/ :
{ {
__end__ = .; libc.a ( * )
end = __end__; libm.a ( * )
*(.heap*) libgcc.a ( * )
. = ORIGIN(RAM) + LENGTH(RAM) - STACK_SIZE; }
__HeapLimit = .;
} > RAM .ARM.attributes 0 : { *(.ARM.attributes) }
/* .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);
_estack = __StackTop;
__StackLimit = __StackTop - STACK_SIZE;
PROVIDE(__stack = __StackTop);
/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
} }