Forum: Mikrocontroller und Digitale Elektronik STM32F4 Linker-Fehler region FLASH overflowed?


von Daniel F. (franken_3)


Lesenswert?

Hallo,

ich habe mal wieder ein Problem mit meinem STM32F4 unter Linux und 
Codeblocks.

Ich versuche seit Tagen C++ zum laufen zu bekommen, jetzt habe ich 
verschiedene Linker-Scripte aus dem Internet ausprobiert. Leider bekomme 
ich jetzt beim Linken einen Fehler den ich nicht verstehe

1
/home/sean/.bin/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: bin/Release/iotogglem0 section `.text' will not fit in region `FLASH'
2
/home/sean/.bin/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 214732 bytes

Weis jemand was da los ist? Hab das Linkerscript mal unten angehangen.

Wenn ich reinen C-Code verwende funktioniert alles, nur eben nicht wenn 
ich die Standard-Header von C++ mit includiere??

Danke schon mal für Hilfe
1
/*
2
*****************************************************************************
3
**
4
**  File        : stm32_flash.ld
5
**
6
**  Abstract    : Linker script for STM32F103VB Device with
7
**                128KByte FLASH, 20KByte RAM
8
**
9
**                Set heap size, stack size and stack location according
10
**                to application requirements.
11
**
12
**                Set memory bank area and size if external memory is used.
13
**
14
**  Target      : STMicroelectronics STM32
15
**
16
**  Environment : Atollic TrueSTUDIO(R)
17
**
18
**  Distribution: The file is distributed “as is,” without any warranty
19
**                of any kind.
20
**
21
**  (c)Copyright Atollic AB.
22
**  You may use this file as-is or modify it according to the needs of your
23
**  project. Distribution of this file (unmodified or modified) is not
24
**  permitted. Atollic AB permit registered Atollic TrueSTUDIO(R) users the
25
**  rights to distribute the assembled, compiled & linked contents of this
26
**  file as part of an application binary file, provided that it is built
27
**  using the Atollic TrueSTUDIO(R) toolchain.
28
**
29
*****************************************************************************
30
*/
31
32
/* Entry Point */
33
ENTRY(Reset_Handler)
34
35
/* Highest address of the user mode stack */
36
_estack = 0x20005000;    /* end of 20K RAM */
37
38
/* Generate a link error if heap and stack don't fit into RAM */
39
_Min_Heap_Size = 0;      /* required amount of heap  */
40
_Min_Stack_Size = 0x100; /* required amount of stack */
41
42
/* Specify the memory areas */
43
MEMORY
44
{
45
  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 128K
46
  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 20K
47
  MEMORY_B1 (rx)  : ORIGIN = 0x60000000, LENGTH = 0K
48
}
49
50
/* Define output sections */
51
SECTIONS
52
{
53
54
55
56
  /* The startup code goes first into FLASH */
57
  .isr_vector :
58
  {
59
    . = ALIGN(4);
60
    KEEP(*(.isr_vector)) /* Startup code */
61
    . = ALIGN(4);
62
  } >FLASH
63
64
  /* The program code and other data goes into FLASH */
65
  .text :
66
  {
67
    . = ALIGN(4);
68
    *(.text)           /* .text sections (code) */
69
    *(.text*)          /* .text* sections (code) */
70
    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
71
    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
72
    *(.glue_7)         /* glue arm to thumb code */
73
    *(.glue_7t)        /* glue thumb to arm code */
74
75
    KEEP (*(.init))
76
    KEEP (*(.fini))
77
78
    . = ALIGN(4);
79
    _etext = .;        /* define a global symbols at end of code */
80
  } >FLASH
81
82
83
   .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
84
    .ARM : {
85
    __exidx_start = .;
86
      *(.ARM.exidx*)
87
      __exidx_end = .;
88
    } >FLASH
89
90
  .ARM.attributes : { *(.ARM.attributes) } > FLASH
91
92
  .preinit_array     :
93
  {
94
    PROVIDE_HIDDEN (__preinit_array_start = .);
95
    KEEP (*(.preinit_array*))
96
    PROVIDE_HIDDEN (__preinit_array_end = .);
97
  } >FLASH
98
  .init_array :
99
  {
100
    PROVIDE_HIDDEN (__init_array_start = .);
101
    KEEP (*(SORT(.init_array.*)))
102
    KEEP (*(.init_array*))
103
    PROVIDE_HIDDEN (__init_array_end = .);
104
  } >FLASH
105
  .fini_array :
106
  {
107
    PROVIDE_HIDDEN (__fini_array_start = .);
108
    KEEP (*(.fini_array*))
109
    KEEP (*(SORT(.fini_array.*)))
110
    PROVIDE_HIDDEN (__fini_array_end = .);
111
  } >FLASH
112
113
  /* used by the startup to initialize data */
114
  _sidata = .;
115
116
  /* Initialized data sections goes into RAM, load LMA copy after code */
117
  .data : AT ( _sidata )
118
  {
119
    . = ALIGN(4);
120
    _sdata = .;        /* create a global symbol at data start */
121
    *(.data)           /* .data sections */
122
    *(.data*)          /* .data* sections */
123
124
    . = ALIGN(4);
125
    _edata = .;        /* define a global symbol at data end */
126
  } >RAM
127
128
  /* Uninitialized data section */
129
  . = ALIGN(4);
130
  .bss :
131
  {
132
    /* This is used by the startup in order to initialize the .bss secion */
133
    _sbss = .;         /* define a global symbol at bss start */
134
    __bss_start__ = _sbss;
135
    *(.bss)
136
    *(.bss*)
137
    *(COMMON)
138
139
    . = ALIGN(4);
140
    _ebss = .;         /* define a global symbol at bss end */
141
    __bss_end__ = _ebss;
142
  } >RAM
143
144
  PROVIDE ( end = _ebss );
145
  PROVIDE ( _end = _ebss );
146
147
  /* User_heap_stack section, used to check that there is enough RAM left */
148
  ._user_heap_stack :
149
  {
150
    . = ALIGN(4);
151
    . = . + _Min_Heap_Size;
152
    . = . + _Min_Stack_Size;
153
    . = ALIGN(4);
154
  } >RAM
155
156
  /* MEMORY_bank1 section, code must be located here explicitly            */
157
  /* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
158
  .memory_b1_text :
159
  {
160
    *(.mb1text)        /* .mb1text sections (code) */
161
    *(.mb1text*)       /* .mb1text* sections (code)  */
162
    *(.mb1rodata)      /* read-only data (constants) */
163
    *(.mb1rodata*)
164
  } >MEMORY_B1
165
166
  /* Remove information from the standard libraries */
167
  /DISCARD/ :
168
  {
169
    libc.a ( * )
170
    libm.a ( * )
171
    libgcc.a ( * )
172
      libgcc.a
173
    libg.a
174
    libnosys.a
175
  }
176
}

von W.S. (Gast)


Lesenswert?

Es steht doch deutlich lesbar da:
"region `FLASH' overflowed by 214732 bytes"

Kurzum, das was du da zusammengebraut hast, ist deutlich zu groß für den 
Chip.

W.S.

von Daniel F. (franken_3)


Lesenswert?

OK Danke, es handelt sich aber doch nur um ein kleines Testprogramm das 
die LED blinken lässt. Kann es sein das ich dem Linker oder Compiler 
noch irgendwelche Optionen mitgeben muss, damit er schlanken Code 
erzeugt?

Hab mal was davon gelessen das man die Execptions oder so ausschalten 
muss??? Aber genaues weis ich leider auch nicht.

Danke

von Dr. Sommer (Gast)


Lesenswert?

Verwende mal die hier angegebenen Compiler/Linker Flags, die diverse 
Optimierungen einschalten und eben Exceptions und RTTI abschalten:

http://www.mikrocontroller.net/articles/ARM_GCC#Compiler_.26_Linker_Flags

von hp-freund (Gast)


Lesenswert?

Du benutzt einen F4 und das link script ist für den STM32F103VB.

Welchen F4 hast Du, bzw wieviel FLASH und RAM?

von Daniel F. (franken_3)


Lesenswert?

hp-freund schrieb:
> Du benutzt einen F4 und das link script ist für den STM32F103VB.
>
> Welchen F4 hast Du, bzw wieviel FLASH und RAM?

Ich habe ein STM32F407VG Discovery Board.

Wo kann ich denn das richtige Script bekommen?
Bietet ST das vielleicht irgendwo auf seiner Homepage an? Bestimmt oder? 
Bisher habe ich nichts gefunden leider

Das Gerät hat 1MB Flash und 192KB Ram

: Bearbeitet durch User
von hp-freund (Gast)


Lesenswert?

Das script ist schon nicht falsch wenn es ohne Fehler compiliert.

Du musst es nur anpassen. 192k hat noch einen Haken, nimm erst mal
128k RAM:
1
/* Highest address of the user mode stack */
2
_estack = 0x20020000;    /* end of 128K RAM */
3
4
/* Generate a link error if heap and stack don't fit into RAM */
5
_Min_Heap_Size = 0;      /* required amount of heap  */
6
_Min_Stack_Size = 0x100; /* required amount of stack */
7
8
/* Specify the memory areas */
9
MEMORY
10
{
11
  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K
12
  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 128K
13
  MEMORY_B1 (rx)  : ORIGIN = 0x60000000, LENGTH = 0K
14
}

von Daniel F. (franken_3)


Lesenswert?

Danke, hab es übernommen. Warum kann man denn nicht die vollen 192K 
nutzen (rein Interressehalber)?

Mein Programm funktioniert auch soweit jetzt, Fehler gibts nur noch wenn 
ich <iostream> einbinde , mit <vector> geht es, ich kann auch eine 
Klasse anlegen, aber nichts mit new anlegen??

Mich verwundert das ein bisschen, da ich ja unter Windows mit Em::Blocks 
es dort erfolgreich dynamisch Speicher reservieren kann. Das möchte ich 
unter Linux auch hinbekommen :)

Vielleicht kennt ja jemand diese Fehler und weis eine Lösung?? Danke

Hier mal die Fehlerausgabe für iostream und new
1
||=== Build: Release in iotogglem0 (compiler: GNU GCC Compiler for ARM) ===|
2
/home/sean/.bin/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libc.a(lib_a-sbrkr.o)||In function `_sbrk_r':|
3
sbrkr.c:(.text._sbrk_r+0xc)||undefined reference to `_sbrk'|
4
/home/sean/.bin/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libc.a(lib_a-signalr.o)||In function `_kill_r':|
5
signalr.c:(.text._kill_r+0xe)||undefined reference to `_kill'|
6
/home/sean/.bin/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libc.a(lib_a-signalr.o)||In function `_getpid_r':|
7
signalr.c:(.text._getpid_r+0x0)||undefined reference to `_getpid'|
8
/home/sean/.bin/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libc.a(lib_a-writer.o)||In function `_write_r':|
9
writer.c:(.text._write_r+0x10)||undefined reference to `_write'|
10
/home/sean/.bin/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libc.a(lib_a-closer.o)||In function `_close_r':|
11
closer.c:(.text._close_r+0xc)||undefined reference to `_close'|
12
/home/sean/.bin/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libc.a(lib_a-fstatr.o)||In function `_fstat_r':|
13
fstatr.c:(.text._fstat_r+0xe)||undefined reference to `_fstat'|
14
/home/sean/.bin/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libc.a(lib_a-isattyr.o)||In function `_isatty_r':|
15
isattyr.c:(.text._isatty_r+0xc)||undefined reference to `_isatty'|
16
/home/sean/.bin/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libc.a(lib_a-lseekr.o)||In function `_lseek_r':|
17
lseekr.c:(.text._lseek_r+0x10)||undefined reference to `_lseek'|
18
/home/sean/.bin/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libc.a(lib_a-readr.o)||In function `_read_r':|
19
readr.c:(.text._read_r+0x10)||undefined reference to `_read'|
20
||=== Build failed: 9 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


Das zugehörige Beispeilprogramm:
1
//#include <iostream>   <--- MACHT NOCH AERGER?? MIT EM-BLOCKS UNTER WINDOWS OK=??
2
3
#include "stm32f4xx.h"
4
#incl<iostreude "stm32f4xx_conf.h"
5
#include "project_defines.h"
6
7
8
#include <vector>
9
10
11
12
using namespace std;
13
14
class test
15
{
16
    private:
17
    int hier;
18
    public:
19
20
    void setHier(int t) {this->hier = t;}
21
    int getHier() {return this->hier;}
22
};
23
24
25
26
27
28
int main(void) {
29
30
    test rob;
31
    //test *obj = new test;  <--- MACHT NOCH AERGER?? MIT EM-BLOCKS UNTER WINDOWS OK=??
32
33
    //obj->setHier(5);
34
35
    //Clock für GPIOD (LEDs, Taster) aktivieren
36
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
37
38
    //GPIOD (LEDS) konfigurieren
39
    GPIO_InitTypeDef  GPIO_InitStructure;
40
    GPIO_InitStructure.GPIO_Pin   = LED_GREEN | LED_ORANGE | LED_RED | LED_BLUE;
41
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
42
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
43
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
44
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
45
    GPIO_Init(GPIOD, &GPIO_InitStructure);
46
47
48
49
    while (1) {
50
51
52
    //if(5 == obj->getHier())
53
    {
54
        //Led an
55
56
    GPIOD->BSRRL = LED_ORANGE;// | LED_BLUE;
57
    Delay(10000000L);
58
    GPIOD->BSRRL = LED_RED;// | LED_BLUE;
59
    Delay(10000000L);
60
    GPIOD->BSRRL = LED_BLUE;
61
    Delay(10000000L);
62
    GPIOD->BSRRL = LED_GREEN;// | LED_BLUE;
63
    Delay(10000000L);
64
    //Led aus
65
    GPIOD->BSRRH = LED_GREEN | LED_ORANGE | LED_RED | LED_BLUE;
66
    Delay(10000000L);
67
    }
68
69
    }
70
}
71
72
void Delay(__IO uint32_t nCount) {
73
  while(nCount--) {
74
  }
75
}

von hp-freund (Gast)


Lesenswert?

Daniel Eck schrieb:
> Danke, hab es übernommen. Warum kann man denn nicht die vollen 192K
> nutzen (rein Interressehalber)?

http://sigalrm.blogspot.de/2013/12/using-ccm-memory-on-stm32.html

von hp-freund (Gast)


Lesenswert?

Da ich die Makefile Methode benutze (eclipse) und nicht codeblocks, kann 
ich dazu auch nicht viel sagen.

Ein einfaches und funktionierendes Makefile Projekt findet sich hier:
http://siwawi.bauing.uni-kl.de/avr_projects/arm_projects/stm32_cpp_test_20120422.zip

Daraus sollten alle Anforderungen für C++ ersichtlich sein....

von Daniel F. (franken_3)


Lesenswert?

Hab das Problem mit den Fehlern gefunden. Auch bei den Linker-Optionen 
musste ich -specs=nosys.specs angeben.

Hatte es nur bei den Compiler-Optionen drin.

Fehlerfrei übersetzt wurde jetzt schon mal :)


Danke für die Hilfe!

EDIT:

Läuft jetzt wie es soll. Mit allen Standard-Libs (auch wenn man Sie 
nicht braucht) und auch der dynamische Speicher mit new/delete 
funktioniert

: Bearbeitet durch User
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.