-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
pull-up.s
79 lines (59 loc) · 1.46 KB
/
pull-up.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
/* Pull-up resistor example */
.thumb
.text
.equ GPIOA_BASE, 0x48000000
.equ GPIOA_MODER_OFFSET, 0x00
.equ GPIOA_MODER, GPIOA_BASE + GPIOA_MODER_OFFSET
.equ GPIOA_OTYPER_OFFSET, 0x04
.equ GPIOA_OTYPER, GPIOA_BASE + GPIOA_OTYPER_OFFSET
.equ GPIOA_IDR_OFFSET, 0x10
.equ GPIOA_IDR, GPIOA_BASE + GPIOA_IDR_OFFSET
.equ GPIOA_PUPDR_OFFSET, 0x0C
.equ GPIOA_PUPDR, GPIOA_BASE + GPIOA_PUPDR_OFFSET
.equ GPIOA_SPEEDR_OFFSET, 0x08
.equ GPIOA_SPEEDR, GPIOA_BASE + GPIOA_SPEEDR_OFFSET
.equ GPIOA_MODER_PA4, 0 << 8 /* Input mode */
.equ GPIOA_OTYPER_PA4, 1 << 4 /* Open-drain */
.equ GPIOA_SPEEDR_PA4, 1 << 8 /* Medium speed */
.equ GPIOA_PUPDR_PA4, 0x00 << 8 /* No pull-up/push-down */
.equ GPIOA_IDR_PA4, 1 << 4
.global start
Vector_Table:
.word 0x20002000
.word start + 1
start:
bl uart_init
bl pull_up_pin_init
main_loop:
bl delay
/* Read the input pin state */
ldr r1, =GPIOA_IDR
ldr r0, [r1]
ldr r2, =GPIOA_IDR_PA4
and r0, r0, r2
lsr r0, #4
bl uart_write_char
bl delay
b main_loop
pull_up_pin_init:
ldr r1, =GPIOA_MODER
ldr r2, =GPIOA_MODER_PA4
ldr r0, [r1]
orr r0, r0, r2
str r0, [r1]
ldr r1, =GPIOA_OTYPER
ldr r2, =GPIOA_OTYPER_PA4
ldr r0, [r1]
orr r0, r0, r2
str r0, [r1]
ldr r1, =GPIOA_PUPDR
ldr r2, =GPIOA_PUPDR_PA4
ldr r0, [r1]
orr r0, r0, r2
str r0, [r1]
ldr r1, =GPIOA_SPEEDR
ldr r2, =GPIOA_SPEEDR_PA4
ldr r0, [r1]
orr r0, r0, r2
str r0, [r1]
bx lr