LPF (Lattice Preference File) files are how you express routing constraints and I/O pin configuration for Lattice ECP5 FPGAs. Annoyingly, it seems Lattice doesn't document the format, and instead forces you to use their proprietary design software to generate LPF files.
Separately, projects like the ULX3s board provide a pre-baked LPF file that documents most of the "hardcoded" routing of board features to FPGA pins, but requires tweaking for some applications (e.g. to add pull-ups, pull-downs, change the drive current...).
I tried getting a license for Lattice Diamond on their website, but they won't let me get a free license to use their software without "account approval", which takes "up to 2 business days". It's Saturday, so instead of waiting for that I'm going to write down a google-able specification of LPF files, as parsed by nextpnr, so that people don't have to go through that themselves.
LPF files are plain text files, with one directive per line. Directives are terminated by a semicolon.
Line comments are supported, from the #
character to the end of the
line.
Each line consists of words. The first word or two define the type of line, and the rest of the line consists of required positional arguments and optional keyword arguments.
A small excerpt of a valid LPF file:
SYSCONFIG CONFIG_IOVOLTAGE=3.3 COMPRESS_CONFIG=ON MCCLK_FREQ=62 MASTER_SPI_PORT=ENABLE SLAVE_SPI_PORT=DISABLE SLAVE_PARALLEL_PORT=DISABLE;
# The FTDI chip provides a serial line to USB port US1.
LOCATE COMP "ftdi_rxd" SITE "L4"; # FPGA transmits to ftdi
IOBUF PORT "ftdi_rxd" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
Several directives accept signal names to reference wires in your design. The signal names correspond to the ports in your design's top-level module. Signal names are case sensitive, so must exactly match the definitions in your HDL.
If your top-level ports contain arrays, your LPF file must manage each
array bit individually. Array bits are referenced using the syntax
array_name[idx]
.
When handling signals, remember that by the time the LPF file is being read, synthesis has already been done. So, if you declared a single-ended output signal, it makes no sense to tie it to a pin configured as a differential input. Your synthesis tool will still happily produce a bitstream describing this, but your design is not going to work correctly.
As an example, if your top-level Verilog module is:
module top(input clk, input [2:0] test_btn, output [1:0] statusLeds);
...
endmodule
Then your LPF file needs to define configuration for signals named
clk
, test_btn[0]
, test_btn[1]
, test_btn[2]
, statusLeds[0]
,
and statusLeds[1]
.
The SYSCONFIG directive sets global FPGA options relating to bitstream generation and loading. When the FPGA first powers on, it has no bitstream loaded, and must get it from external storage. SYSCONFIG specifies basic hardware settings to facilitate that loading.
The ECP5 can read its configuration bitstream from several sources,
dictated by hardcoded signal levels on the CFGMDN
pins of the
sysCONFIG
I/O block. See application node TN1260 from Lattice for
details. Briefly, the CFGMDN
pins put the ECP5 into one of 4 modes:
- SPI master: the ECP5 reads configuration out of a flash chip
attached to the SPI pins of the
sysCONFIG
block. It starts out reading at 2.4MHz, but once it's read enough of the bitstream to find theMCCLK_FREQ
option (see below), it can increase its clock speed for the majority of the read-out. - SPI slave: the ECP5 listens on the SPI pins of the
sysCONFIG
block and waits for an external SPI master to send it a bitstream. - Serial slave: same, but through a serial interface.
- Parallel slave: same, but through a parallel interface.
Depending on the configuration settings below, the ports may remain active after the bitstream has loaded (which allows things like having a CPU access and reconfigure a running device), or the pins can revert to I/O pins usable by your gateware.
Keeping the ports enabled after initial configuration is mostly useful if you want to access them through JTAG later (e.g. to flash a new config to non-volatile storage through the FPGA's JTAG port)
Programming and debugging is always available through the JTAG port,
regardless of the sysCONFIG
mode.
SYSCONFIG takes only optional keyword arguments, which are:
CONFIG_IOVOLTAGE
: sets the pin voltage used on pins in thesysCONFIG
group. One of1.2
,1.5
,1.8
,2.5
(the default),3.3
.COMPRESS_CONFIG
: whether the bitstream generator should use compression. One ofOFF
(the default) orON
(recommended by Lattice).MCCLK_FREQ
: in SPI master mode, the frequency in MHz at which to read configuration from the SPI interface. One of2.4
(the default),4.8
,9.7
,19.4
,38.8
,62
.MASTER_SPI_PORT
: whether the built-in SPI master remains active and blocking the SPI pins after initial loading has completed. One ofENABLE
orDISABLE
(the default). Cannot be set toENABLE
at the same time asSLAVE_SPI_PORT
.SLAVE_SPI_PORT
: whether the built-in SPI slave remains active and blocking the SPI pins after initial loading has completed. One ofENABLE
orDISABLE
(the default). Cannot be set toENABLE
at the same time asMASTER_SPI_PORT
.SLAVE_PARALLEL_PORT
: whether the built-in slave parallel port remains active and blocking the parallel port pins after initial loading has completed. One ofENABLE
orDISABLE
(the default).BACKGROUND_RECONFIG
: whether to enable soft error correction, a mechanism that lets you hot-reload the bitstream to correct cosmic ray bit flips. Requires further work on your part to actually use, see TN1184 for details.DONE_PULL
: whether theDONE
pin should be configured with an internal pull-up resistor. One ofON
(the default) orOFF
.DONE_EX
: whether to delay the end of configuration based on the input value ofDONE
. Used when daisy-chaining FPGAs, combined with theDONE_OD
andDONE_PULL
options so that all FPGAs have to releaseDONE
before any of them can start running. See TN1260 appendix D for more. One ofON
orOFF
(the default).DONE_OD
: whether to configure theDONE
pin as an open drain, rather than a fully driven output. One ofON
orOFF
(the default).CONFIG_SECURE
: whether to allow external read-back of the configuration through JTAG and other programming ports. If enabled, the FPGA must be wiped before it can be reprogrammed. One ofON
orOFF
(the default).CONFIG_MODE
: which bus and mode is being used to load configuration. This option doesn't alter the bitstream at all, it's only here so that the Lattice IDE can block off the right sets of pins from user use based on the selected config mode. One ofJTAG
(the default),SSPI
,SPI_SERIAL
,SPI_DUAL
,SPI_QUAD
,SLAVE_PARALLEL
,SLAVE_SERIAL
.TRANSFR
: whether the bitstream is intended for loading using Lattice's "TransFR" tools, which allow for field reconfiguration with minimal disruption. Exact effect unknown. One ofON
orOFF
(the default).WAKE_UP
: controls the ordering of settingDONE=1
relative to other actions during the transition from configuration mode (aka FPGA being programmed) to user mode (aka running FPGA). One of4
(setDONE=1
before starting user code) or21
(setDONE=1
once the FPGA has already started running user code). The default is4
whenDONE_EX=ON
and21
whenDONE_EX=OFF
.INBUF
: whether to disable unused input buffers to save power. One ofON
orOFF
. [Ed. may not exist in ECP5, only referenced in ECP2 sysCONFIG. But nextpnr parses it, so I'm including it here for completeness.]
Example SYSCONFIG line:
SYSCONFIG CONFIG_IOVOLTAGE=3.3 COMPRESS_CONFIG=ON MCCLK_FREQ=62;
The LOCATE COMP
directive assigns top-level signal in your design to
a physical pin of the FPGA. It is commonly paired with an IOBUF PORT
directive to fully specify the behavior of the pin.
The syntax is:
LOCATE COMP "signal_name" SITE "pin_name";
signal_name
is the name of a top-level signal in your HDL. See the
"Signal names" section above for detailed syntax and behavior.
The pin_name
is the name of the pin from the datasheet, e.g. H3
or
R18
.
Example LOCATE COMP
line, attaching the LSB of the btn
array to
pin D6:
LOCATE COMP "btn[0]" SITE "D6";
The FREQUENCY PORT
directive adds a timing constraint to a top-level
signal in your design. Typically, you would use this to tell the
place-and-route tool about incoming clock signals, so that timing
analysis can verify that the design is stable at that frequency.
[Ed. TODO: can you define frequency constraints for internal signals as well? For example, if you use a PLL module to generate a 300MHz internal clock, can you tag that wire with a frequency constraint?]
The syntax is:
FREQUENCY PORT "signal_name" number unit;
signal_name
is the name of a top-level signal in your HDL. See the
"Signal names" section above for detailed syntax and behavior.
Valid unit
s are MHZ
, KHZ
and HZ
.
Example:
FREQUENCY PORT "clk" 25 MHZ;
The IOBUF PORT
directive configures the physical I/O pin properties
of a top-level signal in your design. It is commonly paired with a
LOCATE COMP
line to attach an HDL wire to the pin.
The syntax is:
IOBUF PORT "signal_name" KEY=VALUE...;
signal_name
is the name of a top-level signal in your HDL. See the
"Signal names" section above for detailed syntax and behavior.
The following key/value pairs exist:
IO_TYPE
: specifies the electrical I/O standard the pin will obey. Valid values are constrained by the I/O reference voltage provided to the relevant I/O bank, as detailed in TN1262. All valid values are:- Basic single pin standards:
LVTTL33
,LVCMOS33
,LVCMOS25
,LVCMOS18
,LVCMOS15
,LVCMOS12
. - Advanced single pin standards (mostly for driving different
DRAM chips):
HSUL12
,SSTL15_I
,SSTL15_II
,SSTL135_I
,SSTL135_II
,SSTL18_I
,SSTL18_II
. - Differential standards (must be paired with another signal,
consult TN1262 for valid pin pairings):
LVDS
,LVDS25E
,BLVDS25
,LVPECL33
,LVPECL33E
,MLVDS
,MLVDS25E
,SLVS
,SUBLVDS
,HSUL12D
,SSTL15D_I
,SSTL15D_II
,SSTL135D_I
,SSTL135D_II
,SSTL18D_I
,SSTL18D_II
,LVTTL33D
,LVCMOS33D
,LVCMOS25D
,LVCMOS18D
.
- Basic single pin standards:
OPENDRAIN
: whether this pin should be configured as an open drain. One ofON
orOFF
(the default).DRIVE
: the amount of current (in mA) to drive when outputting. Valid values depend on the I/O type, see table 8 of TN1262. For example, valid values for LVTTL33 are4
,8
,12
, and16
.DIFFDRIVE
: the amount of drive current for pins using LVDS mode. The only allowed value is 3.5mA, its encoding is unknown.TERMINATION
: the input parallel termination to configure, if any. One ofOFF
(the default),50
,75
, or100
ohms.DIFFRESISTOR
: the differential termination to configure, if any. One ofOFF
(the default) or100
(ohms).CLAMP
: for top and bottom banks, whether to enable input clamping to VCCIO. One ofOFF
(the default) orON
. Input clamping is hardwired on for left and right banks.BANK
: [Ed. unknown, not documented in Lattice TN or seen in the wild]BANK_VCC
: [Ed. unknown, not documented in Lattice TN or seen in the wild]VREF
: must be set toVREF1_LOAD
forHSUL
andSSTL
pin types.OFF
and ignored for other types.PULLMODE
: whether to attach a pull-up or pull-down resistor to the pin. One ofNONE
,UP
, orDOWN
(the default).HYSTERESIS
: whether to enable input hysteresis. Only applicable toLVTTL33
,LVCMOS33
andLVCMOS25
pins. One ofON
(the default for those types) orOFF
.SLEWRATE
: the desired slew rate for output on the pin. Only applicable toLVTTL
andLVCMOS
pin types. One ofFAST
orSLOW
.