cancel
Showing results for 
Search instead for 
Did you mean: 

memory usage in stm32

toufik_iddou
Associate II

Hi community!
I write a simple code in stm32 and I need to calculate the memory usage from the build analyzer 

this is a part of the code 

 

 

#define N 16146
volatile uint16_t adc_buffer[N];
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC2_Init();
MX_TIM2_Init();
MX_TIM6_Init();

int i = 0;
while (1)
 {
adc_buffer[i]=++i;
i=i%N;
 }
}

 

it's just a simple code to test so I think the used RAM should be at least 32.292KB (16146*2) but in the build analyzer I got that I used just 1.86KB

toufik_iddou_0-1716736493013.png

and I don't find the variable adc_buffer in the memory details

toufik_iddou_1-1716736558438.png

I tried to change the build viewer refresh mode to auto and it still gave the same result 

 

 

 

3 REPLIES 3
toufik_iddou
Associate II

I tried to change the place of declaration from main.c to stm32f4xx_it.c and it's working well

If anyone knows the reason, please help me

Muhammed Güler
Senior III

If you do not use the variable somewhere, optimization tools will delete the variable.
The last code you wrote may not have been deleted because the variable usage analysis between files did not work well.
If you do not want non-functional variables to be deleted, you can lower the optimization level from the settings.

I don't think so, I'm working with non-optimization and the O optimization doesn't delete the volatile variable even when you didn't use it