Skip to content

Commit 25d544e

Browse files
committed
adding uartx01 example, uses UART0 instead of UART1
1 parent 3ac806e commit 25d544e

File tree

5 files changed

+307
-0
lines changed

5 files changed

+307
-0
lines changed

uartx01/Makefile

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
ARMGNU ?= arm-none-eabi
3+
4+
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
5+
6+
gcc : uartx01.hex uartx01.bin
7+
8+
all : gcc clang
9+
10+
clean :
11+
rm -f *.o
12+
rm -f *.bin
13+
rm -f *.hex
14+
rm -f *.elf
15+
rm -f *.list
16+
rm -f *.img
17+
rm -f *.bc
18+
rm -f *.clang.opt.s
19+
20+
vectors.o : vectors.s
21+
$(ARMGNU)-as vectors.s -o vectors.o
22+
23+
uartx01.o : uartx01.c
24+
$(ARMGNU)-gcc $(COPS) -c uartx01.c -o uartx01.o
25+
26+
uartx01.elf : memmap vectors.o uartx01.o
27+
$(ARMGNU)-ld vectors.o uartx01.o -T memmap -o uartx01.elf
28+
$(ARMGNU)-objdump -D uartx01.elf > uartx01.list
29+
30+
uartx01.bin : uartx01.elf
31+
$(ARMGNU)-objcopy uartx01.elf -O binary uartx01.bin
32+
33+
uartx01.hex : uartx01.elf
34+
$(ARMGNU)-objcopy uartx01.elf -O ihex uartx01.hex
35+
36+
37+
38+
39+
40+
41+
42+
LOPS = -Wall -m32 -emit-llvm
43+
LLCOPS = -march=arm -mcpu=arm1176jzf-s
44+
LLCOPS0 = -march=arm
45+
LLCOPS1 = -march=arm -mcpu=arm1176jzf-s
46+
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
47+
OOPS = -std-compile-opts
48+
49+
clang : uartx01.clang.hex uartx01.clang.bin
50+
51+
52+
uartx01.clang.bc : uartx01.c
53+
clang $(LOPS) -c uartx01.c -o uartx01.clang.bc
54+
55+
uartx01.clang.opt.elf : memmap vectors.o uartx01.clang.bc
56+
opt $(OOPS) uartx01.clang.bc -o uartx01.clang.opt.bc
57+
llc $(LLCOPS) uartx01.clang.opt.bc -o uartx01.clang.opt.s
58+
$(ARMGNU)-as uartx01.clang.opt.s -o uartx01.clang.opt.o
59+
$(ARMGNU)-ld -o uartx01.clang.opt.elf -T memmap vectors.o uartx01.clang.opt.o
60+
$(ARMGNU)-objdump -D uartx01.clang.opt.elf > uartx01.clang.opt.list
61+
62+
uartx01.clang.hex : uartx01.clang.opt.elf
63+
$(ARMGNU)-objcopy uartx01.clang.opt.elf uartx01.clang.hex -O ihex
64+
65+
uartx01.clang.bin : uartx01.clang.opt.elf
66+
$(ARMGNU)-objcopy uartx01.clang.opt.elf uartx01.clang.bin -O binary
67+
68+
69+
70+
71+

uartx01/README

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
See the top level README for information on where to find the
3+
schematic and programmers reference manual for the ARM processor
4+
on the raspberry pi. Also find information on how to load and run
5+
these programs.
6+
7+
This is similar to the uart## examples except it uses the full blown
8+
uart not the mini uart. UART0 instead of UART1. Same gpio pins are
9+
used, different alternate gpio functions. uart clock is 3000000HZ.
10+
11+
It spits out a bunch of stuff then goes into an echo loop.
12+
13+
See the top level README file for information on how to connect the
14+
raspi uart to your host computer.
15+
16+
Using a dumb terminal (minicom) 115200 board No parity 8 bits 1 stop
17+
bit, no flow control (might have to exit minicom and start again for
18+
the flow control setting to take). What you type on the dumb terminal
19+
comes back.

uartx01/memmap

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
MEMORY
3+
{
4+
ram : ORIGIN = 0x8000, LENGTH = 0x1000
5+
}
6+
7+
SECTIONS
8+
{
9+
.text : { *(.text*) } > ram
10+
.bss : { *(.bss*) } > ram
11+
}
12+

uartx01/uartx01.c

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
2+
//-------------------------------------------------------------------------
3+
//-------------------------------------------------------------------------
4+
5+
extern void PUT32 ( unsigned int, unsigned int );
6+
extern unsigned int GET32 ( unsigned int );
7+
extern void dummy ( unsigned int );
8+
9+
#define GPFSEL1 0x20200004
10+
#define GPSET0 0x2020001C
11+
#define GPCLR0 0x20200028
12+
#define GPPUD 0x20200094
13+
#define GPPUDCLK0 0x20200098
14+
15+
16+
17+
#define UART0_BASE 0x20201000
18+
#define UART0_DR (UART0_BASE+0x00)
19+
#define UART0_RSRECR (UART0_BASE+0x04)
20+
#define UART0_FR (UART0_BASE+0x18)
21+
#define UART0_ILPR (UART0_BASE+0x20)
22+
#define UART0_IBRD (UART0_BASE+0x24)
23+
#define UART0_FBRD (UART0_BASE+0x28)
24+
#define UART0_LCRH (UART0_BASE+0x2C)
25+
#define UART0_CR (UART0_BASE+0x30)
26+
#define UART0_IFLS (UART0_BASE+0x34)
27+
#define UART0_IMSC (UART0_BASE+0x38)
28+
#define UART0_RIS (UART0_BASE+0x3C)
29+
#define UART0_MIS (UART0_BASE+0x40)
30+
#define UART0_ICR (UART0_BASE+0x44)
31+
#define UART0_DMACR (UART0_BASE+0x48)
32+
#define UART0_ITCR (UART0_BASE+0x80)
33+
#define UART0_ITIP (UART0_BASE+0x84)
34+
#define UART0_ITOP (UART0_BASE+0x88)
35+
#define UART0_TDR (UART0_BASE+0x8C)
36+
37+
38+
39+
40+
41+
42+
43+
44+
//GPIO14 TXD0 and TXD1
45+
//GPIO15 RXD0 and RXD1
46+
//alt function 5 for uart1
47+
//alt function 0 for uart0
48+
49+
//(3000000 / (16 * 115200) = 1.627
50+
//(0.627*64)+0.5 = 40
51+
//int 1 frac 40
52+
53+
//------------------------------------------------------------------------
54+
void uart_putc ( unsigned int c )
55+
{
56+
while(1)
57+
{
58+
if((GET32(UART0_FR)&0x20)==0) break;
59+
}
60+
PUT32(UART0_DR,c);
61+
}
62+
//------------------------------------------------------------------------
63+
unsigned int uart_getc ( void )
64+
{
65+
while(1)
66+
{
67+
if((GET32(UART0_FR)&0x10)==0) break;
68+
}
69+
return(GET32(UART0_DR));
70+
}
71+
//------------------------------------------------------------------------
72+
void uart_init ( void )
73+
{
74+
unsigned int ra;
75+
76+
PUT32(UART0_CR,0);
77+
78+
ra=GET32(GPFSEL1);
79+
ra&=~(7<<12); //gpio14
80+
ra|=4<<12; //alt0
81+
ra&=~(7<<15); //gpio15
82+
ra|=4<<15; //alt0
83+
PUT32(GPFSEL1,ra);
84+
85+
PUT32(GPPUD,0);
86+
for(ra=0;ra<150;ra++) dummy(ra);
87+
PUT32(GPPUDCLK0,(1<<14)|(1<<15));
88+
for(ra=0;ra<150;ra++) dummy(ra);
89+
PUT32(GPPUDCLK0,0);
90+
91+
PUT32(UART0_ICR,0x7FF);
92+
PUT32(UART0_IBRD,1);
93+
PUT32(UART0_FBRD,40);
94+
PUT32(UART0_LCRH,0x70);
95+
PUT32(UART0_CR,0x301);
96+
}
97+
//------------------------------------------------------------------------
98+
void hexstrings ( unsigned int d )
99+
{
100+
//unsigned int ra;
101+
unsigned int rb;
102+
unsigned int rc;
103+
104+
rb=32;
105+
while(1)
106+
{
107+
rb-=4;
108+
rc=(d>>rb)&0xF;
109+
if(rc>9) rc+=0x37; else rc+=0x30;
110+
uart_putc(rc);
111+
if(rb==0) break;
112+
}
113+
uart_putc(0x20);
114+
}
115+
//------------------------------------------------------------------------
116+
void hexstring ( unsigned int d )
117+
{
118+
hexstrings(d);
119+
uart_putc(0x0D);
120+
uart_putc(0x0A);
121+
}
122+
//------------------------------------------------------------------------
123+
int notmain ( unsigned int earlypc )
124+
{
125+
unsigned int ra;
126+
127+
uart_init();
128+
hexstring(0x12345678);
129+
hexstring(earlypc);
130+
131+
for(ra=0;ra<30000;ra++)
132+
{
133+
uart_putc(0x30|(ra&7));
134+
}
135+
136+
for(ra=0;ra<100;ra++) uart_putc(0x55);
137+
138+
//probably a better way to flush the rx fifo. depending on if and
139+
//which bootloader you used you might have some stuff show up in the
140+
//rx fifo.
141+
while(1)
142+
{
143+
if(GET32(UART0_FR)&0x10) break;
144+
GET32(UART0_DR);
145+
}
146+
147+
while(1)
148+
{
149+
ra=uart_getc();
150+
if(ra==0x0D) uart_putc(0x0A);
151+
uart_putc(ra);
152+
}
153+
154+
155+
return(0);
156+
}
157+
//-------------------------------------------------------------------------
158+
//-------------------------------------------------------------------------
159+
160+
161+
//-------------------------------------------------------------------------
162+
//
163+
// Copyright (c) 2012 David Welch [email protected]
164+
//
165+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
166+
//
167+
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
168+
//
169+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
170+
//
171+
//-------------------------------------------------------------------------

uartx01/vectors.s

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
.globl _start
3+
_start:
4+
mov sp,#0x8000
5+
mov r0,pc
6+
bl notmain
7+
hang: b hang
8+
9+
.globl PUT32
10+
PUT32:
11+
str r1,[r0]
12+
bx lr
13+
14+
.globl GET32
15+
GET32:
16+
ldr r0,[r0]
17+
bx lr
18+
19+
.globl dummy
20+
dummy:
21+
bx lr
22+
23+
24+
;@-------------------------------------------------------------------------
25+
;@
26+
;@ Copyright (c) 2012 David Welch [email protected]
27+
;@
28+
;@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
29+
;@
30+
;@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
31+
;@
32+
;@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33+
;@
34+
;@-------------------------------------------------------------------------

0 commit comments

Comments
 (0)