Skip to main content
Visitor II
April 5, 2022
Question

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

  • April 5, 2022
  • 1 reply
  • 625 views

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?

    This topic has been closed for replies.

    1 reply

    Graduate II
    April 5, 2022

    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.