顯示具有 ML605 標籤的文章。 顯示所有文章
顯示具有 ML605 標籤的文章。 顯示所有文章

2014年10月9日 星期四

ML605 configuration with sysace

Ml605 configuration with sysace
ISE 14.4

終於需要compact flash來做它的正途了
先做一個小測試建立八個bits file ,每個bit file 內包含不同的led燈亮

先把CF Card format,如果之前已經做過了,就直接把卡片裡面的東西刪掉就好
注意現在要把CF卡與電腦連接,不是放在板子上
impact, file → new project





Name可以自己隨便取,但是位置要選CF卡的槽


有幾個bit file要燒進去就放幾個,名字可以另外取

接下來會跳出視窗要選擇bit file的位置,然後會問要不要放其它file在同一個address,要選No



選好以後按左邊的Generate file,然後確定跳出來的視窗是你剛剛輸入的名子,impact就會開始寫資料進入你的CF,寫入大概需要幾分鐘的時間,寫完以後會看到完成的畫面


CF卡放入ml605,在板子上有個4 poleS1 switch, 第四個polemode, 如果為ON,系統開機時會自動去讀CF卡內的bit file,如果為off則不會

前三個為address,一打開電源系統就會自動去讀cf卡還有switch上的address,如果要換成另一個bit file, 必須要關掉電源重開,只改address不重開電源是不會重燒的!




這邊的address 012 跟燒入的bit file對應關係為

Addr 0 | Addr 1 | Addr 2
Bit file
000
0
100
1
010
2
110
3
001
4
101
5
011
6
111
7




2014年9月26日 星期五

Ml605 use PLB Bus to write CF

ML605板子是成功以後,之後可能會用V5或是V4來做新的版子來測
看了一下AXI BUS只有在Spartan6 還有 Virtex6
所以試做了一下換成PLB bus,大致上跟AXI一樣,有幾個小地方要注意一下
建立Microblaze得時候要選Cache



建立以後,XPSUCF上會出現DDR3Pin location,我測了一下把它加入或是不加入ISEUCF都可以

在建立自己的ip時記得選擇PLB,不要傻傻的一直按next


這邊我不確定需不需要勾選,但是我沒勾選可以成功



在寫mpd file得時候注意vector不要跟上面一樣從LSBMSB
不然系統之後也會這樣合成變成 A TO B



有個地方覺得很匪夷所思
C_SPLB_DWIDTH在程式裡面是32 bits 但是在這裡卻是128,但是又不能改


但是還是寫入32是正確的



2014年9月10日 星期三

Ml605 compact flash card read/write test





先把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,其中SYSACETIMER需加入interrupt


address,再把memory調大,不然之後產生linked script會有空間不夠的error


ISE產生microblazetop layer, ddr3port不用拉出去top繞線,ucf直接把xps中的拷過來,產生bit file
在資料夾中建立workspace目錄
xpsexport 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_WRITECONFIG_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板子,所以只好把系統resetmicroblaze 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;
}


2014年5月16日 星期五

Ml605 microblaze with your own IP

Ml605 microblaze with your own IP

無可避免的還是用microblaze比較威,先來建立一個自己的IP放在AXI,方便接來下用UART進來的資料可以一起經由bus進入IP內部的邏輯

前兩年做過的東西早就忘光了,今天又依照tutorial 做了一次,趕快來紀錄一下,這樣下次複習比較快XDDDD

Tutorial 原版 EDK Concepts, Tools, and Techniques
A Hands-On Guide to EffectiveEmbedded System Design
UG683 (v13.4) January 18, 2012

建立一個專案,新增processer
選擇讓processor先預選基本的配備,然後在刪掉不需要的
local memory size 調大一點
timer新增進來,並加上interrupt

LED之後要做測試用所以不加進來


完成了以後可以看到大致的結構


接下來新增一個自己的IP


依照tutorial 新增一個blink ip,然後一直按到finish


打開\system\pcores\blink_v1_00_a\hdl\vhdl
裡面的兩個vhdl檔來新增port與寫入功能

blink.vhdl


user_logic.vhdl,利用輸入addressdata來決定讓led閃爍或是停止


在打開\system\pcores\blink_v1_00_a\data 裡面的 blink_v2_1_0.mpd
LEDs加入port


改完了以後按


就會在左側的ip列表裡面看到剛剛的blink,按兩下加入bus


base_address 先不用改,稍後系統會自動分配


portleds拉到外面的pin


addresses可以看到我們新增的ipaddress0x7c600000


接下來按hardware- generate netlist

成功了以後來寫top levelucf,注意blink_0_LEDs_pin 是否出現在output pin

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity ml605_microblaze_top is
    Port (
    osc_200m_p : in  STD_LOGIC;
    osc_200m_n : in  STD_LOGIC;
    reset : in  STD_LOGIC;
    uart_tx : out  STD_LOGIC;
    uart_rx : in  STD_LOGIC;
    gpio_led : out  STD_LOGIC_VECTOR (3 downto 0);
    gpio_dip : in  STD_LOGIC_VECTOR (7 downto 0));
end ml605_microblaze_top;

architecture Behavioral of ml605_microblaze_top is

  component system is
    port (
      RS232_Uart_1_sout : out std_logic;
      RS232_Uart_1_sin : in std_logic;
      RESET : in std_logic;
      blink_0_LEDs_pin : out std_logic_vector(3 downto 0);
      DIP_Switches_8Bits_TRI_I : in std_logic_vector(7 downto 0);
      CLK_P : in std_logic;
      CLK_N : in std_logic
    );
  end component;

begin

  microblaze_i : system
    port map (
      RS232_Uart_1_sout => uart_tx,
      RS232_Uart_1_sin => uart_rx,
      RESET => reset,
      blink_0_LEDs_pin => gpio_led,
      DIP_Switches_8Bits_TRI_I => gpio_dip,
      CLK_P => osc_200m_p,
      CLK_N => osc_200m_n
    );
end Behavioral;

NET osc_200m_n LOC = "H9" | DIFF_TERM = "TRUE" | IOSTANDARD = "LVDS_25";
NET osc_200m_p LOC = "J9" | DIFF_TERM = "TRUE" | IOSTANDARD = "LVDS_25";
NET gpio_dip[0] LOC = "D22" | IOSTANDARD = "LVCMOS15";
NET gpio_dip[1] LOC = "C22" | IOSTANDARD = "LVCMOS15";
NET gpio_dip[2] LOC = "L21" | IOSTANDARD = "LVCMOS15";
NET gpio_dip[3] LOC = "L20" | IOSTANDARD = "LVCMOS15";
NET gpio_dip[4] LOC = "C18" | IOSTANDARD = "LVCMOS15";
NET gpio_dip[5] LOC = "B18" | IOSTANDARD = "LVCMOS15";
NET gpio_dip[6] LOC = "K22" | IOSTANDARD = "LVCMOS15";
NET gpio_dip[7] LOC = "K21" | IOSTANDARD = "LVCMOS15";
NET gpio_led[0] LOC = "AC22" | IOSTANDARD = "LVCMOS25";
NET gpio_led[1] LOC = "AC24" | IOSTANDARD = "LVCMOS25";
NET gpio_led[2] LOC = "AE22" | IOSTANDARD = "LVCMOS25";
NET gpio_led[3] LOC = "AE23" | IOSTANDARD = "LVCMOS25";

NET reset LOC = "H10" | IOSTANDARD = "SSTL15" | TIG;
NET uart_rx LOC = "J24" | IOSTANDARD = "LVCMOS25";
NET uart_tx LOC = "J25" | IOSTANDARD = "LVCMOS25";

接下來在ISE geberate programming file

新增一個workspace資料夾

之後在XPS上直接連到SDK,指向剛剛新增的workspace



可以看到SDK上已經有Processor的資料


file-new-application project
新增一個hello world project

然後programm FPGA  


接下來可以用兩種方法來玩一下UART
  1. hello world 不用改,XMD Console
XMD%
Accepted a new TCLSock connection from 127.0.0.1 on port 53775
Programming Bitstream -- D:/ml605_microblaze/workspace/system_hw_platform/download.bit
Fpga Programming Progress ......10....20....30....40....50....60....70....80....90.....Done
mb

JTAG chain configuration
--------------------------------------------------
Device ID Code IR Length Part Name
1 0a001093 8 System_ACE_CF
2 64250093 10 XC6VLX240T

MicroBlaze Processor Configuration :
-------------------------------------
Version............................8.40.b
Optimization.......................Performance
Interconnect.......................AXI-LE
MMU Type...........................No_MMU
No of PC Breakpoints...............1
No of Read Addr/Data Watchpoints...0
No of Write Addr/Data Watchpoints..0
Instruction Cache Support..........off
Data Cache Support.................off
Exceptions Support................off
FPU Support.......................off
Hard Divider Support...............off
Hard Multiplier Support............on - (Mul32)
Barrel Shifter Support.............on
MSR clr/set Instruction Support....on
Compare Instruction Support........on
Data Cache Write-back Support......off
Fault Tolerance Support............off
Stack Protection Support...........off

Connected to MicroBlaze "mdm" target. id = 0
Starting GDB server for "mdm" target (id = 0) at TCP port no 1234

Note:: "mbconnect" command is Deprecated. Use "connect mb" command
XMD% stop
Processor stopped

XMD% mwr 0x7c600000 0x1
XMD% mrd 0x7c600000
7C600000: 00000001

XMD% mwr 0x7c600000 0x0
XMD%

第二種方法新增peripheral_tests_0 application project , 讓我們用c來控制uart



可以看到在左欄已經產了一些與周邊相關的程式,但這不是全部我需要的XD
我需要可以一個可以從UART搜集資料進來變成hex,好讓我可以把資料送入microblazeaxi bus,進而控制自創IPLED



裡面的reference code中的xlib_string.hxil_string.c,人家寫好的函式總是比較好用阿XD \xapp493_DisplayPort_SPM\XAPP493\v6\ML605\sdk_workspace\dp_source_policy_maker_0\src
xlib_string.h
//#define SIMULATION
#define DEBUG_LEVEL 1


#include "xil_types.h"

#define PRINT_TS 0
#define PRINT_EDID 1
#define LLC_TEST_MODE 0

#if (DEBUG_LEVEL >= 4)
#define dbg4_printf xil_printf
#else
#define dbg4_printf do_nothing
#endif

#if (DEBUG_LEVEL >= 3)
#define dbg3_printf xil_printf
#else
#define dbg3_printf do_nothing
#endif

#if (DEBUG_LEVEL >= 2)
#define dbg2_printf xil_printf
#else
#define dbg2_printf do_nothing
#endif

#if (DEBUG_LEVEL >= 1)
#define dbg_printf xil_printf
#define dbg1_printf xil_printf
#else
#define dbg_printf do_nothing
#define dbg1_printf do_nothing
#endif

#if (DEBUG_LEVEL == 0)
#define dbg_printf do_nothing
#endif

#define dbg_llc_printf do_nothing //xil_printf
#define dbg1_llc_printf do_nothing //xil_printf
#define dbg2_llc_printf do_nothing

void do_nothing();

char xil_getc(u32 timeout_ms);

u32 xil_gethex(u8 num_chars);


xil_string.c
#include "xlib_string.h"
#include "stdio.h"
#include "xlib_string.h"
#include "xuartlite_l.h"
#include "xparameters.h"
#include "xtmrctr.h"

char xil_getc(u32 timeout_ms){
 char c;
 u32 timeout = 0;

   extern XTmrCtr TimerCounter;

   //dbg_printf ("timeout_ms = %x\n\r",timeout_ms);
     // Reset and start timer
   if ( timeout_ms > 0 && timeout_ms != 0xff ){
    XTmrCtr_Start(&TimerCounter, 0);
    //dbg_printf ("timeout_ms = %x\n\r",timeout_ms);
   }



  while(XUartLite_IsReceiveEmpty(STDIN_BASEADDRESS) && (timeout == 0)){
      if ( timeout_ms == 0 ){ // no timeout - wait for ever
      timeout = 0;
      } else if ( timeout_ms == 0xff ) { // no wait - special case
      timeout = 1;
      } else if(timeout_ms > 0){
    if(XTmrCtr_GetValue(&TimerCounter, 0) > ( timeout_ms * (XPAR_MICROBLAZE_CORE_CLOCK_FREQ_HZ / 1000) )){
     timeout = 1;
    }
      }
  }
  if(timeout == 1){
   c = 0;
  } else {
   c = XUartLite_RecvByte(STDIN_BASEADDRESS);
  }

  return c;
}


u32 xil_gethex(u8 num_chars){
u32 data;
u32 i;
u8 term_key;
data = 0;

for(i=0;i= 'a') {
  term_key = term_key - 'a' + 10;
 } else if(term_key >= 'A') {
   term_key = term_key - 'A' + 10;
 } else {
  term_key = term_key - '0';
 }
 data = (data << 4) + term_key;
}


return data;
}

void do_nothing(){

}



將這兩個檔案加入我們建立的peripheral project,因為要init platform, 所以也把hello_world_0 裡面的platform.c, platform.h, platform_config.h 加入 peripheral project

將原本的testperiph.c main()拿掉,加入剛剛的h file
#include 
#include "xparameters.h"
#include "xil_cache.h"
#include "xintc.h"
#include "intc_header.h"
#include "uartlite_header.h"
#include "xbasic_types.h"
#include "xgpio.h"
#include "gpio_header.h"
#include "xtmrctr.h"
#include "tmrctr_header.h"
#include "tmrctr_intr_header.h"

//------------------ ADD CODE ---------------------
#include "xlib_string.h"
#include "platform.h"

void reg_write(u32 reg_address, u32 data);
u32  reg_read(u32 reg_address);
XTmrCtr TimerCounter;

int main()
{
    init_platform();
    while(1){
     dbg_printf(" TEST ");
     u32 addr = xil_gethex(8);
     u32 data = xil_gethex(8);
     reg_write(addr,data);
    }//end while
    cleanup_platform();
    return 0;
}

void reg_write(u32 reg_address, u32 data)
{
 dbg_printf("reg_write (0x%08x) 0x%08x\n\r", reg_address, data);
    *(volatile u32*)reg_address = data;
}

u32 reg_read(u32 reg_address)
{
 dbg_printf("reg_read (0x%08x) ", reg_address);
 u32 data = *(volatile u32*)reg_address;
 dbg_printf(" 0x%08x\n\r", data);
    return data;
}


在將產生的elf檔燒入版子,打開tera term,連續寫入addressdata就可以看到板子上的LED已經開始閃耀搂!




要注意一下microblazebaudrateteraterm的是否一致

如果之後不會再改sdk或是下次懶得再開sdk的話也可以直接把download.bit 燒進去板子裡面, programm FPGA後的console下方寫著
data2mem -bm D:/ml605_microblaze/edkBmmFile_bd.bmm -bt \
D:/ml605_microblaze/ml605_microblaze_top.bit -bd \
D:/ml605_microblaze/workspace/peripheral_tests_0/Debug/peripheral_tests_0.elf tag \
microblaze_0 -o b D:/ml605_microblaze/workspace/system_hw_platform/download.bit

系統已經自動幫你下commandworkspace/system_hw_platform/download.bit

結論有錢的真的是大爺,系統都幫你做好了,如果用免錢的microblaze就是童養媳的命運阿阿阿阿!!!!

這篇寫得太囉嗦了,後記下一篇用wxpythonserial來寫一個簡單的小介面來跟板子溝通,並產生exe檔方便其他沒有灌python的人使用