|
| 1 | +import os |
| 2 | +import subprocess |
| 3 | + |
| 4 | +from nmigen.build import * |
| 5 | +from nmigen.vendor.intel import * |
| 6 | +from .resources import * |
| 7 | + |
| 8 | + |
| 9 | +__all__ = ["RZEasyFPGAA2_2Platform"] |
| 10 | + |
| 11 | + |
| 12 | +class RZEasyFPGAA2_2Platform(IntelPlatform): |
| 13 | + device = "EP4CE6" # Cyclone IV 6K LEs |
| 14 | + package = "E22" # EQFP 144 pins |
| 15 | + speed = "C8" |
| 16 | + default_clk = "clk50" # 50MHz builtin clock |
| 17 | + default_rst = "rst" |
| 18 | + resources = [ |
| 19 | + # Clock |
| 20 | + Resource("clk50", 0, Pins("23", dir="i"), |
| 21 | + Clock(50e6), Attrs(io_standard="3.3-V LVTTL")), |
| 22 | + |
| 23 | + # Reset switch, located on the lower left of the board. |
| 24 | + Resource("rst", 0, PinsN("25", dir="i"), Attrs(io_standard="3.3-V LVTTL")), |
| 25 | + |
| 26 | + # LEDs, located on the bottom of the board. |
| 27 | + *LEDResources( |
| 28 | + pins="87 86 85 84", invert=True, |
| 29 | + attrs=Attrs(io_standard="3.3-V LVTTL")), |
| 30 | + |
| 31 | + # Buttons, located on the bottom of the board, right of the LEDs. |
| 32 | + *ButtonResources( |
| 33 | + pins="88 89 90 91", invert=True, |
| 34 | + attrs=Attrs(io_standard="3.3-V LVTTL")), |
| 35 | + |
| 36 | + # Connections to the SKHynix RAM chip on board. |
| 37 | + SDRAMResource(0, |
| 38 | + clk="43", cs="72", we="69", ras="71", cas="70", |
| 39 | + ba="73 74", a="76 77 80 83 68 67 66 65 64 60 75 59", |
| 40 | + dq="28 30 31 32 33 34 38 39 54 53 52 51 50 49 46 44", |
| 41 | + dqm="42 55", attrs=Attrs(io_standard="3.3-V LVCMOS")), |
| 42 | + |
| 43 | + # VGA connector, located on the right of the board. |
| 44 | + Resource("vga", 0, |
| 45 | + Subsignal("r", Pins("106", dir="o")), |
| 46 | + Subsignal("g", Pins("105", dir="o")), |
| 47 | + Subsignal("b", Pins("104", dir="o")), |
| 48 | + Subsignal("hs", Pins("101", dir="o")), |
| 49 | + Subsignal("vs", Pins("103", dir="o")), |
| 50 | + ), |
| 51 | + |
| 52 | + # 4 digit 7 segment display, located on top of the board. |
| 53 | + Display7SegResource(0, |
| 54 | + a="128", b="121", c="125", d="129", e="132", f="126", g="124", dp="127", |
| 55 | + invert=True), |
| 56 | + Resource("display_7seg_ctrl", 0, |
| 57 | + Subsignal("en", Pins("133 135 136 137", dir="o", invert=True)), |
| 58 | + ), |
| 59 | + |
| 60 | + # PS2 port, located on upper right of the board. |
| 61 | + Resource("ps2_host", 0, |
| 62 | + Subsignal("clk", Pins("119", dir="io")), |
| 63 | + Subsignal("dat", Pins("120", dir="io")), |
| 64 | + ), |
| 65 | + |
| 66 | + # LM75 temperature sensor |
| 67 | + I2CResource(0, scl="112", sda="113"), |
| 68 | + |
| 69 | + # AT24C08 EEPROM |
| 70 | + I2CResource(1, scl="99" , sda="98" ), |
| 71 | + |
| 72 | + # Buzzer |
| 73 | + Resource("buzzer", 0, PinsN("110", dir="o")), |
| 74 | + |
| 75 | + # Serial port, located above the VGA port. |
| 76 | + UARTResource(0, tx="114", rx="115"), |
| 77 | + |
| 78 | + # LCD connector, located above the 7 segment display. |
| 79 | + Resource("lcd_hd44780", 0, |
| 80 | + Subsignal("rs", Pins("141", dir="o")), |
| 81 | + Subsignal("rw", Pins("138", dir="o")), |
| 82 | + Subsignal("e" , Pins("143", dir="o")), |
| 83 | + Subsignal("d" , Pins("142 1 144 3 2 10 7 11", dir="io")), |
| 84 | + ), |
| 85 | + |
| 86 | + # IR receiver, located right of the buttons. |
| 87 | + Resource("cir", 0, |
| 88 | + Subsignal("rx", Pins("100", dir="i")) |
| 89 | + ), |
| 90 | + ] |
| 91 | + |
| 92 | + connectors = [ |
| 93 | + # Located above the chip. |
| 94 | + Connector("gpio", 0, |
| 95 | + "- - 11 7 2 144 142 138 136 133 129 127 125 121 119 114 112 110 - " |
| 96 | + "- - 24 10 3 1 143 141 137 135 132 128 126 124 120 115 113 111 - "), |
| 97 | + |
| 98 | + # Located right of the chip. |
| 99 | + Connector("gpio", 1, |
| 100 | + "- - " |
| 101 | + "106 105" |
| 102 | + "104 103" |
| 103 | + "101 100" |
| 104 | + "99 98 " |
| 105 | + "91 90 " |
| 106 | + "89 88 " |
| 107 | + "87 86 " |
| 108 | + "85 84 " |
| 109 | + "- - "), |
| 110 | + |
| 111 | + # Located below the chip. |
| 112 | + Connector("gpio", 2, |
| 113 | + "30 32 34 39 43 46 50 52 54 58 60 65 67 71 73 75 77 83 - - - " |
| 114 | + "28 31 33 38 42 44 51 53 55 59 64 66 68 70 72 74 76 80 - - - "), |
| 115 | + ] |
| 116 | + |
| 117 | + def toolchain_prepare(self, fragment, name, **kwargs): |
| 118 | + overrides = { |
| 119 | + "add_settings": |
| 120 | + '''set_global_assignment -name CYCLONEII_RESERVE_NCEO_AFTER_CONFIGURATION "USE AS REGULAR IO"''' |
| 121 | + } |
| 122 | + return super().toolchain_prepare(fragment, name, **overrides, **kwargs) |
| 123 | + |
| 124 | + def toolchain_program(self, products, name): |
| 125 | + quartus_pgm = os.environ.get("QUARTUS_PGM", "quartus_pgm") |
| 126 | + with products.extract("{}.sof".format(name)) as bitstream_filename: |
| 127 | + subprocess.check_call([quartus_pgm, "--haltcc", "--mode", "JTAG", |
| 128 | + "--operation", "P;" + bitstream_filename]) |
| 129 | + |
| 130 | + |
| 131 | +if __name__ == "__main__": |
| 132 | + from .test.blinky import Blinky |
| 133 | + RZEasyFPGAA2_2Platform().build(Blinky(), do_program=True) |
0 commit comments