Programming Tools User Guide 34
Programming Tools User Guide 34
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.
This user guide is intended to provide users with basic information, and
references on where to find more detailed information, to assist in configuring
and programming Lattice devices using Diamond Programmer and related
tools including Deployment Tool, Programming File Utility, Download
Debugger, and Model 300 Programmer.
Programmer
Diamond Programmer is a system for programming devices. The software
supports both serial and concurrent (turbo) programming of Lattice devices
using PC and Linux environments. The tool also supports embedded
microprocessor programming. Refer to “Programmer Overview” on page 5.
Deployment Tool
Deployment Tool is a stand-alone tool available from the Diamond
Accessories. The Deployment Tool graphical user interface (GUI) is separate
from the Diamond design environment.
The Deployment Tool allows you to generate files for deployment for single
devices, a chain of devices, and can also convert data files to other formats
and use the data files it produces to generate other data file formats. Refer to
“Deployment Tool Overview” on page 13.
Download Debugger
Download Debugger is a utility for debugging programming for debugging
Serial Vector Format (SVF) files, Standard Test And Programming Language
(STAPL) files, and Lattice Embedded (VME) files. Download Debugger allows
you to program a device, and edit, debug, and trace the process of SVF,
STAPL, and VME files. Download Debugger also allows you to create, edit, or
view a VME file in hexadecimal format.
Model 300
The Model 300 Programmer is a simple engineering device programmer that
allows you to perform single-device programming directly from a PC or Linux
environment. The Model 300 Programmer software and hardware support all
JTAG devices produced by Lattice, with device Vcc of 1.8, 2.5, 3.3, and 5.0V.
Detailed information and procedures on how to use the Model 300 hardware
and software are contained in the “Using the Model 300 Programmer” section
in the Lattice Diamond online help or in the stand-alone Model 300 online
help.
Embedded Flow
Programming flow using a processor to read the contents of a stored
programming file and programming the FPGA. Lattice provides the option to
generate several different file formats for different embedded target options.
Refer to “Embedded Flow Overview” on page 19.
Driver Installation
A utility is available for installing programming drivers after the Diamond or
Programmer software has been installed. Refer to the topic “Installing/
Uninstalling Parallel Port Driver and USB Driver on a PC” in the Lattice
Diamond online help or in the stand-alone Programmer online help.
Programmer Overview
Programming Basics
To successfully program devices in-system, there are a few simple
requirements that must first be met. The first of these requirements is that the
devices on the board must be correctly connected into an 1149.1 scan chain.
This scan chain can be used for either programming or testing the board.
program the devices using a PC or Linux system and a board test system
connected by one of the following cables:
A Lattice parallel port cable with the 8-pin AMP connector or 10-pin
JEDEC connector
A Lattice USB port cable
In-System Programming
After you have compiled your design to a data file (JEDEC, hex, or bitstream)
and device programming is necessary, you must serially shift the fuse map (a
fuse map file is a design file that has the fuse data already pre-arranged in
exactly the same format as the physical layout of the fuse array of the device)
data into the device along with the appropriate addresses and commands.
Lattice non-volatile FPGA devices use embedded flash memory and require
only TTL-level programming signals. An integrated state machine controls the
sequence of programming operations, such as identifying the device, shifting
in the appropriate data and commands, and controlling internal signals to
program and erase the embedded Flash in the device. Programming consists
of serially shifting the logic implementation stored in a data file into the device
along with appropriate addresses and commands, programming the data into
the embedded Flash, and shifting the data from the logic array out for device
programming verification.
Most of Lattice’s devices use the IEEE 1149.1-1993 Boundary Scan Test
Access Port (TAP) as the primary interface for in-system programming.
Figure 2 on page 9 shows the basic programming flow for the device. It does
not include the data file conversion into fuse map data, for it assumes that
step has already been done. This programming flow will be the same,
regardless of the programming hardware used.
Note
If the device will not be programmed in-circuit (that is, by a cable or an embedded
processor), it is not necessary to preload or save the I/O states.
Programming Times
The time it takes to program a device can often determine where in the
manufacturing process a device, or group of devices, is programmed. A board
test system costing hundreds of thousands of dollars to purchase and as
much as one dollar per minute to operate can be an expensive alternative to
programming if programming times are too long. In many instances, it is more
cost-effective to buy a couple of PCs and program the devices using these
much cheaper systems.
The time it takes to completely program a device is based on the time it takes
to first erase the device, then to program each row in the device, and finally to
verify the device. The erase time for all devices is between 100 ms and 200
ms. A single row is programmed in 10 ms to 50 ms, depending on the device.
The verification process is the quickest of the required steps in the
programming sequence and mainly depends on the time required to shift the
verification data out of any given device.
USERCODE
User-programmable identification can ease problems associated with
document control and device traceability. Every Lattice 1149.1-compliant
device contains a 32-bit register that is accessible through the optional IEEE
1149.1 USERCODE instruction. This user-programmable ID register is
basically a user’s notepad provided in Flash or SRAM cells on each device.
Within 32 bits available for data storage, you may find it helpful to define
specific fields to make better use of the available storage. A field may use
only one bit (or all bits), and can store a wide variety of information. The
possibilities for these fields are endless, and their definition is completely up
to you.
Even with the device’s security feature enabled, the USERCODE register can
still be read. With a pattern code stored in the USERCODE register, you can
always identify which pattern has been used in a given device. As a second
safety feature, when a device is erased and re-programmed, the USERCODE
identification is automatically erased. This feature prevents any situation in
which an old USERCODE might be associated with a new pattern.
Programming Hardware
All programming specifications, such as the programming cycle and data
retention, are guaranteed when programming devices over the commercial
temperature range (0 to 70 degrees C). It is critical that the programming and
bulk erase pulse width specifications are met by the programming platform to
ensure proper in-system programming. The details of device programming
are invisible to you if you use Lattice programming hardware and software.
Computer Hardware
Programming is most commonly performed on a PC or Linux system using
the parallel port cable or the USB port cable.
Programming Software
Programmer supports programming of all Lattice devices in a serial daisy
chain programming configuration in a PC or Linux environment. The software
is built around a graphical user interface. Any required data files are selected
by browsing with a built-in file manager. The software supports both serial and
Embedded Programming
Programmer embedded source code is available for programming devices in
an embedded or customized environment. The programming source code is
written in ANSI-standard C language, which can be easily incorporated into
an embedded system or tester software to support programming of devices.
This code supports such common operations as Erase, Program, Verify, and
Secure. After completion of the logic design and creation of a JEDEC file,
Programmer can create the data files required for in-system programming on
customer-specific hardware: PCs, testers, or embedded systems.
FPGA Configuration
Programmer provides efficient and economical alternatives to large and
expensive PROMs that are normally used for configuring FPGA devices.
For an up-to-date list of Lattice devices that can be configured using SPI
flash, as well as a list of supported SPI flash devices, refer to the topic “Serial
Peripheral Interface (SPI) Flash Support” in the Lattice Diamond online help
or in the stand-alone Programmer online help.
The Deployment Tool allows you to generate files for deployment for single
devices, a chain of devices, and can also convert data files to other formats
and use the data files it produces to generate other data file formats. A four-
step wizard allows you to select deployment type, input file type, and output
file type.
The function types are accessed from the Function Type dropdown menu on
the Deployment Tool Getting Started dialog box, as shown in Figure 4.
IEEE 1532 ISC Data File Converts JEDEC files to IEEE 1532 compliant
ISC (In System Configuration) data files, which are used in conjunction with
IEEE 1532 compliant BSDL files to program a device.
on your design, or to keep all I/Os as bi-directional. The generic BSDL files
are available on the Lattice website.
JEDEC File Converts the following file types JEDEC, Binary Bitstream,
ASCII Bitstream, or IEEE 1532 ISC into a JEDEC file. The USERCODE,
USERCODE format, and set the Program Security Fuse for the JEDEC file.
Refer to the Deployment Tool online help for information about specific device
support.
SVF - Single Device SVF Single Takes one of the following user data files
types JEDEC, ASCII Bitstream, Binary Bitstream, or IEEE 1532 ISC and then
select an operation to generate an SVF (Serial Vector Format) file. Depending
on the data file selected then a certain set of operation for the device are
available to be selected. The user is able to check several options which will
modify the SVF file.
STAPL - JTAG Chain Generates a STAPL file for testing using only an XCF
file generated by Programmer.
ATE Takes an XCF file and then the user is able to specify Tester Type,
whether or not to skip the verify step in erase program verify or to split into
separate files. An ATE (Automated Test Equipment) is a serial vector file
specific to a test equipment vendor.
Refer to the Deployment Tool online help for information about specific device
support.
JTAG Full VME Embedded Takes an XCF as an input file, then the user
can check options such as Compress VME, include Header along with
several other options. This operation generates a VME file which is a
compressed hexadecimal representation of an SVF files.
Slave SPI Embedded This file type allows field upgrades via the slave SPI
port. This operation can be given an XCF, Binary Bitstream, and ASCII
Bitstream as an input file. If an Bitstream file is given then the operation for the
device must be specified along with whether or not to compress the
embedded file and whether or not to generate a HEX file. If an XCF file is
given there are no other operations or options the user needs to provide. This
operation will output an algorithm file (.sea) and a data file (.sed).
I2C Embedded I2C embedded files enable field upgrades via the I2C port. If
an XCF file is specified then the user is given the option to compress the
embedded files, generate a hex file, include comments, and if there should be
a fixed pulse width. If a Bitstream file is specified then the previous options are
available along with selecting the device operation and specifying the length
of the I2C Slave Address. Two files will be generated a data file (.ied) and an
algorithm file (.iea).
Refer to the Deployment Tool online help for information about specific device
support.
Dual Boot Takes two JEDEC, Binary Bitstream or ASCII Bitstream files and
then creates a single hex file to configure primary and golden sectors of an
external SPI Flash. The output format can be Intel Hex, Motorola Hex, and
Extended Tektronix Hex. The device will usually boot form the primary sector
unless there is a problem then it will boot from the gold sector.
Advanced This operation is for generating hex files which handles more
complicated operations such as Multiple Boot, and Quad I/O to configure
external memory. Users can set the output hex format, how big the SPI Flash
size is, whether or not to do a byte wide bit mirror, retain the bitstream header,
and Whether or not to optimize the memory space. Another option is to set
multiple user data file and where each of those data file's starting address
should be in memory.
sysCONFIG Daisy Chain. This is used when multiple devices are in a daisy
chain and configured from a single SPI flash or CPU. This operation will take
two Binary or ASCII bitstreams and convert them into a single hex file.
Refer to the Deployment Tool online help for information about specific device
support.
JTAG Full VME Embedded Enable field upgrades via the JTAG port.
JTAG Slim VME Embedded Featured s reduced foot print and is designed
for microcontrollers with limited resources, such as 8051 processors.
Slave SPI Embedded Enable field upgrades via the slave SPI port.
For all five embedded types, the Embedded VME support is comprised of C
source files that users must port into their embedded systems for the purpose
of programming Lattice devices. The porting process is also known as the
customization and compiling process. The end product of the porting process
will be the Embedded VME in compiled form, which will reside in the
embedded systems.
Depending on the port interface, such as JTAG, SPI, or I2C, the user can
select one of the five embedded VME types.
Figure 9 shows an example of Full VME embedded file generation for the
JTAG port.
AC Requirements:
TCK Fmax = 25 MHz.
TCK Rise Time and Fall Time = 50ns maximum.
Delay function resolution and accuracy = 1 millisecond minimum.
DC Requirements:
I/O voltage level of the driver = I/O voltage level of the VCC JTAG port of
the target devices. The VCC that power the JTAG port can be:
VCC core (All EE based devices)
VCCIO (MachXO devices)
VCCJ (All SRAM based and Flash based FPGA devices)
Programming current = 1 Ampere maximum.
Note
For information on configuring the Lattice iCE40 family of devices from an
embedded processor, refer to TN1248, iCE40 Programming and Configuration
Guide.
The SRAM based only devices are the easiest devices to support in terms of
Embedded VME porting for they normally do not require accurate timing.
The EE based devices are much more challenging for they require the 1
millisecond resolution and accurate timing.
The Flash based devices are the most challenging among the three types.
The delay function not only must have the 1 millisecond resolution and
accuracy, it also must be able to provide the cumulative delay time up to 150
seconds – the worst case erase time of some Flash based devices.
If the devices are not given the required programming delay time, the Flash
based devices will fail the verification during programming. It will be worse if
failure happens during Flash erase.
All Lattice EE and Flash based devices are designed with the over-stress and
over-charge protection technology. This technology is very critical to the
superior In-System Programmability of Lattice’s non-volatile devices. The
devices cannot be damaged when given an erase delay time or programming
delay time longer than the minimum specified.
The accuracy of the delay function discussed in this document will focus only
on meeting the minimum requirement. It means that when the delay function
is called to generate, for example, 100 ms delay time (by calling the delay
function 100 times), as long as the resulting delay time is equal to or greater
than 100 ms, the delay time is considered accurate.
The only undesirable side effect of applying longer erase delay time or
programming delay time to the devices is on the programming throughput.
Diamond Programmer provides precise delay timing to meet the programming
specification and optimizing on throughput.
If interested to find out the details of their VME files, simply convert the binary
VME files into the corresponding text based SVF file format using the
Download Debugger shipped with Diamond Programmer.
The verify flow is identical for the looping and fixed pulse programming flow.
The delay required for the verify flow is usually ~100us per row. The VME file
still requires 1 millisecond delay per row since the PC cannot provide
accurate timing if the delay is less than 1 millisecond.
Figure 13: Map Four GPIO Pins from the CPU to the Four JTAG Pins
The pin mapping index table on the hardware.c must be revised to match with
the customer’s board layout. On the PCB that is the target for porting the
Embedded VME, it is important and a good practice to route the JTAG port to
a test header for easy access using an oscilloscope or connecting to
Programmer for debugging.
All VME files begin with IDCODE verification to ensure the JTAG port pins are
mapped and connected properly.
The for loop usually is compiled into the ASSEMBLY code as shown below:
LOOP: EDC RA;
JNZ LOOP;
If each line of assembly code needs four (4) machine cycles to execute, the
total number of machine cycles to execute the loop is 2 x 4 = 8.
Note
Some CPUs have a clock multiplier to double the system clock for the machine clock.
Let the machine clock frequency of the CPU be F (in MHz), then one machine
cycle = 1/F.
It is obvious that the formula can be transposed into one microsecond = F/8.
Example: The CPU internal clock is set to 48 MHz, then one microsecond =
48/8 = 6.
The C code shown below can be used to create the millisecond accuracy. All
that needs to be changed is the CPU speed.
Step 2: Calibration
Let the number of system clocks to execute one line of code = 8 clocks.
If the system clock of the native CPU is faster than 400 MHz, the TCK pulses
must be slowed down to meet the 25 MHz maximum specification.
The setup time and hold time of TDI, TMS, and TDO relative to TCK is not of
concern for Embedded VME is constructed in the fashion that it is not possible
to violate that requirement whenever the frequency of TCK is within the
specification.
If the pulse width is found to be smaller than 1 millisecond, then increase the
cpu_frequency value until 1 millisecond delay is captured by the calibration
function.
If the TCK frequency is found to be faster than 25 MHz, then change the
sclock() function in hardware.c as shown below. The IdleTime normally is
Once the calibration is done, the Embedded VME (actually the JTAG port
driver) is ready to program the devices. The device specific programming
information is all self-contained in the VME file.
IDCODE check failure is the most common failure when porting Embedded
VME. It is a good practice to generate a Verify IDCODE only VME file first.
Run the VME file. If it passes, then the JTAG port to GPIO mapping is
confirmed. Once the port mapping is confirmed, then the programming VME
file can be used.
Using the calibration routine provided by Embedded VME will achieve the
accurate timing.
The JTAG Full VME Embedded software is a simplified version of the full
Diamond Programmer. By making it serial vector format (SVF) file centric,
JTAG Full VME Embedded is better targeted for embedded systems. Lattice
JTAG devices are supported and users are able to program competitor
devices through a simple SVF file translator. Lattice JTAG devices are those
devices that can be programmed using the IEEE 1149.1 boundary scan TAP
controller interface. Users are able to quickly and efficiently program chains of
devices using this powerful utility, thus improving productivity and lowering
costs.
The JTAG Full VME Embedded source code is designed to be hardware and
platform independent. A VME data file, or VME file, runs on all JTAG Full VME
Embedded applications.
JTAG Full VME Embedded file supports compression to reduce the VME file
size by compressing the data and address streams. A looping compression is
also employed to reduce the file size even further by taking advantage of the
repeating SVF constructs. The following describes each compression
scheme.
Compression by 4-bit count works by looking for repeating patterns within the
data stream that are not zeros or ‘F’s.
The repeating 4-bit count in this example would be ‘7F9,’ because it repeats
throughout the data stream. The 4-bit would be written only once in the VME
file, and would be followed by the number of repetitions found within the data
stream.
The compression scheme reduces the file size by not extrapolating repeating
information within the address and data streams. That task is left for the VME
processor.
...
...
The looping template is built based on the repeating SIR lines. Notice how the
TDI values for the SIR commands are a repeating sequence of 01, 02, and
07. In this case the resulting template would be:
VAR is written in place to hold the data that does not repeat. The non-
repeating data will get written into the VME file following each template. The
example above would look like this in the VME file:
LOOP 3
ENDLOOP
(20000000000000000000000000)
(7BFFF7BFFFF7BFFF7BFF)
(10000000000000000000000000)
(FFFF7FFFFFFFFFFFFFFF)
(08000000000000000000000000)
(FFFFFFFFFFFFFFFFFFFF)
The ‘LOOP 3’ tells the VME processor to loop the template three times. Each
time it encounters a ‘VAR’, it will grab the first available line of data following
the ‘ENDLOOP’ and replace ‘VAR’ with it. This technique reduces the file
significantly by keeping the similar constructs to a minimal, and only writing
the differences.
The following figure illustrates the JTAG Full VME Embedded flow.
File Mode Under the file mode, data is stored in a file system such as a
hard drive or a DOS flash. The data file is accessed using C library calls, such
as fopen, fread, and fclose. The file read operations collect data into the
system memory. The system memory of the Embedded system must be able
to store the entire bitstream from the file in a contiguous block of memory. The
memory block can be allocated in one of the three locations.
Data Segment – You can pre-determine how many bytes of data the
bitstream will require and then create an uninitialized array variable to
hold the data. This permanently allocates a portion of the Data Segment.
For example:
char programmingData[0x10000]; // allocate 64K
Stack Segment – You can pre-determine how many bytes of data the
bitstream will require and then create an uninitialized array variable to
hold the data. Depending upon the function call sequence, this may or
may not permanently allocate a portion of the system memory. See the
example code below.
int MyFunction ( ) {
char bitstreamArray[0x10000];
}
Heap Segment – You can determine at runtime how many bytes of data
the bitstream will require and then dynamically allocate an uninitialized
array variable to hold the data. You are responsible for freeing the
memory when it is not being used any longer. Below is an example.
char *bitstreamData;
bitstreamData = (char *)malloc(numberOfBitstreamBytes);
Static Linking Mode Under the static linking mode, the bitstream data is
converted from the file on the hard drive into a C source code file. The C
source code defines a byte array. The byte array is exactly the size of the
bitstream. The byte array can be linked into either the Code Segment or the
Data Segment. The memory allocated for the bitstream is permanently
consumed.
PROM Mode Under the PROM-based mode, the bitstream file is converted
from the file on the hard drive into an Intel HEX file. The HEX file is loaded into
a non-volatile memory using a PROM programming tool. The HEX file data is
placed in the non-volatile memory at a known address (that is, a fixed
address). The user C code initializes a pointer. The pointer is given the
starting address of the HEX byte stream. The memory used by the bitstream
is permanently allocated in the non-volatile memory.
The current version of the JTAG Full VME Embedded software is available
through the Programmer installation. The installation creates a sub-directory
called VMEmbedded, where the pre-compiled executables, source code, and
readme.txt can be found.
There are four sets of embedded-related source code that are shipped with
Programmer.
VME – The file-based VME is the programming engine that accepts VME
files as command line arguments to process the devices. By default, the
executable compiled from this source code targets Windows operating
Among all the source codes, only the hardware.c file requires user changes.
You should customize the hardware.c file according to your target platform.
The following figure illustrates JTAG Full VME Embedded JTAG port
programming engine.
This method only calculates the RAM requirements for the data of the device.
It does not account for transient variables that are used to execute the
programming algorithm. Transient variables are more difficult to calculate
because they appear in and out of scope often. Also, a variable size may
depend on the microprocessor’s register size. For example, an integer
variable on a 32-bit system is four bytes while the same variable on a 16-bit
system is only two bytes.
To approximate the RAM requirement for the run-time variables, add twenty
percent to the required RAM.
RAM Calculation Example The following is a partial SVF for the M4A3 32/
32 device:
TDO (000410410410410410410410410104104104104104104104104)
MASK (210410410410410410410410410104104104104104104104104);
The largest data frame size in this device is 202 bits. Therefore, TDI, TDO,
and MASK each require 26 bytes, making it a total of 3*26 = 78 bytes. To
account for run-time variables, the total required size would be 78 * 1.2 = 94
bytes.
To verify that the calculation is correct, convert the SVF file to VME, and use
the VME2HEX utility to convert from VME to HEX. This utility generates the
vme_file.h file, which gives the definitive memory size requirement.
If the VME file had been generated with the looping option, HeapBuf would
require extra bytes as well. Looping requires slightly more RAM but
significantly less ROM. When the VME file has not been looped, it does not
require any additional RAM, but ROM size can significantly increase. This
This method assumes that the SVF file will be generated with the turbo option.
If the SVF file were generated with the sequential option, the worst-case ROM
size would be doubled.
This method only calculates the ROM requirements for the data. It does not
account for opcodes that are used to translate the algorithm of the device. To
approximate the ROM requirement for the algorithm opcodes, add twenty
percent to the required ROM.
The actual ROM requirement might be significantly less than the theoretical
worst-case requirement because SVF2VME utilizes two compression
techniques, compression and looping, to decrease the VME file. The file size
difference is file-dependent.
Timer The engine requires the ability to delay for fixed time periods. The
minimum granularity of the delay is 1 microsecond. You can determine the
type of delay. This can be a simple software timing loop, a hardware timer, or
an operating system call, for example, sleep().
Port Initialization The firmware needs to place the port I/O into a known
state. The software assumes this has occurred.
Get Data Byte The engine calls the GetByte() function to collect one byte
from the JTAG Full VME Embedded or CPU bytestream.
Modify Port Register The engine, as it parses the bitstream data, changes
an in-memory copy of the data to be written onto the I/O pins. Calls to this
function do not modify the I/O pins. The engine uses virtual types (for
example, DONE_PIN) which this function turns into physical I/O pin locations
(for example, 0x400).
Output Data Byte The engine calls this function to write the in-memory
copy onto the I/O pins.
Input Status This function is used by the engine to read back programming
status information. The function translates physical pin locations (for example,
0x400) into virtual types used by the engine (for example, DONE_PIN).
Output Configuration Pins Some systems may wish to use the FPGA
CFG pins, and have the Embedded system control them. There is a separate
function call to manipulate the CFG pins.
Bitstream Initialization You must determine how you plan to get the
bitstream into your memory system, pre-compiled, HEX file based, or
dynamically installed. Whichever method you use the data structures which
pin to the bitstream need to be initialized prior to the first GetByte function call.
Device Device Row Size JTAG Slim VME VME File Size
(Bits) Embedded File Size No Compression
No Compression (1K Byte = 1024 Bytes)
(1K Byte = 1024 Bytes)
ispMACH 4000
Programming Mode: Turbo
Operation: Erase, Program, Verify
19KB
20KB
31KB
43KB
ispMACH 4000ZE
Programming Mode: Turbo
Operation: Erase, Program, Verify
3KB
5KB
Device Device Row Size JTAG Slim VME VME File Size
(Bits) Embedded File Size No Compression
No Compression (1K Byte = 1024 Bytes)
(1K Byte = 1024 Bytes)
10KB
19KB
2KB
1KB
6KB
13KB
LatticeEC/ECP
Programming Mode: Sequential
Operation: Fast Program
75KB
125KB
216KB
378KB
518KB
641KB
Device Device Row Size JTAG Slim VME VME File Size
(Bits) Embedded File Size No Compression
No Compression (1K Byte = 1024 Bytes)
(1K Byte = 1024 Bytes)
957KB
LatticeXP
Programming Mode: Sequential
Operation: FLASH Erase, Program, Verify
117KB
189KB
340KB
494KB
611KB
MachXO
Programming Mode: Sequential
Operation: FLASH Erase, Program, Verify
8KB
Device Device Row Size JTAG Slim VME VME File Size
(Bits) Embedded File Size No Compression
No Compression (1K Byte = 1024 Bytes)
(1K Byte = 1024 Bytes)
MachXO2
Programming Mode: Sequential
Operation: FLASH Erase, Program, Verify
11KB
11KB
24KB
24KB
48KB
48KB
48KB
68KB
68KB
68KB
68KB
115KB
Device Device Row Size JTAG Slim VME VME File Size
(Bits) Embedded File Size No Compression
No Compression (1K Byte = 1024 Bytes)
(1K Byte = 1024 Bytes)
115KB
115KB
115KB
115KB
198KB
198KB
198KB
MachXO3L
Programming Mode: Sequential
Operation: FLASH Erase, Program, Verify
68KB
115KB
198KB
Platform Manager 2
Programming Mode: Sequential
Operation: FLASH Erase, Program, Verify
14KB
Device Device Row Size JTAG Slim VME VME File Size
(Bits) Embedded File Size No Compression
No Compression (1K Byte = 1024 Bytes)
(1K Byte = 1024 Bytes)
22KB
LatticeECP2/2S
Programming Mode: Sequential
Operation: Fast Program
190KB
364KB
565KB
800KB
1140KB
1700KB
LatticeECP2M/2MS
Programming Mode: Sequential
Operation: Fast Program
756KB
1258KB
2022KB
2535KB
3281KB
Device Device Row Size JTAG Slim VME VME File Size
(Bits) Embedded File Size No Compression
No Compression (1K Byte = 1024 Bytes)
(1K Byte = 1024 Bytes)
LatticeXP2
Programming Mode: Sequential
Operation: FLASH Erase, Program, Verify
154KB
243KB
446KB
731KB
1017KB
LatticeECP3
Programming Mode: Sequential
Operation: Fast Program
503KB
882KB
2333KB
2333KB
3714KB
ECP5U
Programming Mode: Sequential
Operation: Fast Program
Device Device Row Size JTAG Slim VME VME File Size
(Bits) Embedded File Size No Compression
No Compression (1K Byte = 1024 Bytes)
(1K Byte = 1024 Bytes)
1883KB
ECP5UM
Programming Mode: Sequential
Operation: Fast Program
1883KB
LatticeSC/SCM
Programming Mode: Sequential
Operation: Fast Program
Important!
If the VME file size is more than 64K bytes, the VME Embedded driver must be
compiled as a 32-bit program. A 16-bit program can only address up to 64K bytes of
memory maximum.
JTAG Full VME Embedded The file-based JTAG Full VME Embedded is the
(file-based) programming engine that accepts VME files as
command line arguments to process the device(s).
In Deployment Tool, the JTAG Full VME Embedded software will then take the
device chain information and generate the VME file. If a non-Lattice device is
in the chain, you must add a JTAG-SVF device and supply the SVF file. For
chains with JTAG-SVF devices, JTAG Full VME Embedded generates two
VME files. You can use one or both files to program the device.
5. For Output Type, choose JTAG Full VME Embedded, then click OK.
6. In the Step 1 of 4 dialog box, select the XCF file, and click Next.
7. In the Step 2 of 4 dialog box, elect the desired file options. For detailed
option descriptions, including the option that allows you to generate a
HEX (.c) file, see the Deployment Tool online help.
8. Click Next.
9. In the Step 3 of 4 dialog box, in the Output File box, specify the location
and file name of the VME file.
10. Click Next.
11. In the Step 4 of 4 dialog box, click Generate.
Deployment Tool generates the VME file depending upon the options you
have chosen, and returns a message indicating that the process succeeded
or failed.
VME files can also be processed using the command line. See Running the
Deployment Tool from the Command Line online help for details.
Advanced Issues
Since SVF files are serial in nature, many vendors have options on the type of
operations to be performed when generating the SVF files. If an SVF file is too
large for the targeted embedded application, consider removing optional
operations or breaking up the operations by creating multiple SVF files. This
approach is much better than arbitrarily dividing the VME file.
Using Programmer, add the target devices into the chain with the appropriate
operations and data files. If a non-Lattice device is in the chain, set the device
as a JTAG-SVF device and provide the appropriate SVF file, SVF vendor, and
TCK frequency. For more information on supporting non-Lattice devices, see
Programmer’s on-line help documentation.
Use the Deployment Tool to generate the VME file. Refer to the Deployment
Tool online help for more information on Deployment Tool.
A HEX file can be created from a VME file by using the vme2hex source code
that is shipped with Programmer, or by selecting the Generate HEX (.c) File
option in Deployment Tool. This source code can be found in the installation
path of Programmer, under the
<install_path>\embedded_source\vmembedded\sourcecode\svf2vme. A HEX
file is a C-programming language file that has the VME byte codes converted
and stored in an array.
Combine the source code and HEX files into a project to be compiled. This
may be done by using a microcontroller compiler.
The TAP controller is a synchronous state machine that is based on the TMS
(Test Mode Select) and TCK (Test Clock) signals of the TAP and controls the
sequence of operations of the circuitry defined by the IEEE 1149.1 standard.
The TCK signal can be driven at a maximum of 25 MHz. JTAG devices in the
chain may limit the TCK speed. Confirm the Maximum TCK for all the devices
in the programming chain.
USERCODE. The first bit clocked into any of the registers is placed into the
MSB, and data is shifted towards TDO as additional bits are clocked in.
The processor begins by calculating the 16-bit CRC of the VME file and
comparing it against the expected CRC. If that is successful, the processor
then verifies the version of the VME file to make sure it is supportable. The
version is an eight byte ASCII of the format ____<Major
Version>.<Minor Version>, where <Major Version> and <Minor
Version> are digits 0-9. If the version verification fails, the processor
returns the error code –4 to indicate a file error.
The Main Engine Switch calls the appropriate case statements based on the
incoming byte code from the VME. Unrecognized byte codes will result in the
program exiting with the error code –4 to indicate a file error.
The SIR case statement begins by extracting the size of the register. The size
will be used later to indicate how many bits of data will be sent or read back
from the device. If the flow control has been set to CASCADE, then the
processor shifts the device to the SHIFTIR. The presence of CASCADE in the
flow control indicates that the SIR instruction is targeting over 64Kb of data
and has been broken down to ease the memory requirements.
If CASCADE has not been set, then the processor shifts the device into the
safe state IRPAUSE, and then to SHIFTIR. If HIR exists (see HIR Case
Statement), then the processor will bypass the HIR. The SIR sub-switch is a
switch that is based off of the byte codes that can potentially be found after
the SIR byte code.
The TDI byte code indicates that there is data that needs to be shifted into the
device. The data following the TDI byte will be extracted and decompressed,
if compression were selected, and held in memory until it is ready to be
shifted into the device.
The TDO byte code indicates that there is data that needs to be read and
verified from the device. The data following the TDO byte will be extracted
and decompressed, if compression were selected, and held in memory until it
is ready to be compared against data in the device.
The XTDO byte code indicates that the TDO data is the TDI data of the
previous frame, such as in the case of concurrent, or turbo, programming.
Data will not follow the XTDO byte code, resulting in a smaller VME. Instead,
the previous frame’s TDI data will be used as the current TDO data.
The MASK byte code indicates that there is mask data that needs to be used
when comparing the TDO values against the actual values read from the
device. The data following the MASK byte will be extracted and
decompressed, if compression were selected, and held in memory until it is
ready to be used when comparing against data in the device.
The DMASK byte code indicates that there is dynamic mask data that needs
to be used when comparing the boundary scan. The data following the
DMASK byte will be extracted and decompressed, if compression were
selected, and held in memory until it is ready to be used when comparing
against the boundary scan.
The CONTINUE byte code terminates the SIR instruction. When this byte is
encountered, it indicates that the processor is ready to send or read and verify
data from the device using the data it is currently holding in memory. If any
byte codes other than TDI, TDO, XTDO, MASK, DMASK, and CONTINUE
were encountered in the SIR Sub-switch, the program will exit with the error
code –4, indicating a file error.
If the TDO or XTDO byte code were encountered in the SIR sub-switch, then
that indicates that the SIR instruction is going to read data from the device,
else the SIR instruction is going to send data to the device.
If reading and verifying data from the device were successful, the processor
checks if the CASCADE flag has been set. If it is set, the control returns to the
Main Engine Switch. If the flag is off, the processor checks if TIR exists (see
TIR Case Statement). If it exists, then the trailer devices must be bypassed.
Next, it shifts the device to the stable state that followed the ENDIR byte code
(see ENDIR Case Statement). The control returns back to the Main Engine
Switch.
If reading and verifying data from the device were unsuccessful, the
processor checks if the vendor has been set to Xilinx. If the vendor is Xilinx,
repeat the read loop up to 30 times before returning an error. If the vendor is
not Xilinx, the processor bypasses the TIR if there are trailer devices. Next, it
shifts the device to the stable state that followed the ENDIR byte code. The
error code returned is –1 to indicate a verification failure.
If TDO or XTDO were not encountered in the SIR sub-switch, then the
processor sends data to the device. If the CASCADE flag has been set, the
control returns to the Main Engine Switch. If TIR exists, then the trailer
devices must be bypassed. Next, it shifts the device to the stable state that
followed the ENDIR byte code. The control returns back to the Main Engine
Switch.
If CASCADE has not been set, then the processor shifts the device into the
safe state DRPAUSE, and then to SHIFTDR. If HDR exists (see HDR Case
Statement), then the processor will bypass the HDR. The SDR sub-switch is a
switch that is based off the byte codes that can potentially be found after the
SDR byte code.
The TDI byte code indicates that there is data that needs to be shifted into the
device. The data following the TDI byte will be extracted and decompressed,
if compression were selected, and held in memory until it is ready to be
shifted into the device.
The TDO byte code indicates that there is data that needs to be read and
verified from the device. The data following the TDO byte will be extracted
and decompressed, if compression were selected, and held in memory until it
is ready to be compared against data in the device.
he XTDO byte code indicates that the TDO data is the TDI data of the
previous frame, such as in the case of concurrent, or turbo, programming.
Data will not follow the XTDO byte code, resulting in a smaller VME. Instead,
the previous frame’s TDI data will be used as the current TDO data.
The MASK byte code indicates that there is mask data that needs to be used
when comparing the TDO values against the actual values read from the
device. The data following the MASK byte will be extracted and
decompressed, if compression were selected, and held in memory until it is
ready to be used when comparing against data in the device.
The DMASK byte code indicates that there is dynamic mask data that needs
to be used when comparing the boundary scan. The data following the
DMASK byte will be extracted and decompressed, if compression were
selected, and held in memory until it is ready to be used when comparing
against the boundary scan.
The CONTINUE byte code terminates the SDR instruction. When this byte is
encountered, it indicates that the processor is ready to send or read and verify
data from the device using the data it is currently holding in memory. If any
byte codes other than TDI, TDO, XTDO, MASK, DMASK, and CONTINUE
were encountered in the SDR Sub-switch, the program will exit with the error
code –4, indicating a file error.
If the TDO or XTDO byte code were encountered in the SDR sub-switch, then
that indicates that the SDR instruction is going to read data from the device,
else the SDR instruction is going to send data to the device.
If reading and verifying data from the device were successful, the processor
checks if the CASCADE flag has been set. If it is set, the control returns to the
Main Engine Switch. If the flag is off, the processor checks if TDR exists (see
TDR Case Statement). If it exists, then the trailer devices must be bypassed.
Next, it shifts the device to the stable state that followed the ENDDR byte
code (see ENDDR Case Statement). The control returns back to the Main
Engine Switch.
If reading and verifying data from the device were unsuccessful, the
processor checks if the vendor has been set to Xilinx. If the vendor is Xilinx,
repeat the read loop up to 30 times before returning an error. If the vendor is
not Xilinx, the processor bypasses the TIR if there are trailer devices. Next, it
shifts the device to the stable state that followed the ENDIR byte code. The
error code returned is –1 to indicate a verification failure.
If TDO or XTDO were not encountered in the SDR sub-switch, then the
processor sends data to the device. If the CASCADE flag has been set, the
control returns to the Main Engine Switch. If TDR exists, then the trailer
devices must be bypassed. Next, it shifts the device to the stable state that
followed the ENDDR byte code. The control returns back to the Main Engine
Switch.
This byte notifies the embedded processor to enable the specified vendor
support.
Flow Control
Value Description
Opcode
INTEL_PRGM 0x0001 Intelligent programming in effect
CASCADE 0x0002 Currently splitting large SDR
REPEATLOOP 0x0008 Currently executing a repeat loop
Indicates the next stream needs a right
SHIFTRIGHT 0x0080
shift
Indicates the next stream needs a left
SHIFTLEFT 0x0100
shift
VERIFYUES 0x0200 Indicates Continue If Fail flag
The following table indicates the paths taken between stable states.
The JTAG Slim VME Embedded software behaves the same as the JTAG Full
VME Embedded. The difference is it is geared to a 8051 processor. The C
code adds memory space keywords specific to the 8051 processor. The size
of the devices which can be programmed are limited by the amount of
contiguous SRAM available to the 8051 processor.
Each project has the following files. The major entry point for JTAG Slim VME
Embedded is slim_vme.c.
slim_vme.c The slim_vme.c file is the only file that differs between the PC-
based and the 8051-based embedded solutions. This difference is due to the
way each of these interfaces to the VME algorithm and data files through the
entry point. This file contains the main and entry point functions.
slim_pro.c The slim_pro.c file provides the programming engine for the
JTAG Slim VME Embedded. The engine operates on the commands in the
VME algorithm, and fetches data from the VME data, if necessary. The engine
is responsible for functions such as sending data, verifying data, observing
timing delay, stepping through the state machine, decompression, and so on.
hardware.c The only file that you should modify is hardware.c. This file
contains the functions to read and write to the port and the timing delay
function. You must update these functions to target the desired hardware. The
released version targets the parallel port of the PC at address 0x0378 using
Lattice’s download cable.
opcode.h The opcode.h file contains the definitions of the byte codes used
in the VME algorithm format and programming engine.
debug.h The debug.h file will print out debugging information if the
preprocessor switch VME_DEBUG is defined in the project. This is an
optional file to include.
windriver.c and windriver.h The windriver.c and windriver.h files target the
JTAG Slim VME Embedded to Windows. These files will be compiled if the
preprocessor switch VME_WINDOWS is defined in the project file. These files
should be omitted when compiling the 8051-based JTAG Slim VME
Embedded onto an embedded platform.
The JTAG Slim VME Embedded system uses a compressed binary variation
of SVF files, called VME, as input. Like the SVF file, the VME file contains
high-level IEEE 1149.1 bus operations. These operations consist of scan
operations and movements between the IEEE 1149.1 TAP states. However,
unlike the SVF file, where the programming algorithm of the device is
intermeshed with the programming data, the VME file is separated into a VME
algorithm file and a VME data file. This separation of the algorithm and data
allows the optimization of the JTAG Slim VME Embedded programming
engine. It also allows you to mix VME data files with VME algorithm files,
provided the chain and operations are the same.
Figure 9 shows an example of Slim VME embedded file generation for the
JTAG port.
The JTAG Slim VME Embedded capability is enabled only if all the following
conditions are met:
All the devices in the chain are IEEE-1532 compliant.
Sequential mode is selected.
Synchronize Enable and Disable setting is unchecked.
Operation is not Read and Save or a display operation such as Calculate
Checksum or Display ID.
The HEX files must be compiled along with the 8051-based JTAG Slim VME
Embedded source code. The source code contains handles that allow the
compiler to link the buffers of the hexadecimal files to the main source code.
The only source code file that you need to modify is the hardware.c file. You
must implement methods to write and read to the hardware port, as well as
observe the timing delay. You must modify the following functions according to
the target platform:
readPort
writePort
ispVMDelay
The following are optional functions that you may wish to modify in the
hardware.c file in order to enable and disable the hardware conditions before
and after processing:
EnableHardware
DisableHardware
STATE 0x01
SIR 0x02
SDR 0x03
TCK 0x04
WAIT 0x05
ENDDR 0x06
ENDIR 0x07
HIR 0x08
TIR 0x09
HDR 0x0A
TDR 0x0B
BEGIN_REPEAT 0x0C
FREQUENCY 0x0D
TDI 0x0E
CONTINUE 0x0F
END_FRAME 0x10
TDO 0x11
MASK 0x12
END_REPEAT 0x13
DATA 0x14
PROGRAM 0x15
VERIFY 0x16
ENDVME 0x17
DTDI 0x18
DTDO 0x19
The byte codes perform the same operations as the SVF commands, with the
exception of BEGIN_REPEAT, CONTINUE, END_FRAME, END_REPEAT,
DATA, PROGRAM, VERIFY, ENDVME, DTDI, and DTDO.
The byte code CONTINUE appears at the end of every SIR and SDR
instruction as a terminator.
The byte code END_FRAME appears at the end of every frame in the VME
data as a terminator.
Translation from the SVF file to VME algorithm file is done command by
command. For example, the following SVF line:
SIR 8 TDI (16);
The VME Algorithm file is similar to the SVF file with the following differences:
VME Algorithm uses byte codes from the table below to represent SVF
commands
Fuse data and USERCODE have been removed
Looping algorithm
The following is an example of an EPV VME Algorithm file and the SVF
translation for the LC4064V device:
Table 2: VME Algorithm Example
VME Algorithm Format Serial Vector Format (SVF) Description
0x0A 0x00 HDR 0;
0x08 0x00 HIR 0;
0x0B 0x00 TDR 0;
0x09 0x00 TIR 0;
0x06 0x03 ENDDR DRPAUSE;
0x07 0x02 ENDIR IRPAUSE;
0x01 0x01 STATE IDLE;
0x02 0x08 0x0E 0x68 0x0F SIR 8 TDI (16); Shift in the IDCODE
instruction
0x01 0x01 STATE IDLE;
0x03 0x20 0x0E 0xFF 0xFF 0xFF SDR 32 TDI (FFFFFFFF) TDO Verify the IDCODE
0xFF 0x11 0xC2 0x09 0x01 0x80 (01809043) MASK (0FFFFFFF);
0x12 0xFF 0xFF 0xF0 0x0F
0x02 0x08 0x0E 0x38 0x0F SIR 8 TDI (1C); Shift in the PRELOAD
instruction
0x03 0x44 0x0E 0x00 0x00 0x00 SDR 68 TDI (00000000000000000); Shift all zero data into
0x00 0x00 0x00 0x00 0x00 0x00 boundary scan cells
0x0F
0x02 0x08 0x0E 0xA8 0x0F SIR 8 TDI (15); Shift in ENABLE instruction
0x01 0x01 0x04 0x03 0x05 0x14 RUNTEST IDLE 3 TCK 2.00E-002 SEC; Execute RUNTEST instruction
0x01 0x01
0x02 0x08 0x0E 0xC0 0x0F SIR 8 TDI (03); Shift in ERASE instruction
0x01 0x01 0x04 0x03 0x05 0x64 RUNTEST IDLE 3 TCK 1.00E-001 SEC; Execute RUNTEST instruction
0x01 0x01
0x02 0x08 0x0E 0x84 0x0F SIR 8 TDI (21); Shift in ADDRESS INIT
instruction
0x01 0x01 STATE IDLE;
0x02 0x08 0x0E 0xE4 0x0F SIR 8 TDI (27); Shift in PROGRAM INCR
instruction
0x0C 0x5F 0x15 N/A Begin PROGRAM repeat loop
of size 95
VME Algorithm Format Serial Vector Format (SVF) Description
0x03 0xE0 0x02 0x18 0x14 0x0F SDR 352 DTDI (DATA); Notice the forth byte is
0x18, which is actually
DTDI. DTDI instructs the
processor to send in data
from the data buffer
0x01 0x01 0x04 0x03 0x05 0x0D RUNTEST IDLE 3 TCK 1.30E-002 SEC; Execute RUNTEST instruction
0x01 0x01
0x13 N/A Terminate the repeat
algorithm
0x02 0x08 0x0E 0x58 0x0F SIR 8 TDI (1A); Shift in PROGRAM USERCODE
instruction
0x03 0x20 0x18 0x14 0x0F SDR 32 DTDI (DATA); Shift in the USERCODE The
USERCODE can be found in
the data buffer.
0x01 0x01 0x04 0x03 0x05 0x0D RUNTEST IDLE 3 TCK 1.30E-002 SEC; Execute RUNTEST instruction
0x01 0x01
0x02 0x08 0x0E 0x80 0x0F SIR 8 TDI (01); Shift in ADDRESS SHIFT
instruction
The first byte in the file indicates whether the data file has been compressed.
A byte of 0x00 indicates that no compression was selected, and 0x01
indicates that compression was selected. When compression has been
selected, each frame is preceded by a frame compression byte to indicate
whether the frame is compressible. This is necessary because even though
you might elect to compress the VME data file, it is possible that a
compressed frame will actually be larger than an uncompressed frame. When
that happens, the frame is not compressed at all and the frame compression
byte of 0x00 notifies the processor that no compression was performed on the
frame.
When compression has not been selected, the VME data file becomes a
direct translation from the data sections of the SVF file. The END_FRAME
byte, 0x10, is appended to the end of every frame as a means for the
processor to verify that the frame has indeed reached the end.
0x00 0x01
<Frame 1>0x10 <Compress Byte><Frame 1>0x10
<Frame 2>0x10 <Compress Byte><Frame 2>0x10
… …
<Frame N>0x10 <Compress Byte><Frame N>0x10
When the processor encounters the first byte 0xFF, it gets the next byte to
determine how many times 0xFF is compressed. The next byte is 0x0A,
which is ten in hexadecimal. This instructs the processor that 0xFF is
compressed ten times. The following byte is 0x12, which is processed as it is.
The next byte is again 0xFF followed by 0x03, which instructs the processor
that 0xFF is compressed three times.
Timer The engine requires the ability to delay for fixed time periods. The
minimum granularity of the delay is 1 microsecond. You can determine the
type of delay. This can be a simple software timing loop, a hardware timer, or
an operating system call, for example, sleep().
Port Initialization The firmware needs to place the port I/O into a known
state. The programming software assumes this has occurred.
Get Data Byte The engine calls the GetByte() function to collect one byte
from the VME or CPU bytestream.
Modify Port Register The engine, as it parses the bitstream data, changes
an in-memory copy of the data to be written onto the I/O pins. Calls to this
function do not modify the I/O pins. The engine uses virtual types (for
example, DONE_PIN) which this function turns into physical I/O pin locations
(for example, 0x400).
Output Data Byte The engine calls this function to write the in-memory
copy onto the I/O pins.
Input Status This function is used by the engine to read back programming
status information. The function translates physical pin locations (for example,
0x400) into virtual types used by the engine (for example, DONE_PIN).
Output Configuration Pins Some systems may wish to use the FPGA
CFG pins. There is a separate function call to manipulate the CFG pins.
Bitstream Initialization You must determine how you plan to get the
bitstream into your memory system, pre-compiled, HEX file based, or
dynamically installed. Whichever method you use the data structures which
pin to the bitstream need to be initialized prior to the first GetByte function call.
In Programmer, create a project, and add the target Lattice IEEE 1532
compliant devices into the chain with the appropriate operations and data
files. Refer to Programmer online help for more information on how to use
Programmer.
1. Save the Programmer project (.xcf).
2. In Deployment Tool, choose Create New Deployment.
3. For Function Type, choose Embedded System.
4. For Output Type, choose JTAG Slim VME Embedded, then click OK.
5. In the Step 1 of 4 dialog box, select the XCF file, and click Next.
6. To have the software check for a USERCODE match between the device
and the VME file before programming, select the Verify USERCODE,
Program Device if Fails option.
Note
Synchronize Enable and Disable has been turned on while using Sequential mode, the
software will force the VME file into Turbo mode.
7. In the Step 2 of 4 dialog box, elect the desired file options. For detailed
option descriptions, including the option that allows you to generate a
HEX (.c) file, see the Deployment Tool online help. To significantly reduce
the ROM required for storing the VME Data buffer in the embedded
system, select Compress VME File.
8. Click Next.
9. In the Step 3 of 4 dialog box, in the Output File box, specify the location
and file name of the VME algorithm and data files.
10. Click Next.
11. In the Step 4 of 4 dialog box, click Generate.
Deployment Tool generates the VME files depending upon the options you
have chosen, and returns a message indicating that the process succeeded
or failed.
slim_vme.c
The file slim_vme.c is the only file to differ between the PC-based and 8051-
based embedded solutions. This difference is due to the way each interfaces
to the VME Algorithm and Data files through the entry point. This file contains
the main and entry point functions.
slim_pro.c
The file slim_pro.c provides the programming engine of the JTAG Slim VME
Embedded. The engine operates on the commands in the VME Algorithm,
and fetches data from the VME Data if necessary. The engine is responsible
for functions such as sending data, verifying data, observing timing delay,
stepping through the state machine, decompression, and so on.
hardware.c
The only file that should be modified by the user is hardware.c. This file
contains the functions to read and write to the port and the timing delay
function. The user must update these functions to target the desired hardware
being used. The released version targets the parallel port of the PC at
address 0x0378 using Lattice's download cable.
opcode.h
The file opcode.h contains the definitions of the byte codes used in the VME
Algorithm format and programming engine.
debug.h
The file debug.h prints out debugging information if the preprocessor switch
VME_DEBUG were defined in the project. This is an optional file to
include.windriver.c and windriver.h
The files windriver.c and windriver.h target the JTAG Slim VME Embedded to
Windows 95 and 98. These files are compiled if the preprocessor switch
VME_WINDOWS were defined in the project file. These files should be
omitted when compiling the 8051-based JTAG Slim VME Embedded onto an
embedded platform.
Step 1. Create Chain with Lattice IEEE 1532 Compliant Devices using
Programmer
Using Programmer, add the target IEEE 1532 compliant devices into the
chain with the appropriate operations and data files. All the devices in the
chain must be IEEE 1532 compliant. For more information on supporting non-
Lattice devices, see Programmer’s on-line help documentation.
Use the Deployment Tool to generate the VME file. By checking the HEX
check box, the VME Algorithm and Data files will be generated as C-
programming files with the Algorithm and Data stored in C-style byte buffers.
Refer to Deployment Tool online help for more information on using the
Deployment Tool.
The 8051-based source code files are written in ANSI C and can be found in
the installation path of Programmer under the <install_path>\
embedded_source\slimembedded\sourcecode\slim_vme_8051 directory. The
file hardware.c is the only file that is required to be modified by the user. The
user must modify the following functions according to the target platform:
readPort
writePort
ispVMDelay
The following are optional functions that the user may wish to modify in order
to enable and disable the hardware conditions before and after processing:
EnableHardware
DisableHardware
Combine the source code and VME HEX files generated into a project to be
compiled. This may be done by using a microcontroller development tool to
create the project. The source codes windriver.c, windriver.h, and debug.h
shall not be required to be added into the project.
The TAP controller is a synchronous state machine that is based on the TMS
(Test Mode Select) and TCK (Test Clock) signals of the TAP and controls the
sequence of operations of the circuitry defined by the IEEE 1149.1 standard.
The TCK signal can be driven at a maximum of 25 MHz for current Lattice
IEEE 1532 Compliant devices.
USERCODE. The first bit clocked into any of the registers is placed into the
MSB, and data is shifted one bit towards TDO as additional bits are clocked
in.
The processor begins by verifying the VME version of the algorithm file. The
version is an eight byte ASCII of the format _SVME<Major Version>.<Minor
Version>, where <Major Version> and <Minor Version> are digits 0-9.
If the version verification fails, the processor returns the error code
ERR_WRONG_VERSION, or -4.
The Main Engine Switch calls the appropriate case statements based on the
incoming byte code from the VME Algorithm buffer. Unrecognized byte codes
will trigger the UNKNOWN case statement.
The SIR case statement begins by extracting the size of the register. The size
will be used later to indicate how many bits of data will be sent or read back
from the device. The processor then shifts the device into the safe state
IRPAUSE, and then to the state SHIFTIR. If HIR exists (see HIR Case
Statement), then the processor will bypass the HIR. The SIR sub-switch is a
switch that is based off of the byte codes that can potentially be found after
the SIR byte code.
The TDI byte code indicates that there is data that needs to be shifted into the
device. The processor will set the TDI index variable to point to the location
where the TDI data begins in the algorithm buffer.
The DTDI byte code indicates that there is data to that needs to be shifted into
the device. Unlike the TDI byte code, the DTDI byte code signals that the data
will be coming from the data buffer. If the data buffer has compression turned
on, the first byte of the data frame will be checked to see if the frame was
indeed compressible.
The TDO byte code indicates that there is data that needs to be read and
verified from the device. The processor will set the TDO index variable to
point to the location where the TDO data begins in the algorithm buffer.
The DTDO byte code indicates that there is data that needs to be read and
verified from the device. Unlike the TDO byte code, the DTDO byte code
signals that the data will be coming from the data buffer. If the data buffer has
compression turned on, the first byte of the data frame will be checked to see
if the frame were indeed compressible.
The MASK byte code indicates that there is mask data that needs to be used
when comparing the TDO values against the actual values scanned out of the
device. The processor will set the MASK index variable to point to the location
where the MASK data begins in the algorithm buffer.
The UNKNOWN case statement is the default for unrecognized byte codes.
This case returns the error code ERR_ALGO_FILE_ERROR, or -5, to indicate
an error in the algorithm.
The CONTINUE byte code terminates the SIR instruction. When this byte is
encountered, it indicates that the TDI, DTDI, TDO, DTDO, and MASK indexes
are pointing to their correct locations and the processor is ready to send or
read and verify data from the device.
If the TDO or DTDO byte code were encountered in the SIR sub-switch, then
that indicates that the SIR instruction is going to read data from the device,
else the SIR instruction is going to send data to the device.
If reading and verifying data from the device were successful, the processor
checks if TIR exists (see TIR Case Statement). If TIR exists, then the trailer
devices must be bypassed. Next it shifts the device to the stable state that
followed the ENDIR byte code (see ENDIR Case Statement). The control
returns back to the Main Engine Switch.
If reading and verifying data from the device were unsuccessful, the
processor checks if TIR exists. If TIR exists, then the trailer devices must be
bypassed. Next it shifts the device to the stable state that followed the ENDIR
byte code. The error code ERR_VERIFY_FAIL, or -1, is returned and the
program exits.
If TDO or DTDO were not encountered in the SIR sub-switch, then the
processor sends data to the device. If TIR exists, then the trailer devices must
be bypassed. Next it shifts the device to the stable state that followed the
ENDIR byte code. The control returns back to the Main Engine Switch.
The TDI byte code indicates that there is data that needs to be shifted into the
device. The processor will set the TDI index variable to point to the location
where the TDI data begins in the algorithm buffer.
The DTDI byte code indicates that there is data to that needs to be shifted into
the device. Unlike the TDI byte code, the DTDI byte code signals that the data
will be coming from the data buffer. If the data buffer has compression turned
on, the first byte of the data frame will be checked to see if the frame were
indeed compressible.
The TDO byte code indicates that there is data that needs to be read and
verified from the device. The processor will set the TDO index variable to
point to the location where the TDO data begins in the algorithm buffer.
The DTDO byte code indicates that there is data that needs to be read and
verified from the device. Unlike the TDO byte code, the DTDO byte code
signals that the data will be coming from the data buffer. If the data buffer has
compression turned on, the first byte of the data frame will be checked to see
if the frame were indeed compressible.
The MASK byte code indicates that there is mask data that needs to be used
when comparing the TDO values against the actual values scanned out of the
device. The processor will set the MASK index variable to point to the location
where the MASK data begins in the algorithm buffer.
The UNKNOWN case statement is the default for unrecognized byte codes.
This case returns the error code ERR_ALGO_FILE_ERROR, or -5, to indicate
an error in the algorithm.
The CONTINUE byte code terminates the SDR instruction. When this byte is
encountered, it indicates that the TDI, DTDI, TDO, DTDO, and MASK indexes
are pointing to their correct locations and the processor is ready to send or
read and verify data from the device.
If the TDO or DTDO byte code were encountered in the SDR sub-switch, then
that indicates that the SDR instruction is going to read data from the device,
else the SDR instruction is going to send data to the device.
If reading and verifying data from the device were successful, the processor
checks if TDR exists (see TDR Case Statement). If TDR exists, then the trailer
devices must be bypassed. Next it shifts the device to the stable state that
followed the ENDDR byte code (see ENDDR Case Statement). The control
returns back to the Main Engine Switch.
If reading and verifying data from the device were unsuccessful, the
processor checks if TDR exists. If TDR exists, then the trailer devices must be
bypassed. Next it shifts the device to the stable state that followed the
ENDDR byte code. The error code ERR_VERIFY_FAIL, or -1, is returned and
the program exits.
If TDO or DTDO were not encountered in the SDR sub-switch, then the
processor sends data to the device. If TDR exists, then the trailer devices
must be bypassed. Next it shifts the device to the stable state that followed
the ENDDR byte code. The control returns back to the Main Engine Switch.
The following is an example of an EPV VME Algorithm file and the SVF
translation for the LC4064V device:
Table 3: VME Algorithm Example
VME Algorithm Format Serial Vector Format (SVF) Description
0x0A 0x00 HDR 0;
0x08 0x00 HIR 0;
0x0B 0x00 TDR 0;
0x09 0x00 TIR 0;
0x06 0x03 ENDDR DRPAUSE;
0x07 0x02 ENDIR IRPAUSE;
0x01 0x01 STATE IDLE;
0x02 0x08 0x0E 0x68 0x0F SIR 8 TDI (16); Shift in the IDCODE
instruction
0x01 0x01 STATE IDLE;
0x03 0x20 0x0E 0xFF 0xFF 0xFF SDR 32 TDI (FFFFFFFF) TDO Verify the IDCODE
0xFF 0x11 0xC2 0x09 0x01 0x80 (01809043) MASK (0FFFFFFF);
0x12 0xFF 0xFF 0xF0 0x0F
0x02 0x08 0x0E 0x38 0x0F SIR 8 TDI (1C); Shift in the PRELOAD
instruction
0x03 0x44 0x0E 0x00 0x00 0x00 SDR 68 TDI (00000000000000000); Shift all zero data into
0x00 0x00 0x00 0x00 0x00 0x00 boundary scan cells
0x0F
0x02 0x08 0x0E 0xA8 0x0F SIR 8 TDI (15); Shift in ENABLE instruction
0x01 0x01 0x04 0x03 0x05 0x14 RUNTEST IDLE 3 TCK 2.00E-002 SEC; Execute RUNTEST instruction
0x01 0x01
0x02 0x08 0x0E 0xC0 0x0F SIR 8 TDI (03); Shift in ERASE instruction
The main routines that will require customization are in the hardware.c file. It
includes the routines for reading from and writing to the JTAG pins and a
delay routine. These routines are well commented in hardware.c and are at
the top of the file. In readPort(), a byte of data is read from the input port. In
writePort(), a byte of data is written to the output port. In ispVMDelay(), the
system delays for the specified number of milliseconds or microseconds. The
port mapping is set at the top of the hardware.c file.
The purpose of this usage note is to provide the user with information about
how to port the Slave SPI Embedded source code to different embedded
systems. The following sections describe the embedded system requirements
and the modifications required to use Slave SPI Embedded source code.
This usage guide is updated for Slave SPI Embedded version 2.0. Major
changes includes new format of data file, and Lattice parallel port and USB
cable support. In the Slave SPI Embedded source code, there are updates in
intrface.c and core.c, but no update in hardware.c. Version 2.0 updates will be
marked with [New in version 2.0] tag.
Requirements
This section lists device requirements, embedded system requirements, and
other requirements.
Device Requirements
Only Lattice Semiconductor's FPGA families with SPI port are supported.
Single device support. Multiple device support is not available.
The Slave SPI port must be enabled on the device in order to use the
Slave SPI interface. This is done by setting the SLAVE_SPI_PORT to
Enable using the Global Preferences spreadsheet in Diamond
Spreadsheet view.
Read and Save operations and display operations are not supported.
Other Requirements
The Slave SPI Embedded system requires memory space to store
programming data file. The storage may be internal or external memory
(RAM, Flash, etc.). The user may also consider storing the programming data
in an external system such as PC. In this case, the user needs to establish
communication between the external system and the embedded system.
STARTTRAN 0x10
CSTOGGLE 0x11
TRANSOUT 0x12
TRANSIN 0x13
RUNCLOCK 0x14
ENDTRAN 0x1F
MASK 0x21
ALGODATA 0x22
PROGDATA 0x25
RESETDATA 0x26
PRODATAEH 0x27
REPEAT 0x41
ENDREPEAT 0x42
LOOP 0x43
ENDLOOP 0x44
STARTOFALGO 0x60
ENDOFALGO 0x61
HCOMMENT 0xA0
HENDCOMMENT 0xA1
ALGOID 0xA2
VERSION 0xA3
BUFFERREQ 0xA4
STACKREQ 0xA5
MASKBUFREQ 0xA6
HCHANNEL 0xA7
HEADERCRC 0xA8
COMPRESSION 0xA9
HDATASET_NUM 0xAA
HTOC 0xAB
uncompressed frame. When that happens, the frame is not compressed at all
and the frame compression byte of 0x00 is added to notify the processor that
no compression was performed on the frame.
Uncompressed Slave SPI Data Format Compressed Slave SPI Data Format
0x00 0x01
<Frame 1>0x10 <Compress Byte><Frame 1>0x10
<Frame 2>0x10 <Compress Byte><Frame 2>0x10
… …
<Frame N>0x10 <Compress Byte><Frame N>0x10
The hex file is a C programming language file that must be compiled with the
EPROM-based version of Slave SPI Embedded processor and utilizes the
extension *.c. The binary file is generated by default. Other options are
available through the dialog, such as data file compression, adding comments
to the algorithm file, or disable generating the algorithm or data file.
Modifications
The Slave SPI Embedded source code is installed in the
<install_path>\embedded_source\sspiembedded\sourcecode directory where
you installed the Diamond Programmer. There are two directories in the src
directory, SSPIEm and SSPIEm_eprom. The first directory, SSPIEm, contains
the file-based Slave SPI Embedded source code, and can support sending
and receiving multiple bytes over the channel. The second directory,
SSPIEm_eprom, contains the EPROM-based Slave SPI Embedded source
code, which supports the algorithm and data being compiled with the process
system.
//*********************************************************************
//* Example comment
//*********************************************************************
Before using the Slave SPI Embedded system, there are three sets of files (.c
/ .h) that need to be modified. The first set, hardware.c and hardware.h, must
be modified. This file contains the SPI initialization, wait function, and SPI
controlling functions. If the user would like to enable debugging functionalities,
debugging utilities need to be modified in this file as well. [New in version 2.0]
hardware.c source code supports transmitting and receiving multiple bytes at
once. This approach may be faster in some SPI architecture, but it requires a
buffer to store the entire frame data. If the user wishes to use single byte
transmission, replace hardware.c and hardware.h with the ones in file
sspiem_sbyte.zip.
The second set, intrface.c and intrface.h, contains functions that utilize the
data and algorithm files. There are two sections in this file that requires
attention. The first one is data section. When the processor in Slave SPI
Embedded system needs to process a byte of data, it calls function
dataGetByte(). Slave SPI Embedded version 2.0 requires data file no
matter what operation it is going to process. Users are responsible to modify
the function to fit their configuration. The second section is algorithm section.
In Programmer, there is the option to generate both the algorithm file and the
data file in hex array format (C compatible). If the user wishes to compile the
algorithm and data along with Slave SPI Embedded system, use the source
code in the
<install_path>\embedded_source\sspiembedded\sourcecode\sspiem_eprom
directory. Users only need to put the generated .c file in the same folder as
Slave SPI Embedded system code and then compile the whole thing. If the
embedded system has internal memory that can be reached by address,
using EPROM version of intrface.c is also ideal. For users who plan to put the
algorithm and data in external storage, intrface.c and intrface.h may need
modification.
[New in version 2.0] The third file set is SSPIEm.c and SSPIEm.h. Function
SSPIEm_preset() provides the user to set which algorithm and data will be
processed. This function needs to be modified according to users'
configuration.
hardware.c
There is update in version 2.0 hardware.c source code. In previous version,
users are responsible to modify function TRANS_tranceive_stream().
Version 2.0 source code, which support transmitting multiple bytes at once,
includes two functions, TRANS_transmitBytes() and
TRANS_receiveBytes(), that function TRANS_tranceive_stream()
would call. Therefore, TRANS_tranceive_stream() no longer require user
attention in this configuration, but the user is responsible to modify
TRANS_transmitBytes() and TRANS_receiveBytes(). If the user wish
to implement Slave SPI Embedded so it transmit one byte at a time, then
TRANS_tranceive_stream() need to be modified.
int SPI_init(); This function will be called at the beginning of the Slave SPI
Embedded system. Duties may include, but not limited to:
int SPI_final(); This function will be called at the very end of the Slave SPI
Embedded system. The function returns a 1 to indicate success, or a 0 to
indicate fail.
void wait(int ms); This function takes a delay time (in milliseconds), and
waits for the amount of delay time. This function does not need a return value.
If the dedicated SPI interface in the embedded system automatically starts the
clock and pulls CS low, then this function only returns a 1. This function
returns a 1 to indicate success, or a 0 to indicate fail.
This way the device will still see the clock but the CS of current channel will
stay high. The function returns a 1 to indicate success, or a 0 to indicate fail.
For single byte transmission, this is the most complex function that needs to
be modified. First, it will transmit the amount of bits specified in trCount with
data stored in trBuffer. Next, it will have the following operations
depending on the flag:
NO_DATA: End of transmission. trCount2 and trBuffer2 are
discarded.
BUFFER_TX: Transmit data from trBuffer2.
BUFFER_RX: Receive data and compare it with trBuffer2.
DATA_TX: Transmit data from external data.
DATA_RX: Receive data from trbuffer2.
If the data is not byte-bounded and your SPI port only transmits and receives
byte-bounded data, padding bits are required to make it byte-bounded. When
transmitting non-byte-bounded data, add the padding bits at the beginning of
the data. When receiving data, do not compare the padding, which are at the
end of the transfer. The function returns a 1 to indicate success, or a 0 to
indicate fail.
SSPIEm.c
int SSPIEm_preset(); This function calls dataPreset() and algoPreset()
functions to pre-set the data and algorithm. The input to this function depends
on the configuration of the embedded system. This function returns 1 to
indicate success, or 0 to indicate fail.
[New in version 2.0] int dataPreset(); This function allows user to set
which data will be used for processing. It returns 1 to indicate success, or 0 to
indicate fail.
int dataInit (unsigned char *comp); This function initializes the data. The
first byte of the data indicates if the fuse data is compressed. It retrieves the
first byte and stores it in the location pointed to by *comp. The fuse data starts
at the second byte. The implementation may vary due to different
configuration. The function returns a 1 to indicate success, or a 0 to indicate
fail. For implementation that uses internal memory, which can be accessed by
addressing, the following is an example implementation:
Points variable data to the beginning of the fuse data.
Resets count to 0.
int dataGetByte(int *byteOut); This function gets one byte from data array
and stores it in the location pointed to by byteOut. The implementation may
vary due to different configuration. The function returns 1 to indicate success,
or 0 to indicate fail. For implementation that uses internal memory, which can
be accessed by addressing, here is a sample implementation:
Gets byte that variable data points to.
Points data to the next byte.
Count++.
int dataReset(); This function resets the data pointer to the beginning of the
fuse data. Note that the first byte of the data is not part of the fuse data. It
indicates if the data is compressed. The implementation may vary due to
different configuration. The function returns a 1 to indicate success, or a 0 to
indicate fail. For implementation that uses internal memory, which can be
accessed by addressing, the following is an example implementation:
Points variable data to the beginning of the data array.
Resets count to 0.
[New in version 2.0] int algoPreset(); This function allows user to set
which algorithm will be used for processing. It returns 1 to indicate success, or
0 to indicate fail.
int algoInit(); This function initializes the data. The implementation may
vary due to different configuration. The function returns a 1 to indicate
success, or a 0 to indicate fail.
1. EPROM Approach
With this version, both algorithm and data are generated into C-compatible
Hex array and compiled along with Slave SPI Embedded source code. Here
is how the functions are modified to fit this configuration:
Include both Hex arrays in the global scale.
Pass the pointer to the arrays to SSPIEm_preset(). In this function,
pass the pointer to algoPreset() and dataPreset() functions,
respectively. Both functions store the pointer in global variables defined in
intrface.c.
Although optional, it may be a good idea to keep track of the size of both data
and algorithm arrays. The size of array may be passed to Slave SPI
Embedded through the preset functions.
If the embedded system uses internal memory that can be reached the same
way as using array, this configuration may also fit into the embedded system.
If the user plans to use EPROM approach, intrface.c will be available, and the
user may not need to modify it. The files intrface.c, intrface.h, SSPIEm.c, and
SSPIEm.h are in the
<install_path>/SSPIEmbedded/SourceCode/src/SSPIEm_eprom directory.
Usage
In order to use the Slave SPI Embedded system, include the Slave SPI
Embedded system in the target embedded system by including SSPIem.h to
the header list. To start the processor, simply make this function call:
Currently, the converter does not have algoID capability. This capability is
reserved for future use. Use 0xFFFFFFFF for algoID.
Succeed 2
Process Failed 0
Initialization Failed -6
I2C Embedded
The physical I2C buss consists of two wires: SCL and SDA.
SCL is the clock line. It is used to synchronize all data transfers over the
I2C bus.
SDA is the data line.
The SCL & SDA lines are connected to all devices on the I2C bus. There must
be a third wire connected to ground or 0 volts. There may also be a 5V wire
for power distribution t he devices. Both SCL and SDA lines are “open drain”
drivers, meaning that the device can drive its output low, but it cannot drive it
high. For the line to be able to go high, you must provide pull-up resistors to
the 5V supply. There should be a resistor from the SCL line to the 5V line and
another from the SDA line to the 5V line. You only need one set of pull-up
resistors for the entire I2C bus, as illustrated below.
The primary I2C port of the Mach XO2 device can be used as a user I2C port
function or as a device programming port. When used for device
programming, the primary I2C port is a slave I2C with a default slave address
The sequence for device programming using the I2C follows the standard
Lattice device programming algorithm. The I2C bus hardware requirements,
the timing requirements, and the receive/transmit protocols must follow the
standard I2C specification. The definition of the SDA data time is the delay
form the SCL falling edge 30% VDD to SDA falling edge 70% VDD. The SDA
data setup time is the time requirement from the SDA falling edge 30% VDD
to the SCL rising edge 30% VDD.
All the I2C slave commands consist of one byte op-code followed by three
one-byte operand, except the ISC DISABLE command. The ISC DISABLE
command for I2C programming consists of one byte op-code followed by two
operands. I2C programming can also be done in the background. In this case,
the ISC ENABLE command (0XC6) should be replaced by the
LSC_ENABLE_X command (0X74).
The programming algorithm of the device is separated into I2C algorithm file
and I2C data file. This separation of the algorithm and data allows the
optimization of the I2C embedded programming engine. It also allows you to
mix I2C data files with I2C algorithm files.
The only source code file that must be modified is the hardware.c file. The
source files can be found in
<install_path>\embedded_source\i2cembedded\src\i2cem diamond directory.
hardware.c
The only file that you should modify is hardware.c. This file contains the
functions to read and write to the port and the timing delay function. You must
update these functions to target the desired hardware.
opcode.h
The opcode.h file contains the definitions of the byte codes used in the I2C
algorithm format and programming engine.
i2c_core.c
The i2c_core.c file provides the programming engine for the I2C embedded
system. The engine operates on the commands in the I2C algorithm, and
obtains data from the I2C data, if necessary. The engine is responsible for
functions such as sending data, verifying data, observing timing delay,
decompression, and so on.
i2c_main.c
The i2c_main.c file is the only file that differs between the PC-based and the
8051-based embedded solutions. This difference is due to the way each of
these interfaces to the I2C algorithm and data files through the entry point.
This file contains the main and entry point functions.
The HEX files must be compiled along with the 8051-based I2C System
source code. The source code contains handles that allow the compiler to link
the buffers of the hexadecimal files to the main source code. The only source
code file that you need to modify is the hardware.c file. The source files can
be found in the
<install_path>\embedded_source\i2cembedded\src\i2cem_eprom directory.
hardware.c
The only file that you should modify is hardware.c. This file contains the
functions to read and write to the port and the timing delay function. You must
update these functions to target the desired hardware.
opcode.h
The opcode.h file contains the definitions of the byte codes used in the I2C
algorithm format and programming engine.
i2c_core_eprom.c
The i2c_core.c file provides the programming engine for the I2C embedded
system. The engine operates on the commands in the I2C algorithm, and
fetches data from the I2C data, if necessary. The engine is responsible for
functions such as sending data, verifying data, observing timing delay,
decompression, and so on.
i2c_eprom.c
The i2c_main.c contains the main and entry point functions for 8051-based
I2C Programming.
I2C_STARTTRAN 0x10
I2C_RESTARTTRAN 0x11
I2C_ENDTRAN 0x12
I2C_TRANSOUT 0x13
I2C_TRANSIN 0x14
I2C_RUNCLOCK 0x15
I2C_WAIT 0x16
I2C_LOOP 0x17
I2C_ENDLOOP 0x18
I2C_TDI 0x19
I2C_CONTINUE 0x1A
I2C_TDO 0x1B
I2C_MASK 0x1C
I2C_BEGIN_REPEAT 0x1D
I2C_END_REPEAT 0x1E
I2C_END_FRAME 0x1F
I2C_DATA 0x20
I2C_PROGRAM 0x21
I2C_VERIFY 0x22
I2C_DTDI 0x23
I2C_DTDO 0x24
I2C_COMMENT 0x25
I2C_ENDVME 0x7F
The first byte in the file indicates whether the data file has been compressed.
A byte of 0x00 indicates that no compression was selected, and 0x01
indicates that compression was selected. When compression has been
selected, each frame is preceded by a frame compression byte to indicate
whether the frame is compressible. This is necessary because even though
you might elect to compress the I2C data file, it is possible that a compressed
frame will actually be larger than an uncompressed frame. When that
happens, the frame is not compressed at all and the frame compression byte
of 0x00 notifies the processor that no compression was performed on the
frame.
When compression has not been selected, the I2C data file becomes a direct
translation from the data sections of the SVF file. The END_FRAME byte,
0x1F, is appended to the end of every frame as a means for the processor to
verify that the frame has indeed reached the end.
Uncompressed I2C Data Format Compressed I2C Data Format
0x00 0x01
<Frame 1>0x10 <Compress Byte><Frame 1>0x10
<Frame 2>0x10 <Compress Byte><Frame 2>0x10
… …
<Frame N>0x10 <Compress Byte><Frame N>0x10
When the processor encounters the first byte 0xFF, it gets the next byte to
determine how many times 0xFF is compressed. The next byte is 0x0A,
which is ten in hexadecimal. This instructs the processor that 0xFF is
compressed ten times. The following byte is 0x12, which is processed as it is.
The next byte is again 0xFF followed by 0x03, which instructs the processor
that 0xFF is compressed three times.
Timer(SetI2Cdelay())
The engine requires the ability to delay for fixed time periods. The minimum
granularity of the delay is 1 microsecond. You can determine the type of delay.
This can be a simple software timing loop, a hardware timer, or an operating
system call, for example, sleep().
Port Initialization
The firmware needs to place the port I/O into a known state.
SetI2CStartCondition()
This function is used to issue a start sequence on the I2C Bus.
SetI2CreStartCondition()
This function is used to issue a start sequence on the I2C Bus.
SetI2CStopCondition()
This function is used to issue a stop sequence on the I2C Bus.
ReadBytesAndSendNACK()
This function is used to read the SDA pin from the port.
SendBytesAndCheckACK()
To apply the specified value to the SDA pin indicated.
To generate an .xcf file for the MachXO2 or MachXO3L, if the .xcf file
does not exist or has not yet been created:
1. Start the Diamond Programmer software and create a new Blank Project.
2. Select MachXO2 or MachXO3L as Device Family.
3. Select the Device Type according to your device.
4. Choose Edit > Device Properties, or right click on the device, and in the
dropdown menu, choose Device Properties.
5. In the Device Properties dialog box:
In the I2C Slave Address box, enter the correct I2C slave address. The
default address is 0x40.
6. Chose File > Save or File > Save (filename).xcf As... and give the file a
name. Ensure that the extension of the file is xcf.
12. The Deployment Tool project can now be saved by selecting File > Save
As. The saved file will generate the same data file and algorithm file when
loaded again.
13. Modify the Source Code File (hardware.c). The 8051-based source code
files are written in ANSI C. The file hardware.c is the only file that is
required to be modified by the user. The user must modify the following
functions according to the target platform:
SetI2Cdelay()
SetI2CStartCondition()
SetI2CreStartCondition()
SetI2CStopCondition()
ReadBytesAndSendNACK( int length, unsigned char *a_ByteRead
, int NAck)
Where
int length = Number of bits to read
*a_ByteRead = Buffer to store byte
int NAck - Option to send
0 = No
1 - Yes
int SendBytesAndCheckACK(int length, unsigned char
*a_bByteSend
Where
int length = Number of bits to send
*a_bByteSend = Buffer storing data to send
The following are optional functions that the user may wish to modify in
order to enable and disable the hardware conditions before and after
processing:
EnableHardware()
DisableHardware()
14. Compile Source Code and I2C HEX Files. Combine the source code and
I2C HEX files generated by Deployment Tool into a project to be compiled.
This may be done using a microcontroller development tool to create the
project.
The for loop usually is compiled into the ASSEMBLY code as shown below:
LOOP: EDC RA;
JNZ LOOP;
If each line of assembly code needs four (4) machine cycles to execute, the
total number of machine cycles to execute the loop is 2 x 4 = 8.
Note
Some CPUs have a clock multiplier to double the system clock for the machine clock.
Let the machine clock frequency of the CPU be F (in MHz), then one machine
cycle = 1/F.
It is obvious that the formula can be transposed into one microsecond = F/8.
Example: The CPU internal clock is set to 48 MHz, then one microsecond =
48/8 = 6.
The C code shown below can be used to create the millisecond accuracy. All
that needs to be changed is the CPU speed.
version assigns a file pointer to the binary I2C Embedded file directly. The
pointer is assigned based on a command line argument. With some minor
modification, this version is useful for embedded high-level 32-bit
microprocessors that can dynamically allocate RAM and have large amounts
of data and code memory. For more modest embedded systems or smaller
processors, the PROM-based version is useful because the memory
resources are completely defined when compiling the executable.The I2C
Embedded file is converted to one or more C files and a header file that are
compiled with the core routines.
sysCONFIG Embedded
The sysCONFIG Embedded software brings sysCONFIG port programming
capability to Lattice Semiconductor's suite of FPGA devices on embedded
systems. The software offers a unique virtual programming engine that can
support the different programming algorithms of each device family. The
software is developed in ANSI C and is available in source code form to allow
users to target specific hardware.
The Diamond software may be used to generate a bitstream file. The file then
must be converted to an embedded bitstream using Deployment Tool. The
significance of the embedded bitstream is that it contains control pin
instructions, which the sysCONFIG Embedded programming engine will
decode. Once the embedded bitstream is obtained, it will be provided to the
sysCONFIG Embedded software to configure the device.
Parallel Mode and Serial Mode CPU Bitstream For LatticeECP/EC and
LatticeECP2 devices, the Deployment Tool software can generate either a
parallel configuration mode (PCM) CPU or a serial configuration mode (SCM)
CPU file depending on the operation type you have specified for the device in
the Device Properties Dialog Box in Diamond Programmer. For example, if
you have selected JTAG 1532 Mode under Device Access Options and Fast
Program under Operation, the CPU bitstream generator will output a parallel
mode CPU file. If you selected Serial Mode and Serial Program in the
Device Information dialog box, a serial mode CPU file will be generated.
Output Format This option, the most important, allows you to specify one of
three sysCONFIG Embedded bitstream formats for generating the embedded
bitstream: binary, C-code, and Intel hexadecimal. You can also generate a
CPU file in text format so that you can see all the commands, data, and the
size of data shifting for debugging purpose.
For Erase, Program, and Verify Operations, Skip the Verify Operation
You can skip the Verify operation while programming a device to reduce
processing time.
Specify Values for the CFG Pins The software allows you to specify the
values of the CFG pins by using configuration mode. By default, selection of
these values is disabled.
Besides the above formats, you can also generate a CPU file in text format so
that you can see all the commands, data, and the size of data shifting for
debugging purpose.
The algorithm section drives and verifies the control pins. A verification failure
return code is issued if a pin fails to verify.
The original bitstream section contains the bitstream broken down by frames.
If the comment option was selected when generating the embedded
bitstream, comments are inserted before frames and displayed by the CPU
engine to notify users the current frame being processed.
This CRC is referred to as the “soft” CRC, not to be confused with the CRC
calculation that is performed internally by the FPGA device. See the figure
below.
There are five components to the sysCONFIG Embedded source code: main,
engine, hardware, simulator, and definition.
Main There are three different main files depending on whether you want to
use the file-based, compile-based, or function-based interface. Each interface
is available in main_f.c, main_e.c, and main_tag.c, respectively. When using
the compile-based interface, the embedded bitstream must be generated as
C-code and compiled with the rest of the source code.
There are two important options to consider when generating the embedded
bitstream. The first option is whether or not to generate the file with built-in
comments. These comments are decoded by the sysCONFIG Embedded
engine and displayed to the terminal to inform the engine's actions. This is
helpful for debugging purposes, but the file size will increase slightly.
The second, and more important, option to consider is which of the three
formats should the embedded bitstream be generated with. See sysCONFIG
Embedded Bitstream Format for details.
Waveform
Waveform
Waveform
sysCONFIG Interface
This page provides interface diagrams and description on the following CPU
sysCONFIG solutions.
CPU programming solution
The SRAM fuses in LatticeXP and LatticeECP/EC and the FLASH fuses
in LatticeXP can be programmed by using the sysCONFIG port connected
to a CPU. This page will describe SRAM fuse programming and present a
66MHz programming solution for LatticeECP/EC devices.
If both the DONE pin and the INIT pin are high after programming, or
refresh, the device then must be programmed successfully.
Note
Only if the FLASH DONE fuse is programmed can the FLASH pattern be
downloaded into the SRAM fuses of the device. If the FLASH DONE fuse is not
programmed, the download is blocked. FLASH DONE fuse is the last fuse to be
downloaded from FLASH to SRAM. The FLASH is downloaded to SRAM in a
protected and shielded environment and therefore it is not subject to the effect of
external noise or ground bounce which is the common problem when downloading
from external FLASH memory devices. The DONE pin is a very reliable indicator
on the programming status. This renders the readback un-necessary.
Note
Only the JTAG port of the device supports readback in both user mode and
programming mode. If the device has not yet been programmed successfully, it
will not respond to the READ_INC command sent to it on the sysCONFIG port.
Opcode Operand
WRITE CTRL 0 hC4 Don't Care X Program the 32 bits program flow control
register 0.
READ CTRL 0 h84 Don't Care X X Read out from the 32 bits control register 0.
READ_IDCODE h87 Don't Care X X Read out the 32 bits JTAG IDCODE of the
device.
VERIFY_IDCODE hC7 Don't Care X X Compare the 32 bits data against the 32 bits
JTAG IDCODE.
BYPASS hFC Don't Care X X Send data to Dout for the next device in
chain.
FLOW_THROUGH hFD Don't Care X X Drive CSO low to select the next device in
chain.
NOOP hFF None X X Put a device in a wait state for extra delay.
Bit 31 of the opcode determines if the command and data is included in CRC.
The opcode shown does not select CRC inclusion. The bitstream generated
by the Diamond software makes that decision automatically. The read
command is not recommended to include CRC.
Only four pins, PROGRAMN, INITN, DONE, and CCLK, are dedicated. The
other pins are dual purpose pins. The DI pin has no function on parallel
programming.
Only four pins, PROGRAMN, INITN, DONE, and CCLK, are dedicated. The
other pins are dual purpose pins. Only the DI pin and DOUT/CSO pin are
used on serial programming.
Only four pins, PROGRAMN, INITN, DONE, and CCLK, are dedicated. The
other pins are dual purpose pins. The read back is turned on by selecting the
Persistent On option when generating the bitstream.
The DI pin has no function on read back. Same as other dual purpose pins, it
cannot be recovered as user IO if read back is selected.
The PROGRAMN pin must be left alone during read back. Pulsing it will
terminate the read back immediately and start re-configuration.
The device responds to read back command only if it has already been
configured successfully.
Note
1. The device captures data on the rising edge of CCLK.
2. The maximum rate sending data to the device is 66MHz.
3. The bitstream file could be for one device or merged for two or more devices.
Board Layout
Waveform
CPU Byte-Wide Read back Flow Below is the CPU byte-wide read back
flow. Before performing CPU byte-wide read back, the persistent fuse must be
programmed already to enable reading.
1. Check if both DONE and INITN pins are high. If they are high then
continue. If not then report failure.
2. Drive WRITEN, CSN, and CS1N to low to enable the D[0..7] interface to
receive command.
3. Write several bytes of 0xFF to D[0..7] and clock them into the device to
clear the bus.
4. Write the pre-amble code 0xBD, 0xB3 and clock them into the device to
enable the command decoder.
5. Write the READ_IDCODE command 0x87 to D[0..7] and clock them into
the device then follow with 3 bytes of 0x00 as operand. Reading IDCODE
is necessary to ensure communication is established with the device.
6. Drive CSN from low to high (or CS1N, not both) then drive WRITEN from
low to high. Pulse one clock on CCLK to change D[0..7] from input port to
output port.
7. Drive CSN back from high to low (or CS1N if it was driven high at step 6).
Pulse one clock on CCLK to present one byte of data on D[0..7].
8. The BUSY pin tracks the CSN (or CS1N) pin. The data on D[0..7] is not
valid when it is high.
9. Read the first byte of the IDCODE from the D[0..7] of the first byte bit[0..7]
of the JTAG IDCODE.
10. Pulse CCLK then read the next byte bit[8..15] of the JTAG IDCODE.
11. Repeat step 10 till bit[16..23] then bit[24..31] is read from D[0..7].
12. Compare the 32 bits IDCODE read from the device against the expected
IDCODE of the device. If they match, then continue. If not, then report
error.
13. Repeat Step 5 to 11 to read the USERCODE. The READ_USERCODE
opcode is 0x83. It is a good practice to put the fuse checksum on
usercode to indicate that the device has been programmed correctly to
the pattern when reading back.
14. Drive CSN from low to high then drive WRITEN from high to low. Pulse
one clock on CCLK to change D[0..7] back to an input port.
15. Drive the first byte of the RESET_ADDRESS command, 0xE2, to D[0..7].
Pulse one clock on CCLK for the device to read it in.
16. Drive D[0..7] and clock CCLK to send 3 bytes of 0x00 as dummy
operands to the device. The address of the device is now set to the first
frame.
17. Drive the first byte of the READ_INC command, 0x81, to D[0..7]. Pulse
one clock on CCLK for the device to read it in.
18. Drive to D[0..7] and clock CCLK the number of frames to be read from the
device expressed in 24 bits hex number, or 3 bytes.
Example: If read 3 frames, then 3 bytes of operand is 0x00, 0x00, 0x03. If
read 256 frames, then 3 bytes of operand is 0x00, 0x01, 0x00.
Note
The number must not be larger than the maximum number of frames in the
device.
19. Drive CSN from low to high then drive WRITEN from low to high, then
pulse CCLK to set D[0..7] up as an output port.
20. Drive CSN from high to low then pulse CCLK for the device to drive the
first byte from the first frame to D[0..7].
21. Pulse CCLK then read the next byte till all the bytes in the first frame are
read. The device will increment the address automatically when all bytes
in the current frame are read.
22. Continue to pulse CCLK till all the frames or up to what is specific on the
operand sent to the device at step 18.
Note
Do not read beyond that number, otherwise the device will drive INIT low to
indicate over-read.
23. Drive CSN from low to high then drive WRITEN from high to low. Pulse
one clock on CCLK to change D[0..7] back to an input port.
24. Drive the opcode, 0xFA, of the END_READ command to D[0..7]. Pulse
CCLK for the device to read it in.
25. Drive 0x00 to D[0..7] then pulse CCLK 3 times as the dummy operand to
complete the command. Read back is then terminated.
26. Drive CSN, CS1N, and WRITEN back to high to disconnect the
sysCONFIG port of the device.
Note
1. If the command is under shift, then the device will enter error state.
2. If the command is over shift, then the device will also enter error state.
3. If the data is under shift, there is no error state.
4. If the data is over shift, dummy data is presented to D[0..7]. The device will not
enter error state.
5. Driving both CSN and CS1N to high will reset the device.
6. The read back clock frequency is much slower than 66MHZ due to the time
required to switch the polarity of D[0..7] from input to output.
7. The data is shift out from the device on the rising edge of CCLK.
8. If the security fuse is programmed, the usercode and JTAG IDCODE still can be
readback.
9. The opcode sent to the device for reading purpose are not recommended to
include CRC. Hence bit7 of the opcode is 1.
10. The number of frames put on the operand must be less than or equal to the
number of frames the device actually has.
11. If the number exceeds the actual number of frames, the device will enter error
state.
3. Pulse several clocks on CCLK to make sure the devices are ready.
4. Wait 20ms then check INITN pin. If it is high, then continue.
5. Drive bit7 of the first byte from the bitstream to DI then pulse the clock to
clock it in.
6. Repeat step 5 till bit6..0 of the first byte is sent.
7. Repeat step 6 till the whole bitstream file is sent to the device.
Programming is then complete.
8. Check if INIT pin is high. If it is high then continue. If it is low, then report
failure.
9. Pulse 100 clocks on CCLK to ensure the devices are waking up.
10. Check if the DONE pin is high. If it is high, then programming is
successful. If it is low, then report failure.
Note
1. The device captures data on the rising edge of CCLK.
2. The maximum rate sending data to the device is 66MHz.
3. The bitstream file could be for one device or merged for two or more devices.
Board Layout
Waveform
B
bitstream
generating CPU embedded bitstream 129
C
CPU Embedded
bitstream format 122
engine 126
flow 121
source code 125
CPU generating 129
D
Deployment Tool 1, 13
device programming
see programming devices
Diamond Programmer 1, 5
Download Debugger 2
E
Embedded System
RAM size requirement for ispVME 37
ROM size requirement for ispVME 39
Embedded, I2C 19
Embedded, JTAG, Full VME 19, 30
Embedded, JTAG, Slim VME 19, 73
Embedded, Slave SPI 19, 100
Embedded, sysCONFIG 19, 120
F
file generation
CPU embedded bitstream 129
file processing
VME 52
file size
program size 42
FPGA
generating a CPU embedded bitstream 129
Full VME Embedded, JTAG 19, 30
G
generating
CPU embedded bitstream 129
slim VME 84
I
I2C Embedded 19
ispVM Embedded
RAM size requirement for ispVME 37
ROM size requirement for ispVME 39
ispVME
engine 36
flow 33
source code 35
ispVME system memory 34
J
JTAG Full VME Embedded 19, 30
JTAG Slim VME Embedded 19, 73
P
processing
VME 52
program memory allocation 41
program memory requirement 41
Programmer
using 8
Programmer, Diamond 1, 5
programming devices
using Programmer 8
programming engine
CPU Embedded 126
ispVME 36
Programming File Utility 2
R
RAM size requirement for ispVME 37
resource requirements
program memory 41
program memory allocation 41
sample program size 42
ROM size requirement for ispVME 39
S
Slave SPI Embedded 19, 100
slim ispVME
generating slim VME 84
slim ispVME source code 74
using the 8051-based slim ispVME 76
using the PC-based slim ispVME 75
VME algorithm format 76
slim ispVMEVME data format 79
Slim VME Embedded, JTAG 19, 73
source code
CPU Embedded 125
ispVME 35
Slim ispVME 74
SPI, Slave, Embedded 19, 100
sysCONFIG Embedded 19, 120
system memory, ispVME 34
U
user changes, ispVME 39
using
8051-based slim ispVME 76
PC-based slim ispVME 75
slim ispVM Embedded System 75
V
VME
algorithm format - slim ispVME 76
data format - slim ispVME 79
format 30
processing 52
RAM size requirement 37
ROM size requirement 39