adding uart02 example, this one receives characters and echos them back out.

This commit is contained in:
David Welch
2012-05-27 00:48:42 -04:00
parent 18d0f8feac
commit d69e19201f
5 changed files with 203 additions and 0 deletions

30
uart02/Makefile Normal file
View File

@@ -0,0 +1,30 @@
ARMGNU ?= arm-none-eabi
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
all : kernel.img
clean :
rm -f *.o
rm -f *.bin
rm -f *.elf
rm -f *.list
rm -f *.img
novectors.o : novectors.s
$(ARMGNU)-as novectors.s -o novectors.o
uart02.o : uart02.c
$(ARMGNU)-gcc $(COPS) -c uart02.c -o uart02.o
kernel.img : memmap novectors.o uart02.o
$(ARMGNU)-ld novectors.o uart02.o -T memmap -o uart02.elf
$(ARMGNU)-objdump -D uart02.elf > uart02.list
$(ARMGNU)-objcopy uart02.elf -O binary kernel.img

22
uart02/README Normal file
View File

@@ -0,0 +1,22 @@
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.
Based on uart01, this one enables the uart rxd1 receiver (gpio15).
It starts by printing 12345678 then whatever you type on the terminal
is echoed back.
You will need something like this
http://www.sparkfun.com/products/718
to connect to the uart pins on the raspi. Do not connect the raspberry
pi pins directly to a com port on a computer you will fry the board.
The above board happens to have pins in the same order as the raspberry
pi. On connector P1 on the raspberry pi connect pin 6 to ground on the
usb to serial board. Pin 8 on P1 to RX on the usb to serial board, and
pin 10 on P1 to TX on the usb to serial board.
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
uart02/memmap Normal file
View File

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

23
uart02/novectors.s Normal file
View File

@@ -0,0 +1,23 @@
.globl _start
_start:
b reset
reset:
mov sp,#0x1000
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

116
uart02/uart02.c Normal file
View File

@@ -0,0 +1,116 @@
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
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 AUX_ENABLES 0x20215004
#define AUX_MU_IO_REG 0x20215040
#define AUX_MU_IER_REG 0x20215044
#define AUX_MU_IIR_REG 0x20215048
#define AUX_MU_LCR_REG 0x2021504C
#define AUX_MU_MCR_REG 0x20215050
#define AUX_MU_LSR_REG 0x20215054
#define AUX_MU_MSR_REG 0x20215058
#define AUX_MU_SCRATCH 0x2021505C
#define AUX_MU_CNTL_REG 0x20215060
#define AUX_MU_STAT_REG 0x20215064
#define AUX_MU_BAUD_REG 0x20215068
//GPIO14 TXD0 and TXD1
//GPIO15 RXD0 and RXD1
//alt function 5 for uart1
//alt function 0 for uart0
//((250,000,000/115200)/8)-1 = 270
//------------------------------------------------------------------------
void uart_putc ( unsigned int c )
{
while(1)
{
if(GET32(AUX_MU_LSR_REG)&0x20) break;
}
PUT32(AUX_MU_IO_REG,c);
}
//------------------------------------------------------------------------
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 ( void )
{
unsigned int ra;
PUT32(AUX_ENABLES,1);
PUT32(AUX_MU_IER_REG,0);
PUT32(AUX_MU_CNTL_REG,0);
PUT32(AUX_MU_LCR_REG,3);
PUT32(AUX_MU_MCR_REG,0);
PUT32(AUX_MU_IER_REG,0);
PUT32(AUX_MU_IIR_REG,0xC6);
PUT32(AUX_MU_BAUD_REG,270);
ra=GET32(GPFSEL1);
ra&=~(7<<12); //gpio14
ra|=2<<12; //alt5
ra&=~(7<<15); //gpio15
ra|=2<<15; //alt5
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(AUX_MU_CNTL_REG,3);
hexstring(0x12345678);
while(1)
{
while(1)
{
if(GET32(AUX_MU_LSR_REG)&0x01) break;
}
ra=GET32(AUX_MU_IO_REG);
//while(1)
//{
//if(GET32(AUX_MU_LSR_REG)&0x20) break;
//}
PUT32(AUX_MU_IO_REG,ra);
}
return(0);
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------