cancel
Showing results for 
Search instead for 
Did you mean: 

C++ constructors that are running before the IAR DLIB lock initialization cause system to hang

EtaiS
Associate

Hi,

We are using the IAR compiler and Cube generated project on STM32L4+ for a new project we intend to code in C++.

Because C++ runs constructors of static objects before the main() function at an undetermined order the program hangs. I need to make sure somehow that the DLIB locks initialization function (generated by cube) runs before all the other constructors.

How can I set the order of execution for the constructors and move the DLIB initialization to be always the first one?

1 REPLY 1

Does it hang, or merely Hard Faults?

A​RM's CMSIS model really expects all clocks and external memory to be brought up by SystemInit(), not some hodgepodge of code in main(). You might want the system in a viable state before initializing statics, and calling constructors.

I​nstrument the Hard Faults Handler to get some actionable information from that.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..