Strange memory problem (static vs heap allocated)

Hi, I have a strange problem. I have a class called “Manager” which implements all the logic of my application.
If I do something like this, all seems to work fine:

static Manager mymanager;
void app_start(int, char**){

However, if I allocate my object at runtime, it only works randomly: often when trying to do a printf on a serial port it crashes (I found out that it goes to the infinite loop in startup.S).

static Manager *mymanager;
void app_start(int, char**){
    mymanager = new Manager();

I checked my linker file, there is enough room in the heap for the object, what can be the reason of the crash?

1 Like

How did you find this out, did you use a debugger? If so, where is it stuck? In the HardFaultHandler or somewhere else?

Yes I used GDB. It goes to the Infinite_Loop in startupstm32xxx.S, the comment written near this loop states:
/* This is the code that gets called when the processor receives an

  •     unexpected interrupt.  This simply enters an infinite loop, preserving
  •     the system state for examination by a debugger.


Sorry for the late reply. gdb should allow you to break whenever it hits that function right? What’s the content of the stack & registers there?

If the code is not too confidential (and the schematics are easy enough for me to reproduce) I’d love to take a look at it. If you want, you can drop me a line at