48
SOPC/NIOSII 設設設設設設設 © 2007 Terasic Corporation 1 Hello World Hello World / / 軟軟 軟軟 •軟 軟軟 •軟 軟軟

Hello World 軟 / 硬體實作

  • Upload
    hallam

  • View
    78

  • Download
    0

Embed Size (px)

DESCRIPTION

硬體實作 軟體實作. Hello World 軟 / 硬體實作. DE2_70. NIOS II Program. SOPC(FPGA). System Interconnect Fabric. 50MHZ. RESET_N(1). NIOS II Processor. On-Chip Memory. POWER. LCD Controller. LCD. PC. USB Blaster. JTAG UART. System Block Diagram. 功能 : 於 LCD 顯示 “ Hello World”. - PowerPoint PPT Presentation

Citation preview

Page 1: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

1

Hello World Hello World 軟軟 // 硬體實作硬體實作

• 硬體實作• 軟體實作

Page 2: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

2

System Block Diagram

DE2_70

50MHZ

SOPC(FPGA)

On-ChipMemory

LCDController

NIOS IIProcessor

JTAGUART

System

Interco

nn

ect Fab

ric

LCD

RESET_N(1)

USBBlaster

PC

NIOS IIProgram

POWER

• 功能 : 於 LCD 顯示 “ Hello World”

Page 3: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

3

Hello World “Hello World “ 硬”體實作硬”體實作

1. 建立 Quartus Project

2. 建立 SOPC

3. 完成 Quartus Top

4. Compile/Download

Page 4: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

4

1.建立 Quartus Project

建立 QUARTUS Project

Page 5: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

5

Start Quartus• Windows Menu “ 開始所有程式

AlteraQuartus II 7.2 (32-btis)”

建立 QUARTUS Project

Page 6: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

6

Start“New Project Wizard…”• Qaurtus Menu “FileNew Project

Wizard…”

建立 QUARTUS Project

Page 7: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

7

Specify Project Info.

建立 QUARTUS Project

Page 8: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

8

Add Project Files

建立 QUARTUS Project

Page 9: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

9

Select FPGA

建立 QUARTUS Project

Page 10: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

10

Select EDA Tool

建立 QUARTUS Project

Page 11: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

11

Confirm/Finish

建立 QUARTUS Project

Page 12: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

12

2.建立 SOPC

建立 SOPC

Page 13: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

13

• 於 Qaurtus 下啟動 SOPC Builder– 選單 “ Tools SOPC Builder…”, 或– 按下 SOPC Builder ICON

啟動 SOPC Builder

建立 SOPC

Page 14: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

14

輸入 SYSTEM 資訊

建立 SOPC

Page 15: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

15

Add “On-Chip Memory”

建立 SOPC

Page 16: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

16

Add “NIOS II Processor”

建立 SOPC

Page 17: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

17

Add “JTAG UART”

建立 SOPC

Page 18: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

18

Add “LCD”

建立 SOPC

Page 19: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

19

完成 SOPC 設計

建立 SOPC

Page 20: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

20

Generate Code- DE2_70_SOPC.V (top)- DE2_70_SOPC.PTF

建立 SOPC

Page 21: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

21

SOPC_DE2_70_SOPC.v (內容 )

建立 SOPC

Page 22: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

22

SOPC_DE2_70_SOPC.v(SYMBLE)

建立 SOPC

Page 23: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

23

3. 完成Q uartus Top

完成 Quartus Top

Page 24: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

24

目的 : 連接 SOPC與週邊

完成 Quartus Top

Page 25: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

25

New Verilog File

完成 Quartus Top

Page 26: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

26

Rename Verilog File

完成 Quartus Top

Page 27: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

27

Coding MY_FIRST_SOPC.vmodule MY_FIRST_SOPC

(

//////////////////// Clock Input ////////////////////

iCLK_50, // 50 MHz

//////////////////// LCD Module 16X2 ////////////////

oLCD_ON, // LCD Power ON/OFF

oLCD_BLON, // LCD Back Light ON/OFF

oLCD_RW, // LCD Read/Write Select, 0 = Write, 1 = Read

oLCD_EN, // LCD Enable

oLCD_RS, // LCD Command/Data Select, 0 = Command, 1 = Data

LCD_D,// LCD Data bus 8 bits

);完成 Quartus Top

Page 28: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

28

Port Declaration// PORT declarations

//==================================================

//////////////////////// Clock Input ////////////////////////

input iCLK_50; // 50 MHz

//////////////////// LCD Module 16X2 ////////////////////////////

inout [7:0] LCD_D; // LCD Data bus 8 bits

output oLCD_ON; // LCD Power ON/OFF

output oLCD_BLON; // LCD Back Light ON/OFF

output oLCD_RW; // LCD Read/Write Select, 0 = Write, 1 = Read

output oLCD_EN; // LCD Enable

output oLCD_RS; // LCD Command/Data Select,

// 0 = Command, 1 = Data完成 Quartus Top

Page 29: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

29

Power On LCD//========== 16*2 LCD Module

assign oLCD_ON = 1'b1; // LCD ON

assign oLCD_BLON = 1'b1; // LCD Back Light

完成 Quartus Top

Page 30: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

30

Connect SYSTEM// Structural coding

//==================================================

DE2_70_SOPC u1 (

// 1) global signals:

.clk(iCLK_50),

.reset_n(1),

// the_lcd

.LCD_E_from_the_lcd(oLCD_EN),

.LCD_RS_from_the_lcd(oLCD_RS),

.LCD_RW_from_the_lcd(oLCD_RW),

.LCD_data_to_and_from_the_lcd(LCD_D)

);

endmodule完成 Quartus Top

Page 31: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

31

Pin Assignment - Analysis• 選單 “ FileSave” save

“MY_FIRST_SOPC.V”

• 選單 “ ProcessingStartStart Analysis & Elaboration”

完成 Quartus Top

Page 32: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

32

開啟 Pin Planner

完成 Quartus Top

Page 33: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

33

輸入 PIN角位置

完成 Quartus Top

滑鼠雙擊後 , 打

B2

Page 34: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

34

4. Compile/Download

Compile/Download

Page 35: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

35

Compile

Compile/Download

Page 36: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

36

Download

13 2

4

• DE2_70 左邊 SWITCH 須切至 “ RUN”

Compile/Download

Page 37: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

37

No USB-Blaster?

1

2

3

Compile/Download

Page 38: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

38

Hello World “Hello World “ 軟”體實軟”體實作作

Page 39: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

39

Start NIOS II IDE 7.2• Windows 選單“開始所有程式

AlteraNIOS II EDS 7.2NIOS II IDE 7.2”

New Project

Page 40: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

40

Setup Workspace• 選單“ FileSwitch Workspace…”

C:\DE2_70\MY_FIRST_SOPC\software\project_hello

New Project

Page 41: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

41

New Nios Project• 選單“ FileNewNios II C/C++ Application”

1

2

34

5

C:\DE2_70\MY_FIRST_SOPC\DE2_70_SOPC.ptf

New Project

Page 42: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

42

NIOS II IDE 介面

Coding

Editor

Project Management

Page 43: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

43

Coding – hello_world.c#include <stdio.h>

#include <stdlib.h>

#include "system.h"

void hello_lcd(void);

int main()

{

printf("Hello from Nios II!\n");

hello_lcd();

return 0;

}

void hello_lcd(void){

FILE *pLCD;

char szHello[] = "DE2_70\nHello\n";

pLCD = fopen(LCD_NAME, "w");

if (pLCD){

fwrite(szHello, strlen(szHello), 1, pLCD);

//fclose(pLCD);

}else{

printf("failed to open LCD\n");

}

}

Coding

Page 44: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

44

• Menu “ProjectBuild All”

• Sytem.h

Compile

Compile

Page 45: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

45

Download Hardware .SOF• Menu “ToolsQuartus II Progammer”

1

23

4

5

Download HW

C:\DE2_70\MY_FIRST_SOPC\MY_FIRST_SOPC.sof

Page 46: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

46

Run

Run

1

2

Page 47: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

47

Run Configuration

1.滑鼠左鍵雙擊

Run

2

3

4

5

NIOS II Hardware Target Connection

只有第一次未指定硬體時才會出現此畫面

Page 48: Hello World  軟 / 硬體實作

SOPC/NIOSII設計與實作課程

© 2007 Terasic Corporation

48

• LCD 上出現

• NIO2 IDE Console 出現

結果

DE2_70Hello

Run