Professional Documents
Culture Documents
com 1
20092010 Xilinx, Inc. XILINX, the Xilinx logo, Virtex, Spartan, ISE, and other designated brands included herein are trademarks of Xilinx in the United States and other
countries. All other trademarks are the property of their respective owners.
Summary The Simple MicroBlaze Microcontroller (SMM) is a small form factor 32-bit microcontroller
based on the MicroBlaze processor that can be instantiated into an FPGA design quickly and
easily.
Introduction Using a small microcontroller programmed in C or C++ can be more efficient than doing the
same function in HDL. This application note provides a new way to easily add a simple
MicroBlaze microcontroller without having to learn new tools. The controller is instantiated
directly into the HDL and can be used immediately in a standard FPGA design flow without
special scripts or complicated steps. Only three files are necessary to get started.
Hardware and
Software
Requirements
The hardware and software requirements for this reference system are:
Xilinx ML605 board, Xilinx SP605 board, or Xilinx Spartan-3A Starter Kit
RS232 serial cable and serial communication utility (HyperTerminal)
Xilinx Software Development KIt (SDK) 11.4
Xilinx Integrated Software Environment (ISE) 11.4
Xilinx Embedded Development Kit (EDK) 11.4 is optional
Reference
System
Specifics
The microcontroller comes initially implemented for Spartan-6, Spartan-3A/AN, Virtex-6,
and Virtex-5 architectures and can be modified to support other architectures.
The entire embedded system is delivered as a netlist that can easily be instantiated into a
Verilog or VHDL design, removing the need to create an EDK design.
Starting with ISE Design Suite 11.1, MicroBlaze software development is fully supported by
the standalone SDK, allowing C and C++ applications to be created and debugged without the
need for EDK.
The microcontroller comes pre-configured with two options: a UART option and a debug option.
Once the code is debugged, the user can switch netlists to reduce the size of the design.
With a total of 3 files (2 for hardware implementation, 1 for software), a complete 32-bit
MicroBlaze microcontroller can be added to any FPGA design.
Application Note: Embedded Processing
XAPP1141 (v2.0) February 8, 2010
The Simple MicroBlaze Microcontroller
Concept
Author: Christophe Charpentier
Reference System Specifics
XAPP1141 (v2.0) February 8, 2010 www.xilinx.com 2
Simple MicroBlaze Microcontroller Features
32-bit MicroBlaze RISC processor
8KB of internal RAM/ROM
Software application is stored in BRAMs at configuration time
32-bit wide Input and Output ports
64KB of addressable user space
Interrupt input
Optional UART
Full C/C++ support
Optional debug support
Simple hardware interface
SMM is available in 4 pre-configured netlists for the Spartan-6, Spartan-3 (A, AN, ADSP), Vir-
tex-6 and Virtex-5 architectures.
SMM with Debug support and UART option
SMM with Debug support and no UART option
SMM with UART option and no Debug support
SMM with no UART option and no Debug support
The user could start with Debug support during the development phase then switch to the no
Debug support netlist for production. The estimated size for each implementation using default
mapping options for ISE 11.4 is shown in Table 1. Different mapping options might yield slightly
different results.
Table 1: SMM Size
FPGA Family Spartan-6 Spartan-3 Virtex-6 Virtex-5
Configuration LUTs FFs Slices LUTs FFs Slices LUTs FFs Slices LUTs FFs Slices
SMM + UART
+ Debug
1350 1200 470 1770 1240 1120 1350 1200 520 1020 1230 460
SMM + UART 1060 860 320 1510 900 1090 1050 870 350 830 880 360
SMM + Debug 990 750 410 1390 790 820 990 750 430 820 780 330
SMM 690 440 220 1130 450 630 690 440 250 630 440 220
Signal Descriptions
XAPP1141 (v2.0) February 8, 2010 www.xilinx.com 3
Microcontroller Interfaces
The block diagram of the Simple MicroBlaze Controller is shown in Figure 1.
Signal
Descriptions
The Simple MicroBlaze Controller signal names and descriptions are shown in Table 2.
X-Ref Target - Figure 1
Figure 1: Simple MicroBlaze Controller Diagram
Simple
MicroBlaze
Microcontroller
DIN [0:31]
SIN (Optional)
INTERRUPT
RESET
DOUT [0:31]
BE [0:3]
ADDR [0:15]
CS
RNW
SOUT (Optional)
INTERRUPT_ACK CLK
X1141_01_060809
ILMB
Debug
DLMB
DPLB
MDM
BSCAN
SOUT
INTERRUPT_ACK
INTERRUPT
CLK
Customizing the Simple MicroBlaze Microcontroller
XAPP1141 (v2.0) February 8, 2010 www.xilinx.com 22
SMM Source Directory Contents
The source files to generate the microcontroller are provided for each configuration (Figure 18).
Each architecture directory contains a complete XPS project for the four pre-configured
versions of the Simple MicroBlaze Microcontroller. Our example modifies the
SMM_Src\V5\SMM_Full project.
SMM Customization
1. Copy the SMM_Src\V5\SMM_Full directory to a working directory.
For example C:\SMM_proj\custom\SMM_Full.
2. Start Xilinx Platform Studio (XPS) 11.4 and open the smm.xmp project.
3. Select the Addresses tab in the System Assembly View.
4. Expand microblaze_0s Address Map.
5. For the dlmb_cntlr and ilmb_ctlr select 16K.
X-Ref Target - Figure 18
Figure 18: Source Directory Contents
SMM
Note:
The V6, S6, and S3 directories follow the
same structure as the V5 directory structure
shown below.
etc
pcores
smm.mhs
smm.xmp
SMM_V5
SMM_S5
SMM_Src
SMM_Ref
SMM_Full
SMM_UART_noDBG
SMM_DBG_noUART
SMM_noDBG_noUART
V6
V5
X1141_18_060809
SMM_V6
SMM_S6
S6
S3
data
SMM Reference Designs
XAPP1141 (v2.0) February 8, 2010 www.xilinx.com 23
6. Go to Hardware > Generate Netlist to create the new netlist and BMM file.
7. When complete, go to Project > Export Hardware Design to SDK to create the new xml file.
Click on Export Only.
8. Copy the three required SMM files to the working ISE and SDK projects. The files locations are:
smm.ngc: C:\SMM_proj\custom\SMM_Full\implementation\smm.ngc
smm.bmm: C:\SMM_proj\custom\SMM_Full\implementation\smm_stub.bmm
smm.xml: C:\SMM_proj\custom\SMM_Full\SDK\SDK_Export\hw\smm.xml
When replacing an existing smm.ngc file in the ISE project, a full re-implementation of the
FPGA is necessary.
When replacing an existing smm.xml file in the SDK project, SDK will automatically detect a
new xml file and will rebuild the software platform to match the new configuration
SMM Reference
Designs
Reference designs are provided in the SMM_Ref directory. They are two identical designs, one
for the S3A Starter Kit and the other for the ML605 board.
The reference design uses the SMM to print information to the character LCD screen. The ISE
and SDK projects are provided using the smallest pre-configured version of SMM (without
Debug and UART). The directory structure for the reference directory is shown in Figure 19.
SMM Reference Designs
XAPP1141 (v2.0) February 8, 2010 www.xilinx.com 24
Reference Directory Contents
The src directory contains the VHDL source files for the ISE project. The ise directory contains
the ISE project, including the constraints file. The sdk directory contains the SDK project,
including the C source file.
Reference Design Overview
The reference design uses a combination of FPGA logic and C code running on the
microcontroller to output messages to the LCD screen.
The microcontroller handles the initialization of the LCD and the printing of string messages to
the LCD.
Because the LCD timing is very slow, with some instructions requiring up to 1.6us of wait time,
a 32-bit timer located in the FPGA logic handles the wait times. The timer generates an
interrupt to the SMM to indicate that the timer has reached a loaded value.
The LCD hardware timing is created in the FPGA logic. The microcontroller sends commands
and data through a single 16-bit register. Bit 0 is used to differentiate between LCD data and
commands.
X-Ref Target - Figure 19
Figure 19: Reference Directory Contents
SMM
Note:
The S3A directory follows the same structure
as the ML605 directory structure shown below.
SMM_V5
SMM_S3
SMM_Ref
SMM_Src
lcd_ref
S3A_LCD_Ref
ML605_LCD_Ref
ise
lcd_ref.ucf
smm.ngc
sdk
smm.xml
smm.bmm
lcd_ref.xise
src
lcd_ref.vhd
lcd_ctlr.vhd
timer.vhd
X1141_19_060809
SMM Reference Designs
XAPP1141 (v2.0) February 8, 2010 www.xilinx.com 25
VHDL Source Files Overview
lcd_ref.vhd: Top level VHDL file. Contains the input and output ports for the design, the
SMM instantiation, the 32-bit timer instantiation, and the LCD Controller instantiation. For
the S3A Kit, the LCD is used in 8-bit mode. For the ML605, the LCD is used in 4-bit mode.
The South push button is used as a user input. The push button is sampled into a register
using the clock input. The register is cleared when read by the SMM.
timer.vhd: Sub-module VHDL file. Contains a 32-bit counter. The timer is loaded with a
software accessible register. The counter starts after the load. An interrupt is generated
when the counter reaches the loaded value. The INTERRUPT_ACK signal from the SMM
is used to clear the interrupt.
lcd_ctlr.vhd: Sub-module VHDL file. Contains the LCD screen logic. A 16-bit software
accessible register is used to output data and commands to the LCD_DB pins. Bit 0 of the
register is used to generate the LCD_RS bit. The least significant bits of the register are
used for LCD_DB. Once a value is written to the register, the LCD_E signal is asserted.
The logic handles the hold and width times of the LCD_E signal using a small counter.
ISE Files Overview
lcd_ref.xise: ISE project file
lcd_ref.ucf: ISE project constraints file
smm.ngc: SMM netlist without Debug Support and without UART
smm.bmm: SMM BRAM Memory Map
SDK Files Overview
The sdk directory contains files needed for an SDK project. There is a single C source file for
the processor.
lcd_ref.c: C source file. Contains the LCD reference application source code. The
application enable interrupts, initializes the LCD, writes a couple lines to the LCD, and
waits for the push button input to continue. Some local functions are created to make the
code more readable.
void Timer_Wait (Xuint32 delay): Sends the delay value to the FPGA logic timer and
waits for the interrupt to be serviced.
void timer_int_handler(void * arg): Interrupt service routine.
void lcd_init (void): Handles the LCD screen initialization.
void lcd_print (Xuint32 Line, Xuint8 *Str): Prints characters to the LCD. The Line
argument indicates which of the 2 lines to print to.
void lcd_clear (void): Clears the LCD Screen. It includes the 1.56ms delay required
after a clear.
lcd_4_write (Xuint16 value): For the ML605, the LCD is used in 4-bit mode. This
function takes an 8-bit value and sends two 4-bit values to the LCD. It only applies for
the ML605 design.
Running the Design
Follow these instructions to run the design on the S3A Kit or ML605.
1. Open the ise directory and double-click on the lcd_ref.xise file.
2. In Project Navigator double-click on Generate Programming File.
3. Close Project Navigator when finished.
4. Start Xilinx SDK 11.4.
5. Browse to the sdk directory for the workspace selection and Click OK.
References
XAPP1141 (v2.0) February 8, 2010 www.xilinx.com 26
6. Browse to the smm.xml file in the sdk directory for the Hardware Specification File. Click
OK twice.
7. Go to File > New > Software Platform
8. Select standalone for the project name then click Finish.
9. Go to File > Import Select Existing Projects into Workspace. Click Next.
10. Browse to the sdk directory. Make sure that only the lcd_ref project is checked.
11. Click Finish.
Wait for the project to build.
12. Connect the USB JTAG cable.
13. Power-on the board.
14. Go to Tools > Program FPGA
15. Browse to the ISE project and use lcd_ref.bit for the Bit File.
16. Browse to the ISE project use smm_bd.bmm for the Bmm File.
17. Select lcd_ref.elf to be initialized inside the BRAM memory.
18. Click Save and Program.
19. Check the LCD screen. Press the South push button to clear the screen and output a new
line.
References 1. UG081 MicroBlaze Processor Reference Guide
2. UG330 Spartan-3A FPGA Starter Kit User Guide
3. UG534 ML605 Hardware User Guide
4. UG526 SP605 Hardware User Guide
Revision
History
The following table shows the revision history for this document.
Notice of
Disclaimer
Xilinx is disclosing this Application Note to you AS-IS with no warranty of any kind. This Application Note
is one possible implementation of this feature, application, or standard, and is subject to change without
further notice from Xilinx. You are responsible for obtaining any rights you may require in connection with
your use or implementation of this Application Note. XILINX MAKES NO REPRESENTATIONS OR
WARRANTIES, WHETHER EXPRESS OR IMPLIED, STATUTORY OR OTHERWISE, INCLUDING,
WITHOUT LIMITATION, IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR
FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL XILINX BE LIABLE FOR ANY LOSS OF
DATA, LOST PROFITS, OR FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR INDIRECT
DAMAGES ARISING FROM YOUR USE OF THIS APPLICATION NOTE.
Date Version Description of Revisions
7/8/09 1.0 Initial Xilinx release.
2/08/10 2.0 Added support for Spartan-6 and Virtex-6 families. Replaced the ML505
reference design with the ML605 reference design.