Forum > Embedded - ARM

STM32 initialization sequence details


Hopefully, the name of my thread is not too ambiguous ...

Anyway, in the SPL package for STM32L1 (provided by ST Microelectronics) there is a file, startup_stm32l1xx_xl.s used for initialization, and there is a portion of code where SystemInit function is inserted and executed first (before giving control to the main function):

--- Code: ---/* Call the clock system intitialization function.*/
    bl  SystemInit
/* Call static constructors */
    bl __libc_init_array
/* Call the application's entry point.*/
  bl main
  bx lr

--- End code ---

and, in pascal, there is this code:

--- Code: ---  bl PASCALMAIN
  b HaltProc

--- End code ---

so, I understand that you give control directly to the main block of your pascal program so, if I write a similar procedure with SystemInit, all I need to do to call it first is to insert it as the first line of code in the pascal main block, right? Like below?

--- Code: ---begin
  { other initializations }
  { and the rest of the code }

--- End code ---

Thank you!

Almost. Pascalmain is a bit magic, it calls the procedure to call all unit initialization procedures in the start, and then all the finalization blocks when(and if) it exits

So if you want something run before that you would have to put it in an initialization section, and even then you would have the initialization section of the system unit called first

Laksen is right. But I guess your code will still work. I am doing the same for the Wio Terminal.

Thank you for the info guys!


[0] Message Index

Go to full version