先把cf
card format
去這邊下載mkdosfs
utility
http://www-inst.eecs.berkeley.edu/~cs150/Documents/mkdosfs.zip
然後由cmd進入解壓縮後得資料夾
下command
> mkdosfs –s 64
–F 16 –R 1 f:
注意f是讀卡機的槽
然後把從xilinx下載的rdf0022解壓縮後放入cf卡,注意放的位置要在最上層,外面部可以再用資料夾覆蓋,不然板子會抓不到xilinx.sys,會一直亮error的燈
把cf卡插回板子以後,會看到led燈輕微閃爍,按sw3之後會在tera
term上出現可以測試的項目,表示cf卡已經成功可以使用拉!
在ISE建立新的專案,新增microblaze,在裡面先把local
memory調大,必須加入DDR3,UART,SYSACE,TIMER,其中SYSACE與TIMER需加入interrupt
在address中,再把memory調大,不然之後產生linked
script會有空間不夠的error
在ISE產生microblaze的
top layer, ddr3的port不用拉出去top繞線,ucf直接把xps中的拷過來,產生bit
file
在資料夾中建立workspace目錄
在xps中export
and lunch SDK,指向workspace路徑
File->New->Application Project,
注意OS
Platform 選xilkernal,接下來選empty
application
在左邊的目錄欄中按bsp目錄下的system.mss,右邊會出現modify
this BSP setting
然後勾選xilfatfs
這個library
之後在點選左上overview下面的xilfatfs,把CONFIG_WRITE與CONFIG_DIR_SUPPORT改成true
在project中的src按右鍵新增c
file,記得檔名後面要加.c,不然它會變成記事本
= =
把在reference
link中,大好心人寫的main貼近來,但是記得要把using
namespace std拿走
這個檔是在讀放在cf卡中的xilinx文件rdf0022.zip中的test資料夾下的test.txt
#include "sysace_stdio.h" #include "xparameters.h" #include "xstatus.h" #include "xsysace.h" #include "xintc.h" int main() { char* path = "a:\\test"; unsigned char mybuf[100]; const char fname [] = "a:\\test\\test.txt"; if( sysace_chdir (path)==-1 ) { xil_printf("ERROR: Can't change directory to %s.\n\r", path); } path = "a:\\internet"; if( sysace_chdir (path)==-1 ) { xil_printf("ERROR: Can't change directory to %s.\n\r", path); } SYSACE_FILE *infile; infile = sysace_fopen(fname,"r"); sysace_fread(mybuf, 1, 500, infile); xil_printf((char*)mybuf); sysace_fclose(infile); return 0; } |
compile過後,按project的右鍵,generate
linker script,改變紅色圈的設定,size值要超過100k
,所以打入120000,它就會自己換算變值
generate完以後把tera
term打開,然後programm
FPGA
就可以看到在tera
term
上面印出在test.txt中的資訊,因為在cf卡中沒有internet這個資料夾,所以理所當然會是error,至於後面那個亂碼是啥我也不知道
= =
在另外測試一下建資料夾,先寫在讀的功能,注意如果資料夾已經建立過了,就會出現error訊息
#include
"sysace_stdio.h"
#include
"xparameters.h"
#include
"xstatus.h"
#include
"xsysace.h"
#include
"xintc.h"
void
make_folder();
void
write_file();
void
read_file();
int
main()
{
make_folder();
write_file();
read_file();
return
0;
}
void
make_folder()
{
char
*path;
path
= "a:\\result";
if(sysace_mkdir(path)==
-1)
{
xil_printf("Fail
to make new folder",path);
}
}
void
write_file()
{
unsigned
char
write_data[10]= "1a2b3c4d5e";
const
char
fname [] = "a:\\result\\test.txt";
SYSACE_FILE
*infile;
infile
= sysace_fopen(fname,"w");
sysace_fwrite(write_data,1,10,infile);
sysace_fclose(infile);
}
void
read_file()
{
unsigned
char
read_data[10];
const
char
fname [] = "a:\\result\\test.txt";
SYSACE_FILE
*infile;
infile
= sysace_fopen(fname,"r");
sysace_fread(read_data,1,10,infile);
xil_printf((char*)read_data);
sysace_fclose(infile);
}
|
做了幾次實驗發現這個compact
flash
如果按下reset鍵就會重寫,而且一次只能同時寫一個file,sysace_flose後才會真正寫入,所以我需要記錄每次測試的結果,而測試又需要每次reset板子,所以只好把系統reset與microblaze
reset分開來繞,並用迴圈重覆把測試結果塞進去buffer,等使用者測試完畢後按下push
buffer再寫入資料,再microblaze
的user
ip內多寫幾個io,方便軟硬體做ready
ack的溝通,紀錄一下idea
int
main()
{
u32
write_start;
u32
write_end;
int
error_pos;
char
write_data[5];
u32
rcv_ack_rst;
make_folder();
const
char
fname [] = "a:\\Test\\result.txt";
SYSACE_FILE
*infile;
infile
= sysace_fopen(fname,"w");
while(1)
{
do{
write_start
= Xil_In32(0x70E00004); // waiting
for write
write_end
= Xil_In32(0x70E0000C); // Close
file
if(write_start
== 0x1) // time to write
{
error_pos
= Xil_In32(0x70E00000); // read from
vhdl
to know what to write
int2str(error_pos,
write_data);
sysace_fwrite(&write_data,1,strlen(write_data),infile);
xil_printf("write
file: 0x%x\n\r",error_pos);
//
send ack
to tell hw
that sysace_fwrite done
Xil_Out32(0x70E00018,0x00000001);
break;
}
if(write_end
== 0x1) // push button to close file
{
sysace_fclose(infile);
xil_printf("file
closed\n\r");
}
}while(
write_start == 0x0);
//
hw
tell sdk
that it receive the ack
rcv_ack_rst
= Xil_In32(0x70E00010);
if(rcv_ack_rst
== 0x1)
{
//
so sdk
set the ack
back to zero
Xil_Out32(0x70E00018,0x00000000);
}
}
return
0;
}
|
沒有留言:
張貼留言