STM32 initialization sequence details lazarus / 79-Embedded - ARM ---------------------------------------------------------------------- funlw65 · 2021-03-06 12:26 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! ---------------------------------------------------------------------- Laksen · 2021-03-06 13:12 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 ---------------------------------------------------------------------- DonAlfredo · 2021-03-06 13:20 Laksen is right. But I guess your code will still work. I am doing the same for the Wio Terminal. https://github.com/LongDirtyAnimAlf/mbf-freertos-wio/blob/master/Sampl esBoardSpecific/WioTerminal/Examples/Clock/ClockTask.lpr#L187 https://github.com/LongDirtyAnimAlf/mbf-freertos- wio/tree/master/SamplesBoardSpecific/WioTerminal/Examples ---------------------------------------------------------------------- funlw65 · 2021-03-06 13:31 Thank you for the info guys!