This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Why use __low_level_init

Other Parts Discussed in Thread: MSP430F67791

Hi TI Community,

I'm currently working on MSP430F67791 using IAR Embedded workbench. I have a reference code for my 3 phase smart meter and I found something interesting function names "__low_level_init".  I dig about this function and I found that it works before "main" called. My questions are 

1) What's the requirement of this function and when to use it ?

2) How its different rather than calling a function inside the main function?

Thanks in advance,

  • Probably I find out the answer myself in this PDF.
    www.ti.com/.../slaa294a.pdf

  • Hi,

    Glad you found this document. __low_level_init is by default a stub function that gets called before variables are initialized before main. It is there so you could do things like disable the watchdog before the variable init (like if you have large arrays that will take too long to initialize), or if you have some other special case. Most of the time it is not needed other than to stop the watchdog if you have a large number of variables that will cause it to time out before main.

    Regards,
    Katie
  • This function can also be used to disable the initialization of the global variables, maybe after checking some magic value. So the device can recover from a reset without starting from scratch. It may check the reset cause and if it wasn't a brownout, variables may remain untouched and main can later skip much of the high-level init code and continue working normally. As if the reset was just a normal interrupt.
    However, this is rather advanced stuff.
  • Hi, Gross

    First, thanks for the answer, but I need clarification about high-level init code. Could you please elaborate your answer.

  • Normally, after a reset, the execution is always the same: Global variables are initialized by the C startup code, then main() is started where your code initializes the internal and sometimes also the external peripherals before entering its normal working loop. This is the 'high-level initialization' I was talking about.
    However, if at __low_level_init you determine that the reset was not due to power loss, you may want (maybe after an additional consistency check) to skip initializing the global variables, and later also skip initializing external peripherals or such, to just continue where you were interrupted.
    It is only a possible usage, and depends on your application. But it needs to be decided long before main() is started.

**Attention** This is a public forum