aboutsummaryrefslogtreecommitdiff
path: root/setup/clocks.s
diff options
context:
space:
mode:
authorJacques Comeaux <jacquesrcomeaux@protonmail.com>2024-05-20 23:19:14 -0500
committerJacques Comeaux <jacquesrcomeaux@protonmail.com>2024-05-20 23:19:14 -0500
commit7388c270069c2d1418539bca1d2789a6d468ecc2 (patch)
treed3848031f6c2d4d45ec0a7c75b12a9f476680726 /setup/clocks.s
parent7f47fc894d43739fb0107fd17e76f65ae2bf46bc (diff)
Make shared object for setup routines
Diffstat (limited to 'setup/clocks.s')
-rw-r--r--setup/clocks.s31
1 files changed, 31 insertions, 0 deletions
diff --git a/setup/clocks.s b/setup/clocks.s
new file mode 100644
index 0000000..83bc9ff
--- /dev/null
+++ b/setup/clocks.s
@@ -0,0 +1,31 @@
+.syntax unified
+.cpu cortex-m0plus
+.thumb
+
+.equ CLOCKS_BASE, 0x40008000
+.equ CLK_REF_CTRL_OFST, 0x30
+.equ CLK_SYS_CTRL_OFST, 0x3c
+.equ CLK_PERI_CTRL_OFST, 0x48
+
+.type setup_clocks, %function
+.global setup_clocks
+
+setup_clocks:
+
+ ldr r1, =CLOCKS_BASE
+
+ // Reference clock
+ movs r0, 0x2 // src = xosc
+ str r0, [r1, CLK_REF_CTRL_OFST]
+
+ // System clock
+ movs r0, 0x0 // src = clk_ref
+ str r0, [r1, CLK_SYS_CTRL_OFST]
+
+ // Peripheral clock
+ movs r0, 1 // set enable
+ lsls r0, 11
+ adds r0, 0x4 << 5 // src = xosc
+ str r0, [r1, CLK_PERI_CTRL_OFST]
+
+ bx lr