@@ -207,11 +207,11 @@ def elaborate(self, platform):
207207
208208class LatticePlatform (TemplatedPlatform ):
209209 """
210- .. rubric:: Trellis toolchain (ECP5 only )
210+ .. rubric:: Trellis toolchain (ECP5, MachXO2, MachXO3 )
211211
212212 Required tools:
213213 * ``yosys``
214- * ``nextpnr-ecp5``
214+ * ``nextpnr-ecp5`` or ``nextpnr-machxo2``
215215 * ``ecppack``
216216
217217 The environment is populated by running the script specified in the environment variable
@@ -220,11 +220,11 @@ class LatticePlatform(TemplatedPlatform):
220220 Available overrides:
221221 * ``verbose``: enables logging of informational messages to standard error.
222222 * ``read_verilog_opts``: adds options for ``read_verilog`` Yosys command.
223- * ``synth_opts``: adds options for ``synth_ecp5 `` Yosys command.
223+ * ``synth_opts``: adds options for ``synth_<family> `` Yosys command.
224224 * ``script_after_read``: inserts commands after ``read_ilang`` in Yosys script.
225- * ``script_after_synth``: inserts commands after ``synth_ecp5 `` in Yosys script.
225+ * ``script_after_synth``: inserts commands after ``synth_<family> `` in Yosys script.
226226 * ``yosys_opts``: adds extra options for ``yosys``.
227- * ``nextpnr_opts``: adds extra options for ``nextpnr-ecp5 ``.
227+ * ``nextpnr_opts``: adds extra options for ``nextpnr-<family> ``.
228228 * ``ecppack_opts``: adds extra options for ``ecppack``.
229229 * ``add_preferences``: inserts commands at the end of the LPF file.
230230
@@ -294,11 +294,16 @@ class LatticePlatform(TemplatedPlatform):
294294 "BG756" : "caBGA756" ,
295295 }
296296
297- _trellis_required_tools = [
297+ _trellis_required_tools_ecp5 = [
298298 "yosys" ,
299299 "nextpnr-ecp5" ,
300300 "ecppack"
301301 ]
302+ _trellis_required_tools_machxo2 = [
303+ "yosys" ,
304+ "nextpnr-machxo2" ,
305+ "ecppack"
306+ ]
302307 _trellis_file_templates = {
303308 ** TemplatedPlatform .build_script_templates ,
304309 "{{name}}.il" : r"""
@@ -322,7 +327,11 @@ class LatticePlatform(TemplatedPlatform):
322327 {% endfor %}
323328 read_ilang {{name}}.il
324329 {{get_override("script_after_read")|default("# (script_after_read placeholder)")}}
325- synth_ecp5 {{get_override("synth_opts")|options}} -top {{name}}
330+ {% if platform.family == "ecp5" %}
331+ synth_ecp5 {{get_override("synth_opts")|options}} -top {{name}}
332+ {% else %}
333+ synth_lattice -family xo2 {{get_override("synth_opts")|options}} -top {{name}}
334+ {% endif %}
326335 {{get_override("script_after_synth")|default("# (script_after_synth placeholder)")}}
327336 write_json {{name}}.json
328337 """ ,
@@ -356,13 +365,17 @@ class LatticePlatform(TemplatedPlatform):
356365 {{name}}.ys
357366 """ ,
358367 r"""
359- {{invoke_tool("nextpnr-ecp5" )}}
368+ {{invoke_tool("nextpnr-" + platform.family )}}
360369 {{quiet("--quiet")}}
361370 {{get_override("nextpnr_opts")|options}}
362371 --log {{name}}.tim
363- {{platform._nextpnr_device_options[platform.device]}}
364- --package {{platform._nextpnr_package_options[platform.package]|upper}}
365- --speed {{platform.speed}}
372+ {% if platform.family == "ecp5" %}
373+ {{platform._nextpnr_device_options[platform.device]}}
374+ --package {{platform._nextpnr_package_options[platform.package]|upper}}
375+ --speed {{platform.speed}}
376+ {% else %}
377+ --device {{platform.device}}-{{platform.speed}}{{platform.package}}{{platform.grade}}
378+ {% endif %}
366379 --json {{name}}.json
367380 --lpf {{name}}.lpf
368381 --textcfg {{name}}.config
@@ -422,7 +435,7 @@ class LatticePlatform(TemplatedPlatform):
422435 prj_run Map -impl impl
423436 prj_run PAR -impl impl
424437 prj_run Export -impl impl -task Bitgen
425- {% if family == "machxo2" -%}
438+ {% if platform. family == "machxo2" -%}
426439 prj_run Export -impl impl -task Jedecgen
427440 {% endif %}
428441 {{get_override("script_after_export")|default("# (script_after_export placeholder)")}}
@@ -523,7 +536,10 @@ def __init__(self, *, toolchain=None):
523536 @property
524537 def required_tools (self ):
525538 if self .toolchain == "Trellis" :
526- return self ._trellis_required_tools
539+ if self .family == "ecp5" :
540+ return self ._trellis_required_tools_ecp5
541+ elif self .family == "machxo2" :
542+ return self ._trellis_required_tools_machxo2
527543 if self .toolchain == "Diamond" :
528544 return self ._diamond_required_tools
529545 assert False
0 commit comments