Recent

Author Topic: STM32 initialization sequence details  (Read 1913 times)

funlw65

  • Full Member
  • ***
  • Posts: 116
    • Visual Pin Configurator for Nucleo 64pin boards
STM32 initialization sequence details
« on: March 06, 2021, 01:26:02 pm »
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: [Select]
/* 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

and, in pascal, there is this code:

Code: [Select]
  bl PASCALMAIN
  b HaltProc

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: [Select]
begin
  SystemInit;
  { other initializations }
  { and the rest of the code }
end.

Thank you!
Lazarus 2.2.0rc3 fpc 3.2.2, Linux, UNIX BSD
widgetset: gtk2, msegui, qt5,  bgrabitmap controls
Immediate mode GUI: raygui 3.0

Laksen

  • Hero Member
  • *****
  • Posts: 697
    • J-Software
Re: STM32 initialization sequence details
« Reply #1 on: March 06, 2021, 02:12:26 pm »
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


funlw65

  • Full Member
  • ***
  • Posts: 116
    • Visual Pin Configurator for Nucleo 64pin boards
Re: STM32 initialization sequence details
« Reply #3 on: March 06, 2021, 02:31:24 pm »
Thank you for the info guys!
Lazarus 2.2.0rc3 fpc 3.2.2, Linux, UNIX BSD
widgetset: gtk2, msegui, qt5,  bgrabitmap controls
Immediate mode GUI: raygui 3.0

 

TinyPortal © 2005-2018