Skip to main content
RKUMA.2
Associate III
May 4, 2021
Solved

when I build the project, it is showing the error of 1. .text' will not fit in region `FLASH' 2. `FLASH' overflowed by 12480 bytes

Hello everyone,

I am working with stm32f070c6 , I am developing an application of USB_CDC , When I build the project it is showing the error of 

1. .text' will not fit in region `FLASH'

2. `FLASH' overflowed by 12480 bytes

actually I had increase the heap size to 0x400 and stack size 0x400, In my program I am using a buffer size of 64 bytes,

can you please help me out how to overcome flash overflow error.

This topic has been closed for replies.
Antypas.Peter
Antypas.PeterBest answer
Senior
May 8, 2021

A few things I do with every ARM Cortex:

  • Compile with the link time optimizer (-flto)
  • For release builds, unless I absolutely need speed optimizations, I optimize for size (-Os)
  • Let the linker remove unused sections (--gc-sections)
  • Link with newlib-nano (--specs=nano.specs)
  • Never use syscalls (--specs=nosys.specs)

If none of these do the trick, then there must be something in your project that allocates large chunks of FLASH. Any large static const arrays, by any chance?

6 replies

TDK
May 4, 2021

Options:

  • Reduce the size of your program. One easy way to do this is to compile in Release mode.
  • Switch to a different chip with more memory.
"If you feel a post has answered your question, please click ""Accept as Solution""."
RKUMA.2
RKUMA.2Author
Associate III
May 5, 2021

Thanks for your reply @TDK is there any alternatives to overcome that flash overflow error, I reduced the static variables in my program but the problem is remains same

TDK
May 5, 2021
Can’t use more memory than you have on the chip. Pretty simple concept.
"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
May 4, 2021

Perhaps review what exactly you have sucking up all the resources, is it code, or static data?

You can perhaps tell the linker it has more memory to work with so it can get closure, and then inspect the .MAP to determine the resource hogs.

Bitmaps? Data Tables?

Are you using a lot of heap space? How much stack is actually being utilized?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Antypas.Peter
Antypas.PeterBest answer
Senior
May 8, 2021

A few things I do with every ARM Cortex:

  • Compile with the link time optimizer (-flto)
  • For release builds, unless I absolutely need speed optimizations, I optimize for size (-Os)
  • Let the linker remove unused sections (--gc-sections)
  • Link with newlib-nano (--specs=nano.specs)
  • Never use syscalls (--specs=nosys.specs)

If none of these do the trick, then there must be something in your project that allocates large chunks of FLASH. Any large static const arrays, by any chance?

Associate
May 17, 2024

Can you elaborate on how to make these changes? I'm a newbie to CubeIDE. Thanks!