Skip to main content
Associate III
December 10, 2025
Solved

STM32G431CBU: section `.bss' will not fit in region `RAM'

  • December 10, 2025
  • 9 replies
  • 2876 views

 

Good morning.
Could anyone tell me about this error and how to resolve it.
C:/ST/STM32CubeIDE_1.19.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3 .rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: Oscillo_STM32G431CBU.elf section `.bss' will not fit in region `RAM'
C:/ST/STM32CubeIDE_1.19.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3 .rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: region `RAM' overflowed by 54928 bytes
I'm using IDE 1.19 to compile the code for a G431CBU
Grateful

Valter Matos

Best answer by Andrew Neil

So you have:

#define ILI9488_TFTWIDTH 	320
#define ILI9488_TFTHEIGHT 	480

and

/**
 * @brief Buffer storing 4-bit color values for each LCD pixel.
 * Each byte represents color information for two adjacent pixels, utilizing 4 bits per pixel
 */
static uint8_t image_buffer[ ILI9488_TFTWIDTH*ILI9488_TFTHEIGHT/2 ] = {0};

which becomes

static uint8_t image_buffer[ 320*480/2 ] = {0};

320*480/2 = 76800 bytes !

ie, 75K bytes

 

Which is exactly what @KnarfB said earlier - from the map file.

9 replies

mƎALLEm
Technical Moderator
December 10, 2025

Hello,

region `RAM' overflowed by 54928 bytes

Maybe you declared a large table in the RAM..

Use const for the table declaration to relocated it into the flash if that table content keeps unchanged in your application 

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
Andrew Neil
Super User
December 10, 2025

The key part of the message is:

section `.bss' will not fit in region `RAM'

It's telling you that your code uses more RAM than is available on the chip.

Specifically:

region `RAM' overflowed by 54928 bytes

It needs 54,928 more bytes.

The STM32G431CBU has 128K 32K bytes of RAM; your code is using 54K more than that - so about 182K 86K total.

You have 2 choices:

  1. Reduce the amount of RAM your code uses;
  2. Choose a different chip - with >182K RAM.

 

Correction: The chip has only 32K RAM - see post below by @KnarfB 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate III
December 10, 2025

It's a relatively small code, without many tables, and I still don't know how to optimize it.

Andrew Neil
Super User
December 10, 2025

@ValterMatos wrote:

without many tables, 


It's not about the number - it's about the total amount of RAM that they occupy...

 


@ValterMatos wrote:

I still don't know how to optimize it.


Nobody can help you without seeing the code!

How to insert source code

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Andrew Neil
Super User
December 10, 2025

A possibility overlooked so far: your linker script is incorrect - the definition of the 'RAM' region is too small.

So also post your linker script (the .ld file).

See the directions here.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
LCE
Principal II
December 10, 2025

I've attached the compressed file.

Most people don't like 1) downloading 2) unzipping 3) ... stuff.

As Andrew said, please post relevant source code:

- variable declarations

- DMA calls

 

Edit: maybe also your linker file, maybe there's a wrong RAM size setting.

Associate III
December 10, 2025
mƎALLEm
Technical Moderator
December 10, 2025

@ValterMatos ,

As stated previously there is an issue with the attachements these days:

mALLEm_0-1765382021731.png

We cannot download any of your attachments, so better to post your code using </> button.

Read How to insert source code

You need to share your linker file + the code.

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
LCE
Principal II
December 10, 2025

Many "medium" sized buffers... it all adds up!

Don't forget that u16 takes 2 bytes and so on...

So you got 2 channels, each with:

uint16_t waveform_raw_adc[512]

uint32_t waveform_display[480]

double fft_amplitude[64];

int32_t fft_frequency[64];

= 3712 bytes / channel

How many "Oscilloscope" do you declare?

Andrew Neil
Super User
December 10, 2025

@ValterMatos again, have you examined the map file, and/or used the Build Analyzer?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate III
December 10, 2025

Oscilloscope is declared only once.
I haven't examined the map yet and haven't used the Build Analyzer.
I've already examined all the code and haven't found where there's an increase of 50K in RAM usage.
By my estimates, it wouldn't reach 20K in total.
Thank you.

Associate III
December 10, 2025
/*
 * sprites.c
 *
 * Created on: 3 maj 2024
 * Author: Dominik
 */

#include "sprites.h"
#include "ILI9488.h"



const uint8_t trigRisingIcon[15][9] = {
 {0 , 0 , 0 , 0 , WHITE , WHITE , WHITE , WHITE , WHITE},
 {0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 },
 {0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 },
 {0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 },
 {0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 },
 {0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 },
 {0 , 0 , 0 , WHITE , WHITE , WHITE , 0 , 0 , 0 },
 {0 , 0 , WHITE , WHITE , WHITE , WHITE , WHITE , 0 , 0 },
 {0 , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , 0 },
 {0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 },
 {0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 },
 {0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 },
 {0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 },
 {0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 },
 {WHITE , WHITE , WHITE , WHITE , WHITE , 0 , 0 , 0 , 0 }
};

const uint8_t arrowUpDown[15][8] = {
 {0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0},
 {0 , 0 , WHITE , WHITE , WHITE , 0 , 0 , 0},
 {0 , WHITE , WHITE , WHITE , WHITE , WHITE , 0 , 0},
 {WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , 0},
	{0 , 0 , WHITE , WHITE , WHITE , 0 , 0 , 0},
 {0 , 0 , WHITE , WHITE , WHITE , 0 , 0 , 0},
 {0 , 0 , WHITE , WHITE , WHITE , 0 , 0 , 0},
 {0 , 0 , WHITE , WHITE , WHITE , 0 , 0 , 0},
 {0 , 0 , WHITE , WHITE , WHITE , 0 , 0 , 0},
 {0 , 0 , WHITE , WHITE , WHITE , 0 , 0 , 0},
 {0 , 0 , WHITE , WHITE , WHITE , 0 , 0 , 0},
 {WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , 0},
 {0 , WHITE , WHITE , WHITE , WHITE , WHITE , 0 , 0},
 {0 , 0 , WHITE , WHITE , WHITE , 0 , 0 , 0},
 {0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0}
};

const uint8_t arrowLeftRight[7][15] = {
 {0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0},
 {0 , 0 , WHITE , WHITE , 0 , 0 , 0 , 0 , 0 , 0 , 0 , WHITE , WHITE , 0 , 0},
 {0 , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , 0},
 {WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE},
 {0 , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , WHITE , 0},
 {0 , 0 , WHITE , WHITE , 0 , 0 , 0 , 0 , 0 , 0 , 0 , WHITE , WHITE , 0 , 0},
 {0 , 0 , 0 , WHITE , 0 , 0 , 0 , 0 , 0 , 0 , 0 , WHITE , 0 , 0 , 0}
};
LCE
Principal II
December 11, 2025

@Andrew Neil wrote:

> And it seems that the target audience is electronics focussed - not software.

> It seems to me that any electronics learning is going to be lost with all the software complexities.

 

100% agreed !

We find many people here who come from the software side or are beginners in general, they often have no idea about basic electronics, using an oscilloscope, MCUs in general and that these are mostly not machines with GBs of RAM and flash and GHz clocks.

Throwing a graphics project at them... too much in general - and not enough electronics.

Maybe they should start getting UART, ADC, DAC to work (without HAL), then checking IOs on the scope, playing with filters on the digital and analog side, etc...

Ozone
Principal
December 11, 2025

I vividly remember my university times. Back then, I studied electrical engineering, due to the lack of more specific alternatives. So I was the only one in my study group who had delved into computers and actual coding projects before.

Which became obvious during the final test in the "C programming" course we took, which consisted of "debugging" a short program with about 30 lines. While I was finished in less than 15 minutes, about half struggled until the end.

If it is not the focus area of the study field, a lecturer has to expect a wide variety of performances, and thus moderate his standards.

Andrew Neil
Super User
December 11, 2025

I once took a VHDL course.

About half the attendees were electronics (hardware) people, and half were software.

It was fascinating to see the different points which one group would find easy, while the other group struggled!

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
waclawek.jan
Super User
December 11, 2025

The ILI9488 controller contains videoRAM, so you don't need to allocate it in the mcu.

Of course, all the graphics routines have to be written with this in mind.

JW

Associate III
December 11, 2025

As I said before.

I am a Chemical Engineer with a lot of experience in research.

I have been a student, an employee, a team leader, and I have trained many students.
Today I am retired, a volunteer, and still learning.
If I had given up on the first challenge, I wouldn't have publications and patents registered in my name.
I am learning in STM and trying to guide people with what I know.
Challenges don't overwhelm; they teach you to look for solutions.
The chosen project was attempted in F303, but some structures were not allowed.
They managed to get some G431. I ported it, getting the necessary structures, but I didn't pay attention to the necessary memory.
I am trying to manipulate the image to fit the memory size.
I partially succeeded. It compiles, runs with some deficiencies.
In short, I'm not the one who decides the project. I help and learn.

Don't give up. Change the path to the objective.

Sorry and thank you for your attention.