aboutsummaryrefslogtreecommitdiff
path: root/xosc.s
diff options
context:
space:
mode:
authorJacques Comeaux <jacquesrcomeaux@protonmail.com>2023-12-23 14:12:08 -0600
committerJacques Comeaux <jacquesrcomeaux@protonmail.com>2023-12-23 14:12:08 -0600
commit8f6eed4e102500204879d848572547b35a267cea (patch)
treead5f5138f9068af37d11e20ac6c87e28c3f92d45 /xosc.s
parent987e12b6c90ed3a3606a4948e9d7cad6d6f34026 (diff)
Use crystal oscilator for system clock
Diffstat (limited to 'xosc.s')
-rw-r--r--xosc.s23
1 files changed, 23 insertions, 0 deletions
diff --git a/xosc.s b/xosc.s
new file mode 100644
index 0000000..ee58ec0
--- /dev/null
+++ b/xosc.s
@@ -0,0 +1,23 @@
+.syntax unified
+.cpu cortex-m0plus
+.thumb
+
+.equ XOSC_BASE, 0x40024000
+.equ CTRL_OFST, 0x0
+.equ STATUS_OFST, 0x4
+.equ STARTUP_OFST, 0xc
+
+.type start_xosc, %function
+.global start_xosc
+
+start_xosc:
+ ldr r1, =XOSC_BASE
+ movs r0, 47 // startup delay = 47 for 12Mhz crystal
+ str r0, [r1, STARTUP_OFST]
+ ldr r0, =0x00fabaa0 // enable
+ str r0, [r1, CTRL_OFST]
+1:
+ ldr r0, [r1, STATUS_OFST]
+ lsrs r0, r0, 31 // poll status bit
+ beq 1b
+ mov pc, lr