When is going malloc() / dynamic allocation to be fixed?
Edit: It seems there's a bug that will randomly delete sysmem.c and syscalls.c.
If it happens, cubeMX won't regenerate them.
Also no warnings at compile time, so you won't suspect anything was deleted.
So the solution is to make a new empty project and copy these files back.
___________________________________________________________________________________
I don't know if it's a bug, wrong initialization, or lacking code.
I remember once in 2019 where it worked, I could run malloc(X) and the pointer would be null if wanting too much.
But since then, none of the Cube IDE versions have worked correctly.
I can run a 100KB malloc on a 16KB stm32, yet it will return a valid pointer.
Of course a hard fault will happen when you try to access the memory.
I had to modify every project to use static allocation, which is sometimes a problem because I could save a lot of RAM when certain parts of the code is not being used.
The minimum heap allocation just reserves the heap at compile time, doesn't fix anything.
Also, free() doesn't seem to work correctly.
I can malloc 64KB on a 128KB device and use it.
But if I malloc 1KB and 16KB, then free both, I can't malloc 64KB (it does, but outside the memory limits).
I don't understand why, as these pointers where freed up, so memory fragmentation shouldn't be happening?
I'm spending more time in looking over these bugs than on my own ones...
Don't tell me that I have to increase heap. Because I could put 16TB of heap, and still get hard faults when it goes too far.
Why doesn't malloc check the remaining space?