|
| 1 | +import os |
| 2 | +import subprocess |
| 3 | +import shutil |
| 4 | + |
| 5 | +from nmigen.build import * |
| 6 | +from nmigen.vendor.lattice_ecp5 import * |
| 7 | +from .resources import * |
| 8 | + |
| 9 | +__all__ = ["ColorLightI9Platform"] |
| 10 | + |
| 11 | +class ColorLightI9Platform(LatticeECP5Platform): |
| 12 | + package = "BG381" |
| 13 | + speed = "8" |
| 14 | + default_clk = "clk25" |
| 15 | + device = "LFE5U-45F" |
| 16 | + |
| 17 | + resources = [ |
| 18 | + Resource("clk25", 0, Pins("P3", dir="i"), Clock(25e6), Attrs(IO_TYPE="LVCMOS33")), |
| 19 | + |
| 20 | + *LEDResources(pins="L2", |
| 21 | + attrs=Attrs(IO_TYPE="LVCMOS33", DRIVE="4")), |
| 22 | + |
| 23 | + *SPIFlashResources(0, |
| 24 | + cs_n="R2", clk="U3", copi="W2", cipo="V2", |
| 25 | + attrs=Attrs(PULLMODE="NONE", DRIVE="4", IO_TYPE="LVCMOS33") |
| 26 | + ), |
| 27 | + |
| 28 | + RGMIIResource(0, |
| 29 | + txc="U19", txd="U20 T19 T20 R20", tx_ctl="P19", |
| 30 | + rxc="L19", rxd="P20 N19 N20 M19", rx_ctl="M20", |
| 31 | + mdc="N5", mdio="P5", |
| 32 | + attrs=Attrs(PULLMODE="NONE", DRIVE="4", SLEWRATE="FAST", IO_TYPE="LVCMOS33") |
| 33 | + ), |
| 34 | + |
| 35 | + RGMIIResource(1, |
| 36 | + txc="G1", txd="G2 H1 J1 J3", tx_ctl="K1", |
| 37 | + rxc="H2", rxd="K2 L1 N1 P1", rx_ctl="P2", |
| 38 | + mdc="N5", mdio="P5", |
| 39 | + attrs=Attrs(PULLMODE="NONE", DRIVE="4", SLEWRATE="FAST", IO_TYPE="LVCMOS33") |
| 40 | + ), |
| 41 | + |
| 42 | + SDRAMResource(0, |
| 43 | + clk="B9", we_n="A10", cas_n="A9", ras_n="B10", |
| 44 | + ba="B11 C8", a="B13 C14 A16 A17 B16 B15 A14 A13 A12 A11 B12", |
| 45 | + dq="B6 A5 A6 A7 C7 B8 B5 A8 D8 D7 E8 D6 C6 D5 E7 C5 C10 D9 E11 D11 C11 D12 E9 C12 E14 C15 E13 D15 E12 B17 D14 D13", |
| 46 | + attrs=Attrs(PULLMODE="NONE", DRIVE="4", SLEWRATE="FAST", IO_TYPE="LVCMOS33") |
| 47 | + ), |
| 48 | + ] |
| 49 | + |
| 50 | + connectors = [ |
| 51 | + Connector("ddr2-sodimm-200p", 0, ( |
| 52 | + "- - - - - - - - - - " # 1- 10 |
| 53 | + "- - - - - - - - - - " # 11- 20 |
| 54 | + "- - - - - - - - - - " # 21- 30 |
| 55 | + "- - - - - - - - - - " # 31- 40 |
| 56 | + "L2 R1 - T1 - U1 - Y2 K18 W1 " # 41- 50 |
| 57 | + "C18 V1 - M1 - - T18 N2 R18 N3 " # 51- 60 |
| 58 | + "R17 T2 P17 M3 M17 T3 T17 R3 U18 N4 " # 61- 70 |
| 59 | + "U17 M4 P18 L4 N17 L5 N18 P16 M18 J16 " # 71- 80 |
| 60 | + "L20 J18 L18 J17 K20 H18 K19 H17 J20 G18 " # 81- 90 |
| 61 | + "J19 H16 H20 F18 G20 G16 G19 E18 F20 F17 " # 91-100 |
| 62 | + "F19 F16 E20 E16 - - - - E19 E17 " # 101-110 |
| 63 | + "D20 D18 D19 D17 C20 G5 B20 D16 B19 F5 " # 111-120 |
| 64 | + "B18 E6 A19 E5 C17 F4 A18 E4 D3 F1 " # 121-130 |
| 65 | + "C4 F3 B4 G3 C3 H3 E3 H4 A3 H5 " # 131-140 |
| 66 | + "C2 J4 B1 J5 C1 K3 D2 K4 D1 K5 " # 141-150 |
| 67 | + "E2 B3 E1 A2 F2 B2 - - L17 N16 " # 151-160 |
| 68 | + "- - - - - - - - - - " # 161-170 |
| 69 | + "- - - - - - - - - - " # 171-180 |
| 70 | + "- - - - - - - - - A4 " # 181-190 |
| 71 | + "D10 M5 E10 C9 - A15 - - - - " # 191-200 |
| 72 | + )) |
| 73 | + ] |
| 74 | + |
| 75 | + @property |
| 76 | + def required_tools(self): |
| 77 | + return super().required_tools + [ |
| 78 | + "openFPGALoader" |
| 79 | + ] |
| 80 | + |
| 81 | + def toolchain_prepare(self, fragment, name, **kwargs): |
| 82 | + overrides = dict(ecppack_opts="--compress") |
| 83 | + overrides.update(kwargs) |
| 84 | + return super().toolchain_prepare(fragment, name, **overrides) |
| 85 | + |
| 86 | + def toolchain_program(self, products, name): |
| 87 | + tool = os.environ.get("OPENFPGALOADER", "openFPGALoader") |
| 88 | + with products.extract("{}.bit".format(name)) as bitstream_filename: |
| 89 | + subprocess.check_call([tool, '-m', bitstream_filename]) |
| 90 | + |
| 91 | +if __name__ == "__main__": |
| 92 | + from .test.blinky import * |
| 93 | + ColorLightI9Platform().build(Blinky(), do_program=True) |
0 commit comments