Last active
August 19, 2023 13:04
-
-
Save ppannuto/672328eb8184abdb9559 to your computer and use it in GitHub Desktop.
Replacement startup routine for STM32L0XX (or really most any Cortex-M0[+])
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.syntax unified | |
.cpu cortex-m0plus | |
.fpu softvfp | |
.thumb | |
.global g_pfnVectors | |
.global Default_Handler | |
/* start address for the initialization values of the .data section. | |
defined in linker script */ | |
.word _sidata | |
/* start address for the .data section. defined in linker script */ | |
.word _sdata | |
/* end address for the .data section. defined in linker script */ | |
.word _edata | |
/* start address for the .bss section. defined in linker script */ | |
.word _sbss | |
/* end address for the .bss section. defined in linker script */ | |
.word _ebss | |
.section .text.Reset_Handler | |
.weak Reset_Handler | |
.type Reset_Handler, %function | |
Reset_Handler: | |
/* Don't need to set this here, the stack pointer is loaded out of | |
* the vector table automatically by the core on boot. | |
ldr r0, =_estack | |
mov sp, r0 | |
*/ | |
/* Copy the data segment initializers from flash to SRAM */ | |
/* | |
movs r1, #0 | |
b LoopCopyDataInit | |
CopyDataInit: | |
ldr r3, =_sidata | |
ldr r3, [r3, r1] | |
str r3, [r0, r1] | |
adds r1, r1, #4 | |
LoopCopyDataInit: | |
ldr r0, =_sdata | |
ldr r3, =_edata | |
adds r2, r0, r1 | |
cmp r2, r3 | |
bcc CopyDataInit | |
*/ | |
CopyDataInitializersStart: | |
ldr r0, =_sdata /* write to this addr */ | |
ldr r1, =_edata /* until you get to this addr */ | |
ldr r2, =_sidata /* reading from this addr */ | |
b CopyDataInitializersEnterLoop | |
CopyDataInitializersLoop: | |
ldmia r2!, {r3} | |
stmia r0!, {r3} | |
CopyDataInitializersEnterLoop: | |
cmp r0, r1 | |
bcc CopyDataInitializersLoop | |
/* | |
ldr r2, =_sbss | |
b LoopFillZerobss | |
FillZerobss: | |
movs r3, #0 | |
str r3, [r2] | |
adds r2, r2, #4 | |
LoopFillZerobss: | |
ldr r3, = _ebss | |
cmp r2, r3 | |
bcc FillZerobss | |
*/ | |
WriteZeroToBssStart: | |
ldr r0, =_sbss | |
ldr r1, =_ebss | |
movs r2, #0 | |
b WriteZeroToBssEnterLoop | |
WriteZeroToBssLoop: | |
stmia r0!, {r2} | |
WriteZeroToBssEnterLoop: | |
cmp r0, r1 | |
bcc WriteZeroToBssLoop | |
/* Call the clock system intitialization function.*/ | |
bl SystemInit /* void SystemInit (void) */ | |
/* Call static constructors */ | |
bl __libc_init_array | |
/* Call the application's entry point.*/ | |
bl main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment