Code Monkey home page Code Monkey logo

Comments (4)

shareefj avatar shareefj commented on June 12, 2024

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.

hvegh avatar hvegh commented on June 12, 2024

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.

shareefj avatar shareefj commented on June 12, 2024

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.

shareefj avatar shareefj commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.