Comments (4)
Nothing like a bit of printf debugging - so my multi-driven net was due to the fact that calling pll.create_clkout
also adds an async reset synchroniser to the same domain. So having removed the duplicate it now seems to at least synthesise correctly.
So my only outstanding question is how would I go about assigning an external signal to either soc_rst
or cpu_rst
individually?
from litex.
Something like:
# Define output pins
from litex.build.generic_platform import Pins, IOStandard
platform.add_extension([
("reset2", 0, Pins("69"), IOStandard("LVCMOS33")),
])
rst2 = platform.request("reset2"),
from litex.
Thanks but perhaps a better description is in order.
Inside of litex.soc.integration.soc
there is a SoCController
class that instantiates two CSRs that enable software to reset either just the CPU or the full SoC. https://github.com/enjoy-digital/litex/blob/master/litex/soc/integration/soc.py#L792
Within the same file, in the SoC
class, the CPU reset is driven by OR'ing these two signals together. https://github.com/enjoy-digital/litex/blob/master/litex/soc/integration/soc.py#L1143
And finally, the soc_rst
is used to reset the CRG
if it has an attribute named rst
: https://github.com/enjoy-digital/litex/blob/master/litex/soc/integration/soc.py#L1181
So we effectively have the following RTL:
assign soc_rst = soc_controller.soc_rst;
assign cpu_rst = soc_controller.cpu_rst;
assign cpu.reset = soc_rst || cpu_rst;
assign crg.rst = soc_rst;
What I want to do is add an external reset source to either the soc_rst
or cpu_rst
terms. So let's say I grab that input pin using the usual platform.request()
call, how do I feed that into those reset terms so that I end up with:
assign cpu.reset = soc_rst || cpu_reset || external_reset;
from litex.
OK, after a few questions on Discord, it seems that the way to do this is to work around the limitations of Migen by creating a new clock domain into which you synchronise the external reset. Then you have a reset term that you can feed into the CPU reset.
class CRG(Module, AutoCSR):
"""Clock and Reset Generation"""
def __init__(self, platform):
self.rst = Signal()
self.clock_domains.cd_sys = ClockDomain()
self.clock_domains.cd_por = ClockDomain(reset_less=True)
self.clock_domains.cd_ext = ClockDomain()
clk_in = platform.request(platform.default_clk_name)
clk_in_freq = round(1e9 / platform.default_clk_period)
# Power on reset
por_count = Signal(16, reset=2**16 - 1)
por_done = Signal()
self.comb += self.cd_por.clk.eq(clk_in)
self.comb += por_done.eq(por_count == 0)
self.sync.por += If(~por_done, por_count.eq(por_count - 1))
# PLL
self.submodules.pll = pll = ECP5PLL()
self.comb += pll.reset.eq(~por_done | self.rst)
pll.register_clkin(clk_in, clk_in_freq)
pll.create_clkout(self.cd_sys, 50e6, margin=0, with_reset=False)
# The SYS domain is reset whenever the PLL is unlocked
sys_rst = Signal()
self.comb += sys_rst.eq(~pll.locked)
self.specials += AsyncResetSynchronizer(self.cd_sys, sys_rst)
# External push button reset synchronised into its own domain
rst_n = platform.request("rst_n")
self.comb += self.cd_ext.clk.eq(self.cd_sys.clk)
self.specials += AsyncResetSynchronizer(self.cd_ext, ~rst_n)
class VersaSoC(SoCCore):
"""Top level of the Versa platform"""
def __init__(self, **kwargs):
platform = lattice_versa_ecp5.Platform(device="LFE5UM", toolchain="trellis")
SoCCore.__init__(self, platform=platform, clk_freq=50e6, **kwargs)
# Clock/Reset Generator
self.crg = CRG(platform)
# Hook up the push button reset
self.comb += If(self.crg.cd_ext.rst, self.cpu.reset.eq(1))
Be careful of trying to do what you might expect is valid by just OR'ing in the reset term. Migen uses non-blocking assignments for everything (!) so the following doesn't work:
# Hook up the push button reset
self.comb += self.cpu.reset.eq(self.cpu.reset | ~self.crg.rst_n)
I think it's probably easier to write your CRG in SV and import that if you are doing anything more complex with clocks/resets.
from litex.
Related Issues (20)
- brew cask install tuntap
- The non-ASCII character "…" in README.md may cause failure in setup HOT 1
- Upgrade of the CV32E40P to the openhwgroup repo ? HOT 9
- Failed to modify “boot.c” and the riscv64-unknown-elf/bin/ld report an error “undefined reference to `__heap_start'” HOT 4
- WSL2 Debian Gowin Toolchain Path HOT 5
- Missing VCCIO settings for ECP5 when using diamond toolchain
- Html doc not generating for TUL PYNQ Z2 HOT 2
- Make Error *** No rule to make target 'boot-helper.o', needed by 'bios.elf'. Stop. Neorv32 core TUL PYNQ Z2 HOT 1
- Wishbone bus high latency in read on Vexriscv CPU "minimal" variant and read/write on others CPU. HOT 3
- Help with LiteScope and jtagbone HOT 5
- No serial output on tang 9k when selecting other sys-clk-freq HOT 11
- [Feature request] Support to run WebAssembly on FPGA HOT 1
- LiteScope: more help needed HOT 5
- tang Nano 9k no uart out HOT 2
- [Feature request] Support of pmem / Non Volatile Memory HOT 1
- Clock domain crossing for peripherals HOT 3
- vexriscv_smp: only 32 CSR locations supported with current mem_mam HOT 4
- Unexpected behaviour of printf HOT 9
- Windows based build cannot find toolchain support HOT 3
- NuttX + LiteEth: Potential regression when using Hybrid Etherbone/Ethernet. HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from litex.