Lattice Mico 32 HWDeveloper UG310
Lattice Mico 32 HWDeveloper UG310
Lattice Mico 32 HWDeveloper UG310
May 2014
Copyright
Copyright © 2014 Lattice Semiconductor Corporation.
Trademarks
Lattice Semiconductor Corporation, L Lattice Semiconductor Corporation (logo), L
(stylized), L (design), Lattice (design), LSC, CleanClock, Custom Mobile Device,
DiePlus, E2CMOS, ECP5, Extreme Performance, FlashBAK, FlexiClock, flexiFLASH,
flexiMAC, flexiPCS, FreedomChip, GAL, GDX, Generic Array Logic, HDL Explorer,
iCE Dice, iCE40, iCE65, iCEblink, iCEcable, iCEchip, iCEcube, iCEcube2, iCEman,
iCEprog, iCEsab, iCEsocket, IPexpress, ISP, ispATE, ispClock, ispDOWNLOAD,
ispGAL, ispGDS, ispGDX, ispGDX2, ispGDXV, ispGENERATOR, ispJTAG, ispLEVER,
ispLeverCORE, ispLSI, ispMACH, ispPAC, ispTRACY, ispTURBO, ispVIRTUAL
MACHINE, ispVM, ispXP, ispXPGA, ispXPLD, Lattice Diamond, LatticeCORE,
LatticeEC, LatticeECP, LatticeECP-DSP, LatticeECP2, LatticeECP2M, LatticeECP3,
LatticeECP4, LatticeMico, LatticeMico8, LatticeMico32, LatticeSC, LatticeSCM,
LatticeXP, LatticeXP2, MACH, MachXO, MachXO2, MachXO3, MACO, mobileFPGA,
ORCA, PAC, PAC-Designer, PAL, Performance Analyst, Platform Manager,
ProcessorPM, PURESPEED, Reveal, SensorExtender, SiliconBlue, Silicon Forest,
Speedlocked, Speed Locking, SuperBIG, SuperCOOL, SuperFAST, SuperWIDE,
sysCLOCK, sysCONFIG, sysDSP, sysHSI, sysI/O, sysMEM, The Simple Machine for
Complex Design, TraceID, TransFR, UltraMOS, and specific product designations are
either registered trademarks or trademarks of Lattice Semiconductor Corporation or its
subsidiaries in the United States and/or other countries. ISP, Bringing the Best
Together, and More of the Best are service marks of Lattice Semiconductor
Corporation.
Other product names used in this publication are for identification purposes only and
may be trademarks of their respective companies.
Disclaimers
NO WARRANTIES: THE INFORMATION PROVIDED IN THIS DOCUMENT IS “AS IS”
WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING
WARRANTIES OF ACCURACY, COMPLETENESS, MERCHANTABILITY,
NONINFRINGEMENT OF INTELLECTUAL PROPERTY, OR FITNESS FOR ANY
PARTICULAR PURPOSE. IN NO EVENT WILL LATTICE SEMICONDUCTOR
CORPORATION (LSC) OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES
WHATSOEVER (WHETHER DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
CONSEQUENTIAL, INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF
PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING
OUT OF THE USE OF OR INABILITY TO USE THE INFORMATION PROVIDED IN
THIS DOCUMENT, EVEN IF LSC HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE EXCLUSION
OR LIMITATION OF CERTAIN LIABILITY, SOME OF THE ABOVE LIMITATIONS MAY
NOT APPLY TO YOU.
Bold Items in the user interface that you select or click. Text that you type
into the user interface.
Courier Code examples. Messages, reports, and prompts from the software.
Glossary 117
Index 123
Chapter 1
This hardware developer guide describes the flow of tools involved in creating
and configuring a hardware platform for the LatticeMico32 embedded
microprocessor.
These applications work in the background through the user interface and can
be accessed through different “perspectives” in the LatticeMico System
software. Perspectives are a prearranged and predefined set of user
functions that can be accessed within the software user interface.
Perspectives are described in more detail in “LatticeMico System
Perspectives” on page 8.
You can use the C/C++ Software Project Environment (SPE) to develop the
software application code that drives the platform. The Debugger is used to
analyze and correct your code. You can access these programs by enabling
the C/C++ and Debug perspectives, respectively. However, these two
perspectives overlap in terms of functionality. Many of the same functions and
views available in the C/C++ perspective are also available in the Debug
perspective because the functions are so intertwined.
Device Support
The Lattice FPGA devices that are currently supported in this design flow are
the following:
ECP5
LatticeECP
LatticeEC
LatticeECP2
LatticeECP2M
LatticeECP3
LatticeXP
LatticeXP2
LatticeSC
LatticeSCM
For complete information about using the C/C++ SPE and Debugger
perspectives to build and test your software application, refer to the
LatticeMico32 Software Developer User Guide.
Related Documentation
You can access the LatticeMico System online Help and manuals by choosing
Help > Help Contents in the LatticeMico System interface. These manuals
include the following:
LatticeMico32 Processor Reference Manual, which contains information
on the architecture of the LatticeMico32 microprocessor chip, including
configuration options, pipeline architecture, register architecture, debug
architecture, and details about the instruction set.
LatticeMico32 Software Developer User Guide, which introduces you to
the run-time environment, the build management process, the directory
structure for the managed build, information on the device driver
framework, and the processes occurring in the background. It is intended
for a programmer.
LatticeMico32/DSP Development Board User Guide, which describes the
features and functionality of the LatticeMico32/DSP development board.
This board is designed as a hardware platform for design and
development with the LatticeMico32 microprocessor, as well as for the
LatticeMico8 microcontroller, and for various DSP functions.
Eclipse C/C++ Development Toolkit User Guide, which is an online
manual from Eclipse that gives instructions for using the C/C++
Development Toolkit (CDT) in the Eclipse Workbench.
LatticeMico Asynchronous SRAM Controller, which describes the features
and functionality of the LatticeMico asynchronous SRAM controller
LatticeMico DMA Controller, which describes the features and
functionality of the LatticeMico DMA controller
LatticeMico On-Chip Memory Controller, which describes the features and
functionality of the LatticeMico on-chip memory controller
LatticeMico Parallel Flash Controller, which describes the features and
functionality of the LatticeMico parallel flash controller
LatticeMico GPIO, which describes the features and functionality of the
LatticeMico GPIO
LatticeMico Master Passthrough, which describes the features and
functionality of the LatticeMico master passthrough.
LatticeMico Slave Passthrough, which describes the features and
functionality of the LatticeMico slave passthrough
LatticeMico SDR SDRAM Controller, which describes the features and
functionality of the LatticeMico SDR SDRAM controller
LatticeMico SPI, which describes the features and functionality of the
LatticeMico serial peripheral interface (SPI)
LatticeMico SPI Flash, which describes the features and functionality of
the LatticeMico serial peripheral interface (SPI) flash memory controller
LatticeMico Timer, which describes the features and functionality of the
LatticeMico Timer
LatticeMico UART, which describes the features and functionality of the
LatticeMico universal asynchronous receiver-transmitter (UART)
Chapter 2
This chapter assumes that you have read “LatticeMico System Overview” on
page 1 and are familiar with the general high-level steps in this product flow.
This chapter also assumes that you have not customized the user interface.
The LatticeMico32 tools share the same Eclipse workbench, which provides a
unified graphical user interface for the software and hardware development
flows. You use MSB to define the structure of your microprocessor or your
hardware platform. C/C++ SPE enables you to develop and compile your
code in a managed and well-structured build environment. The Debugger
includes tools that analyze your code for errors and simulates instruction calls
within the software environment or to an actual programmed device on a
circuit board.
You will learn more about how these functions are encountered in the
software throughout this chapter. This chapter assumes that you have
installed all of the necessary software and have not modified your default
perspectives in any way.
The LatticeMico System interface initially opens with the MSB perspective
active by default, as shown in Figure 5 on page 16. After that, the software
opens to the last opened perspective.
functional tools, MSB, C/C++ SPE, and the Debugger, within the user
interface. Do not confuse the underlying functional tools in the LatticeMico
System software with the various perspectives in the user interface.
Within the Eclipse framework, the three functional tools appear as different
user interfaces integrated into the same framework. A “perspective” in the
LatticeMico System software is a separate combination of views, menus,
commands, and toolbars in a given graphical user interface window that
enables you to perform a set of particular, predefined tasks. For example, the
Debug perspective has views that enable you to debug the programs that you
developed using the C++ SPE tool. For an overview on Eclipse workbench
concept and terminologies, refer to the Eclipse Reference Manual.
When you first open LatticeMico System, the MSB perspective is the active
perspective by default. After working in the interface, the software defaults to
the last opened perspective. The Eclipse workbench that is integrated into the
LatticeMico System software has three activation buttons for quickly toggling
back and forth between the MSB, C/C++, and Debug perspectives. These
buttons are shown in Figure 3. They enable you to switch between
perspectives by clicking on them. The current active perspective is displayed
in the upper left of the window’s title bar.
The three different perspectives—the MSB, the C++ SPE, and the Debug—
include overlapping tool functions that you access through various commands
and interactive views, as illustrated in Figure 4. You can find more information
on these commands and views later in this document and in the online Help.
Note
Particular views and options within the MSB perspective are described throughout this
chapter as they are encountered in the design flow. For descriptions of the C/C++ SPE
and Debugger perspectives, refer to the LatticeMico System Software Developer User
Guide. More information about the graphical user interface for each perspective is
described in more detail in the LatticeMico32 online Help.
3. Select the perspective that you want to define as the default and click
Make Default.
The default indicator moves to the perspective that you selected.
4. Click OK.
At times, you may want to close views to make more space for working in a
desired view. For example, after you add all of the components that you need
in your platform, you may opt to close the Available Components view in the
MSB perspective.
Note
If you are going to use LatticeMico System on the Linux platform, you must install a
stand-alone synthesis tool, such as Synplicity® Synplify Pro®, before you create an
Diamond project.
In addition, your Linux system must meet the minimum system requirements outlined
in the Diamond <release_number> Installation Guide for Linux.
This is important for your current project. Maintaining the Diamond project
directory will ensure that future changes to the IP will be applied to the
current design project.
7. In the IPexpress Interface section, click Launch IPexpress.
8. In the Lattice IP Core interface, specify the desired parameters, and then
click Generate.
IPexpress generates the IP core. When the process has finished, it
displays a log, which shows the output directory and path and the files
generated.
9. Click Close to return to the Add<IP_core> dialog box.
The Generated NGO File text box is now populated with the location of
the .ngo file inside the Diamond project directory.
10. Click OK to add the newly generated IP core to your project’s platform.
11. Follow the remaining instructions in the section “Creating the
Microprocessor Platform in MSB” on page 15 to connect master and slave
ports, assign addresses and interrupt priorities, and generate the platform.
Starting MSB
Note
If you are going to be using LatticeMico System on the Linux platform, set up
the environment to point to the location where the stand-alone synthesis tool
is installed before starting LatticeMico System, as in this example:
setenv IPEXPRESS_SYN_PATH /install/synplify/fpga_89/bin/
synplify_pro
To start MSB:
1. If you have not yet opened the software, as described in “Running
LatticeMico System” on page 8, choose Start > Programs > Lattice
Diamond > Accessories > LatticeMico System.
During its launch process, the LatticeMico System software creates an
Eclipse workspace file. This file is created in your home directory. On the
Windows operating systems, it is in the Documents and Settings directory.
On the Linux operating system, it is in ~.
Eclipse uses the workspace file to store information about your Eclipse
environment and the projects that you have been working on. You can
switch workspaces by selecting the File > Switch Workspace command.
2. In the upper left-hand corner of the graphical user interface, select MSB, if
it is not already selected, to open the MSB perspective.
The MSB perspective is active by default, as shown in Figure 5.
Editor
Available view
Components
view
Console view
(shown)
Component
Help view
Name, which displays the names of the chosen component and their
ports
Connection, which displays the connectivity between master and
slave ports
Base, which displays the start addresses for components with slave
ports. This field is editable.
End, which displays the end addresses for components with slave
ports. This field is not editable. The value of the end address is
equivalent to the value of the base address plus the value of the size.
Size, which displays the number of addresses available for
component access. This field is editable for the LatticeMico32 on-chip
memory controller and LatticeMico32 asynchronous SRAM controller
components only.
Lock, which indicates whether addresses are locked from any
assignments. If you lock a component, its address will not change
when you select Platform Tools > Generate Address.
IRQ, which displays the interrupt request priorities of all components
that have an interrupt line connected to the microprocessor. It is not
applicable to memories.
Disable, which excludes a component from a platform definition. It can
be toggled on and off.
Component Help view, which displays information about the component
that you selected in the Available Components view. This view is also
called “About <Component_name>,” for example, “About Timer” or “About
UART.”
Console view, which displays informational and error messages output by
MSB
Component Attributes view, which displays the features, parameters, and
values of the selected component. This view is read-only.
Clicking the “X” icon next to the View title closes the selected view. To reopen
a view that you previously closed, choose Window > Show View and the
desired view submenu option. For a detailed explanation of the available
views, refer to the LatticeMico32 online Help.
You must perform two major steps in MSB to create a new platform: create an
.msb file and add your components to the file.
2. In the New Platform Wizard dialog box, enter the name of the platform in
the Platform Name box.
3. In the Directory box, browse to the folder in which you want to store your
platform files and click OK.
4. If the design that will incorporate this platform is in pure Verilog code,
leave Create VHDL Wrapper unselected.
If the design that will incorporate this platform is in mixed Verilog/VHDL,
do the following.
a. Select Create VHDL Wrapper.
b. If you want to continue using the NGO flow, select Create VHDL NGO
File. Otherwise, leave this option cleared.
5. In the Board Frequency box, enter the board frequency.
6. In the Arbitration Scheme box, select the desired arbitration scheme from
the pull-down menu.
7. In the Device Family section, select a Lattice family and a device from the
pull-down menus.
8. If you want to duplicate the platform, select Clone Platform, and then
browse to the platform description (.msb file) that you want to duplicate.
The Clone Platform option is useful if your platform contains several
peripherals and you want to retain them but experiment by modifying their
settings. When you select this option, the Platform Templates and the
Description boxes are no longer available, but the Select Platform option
becomes available.
Warning!
If you are cloning a platform that contains IPs and you select a different device
family, you will need to rerun IPexpress for the IPs in the platform. If you do not
rerun IPexpress, you might encounter problems during synthesis.
9. If you have not selected Clone Platform, select the desired template from
the Platform Templates list; or select Blank for a new template.
10. Click Finish.
You now have created an .msb file. This file will hold the contents of your
platform: a CPU, its peripherals, and the interconnections between them.
Currently, the platform description contains no components. You will add
components in the following procedures.
Note
If you installed LatticeMico System without installing Diamond, you cannot include in
the platform any PLLs or any IPs, which are components that you download from
IPexpress. In addition, you cannot generate a VHDL wrapper for the platform. If you
want to perform these functions, you must install LatticeMico32 with the Diamond
software. See the references given in “LatticeMico System Requirements” on page 8
for information on installing Diamond and LatticeMico System.
To quickly maximize the Component Help view, press Ctrl+M. Press Ctrl+M
again to return to the previous size.
Attached to one or more slave ports, master port signals initiate read and
write transactions that are communicated to the targeted slave device, which
in turn responds appropriately. Generally, a component can have one or more
master ports, one or more slave ports, or both.
Arbitration Schemes
The connections that MSB makes depend on which arbitration scheme you
choose while creating the platform.
Each master port connected to the arbiter has priority of access to the slave
ports. In the case of simultaneous access requests by multiple master ports,
the highest-priority master port is granted access to the bus. Master ports
have default priorities assigned in their components' .xml files when you add
the components to the platform. The master ports of the LatticeMico32
processor have defaults of 0 and 1. The master ports of the DMA controller
have defaults of 2 and 3. However, you can change these priorities by
selecting Platform Tools > Edit Arbitration Priorities and changing the priorities
in the Edit Arbitration Priorities dialog box. When you perform a DRC check,
MSB checks the validity of the priorities that you have changed.
Peripheral 1
Instruction
port
Peripheral 2
Peripheral 3
Peripheral 4
Peripheral 1
Instruction
port
Peripheral 3
Arbiter 2 Peripheral 4
Each master port connected to the arbiter has priority of access to the slave
ports. In the case of simultaneous access requests by multiple master ports,
the highest-priority master port is granted access to the slave. Master ports
have default priorities assigned in their components' .xml files when you add
the components to the platform. Since each multi-master slave has its own
arbiter in this scheme, arbitration priorities are assigned per slave. However,
you can change these priorities by selecting Platform Tools > Edit Arbitration
Priorities and changing the priorities in the Edit Arbitration Priorities dialog
box. When you perform a DRC check, MSB checks the validity of the priorities
that you have changed.
In the slave-side round-robin scheme, the Platform Tools > Edit Arbitration
Priorities command is not available.
Both the slave-side fixed and the slave-side round-robin arbitration schemes
use separate arbiters for each multi-master slave, so the area of the platforms
generated with these schemes is slightly larger than that resulting from the
shared-bus arbitration scheme. For example, for a typical system consisting
of four multi-master slaves, the slave-side fixed and the slave-side round-
robin schemes require four arbiters, but the shared-bus scheme requires only
one arbiter. The area required by the system with the slave-side arbitration
schemes is approximately three times more than the area required by the
system with the shared-bus arbitration scheme.
The slave-side arbitration schemes offer better performance than the shared-
bus arbitration scheme. For example, the SoC used in this topic (a CPU with a
DMA controller) yields better performance with a slave-side arbitration
scheme than with a shared-bus arbitration scheme. When a slave-side
arbitration scheme is used in this SoC, the DMA controller's read and write
ports can work in parallel and transfer the data from the external SRAM
memory to on-chip memory. When a shared-bus arbitration scheme is used in
the SoC, data cannot be transferred in parallel because there is a single
arbiter for both memories.
Figure 9 shows an example of the connections that result in the Editor view
when the shared-bus arbitration scheme is used. All master signal connection
lines are represented in black, and all slave connection lines are represented
in blue.
Figure 10 shows an example of the connections that result in the Editor view
when the slave-side fixed and slave-side round-robin arbitration schemes are
used.
In the slave-side fixed arbitration scheme, you can change the priorities of the
master ports, so the Edit Arbitration Priorities command is available on the
Platform Tools menu, as shown in Figure 11. However, in the slave-side
round-robin arbitration scheme, you cannot change the priorities of the master
ports because the arbitration between the master ports occurs in a round-
robin fashion. The Edit Arbitration Priorities command on the Platform Tools
Figure 11 shows the Platform Tools menu with the Edit Arbitration Priorities
command enabled in the MSB perspective after all components have been
added in a slave-side fixed arbitration scheme.
Figure 12 shows the Platform Tools menu with the Edit Arbitration Priorities
command disabled in the MSB perspective after all components have been
added in a slave-side round-robin arbitration scheme.
Figure 11: MSB Perspective After Adding All Components in a Slave-Side Fixed Arbitration Scheme
Figure 12: MSB Perspective After Adding All Components in a Slave-Side Round-Robin Arbitration
Scheme
When you perform a DRC check, MSB checks the validity of the priorities that
you have changed.
When you assign arbitration priorities to the master port of a slave in the
slave-side fixed arbitration scheme, the number of priorities should not be
greater than the total number of master ports for that slave. For example, if a
slave has three master port values, the arbitration priorities would be 0, 1, and
2. If you defined more than three values for any master, an error message
would appear, as shown for the UART slave example in Figure 13.
If you look in the Editor view in the Base column, you will notice that the
components, after initial setup, all are assigned to the same default address
location on creation, unless you actively assign a unique base address in a
component dialog box when you first add the component to the platform. Any
duplicate address locations of any component are, of course, not viable. This
section provides procedures for assigning these unique address locations.
Before you generate addresses, you can lock the base addresses of
individual components so that MSB will not assign them new addresses. See
“Locking Component Addresses” on page 29 for details.
Note
Address and size values that appear in italic font in the Editor view cannot be changed.
Address locations for all of the existing components that you have created
in your MSB session are now automatically generated.
2. Choose File > Save.
The assigned component addresses are now saved in the .msb file.
Note
To assign an address for only one component, lock all other components.
Note
You can only edit the Base address. You cannot edit the End address. The value
of the end address is equivalent to the value of the base address plus the value of
the size.
Note
If you did not set the IPEXPRESS_SYN_PATH environment variable before
starting Synplify Pro, as noted in “Starting MSB” on page 15, or if Synplify Pro
failed to complete the synthesis, MSB may issue the following error message:
ERROR: edif2ngd: Cannot open input file
"<platform_name>.edi".
If you receive this error message, verify that the IPEXPRESS_SYN_PATH is set
correctly, and check the synthesis output in the log file or .srr file in the soc/ngo/
rev_1 directory to see if the error is a synthesis syntax error.
If you edit the .msb file after it has been generated, save it by choosing
File > Save As. An asterisk (*) preceding <platform_name>.msb above
the Editor view indicates that the <platform_name>.msb file has been
edited.
During the generation process, MSB creates the following files in the
<Diamond_install_path>\<platform_name>\soc directory:
A <platform_name>.msb file, which describes the platform. It is in XML
format and contains the configurable parameters and bus interface
information for the components. It is passed to C/C++ SPE, which extracts
the platform information (for example, where components reside in the
memory map) required by the software that will run on the platform. It is
used by users of the Verilog flow and the VHDL flow.
A <platform_name>.v (Verilog) file, which is used by both Verilog and
VHDL users:
If you want to change that connection, you must manually modify the code in
the <platform_name>.v file in the ./<platform_name>/soc directory by adding
logic to the tristates so that multiple LatticeMico32 components can share this
bidirectional bus.
IF you want to modify the shared bidirectional data bus in certain platform
components in the VHDL, you must modify the verilog code to change the
tristate control. You can do this by either pulling the tristates outside of the
platform or making the changes within the platform. If you pull the tristates
from the platform and you are using the VHDL wrapper, then you must also
modify the <platform_name>_vhd.vhd file in the ./<platform_name>/soc
directory.
However, if you regenerate the platform in MSB after you add logic to the
tristates, these additions will be lost in the automatically generated
<platform_name>.v or <platform_name>_vhd.vhd file in the
./<platform_name>/soc directory. To avoid losing your work, copy the modified
<platform_name>.v or <platform_name>_vhd.vhd file to another location,
regenerate the platform, and then copy the modified <platform_name>.v or
<platform_name>_vhd.vhd file back to the ./<platform_name>/soc directory.
When you declare the I/O ports as black-box pads during VHDL synthesis, the
synthesis tools do not insert I/O pads for these signals and therefore avoid
double buffering.
Figure 15 further clarifies the connection. For all non-bidirectional I/Os, the I/O
buffers (in green) are provided by the VHDL wrapper during VHDL synthesis.
The bidirectional I/O buffers (in red) are provided by the .ngo file itself.
Inputs or outputs
Bidirectional I/Os
VHDL wrapper
<platform_name>/components/i2cm_opencores/rtl/verilog
See the Synthesis Data Flow Tutorial for step-by-step information about
synthesizing designs in Precision RTL Synthesis and Synplify Pro.
will build the database; map, place, and route the design; and generate the
bitstream in Diamond so that you can download that configuration bitstream to
the chip on a circuit board.
To import the Verilog (.v) and VHDL (.vhd) files output by MSB on the
Windows platform:
1. Choose File > Add > Existing File.
2. In the dialog box, browse to the <platform_name>\soc\ location and do
one of the following:
Select the <platform_name>.v file (Verilog) and click Add.
If your design is mixed Verilog/VHDL, select both the
<platform_name>.v file and the <platform_name>_vhd.vhd file and
click Add.
3. If your design is mixed Verilog/VHDL and you selected the Create VHDL
Wrapper option to generate <platform_name>_vhd.vhd without selecting
the Create VHDL NGO File option, perform these additional steps:
a. Choose Project > Property Pages.
b. In the dialog box, select the project name that appears in bold type
next to the implementation icon .
c. In the right pane, click inside the Value cell for “Top-Level Unit” and
select <platform_name>_vhd from the drop-down menu.
d. Click inside the Value cell for “Verilog Include Search Path,” and then
click the browse button to open the “Verilog Include Search Path”
dialog box.
e. In the dialog box, click the New Search Path button , browse to the
<platform_name>\soc directory, and click OK.
f. Click OK to add the path to the Project Properties and close the
“Verilog Include Search Path” dialog box.
g. Click OK to return to the Diamond main window.
This topic describes the process for using an HDL simulation tool such as
Mentor Graphics ModelSim™ or Aldec Active-HDL™. The method described
is applicable to designs written in VHDL, Verilog, or a combination of both.
The example LatticeMico32 platform in this topic uses the FPGA's on-chip
memory, Embedded Block Ram (EBR). The firmware (C/C++ code) is
compiled using the Lattice C/C++ SPE and Debug software, and a memory
initialization file is created that is loaded into the on-chip memory. It is possible
to locate the firmware in other off-chip memories as long as there exists a
behavioral model for the memory.
The example application used in this topic is the “Hello World” application,
which is available as a predefined C/C++ SPE project. See Chapter 2 and
Chapter 6 of the LatticeMico System Software Developer User Guide for more
information about creating the “Hello World” application, compiling it, and
deploying it to the EBR.
with the deployed software. The EBR memory size must be large enough
to hold your C/C++ application. In this example, the memory is 128KB,
which is more than enough for the “Hello World” application but too large
for most FPGAs to support.
Ensure that the LM32 Exception Base Address (EBA) points to the base
address of the memory component that contains the deployed software/
firmware. This address must be aligned to a 256-byte boundary, since the
hardware ignores the least-significant byte. Unpredictable behavior occurs
when the exception base address and the exception vectors are not aligned
on a 256-byte boundary. In the platform shown in Figure 16 on page 40, the
software is deployed in EBR. Therefore, modify the “Location of Exception
Handlers” field in the LM32 processor dialog box to point to the base address
of EBR (0x00020000), as shown in Figure 18.
Directory Structure
When MSB is used to generate a platform, a set of directories is created in a
top-level platform directory. The top-level directory is automatically assigned
the same name as the MSB project name, which is Platform in this example.
<path_to_toplevel_directory>/Platform
components
soc
The components directory contains RTL and software drivers that pertain to
each of the components instantiated within the design. Important files in the
soc directory include:
system_conf.v – This file contains the auto-generated macro definitions of
the various components in the design. As mentioned previously, this file
must be modified if the “Enable Debug Interface” option is selected in the
LM32 processor dialog box.
platform.v – This file contains the top-level module of the design, which is
Platform in this example.
pmi_def.v – This file contains module definitions of all the PMI modules
used in the design. For the purpose of functional simulation, the PMI
behavioral models must be provided. See “Replace PMI Black-box
Instantiations with Behavioral Models.” on page 46.
module testbench;
event done;
// Inputs
reg clk_i;
reg reset_n;
// Outputs
wire [7:0] LEDPIO_OUT;
wire sramsram_wen;
wire [31:0] sramsram_data;
wire [22:0] sramsram_addr;
wire sramsram_csn;
wire [3:0] sramsram_be;
wire sramsram_oen;
wire uartSIN;
wire uartSOUT;
Platform_vhd Platform_u
(
.clk_i(clk_i),
.reset_n(reset_n),
.sramsram_wen(sramsram_wen),
.sramsram_data(sramsram_data),
.sramsram_addr(sramsram_addr),
.sramsram_csn(sramsram_csn),
.sramsram_be(sramsram_be),
.sramsram_oen(sramsram_oen),
.LEDPIO_OUT(LEDPIO_OUT),
.uartSIN(uartSIN),
.uartSOUT(uartSOUT),
);
/*----------------------------------------------------------------------
Trap "Exit" System Call to terminate simulation
----------------------------------------------------------------------*/
reg scall_m, scall_w;
always @(negedge clk_i)
begin
if (Platform_u.Platform_u.LM32.cpu.stall_m == 1'b0)
begin
scall_m <= Platform_u.Platform_u.LM32.cpu.scall_x &
Platform_u.Platform_u.LM32.cpu.valid_x;
scall_w <= scall_m & Platform_u.Platform_u.LM32.cpu.valid_m;
end
// System Call number is passed in r8, Exit System Call is call number 1
if (scall_w && (Platform_u.Platform_u.LM32.cpu.registers[8] == 1))
begin
$display("Program exited with code %0d.\n",
Platform_u.Platform_u.LM32.cpu.registers[1]);
-> done;
end
end
/*----------------------------------------------------------------------
Tasks to perform when simulation terminates
----------------------------------------------------------------------*/
always @(done)
$finish;
endmodule
<diamond_install_path>/cae_library/simulation/verilog/pmi
Select the behavioral model of each PMI module from the simulation
directory in the Diamond installation. Figure 21 shows those selected
for the Platform example.
Copy the selected models and paste them into the platform’s
simulation directory. Figure 22 shows the simulation directory of the
Platform example where PMI modules have been replaced by the
appropriate behavior models.
# the VSIM command uses the Aldec for Lattice pre-compiled FPGA
# libraries. If the Aldec for Lattice simulator is not being
# used, it will be necessary to compile the behavioral code for
# the FPGA. For the ECP2, the behavioral code is located at:
# <isptools>/cae_library/simulation/verilog/ecp2
Launch the Active-HDL software and execute the following command in the
console window:
cd <path_to_toplevel_directory>/Platform/simulation
pwd
do aldec_script.do
vlib work
vdel –lib work –all
vlib work
vlog pmi_addsub.v
vlog pmi_ram_dq.v
vlog pmi_ram_dq.v
vlog pmi_ram_dp.v
vlog pmi_ram_dp_true.v
vlog pmi_distributed_dpram.v
vlog pmi_fifo.v
vlog pmi_fifo_dc.v
vlog +define+SIMULATION \
+incdir+../soc+../components/gpio/rtl/verilog+../components/
lm32_top/rtl/verilog+../components/timer/rtl/verilog+../
components/wb_ebr_ctrl/rtl/verilog+../components/asram_top/rtl/
verilog+../components/uart_core/rtl/verilog+../components/
wb_dma_ctrl/rtl/verilog \
../soc/platform.v
vcom ../soc/platform_vhdl.vhd
vlog +incdir+../components/lm32_top/rtl/verilog testbench.v
Note
When doing mixed-language simulation, use the -t 1ps command-line option for the
“vsim” command.
The hardware developer needs to have both Lattice Diamond and LatticeMico
System installed in order to generate the files and provide them to the
software developer.
For example:
5. Sends the software developers the FPGA bitstream file (.bit) that was
generated using Diamond.
Chapter 3
This chapter shows you how to bring your WISHBONE interface component
into the Mico System Builder (MSB) so that it is listed as an available
component in MSB for use in platforms. It assumes that you already have the
Verilog or VHDL source code for the component that you wish to add. Refer to
the section “WISHBONE Interconnect Architecture” in the LatticeMico32
Processor Reference Manual.
This chapter assumes that you have implemented your custom component
and that your custom component has a WISHBONE interface that contains
the signals required for connecting to the LatticeMico32’s WISHBONE fabric.
Your custom component may have a custom I/O interface that may need to be
used as platform input and output pins. Finally, your custom component may
require a clock signal and a reset signal. It may provide an interrupt request to
the LatticeMico32 processor through an interrupt pin.
The following steps are required to import your custom component into MSB:
1. Open the Import/Create Custom Component dialog box.
2. Specify the component attributes.
3. Specify the WISHBONE interface connections.
4. Specify the clock/reset and optional external port connections.
5. Specify your custom component’s RTL design files.
6. Specify the user-configurable parameters that your RTL design, software,
or both may need, if applicable.
7. Optionally, specify software elements.
8. Specify the optional software files that your custom component may
provide for use in LatticeMico32 applications.
9. Apply the changes.
Note
The entire flow is based on the assumption that your custom component is written in
Verilog. If you have a custom component written in VHDL, you must perform a few
more steps before performing the steps just given. Refer to “Creating the Verilog
Wrapper for VHDL Designs” on page 87 for these steps.
Once you have imported your custom component into MSB, you can use the
same Import/Create Custom Component dialog box to edit the provided
information.
Note
A custom component is indicated in the MSB Available Components view with the
following icon: . You can remove a previously created custom component by
highlighting the component in the Available Components view and clicking the
Remove Custom Component button.
The location of the new component is stored in a settings file that MSB uses
to identify the available components.
Note
Do not use the top-level module name of your custom component as the component
name in this tab. Also, do not specify a directory within the Diamond installation as the
location for the new component.
Component Properties
You must set the parameters shown in Table 1 for your new component in the
Component tab.
Open Component XML Opens an existing component description file (<component_name>.xml) to edit
the existing component.
New Component Name Specifies the name of the component. The name you enter in this box will be used
to create a folder and a component description file (<component_name>.xml).
New Component Directory/ New Component Directory – Specifies the path of the component file. This option
is available if you are creating a new custom component and have selected the
Select Component XML
Create New Component option. Type in the path to your component folder, or use
the Browse button to browse to your new component folder.
Note: Your new component folder should be outside of the .\micosystem folder.
Select Component XML – Specifies the path of the component description file.
This option is available if you are editing an existing component and have
selected the Open Component XML option. Use the Browse button to browse to
the component description file (<component_name>.xml) of the component that
you want to edit.
Display Name Specifies the name of your component that you want MSB to display when it
appears in the Available Components window. It is not used for a folder or a file
name, so any combination of ASCII characters is permitted.
Version Specifies the version number of the component that you want MSB to display next
to the display name in the MSB Available Components window.
Type Specifies the type of component: I/O or memory. MSB supports only these two
types of components. The type of component determines the address assignment
of the component in MSB. I/O components are located in the LatticeMico32
processor’s non-cacheable region, and memory components are located in
LatticeMico32 processor’s cacheable region.
Choose IO or Memory from the drop-down menu. Memory components reside in
the lower 2G of the LatticeMico32 memory map and can be added to the
instruction and data ports. I/O components reside in the upper 2G. The I/O
component can only be connected to the data port.
Access The text entered in this field is not used by MSB for any other purpose
than to concatenate to the Display Name. For example, the SPI flash
component has read-only access, so the SPI flash can be used to store the
read-only or code sections of the .elf file, but it cannot be used for the
read-write section of the .elf file.
Read – Stores .elf file .rodata, .boot, and .text sections in memory.
Write – Stores .elf file .bss and .data sections in memory.
Read/Write – Stores any .elf section in memory.
HTML Help Specifies the name of the help file, if your component has an HTML help file
associated with it. It enables you to enter a path to an existing HTML file
describing your new component. Once you close the dialog box, this file is copied
into the directory structure created by the dialog box, so the original file is no
longer referenced. The contents of this file are displayed in the MSB Component
Help view. This file is optional.
Save Saves all the data currently entered for the component being defined. The Save
button performs a DRC to determine if the component is syntactically correct and
saves the data.
If the DRC fails, a message is displayed indicating that the component has errors
and cannot be used in a platform. The component icon displays a small red “x” in
the bottom left-hand corner.
If you are going to overwrite an existing component, another message appears
that asks permission to overwrite the previous design files.
Cancel Cancels the actions and closes the dialog box. If you did not save your changes,
a message box comes up to warn you that the changed data will be lost.
If your component has a master port—that is, if it can drive the WISHBONE
bus—you must specify master port connections. If your component has a
slave port—that is, it responds to bus master requests—you must specify the
slave port connections. If your component has both types of ports, you must
specify both port connections sequentially.
Figure 27 shows the basic steps required for specifying the connections to
your component’s master or slave port signals.
Not all port signals are mandatory. See Table 3 and Table 4 for a list of port
signals required for master and slave port connections.
All of the mandatory fields in the Port Attributes group box must be supplied
and the Add button clicked in order for entries to be visible in the Master/Slave
Ports group box. You can update an existing master or slave port connection
by clicking on the appropriate row in the spreadsheet view. Make any
changes to the port highlighted in the Master/Slave Ports group box by
modifying the appropriate element in the Port Attributes group box. When the
changes are complete, click the Update button to make the changes
permanent.
Table 2 lists the options available in the Master/Slave Ports tab of the Import/
Create Custom Component dialog box.
Master/Slave Ports Lists the master ports and the slave ports in your component.
You can create more than one master port.
Delete To delete a master port or a slave port, highlight the port in the Master/Slave
Ports list and click Delete. The port is not permanently deleted until you
save the component by using the Save or OK button.
Note: You cannot “undo” a port deletion. Once you click Delete and then OK, the
port is permanently deleted.
Type Specifies the type of port. Choose either MasterPort or SlavePort in the drop-
down menu. Master ports can generate WISHBONE cycles to attached
WISHBONE slave components. Slave ports cannot initiate WISHBONE
bus cycles; they can only respond to a WISHBONE master.
Display Name Specifies the name of the master or slave port. The name is displayed indented
and below the instance name of a component that has been added to a
MSB platform. Any ASCII character is permitted in this field.
Prefix Specifies a prefix that is used for two purposes:
It creates a unique name for the component ports connected to the
WISHBONE bus, for example, <prefix>_DAT_O.
It enables you to use the same instance name for different components and
avoid having name conflicts in the wires of the platform’s top level. When the
top-level interconnect is built, the wire connecting a slave component output
back to the master or masters is named
<instance_name><component_port_name>. Since <prefix> is used in
<component_port_name>, <prefix> appears in this wire name. For example,
if the prefix for a GPIO component is “GPIO,” the wire name will be
inst1GPIO_DAT_O.
Port Attributes The Port Attributes group box is used to perform a name translation
between the WISHBONE signal names in your custom component and
the WISHBONE signal names attached to the LatticeMico32 bus arbiter.
Refer to Table 3 on page 59 for a description of WISHBONE slave port signals.
Update Updates the options in the Master/Slave Ports tab. The Update button is only
available after a master or slave port entry in the Master/Slave Ports
group box has been highlighted. The Port Attributes group box displays
the values associated with the highlighted master or slave port element.
Use the Update button after modifying any of the Port Attribute fields.
Add Adds the master port or slave port to the Master/Slave Ports list at the top of the
dialog box.
Save Saves all the data currently entered for the component being defined. The Save
button performs a DRC to determine if the component is syntactically correct and
saves the data.
If the DRC fails, a message is displayed indicating that the component has errors
and cannot be used in a platform. The component icon displays a small red “x” in
the bottom left-hand corner.
If you are going to overwrite an existing component, another message appears
that asks permission to overwrite the previous design files.
Cancel Cancels the actions and closes the dialog box. If you did not save your changes,
a message box comes up to warn you that the changed data will be lost.
Table 3 lists the signals required to connect the master port to the
LatticeMico32 platform. Table 4 lists the signals required to connect the slave
port to the LatticeMico32 microprocessor. The ports that make up the
WISHBONE master or slave port must follow the specifications described in
the LatticeMico32 Processor Reference Manual table entitled “List of
Component Port and Signal Name Suffixes.”
<Prefix>_DAT_O Output 32 No
<Prefix>_LOCK_0 Output 1 No
<Prefix>_CTI_O Output 3 No
<Prefix>_BTE_O Output 2 No
<Prefix>_DAT_I Input 32 No
<Prefix>_ERR_I Input 1 No
<Prefix>_RTY_I Input 1 No
<Prefix>_DAT_I Input 32 No
<Prefix>_LOCK_I Input 1 No
<Prefix>_BTE_I Input 2 No
<Prefix>_DAT_O Output 32 No
<Prefix>_ERR_O Output 1 No
<Prefix>_RTY_O Output 1 No
The example in Figure 28 shows the steps required for specifying a slave port
connection on the custom component. Consider the following module
definition for a custom component:
In this module definition, there are three sets of signals: slave WISHBONE
port signals, mandatory clock/reset signals, and external interface signals
specific to the component’s behavior. In the Master/Slave Ports tab, only the
slave WISHBONE port signals are added. The mandatory clock/reset and the
external interface signals are added in the next tab.
This tab continues the task of building a Verilog wrapper around the custom
component. You use this tab to define the CLK_I, RST_I, and optional
INTR_O control signals. The component port specifies the signal name
presented at the <platform>.v top-level module created by MSB when the
platform is generated.
Step 4: Specify
component port signals.
The Connect To entry creates a connection from the signal name entered in
the Component Port box to a signal on the custom component.
Note
You cannot create dynamic-width input and output ports by using the Import/Create
Custom Component dialog box. You must directly edit the XML to create these ports.
Table 5 lists the options available in the External Ports tab of the Import/
Create Custom Component dialog box.
Delete Deletes the selected external port from the Parameters list.
Note: You cannot “undo” a port deletion. If you click OK, the port will be
permanently deleted. You cannot delete the ClockPort, ResetPort, or Interrupt
entries.
Port Type Displays the port type of the port selected in the Parameters box (either
ClockPort, ResetPort, Interrupt, or ExternalPort). You cannot select or edit this
information.
Direction Enables you to choose the port direction. Choose input, output, or inout from the
drop-down menu.
Active This option is only available if the Port Type is Interrupt. Choose <blank>, High,
or Low from the drop-down menu.
Connect To Specifies the name of the user-defined component port that will be connected to
the wrapper port named in the Component Port field.
Update Updates the port parameters list. Whenever a change is made to the Port
Attribute entries that you wish to make permanent, you must click the Update
button.
Add Inserts a new external port into the list of ports that the custom component
implements. Fill in each of the active Port Attribute fields and then click Add. If
there are no syntax errors, a new entry will be appended to the list of external
ports.
Reset Clears all entries in the Port Attributes group box and permits the entry of a new
external port. Use this button if the Add button is not available.
Save Adds the custom component to LatticeMico32. If the design-rule check fails, a
message appears that warns you that the data to be saved contains errors and
cannot be used in a platform. The component icon displays a small red “x” in the
bottom left-hand corner.
If the custom component passes the design-rule check, no message box or red
“x” appears, and the data is saved.
If you are going to override an existing file, another message comes up to ask
you for override permission.
Cancel Cancels the actions and closes the dialog box. If you did not save your changes,
a message box comes up to warn you that the changed data will be lost.
The External Ports tab enables you to specify connectivity of the following
sets of signals between your custom component’s top-level module and the
GUI-generated wrapper module:
In this example, the custom component has four external signals that must be
made available as platform inputs and outputs. It also requires an interrupt
line to be connected to the processor. The component’s mandatory clock
input port is named “wb_clk,” and the mandatory reset port is named “wb_rst.”
The following steps demonstrate how to connect the reset and clock ports of
the GUI-generated reset and clock ports of the custom component.
Figure 33: Selecting the Clock Port in the External Ports Tab
Note
MSB applies the platform port-naming convention when it generates the platform,
so the actual port name at the top level of the platform is
<instance_name>my_out_bus, where the <instance_name> is the name of the
component’s instance as entered in MSB.
6. To apply this port specification, select the Add button to update the GUI.
7. To add the other port specifications, you can do one of the following:
Click the Reset button and repeat the steps in this section for the
other port specifications.
Modify the editable boxes and select the Add button to add the other
port specifications.
Once you have done this, the External Ports tab should look like Figure 38,
completing the step of declaring the component’s external interface.
You specify the Verilog HDL files in the RTL Files tab of the Import/Create
Custom Component dialog box.
Table 6 lists the options available in the RTL Files tab of the Import/Create
Custom Component dialog box.
Top-Level Module Name If the custom component is a Verilog component, this option specifies the top-
level module name of the custom component.
If the custom component is a VHDL component, you must create a Verilog black-
box definition of the VHDL custom component and specify the name of the
Verilog black-box module.
The GUI creates a wrapper that instantiates the top-level module of the Verilog
custom component or the Verilog black-box module for a VHDL custom
component according to the port specifications for the custom component
provided in the Master/Slave Ports and External Ports tabs and the parameters
specification provided in the Parameters tab.
For VHDL custom components, passing VHDL generics is not supported, since
the VHDL custom component flow relies on .ngo files. Refer to “Creating the
Verilog Wrapper for VHDL Designs” on page 87 for more information on
importing VHDL WISHBONE-compliant custom components.
RTL File This entry box enables you to enter a file name containing HDL code that is a
part of your component. Enter a path and module name directly or use the
Browse button to add HDL files interactively.
Add Click the Add button to insert the file listed in the RTL File entry box to the list of
files displayed in the Import RTL Files table. Clicking Add does not update
the Component RTL Files group box. The Component RTL Files group
box is only populated when you edit an existing custom component, not
when you create a new custom component.
Delete Use this button to delete files from the Import RTL Files list. Highlight the file that
you wish to remove from the list and click Delete.
Directory When a custom component is being edited, the Directory text box shows the path
to the .rtl files currently associated with the component. You cannot edit this field.
Delete The Delete button in the Component RTL Files group box enables you to remove
files already associated with a custom component. Highlight the HDL file that you
want to remove and click Delete.
Save Adds the custom component to LatticeMico32. If the design-rule check fails, a
message appears that warns you that the data to be saved contains errors and
cannot be used in a platform. The component icon displays a small red “x” in the
bottom left-hand corner.
If the custom component passes the design-rule check, no message box or red
“x” appears, and the data is saved.
If you are going to override an existing file, another message comes up to ask
you for override permission.
Cancel Cancels the actions and closes the dialog box. If you did not save your changes,
a message box comes up to warn you that the changed data will be lost.
The custom component editor enables you to create a simple user interface
for assigning definitions and passed parameters to the component. You use
the Parameters tab to create this interface. The values entered into the user
interface enable you to:
Create Verilog definitions and parameters that control how the RTL is
synthesized.
Create C/C++ #define statements to provide information to the firmware
controlling the component.
RTL Parameters
You define the RTL parameters by selecting the parameter value in the Flags
drop-down box. The other controls in the Parameter Attributes group box
determine the properties of the parameter.
In the second case, the `define is a global value, which is useful for
configuring every instance of a component, not just a single instance of a
component.
Writing code that uses the system_conf.v file to find parameters is not
recommended.
Software Parameters
If your custom component has parameters meant for software use, you make
them available to the software by not declaring these parameters as
“parameter.” See Figure 41. Parameters used for RTL are also available for
software use.
Table 8 shows how the various value types are translated into this header file.
String Character string type Any printable characters #define PARAMETER “VALUE”
Frequency Platform frequency (passed by MSB provides the platform #define CPU_FREQUENCY
MSB when generating a frequency value, and SPE (FREQUENCY_IN_HERTZ)
platform) translates it to
CPU_FREQUENCY macro (e.g.
25MHz is passed as 25000000)
You cannot change this parameter’s value when instantiating the component
in a platform. It applies to all instances of the component in a platform. C/C++
SPE ignores this parameter and its value for components declared as
memory components. Refer to Chapter 3 and Chapter 4 of the LatticeMico
System Software Developer User Guide for more information on the file
support implementation for LatticeMico32.
GUI Presentation
The MSB perspective displays a configuration dialog box for your custom
component when you try to insert your component into a platform. This dialog
box enables you to modify the parameter values through a GUI interface. The
available GUI widgets for configuring parameters are:
Check – Enables you to select or deselect a parameter.
Radio – Enables you to select one of multiple parameters.
Text – Enables you to enter a value.
Combo – Enables you to select pre-determined values from a drop-down
menu.
Spinner – Enables you to select a value from a pre-determined range.
Table 9 shows the possible GUI widgets for the various value types.
String Text
List Combo
Table 10 lists the options available in the Parameters tab of the Import/Create
Custom Component dialog box
Parameter Name Specifies the name of the parameter to be passed to the Verilog source code.
When using Define types, be sure to make the name globally unique.
Display Text Specifies the display text that will be placed adjacent to the specific control. Each
component, when added to the platform, brings up an individualized dialog box.
Each element in the dialog box has descriptive text placed adjacent to a control.
Value Type Specifies the value type. Choose Define, String, Integer, List, or Frequency from
the drop-down menu.
Default Value Specifies how each parameter or `define is initialized when a component is
added to the platform. This field is free-form, so you must be careful when
entering default values. Any type mismatch or incorrect data entered here will
impact the synthesis process later.
If the value type is Integer, choose Text or Spinner from the drop-down menu.
If the value type is List, choose <blank> or Combo from the drop-down menu.
If the value type is Frequency, choose <blank> or Text from the drop-down
menu.
WIdget Setting Specifies the GUI widget setting. If the GUI widget is Combo, enter comma-
separated list values. If GUI widget is Spinner, enter minimum and maximum
values as a hyphen-separated pair.
The compiler flag specifies that this is a compiler option to be used in C/C++
SPE.
Standard I/O This option is only available for CharIODevice. Choose <blank>, input, output, or
inout from the drop-down menu.
Save Adds the custom component to LatticeMico32. If the design-rule check fails, a
message appears that warns you that the data to be saved contains errors and
cannot be used in a platform. The component icon displays a small red “x” in the
bottom left-hand corner.
If the custom component passes the design-rule check, no message box or red
“x” appears, and the data is saved.
If you are going to override an existing file, another message comes up to ask
you for override permission.
Cancel Cancels the actions and closes the dialog box. If you did not save your changes,
a message box comes up to warn you that the changed data will be lost.
You can specify these elements through the Software tab of the Import/Create
Custom Component dialog box.
C/C++ SPE uses the information provided through this tab for managed-make
projects or for platform library projects when generating code based on a
platform containing this component.
You can additionally specify elements of the structure to be initialized with the
values configured for parameters when you generate the platform.
The data type for structure members determines if they can be marked for
initialization by the C/C++ SPE managed-make build process. In Figure 43,
you select the initial value by selecting an appropriate parameter available in
the Value drop-down menu (step 3d). The parameter value types define which
parameters are listed in the Value drop-down menu on the basis of the
structure member’s data type.
Table 11 shows the data types that are available for elements of the structure
and the parameters available for initializing members of an element if you
choose to initialize the element during platform creation.
void * No N/A
int * No N/A
unsigned int Yes Integer, List, Define List must be a numeric list.
unsigned char Yes Integer, List, Define Values are not enclosed in
quotation marks and must
be valid numeric values.
Note
If you select the Array box for any member, you must select a “value” parameter. This
selected parameter’s value is used to determine the array size. C/C++ SPE cannot
initialize the array contents, but you can do so in your component’s initialization
function.
If your component needs to know the interrupt line it is connected to in a platform, you
can add an “int” or an “unsigned int” data member and declare its “value” as Interrupt.
C/C++ SPE automatically initializes this data member’s value to the interrupt line
assigned by MSB in the platform when performing a managed build.
Table 12 lists the options available in the Software tab of the Import/Create
Custom Component dialog box.
Data Type Specifies the C data type of the DDStruct element being added. The drop-down
menu enables you to specify the following C data types: void *, unsigned int, int,
int *, const char, unsigned char, unsigned char *, char, or char *.
Member Name Specifies the name of the DDStruct element being added.
Value Available values in the drop-down menu depend on the chosen data type.
Update Allows an element already added to the DDStruct to be modified. Highlight the
element, make any desired changes to the element, and the click Update to
activate the changes.
Add Adds a new element to the DDStruct structure with the values active in the
DDStruct Attributes group box.
Save Adds the custom component to LatticeMico32. If the design-rule check fails, a
message appears that warns you that the data to be saved contains errors and
cannot be used in a platform. The component icon displays a small red “x” in the
bottom left-hand corner.
If the custom component passes the design-rule check, no message box or red
“x” appears, and the data is saved.
If you are going to override an existing file, another message comes up to ask
you for override permission.
Cancel Cancels the actions and closes the dialog box. If you did not save your changes,
a message box comes up to warn you that the changed data will be lost.
Figure 44 shows the steps required for adding software support files.
The file types that you can select by using the Browse button and their
extensions are shown in Table 13.
Table 13: File Extensions and File Types of Imported C Software Files
File Extension File Type
For the managed build framework, the software files are classified as follows:
Application file type – These source files are compiled and linked as part
of the application build process instead of being compiled during the
platform library build process and becoming part of the platform library
archive.
Platform library file type – These source files are compiled during the
platform library build process and become part of the platform library
archive. The functions in these source-code files can be overridden by
The application file type and platform library file type govern the composition
of the component makefile.
Imported files do not become part of the component until you click the OK
button and save the component without error. The Current Software Files
portion of the Software Files tab only displays software files if an existing
custom component is being edited.
Table 14 lists the options available in the Software Files tab of the Import/
Create Custom Component dialog box.
Software File Enables you to browse to the software driver files. Copies the selected file into
the component folder.
Add Adds the file currently listed in the Software File entry box to the table of
Imported Files.
Delete Deletes the highlighted entry in the Import Software Files table.
Directory Displays the folder where the source code files associated with the component
being edited reside.
Delete Deletes a source file already associated with the component being edited.
File Type Specifies the file type. Choose the following from the drop-down menu:
Application, Platform Library, Structure Header, Header.
Save Adds the custom component to LatticeMico32. If the design-rule check fails, a
message appears that warns you that the data to be saved contains errors and
cannot be used in a platform. The component icon displays a small red “x” in the
bottom left-hand corner.
If the custom component passes the design-rule check, no message box or red
“x” appears, and the data is saved.
If you are going to override an existing file, another message comes up to ask
you for override permission.
Cancel Cancels the actions and closes the dialog box. If you did not save your changes,
a message box comes up to warn you that the changed data will be lost.
Note
Older versions of LatticeMico System Builder do not provide a member element of the
type DeviceReg_t in the DDStruct C structure by default. You can add it as an element
of user-defined data type. The DDStruct Attributes to be specified, as shown in
Figure 43, are as follows:
Data Type: DeviceReg_t
Member Name: lookupReg
Value: Uninitialized
Applying Changes
To apply the changes that you have made in the tabs of the Import/Create
Custom Component dialog box, select the OK button at the bottom of the
dialog box. LatticeMico System now performs design-rule checks. If it finds no
errors, the dialog box will close and the custom component will appear in the
MSB perspective.
If you need to re-edit the added custom component, select that component
and open the Import/Create Custom Component dialog box.
3. Import the VHDL source code into the project. During synthesis, turn off
I/O insertion by following these steps:
a. Select the File List tab in Diamond and double-click the name of the
currently active strategy, which is displayed in bold type.
b. In the Strategies dialog box, expand the Synthesis folder and select
the synthesis tool you will be using.
c. In the synthesis pane on the right, set Disable IO Insertion to True and
click OK.
d. In Diamond, select the Process tab , and double-click Translate
Design.
Diamond now generates the <platform>.ngo file.
4. Create a black-box declaration of the component in Verilog.
This declaration represents this component in any platform generated by
MSB that uses this component. It is combined with the .ngo file previously
created (that holds the actual functionality of the component) after
synthesis in the Translate Design process. If there are any bidirectional I/
Os in the custom VHDL component, you must declare them as black-box
pads. Lattice Semiconductor FPGAs only have tristate buffers in their I/O
cells. In a single-language implementation, the synthesis tool can
reconcile multiple tristate I/O requests to a single tristate buffer. In the
dual-language implementation, the Verilog wrapper has no visibility into
the VHDL .ngo black-box element, preventing any reconciliation of
multiple tristate buffers. The black-box pad declaration directs the
synthesis process not to create a second set of tristate buffers because
tristate buffers have already been created for these black-box ports.
Figure 45 is an example Verilog black-box definition of a VHDL custom
component illustrating the black_box_pad declaration in the Verilog black-
box definition for the VHDL custom component's inout port. This Verilog
black-box definition is the RTL input file for the custom component GUI.
Note
The Verilog module name must match the .ngo file name in order for Diamond to
correctly link the .ngo contents to the Verilog wrapper.
If there are tristate (bidirectional) I/Os in the custom VHDL component, you
must also add the black_box_pad_pin attribute of these ports to the VHDL
wrapper files’ component declaration section. The black_box_pad_pin
attribute is a synthesis directive that specifies pins on a user-defined black-
box component as I/O pads that are visible to the environment outside of the
black box. Because the I/O primitives are added to the tristate (bidirectional)
I/Os in the .ngo file, adding the black_box_pad_pin attribute to these I/Os
enables the top-level VHDL RTL code to recognize them.
// external signals
output [30:0] custom_ext,
inout [30:0] custom_ext_io,
input CLK_I,
input RST_I,
output INTR_O )/*synthesis syn_black_box
black_box_pad_pin = “custom_ext_io[30:0]” */;
endmodule
If your directory structure is not one of these, use your best guess to
provide either the relative path or absolute path and see if Diamond issues
an error message saying that it cannot expand the .ngo definition.
Directory Structure
Figure 46 shows a typical directory and file structure that LatticeMico System
generates for a LatticeMico32 component.
The following is a brief description of the folders and files contained in a
typical custom component folder:
<component_name> folder – Contains the following files and directories:
<component_name>.xml – Contains the XML code required to attach
your component to the LatticeMico32 processor.
document folder – Contains documentation file or files. At a minimum,
this folder contains the <component_name>.htm file, which is an
HTML file that is displayed in the Component Help view in the MSB
main window.
drivers folder – Contains the peripheral.mk file, which is used to direct
C/C++ System Programming Environment (SPE) to the C/assembly
<component_name>.c
Device driver files
<component_name>.h
<component_name>service.c
System service files
<component_name>service.h
rtl “rtl” subfolder
verilog “verilog” subfolder
<file>.v
Verilog component RTL files
<file>.v
endmodule
return;
}
Reg_Comp.h File The Reg_Comp.h file, shown in Figure 49, is the header
file for the software driver.
#include "DDStructs.h"
#ifdef __cplusplus
extern "C"{
#endif /* __cplusplus */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif//_REG_COMP_HEADER_FILE_
Functional Description
The sample custom component is a WISHBONE slave component containing
the three registers shown in Table 16 on page 99. These three registers are
general-purpose read/write registers. The lowest byte of register reg_00 is
made available as external pins of the component.
The port interface of the custom component in this example is shown
diagrammatically in Figure 50. The Verilog source code for this component is
shown in “Verilog RTL Implementation” on page 92.
Table 15 lists the input and output signals for the example component.
The example custom component includes the three 32-bit registers shown in
Table 16.
Software Support
For illustrative purposes, the example component’s initialization function must
set the reg_00 register to the value that was used to initialize the reg_08
register in the RTL. At run time, you can read this value from the reg_00
register and compare it to the RTL-initialized value in the reg_08 register.
Additionally, you can also read the platform frequency for which the platform
was configured in the reg_04 register.
While simple, the sample custom component contains enough useful features
to illustrate the key steps needed to import it into MSB:
WISHBONE slave interface
External pins
INterrupt signal
RTL parameter initialization
Software support
Figure 53: Opening the Import/Create Custom Component Graphical User Interface
Warning
The display name should not be the same as that of any of the design RTL files. It
also cannot be the same as the name of the top module file.
3. Specify the WISHBONE slave port signals for the component, as shown in
Figure 55.
4. Specify the component’s WISHBONE clock signal, as shown in Figure 56.
5. Specify the component’s WISHBONE reset signal, as shown in Figure 57.
6. Optionally, specify the component’s interrupt signal information, as shown
in Figure 58. If your component does not have an interrupt line, you do not
need to perform this step. Since the example component has an interrupt
line, you must specify its properties.
7. Specify the component’s external ports, as shown in Figure 59.
8. Specify the component’s RTL files, as shown in Figure 60.
9. Specify the component’s RTL parameters, as shown in Figure 61.
Figure 55: Specifying the WISHBONE Slave Port Signals for the Component
Figure 56: Specifying the WISHBONE Clock Signal for the Component
Figure 57: Specifying the WISHBONE Reset Signal for the Component
Figure 61 shows the steps required for adding a GUI widget for
configuring the reg_08 register’s value when you instantiate the custom
component in a platform.
Note
You might need to adjust the default size for your component.
Figure 62 shows the steps required for adding the CLK_MHZ parameter
for the component that will receive the platform’s WISHBONE clock-
frequency from MSB when instantiated a platform. This parameter will not
be visible for configuration.
Figure 62: Specifying the Platform’s WISHBONE Clock Frequency RTL Parameter
When importing a new component, you should always check the SIZE
parameter. The default value for the SIZE parameter determines the
default address-decode space for the component. Although you can
change it when you instantiate it in the platform, it is always a good idea to
make sure that the default value is sufficient to cover the entire
addressable space (for example, the space for registers, memory, or I/Os)
that is provided for the component being imported. The custom
component example has three registers—that is, a total decode space of
12 bytes—so the default value of 32 for the SIZE parameter is adequate.
The example custom component requires a data structure like that shown
in Figure 63.
Output
After you perform the steps in the “Adding the Custom Component” on
page 100, the component now appears in the MSB graphical user interface,
as shown in Figure 68.
Figure 70 shows the directory structure and the contents of the directories
created by the MSB graphical user interface.
Following are the terms and concepts that you should understand to use this
guide effectively.
application build An application build is the files that the managed build
process outputs and places in the application build output folder, for example,
the application executable, application build makefiles, application object files,
and necessary platform library files.
application object files Application object files are user source object files
that have been compiled and assembled from their source C files.
The component’s information in the .msb file includes the details about the
component’s source files that will need to be included in the build process.
The information is then extracted from the .msb file by the build process and
put into the DDStructs.h file. Each unique component must have its own
unique component information structure defined within its component
description file.
default linker script The default linker script, named linker.ld, is the default
linker script for the particular platform/project combination and can be used as
a starting point for creating a custom linker script file.
device driver files Device driver files are the source .c and .h C/C++ files
that contain driver code that will be compiled into object files during software
build.
.elf file An .elf file is a file in executable linked format that contains the
software application code written in C/C++SPE.
JTAG ports JTAG ports are pins on an FPGA or ispXPGA device that can
capture data and programming instructions.
makefiles Makefiles contain scripts that define what files the make utility
must use to compile and link during the build process. There are many
makefiles employed in the LatticeMico System build process. The makefile
file is the application build makefile, calling all of the other makefiles that allow
the generation and build of the platform library and for eventually generating
the final executable image.
.msb file The .msb file is the output XML file output by the MSB tool when
working in the MSB perspective. This .msb file is generated or updated when
you save your changes in the MSB perspective. This file defines your
platform, that is, the CPU and the peripherals in your design and also their
interconnectivity.
platform library The platform library is a set of files that contain subroutine
code that references the application files that are necessary for linking during
the build process.
platform library build The platform library build is an integral part of the
managed build process. Another is the application build. The platform library
files contain code that is necessary to the linking during the build process. The
platform library build also outputs a platform library archive (<platform>.a) file
that is referenced by the application build. It allows you to override any default
software implementation.
platform library archive (.a) file The platform library archive (<platform>.a)
file is automatically generated during a platform library build. It is used when
linking the application executable to resolve platform functions used by the
application and is derived from the platform library object files.
platform library object (.o) file The platform library object (.o) file is a
compiled output of the library source files and is input for creating platform
library archive files.
platform settings file The platform settings file is the user.pref file that is
generated during the build process contains platform information for the
platform used by the current project.
resources or resource files Resources are the projects, folders, and files
that exist in the Workbench. The navigation views provide a hierarchical view
of resources and allows you to open them for editing. Other tools may display
and handle these resources differently.
software application The software application is the code that runs on the
32-bit Mico processor to control the peripherals, the bus, and the memories.
The application is written in a high-level language such as C++.
source files In this document, source files generically refer to source .c and
header .h files written in C/C++ programming language.
source folders Source folders are the folders you may have on your
system or in the project folder that contain input for a project. Input might
include source files and resource files to help enhance or to initially establish
a LatticeMico32 project.
.xml file (1) The .xml file contains information about the parent project and
its settings, as well as information on the platform referenced by the parent
project. (2) The <comp_name>.xml files contain code declarations referred to
as component instance definitions that define the structure of each
component. These files reside in the <install_dir>/components folder. On build
generation, this information is copied into the .msb file by MSB.
CSR 118 E
custom components Eclipse 118
adding software files 84, 111 Eclipse C/C++ Development Toolkit User Guide
connecting external output ports 69 document 5
contents of custom component folder 90 Eclipse workbench 8, 9
creating Verilog wrapper for 61, 87 EDIF
defining control signals 61, 102 creating file in Linux 35, 36
directory structure created 54, 90 importing file into Diamond 36, 38
displaying software files 86 Edit Arbitration Priorities command 24, 25
editing 52 Edit Arbitration Priorities dialog box 26
example 92 Editor view 16, 24, 27
making available in MSB 90, 100 .elf file
specifying attributes 53, 101 definition of 118
specifying clock/reset and external ports 67, external input/output ports 66
102 External Ports tab 61, 102
specifying interrupt port 68, 102 connecting external output ports 68, 102
specifying RTL files 72, 75, 102 options available in 64
specifying RTL parameters 79, 102 sets of signals connected in 65
specifying software elements 81
specifying WISHBONE interface F
connections 56, 102 Family parameter 19
steps involved in creating 52, 101 fixed slave-side arbitration scheme 22, 23, 24, 26
WISHBONE interface in 51 Functional Simulation
Customize Perspective dialog box 10 Aldec Active-HDL 48
customizing default perspectives 10 ModelSim 48
functional simulation 40
D
data sheets 5 G
DDStruct structure 83 Generate Address command 28
DDStructs.h header file 86 Generate Address toolbar button 28
Debug perspective 9 Generate IRQ command 30
see also Debugger Generate IRQ toolbar button 30
Debugger generating bitstream for FPGA 37, 38
place in design flow 3 generating platform 30
purpose 2, 7 GNU Compiler Collection see GNU GCC compiler
deleting custom perspectives 11 GNU GCC compiler
Design Flow, IP 14 definition 119
design rule checks see DRC GNU GDB debugger
device driver files 118 definition 119
devices suppported 3 GPIO see LatticeMico GPIO
Diamond GUI widgets 77, 80
creating project 13
generating bitstream 37 H
generating FPGA bitstream 38
HAL 119
importing .lpf file 38
hardware platform see platform
importing EDIF file 38
importing Verilog file 36
importing VHDL file 36 I
installing 8 Import/Create Custom Component button 53
IP design flow 14 Import/Create Custom Component dialog box
Diamond Installation Notice document 6 applying changes 87
Directory parameter 18 Component tab 53, 101
DMA controller see LatticeMico DMA controller External Ports tab 61, 102
document icon 20 Master/Slave Ports tab 56, 102
double-buffered bidirectional ports 34 opening 52
DRC 21, 27, 30 Parameters tab 79, 102
purpose 52
RTL Files tab 72, 75, 102
saving settings 90
U
UART see LatticeMico UART
universal asynchronous receiver-transmitter see
LatticeMico UART
V
.v files 31, 33
Verilog
.msb file used in flow 31
.v file used in flow 31
adding logic to enable bidirectional bus
sharing 33
creating platform in 31
creating top-level module 61
creating wrapper for custom components 87
files generated by platform creation 31
importing file into Diamond 36
importing file on Windows 37
instantiation template 32
shared bus connection pattern in .v file 33
specifying in MSB 18
wrapper around custom components 61
.vhd file 32, 34