adding uartx01 example, uses UART0 instead of UART1

This commit is contained in:
David Welch
2012-07-26 16:19:17 -04:00
parent 3ac806e23c
commit 25d544e359
5 changed files with 307 additions and 0 deletions

71
uartx01/Makefile Normal file
View File

@@ -0,0 +1,71 @@
ARMGNU ?= arm-none-eabi
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
gcc : uartx01.hex uartx01.bin
all : gcc clang
clean :
rm -f *.o
rm -f *.bin
rm -f *.hex
rm -f *.elf
rm -f *.list
rm -f *.img
rm -f *.bc
rm -f *.clang.opt.s
vectors.o : vectors.s
$(ARMGNU)-as vectors.s -o vectors.o
uartx01.o : uartx01.c
$(ARMGNU)-gcc $(COPS) -c uartx01.c -o uartx01.o
uartx01.elf : memmap vectors.o uartx01.o
$(ARMGNU)-ld vectors.o uartx01.o -T memmap -o uartx01.elf
$(ARMGNU)-objdump -D uartx01.elf > uartx01.list
uartx01.bin : uartx01.elf
$(ARMGNU)-objcopy uartx01.elf -O binary uartx01.bin
uartx01.hex : uartx01.elf
$(ARMGNU)-objcopy uartx01.elf -O ihex uartx01.hex
LOPS = -Wall -m32 -emit-llvm
LLCOPS = -march=arm -mcpu=arm1176jzf-s
LLCOPS0 = -march=arm
LLCOPS1 = -march=arm -mcpu=arm1176jzf-s
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
OOPS = -std-compile-opts
clang : uartx01.clang.hex uartx01.clang.bin
uartx01.clang.bc : uartx01.c
clang $(LOPS) -c uartx01.c -o uartx01.clang.bc
uartx01.clang.opt.elf : memmap vectors.o uartx01.clang.bc
opt $(OOPS) uartx01.clang.bc -o uartx01.clang.opt.bc
llc $(LLCOPS) uartx01.clang.opt.bc -o uartx01.clang.opt.s
$(ARMGNU)-as uartx01.clang.opt.s -o uartx01.clang.opt.o
$(ARMGNU)-ld -o uartx01.clang.opt.elf -T memmap vectors.o uartx01.clang.opt.o
$(ARMGNU)-objdump -D uartx01.clang.opt.elf > uartx01.clang.opt.list
uartx01.clang.hex : uartx01.clang.opt.elf
$(ARMGNU)-objcopy uartx01.clang.opt.elf uartx01.clang.hex -O ihex
uartx01.clang.bin : uartx01.clang.opt.elf
$(ARMGNU)-objcopy uartx01.clang.opt.elf uartx01.clang.bin -O binary

19
uartx01/README Normal file
View File

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

12
uartx01/memmap Normal file
View File

@@ -0,0 +1,12 @@
MEMORY
{
ram : ORIGIN = 0x8000, LENGTH = 0x1000
}
SECTIONS
{
.text : { *(.text*) } > ram
.bss : { *(.bss*) } > ram
}

171
uartx01/uartx01.c Normal file
View File

@@ -0,0 +1,171 @@
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
extern void PUT32 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
extern void dummy ( unsigned int );
#define GPFSEL1 0x20200004
#define GPSET0 0x2020001C
#define GPCLR0 0x20200028
#define GPPUD 0x20200094
#define GPPUDCLK0 0x20200098
#define UART0_BASE 0x20201000
#define UART0_DR (UART0_BASE+0x00)
#define UART0_RSRECR (UART0_BASE+0x04)
#define UART0_FR (UART0_BASE+0x18)
#define UART0_ILPR (UART0_BASE+0x20)
#define UART0_IBRD (UART0_BASE+0x24)
#define UART0_FBRD (UART0_BASE+0x28)
#define UART0_LCRH (UART0_BASE+0x2C)
#define UART0_CR (UART0_BASE+0x30)
#define UART0_IFLS (UART0_BASE+0x34)
#define UART0_IMSC (UART0_BASE+0x38)
#define UART0_RIS (UART0_BASE+0x3C)
#define UART0_MIS (UART0_BASE+0x40)
#define UART0_ICR (UART0_BASE+0x44)
#define UART0_DMACR (UART0_BASE+0x48)
#define UART0_ITCR (UART0_BASE+0x80)
#define UART0_ITIP (UART0_BASE+0x84)
#define UART0_ITOP (UART0_BASE+0x88)
#define UART0_TDR (UART0_BASE+0x8C)
//GPIO14 TXD0 and TXD1
//GPIO15 RXD0 and RXD1
//alt function 5 for uart1
//alt function 0 for uart0
//(3000000 / (16 * 115200) = 1.627
//(0.627*64)+0.5 = 40
//int 1 frac 40
//------------------------------------------------------------------------
void uart_putc ( unsigned int c )
{
while(1)
{
if((GET32(UART0_FR)&0x20)==0) break;
}
PUT32(UART0_DR,c);
}
//------------------------------------------------------------------------
unsigned int uart_getc ( void )
{
while(1)
{
if((GET32(UART0_FR)&0x10)==0) break;
}
return(GET32(UART0_DR));
}
//------------------------------------------------------------------------
void uart_init ( void )
{
unsigned int ra;
PUT32(UART0_CR,0);
ra=GET32(GPFSEL1);
ra&=~(7<<12); //gpio14
ra|=4<<12; //alt0
ra&=~(7<<15); //gpio15
ra|=4<<15; //alt0
PUT32(GPFSEL1,ra);
PUT32(GPPUD,0);
for(ra=0;ra<150;ra++) dummy(ra);
PUT32(GPPUDCLK0,(1<<14)|(1<<15));
for(ra=0;ra<150;ra++) dummy(ra);
PUT32(GPPUDCLK0,0);
PUT32(UART0_ICR,0x7FF);
PUT32(UART0_IBRD,1);
PUT32(UART0_FBRD,40);
PUT32(UART0_LCRH,0x70);
PUT32(UART0_CR,0x301);
}
//------------------------------------------------------------------------
void hexstrings ( unsigned int d )
{
//unsigned int ra;
unsigned int rb;
unsigned int rc;
rb=32;
while(1)
{
rb-=4;
rc=(d>>rb)&0xF;
if(rc>9) rc+=0x37; else rc+=0x30;
uart_putc(rc);
if(rb==0) break;
}
uart_putc(0x20);
}
//------------------------------------------------------------------------
void hexstring ( unsigned int d )
{
hexstrings(d);
uart_putc(0x0D);
uart_putc(0x0A);
}
//------------------------------------------------------------------------
int notmain ( unsigned int earlypc )
{
unsigned int ra;
uart_init();
hexstring(0x12345678);
hexstring(earlypc);
for(ra=0;ra<30000;ra++)
{
uart_putc(0x30|(ra&7));
}
for(ra=0;ra<100;ra++) uart_putc(0x55);
//probably a better way to flush the rx fifo. depending on if and
//which bootloader you used you might have some stuff show up in the
//rx fifo.
while(1)
{
if(GET32(UART0_FR)&0x10) break;
GET32(UART0_DR);
}
while(1)
{
ra=uart_getc();
if(ra==0x0D) uart_putc(0x0A);
uart_putc(ra);
}
return(0);
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//
// Copyright (c) 2012 David Welch dwelch@dwelch.com
//
// 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:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// 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.
//
//-------------------------------------------------------------------------

34
uartx01/vectors.s Normal file
View File

@@ -0,0 +1,34 @@
.globl _start
_start:
mov sp,#0x8000
mov r0,pc
bl notmain
hang: b hang
.globl PUT32
PUT32:
str r1,[r0]
bx lr
.globl GET32
GET32:
ldr r0,[r0]
bx lr
.globl dummy
dummy:
bx lr
;@-------------------------------------------------------------------------
;@
;@ Copyright (c) 2012 David Welch dwelch@dwelch.com
;@
;@ 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:
;@
;@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
;@
;@ 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.
;@
;@-------------------------------------------------------------------------