Microblaze MCS Tutorial v5
Microblaze MCS Tutorial v5
This tutorial shows how to add a Microblaze Microcontroller System (MCS) embedded processor to a
project including adding a simple C program. The design was targeted to a Spartan 6 FPGA (on a Nexys3
board) but the steps should be general enough to work on other platforms.
Create a new project and then select Project => New Source, and select IP (Core Generator &
Architecture Wizard) (do NOT select the Embedded Processor source type we want the simpler MCS
version) and provide a file name (I used microblaze_mcs in this example)
Note: the file name you provide in the New Source File Name Dialog box will determine the component
name. In the screen shots below this is shown as microblaze_mcs. Later in this tutorial you will need
the name you provided.
Set the Input Clock Frequency to match your Nexys3 board (100MHz)
Increase the memory size from 8KB to 16KB (allows for slightly larger C program)
Note the Instance Hierarchical Design Name mcs_0 (we will need this later)
Select the UART Tab and enable the receiver and transmitter and select your baud rate:
Add an 8-bit GPI (we will connect to the slider switches later):
Click on Generate wait a few minutes (approx. 5 minutes) for the core to be created.
Select the microblaz-mcs core in the Hierarchy Pane then expand the CORE Generator in the Processes
pane and select the View HDL Instantiation Template :
Note: we are using Verilog in this example but by changing the project settings preferred language you
can create a VHDL component instead.
Create a new top level with connections to the clock and peripherals on the Nexys board and then
instantiate the microblaze core by using the instantiation template provided.
Note: you may see a GPI1_Interrupt signal (if so you can ignore this port just leave it open)
Important: Use the component name you used and the instance name mcs_0 mentioned earlier. In this
example the component name is microblaze_mcs and instance name is mcs_0.
Synthesize your project and make sure there are no warnings or errors.
Note: If you are working with the older Nexys2 board (with the Spartan 3E FPGA) you will see three
warning messages similar to the following:
Analyzing top module <mcs>.
WARNING:Xst:2211 - "ipcore_dir/microblaze_mcs.v" line 36: Instantiating black
box module <microblaze_mcs>.
Module <mcs> is correct for synthesis.
WARNING:Xst:616 - Invalid property "SYN_BLACK_BOX 1": Did not attach to mcs_0.
WARNING:Xst:616 - Invalid property "SYN_NOPRUNE 1": Did not attach to mcs_0.
You can ignore these warnings but notice you should still manage to synthesize successfully:
Process "Synthesize - XST" completed successfully
source ipcore_dir/microblaze_mcs_setup.tcl
You should see:
Command>source ipcore_dir/microblaze_mcs_setup.tcl
microblaze_mcs_setup: Found 1 MicroBlaze MCS core.
microblaze_mcs_setup: Added "-bm" option for "microblaze.bmm" to ngdbuild
command line options.
microblaze_mcs_setup: Done.
The next steps are related to the software development using SDK (Software Development Kit)
Start SDK and select the Workspace to match where your design is stored (for example the project is
located in this example at C:\ece3829\mcs_v3):
Note: when you add the \workspace to your project path this new folder will be automatically created.
Click OK
SDK Starts:
Close the Welcome screen and the Project Explorer Window will open:
Select Specify and browse to select the xml project created by ISE (will be in ipcore_dir) as shown below:
Click Finish
Click Finish
Click OK
You should eventually see in the SDK Console Window:
"Compiling iomodule"
"Compiling cpu"
Running execs_generate.
'Finished building libraries'
Click Next
10
Now go back to ISE Project Navigator add a UCF file to match your Nexys board (remember to include a
period timing constraint).
For example:
So this means that the FPGA transmits on N18 (port tx in the UCF file) and receives on N17 (port rx)
11
Note: if you see a question mark ? next to the Generate Programming File in the Processes window
rerun the Generate Programming File process to create an updated bit file with the new C program
added (you do not need to redo any of the previous synthesis or implementation steps). You will need
to do this anytime you modify the C program.
Connect the board to a PC using an RS232 cable (Nexys2) or a USB cable (Nexys3) .
Using the Digilent Adept tool you can now download the fpga bit file from the main project directory to
your board.
You should see Hello World appear on a serial communications link such as Putty or a Hyperterminal
window:
12
Modify the statements as required (for example change the Hello World to add your name) and then
press save. A new ELF file is automatically generated.
Back in ISE, Rerun the Generate Programming File process to create an updated bit file with the new C
program added (you do not need to redo any of the previous synthesis or implementation steps).
Download the new bit file to the board and verify the new changes.
13
<stdio.h>
"platform.h"
"xparameters.h"
"xiomodule.h"
// add
// add
You can find the API documentation in the SDK Project Explorer, under <BSP Name>/BSP
Documentation/iomodule_v1_00_a. Click on "Files", "xiomodule.h" for a list of functions.
14
Assembler instructions:
If you want to see the assembler instructions that are created from your C program look in the
hello_world => Debug => Src folder (top left pane in the Xilinx SDK application) and double-click on the
hello_world_0.elf file.
If you scroll down this file until you find 'int main()' you will see your C instructions and the
corresponding assembler and machine code values. Interesting stuff!
15
Extra: Accessing the GPIO, using xil_printf, and using the UART.
#include
#include
#include
#include
<stdio.h>
"platform.h"
"xparameters.h"
"xiomodule.h"
// add
// add
16
1)
data = XIOModule_DiscreteRead(&iomodule, 2); // read push (channel 2)
XIOModule_DiscreteWrite(&iomodule, 1, data); // turn on LEDs (channel 1)
}
cleanup_platform();
return 0;
}
17