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)
SECTIONS /* 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
{ {
.text : RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
{ FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 64K
KEEP(*(.isr_vector)) }
*(.text*)
KEEP(*(.init)) /* Sections */
KEEP(*(.fini)) SECTIONS
{
/* .ctors */ /* The startup code into "FLASH" Rom type memory */
*crtbegin.o(.ctors) .isr_vector :
*crtbegin?.o(.ctors) {
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) . = ALIGN(4);
*(SORT(.ctors.*)) KEEP(*(.isr_vector)) /* Startup code */
*(.ctors) . = ALIGN(4);
} >FLASH
/* .dtors */
*crtbegin.o(.dtors) /* The program code and other data into "FLASH" Rom type memory */
*crtbegin?.o(.dtors) .text :
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) {
*(SORT(.dtors.*)) . = ALIGN(4);
*(.dtors) *(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata*) *(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
KEEP(*(.eh_frame*)) *(.eh_frame)
} > FLASH
KEEP (*(.init))
.ARM.extab : KEEP (*(.fini))
{
*(.ARM.extab* .gnu.linkonce.armextab.*) . = ALIGN(4);
} > FLASH _etext = .; /* define a global symbols at end of code */
} >FLASH
__exidx_start = .;
.ARM.exidx : /* Constant data into "FLASH" Rom type memory */
{ .rodata :
*(.ARM.exidx* .gnu.linkonce.armexidx.*) {
} > FLASH . = ALIGN(4);
__exidx_end = .; *(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
__etext = .; . = ALIGN(4);
_sidata = .; } >FLASH
.data : AT (__etext) .ARM.extab : {
{ . = ALIGN(4);
__data_start__ = .; *(.ARM.extab* .gnu.linkonce.armextab.*)
_sdata = .; . = ALIGN(4);
*(vtable) } >FLASH
*(.data*)
.ARM : {
. = ALIGN(8); . = ALIGN(4);
/* preinit data */ __exidx_start = .;
PROVIDE_HIDDEN (__preinit_array_start = .); *(.ARM.exidx*)
KEEP(*(.preinit_array)) __exidx_end = .;
PROVIDE_HIDDEN (__preinit_array_end = .); . = ALIGN(4);
} >FLASH
. = ALIGN(8);
/* init data */ .preinit_array :
PROVIDE_HIDDEN (__init_array_start = .); {
KEEP(*(SORT(.init_array.*))) . = ALIGN(4);
KEEP(*(.init_array)) PROVIDE_HIDDEN (__preinit_array_start = .);
PROVIDE_HIDDEN (__init_array_end = .); KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
. = ALIGN(8); } >FLASH
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .); .init_array :
KEEP(*(SORT(.fini_array.*))) {
KEEP(*(.fini_array)) . = ALIGN(4);
PROVIDE_HIDDEN (__fini_array_end = .); PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP(*(.jcr*)) KEEP (*(.init_array*))
. = ALIGN(8); PROVIDE_HIDDEN (__init_array_end = .);
/* All data end */ . = ALIGN(4);
__data_end__ = .; } >FLASH
_edata = .;
.fini_array :
} > RAM {
. = ALIGN(4);
.bss : PROVIDE_HIDDEN (__fini_array_start = .);
{ KEEP (*(SORT(.fini_array.*)))
. = ALIGN(8); KEEP (*(.fini_array*))
__bss_start__ = .; PROVIDE_HIDDEN (__fini_array_end = .);
_sbss = .; . = ALIGN(4);
*(.bss*) } >FLASH
*(COMMON)
. = ALIGN(8); /* Used by the startup to initialize data */
__bss_end__ = .; _sidata = LOADADDR(.data);
_ebss = .;
} > RAM /* Initialized data sections into "RAM" Ram type memory */
.data :
.heap (COPY): {
{ . = ALIGN(4);
__end__ = .; _sdata = .; /* create a global symbol at data start */
end = __end__; *(.data) /* .data sections */
*(.heap*) *(.data*) /* .data* sections */
. = ORIGIN(RAM) + LENGTH(RAM) - STACK_SIZE;
__HeapLimit = .; . = ALIGN(4);
} > RAM _edata = .; /* define a global symbol at data end */
/* .stack_dummy section doesn't contains any symbols. It is only } >RAM AT> FLASH
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later */ /* Uninitialized data section into "RAM" Ram type memory */
.stack_dummy (COPY): . = ALIGN(4);
{ .bss :
*(.stack*) {
} > RAM /* This is used by the startup in order to initialize the .bss section */
_sbss = .; /* define a global symbol at bss start */
/* Set stack top to end of RAM, and stack limit move down by __bss_start__ = _sbss;
* size of stack_dummy section */ *(.bss)
__StackTop = ORIGIN(RAM) + LENGTH(RAM); *(.bss*)
_estack = __StackTop; *(COMMON)
__StackLimit = __StackTop - STACK_SIZE;
PROVIDE(__stack = __StackTop); . = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
/* Check if data + heap + stack exceeds RAM limit */ __bss_end__ = _ebss;
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") } >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);
} >RAM
/* Remove information from the compiler libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
} }