altera university program cyclone v soc course blair fort

341
Altera University Program Cyclone V SoC Course Blair Fort

Upload: anthony-sherman

Post on 19-Jan-2016

270 views

Category:

Documents


22 download

TRANSCRIPT

Page 1: Altera University Program Cyclone V SoC Course Blair Fort

Altera University ProgramCyclone V SoC Course

Blair Fort

Page 2: Altera University Program Cyclone V SoC Course Blair Fort

About the Presenter (me)

Ph.D. candidate at the University of Toronto- High-Level Synthesis as part of the LegUp group

Member of the Altera University Program since 2006- Course materials and exercises- Altera Monitor Program

2

Page 3: Altera University Program Cyclone V SoC Course Blair Fort

About the University Program Staff

Members:- Prof. Stephen Brown- Prof. Zvonko Vranesic- Kevin Nam- Aja Canyon- Blair Fort

Successful books in print

3

Page 4: Altera University Program Cyclone V SoC Course Blair Fort

Why Teach Students about FPGAs?

Field-Programmable Gate Arrays are programmable hardware chips- Can be used to implement any digital hardware circuit

Digital hardware is found is almost all modern products- Consumer produces, like audio and video players- Telephone and television equipment- Cars, airplanes, trains- Medical equipment, and industrial control

4

Page 5: Altera University Program Cyclone V SoC Course Blair Fort

Why Teach Students about FPGAs?

Field-Programmable Gate Arrays are programmable hardware chips- Can be used to implement any digital hardware circuit

Digital hardware is found is almost all modern products- Consumer produces, like audio and video players- Telephone and television equipment- Cars, airplanes, trains- Medical equipment, and industrial control

FPGAs are … everywhere

5

Page 6: Altera University Program Cyclone V SoC Course Blair Fort

About Altera Corporation

Page 7: Altera University Program Cyclone V SoC Course Blair Fort

Altera Highlights

Founded in 1983 High-growth semiconductor company Products include

- FPGAs- structured ASICs- embedded soft processors- design software- IP- development kits

3,100 employees ~$2 billion in revenue

7

Page 8: Altera University Program Cyclone V SoC Course Blair Fort

Altera Products

FPGAs:- Cyclone series: low cost, high performance- Arria series: Mid range, transceivers- Stratix series: largest, full featured, highest performance

Stratix 10- 2X core performance- Intel’s 14nm Tri-Gate process- 64-bit quad-core ARM Cortex-A53

CPLDs:- MAX series: for small, instant-on applications, non-volatile configuration

Design Support:- Quartus II: easy to use, complete CAD flow- Qsys System Integration tool

Development environment for embedded systems Nios II: embedded processor, ARM processor

- Embedded Design Suite: Nios II and ARM

8

Page 9: Altera University Program Cyclone V SoC Course Blair Fort

Altera R&D Sites

9

San Jose, US• Headquarter

s

High Wycombe, UK

Toronto, Canada• New Device Architectures• CAD Algorithms• IP• University Program

Penang, Malaysia

Austin, US

Herlev, DenmarkSt. John’s, Canada

New Jersey, US

Page 10: Altera University Program Cyclone V SoC Course Blair Fort

Altera University ProgramOverview

Page 11: Altera University Program Cyclone V SoC Course Blair Fort

Altera’s University Program Advantage

Ready-to-teach course material for universities- Tutorials (written for students, not experienced engineers!)

- Lab exercises Written by experienced Professors Digital Logic, Computer Organization, Embedded Systems

- Design examples I.P. cores for all of the peripherals on our teaching boards Prebuilt Nios II and ARM computer systems for use in courses

- Software: Quartus II, Nios II and ARM development tools Easy to use, powerful tools All software licenses are free to universities

- Distributed through the Web (www.altera.com/education/univ)

Best-in-class lab boards for teaching

11

Page 12: Altera University Program Cyclone V SoC Course Blair Fort

DE1-SoC

$150 USD Cyclone V SoC FPGA

Dual-core ARM Cortex-A9- 1GB DDR 3 SDRAM, MicroSD

- USB, Triple-speed Ethernet

- ADC, Accelerometer

- LED, Pushbutton

FPGA- 85K Programmable Logic Elements

- 64 MB SDRAM

- DVD-quality audio in/out, Video in/VGA out

- PS/2, IrDA

- 4 debounced pushbuttons, 10 slider switches, 10 red LEDs, six 7-segment displays

- Expansion headers

Built-in USB Blaster for FPGA programming

12

Page 13: Altera University Program Cyclone V SoC Course Blair Fort

DE-series Design Objective

Boards are ideal for use across the curriculum:

- Introductory Digital Logic - Computer Organization- Embedded Systems- Advanced Digital Logic (System Design)- Senior Digital Design Projects

13

Page 14: Altera University Program Cyclone V SoC Course Blair Fort

Research Platform: DE5-Net (Stratix V)

14

USB Blaster

RJ45

SFP+ x4

PCI Express x8

SW x4 LED x47-seg x2

DDR3 SO-DIMM B DDR3 SO-DIMM ASATA x4

QDR II+ SRAM

Flash

Page 15: Altera University Program Cyclone V SoC Course Blair Fort

Getting Started with the U.P.

Enroll as a member Professor at- http://university.altera.com

Receive free licenses for Quartus II CAD tools, Nios II processor, and other I.P. core designs

Request a free sample DE-series board

After evaluating the board:- Purchase additional boards (at Altera U.P. prices) from www.terasic.com or- Request a larger donation

(We also offer grants of FPGA chips for teaching & research projects)

15

Page 16: Altera University Program Cyclone V SoC Course Blair Fort

Altera U.P. Web Site

16

Page 17: Altera University Program Cyclone V SoC Course Blair Fort

Over 1,500 Universities with Altera Labs

17

Canada• 50 Labs

United States• 450 Labs

Europe• 500 Labs

East Asia• 500 Labs

Page 18: Altera University Program Cyclone V SoC Course Blair Fort

ARM Cortex-A9

Tutorial #1

Page 19: Altera University Program Cyclone V SoC Course Blair Fort

ARM

Founded in November 1990

Designs the ARM range of RISC processor cores- Licenses ARM core designs to semiconductor partners who fabricate and

sell to their customers- ARM does not fabricate silicon itself

Also develop technologies to assist with the designing of the ARM architecture- Software tools, boards, debug hardware- Application software- Bus architectures- Peripherals, etc

19

Page 20: Altera University Program Cyclone V SoC Course Blair Fort

ARM Cortex Processor (v7) Families

ARM Cortex-A family (v7-A):- Applications processors for full OS

and 3rd party applications

ARM Cortex-R family (v7-R):- Embedded processors for real-time

signal processing, control applications

ARM Cortex-M family (v7-M):- Microcontroller-oriented processors

for MCU and SoC applications

20

Page 21: Altera University Program Cyclone V SoC Course Blair Fort

ARM Cortex Processor (v7) Highlights

Reduced Instruction Set Computer (RISC) architecture- aka. Load/Store architecture

16 and 32-bit instruction modes- ARM (32-bits)- Thumb (16-bits)- Thumb 2 (16/32-bits)

32-bit word-length

16 general-purpose registers

Condition code flags, usable with many types of instructions

21

Page 22: Altera University Program Cyclone V SoC Course Blair Fort

ARM Cortex-A9

Cyclone V SoC and Arria V SoC families- 1-2 Cores

Application-level processor

Features:- 800 MHz 32-bit processor- 32 KB instruction and data L1 caches- Snoop control unit (SCU)- Accelerator Coherency Port (ACP)- Unified 512KB L2 Cache- ARM NEON™ single instruction, multiple data (SIMD) coprocessor- Floating point unit

22

Page 23: Altera University Program Cyclone V SoC Course Blair Fort

ARM Cortex-A9 MPCore

23

CPU 0

ARM Cortex-A9

SIMD and FPU

MMU

I-Cache D-Cache

Private Timers

Generic Interrupt Controller

CPU 1

ARM Cortex-A9

SIMD and FPU

MMU

I-Cache D-Cache

Private Timers

Accelerator Coherency Port and Snoop Controller

Page 24: Altera University Program Cyclone V SoC Course Blair Fort

ARM Cortex-A9 Registers

Arguments and Result

Register variables- Must be preserved

Scratch register

Stack Pointer Link Register Program Counter

24

R0

R1

R2

R3

R4

R5

R6

R7

R8

R9

R10

R11

R12

R13 / SP

R14 / LR

R15 / PC

This is defined by the Procedure Call Standard for the ARM Architecture (AAPCS)

Link register stores the return address for subroutine calls

Page 25: Altera University Program Cyclone V SoC Course Blair Fort

ARM Cortex-A9 CPSR

Current Program Status Register (CPSR)

25

31

N

30

Z

29

C

28

V

7

I

6

F

5

T

4 0

Condition code flags

Interrupt disable bits

ARM or Thumb operation

Processor mode

Page 26: Altera University Program Cyclone V SoC Course Blair Fort

ARM Instruction Set

32-bit instructions

Unified Assembler Language (UAL)- Common syntax for ARM and Thumb instructions

Instruction Classes- Branch instructions- Data-processing instruction- Load and store instructions- Status register access instructions- Miscellaneous instructions

26

Page 27: Altera University Program Cyclone V SoC Course Blair Fort

ARM Machine Code Format

Format:

Rd: Destination register

Rn: Operand 1

Operand 2- 12-bit immediate offset or- Rm (lower four bits) and shift_operand

Condition codes- For conditional execution of the instruction

27

31 28 27 16 15 12 111920 0

Condition Rd Immediate or RmOP code Rn

Page 28: Altera University Program Cyclone V SoC Course Blair Fort

ARM Assembly Syntax

Operation Result, Operand 1, Operand 2

Operand 2: 12-bit immediateOP Rd, Rn, #value

Operand 2: registerOP Rd, Rn, Rm

Operand 2: register with shiftOP Rd, Rn, Rm, SHIFT #shift_value

SHIFT: left/right shift or rotate- 5-bit shift value- Changes contents of Rm prior to being used

28

31 28 27 16 15 12 111920 0

Condition Rd Immediate or RmOP code Rn

Page 29: Altera University Program Cyclone V SoC Course Blair Fort

Branch Instructions

Branch target address- Program Counter (pc/r15) + 24-bit offset (2’s complement)

Syntax- B{condition code} LABEL- BEQ LOOP

29

31 28 27 0

Condition Offset or Rm

24 23

OP code

Page 30: Altera University Program Cyclone V SoC Course Blair Fort

Branch Instructions

Branch target address- Program Counter (pc/r15) + 24-bit offset (2’s complement)

Syntax- B{condition code} LABEL- BEQ LOOP

Subroutine calls- Branch and Link instruction: BL LABEL- Next address is stored in LR, for return

Subroutine returns- Branch and Exchange: BX LR

30

31 28 27 0

Condition Offset or Rm

24 23

OP code

Page 31: Altera University Program Cyclone V SoC Course Blair Fort

ARM Condition Codes

31

Page 32: Altera University Program Cyclone V SoC Course Blair Fort

Data-processing Instructions

Arithmetic- ADD, SUB, MUL, MLA (multiple accumulate)

Logic- AND, ORR, EOR- BIC (bit clear), TST (test)

Move- MOV, MVN (move negative (not)), MOVT (move top)

Shift and rotate- ASR, LSL, LSR, ROR

Comparison- CMP, CMN (compare negative)

32

31 28 27 16 15 12 111920 0

Condition Rd Immediate or RmOP code Rn

Page 33: Altera University Program Cyclone V SoC Course Blair Fort

Setting Condition Codes

Always set by comparison and test instructions

Arithmetic, logic and move instruction can optionally affect the flags.- ADD R2, R3, R4 (does not affect the flags)

- ADDS R2, R3, R4 (does affect the flags)

33

Page 34: Altera University Program Cyclone V SoC Course Blair Fort

Conditional Execution

Most ARM instructions are executed conditionally.ADD R2, R3, R4 (always execute)ADDAL R2, R3, R4

ADDNE R2, R3, R4 (execute only if the Z flag is clear)

34

Page 35: Altera University Program Cyclone V SoC Course Blair Fort

Conditional Execution

Most ARM instructions are executed conditionally.ADD R2, R3, R4 (always execute)ADDAL R2, R3, R4

ADDNE R2, R3, R4 (execute only if the Z flag is clear)

Example: c = (a > b) ? (a – b) : (b – a);

35

Page 36: Altera University Program Cyclone V SoC Course Blair Fort

Conditional Execution

Most ARM instructions are executed conditionally.ADD R2, R3, R4 (always execute)ADDAL R2, R3, R4

ADDNE R2, R3, R4 (execute only if the Z flag is clear)

Example: c = (a > b) ? (a – b) : (b – a);

START: CMP R0, R1 BLT LESS

SUB R2, R0, R1 B ENDLESS: SUB R2, R1, R0END:

36

Page 37: Altera University Program Cyclone V SoC Course Blair Fort

Conditional Execution

Most ARM instructions are executed conditionally.ADD R2, R3, R4 (always execute)ADDAL R2, R3, R4

ADDNE R2, R3, R4 (execute only if the Z flag is clear)

Example: c = (a > b) ? (a – b) : (b – a);

START: CMP R0, R1 START: CMP R0, R1 BLT LESS SUBGT R2, R0, R1

SUB R2, R0, R1 SUBLE R2, R1, R0 B ENDLESS: SUB R2, R1, R0END:

37

Page 38: Altera University Program Cyclone V SoC Course Blair Fort

Assembler Directives

Directives provide information required by the assembler

GNU Assembler directives- .text

Identifies code section

- .global symbol Makes symbol visible outside the assembled object file

- .word expressions Comma separated expression are assembled into 32-bit numbers

- .end Marks the end of the source file

38

Page 39: Altera University Program Cyclone V SoC Course Blair Fort

Hands-on Session 1

Create a software project targeting the ARM Cortex-A9 Compile the application Download the compiled software to the DE1-SoC Run and debug the application

39

Page 40: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 1: Greatest Common Divisor (GCD)

40

int a = 54, b = 24;do {

if ( a > b) a = a – b;else b = b – a;

} while (a != b);

Page 41: Altera University Program Cyclone V SoC Course Blair Fort

int a = 54, b = 24;do {

if ( a > b) a = a – b;else b = b – a;

} while (a != b);

.text

.global _start

_start: MOV R0, #54 /* Register R0 is the first number. */ MOV R1, #24 /* Register R1 is the second number. */

GCD: CMP R0, R1 /* Set the condition codes. */SUBGT R0, R0, R1 /* If (R0 > R1) then R0 = R0 - R1. */SUBLT R1, R1, R0 /* If (R0 < R1) then R1 = R1 - R0. */BNE GCD /* If (R0 != R1) then loop again. */

STOP: B STOP /* If (R0 == R1) then stop. */

.end

Exercise 1: Greatest Common Divisor (GCD)

41

Page 42: Altera University Program Cyclone V SoC Course Blair Fort

Step 1: Start Altera Monitor Program

42

Page 43: Altera University Program Cyclone V SoC Course Blair Fort

Step 2: Create a New Project

Sets up the Altera Monitor Program- Select files to work with- Specify target system

43

Page 44: Altera University Program Cyclone V SoC Course Blair Fort

Step 2.1: Specify name, directory and architecture

44

Page 45: Altera University Program Cyclone V SoC Course Blair Fort

Step 2.2: Select the ARM Cortex-A9 System

45

Page 46: Altera University Program Cyclone V SoC Course Blair Fort

Step 2.3: Select Program Type

46

Page 47: Altera University Program Cyclone V SoC Course Blair Fort

Step 2.4: Add Source File

47

Page 48: Altera University Program Cyclone V SoC Course Blair Fort

Step 2.5: Set Board Connection and Select Processor

48

Page 49: Altera University Program Cyclone V SoC Course Blair Fort

Step 2.6: Leave Default Memory Settings

49

Page 50: Altera University Program Cyclone V SoC Course Blair Fort

Step 3: Compile and Load

50

Compile your assembly language program

Load the compiled code into the memory on the DE1-SoC board

Page 51: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Disassembly Window

51

Page 52: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Disassembly Window

52

Disassembly

Page 53: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Disassembly Window

53

Registers

Page 54: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Disassembly Window

54

Info & Error Msgs

Page 55: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Disassembly Window

55

Terminal

Page 56: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Disassembly Window

56

Page 57: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Disassembly Window

57

Page 58: Altera University Program Cyclone V SoC Course Blair Fort

Step 5: Single Step your Program

58

Page 59: Altera University Program Cyclone V SoC Course Blair Fort

Step 5: Single Step your Program

59

Page 60: Altera University Program Cyclone V SoC Course Blair Fort

Step 6: Change Register View

60

Page 61: Altera University Program Cyclone V SoC Course Blair Fort

Step 7: Single Step your Program Again

61

Page 62: Altera University Program Cyclone V SoC Course Blair Fort

Step 8: Set a Breakpoint

62

Page 63: Altera University Program Cyclone V SoC Course Blair Fort

Step 9: Run to the Breakpoint

63

Page 64: Altera University Program Cyclone V SoC Course Blair Fort

Step 9: Run to the Breakpoint

64

Page 65: Altera University Program Cyclone V SoC Course Blair Fort

Step 10: Change Register View

65

Page 66: Altera University Program Cyclone V SoC Course Blair Fort

Step 11: Look at CPSR

66

31

N

30

Z

29

C

28

V

7

I

6

F

5

T

4 0

Condition code flags

Interrupt disable bits

ARM or Thumb operation

Processor mode

Page 67: Altera University Program Cyclone V SoC Course Blair Fort

CPSR = 0x200001D3

Step 11: Look at CPSR

67

31

N

30

Z

29

C

28

V

7

I

6

F

5

T

4 0

Page 68: Altera University Program Cyclone V SoC Course Blair Fort

CPSR = 0x200001D3

Step 11: Look at CPSR

68

31

N

30

Z

29

C

28

V

7

I

6

F

5

T

4 0

0 0 1 0

Page 69: Altera University Program Cyclone V SoC Course Blair Fort

CPSR = 0x200001D3

What should have happened in our code?

Step 11: Look at CPSR

69

31

N

30

Z

29

C

28

V

7

I

6

F

5

T

4 0

0 0 1 0

GCD: CMP R0, R1SUBGT R0, R0, R1SUBLT R1, R1, R0BNE GCD

Page 70: Altera University Program Cyclone V SoC Course Blair Fort

CPSR = 0x200001D3

What should have happened in our code?

Note- GT is Z clear and N equals V- LT is N is not equal to V- NE is Z clear

Step 11: Look at CPSR

70

31

N

30

Z

29

C

28

V

7

I

6

F

5

T

4 0

0 0 1 0

GCD: CMP R0, R1SUBGT R0, R0, R1SUBLT R1, R1, R0BNE GCD

Page 71: Altera University Program Cyclone V SoC Course Blair Fort

CPSR = 0x200001D3

What should have happened in our code?

Note- GT is Z clear and N equals V- LT is N is not equal to V- NE is Z clear

Step 11: Look at CPSR

71

31

N

30

Z

29

C

28

V

7

I

6

F

5

T

4 0

0 0 1 0

GCD: CMP R0, R1SUBGT R0, R0, R1SUBLT R1, R1, R0BNE GCD

Page 72: Altera University Program Cyclone V SoC Course Blair Fort

Step 12: Set a Breakpoint at the End and Run

72

Page 73: Altera University Program Cyclone V SoC Course Blair Fort

Step 13: Restart the Program

73

Page 74: Altera University Program Cyclone V SoC Course Blair Fort

Step 14: Single Step

74

Page 75: Altera University Program Cyclone V SoC Course Blair Fort

Step 15: Modify R0

75

Page 76: Altera University Program Cyclone V SoC Course Blair Fort

Step 16: Run to Breakpoint

76

Page 77: Altera University Program Cyclone V SoC Course Blair Fort

Step 17: Disconnect from the DE1-SoC Board

77

Page 78: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0x40 into register R1

78

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

0x00000000

0x00000004

0x00000008

Page 79: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0x40 into register R1

LDR R1, [R0]

79

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

0x00000000

0x00000004

0x00000008

Page 80: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0x40 into register R1

MOV R0, #0x40LDR R1, [R0]

80

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

0x00000000

0x00000004

0x00000008

Page 81: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0x40 into register R1

MOV R0, #0x40LDR R1, [R0]

81

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

0x00000000

0x00000004

0x00000008

Page 82: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0x40 into register R1

MOV R0, #0x40LDR R1, [R0]

82

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0x40

0

0x00000000

0x00000004

0x00000008

Page 83: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0x40 into register R1

MOV R0, #0x40LDR R1, [R0]

83

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0x40

0x12345678

0x00000000

0x00000004

0x00000008

Page 84: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0xFF200040 into register R1

84

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

0x00000000

0x00000004

0x00000008

Page 85: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0xFF200040 into register R1

MOV R0, #0xFF200040LDR R1, [R0]

85

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

0x00000000

0x00000004

0x00000008

Page 86: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0xFF200040 into register R1

MOV R0, #0xFF200040LDR R1, [R0]

0xFF200040 is larger than 16 bits

86

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

0x00000000

0x00000004

0x00000008

Page 87: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0xFF200040 into register R1

MOV R0, #0x0040MOVT R0, #0xFF20LDR R1, [R0]

87

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

0x00000000

0x00000004

0x00000008

Page 88: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0xFF200040 into register R1

MOV R0, #0x0040MOVT R0, #0xFF20LDR R1, [R0]

88

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

0x00000000

0x00000004

0x00000008

Page 89: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0xFF200040 into register R1

MOV R0, #0x0040MOVT R0, #0xFF20LDR R1, [R0]

89

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0x40

0

0x00000000

0x00000004

0x00000008

Page 90: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0xFF200040 into register R1

MOV R0, #0x0040MOVT R0, #0xFF20LDR R1, [R0]

90

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0xFF200040

0

0x00000000

0x00000004

0x00000008

Page 91: Altera University Program Cyclone V SoC Course Blair Fort

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0xFF200040 into register R1

MOV R0, #0x0040MOVT R0, #0xFF20LDR R1, [R0]

91

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0xFF200040

0xFEDCBA90

0x00000000

0x00000004

0x00000008

Page 92: Altera University Program Cyclone V SoC Course Blair Fort

0x00000000

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0xFF200040 into register R1

LDR R0, =0xFF200040LDR R1, [R0]

92

0x00000004

0x00000008

0x00000040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

Page 93: Altera University Program Cyclone V SoC Course Blair Fort

0x00000000

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0xFF200040 into register R1

LDR R0, =0xFF200040LDR R1, [R0]

Assembled code:

LDR R0, [pc, #0]LDR R1, [R0]

93

0x00000004

0x00000008

0x00000040

0xFF200040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

Page 94: Altera University Program Cyclone V SoC Course Blair Fort

0x00000000

Load and Store Instructions

Reading data from memory- How do we read the memory contents at

address 0xFF200040 into register R1

LDR R0, =0xFF200040LDR R1, [R0]

Assembled code:

LDR R0, [pc, #0]LDR R1, [R0]

94

0x00000004

0x00000008

0x00000040

0xFF200040

0xFF200040

0x12345678

0xFEDCBA90

R0

R1

0

0

LiteralPool

Page 95: Altera University Program Cyclone V SoC Course Blair Fort

0x00000000

Load and Store Instructions

Writing data to memory- How do we write the contents of R1 to the

memory location 0x40

LDR R0, =0x00000040STR R1, [R0]

95

0x00000004

0x00000008

0x00000040

0xFF200040

0x00000040

0x12345678

0xFEDCBA90

R0

R1

0

0

Page 96: Altera University Program Cyclone V SoC Course Blair Fort

0x00000000

Load and Store Instructions

Writing data to memory- How do we write the contents of R1 to the

memory location 0x40

LDR R0, =0x00000040STR R1, [R0]

Assembled code:

LDR R0, [pc, #0]STR R1, [R0]

96

0x00000004

0x00000008

0x00000040

0xFF200040

0x00000040

0x12345678

0xFEDCBA90

R0

R1

0

0

Page 97: Altera University Program Cyclone V SoC Course Blair Fort

Addressing Modes

Register indirect:- Register offset: [Rn]

Offset mode:- Immediate offset: [Rn, #offset]- Register offset: [Rn, ± Rm, shift]

97

Page 98: Altera University Program Cyclone V SoC Course Blair Fort

Addressing Modes

Register indirect:- Register offset: [Rn]

Offset mode:- Immediate offset: [Rn, #offset]- Register offset: [Rn, ± Rm, shift]

Indexed mode:- Updates the contents of Rn

98

Page 99: Altera University Program Cyclone V SoC Course Blair Fort

Addressing Modes

Register indirect:- Register offset: [Rn]

Offset mode:- Immediate offset: [Rn, #offset]- Register offset: [Rn, ± Rm, shift]

Indexed mode:- Updates the contents of Rn

Pre-indexed mode:- Immediate offset: [Rn, #offset]!- Register offset: [Rn, ± Rm, shift]!

Post-indexed mode:- Immediate offset: [Rn], #offset- Register offset: [Rn], ± Rm, shift

99

Page 100: Altera University Program Cyclone V SoC Course Blair Fort

Storing and Loading Multiple Registers

Two pseudo-instructions- PUSH and POP- For storing and loading multiple registers

100

Page 101: Altera University Program Cyclone V SoC Course Blair Fort

Storing and Loading Multiple Registers

Two pseudo-instructions- PUSH and POP- For storing and loading multiple registers

- PUSH {R1, R3-R5}

- POP {R1, R3-R5}

101

Page 102: Altera University Program Cyclone V SoC Course Blair Fort

Storing and Loading Multiple Registers

Two pseudo-instructions- PUSH and POP- For storing and loading multiple registers

- PUSH {R1, R3-R5} STMDB SP!, {R1, R3-R5}

- POP {R1, R3-R5} LDMIA SP!, {R1, R3-R5}

102

Page 103: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 2: Dot product

103

Page 104: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 2: Dot product

104

Page 105: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 2: Dot product

105

Page 106: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 2: Dot product

106

Page 107: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 2: Dot product

107

Page 108: Altera University Program Cyclone V SoC Course Blair Fort

Step 1: Create a New Project

Sets up the Altera Monitor Program- Select files to work with- Specify target system

108

Page 109: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.1: Specify name, directory and architecture

109

Page 110: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.2: Select the ARM Cortex-A9 System

110

Page 111: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.3: Select Program Type

111

Page 112: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.4: Add Source File

112

Page 113: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.5: Set Board Connection and Select Processor

113

Page 114: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.6: Leave Default Memory Settings

114

Page 115: Altera University Program Cyclone V SoC Course Blair Fort

Step 2: Compile and Load

115

Compile your assembly language program

Load the compiled code into the memory on the DE1-SoC board

Page 116: Altera University Program Cyclone V SoC Course Blair Fort

Step 3: Notice the use of the Literal Pool

116

Page 117: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Go to the Memory Window

117

Page 118: Altera University Program Cyclone V SoC Course Blair Fort

Step 5: Find the Address of AVECTOR

118

Page 119: Altera University Program Cyclone V SoC Course Blair Fort

Step 6: Find the Address of BVECTOR

119

Page 120: Altera University Program Cyclone V SoC Course Blair Fort

Step 7: Find the Data of the Vectors

120

Page 121: Altera University Program Cyclone V SoC Course Blair Fort

Step 8: Change to Signed Representation

121

Page 122: Altera University Program Cyclone V SoC Course Blair Fort

Step 8: Change to Signed Representation

122

Page 123: Altera University Program Cyclone V SoC Course Blair Fort

Step 9: Change to Decimal Format

123

Page 124: Altera University Program Cyclone V SoC Course Blair Fort

Step 9: Change to Decimal Format

124

Page 125: Altera University Program Cyclone V SoC Course Blair Fort

Step 10: Find Literal Pool in the Disassembly Window

125

Page 126: Altera University Program Cyclone V SoC Course Blair Fort

Step 11: Single Step or Set Breakpoints and Run

126

Page 127: Altera University Program Cyclone V SoC Course Blair Fort

Step 12: Final Result in R3

127

Page 128: Altera University Program Cyclone V SoC Course Blair Fort

Step 12: … And in the Memory Location DOTP

128

Page 129: Altera University Program Cyclone V SoC Course Blair Fort

Summary #1

What did we learn?- ARM Cortex-A9- Unified Assembly Language (UAL)- How to run and debug programs using the Altera Monitor Program

Where did we go from here?- Tutorials:

Introduction to the ARM Processor Altera Monitor Program Tutorial for ARM

- http://university.altera.com

- Literature: ARM Architecture Reference Manual

- http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406c/index.html

129

Page 130: Altera University Program Cyclone V SoC Course Blair Fort

Intro to Cyclone V’sHard Processor System (HPS)

Tutorial #2

Page 131: Altera University Program Cyclone V SoC Course Blair Fort

ARM Cortex-A9 MPCore

131

CPU 0

ARM Cortex-A9

SIMD and FPU

MMU

I-Cache D-Cache

Private Timers

Generic Interrupt Controller

CPU 1

ARM Cortex-A9

SIMD and FPU

MMU

I-Cache D-Cache

Private Timers

Accelerator Coherency Port and Snoop Controller

Page 132: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Altera HPS Block Diagram

132

MPCore

Page 133: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Altera HPS Block Diagram

133

MPCore

L2 Cache

0 GB

1 GB

2 GB

3 GB

4 GB

Page 134: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Altera HPS Block Diagram

134

MPCore

L2 Cache

0 GB

1 GB

2 GB

3 GB

4 GB

L3 Interconnect

Page 135: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Altera HPS Block Diagram

135

Boot ROM

MPCore

L2 Cache

Boot Region0 GB

1 GB

2 GB

3 GB

4 GB

Page 136: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Altera HPS Block Diagram

136

Boot ROM

MPCore

DDR3Chips

L2 Cache

SDRAMController SDRAM

Window

Boot Region0 GB

1 GB

2 GB

3 GB

4 GB

Page 137: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Altera HPS Block Diagram

137

Boot ROM

MPCore

DDR3Chips

L2 Cache

SDRAMController SDRAM

Window

Boot Region0 GB

1 GB

2 GB

3 GB

4 GB

Page 138: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Altera HPS Block Diagram

138

Boot ROM

MPCore

On-Chip RAM

DDR3Chips

L2 Cache

SDRAMController SDRAM

Window

Boot Region0 GB

1 GB

2 GB

3 GB

4 GB

Page 139: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Altera HPS Block Diagram

139

Boot ROM

MPCore

On-Chip RAM

Timers

DDR3Chips

L2 Cache

SDRAMController SDRAM

Window

Boot Region0 GB

1 GB

2 GB

3 GB

4 GB

Page 140: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Altera HPS Block Diagram

140

Boot ROM

MPCore

On-Chip RAM

GPIO

Timers

DDR3Chips

LEDGKEY

L2 Cache

SDRAMController SDRAM

Window

Boot Region0 GB

1 GB

2 GB

3 GB

4 GB

Page 141: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Altera HPS Block Diagram

141

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController SDRAM

Window

Boot Region0 GB

1 GB

2 GB

3 GB

4 GB

Page 142: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Altera HPS Block Diagram

142

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController SDRAM

Window

Boot Region0 GB

1 GB

2 GB

3 GB

4 GBPeripherals

Page 143: Altera University Program Cyclone V SoC Course Blair Fort

Hands-on Session 2

Write a program that uses HPS peripherals

Write a program that uses FPGA peripherals

Write a program that uses printf and scanf

143

Page 144: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 3: HPS Peripherals

The program will use the HPS pushbutton and LED

144

Page 145: Altera University Program Cyclone V SoC Course Blair Fort

HPS Pushbutton and LED

Both are attached to the memory-mapped GPIO 1 port- Base address: 0xFF709000- 16 registers

Data, Interrupts, Configuration, etc.

145

External Port

Data Register

Direction Register

Interrupt Enable

Page 146: Altera University Program Cyclone V SoC Course Blair Fort

HPS Pushbutton and LED

Both are attached to the memory-mapped GPIO 1 port- Base address: 0xFF709000- 16 registers

Data, Interrupts, Configuration, etc.

Each bit corresponds to a different I/O pin

146

External Port

Data Register

Direction Register

Interrupt Enable

Page 147: Altera University Program Cyclone V SoC Course Blair Fort

HPS Pushbutton and LED

Both are attached to the memory-mapped GPIO 1 port- Base address: 0xFF709000- 16 registers

Data, Interrupts, Configuration, etc.

Each bit corresponds to a different I/O pin- LED

Bit 24

147

External Port

Data Register

Direction Register

Interrupt Enable

Page 148: Altera University Program Cyclone V SoC Course Blair Fort

HPS Pushbutton and LED

Both are attached to the memory-mapped GPIO 1 port- Base address: 0xFF709000- 16 registers

Data, Interrupts, Configuration, etc.

Each bit corresponds to a different I/O pin- LED

Bit 24- Pushbutton

Bit 25

148

External Port

Data Register

Direction Register

Interrupt Enable

Page 149: Altera University Program Cyclone V SoC Course Blair Fort

Program

Read the pushbutton and display the value on the LED

149

#define bit_25_pattern 0x02000000

int main(void)(volatile int * HPS_GPIO1_Data = (int *) 0xFF709000;volatile int * HPS_GPIO1_Direction = (int *) 0xFF709004;volatile int * HPS_GPIO1_External = (int *) 0xFF709050;

*HPS_GPIO1_Direction = (1 << 24); // Set bit 24 (LEDG) of GPIO1 // to be an output

while(1){

int value = *HPS_GPIO1_External; // Read the value of the GPIO port

value &= bit_25_pattern; // Mask out the pushbutton value

*HPS_GPIO1_Data = (value >> 1); // Set the LEDG to the read value}

}

Page 150: Altera University Program Cyclone V SoC Course Blair Fort

Step 1: Create a New Project

Sets up the Altera Monitor Program- Select files to work with- Specify target system

150

Page 151: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.1: Specify name, directory and architecture

151

Page 152: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.2: Select the ARM Cortex-A9 System

152

Page 153: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.3: Select Program Type

153

Page 154: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.4: Add Source File

154

Page 155: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.5: Set Board Connection and Select Processor

155

Page 156: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.6: Leave Default Memory Settings

156

Page 157: Altera University Program Cyclone V SoC Course Blair Fort

Step 2: Compile and Load

157

Compile your C language program

Load the compiled code into the memory on the DE1-SoC board

Page 158: Altera University Program Cyclone V SoC Course Blair Fort

Step 3: Go to the Memory Window

158

Page 159: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Jump to the GPIO’s Address Range

159

Page 160: Altera University Program Cyclone V SoC Course Blair Fort

Step 5: Why is the Memory Window Blank?

160

Page 161: Altera University Program Cyclone V SoC Course Blair Fort

Step 6: Highlight the First Two Registers of the GPIO Port

161

Page 162: Altera University Program Cyclone V SoC Course Blair Fort

Step 7: Right Click and Read Selected Address Range

162

Page 163: Altera University Program Cyclone V SoC Course Blair Fort

Step 7: Right Click and Read Selected Address Range

163

Page 164: Altera University Program Cyclone V SoC Course Blair Fort

Step 8: Read the GPIO’s External Port

164

Page 165: Altera University Program Cyclone V SoC Course Blair Fort

Step 9: Hold Down the Button and Re-read the Location

165

Page 166: Altera University Program Cyclone V SoC Course Blair Fort

Step 10: Disassembly Window

166

Page 167: Altera University Program Cyclone V SoC Course Blair Fort

Step 11: Jump to Main

167

Page 168: Altera University Program Cyclone V SoC Course Blair Fort

Step 11: Jump to Main

168

Page 169: Altera University Program Cyclone V SoC Course Blair Fort

Step 12: Set a Breakpoint and Run to Main

169

Page 170: Altera University Program Cyclone V SoC Course Blair Fort

Step 13: Single Step or Run

170

Page 171: Altera University Program Cyclone V SoC Course Blair Fort

Step 14: Stop while Holding Down the Pushbutton

171

Page 172: Altera University Program Cyclone V SoC Course Blair Fort

HPS

How About Communication with the FPGA?

172

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController SDRAM

Window

Boot Region0 GB

1 GB

2 GB

3 GB

4 GBPeripheralsFPGA

Page 173: Altera University Program Cyclone V SoC Course Blair Fort

HPS

There are Several Bridges Between the HPS and FPGA

173

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

FPGA

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController

Bridges

SDRAMWindow

Boot Region0 GB

1 GB

2 GB

3 GB

4 GBPeripherals

Page 174: Altera University Program Cyclone V SoC Course Blair Fort

HPS

HPS-to-FPGA Bridge

174

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

FPGA

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController

H2F

On-Chip Cores

Ports

LEDRSwitches

Etc.

SDRAMWindow

Boot Region

FPGASlave

Region

0 GB

1 GB

2 GB

3 GB

4 GBPeripherals

Page 175: Altera University Program Cyclone V SoC Course Blair Fort

FPGAHPS

Lightweight HPS-to-FPGA Bridge

175

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController

LW H2F

Ports

LEDRSwitches

Etc.

SDRAMWindow

Boot Region

FPGASlave

Region

0 GB

1 GB

2 GB

3 GB

4 GBPeripherals

On-Chip Cores

Page 176: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 4: FPGA Peripherals

Circuit must be configured in the FPGA

176

Page 177: Altera University Program Cyclone V SoC Course Blair Fort

Pre-built DE1-SoC Computer System

Download the system onto the DE1-SoC board- Can be configured to load on power-

up

Develop programs using the Altera Monitor Program

177

Page 178: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 4: FPGA Peripherals

We will use the red LEDs, seven-segment display and the slider switches

In the DE1-SoC, they are connecting to the Lightweight HPS-to-FPGA bridge using the Altera Parallel I/O (PIO) component

178

Page 179: Altera University Program Cyclone V SoC Course Blair Fort

PIO Components

Parallel I/O (PIO) Component- Depending on the PIO’s settings, not

are registers are usable

179

Edgecapture Register

Data Register

Direction Register

Interruptmask Register

Page 180: Altera University Program Cyclone V SoC Course Blair Fort

PIO Components

Parallel I/O (PIO) Component- Depending on the PIO’s settings, not

are registers are usable

DE1-SoC Computer- Red LEDs

Base address: 0xFF200000

- Seven segment displays Base address: 0xFF200020

- Slider switches Base address: 0xFF200040

180

Edgecapture Register

Data Register

Direction Register

Interruptmask Register

Page 181: Altera University Program Cyclone V SoC Course Blair Fort

Program

Read switches and display on LEDs and 7-Segs

181

int main(void)(volatile int * LEDs = (int *) 0xFF200000;volatile int * HEX3_HEX0 = (int *) 0xFF200020;volatile int * SW_switch = (int *) 0xFF200040;int hex_conversions[16] = {0x3F, ..., 0x71};while(1){

int value = *SW_switch;*LEDs = value;int first_digit = value & 0xF;int second_digit = (value >> 4) & 0xF;

int third_digit = (value >> 8) & 0xF;int hex_value = hex_conversions[first_digit];hex_value |= hex_conversions[second_digit] << 8;hex_value |= hex_conversions[third_digit] << 16;*HEX3_HEX0 = hex_value;

}}

Page 182: Altera University Program Cyclone V SoC Course Blair Fort

Step 1: Create a New Project

Sets up the Altera Monitor Program- Select files to work with- Specify target system

182

Page 183: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.1: Specify name, directory and architecture

183

Page 184: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.2: Select the DE1-SoC Computer System

184

Page 185: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.3: Select Program Type

185

Page 186: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.4: Add Source File

186

Page 187: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.5: Set Board Connection and Select Processor

187

Page 188: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.6: Leave Default Memory Settings

188

Page 189: Altera University Program Cyclone V SoC Course Blair Fort

Step 2: Program the FPGA with the Computer System

189

Page 190: Altera University Program Cyclone V SoC Course Blair Fort

Step 3: Compile and Load

190

Compile your C language program

Load the compiled code into the memory on the DE1-SoC board

Page 191: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Jump to the FPGA’s Address Range

191

Page 192: Altera University Program Cyclone V SoC Course Blair Fort

Step 5: Read the Switches, LEDs and 7-Segs Locations

192

Page 193: Altera University Program Cyclone V SoC Course Blair Fort

Step 6: Toggle Some Switches and Re-read

193

Page 194: Altera University Program Cyclone V SoC Course Blair Fort

Step 7: Write Some Values to the LEGs and 7-Segs

194

Page 195: Altera University Program Cyclone V SoC Course Blair Fort

Step 8: Go to the Main Function

195

Page 196: Altera University Program Cyclone V SoC Course Blair Fort

Step 9: Set a Breakpoint at the Load from Switches

196

Page 197: Altera University Program Cyclone V SoC Course Blair Fort

Step 10: Toggle Some Switches and then Single Step

197

Page 198: Altera University Program Cyclone V SoC Course Blair Fort

Step 11: Single Step until the LEDs are Set

198

Page 199: Altera University Program Cyclone V SoC Course Blair Fort

Step 12: Single Step or Run

199

Page 200: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Can FPGA Components access the HPS Memory?

200

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

FPGA

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController

Bridges

On-Chip Cores

Ports

LEDRSwitches

Etc.

SDRAMWindow

Boot Region

FPGASlave

Region

0 GB

1 GB

2 GB

3 GB

4 GBPeripherals

Page 201: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Yes, by using the FPGA to HPS bridge.

201

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

FPGA

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController

F2H

On-Chip Cores

Ports

LEDRSwitches

Etc.

SDRAMWindow

FPGASlave

Region

0 GB

1 GB

2 GB

3 GB

4 GBPeripherals

Page 202: Altera University Program Cyclone V SoC Course Blair Fort

HPS

What about the MPCore’s Cached Data?

202

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

FPGA

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController

F2H

On-Chip Cores

Ports

LEDRSwitches

Etc.

SDRAMWindow

FPGASlave

Region

0 GB

1 GB

2 GB

3 GB

4 GBPeripherals

Page 203: Altera University Program Cyclone V SoC Course Blair Fort

HPS

Accelerator Coherency Port (ACP)

203

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

FPGA

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController

F2H

On-Chip Cores

Ports

LEDRSwitches

Etc.

SDRAMWindow

FPGASlave

Region

0 GB

1 GB

2 GB

3 GB

4 GBPeripherals

ACP ACPWindow

Page 204: Altera University Program Cyclone V SoC Course Blair Fort

HPS

What if the FPGA Requires Access to the SDRAM?

204

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

FPGA

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController

Bridges

On-Chip Cores

Ports

LEDRSwitches

Etc.

0 GB

1 GB

2 GB

3 GB

4 GB

SDRAMWindow

FPGASlave

Region

Peripherals

ACPWindow

Page 205: Altera University Program Cyclone V SoC Course Blair Fort

HPS

FPGA to SDRAM Direct Access

205

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

FPGA

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController

Bridges

On-Chip Cores

Ports

LEDRSwitches

Etc.

SDRAM

SDRAM

0 GB

1 GB

2 GB

3 GB

4 GB

Page 206: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 5: Semihosting

Virtual Operating System

Allows C programs to make system calls- I/O functions- Time functions- File operations

Altera Monitor Program supports a subset- printf and scanf to and from the terminal window.- Some time functions

206

Page 207: Altera University Program Cyclone V SoC Course Blair Fort

Program

Printf, scanf and time functions

207

#include <stdio.h>#include <time.h>

int main(void)(char str[64];int age = 0;// Get the initial timestampclock_t start_time = clock();while(1){

printf("What is your name?\n");scanf("%s",str);printf("What is your age?\n");scanf("%d",&age);...

}return 0;

}

Page 208: Altera University Program Cyclone V SoC Course Blair Fort

Step 1: Create a New Project

Sets up the Altera Monitor Program- Select files to work with- Specify target system

208

Page 209: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.1: Specify name, directory and architecture

209

Page 210: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.2: Select the DE1-SoC Computer System

210

Page 211: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.3: Select Program Type and Sample Program

211

Page 212: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.4: Automatically Includes Example’s Source Files

212

Page 213: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.5: Set Board Connection and Select Processor

213

Page 214: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.6: Leave Default Memory Settings

214

Page 215: Altera University Program Cyclone V SoC Course Blair Fort

Step 2: Program the FPGA with the Computer System

215

Page 216: Altera University Program Cyclone V SoC Course Blair Fort

Step 3: Compile and Load

216

Compile your C language program

Load the compiled code into the memory on the DE1-SoC board

Page 217: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Run

217

Page 218: Altera University Program Cyclone V SoC Course Blair Fort

Step 5: Type in your name

218

Page 219: Altera University Program Cyclone V SoC Course Blair Fort

Step 6: Type in your age

219

Page 220: Altera University Program Cyclone V SoC Course Blair Fort

Step 7: See the Result of the Semi-hosting Functions

220

Page 221: Altera University Program Cyclone V SoC Course Blair Fort

Typical ARM Cortex-A9 Boot Sequence

Boot ROM- Hard coded by Altera- Determines the boot source by reading the boot select pins

Preloader- In Flash/SD Card or FPGA- Typically initializes the DDR3 SDRAM and HPS I/O pins

Boot loader- Loads and starts the operating system

221

Page 222: Altera University Program Cyclone V SoC Course Blair Fort

Boot Sequence with Altera Monitor Program

Resets the HPS

Halts the code in the Boot ROM

Loads a preloader into the HPS on-chip RAM- Preloader comes pre-compiled with the Monitor Program- Initializes the DDR3 SDRAM and HPS I/O pins- Enables the HPS-FPGA bridges- Disables the watchdog timers- Re-maps the DDR3 SDRAM to address 0x00000000

Loads the user’s code into the DDR3 SDRAM- Pauses the processor at the first instruction

222

Page 223: Altera University Program Cyclone V SoC Course Blair Fort

Summary #2

What did we learn?- Altera HPS peripherals- Memory layout of the HPS - How to communicate between the HPS and FPGA- ARM Cortex-A9 Boot Sequence

Where did we go from here?- Tutorials:

Introduction to the ARM Processor Altera Monitor Program Tutorial for ARM DE1-SoC Computer System

- http://university.altera.com

- Literature: Cyclone V Handbook

- http://www.altera.com/literature/lit-cyclone-v.jsp Address Map for HPS

- http://www.altera.com/literature/hb/cyclone-v/hps.html

223

Page 224: Altera University Program Cyclone V SoC Course Blair Fort

ARM’s Generic Interrupt Controller

Tutorial #3

Page 225: Altera University Program Cyclone V SoC Course Blair Fort

Processor Modes

ARM processor modes- User Non-privileged execution (user programs)- Supervisor (SVC) 1 Privileged execution (OS code)- Abort Error condition mode- Undefined Undefined instruction fetched- System “Same” as Supervisor- IRQ 2 Interrupt mode- FIQ Fast interrupt mode- Monitor Secure mode (only for “security extensions”)

1. The ARM A9 is in SVC mode after being reset2. IRQ mode is entered when a hardware interrupt occurs

225

Page 226: Altera University Program Cyclone V SoC Course Blair Fort

Current Program Status Register

The Current Program Status Register (CPSR) includes mode bits: writing to these bits can change the mode

226

Processor mode: 10000 (User), 10001 (FIQ), 10010 (IRQ), 10011 (SVC), 10111 (Abort), 11011 (Undefined), 11111 (System)

Page 227: Altera University Program Cyclone V SoC Course Blair Fort

ARM Banked Registers for each Mode

Separate copies exist of some registers in each mode

Each mode has a unique SP and LR

SPSR is a saved copy of previous CPSR

227

Page 228: Altera University Program Cyclone V SoC Course Blair Fort

Modes and Exceptions

Processor mode can be changed manuallyMOV R1, #0x12 // mode bit pattern for IRQ mode

MSR CPSR, R1 // change to IRQ mode

Processor mode can be changed due to an exception

Reset of the ARM processor Error conditions

- fetched an unimplemented instruction- unaligned word read/write- unaligned instruction fetch

Execution of the SVC instruction causes an exception External hardware interrupt

228

Page 229: Altera University Program Cyclone V SoC Course Blair Fort

Exception Processing

main:

instructioninstruction…instructioninstruction…

229

Exception

The ARM processor automatically:

1. Saves CPSR into banked SPRS2. Saves return address into banked LR3. Changes CPSR to reflect the Exception Mode4. Fetches instruction from exception vector table

Page 230: Altera University Program Cyclone V SoC Course Blair Fort

Exception Vector Table

Address Exception Priority Mode entered

0x0 Reset 1 SVC

0x4 Unimplemented instruction

6 Undefined

0x8 SVC instruction - SVC

0xC Data access violation

2 Abort

0x10 Instruction access violation

5 Abort

0x18 Interrupt 4 IRQ

0x1C Fast interrupt 3 FIQ

230

Page 231: Altera University Program Cyclone V SoC Course Blair Fort

Returning from an Exception

The LR is “related” to the return address:

Example: SUBS PC, LR, #4 // returns from IRQ handler

Note: SUBS with destination PC means “return from exception”. It causes SPSR to be restored back into CPSR!

231

Processor mode Return address

Data Abort LR-8

IRQ, FIQ, pre-fetch Abort LR-4

SVC instruction LR

Undefined instruction LR

Page 232: Altera University Program Cyclone V SoC Course Blair Fort

Exception Vector Table (Assembly code)

.section .vectors, “ax”

B _start // reset vector

B SERVICE_UND // undefined instruction vector

B SERVICE_SVC // software interrrupt vector

B SERVICE_ABT_INST // aborted prefetch vector

B SERVICE_ABT_DATA // aborted data vector

.word 0 // unused vector

B SERVICE_IRQ // IRQ interrupt vector

B SERVICE_FIQ // FIQ interrupt vector

.text

Main: …

SERVICE_IRQ:

// code for handling the IRQ exception goes here

SUBS PC, LR, #4 // return from IRQ mode

232

Page 233: Altera University Program Cyclone V SoC Course Blair Fort

Exception Handlers (and Vectors) in C code

// Define the IRQ exception handlers void __attribute__ ((interrupt)) __cs3_reset (void) { … }void __attribute__ ((interrupt)) __cs3_isr_undef (void) { … }void __attribute__ ((interrupt)) __cs3_isr_swi (void) { … }void __attribute__ ((interrupt)) __cs3_isr_pabort (void) { … }void __attribute__ ((interrupt)) __cs3_isr_dabort (void) { …}void __attribute__ ((interrupt)) __cs3_isr_irq (void){

code for handling the IRQ exception goes here … }void __attribute__ ((interrupt)) __cs3_isr_fiq (void) { … }

The C compiler and linker will automatically make the exception vector table

233

Page 234: Altera University Program Cyclone V SoC Course Blair Fort

ARM Interrupt Architecture

GIC: handles up to 255 interrupt sources; sends IRQ to either/both A9 Cores

234

Various peripherals, MMU, etc.

Peripheral IRQPeripheral IRQ

Peripheral IRQ

A9 Core A9 Core

IRQ IRQ

Generic Interrupt Controller (GIC)

Page 235: Altera University Program Cyclone V SoC Course Blair Fort

Generic Interrupt Controller (GIC)

PPI: private peripheral interrupt (IRQ for a specific processor) SPI: share peripheral interrupt (IRQ for either processor)

SGI: software generated interrupt (IRQ caused by writing to

a special register in the GIC

235

Page 236: Altera University Program Cyclone V SoC Course Blair Fort

Interrupt IDs

Each peripheral is assigned an interrupt ID DE1-SoC Computer Interrupt IDs:

236

Page 237: Altera University Program Cyclone V SoC Course Blair Fort

GIC Example

KEY interrupt signal is received by Distributor. If ID 73 is enabled for CPU 0, send to CPU Interface 0, which can send to A9 core

237

Pushbutton KEYIRQ 73

(ID 73)

Page 238: Altera University Program Cyclone V SoC Course Blair Fort

Summary of Interrupt-driven Code

1. Set up vector table

2. Main program initializes SP for IRQ mode, initializes GIC for each interrupt ID, initializes peripherals (like KEY port), enables interrupts on A9 processor (CPSR bit I = 0), then loops

3. Exception handler for IRQi. Queries GIC to find the interrupt IDii. Calls the appropriate interrupt service routine (ISR)iii. Returns from exception (SUBS PC, LR, #4)

4. Interrupt Service Routine (ISR)i. Clears interrupt sourceii. Performs interrupt function

238

Page 239: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 6: Handling Interrupts

We will look at the code required for handling interrupts generated by the FPGA’s pushbutton keys- 1. Assembly code- 2. C code

239

Page 240: Altera University Program Cyclone V SoC Course Blair Fort

Handling Interrupts: Assembly Code

Step 1: Set up vector table

240

.section .vectors, "ax"

B _start // reset vectorB SERVICE_UND // undefined instruction vectorB SERVICE_SVC // software interrrupt vectorB SERVICE_ABT_INST // aborted prefetch vectorB SERVICE_ABT_DATA // aborted data vector.word 0 // unused vectorB SERVICE_IRQ // IRQ interrupt vectorB SERVICE_FIQ // FIQ interrupt vector

Page 241: Altera University Program Cyclone V SoC Course Blair Fort

Handling Interrupts: Assembly Code

Step 2: Set stack pointers

241

/* Set up stack pointers for IRQ and SVC processor modes */MOV R1, #INT_DISABLE | IRQ_MODEMSR CPSR_c, R1 // change to IRQ modeLDR SP, =A9_ONCHIP_END - 3 // set IRQ stack to top of A9 onchip memory/* Change to SVC (supervisor) mode with interrupts disabled */MOV R1, #INT_DISABLE | SVC_MODEMSR CPSR, R1 // change to supervisor modeLDR SP, =DDR_END - 3 // set SVC stack to top of DDR3 memory

Page 242: Altera University Program Cyclone V SoC Course Blair Fort

Handling Interrupts: Assembly Code

Step 2: Enable interrupts

242

/* To configure the FPGA KEYS interrupt (ID 73): * 1. set the target to cpu0 in the ICDIPTRn register (addr 0xFFFED848) * 2. enable the interrupt in the ICDISERn register (addr 0xFFFED108) */LDR R0, =0xFFFED848 // ICDIPTRn: processor targets registerLDR R1, =0x00000100 // set targets to cpu0STR R1, [R0]

LDR R0, =0xFFFED108 // ICDISERn: set enable registerLDR R1, =0x00000200 // set interrupt enableSTR R1, [R0]

...

Page 243: Altera University Program Cyclone V SoC Course Blair Fort

Handling Interrupts: Assembly Code

Step 3: Exception Handler

243

SERVICE_IRQ:PUSH {R0-R7, LR}/* Read the ICCIAR from the CPU interface */LDR R4, =MPCORE_GIC_CPUIFLDR R5, [R4, #ICCIAR] // read the interrupt ID

FPGA_IRQ1_HANDLER:CMP R5, #FPGA_IRQ1

UNEXPECTED:BNE UNEXPECTED // if not recognized, stop hereBL KEY_ISR

EXIT_IRQ: /* Write to the End of Interrupt Register (ICCEOIR) */STR R5, [R4, #ICCEOIR]POP {R0-R7, LR}SUBS PC, LR, #

Page 244: Altera University Program Cyclone V SoC Course Blair Fort

Handling Interrupts: Assembly Code

Step 4: Interrupt Service Routine (ISR)

244

KEY_ISR:LDR R0, =KEY_BASE // base address of pushbutton KEY parallel portLDR R1, [R0, #0xC] // read edge capture registerMOV R2, #0xFSTR R2, [R0, #0xC] // clear the interrupt

...

END_KEY_ISR:BX LR

Page 245: Altera University Program Cyclone V SoC Course Blair Fort

Step 1: Create a New Project

Sets up the Altera Monitor Program- Select files to work with- Specify target system

245

Page 246: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.1: Specify name, directory and architecture

246

Page 247: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.2: Select the DE1-SoC Computer System

247

Page 248: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.3: Select Program Type

248

Page 249: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.4: Add Source File

249

Page 250: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.5: Set Board Connection and Select Processor

250

Page 251: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.6: Choose the Exceptions Memory Settings

251

Page 252: Altera University Program Cyclone V SoC Course Blair Fort

Step 2: Program the FPGA with the Computer System

252

Page 253: Altera University Program Cyclone V SoC Course Blair Fort

Step 3: Compile and Load

253

Compile your assembly language program

Load the compiled code into the memory on the DE1-SoC board

Page 254: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Notice the Starting Address

254

Page 255: Altera University Program Cyclone V SoC Course Blair Fort

Step 5: Look at the Vector Table

255

Page 256: Altera University Program Cyclone V SoC Course Blair Fort

Step 6: Look at the Exception Handler

256

Page 257: Altera University Program Cyclone V SoC Course Blair Fort

Step 7: Look at the Interrupt Service Routine

257

Page 258: Altera University Program Cyclone V SoC Course Blair Fort

Step 8: Set a Breakpoint at the Beginning of the ISR

258

Page 259: Altera University Program Cyclone V SoC Course Blair Fort

Step 9: Single Step and Notice the Change of Mode

259

Page 260: Altera University Program Cyclone V SoC Course Blair Fort

Step 10: Single Step and Notice the new Stack Pointer

260

Page 261: Altera University Program Cyclone V SoC Course Blair Fort

Step 11: Single Step and Notice the Change of Mode

261

Page 262: Altera University Program Cyclone V SoC Course Blair Fort

Step 12: Single Step and Notice the new Stack Pointer

262

Page 263: Altera University Program Cyclone V SoC Course Blair Fort

Step 13: Run the Program

263

Page 264: Altera University Program Cyclone V SoC Course Blair Fort

Step 14: Single Step Through the ISR

264

Page 265: Altera University Program Cyclone V SoC Course Blair Fort

Step 15: See the value of the Edge Capture Register

265

Page 266: Altera University Program Cyclone V SoC Course Blair Fort

Handling Interrupts: C Language Code

Step 1: Set up vector table

266

// Define the remaining exception handlersvoid __attribute__ ((interrupt)) __cs3_reset (void){ while(1);}

void __attribute__ ((interrupt)) __cs3_isr_undef (void){ while(1);}

...

Page 267: Altera University Program Cyclone V SoC Course Blair Fort

Handling Interrupts: C Language Code

Step 2: Set stack pointers

267

int stack, mode;// top of A9 onchip memory, aligned to 8 bytesstack = A9_ONCHIP_END - 7;

/* change processor to IRQ mode with interrupts disabled */mode = INT_DISABLE | IRQ_MODE;asm("msr cpsr, %[ps]" : : [ps] "r" (mode));/* set banked stack pointer */asm("mov sp, %[ps]" : : [ps] "r" (stack));

/* go back to SVC mode before executing subroutine return! */mode = INT_DISABLE | SVC_MODE;asm("msr cpsr, %[ps]" : : [ps] "r" (mode));

Page 268: Altera University Program Cyclone V SoC Course Blair Fort

Handling Interrupts: C Language Code

Step 2: Enable interrupts

268

/* configure the FPGA KEYs interrupts */*((int *) 0xFFFED848) = 0x00000100;*((int *) 0xFFFED108) = 0x00000200;

...

Page 269: Altera University Program Cyclone V SoC Course Blair Fort

Handling Interrupts: C Language Code

Step 3: Exception Handler

269

void __attribute__ ((interrupt)) __cs3_isr_irq (void){

// Read the ICCIAR from the processor interface int address = MPCORE_GIC_CPUIF + ICCIAR; int int_ID = *((int *) address);

if (int_ID == KEYS_IRQ) // check if interrupt is from the KEYs

pushbutton_ISR ();else

while (1); // if unexpected, then stay here

// Write to the End of Interrupt Register (ICCEOIR)address = MPCORE_GIC_CPUIF + ICCEOIR;*((int *) address) = int_ID;

return;}

Page 270: Altera University Program Cyclone V SoC Course Blair Fort

Handling Interrupts: C Language Code

Step 4: Interrupt Service Routine (ISR)

270

void pushbutton_ISR( void ){

volatile int * KEY_ptr = (int *) KEY_BASE;volatile int * HEX3_HEX0_ptr = (int *) HEX3_HEX0_BASE;int press, HEX_bits;

press = *(KEY_ptr + 3); // read the pushbutton interrupt register*(KEY_ptr + 3) = press; // Clear the interrupt

...

return;}

Page 271: Altera University Program Cyclone V SoC Course Blair Fort

Step 1: Create a New Project

Sets up the Altera Monitor Program- Select files to work with- Specify target system

271

Page 272: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.1: Specify name, directory and architecture

272

Page 273: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.2: Select the DE1-SoC Computer System

273

Page 274: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.3: Select Program Type

274

Page 275: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.4: Add C Source File

275

Page 276: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.5: Set Board Connection and Select Processor

276

Page 277: Altera University Program Cyclone V SoC Course Blair Fort

Step 1.6: Choose the Exceptions Memory Settings

277

Page 278: Altera University Program Cyclone V SoC Course Blair Fort

Step 2: Program the FPGA with the Computer System

278

Page 279: Altera University Program Cyclone V SoC Course Blair Fort

Step 3: Compile and Load

279

Compile your C language program

Load the compiled code into the memory on the DE1-SoC board

Page 280: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Look at the Exception Handler

280

Page 281: Altera University Program Cyclone V SoC Course Blair Fort

Step 5: Set a Breakpoint at the Interrupt Service Routine

281

Page 282: Altera University Program Cyclone V SoC Course Blair Fort

Step 6: Set a Breakpoint and Run to the Main Function

282

Page 283: Altera University Program Cyclone V SoC Course Blair Fort

Step 7: Single Step through Setting the Stack Pointers

283

Page 284: Altera University Program Cyclone V SoC Course Blair Fort

Step 8: Run the Program

284

Page 285: Altera University Program Cyclone V SoC Course Blair Fort

Summary #3

What did we learn?- Banked registers- Generic Interrupt Controller- Setting the stack pointers

Where did we go from here?- Tutorials:

Introduction to the ARM Processor Altera Monitor Program Tutorial for ARM DE1-SoC Computer System

- http://university.altera.com- Literature:

Cyclone V Handbook- http://www.altera.com/literature/lit-cyclone-v.jsp

285

Page 286: Altera University Program Cyclone V SoC Course Blair Fort

Creating a Custom FPGA System for ARM

Tutorial #4

Page 287: Altera University Program Cyclone V SoC Course Blair Fort

HPS

What if you want to create a custom system?

287

Boot ROM

Ports

MPCore

On-Chip RAM

GPIO

FPGA

Timers

DDR3Chips

LEDGKEY

USBEthernet

L2 Cache

SDRAMController

Bridges

On-Chip Cores

Ports

LEDRSwitches

Etc.

Page 288: Altera University Program Cyclone V SoC Course Blair Fort

Quartus II System Integration Tool (Qsys)

288

Page 289: Altera University Program Cyclone V SoC Course Blair Fort

Qsys Windows

289

Selected ComponentsAnd connectivity

Messages

AvailableComponents

Page 290: Altera University Program Cyclone V SoC Course Blair Fort

Select Components to add to the System

290

Page 291: Altera University Program Cyclone V SoC Course Blair Fort

Configure the Components using their Wizards

291

Page 292: Altera University Program Cyclone V SoC Course Blair Fort

HPS Component:Adding/Removing FPGA to SDRAM Bridges

292

Page 293: Altera University Program Cyclone V SoC Course Blair Fort

HPS Component: Editing HPS Peripherals

293

Page 294: Altera University Program Cyclone V SoC Course Blair Fort

HPS Component: Editing SDRAM Parameters

294

Page 295: Altera University Program Cyclone V SoC Course Blair Fort

Component is now in the System

295

Page 296: Altera University Program Cyclone V SoC Course Blair Fort

Creating a Custom System

Select a processor- Altera HPS or a Nios II

Add off-the-shelf with standard interfaces (SPI, I2C, JTAG, etc.) to help solve the problem- Use existing drivers or write one yourself- Sometimes an existing driver needs to be augmented for a particular

application

Add custom components when the needed ones are not available (or too expensive)

Add I/O as needed Write code to run on the system

- Usually a single program

296

Page 297: Altera University Program Cyclone V SoC Course Blair Fort

How to put them together?

Qsys system integration tool- Add components

Quartus II software- Synthesize circuit for the FPGA

Altera Monitor Program- For compiling and debugging software

297

Page 298: Altera University Program Cyclone V SoC Course Blair Fort

Hands-on Session 4

Build a system using the Qsys system integration tool

Compile the system using the Quartus II software

Download the system to the board

Run the previous software application

298

Page 299: Altera University Program Cyclone V SoC Course Blair Fort

Exercise 7: Making a Custom System

Using Qsys make a system with:

- Altera HPS component

- PIO cores for: Red LEDs Seven Segments Displays Slider switches

299

Page 300: Altera University Program Cyclone V SoC Course Blair Fort

Step 1: Open the DE1_SoC Project in Quartus II

300

Page 301: Altera University Program Cyclone V SoC Course Blair Fort

Step 2: Open the DE1_SoC Project in Quartus II

301

Page 302: Altera University Program Cyclone V SoC Course Blair Fort

Step 3: Launch Qsys

302

Page 303: Altera University Program Cyclone V SoC Course Blair Fort

Step 4: Select the Computer System

303

Page 304: Altera University Program Cyclone V SoC Course Blair Fort

Step 5: The Pre-Started System

304

Page 305: Altera University Program Cyclone V SoC Course Blair Fort

Step 6: Add PIO Component for the LEDRs

305

Page 306: Altera University Program Cyclone V SoC Course Blair Fort

Step 7: Configure the PIO for the LEDRs

306

Page 307: Altera University Program Cyclone V SoC Course Blair Fort

Step 8: Add and Configure a PIO for the 7-Segs

307

Page 308: Altera University Program Cyclone V SoC Course Blair Fort

Step 9: Add and Configure a PIO for the Switches

308

Page 309: Altera University Program Cyclone V SoC Course Blair Fort

Step 10: Current System

309

Page 310: Altera University Program Cyclone V SoC Course Blair Fort

Step 11: Export PIOs’ External Connections

310

Page 312: Altera University Program Cyclone V SoC Course Blair Fort

Step 13: Make Connections

312

Page 313: Altera University Program Cyclone V SoC Course Blair Fort

Step 14: Go to Address Map Tab

313

Page 314: Altera University Program Cyclone V SoC Course Blair Fort

Step 15: Set the Slave Addresses

314

Page 315: Altera University Program Cyclone V SoC Course Blair Fort

Step 16: Generate the System

315

Page 316: Altera University Program Cyclone V SoC Course Blair Fort

Step 17: Generate the System

316

Page 317: Altera University Program Cyclone V SoC Course Blair Fort

Step 18: System Generation Finished

317

Page 318: Altera University Program Cyclone V SoC Course Blair Fort

Step 18: Generated System

318

FPGA

LEDs

7-Segs

Switches

HPSHPS

module Computer_System (clk_clk,reset_reset_n,

// LEDsledr_export,

// Seven Segshex3_hex0_export,

// Slider Switchessw_export,

...);

Page 319: Altera University Program Cyclone V SoC Course Blair Fort

Step 19: Create Top Level File for project

System must be instantiated in your design- Must connect system ports to the I/O ports

In this demo the top level file has been created for you- Compile your project.

Approximately 2 minutes.- Open the DE1_SoC.v to examine the system connectivity while Quartus II

compiles the project.

319

Page 320: Altera University Program Cyclone V SoC Course Blair Fort

Step 20: Compile the System in Quartus II

320

Page 321: Altera University Program Cyclone V SoC Course Blair Fort

Step 21: Wait for Compilation to Finish

321

Page 322: Altera University Program Cyclone V SoC Course Blair Fort

Step 22: Create a New Project

Sets up the Altera Monitor Program- Select files to work with- Specify target system

322

Page 323: Altera University Program Cyclone V SoC Course Blair Fort

Step 22.1: Specify name, directory and architecture

323

Page 324: Altera University Program Cyclone V SoC Course Blair Fort

Step 22.2: Select a Custom System

324

Page 325: Altera University Program Cyclone V SoC Course Blair Fort

Step 22.3: Select Program Type

325

Page 326: Altera University Program Cyclone V SoC Course Blair Fort

Step 22.4: Add Source File

326

Page 327: Altera University Program Cyclone V SoC Course Blair Fort

Step 22.5: Set Board Connection and Select Processor

327

Page 328: Altera University Program Cyclone V SoC Course Blair Fort

Step 22.6: Leave Default Memory Settings

328

Page 329: Altera University Program Cyclone V SoC Course Blair Fort

Step 23: Program the FPGA with the Custom System

329

Page 330: Altera University Program Cyclone V SoC Course Blair Fort

Step 24: Compile and Load

330

Compile your C language program

Load the compiled code into the memory on the DE1-SoC board

Page 331: Altera University Program Cyclone V SoC Course Blair Fort

Step 25: View Memory Content

331

Page 332: Altera University Program Cyclone V SoC Course Blair Fort

Step 26: Run the Program

332

Page 333: Altera University Program Cyclone V SoC Course Blair Fort

Summary #4

What did we learn?- How to create a custom system with the Altera HPS component

Where did we go from here?- Tutorials:

Introduction to the Altera Qsys System Integration Tool Making Qsys Components Quartus II Introduction

- http://university.altera.com

- Literature: Quartus II Handbook

- Volume 1: Section II. System Design with Qsys- http://www.altera.com/literature/lit-qts.jsp

333

Page 334: Altera University Program Cyclone V SoC Course Blair Fort

Other Tools

Tutorial #5

Page 335: Altera University Program Cyclone V SoC Course Blair Fort

ARM DS-5 Altera Edition

ARM Development Studio 5 (DS-5)- Eclipse Based IDE- Baremetal & Linux Development and Debug

335

Page 336: Altera University Program Cyclone V SoC Course Blair Fort

What Makes DS-5 FPGA Adaptive?

Altera USB-Blaster Support- A single cable to debug FPGA & SOC simultaneously

QSys CMSIS Generation and Peripheral Discovery- DS-5 automatically adapts to the peripherals on the FPGA

Cross-triggering between the CPU and FPGA domains- Want to know why that Soft IP keeps sending unexpected interrupts?

Add customer performance counters in FPGA fabric to DS-5 Streamline

CoreSight compatible FPGA IP is visible from DS-5- Make your very own non-intrusive debug-able IP core

336

Page 337: Altera University Program Cyclone V SoC Course Blair Fort

StreamlineSystem-Level Performance Analysis

Performance analysis of Linux systems- Profiling reports from process-level

down to assembly level- Support for software events and

CPU performance counters- Requires only a TCP connection

to the target

Streamline enables- Analyse how your software runs

on single & multi-core targets- Spot bottlenecks and code

inefficiencies- Can also analyse power usage with a third party adapter

337

Page 338: Altera University Program Cyclone V SoC Course Blair Fort

Keil

338

Page 339: Altera University Program Cyclone V SoC Course Blair Fort

Keil

339

Page 340: Altera University Program Cyclone V SoC Course Blair Fort

Summary #5

What did we learn?- About other available tools for ARM

Where did we go from here?- Tutorials:

Introduction to the ARM Processor Using ARM Toolchain- http://university.altera.com

- Literature: Altera SoC Embedded Design Suite User Guide

- http://www.altera.com/literature/lit-soc.jsp

- Software: ARM DS-5 License Request

- http://www.arm.com/support/university/educators/processor/microprocessor-systemsapplications-software-tools-for-educators.php

Keil- http://www.keil.com/

340

Page 341: Altera University Program Cyclone V SoC Course Blair Fort

Thank You

http://university.altera.com/

[email protected]