-
Notifications
You must be signed in to change notification settings - Fork 2
/
uart.S
65 lines (53 loc) · 1.26 KB
/
uart.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
;;;
;;; UART
;;;
.include "mmio.inc"
.include "uart.inc"
.text
;;; r0 ... base rate (VPU)
;;;
.global uart_init
uart_init:
stm lr,(--sp)
mov r1, TARGET_BAUD_RATE*8
div.uu r3, r0, r1
;; Configure TX and RX GPIO pins for Mini Uart function.
mov r1, GPIO_BASE
ld r0, (r1 + GPIO_GPFSEL1)
and r0, ~(7<<12) & ~(7<<15)
or r0, (2<<12) | (2<<15)
st r0, (r1 + GPIO_GPFSEL1)
mov r0, 0
st r0, (r1 + GPIO_GPPUD)
mov r0,150
bl delay
mov r0, (1<<14) | (1<<15)
st r0, (r1 + GPIO_GPPUDCLK0)
mov r0,150
bl delay
mov r0, 0
st r0, (r1 + GPIO_GPPUDCLK0)
;; Set up serial port
mov r2, 1
mov r1, UART1_BASE
st r2, (r1 + UART_AUX_ENABLES)
mov r2, 0x43
st r0, (r1 + UART_AUX_MU_IER_REG)
st r0, (r1 + UART_AUX_MU_CNTL_REG)
st r2, (r1 + UART_AUX_MU_LCR_REG)
mov r2, 0xc6
st r0, (r1 + UART_AUX_MU_MCR_REG)
st r0, (r1 + UART_AUX_MU_IER_REG)
st r2, (r1 + UART_AUX_MU_IIR_REG)
add r0, r3, -1
mov r2, 3
st r0, (r1 + UART_AUX_MU_BAUD_REG)
st r2, (r1 + UART_AUX_MU_CNTL_REG)
;; keep TX low for 16 bits before returning to the caller,
;; so our serial connection peer can detect a break condition
;; and recover the start of the next frame if a transmission
;; was interrupted
shl r0, r3, 4 + 3
bl delay
st r2, (r1 + UART_AUX_MU_LCR_REG)
ldm pc,(sp++)