Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid HFOSC divider value '0b0' on lattice ICE40 #520

Closed
davidlattimore opened this issue Nov 2, 2020 · 1 comment · Fixed by #521
Closed

Invalid HFOSC divider value '0b0' on lattice ICE40 #520

davidlattimore opened this issue Nov 2, 2020 · 1 comment · Fixed by #521
Labels
Milestone

Comments

@davidlattimore
Copy link
Contributor

If I run the following python script:

from nmigen import *

class TestLEDModule( Elaboratable ):
  def __init__( self ):
    self.count = Signal( 32, reset = 0 )
  def elaborate( self, platform ):
    m = Module()
    m.d.sync += self.count.eq( self.count + 1 )
    return m

from nmigen_boards.upduino_v2 import *
if __name__ == "__main__":
  dut = TestLEDModule()
  UpduinoV2Platform().build( dut )

I get the following error:

ERROR: Invalid HFOSC divider value '0b0' - expecting 0b00, 0b01, 0b10 or 0b11
ERROR: Packing design failed.

Making the following change appears to fix it

diff --git a/nmigen/vendor/lattice_ice40.py b/nmigen/vendor/lattice_ice40.py
index 14026fa..d5e4dd6 100644
--- a/nmigen/vendor/lattice_ice40.py
+++ b/nmigen/vendor/lattice_ice40.py
@@ -379,7 +379,7 @@ class LatticeICE40Platform(TemplatedPlatform):
                 m.submodules += Instance("SB_HFOSC",
                                          i_CLKHFEN=1,
                                          i_CLKHFPU=1,
-                                         p_CLKHF_DIV="0b{0:b}".format(self.hfosc_div),
+                                         p_CLKHF_DIV="0b{0:02b}".format(self.hfosc_div),
                                          o_CLKHF=clk_i)
                 delay = int(100e-6 * self.default_clk_frequency)
             # Internal low-speed clock: 10 KHz.

I've only just started using nmigen today, so it's always possible that I'm doing some thing silly. I'm happy to send a PR if you'd like.

@whitequark whitequark added the bug label Nov 2, 2020
@whitequark
Copy link
Member

This is clearly a bug--most likely, the code in question predates improved syntax checking in nextpnr. Please send a PR.

davidlattimore pushed a commit to davidlattimore/nmigen that referenced this issue Nov 2, 2020
@whitequark whitequark added this to the 0.3 milestone Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants