adding uart03. same as uart02 except mostly thumb instead of ARM
This commit is contained in:
32
uart03/Makefile
Normal file
32
uart03/Makefile
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
ARMGNU ?= arm-none-eabi
|
||||
|
||||
COPS = -mthumb -Wall -O2 -nostdlib -nostartfiles -ffreestanding
|
||||
|
||||
all : uart03.hex
|
||||
|
||||
clean :
|
||||
rm -f *.o
|
||||
rm -f *.bin
|
||||
rm -f *.hex
|
||||
rm -f *.elf
|
||||
rm -f *.list
|
||||
rm -f *.img
|
||||
|
||||
novectors.o : novectors.s
|
||||
$(ARMGNU)-as novectors.s -o novectors.o
|
||||
|
||||
uart03.o : uart03.c
|
||||
$(ARMGNU)-gcc $(COPS) -c uart03.c -o uart03.o
|
||||
|
||||
uart03.hex : memmap novectors.o uart03.o
|
||||
$(ARMGNU)-ld novectors.o uart03.o -T memmap -o uart03.elf
|
||||
$(ARMGNU)-objdump -D uart03.elf > uart03.list
|
||||
$(ARMGNU)-objcopy uart03.elf -O binary uart03.bin
|
||||
$(ARMGNU)-objcopy uart03.elf -O ihex uart03.hex
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
30
uart03/README
Normal file
30
uart03/README
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
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 uart02, the difference is that this is primarily thumb code
|
||||
instead of ARM. ARM in this case meaning the traditional 32 bit
|
||||
instruction set and thumb meaning the traditional 16 bit instruction
|
||||
subset. Thumb2 has confused/blurred those definitions though.
|
||||
(thumb2 is a mostly 32 bit extension to the thumb instruction set using
|
||||
formerly undefined instructions to create variable word length instructions).
|
||||
|
||||
You have two choices you can use my bootloader with the uart03.hex file
|
||||
or copy the uart02.bin file to (overwrite the) kernel.img on your raspi
|
||||
sd card. (might want to back up that file if you want to go back to
|
||||
running linux with it later, or download a replacement from the net).
|
||||
|
||||
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
|
||||
echos back.
|
||||
12
uart03/memmap
Normal file
12
uart03/memmap
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
MEMORY
|
||||
{
|
||||
ram : ORIGIN = 0x00000000, LENGTH = 0x1000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : { *(.text*) } > ram
|
||||
.bss : { *(.bss*) } > ram
|
||||
}
|
||||
|
||||
36
uart03/novectors.s
Normal file
36
uart03/novectors.s
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
.globl _start
|
||||
_start:
|
||||
b reset
|
||||
reset:
|
||||
ldr sp,stack_start
|
||||
ldr r0,thumb_start_add
|
||||
bx r0
|
||||
|
||||
stack_start: .word 0x1000
|
||||
thumb_start_add: .word thumb_start
|
||||
.word 0
|
||||
.word 0
|
||||
|
||||
.thumb
|
||||
.thumb_func
|
||||
thumb_start:
|
||||
bl notmain
|
||||
hang: b hang
|
||||
|
||||
.thumb_func
|
||||
.globl PUT32
|
||||
PUT32:
|
||||
str r1,[r0]
|
||||
bx lr
|
||||
|
||||
.thumb_func
|
||||
.globl GET32
|
||||
GET32:
|
||||
ldr r0,[r0]
|
||||
bx lr
|
||||
|
||||
.thumb_func
|
||||
.globl dummy
|
||||
dummy:
|
||||
bx lr
|
||||
116
uart03/uart03.c
Normal file
116
uart03/uart03.c
Normal 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);
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user