Recent

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

funlw65

  • Full Member
  • ***
  • Posts: 148
    • 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!
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

Laksen

  • Hero Member
  • *****
  • Posts: 755
    • 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: 148
    • 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!
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

 

TinyPortal © 2005-2018