Edk 8.1 Microblaze Tutorial in Spartan 3: Objectives
Edk 8.1 Microblaze Tutorial in Spartan 3: Objectives
Edk 8.1 Microblaze Tutorial in Spartan 3: Objectives
System Requirements
Tutorial Steps
Starting XPS
System Requirements
You must have the following software installed on your PC to complete this tutorial:
In order to download the completed processor system, you must have the following hardware:
Serial Cable
Note: It should be noted that other hardware could be used with this tutorial. However, the completed design
has only been verified on the board specified above. The following design changes are required:
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
Hardware components
Memory map
Software application
MicroBlaze
LMB_BRAM_IF_CNTLR
BRAM_BLOCK
OPB_MDM
OPB_UARTLITE
3 - OPB_GPIOs
OPB_EMC
Address
Min
0x0000_0000
0x4140_0000
0x4060_0000
0x4002_0000
0x4000_0000
0x4004_0000
0x2010_0000
Max
0x0000_1FFF
0x4140_FFFF
0x4060_FFFF
0x4002_FFFF
0x4000_FFFF
0x4004_FFFF
0x201F_FFFF
Size
8K bytes
64K bytes
64K bytes
64K bytes
64K bytes
64K bytes
512K bytes
Comment
LMB Memory
MDM Module
Serial Output
LED output
Push Buttons
DIP switches
SRAM Memory
Tutorial Steps
SetUp
Spartan-3 board with a RS-232 terminal connected to the serial port and configured for 57600 baud, with 8 data
bits, no parity and no handshakes.
www.xilinx.com
1-800-255-7778
An editor and a project management interface for creating and editing source code
Project Navigator project file that allows you to control the hardware implementation flow
XPS supports the software tool flows associated with these software specifications. Additionally, you can use XPS to
customize software libraries, drivers, and interrupt handlers, and to compile your programs.
Starting XPS
To open XPS, select Start Programs Xilinx Platform Studio 8.1i Xilinx Platform Studio
Select Base System Builder Wizard (BSB) to open the Create New Project Using BSB Wizard dialog box shown
in Figure 1.
Click Ok.
Use the Project File Browse button to browse to the folder you want as your project directory.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
MHS File
The Microprocessor Hardware Specification (MHS) file describes the following:
Embedded processor: either the soft core MicroBlaze processor or the hard core PowerPC (only available in
Virtex-II Pro and Virtex-4 FX devices)
Buses
The MHS file is a readable text file that is an input to the Platform Generator (the hardware system building tool).
Conceptually, the MHS file is a textual schematic of the embedded system. To instantiate a component in the MHS file,
you must include information specific to the component.
MPD File
Each system peripheral has a corresponding MPD file. The MPD file is the symbol of the embedded system peripheral to
the MHS schematic of the embedded system. The MPD file contains all of the available ports and hardware parameters
for a peripheral. The tutorial MPD file is located in the following directory:
$XILINX_EDK/hw/XilinxProcessorIPLib/pcores/<peripheral_name>/data
Note: For more information on the MPD and MHS files, refer to the Microprocessor Peripheral Description
(MPD) and Microprocessor Hardware Specification (MHS) chapters in the Embedded System Tools Guide.
EDK provides two methods for creating the MHS file. Base System Builder Wizard and the Add/Edit Cores Dialog assist
you in building the processor system, which is defined in the MHS file. This tutorial illustrates the Base System Builder.
In the Base System Builder Select I would like to create a new design then click Next.
In the Base System Builder - Select Board Dialog select the following, as shown in Figure 2:
Board Vendor:
Xilinx
Board Name:
Board Revision: E
www.xilinx.com
1-800-255-7778
Click Next. MicroBlaze is the only processor option for this board.
Click Next. You will now specify several processor options as shown in Figure 3:
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
Processor-Bus clock frequency: This is the frequency of the clock driving the processor system.
Processor Configuration:
Debug I/F:
On-Chip H/W Debug module: When the H/W debug module is selected; an OPB MDM module is
included in the hardware system. This introduces hardware intrusive debugging with no software stub
required. This is the recommended way of debugging for MicroBlaze system.
XMD with S/W Debug stub: Selecting this mode of debugging interface introduces a software intrusive
debugging. There is a 1200-byte stub that is located at 0x00000000. This stub communicates with the
debugger on the host through the JTAG interface of the OPB MDM module.
Note: For more information about the Xilinx Microprocessor Debugger (XMD), refer to the Xilinx
Microprocessor Debugger (XMD) chapter in the Embedded System ToolsReference Manual.
www.xilinx.com
1-800-255-7778
Users can specify the size of the local instruction and data memory.
Cache setup:
Enable OPB cache: Caching will be used through the OPB bus
Enable cache link: Caching will be used through the FSL bus
You can also specify the use of the floating point unit (FPU).
Click Next.
Select the peripheral subset as shown in Figure 4 and Figure 5. It should be noted that the number of peripheral shown
on each dialog box is dynamic based upon your computers resolution.
Note: The Baud rate for the OPB UARTLITE must be updated to 57600.
Click Next
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
Click Next through the Add Internal Peripherals page as we will not add any in this example.
This completes the hardware specification and we will now configure the software settings.
Using the Software Setup dialog box as shown in Figure 6, specify the following software settings:
www.xilinx.com
1-800-255-7778
Click Next.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
Instructions ilmb_cntlr
Data dlmb_cntlr
Stack/Heap dlmb_cntlr
Click Next.
The completed system including the memory map will be displayed as shown in Figure 8. Currently the memory map
cannot be changed or updated in the BSB. If you want to change the memory map you can do this in XPS.
10
www.xilinx.com
1-800-255-7778
Review
The Base System Builder Wizard has created the hardware and software specification files that define the processor
system. When we look at the project directory, shown in Figure 9, we see these as system.mhs and system.mss. There
are also some directories created.
data contains the UCF (user constraints file) for the target board.
etc contains system settings for JTAG configuration on the board that is used when downloading the bit file
and the default parameters that are passed to the ISE tools.
TestApp_Memory contains a user application in C code source, for testing the memory in the system.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
11
12
www.xilinx.com
1-800-255-7778
Project Options
To see the project options that Base System Builder has configured select: Project Project Options. As shown in
Figure 10, the device information is specified.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
13
In XPS, select Hardware Create or Import Peripheral to open the Create and Import Peripheral
Wizard.
By default the new peripheral will be stored in the project_directory/pcores directory. This enables XPS to find the core
for utilization during the embedded system development.
Click Next. In the Create Peripheral Name and Version dialog, enter custom_ip as the name of the peripheral.
This is shown in Figure 12.
14
Click Next. In the Create Peripheral Bus Interface dialog, select On-Chip Peripheral Bus (OPB), as this is the
bus to which the new peripheral will be connected.
Click Next. The Create Peripheral IPIF Services dialog enables the selection of several services. For additional
information regarding each of these services, select More Info. Select the User logic S/W register support
option.
www.xilinx.com
1-800-255-7778
Click Next. In the Create Peripheral User S/W Register dialog, change the Number of software accessible
registers to 4.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
15
Click Next. In the Create Peripheral (OPTIONAL) Peripheral Simulation Support dialog, a Bus Functional
Model (BFM) simulation environment can be generated. This tutorial will not cover BFM simulation. Leave the
option unchecked.
Click Next. In the Create Peripheral (OPTIONAL) Peripheral Implementation Support dialog, uncheck the
Generate ISE and XST project files to help you implement the peripheral using XST flow.
The Create or Import Peripheral Wizard creates a new directory called custom_ip_v1_00_a in the pcores directory. This
new directory contains the following:
MB_tutorial\pcores\custom_ip_v1_00_a\hdl
vhdl/custom_ip.vhd
This is the template file for your peripheral's top design entity. It configures and instantiates the
corresponding IPIF unit in the way you indicated in the wizard GUI and connects it to the stub user
logic where the user logic should get implemented. You are not expected to modify this template file
except in certain marked places for adding user specific generics and ports.
vhdl/user_logic.vhd
This is the template file for the stub user logic design entity, either in VHDL or Verilog, where the
actual functionalities should get implemented. Some sample code may be provided for demonstration
purpose.
MB_tutorial\pcores\ custom_ip_v1_00_a\data
custom_ip_v2_1_0.mpd
This Microprocessor Peripheral Description file contains interface information of your peripheral so
that other EDK tools can recognize the peripheral.
custom_ip_v2_1_0.pao
This Peripheral Analysis Order file defines the analysis order of all the HDL source files that are used
to compile your peripheral.
16
www.xilinx.com
1-800-255-7778
Open user_logic.vhd. Currently the code provides an example of reading and writing to four 32-bit registers.
For the purpose of this tutorial, this code will not be modified.
Close user_logic.vhd
In order for XPS to add the new custom IP core to the design, the pcores directory must be rescanned. This can be
accomplished by selecting Project Rescan User Repositories. XPS also automatically rescans the pcores
directory when the project is opened.
Double clicking on any of the IPs listed in the System Assembly View allows modification of that particular IP. The
System Assembly View has the following filters:
Bus Interface filter: With the Bus Interface activated, the patch panel to the left of the System Assembly View gets
activated. The bus connectivity of the core is shown when the hierarchy of the IP is expanded.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
17
Ports filter: With this filter on, the port connections appear when the hierarchy of the IP is expanded. You
need to activate this filter to be able to add external ports.
Addresses filter: The IPs addresses can be viewed when expanding the IP. This is where you can generate addresses for
the IPs.
The IP Catalog tab shows all of the IP that is available to use in the EDK project. To add new IP:
Drag and drop the IP into the System Assembly View or double click on the IP.
18
www.xilinx.com
1-800-255-7778
Select the Default Connection pull down menu and change the clock connection to sys_clk_s
Select the Addresses filter to define an address for the newly added custom_ip peripheral. The address can be assigned
by entering the Base Address or the tool can assign an address. For the purpose of this tutorial, the tool will be used to
assign an address.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
19
Start ISE by selecting Start Programs Xilinx ISE 8.1i Project Navigator.
In ISE, select File New Project to create a new Project Navigator project.
In the New Project dialog box shown in Figure 20, browse to the XPS project directory and then enter the
Project Name, project_navigator.
20
Click Next. Configure the Device and Design flow as shown in Figure 21. It should be noted that these settings
need to be consistent with the XPS project settings.
www.xilinx.com
1-800-255-7778
Click Next. ISE has the ability to add an XPS project file as a new source file. However, the tutorial will not
cover this aspect.
Browse up into the XPS project and add the system.xmp in the New Project Wizard - Add Existing Sources
dialog window.
Click Next
Click Finish
Click OK
Select the system.xmp source file and double click on the View HDL Instantiation Template.
Once the process has completed the editor window will contain the instantiation template called system_stub.vhd.
In ISE, select Project Add Source. Select the system_stub.vhd in the project_navigator directory.
The Source Type is a VHDL Design File.
By adding system_stub.vhd to the Project Navigator project the hierarchy is updated as shown in Figure 22.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
21
In ISE, select Project Add Source. Select the system.ucf file in the <xps_project>\data directory.
Select system_stub.vhd and double click on Generate Programming File to implement the design and generate a
bit file.
ISE will call XPS to generate the EDK to create the following directories:
o
hdl contains the VHDL files that define the processor system
synthesis contains the projects and information from synthesizing the files in the hdl directory to create those
in the implementation directory
Standalone
xilkernel
uclinux
nucleus
22
www.xilinx.com
1-800-255-7778
Select the OS and Libraries view as shown in Figure 24. This view allows the user to configure OS and library
parameters. No changes are required.
Select the Drivers view. This view allows you to select the software versions for the peripherals in the system
as shown in Figure 25. Notice that the driver version is independent of the HW version.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
23
Click OK.
In XPS, select Software Generate Libraries and BSPs to run LibGen and create the BSP which includes
device drivers, libraries, configures the STDIN/STDOUT, and Interrupt handlers associated with the design.
LibGen creates the following directories in the microblaze_0 directory, shown in Figure 26:
o
code: contains the compiled and linked application code in an ELF file
include: contains the header files for peripherals included in the design (such as xgpio.h and
xuartlite.h)
24
Software application code development can be managed by selecting the Applications tab as shown in Figure 27. The
Base System Builder (BSB) generates a sample application which tests a subset of the peripherals included in the design.
Select Software Build All User Applications to run mb-gcc. Mb-gcc compiles the source files.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
25
Connect the host computer to the target board, including connecting the Parallel-JTAG cable and the serial
cable.
com1 This is dependant on the com port your serial cable is connected to.
Data bits:
Parity:
none
Stop bits:
Flow control:
none
In the process window, double click on Update Bitstream with Processor Data
In the process window, double click on Configure Device (iMPACT) under Generate Programming File
With iMPACT, configure the FPGA using system_stub_download.bit located in the project_navigator directory
choosing to bypass all of the other chips in the JTAG chain
After the configuration is complete, you should see a display similar to that in shown in Figure 29:
26
www.xilinx.com
1-800-255-7778
In XPS, select Debug XMD Debug Options. The XMD Debug Options dialog box allows the user to specify
the connections type and JTAG Chain Definition. Three connection types are available for MicroBlaze:
Stub enables XMD to connect to the JTAG UART or UART via XMDSTUB
Virtual platform enables a Virtual (C model) to be used (not covered in this tutorial)
Select Save.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
27
In XPS, select Debug Launch Software Debugger to open the GDB interface.
In GDB, select File Target Settings to display the Target Selection dialog box as shown in Figure 31.
Click OK.
Select executable.elf in the TestApp_Memory directory. The C code is visible because the Create symbols for
debugging (-g option) is selected by default in the compiler options.
In the Applications window of XPS, double click on the Project: TestApp_Memory label.
In the Debug and Optimization tab set the Optimization Level to No Optimization
Click OK.
28
There is an automatic breakpoint at main. GDB allows you to single step the C or assembly code.
Note: The default values displayed in the Registers Window are in hex, while the values displayed in the
Source Window are in decimal.
XPS, select Project Project Options. In the Project Options dialog box select the HDL and Simulation tab.
Browse to the precompiled EDK Library and Xilinx Library as shown in Figure 33. It should be noted that the paths will
be different to match you system. For additional information on compiling the simulation libraries refer to the
Embedded System Tools Reference Manual Chapter 3.
Click Ok.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
29
Select Simulation Generate Simulation HDL Files. This will generate all of the EDK HDL Simulation
files in the EDK\simulation\behavioral directory created by SimGen.
Now that the EDK simulation files have been created, the ISE simulation environment can be created.
In ISE, select system_stub.vhd and double click on Create New Source in the Process Window.
In the New Source dialog, select the source type as VHDL Test Bench and the File Name as testbench
Click Next. Select system_stub as the source file to which the testbench will be associated.
Now select Behavioral Simulation in the Sources window as shown in Figure 34.
www.xilinx.com
1-800-255-7778
In order to populate the BRAMs with the TestApp_Memory Application, a configuration statement must be created.
Add the following after the testbench architecture:
configuration testbench_vhd_conf of testbench_vhd is
for behavior
for uut: system_stub
for STRUCTURE
for system_i : system
use configuration work.system_conf;
end for;
end for;
end for;
end for;
end tb_conf;
Save and close the testbench.vhd file.
Select testbench.vhd in the ISE Source Window. Expand the ModelSim Simulator in the process window then rightclick on the Simulate Behavioral Model and select Properties.
Change the simulation run time to 0ns, select Use Configuration Name and insert testbench_vhd_conf in the
Configuration Name field as shown in Figure 35.
MicroBlaze Tutorial
WT001 (v4.0) January 30, 2006
www.xilinx.com
1-800-255-7778
31
32
www.xilinx.com
1-800-255-7778