2024-05-26 08:18 AM
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
and I don't find the variable adc_buffer in the memory details
I tried to change the build viewer refresh mode to auto and it still gave the same result
2024-05-26 08:44 AM
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
2024-05-26 09:47 AM
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.
2024-05-26 10:45 AM
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