用freepascal写了个at91的程序,贴出源代码来供大家参考。

这个程序在skyeye里测试通过,UART输出正常,lcd窗口可以显示出来,但是显示颜色还不行。

程序文件tled7.lpr:
{for at91sam7x256
$fffd001c is at91 uart0 address}

program tled7;

//uses at91sam7x256;

const
BOARD_LBEN = (1 shl 12);
SPI0CS1 = (1 shl 13);
SPI0CS2 = (1 shl 14);
SPI0CS3 = (1 shl 15);
MOSI0 = (1 shl 16);
MISO0 = (1 shl 17);
SCLK0 = (1 shl 18);
AT91C_SPI_PCS = ($F shl 16);
AT91C_SPI_SPIEN = ($1 shl 0);
AT91C_SPI_TXEMPTY = ($1 shl 9);
AT91C_SPI_TDRE = ($1 shl 1);
AT91C_SPI_MSTR = ($1 shl 0); // (SPI) Master/Slave Mode
AT91C_SPI_MODFDIS = ($1 shl 4); // (SPI) Mode Fault Detection
// -------- PDC_PTCR : (PDC Offset: 0x20) PDC Transfer Control Register --------
AT91C_PDC_RXTEN = ($1 shl 0); // (PDC) Receiver Transfer Enable
AT91C_PDC_RXTDIS = ($1 shl 1); // (PDC) Receiver Transfer Disable
AT91C_PDC_TXTEN = ($1 shl 8); // (PDC) Transmitter Transfer Enable
AT91C_PDC_TXTDIS = ($1 shl 9); // (PDC) Transmitter Transfer Disable

type
AT91PS_SPI = record
CR, // Control Register
MR, // Mode Register
RDR, // Receive Data Register
TDR, // Transmit Data Register
SR, // Status Register
IER, // Interrupt Enable Register
IDR, // Interrupt Disable Register
IMR: dword; // Interrupt Mask Register
Reserved0: array[0..3] of dword; //
CSR: array[0..3] of dword; // Chip Select Register
Reserved1: array[0..47] of dword; //
RPR, // Receive Pointer Register
RCR, // Receive Counter Register
TPR, // Transmit Pointer Register
TCR, // Transmit Counter Register
RNPR, // Receive Next Pointer Register
RNCR, // Receive Next Counter Register
TNPR, // Transmit Next Pointer Register
TNCR, // Transmit Next Counter Register
PTCR, // PDC Transfer Control Register
PTSR: dword; // PDC Transfer Status Register
end;

AT91PS_PDC = record
RPR, // Receive Pointer Register
RCR, // Receive Counter Register
TPR, // Transmit Pointer Register
TCR, // Transmit Counter Register
RNPR, // Receive Next Pointer Register
RNCR, // Receive Next Counter Register
TNPR, // Transmit Next Pointer Register
TNCR, // Transmit Next Counter Register
PTCR, // PDC Transfer Control Register
PTSR: dword; // PDC Transfer Status Register
end;

var
// vidmem: PChar = PChar($E000C01C);
// i: Integer;
UART0_SCR: DWord absolute $fffd001c;
pSPI0: AT91PS_SPI absolute $fffe0000;
pPDC: AT91PS_PDC absolute $fffe0100;
AT91PS_SPI_CSR0: DWord absolute $fffe0030;

SYSCON1: DWord absolute $ffc00100;
LCDCON: DWord absolute $ffc002c0; //* LCD Control register ---------------------------- */
PALLSW: DWord absolute $ffc00540; //* Least-significant 32-bit word of LCD Palette reg. */
PALMSW: DWord absolute $ffc00580; //* Most-significant 32-bit word of LCD Palette reg. */
VBUFSIZ: DWord = $00001fff; //* Video buffer size (bits/128-1) */
LINELEN: DWord = $0007e000; //* Line length (pix/16-1) */
LINELEN_SHIFT: DWord = 13;
PIXPSC: DWord = $01f80000; //* Pixel prescale (526628/pixels-1) */
PIXPSC_SHIFT: DWord = 19;
ACPSC: DWord = $3e000000; //* AC prescale */
ACPSC_SHIFT: DWord = 25;
GSEN: DWord = $40000000; //* Grayscale enable (0: monochrome) */
GSMD: DWord = $80000000; //* Grayscale mode (0: 2 bit, 1: 4 bit) */
FBADDR: DWord absolute $ffc01000;
FBADDRP: DWord absolute $c0000000;
LCDEN: DWord = $00001000; //* LCD enable */

TSCON: DWord absolute $ff00b000;

procedure LCD_Delayus(ius: cardinal);
var
i: integer;
begin
while (ius>0) do
begin
for i:=0 to 6 do ;
dec(ius);
end;
end;

procedure LCD_Delayms(ims: cardinal);
begin
while (ims>0) do
begin
LCD_Delayus(1000);
dec(ims);
end;
end;

procedure LCD_ChipDisable;
begin
AT91C_PMC_PCER:= 1 shl AT91C_PIOB_IDR;

AT91C_PIOB_SODR:= $ff;

AT91C_PIOB_PER:= $ff;
AT91C_PIOB_OER:= $ff;

LCD_Delayus(10);
end;

procedure SPI_Write(spi: AT91PS_SPI; npcs: cardinal; data: byte);
begin
// Discard contents of RDR register
//volatile unsigned int discard = spi->SPI_RDR;

// Send data
while ((spi.SR and AT91C_SPI_TXEMPTY) = 0) do ;
spi.TDR:= data or ((not (1 shl npcs) and $F) shl 16);
while ((spi.SR and AT91C_SPI_TDRE) = 0) do ;
end;

procedure LCD_Reset;
var
linelin: DWord;
vbufsize: DWord;
begin
linelin := 320 * 3 div 16 - 1;
vbufsize := 240 * 320 * 3 * 4 div 128 - 1;

AT91C_US0_RPR:= AT91C_US0_RPR and (not LCDEN); //关闭lcd

PALLSW:= $76543210;
PALMSW:= $fedcba98;
FBADDR:= $0000000c;

//LCDCON:= (( LINELEN shl LINELEN_SHIFT) + VBUFSIZ);
//LCDCON:= ( linelin shl LINELEN_SHIFT) + vbufsize;
LCDCON:= $e60f7c1f; //1/4vga

AT91C_US0_RPR:= AT91C_US0_RPR or LCDEN; //打开lcd

//LCD_Delayms(15);
end;

//绘制屏幕背景颜色,颜色为c
procedure Brush_Background(c: word);
var
i: cardinal;
p: ^byte;
pi: integer;
buffer: array[0..2] of byte;
begin
pi:= integer(@FBADDRP);

buffer[0]:= c and $ff;
buffer[1]:= ((c and $f00) shr 8) + ((c and $0f) shl 4);
buffer[2]:= c shr 4;

//for i:=0 to 320 * 240 * 12 div 8-1 do
for i:=0 to 64 * 48 * 12 div 8-1 do
begin
p:= pointer(pi);
p^:= buffer[i mod 3];

inc(pi);
end;
end;

var
i: integer;
begin
UART0_SCR:= $44;
UART0_SCR:= $45;

LCD_Reset;
Brush_Background($f000);

{for i:= 0 to slen do
begin
SPI_Write(pSPI0, 3, sdata[i]);
end;}
//SPI_Write(pSPI0, 3, $46);

UART0_SCR:= $48;
UART0_SCR:= $49;
end.

编译文件build-tled7.bat,编译环境fpc2.7:
@echo off

set path=%path%;E:\Project\FPC\arm-eabi\bin

C:\codetyphon\fpc\bin\i386-win32\ppcrossarm @armembedded27.cfg -Parm  -Tembedded -Cparmv4t -Wpat91sam7x256 -XParm-none-eabi-   tled7.lpr

rem C:\codetyphon\fpc\bin\i386-win32\arm-embedded-objcopy -O binary tled7.elf tled7.bin

rem C:\codetyphon\fpc\bin\i386-win32\readelf -a tled7.elf > tled7.elf.txt

echo step 2----------------
rem E:\Project\FPC\arm-eabi\bin\arm-none-eabi-ld --emit-relocs --strip-all -N -p -X -Tskyeye.ld -o tled7arm at91sam7x256.o system.o tled7.o
rem C:\codetyphon\fpc\bin\i386-win32\readelf -a tled7arm > tled7arm.txt

if not errorlevel 1 goto end

pause

:end
@echo on

skyeye.conf配置文件,skyeye1.3.5r1:
#skyeye config file sample
arch:arm
cpu: arm7tdmi

#mach: lpc
mach: at91

mem_bank: map=M, type=RW, addr=0x00000000, size=0x00004000
mem_bank: map=M, type=RW, addr=0x01000000, size=0x00400000
mem_bank: map=M, type=R,  addr=0x01400000, size=0x00400000
mem_bank: map=M, type=RW, addr=0x02000000, size=0x00400000
mem_bank: map=M, type=RW, addr=0x02400000, size=0x00008000
mem_bank: map=M, type=RW, addr=0x04000000, size=0x00400000
mem_bank: map=M, type=RW, addr=0xc0000000, size=0x00100000
#mem_bank: map=I, type=RW, addr=0xe0000000, size=0x20000000
mem_bank: map=I, type=RW, addr=0xf0000000, size=0x10000000

#mem_bank: map=M, type=RW, addr=0x10000000, size=0x00000800, file=./loader.bin,boot=yes

#uart:mod=term
uart:mod=stdio
#uart: fd_in=/dev/ttyS0, fd_out=/dev/ttyS0
#则你可以使用minicon来监听COM1口来进行数据交换
uart_16550:base=0xd1000000, length=0x100, irq=0x20
#net: state = on, mac=0:4:3:2:1:f, ethmod=tuntap, hostip=10.0.0.1

#lcd:state=on
#lcd: type=at91, mod=gtk
lcd: type=ep7312,mod=gtk

#dbct: state=on

#instr_log: logon=0, logfile=./sk1.log, start=0, end=200000

 

elf,bin,hex问件:
这是我编译好的执行文件,大家可以测试下。
http://antoo-upload.stor.sinaapp.com/2013/0305/20130305022804975.rar