-
Notifications
You must be signed in to change notification settings - Fork 1
/
blink.S
81 lines (53 loc) · 1.3 KB
/
blink.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
.syntax unified
.cpu cortex-m4
.fpu fpv4-sp-d16
.thumb // Oddly, this allows NON-thumb instructions (ie: standard ARM)
#include "regs_inc.S"
/* This program just loops and blinks the LED,
* on an STM32 Nucleo series board
* Currently only f401RE and L476VG have been tested/supported
*/
.equ DELAY_INTERVAL, 0x186004
.global main
// enable clock for GPIOA
asm_rcc_enable:
ldr r1, =RCC_GPIO_ENABLER
mov r2, #RCC_GPIOA_EN
ldr r3, [r1] // Load in values for all clocks
orr r3, r2 // just OR, since we KNOW we are adding bits only
str r3, [r1]
bx lr
// Set the mode on the GPIOA, pin 5, to mode=output
asm_gpio_set_A5_output:
ldr r0, =GPIOA_MODER
mov r1, #GPIO_MODE_OUTPUT
lsl r1, #(5*2) // "pin5, x2 bits"
str r1, [r0]
ldr r0, =GPIOA_PUPDR
mov r1, #GPIO_PUPD_PULLUP
lsl r1, #(5*2) // "pin5, x2 bits"
str r1, [r0]
bx lr
asm_led_toggle:
ldr r3, =GPIOA_ODR // has port addr
ldr r1, [r3] // has port addr contents
mov.w r2, #GPIO_PIN5
eor r1,r2
str r1, [r3]
bx lr
delay:
ldr r0, =DELAY_INTERVAL
loop2:
nop
sub r0, #1
cmp r0, #0
bge loop2
bx lr
blinkonly:
bl delay
bl asm_led_toggle
b blinkonly
main:
bl asm_rcc_enable
bl asm_gpio_set_A5_output
b blinkonly