cancel
Showing results for 
Search instead for 
Did you mean: 

Why do I keep getting "Flash region overflowed" error?

zedeg
Associate III

​Hi everyone)

I've attached project, that I refer further.

I'm trying to write program on my STM32F103(C8T6).

"From scratch" I've made CubeMX project, set all needed pins in modes I need to, generated it.

I've tried to flash a led on a couple of ports, it's ok.

So, next thing, I've converted project to C++, and this is part, when all the fun begins.

I've added function "my_main" to my_main.cpp file, used it from main.c, it worked, but when I tried to call some function from my_main() (HAL_Delay, or one of my class methods), I keep getting errors like "ld.exe: region `FLASH' overflowed by 17904 bytes", it can be caused by "stm32f103_lcd_board.elf section `.text' will not fit in region `FLASH'" or for example '.ARM' might not fit too (I've seen it on a project, that I used previously).

I can't understand, what's wrong, since earlier I've done projects like this with no trouble at all.

So, if someone have a clue, or can check attached project, I'll be grateful)

14 REPLIES 14
 .text          0x08000150     0x6698 c:/program files/atollic/truestudio for stm32 9.1.0/armtools/bin/../lib/gcc/arm-atollic-eabi/6.3.1/../../../../arm-atollic-eabi/lib/armv7-m\libstdc++.a(cp-demangle.o)
                0x0800670c                __cxa_demangle
                0x080067c4                __gcclibcxx_demangle_callback
 
 .rodata.str1.4
                0x08012f64      0x850 c:/program files/atollic/truestudio for stm32 9.1.0/armtools/bin/../lib/gcc/arm-atollic-eabi/6.3.1/../../../../arm-atollic-eabi/lib/armv7-m\libstdc++.a(cp-demangle.o)
                                0x89e (size before relaxing)
 

Particularly greedy function(s) consuming code and data space in FLASH (27-28KB)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
zedeg
Associate III

Thank's, now I can see ones.

But why do I get it just now?

Earlier on, on same board, with same code style, with more standard and HAL libs used (used uart, gpio, usb, SPRINTF, and bunch of data (around 10-15k) ), and with more code, obiviously, I was able to work just fine.

I guess, I can provide my previous project for comparison.

There's must be something with changes I've made in CubeMX side of project or in some TrueStudio's preferences.

Can't see any other reason, why should this pop up like that (since I've made no consciously changes to any compiler/linker options).

Also, after I've faced this issue, I tried to change optimization levels, or delete my .eclipse and workspace dir's, but it has no significant effect.

zedeg
Associate III

Ugh...

I've found some kind of reason to all this situation. It may be a TrueStudio bug, or may be you can explain to me, where I acting wrong.

So, I decided to delete all my project's TrueStudio-related files.

Generated it with Cube again, passed all mentioned steps, recompiled, and it's just worked (smth like 19k overall, with .text, .data, etc).

And as always, here funny part begins:

I've changed 1 only thing in project's properties - set C compiler optimization to -O0 level, and problem appeared.

Ok, so I've tried to revert my changes back - set C compiler to -Os, where it's been. But, it had no significant effect, problem is in place. (So, I managed to locate some part of problem, so now I know what to avoid to, yet I can't consider fearly avoiding some option as a good solution to me).

So, yeah, I'll attach screenshots and both projects (freshly generated and compiled, and the one after optimization changes), don't know, if anybody will want to look into it...

zedeg
Associate III

-

Sorry, didn't noticed "more posts" button)

So, briefly.

I've found a "fix" for this error. It's seems as TrueStudio bug to me... Let me explain what I did.

First at first, I couldn't get in mind, why there's some big C++ funcs, which I defenetly didn't use at all.

So, I started out with project's properties check... There were level -O0 optimization for both C and C++ parts.

I've changed it to various combinations, but none gave me significant result...

Then I decided to delete all TrueStudio related files (.prj, .ln, .settings and debug folders), and regenerate project with CubeMX, and convert it to C++ proj again. And after that... It compiled and assmbled, just perfectly, with overall size of 19KB.

So, as it turns out, when I generate stock project, it has optimization keys -Os for C and -O0 for C++.

if i change C key to -O0 - this issue shows up. Seems logical...

BUT! Even if I try to revert changes back, and use -Os for C, it takes no signifficant effect (as well, as -Od or other keys).

May be, I miss something important, but I've checked out this behaviour for several times, and it comes down to C optimization key irreversable change. If it's my fault, can somebody explain it to me? Thx)

Also, I've attached console build output screenshots to my post, as well as two 'versions' of project ("freshly-generated", that compiles just fine with 19K, and "spoiled" one, that compiles with unnecessary parts and is ~82K), if someone will want to analyze it.