5 from functools
import reduce
6 from operator
import or_
8 from migen
import (Signal
, FSM
, If
, Display
, Finish
, NextValue
, NextState
,
9 Cat
, Record
, ClockSignal
, wrap
)
11 from litex
.build
.generic_platform
import Pins
, Subsignal
12 from litex
.build
.sim
import SimPlatform
13 from litex
.build
.io
import CRG
14 from litex
.build
.sim
.config
import SimConfig
16 from litex
.soc
.integration
.soc
import SoCRegion
17 from litex
.soc
.integration
.soc_core
import SoCCore
18 from litex
.soc
.integration
.soc_sdram
import SoCSDRAM
19 from litex
.soc
.integration
.builder
import Builder
20 from litex
.soc
.integration
.common
import get_mem_data
22 from litedram
import modules
as litedram_modules
23 from litedram
.phy
.model
import SDRAMPHYModel
24 #from litedram.phy.gensdrphy import GENSDRPHY, HalfRateGENSDRPHY
25 from litedram
.common
import PHYPadsCombiner
, PhySettings
26 from litedram
.phy
.dfi
import Interface
as DFIInterface
27 from litex
.soc
.cores
.spi
import SPIMaster
28 from litex
.soc
.cores
.pwm
import PWM
29 from litex
.soc
.cores
.bitbang
import I2CMaster
31 from litex
.tools
.litex_sim
import sdram_module_nphases
, get_sdram_phy_settings
33 from litex
.tools
.litex_sim
import Platform
34 from libresoc
.ls180
import LS180Platform
36 from migen
import Module
37 from litex
.soc
.interconnect
.csr
import AutoCSR
39 from libresoc
import LibreSoC
40 from microwatt
import Microwatt
43 from litex
.soc
.integration
.soc
import SoCCSRHandler
44 SoCCSRHandler
.supported_address_width
.append(12)
46 # GPIO Tristate -------------------------------------------------------
47 # doesn't work properly.
48 #from litex.soc.cores.gpio import GPIOTristate
49 from litex
.soc
.interconnect
.csr
import CSRStorage
, CSRStatus
50 from migen
.genlib
.cdc
import MultiReg
53 from litex
.soc
.interconnect
import wishbone
54 from litesdcard
.phy
import (SDPHY
, SDPHYClocker
,
55 SDPHYInit
, SDPHYCMDW
, SDPHYCMDR
,
56 SDPHYDATAW
, SDPHYDATAR
,
58 from litesdcard
.core
import SDCore
59 from litesdcard
.frontend
.dma
import SDBlock2MemDMA
, SDMem2BlockDMA
60 from litex
.build
.io
import SDROutput
, SDRInput
63 class GPIOTristateASIC(Module
, AutoCSR
):
64 def __init__(self
, pads
):
65 nbits
= len(pads
.oe
) # hack
66 self
._oe
= CSRStorage(nbits
, description
="GPIO Tristate(s) Control.")
67 self
._in
= CSRStatus(nbits
, description
="GPIO Input(s) Status.")
68 self
._out
= CSRStorage(nbits
, description
="GPIO Ouptut(s) Control.")
72 _pads
= Record( (("i", nbits
),
75 self
.comb
+= _pads
.i
.eq(pads
.i
)
76 self
.comb
+= pads
.o
.eq(_pads
.o
)
77 self
.comb
+= pads
.oe
.eq(_pads
.oe
)
79 self
.comb
+= _pads
.oe
.eq(self
._oe
.storage
)
80 self
.comb
+= _pads
.o
.eq(self
._out
.storage
)
81 for i
in range(nbits
):
82 self
.specials
+= MultiReg(_pads
.i
[i
], self
._in
.status
[i
])
84 # SDCard PHY IO -------------------------------------------------------
87 def __init__(self
, pad
, name
, o
, oe
, i
):
89 _o
= getattr(pad
, "%s_o" % name
)
90 _oe
= getattr(pad
, "%s_oe" % name
)
91 _i
= getattr(pad
, "%s_i" % name
)
92 for j
in range(len(_o
)):
93 self
.specials
+= SDROutput(clk
=clk
, i
=o
[j
], o
=_o
[j
])
94 self
.specials
+= SDROutput(clk
=clk
, i
=oe
, o
=_oe
[j
])
95 self
.specials
+= SDRInput(clk
=clk
, i
=_i
[j
], o
=i
[j
])
98 class SDPHYIOGen(Module
):
99 def __init__(self
, clocker
, sdpads
, pads
):
101 if hasattr(pads
, "rst"):
102 self
.comb
+= pads
.rst
.eq(0)
105 self
.specials
+= SDROutput(
107 i
= ~clocker
.clk
& sdpads
.clk
,
113 self
.submodules
.sd_cmd
= SDRPad(pads
, "cmd", c
.o
, c
.oe
, c
.i
)
117 self
.submodules
.sd_data
= SDRPad(pads
, "data", d
.o
, d
.oe
, d
.i
)
120 class SDPHY(Module
, AutoCSR
):
121 def __init__(self
, pads
, device
, sys_clk_freq
,
122 cmd_timeout
=10e-3, data_timeout
=10e-3):
123 self
.card_detect
= CSRStatus() # Assume SDCard is present if no cd pin.
124 self
.comb
+= self
.card_detect
.status
.eq(getattr(pads
, "cd", 0))
126 self
.submodules
.clocker
= clocker
= SDPHYClocker()
127 self
.submodules
.init
= init
= SDPHYInit()
128 self
.submodules
.cmdw
= cmdw
= SDPHYCMDW()
129 self
.submodules
.cmdr
= cmdr
= SDPHYCMDR(sys_clk_freq
,
131 self
.submodules
.dataw
= dataw
= SDPHYDATAW()
132 self
.submodules
.datar
= datar
= SDPHYDATAR(sys_clk_freq
,
137 self
.sdpads
= sdpads
= Record(_sdpads_layout
)
140 sdphy_cls
= SDPHYIOGen
141 self
.submodules
.io
= sdphy_cls(clocker
, sdpads
, pads
)
143 # Connect pads_out of submodules to physical pads --------------
144 pl
= [init
, cmdw
, cmdr
, dataw
, datar
]
146 sdpads
.clk
.eq( reduce(or_
, [m
.pads_out
.clk
for m
in pl
])),
147 sdpads
.cmd
.oe
.eq( reduce(or_
, [m
.pads_out
.cmd
.oe
for m
in pl
])),
148 sdpads
.cmd
.o
.eq( reduce(or_
, [m
.pads_out
.cmd
.o
for m
in pl
])),
149 sdpads
.data
.oe
.eq(reduce(or_
, [m
.pads_out
.data
.oe
for m
in pl
])),
150 sdpads
.data
.o
.eq( reduce(or_
, [m
.pads_out
.data
.o
for m
in pl
])),
153 self
.comb
+= m
.pads_out
.ready
.eq(self
.clocker
.ce
)
155 # Connect physical pads to pads_in of submodules ---------------
157 self
.comb
+= m
.pads_in
.valid
.eq(self
.clocker
.ce
)
158 self
.comb
+= m
.pads_in
.cmd
.i
.eq(sdpads
.cmd
.i
)
159 self
.comb
+= m
.pads_in
.data
.i
.eq(sdpads
.data
.i
)
161 # Speed Throttling -------------------------------------------
162 self
.comb
+= clocker
.stop
.eq(dataw
.stop | datar
.stop
)
165 # Generic SDR PHY ---------------------------------------------------------
167 class GENSDRPHY(Module
):
168 def __init__(self
, pads
, cl
=2, cmd_latency
=1):
169 pads
= PHYPadsCombiner(pads
)
170 addressbits
= len(pads
.a
)
171 bankbits
= len(pads
.ba
)
172 nranks
= 1 if not hasattr(pads
, "cs_n") else len(pads
.cs_n
)
173 databits
= len(pads
.dq_i
)
175 assert databits
%8 == 0
177 # PHY settings ----------------------------------------------------
178 self
.settings
= PhySettings(
179 phytype
= "GENSDRPHY",
182 dfi_databits
= databits
,
190 read_latency
= cl
+ cmd_latency
,
194 # DFI Interface ---------------------------------------------------
195 self
.dfi
= dfi
= DFIInterface(addressbits
, bankbits
, nranks
, databits
)
199 # Iterate on pads groups ------------------------------------------
200 for pads_group
in range(len(pads
.groups
)):
201 pads
.sel_group(pads_group
)
203 # Addresses and Commands --------------------------------------
205 self
.specials
+= [SDROutput(i
=p0
.address
[i
], o
=pads
.a
[i
])
206 for i
in range(len(pads
.a
))]
207 self
.specials
+= [SDROutput(i
=p0
.bank
[i
], o
=pads
.ba
[i
])
208 for i
in range(len(pads
.ba
))]
209 self
.specials
+= SDROutput(i
=p0
.cas_n
, o
=pads
.cas_n
)
210 self
.specials
+= SDROutput(i
=p0
.ras_n
, o
=pads
.ras_n
)
211 self
.specials
+= SDROutput(i
=p0
.we_n
, o
=pads
.we_n
)
212 if hasattr(pads
, "cke"):
213 for i
in range(len(pads
.cke
)):
214 self
.specials
+= SDROutput(i
=p0
.cke
[i
], o
=pads
.cke
[i
])
215 if hasattr(pads
, "cs_n"):
216 for i
in range(len(pads
.cs_n
)):
217 self
.specials
+= SDROutput(i
=p0
.cs_n
[i
], o
=pads
.cs_n
[i
])
219 # DQ/DM Data Path -------------------------------------------------
222 self
.submodules
.dq
= SDRPad(pads
, "dq", d
.wrdata
, d
.wrdata_en
, d
.rddata
)
224 if hasattr(pads
, "dm"):
225 for i
in range(len(pads
.dm
)):
226 self
.comb
+= pads
.dm
[i
].eq(0) # FIXME
228 # DQ/DM Control Path ----------------------------------------------
229 rddata_en
= Signal(cl
+ cmd_latency
)
230 self
.sync
+= rddata_en
.eq(Cat(dfi
.p0
.rddata_en
, rddata_en
))
231 self
.sync
+= dfi
.p0
.rddata_valid
.eq(rddata_en
[-1])
234 # LibreSoC 180nm ASIC -------------------------------------------------------
236 class LibreSoCSim(SoCCore
):
237 def __init__(self
, cpu
="libresoc", debug
=False, with_sdram
=True,
238 sdram_module
= "AS4C16M16",
239 #sdram_data_width = 16,
240 #sdram_module = "MT48LC16M16",
241 sdram_data_width
= 16,
242 irq_reserved_irqs
= {'uart': 0},
245 assert cpu
in ["libresoc", "microwatt"]
246 sys_clk_freq
= int(50e6
)
248 if platform
== 'sim':
249 platform
= Platform()
251 elif platform
== 'ls180':
252 platform
= LS180Platform()
260 # reserve XICS ICP and XICS memory addresses.
261 self
.mem_map
['icp'] = 0xc0010000
262 self
.mem_map
['ics'] = 0xc0011000
263 #self.csr_map["icp"] = 8 # 8 x 0x800 == 0x4000
264 #self.csr_map["ics"] = 10 # 10 x 0x800 == 0x5000
268 #ram_init = get_mem_data({
269 # ram_fname: "0x00000000",
271 ram_init
= get_mem_data(ram_fname
, "little")
273 # remap the main RAM to reset-start-address
275 # without sram nothing works, therefore move it to higher up
276 self
.mem_map
["sram"] = 0x90000000
278 # put UART at 0xc000200 (w00t! this works!)
279 self
.csr_map
["uart"] = 4
281 self
.mem_map
["main_ram"] = 0x90000000
282 self
.mem_map
["sram"] = 0x00000000
284 # SoCCore -------------------------------------------------------------
285 SoCCore
.__init
__(self
, platform
, clk_freq
=sys_clk_freq
,
286 cpu_type
= "microwatt",
287 cpu_cls
= LibreSoC
if cpu
== "libresoc" \
289 #bus_data_width = 64,
290 csr_address_width
= 14, # limit to 0x8000
291 cpu_variant
= variant
,
294 uart_name
= uart_name
,
295 with_sdram
= with_sdram
,
296 sdram_module
= sdram_module
,
297 sdram_data_width
= sdram_data_width
,
298 integrated_rom_size
= 0, # if ram_fname else 0x10000,
299 integrated_sram_size
= 0x200,
300 #integrated_main_ram_init = ram_init,
301 integrated_main_ram_size
= 0x00000000 if with_sdram \
302 else 0x10000000 , # 256MB
304 self
.platform
.name
= "ls180"
306 # SDR SDRAM ----------------------------------------------
307 if False: # not self.integrated_main_ram_size:
308 self
.submodules
.sdrphy
= sdrphy_cls(platform
.request("sdram"))
310 if cpu
== "libresoc":
311 # XICS interrupt devices
312 icp_addr
= self
.mem_map
['icp']
313 icp_wb
= self
.cpu
.xics_icp
314 icp_region
= SoCRegion(origin
=icp_addr
, size
=0x20, cached
=False)
315 self
.bus
.add_slave(name
='icp', slave
=icp_wb
, region
=icp_region
)
317 ics_addr
= self
.mem_map
['ics']
318 ics_wb
= self
.cpu
.xics_ics
319 ics_region
= SoCRegion(origin
=ics_addr
, size
=0x1000, cached
=False)
320 self
.bus
.add_slave(name
='ics', slave
=ics_wb
, region
=ics_region
)
322 # CRG -----------------------------------------------------------------
323 self
.submodules
.crg
= CRG(platform
.request("sys_clk"),
324 platform
.request("sys_rst"))
328 # SDRAM ----------------------------------------------------
330 sdram_clk_freq
= int(100e6
) # FIXME: use 100MHz timings
331 sdram_module_cls
= getattr(litedram_modules
, sdram_module
)
332 sdram_rate
= "1:{}".format(
333 sdram_module_nphases
[sdram_module_cls
.memtype
])
334 sdram_module
= sdram_module_cls(sdram_clk_freq
, sdram_rate
)
335 phy_settings
= get_sdram_phy_settings(
336 memtype
= sdram_module
.memtype
,
337 data_width
= sdram_data_width
,
338 clk_freq
= sdram_clk_freq
)
339 #sdrphy_cls = HalfRateGENSDRPHY
340 sdrphy_cls
= GENSDRPHY
341 self
.submodules
.sdrphy
= sdrphy_cls(platform
.request("sdram"))
342 #self.submodules.sdrphy = sdrphy_cls(sdram_module,
346 self
.add_sdram("sdram",
348 module
= sdram_module
,
349 origin
= self
.mem_map
["main_ram"],
351 l2_cache_size
= 0, # 8192
352 l2_cache_min_data_width
= 128,
353 l2_cache_reverse
= True
355 # FIXME: skip memtest to avoid corrupting memory
356 self
.add_constant("MEMTEST_BUS_SIZE", 128//16)
357 self
.add_constant("MEMTEST_DATA_SIZE", 128//16)
358 self
.add_constant("MEMTEST_ADDR_SIZE", 128//16)
359 self
.add_constant("MEMTEST_BUS_DEBUG", 1)
360 self
.add_constant("MEMTEST_ADDR_DEBUG", 1)
361 self
.add_constant("MEMTEST_DATA_DEBUG", 1)
363 # GPIOs (bi-directional)
364 self
.submodules
.gpio
= GPIOTristateASIC(platform
.request("gpio"))
368 self
.submodules
.spi_master
= SPIMaster(
369 pads
= platform
.request("spi_master"),
371 sys_clk_freq
= sys_clk_freq
,
374 self
.add_csr("spi_master")
376 # EINTs - very simple, wire up top 3 bits to ls180 "eint" pins
377 self
.comb
+= self
.cpu
.interrupt
[12:16].eq(platform
.request("eint"))
380 jtagpads
= platform
.request("jtag")
381 self
.comb
+= self
.cpu
.jtag_tck
.eq(jtagpads
.tck
)
382 self
.comb
+= self
.cpu
.jtag_tms
.eq(jtagpads
.tms
)
383 self
.comb
+= self
.cpu
.jtag_tdi
.eq(jtagpads
.tdi
)
384 self
.comb
+= jtagpads
.tdo
.eq(self
.cpu
.jtag_tdo
)
389 setattr(self
.submodules
, name
, PWM(platform
.request("pwm", i
)))
393 self
.submodules
.i2c
= I2CMaster(platform
.request("i2c"))
396 # SDCard -----------------------------------------------------
399 sdcard_pads
= self
.platform
.request("sdcard")
402 self
.submodules
.sdphy
= SDPHY(sdcard_pads
,
403 self
.platform
.device
, self
.clk_freq
)
404 self
.submodules
.sdcore
= SDCore(self
.sdphy
)
405 self
.add_csr("sdphy")
406 self
.add_csr("sdcore")
409 bus
= wishbone
.Interface(data_width
=self
.bus
.data_width
,
410 adr_width
=self
.bus
.address_width
)
411 self
.submodules
.sdblock2mem
= SDBlock2MemDMA(bus
=bus
,
412 endianness
=self
.cpu
.endianness
)
413 self
.comb
+= self
.sdcore
.source
.connect(self
.sdblock2mem
.sink
)
414 dma_bus
= self
.bus
if not hasattr(self
, "dma_bus") else self
.dma_bus
415 dma_bus
.add_master("sdblock2mem", master
=bus
)
416 self
.add_csr("sdblock2mem")
419 bus
= wishbone
.Interface(data_width
=self
.bus
.data_width
,
420 adr_width
=self
.bus
.address_width
)
421 self
.submodules
.sdmem2block
= SDMem2BlockDMA(bus
=bus
,
422 endianness
=self
.cpu
.endianness
)
423 self
.comb
+= self
.sdmem2block
.source
.connect(self
.sdcore
.sink
)
424 dma_bus
= self
.bus
if not hasattr(self
, "dma_bus") else self
.dma_bus
425 dma_bus
.add_master("sdmem2block", master
=bus
)
426 self
.add_csr("sdmem2block")
428 # Debug ---------------------------------------------------------------
432 # setup running of DMI FSM
435 dmi_dout
= Signal(64)
441 dbg_dout
= Signal(64)
444 # capture pc from dmi
446 active_dbg
= Signal()
447 active_dbg_cr
= Signal()
448 active_dbg_xer
= Signal()
457 # increment counter, Stop after 100000 cycles
459 self
.sync
+= uptime
.eq(uptime
+ 1)
460 #self.sync += If(uptime == 1000000000000, Finish())
462 # DMI FSM counter and FSM itself
463 dmicount
= Signal(10)
464 dmirunning
= Signal(1)
465 dmi_monitor
= Signal(1)
467 self
.submodules
+= dmifsm
471 If(dmi_req
& dmi_wen
,
472 (self
.cpu
.dmi_addr
.eq(dmi_addr
), # DMI Addr
473 self
.cpu
.dmi_din
.eq(dmi_din
), # DMI in
474 self
.cpu
.dmi_req
.eq(1), # DMI request
475 self
.cpu
.dmi_wr
.eq(1), # DMI write
482 If(dmi_req
& ~dmi_wen
,
483 (self
.cpu
.dmi_addr
.eq(dmi_addr
), # DMI Addr
484 self
.cpu
.dmi_req
.eq(1), # DMI request
485 self
.cpu
.dmi_wr
.eq(0), # DMI read
487 # acknowledge received: capture data.
489 NextValue(dbg_addr
, dmi_addr
),
490 NextValue(dbg_dout
, self
.cpu
.dmi_dout
),
491 NextValue(dbg_msg
, 1),
498 # DMI response received: reset the dmi request and check if
502 NextState("FIRE_MONITOR"), # fire "monitor" on next cycle
504 NextState("START"), # back to start on next cycle
506 NextValue(dmi_req
, 0),
507 NextValue(dmi_addr
, 0),
508 NextValue(dmi_din
, 0),
509 NextValue(dmi_wen
, 0),
512 # "monitor" mode fires off a STAT request
513 dmifsm
.act("FIRE_MONITOR",
514 (NextValue(dmi_req
, 1),
515 NextValue(dmi_addr
, 1), # DMI STAT address
516 NextValue(dmi_din
, 0),
517 NextValue(dmi_wen
, 0), # read STAT
518 NextState("START"), # back to start on next cycle
522 self
.comb
+= xer_so
.eq((dbg_dout
& 1) == 1)
523 self
.comb
+= xer_ca
.eq((dbg_dout
& 4) == 4)
524 self
.comb
+= xer_ca32
.eq((dbg_dout
& 8) == 8)
525 self
.comb
+= xer_ov
.eq((dbg_dout
& 16) == 16)
526 self
.comb
+= xer_ov32
.eq((dbg_dout
& 32) == 32)
529 self
.sync
+= If(dbg_msg
,
530 (If(active_dbg
& (dbg_addr
== 0b10), # PC
531 Display("pc : %016x", dbg_dout
),
533 If(dbg_addr
== 0b10, # PC
534 pc
.eq(dbg_dout
), # capture PC
536 #If(dbg_addr == 0b11, # MSR
537 # Display(" msr: %016x", dbg_dout),
539 If(dbg_addr
== 0b1000, # CR
540 Display(" cr : %016x", dbg_dout
),
542 If(dbg_addr
== 0b1001, # XER
543 Display(" xer: so %d ca %d 32 %d ov %d 32 %d",
544 xer_so
, xer_ca
, xer_ca32
, xer_ov
, xer_ov32
),
546 If(dbg_addr
== 0b101, # GPR
547 Display(" gpr: %016x", dbg_dout
),
549 # also check if this is a "stat"
550 If(dbg_addr
== 1, # requested a STAT
551 #Display(" stat: %x", dbg_dout),
552 If(dbg_dout
& 2, # bit 2 of STAT is "stopped" mode
553 dmirunning
.eq(1), # continue running
554 dmi_monitor
.eq(0), # and stop monitor mode
562 self
.sync
+= If(uptime
== 0,
563 (dmi_addr
.eq(0), # CTRL
564 dmi_din
.eq(1<<0), # STOP
570 self
.sync
+= If(uptime
== 4,
574 self
.sync
+= If(dmirunning
,
575 dmicount
.eq(dmicount
+ 1),
578 # loop every 1<<N cycles
582 self
.sync
+= If(dmicount
== 4,
583 (dmi_addr
.eq(0b10), # NIA
590 self
.sync
+= If(dmicount
== 8,
591 (dmi_addr
.eq(0), # CTRL
592 dmi_din
.eq(1<<3), # STEP
595 dmirunning
.eq(0), # stop counter, need to fire "monitor"
596 dmi_monitor
.eq(1), # start "monitor" instead
600 # limit range of pc for debug reporting
601 #self.comb += active_dbg.eq((0x378c <= pc) & (pc <= 0x38d8))
602 #self.comb += active_dbg.eq((0x0 < pc) & (pc < 0x58))
603 self
.comb
+= active_dbg
.eq(1)
607 self
.sync
+= If(active_dbg
& (dmicount
== 12),
608 (dmi_addr
.eq(0b11), # MSR
614 if cpu
== "libresoc":
615 #self.comb += active_dbg_cr.eq((0x10300 <= pc) & (pc <= 0x12600))
616 self
.comb
+= active_dbg_cr
.eq(0)
619 self
.sync
+= If(active_dbg_cr
& (dmicount
== 16),
620 (dmi_addr
.eq(0b1000), # CR
626 #self.comb += active_dbg_xer.eq((0x10300 <= pc) & (pc <= 0x1094c))
627 self
.comb
+= active_dbg_xer
.eq(active_dbg_cr
)
630 self
.sync
+= If(active_dbg_xer
& (dmicount
== 20),
631 (dmi_addr
.eq(0b1001), # XER
639 self
.sync
+= If(active_dbg
& (dmicount
== 24+(i
*8)),
640 (dmi_addr
.eq(0b100), # GSPR addr
647 self
.sync
+= If(active_dbg
& (dmicount
== 28+(i
*8)),
648 (dmi_addr
.eq(0b101), # GSPR data
654 # monitor bbus read/write
655 self
.sync
+= If(active_dbg
& self
.cpu
.dbus
.stb
& self
.cpu
.dbus
.ack
,
656 Display(" [%06x] dadr: %8x, we %d s %01x w %016x r: %016x",
670 self
.sync
+= If(active_dbg
& self
.cpu
.ibus
.stb
& self
.cpu
.ibus
.ack
&
672 Display(" [%06x] iadr: %8x, s %01x w %016x",
681 self
.sync
+= If(active_dbg
& self
.cpu
.ibus
.stb
& self
.cpu
.ibus
.ack
&
683 Display(" [%06x] iadr: %8x, s %01x r %016x",
692 # Build -----------------------------------------------------------------------
695 parser
= argparse
.ArgumentParser(description
="LiteX LibreSoC CPU Sim")
696 parser
.add_argument("--cpu", default
="libresoc",
697 help="CPU to use: libresoc (default) or microwatt")
698 parser
.add_argument("--platform", default
="sim",
699 help="platform (sim or ls180)")
700 parser
.add_argument("--debug", action
="store_true",
701 help="Enable debug traces")
702 parser
.add_argument("--trace", action
="store_true",
703 help="Enable tracing")
704 parser
.add_argument("--trace-start", default
=0,
705 help="Cycle to start FST tracing")
706 parser
.add_argument("--trace-end", default
=-1,
707 help="Cycle to end FST tracing")
708 parser
.add_argument("--build", action
="store_true", help="Build bitstream")
709 args
= parser
.parse_args()
712 if args
.platform
== 'ls180':
713 soc
= LibreSoCSim(cpu
=args
.cpu
, debug
=args
.debug
,
714 platform
=args
.platform
)
716 builder
= Builder(soc
, compile_gateware
= True)
717 builder
.build(run
= True)
721 sim_config
= SimConfig(default_clk
="sys_clk")
722 sim_config
.add_module("serial2console", "serial")
725 soc
= LibreSoCSim(cpu
=args
.cpu
, debug
=args
.debug
,
726 platform
=args
.platform
)
727 builder
= Builder(soc
, compile_gateware
= i
!=0)
728 builder
.build(sim_config
=sim_config
,
731 trace_start
= int(args
.trace_start
),
732 trace_end
= int(args
.trace_end
),
736 if __name__
== "__main__":