2020-11-25 07:58 AM
I upgraded to STM32CUBE IDE v1.5 few days ago, then strange problems began to appear.
Suddenly, code that previously worked on v1.3, doesn't. No major changes.
The program uses a some dynamic memory allocation, so to debug the free memory, I use this routine.
It allocates adding 100 byte blocks. I know it's not perfect, but it gives me a idea of the memory usage.
It worked well last time I used it, 2 weeks ago, allocating 10K of ram before and 2K after the program initialization.
Now the malloc always returns a valid pointer, and the allocation value increases without control until it triggers a HardFault.
__attribute__((optimize("O0"))) // Disable all optimizations
uint16_t freeram(void){
uint16_t ram=100; // Start with 100 byte allocation
uint8_t* ptr; // Pointer for malloc function
while(1){
ptr=malloc(ram); // Try to malloc 'ram' bytes
if(ptr==NULL){ // If null pointer
return (ram-100); // Return previous ram value
}
else{ // If not null
free(ptr); // Free up the allocated memory
ram+=100; // Increase allocation size
}
}
}