|
| 1 | +# This file is Copyright (c) 2015 William D. Jones <thor0505@comcast.net> |
| 2 | +# License: BSD |
| 3 | + |
| 4 | +from mibuild.generic_platform import * |
| 5 | +from mibuild.xilinx import XilinxPlatform |
| 6 | +from mibuild.xilinx.programmer import XC3SProg |
| 7 | + |
| 8 | + |
| 9 | +_io = [ |
| 10 | + ("clk50", 0, Pins("P43"), IOStandard("LVCMOS33")), |
| 11 | + |
| 12 | + ("user_btn", 0, Pins("P41"), IOStandard("LVTTL")), |
| 13 | + |
| 14 | + # The serial interface and flash memory have a shared SPI bus. |
| 15 | + # FPGA is secondary |
| 16 | + ("spiserial", 0, |
| 17 | + Subsignal("cs_n", Pins("P39"), IOStandard("LVTTL")), |
| 18 | + Subsignal("clk", Pins("P53"), IOStandard("LVTTL")), |
| 19 | + Subsignal("mosi", Pins("P46"), IOStandard("LVTTL")), |
| 20 | + Subsignal("miso", Pins("P51"), IOStandard("LVTTL")) |
| 21 | + ), |
| 22 | + |
| 23 | + # FPGA is primary |
| 24 | + ("spiflash", 0, |
| 25 | + Subsignal("cs_n", Pins("P27"), IOStandard("LVTTL")), |
| 26 | + Subsignal("clk", Pins("P53"), IOStandard("LVTTL")), |
| 27 | + Subsignal("mosi", Pins("P46"), IOStandard("LVTTL")), |
| 28 | + Subsignal("miso", Pins("P51"), IOStandard("LVTTL")) |
| 29 | + ), |
| 30 | + |
| 31 | + ("spiflash2x", 0, |
| 32 | + Subsignal("cs_n", Pins("P27")), |
| 33 | + Subsignal("clk", Pins("P53")), |
| 34 | + Subsignal("dq", Pins("P46", "P51")), |
| 35 | + IOStandard("LVTTL"), Misc("SLEW=FAST") |
| 36 | + ), |
| 37 | + |
| 38 | + # ADC over SPI- FPGA is primary |
| 39 | + ("adc", 0, |
| 40 | + Subsignal("cs_n", Pins("P12"), IOStandard("LVTTL")), |
| 41 | + Subsignal("clk", Pins("P9"), IOStandard("LVTTL")), |
| 42 | + Subsignal("mosi", Pins("P10"), IOStandard("LVTTL")), |
| 43 | + Subsignal("miso", Pins("P21"), IOStandard("LVTTL")) |
| 44 | + ), |
| 45 | + |
| 46 | + # GPIO control- SRAM and connectors are shared: these pins control how |
| 47 | + # to access each. Recommended to combine with gpio_sram_bus extension, |
| 48 | + # since these pins are related but not exposed on connectors. |
| 49 | + ("gpio_ctl", 0, |
| 50 | + Subsignal("ce_n", Pins("P3")), # Memory chip-enable. Called MEM_CEN |
| 51 | + # in schematic. |
| 52 | + Subsignal("bussw_oe_n", Pins("P30")), # 5V tolerant GPIO is shared |
| 53 | + # w/ memory using this pin. |
| 54 | + IOStandard("LVTTL"), Misc("SLEW=FAST") |
| 55 | + ) |
| 56 | +] |
| 57 | + |
| 58 | +# Perhaps define some connectors as having a specific purpose- i.e. a 5V GPIO |
| 59 | +# bus with data, peripheral-select, and control signals? |
| 60 | +_connectors = [ |
| 61 | + ("GPIO", """P59 P60 P61 P62 P64 P57 |
| 62 | + P56 P52 P50 P49 P85 P84 |
| 63 | + P83 P78 P77 P65 P70 P71 |
| 64 | + P72 P73 P5 P4 P6 P98 |
| 65 | + P94 P93 P90 P89 P88 P86"""), # 5V I/O- LVTTL |
| 66 | + ("DIO", "P20 P32 P33 P34 P35 P36 P37"), # Fast 3.3V IO (Directly attached |
| 67 | + # to FPGA)- LVCMOS33 |
| 68 | + ("CLKIO", "P40 P44"), # Clock IO (Can be used as GPIO)- LVCMOS33 |
| 69 | + ("INPUT", "P68 P97 P7 P82"), # Input-only pins- LVCMOS33 |
| 70 | + ("LED", "P13 P15 P16 P19") # LEDs can be used as pins as well- LVTTL. |
| 71 | +] |
| 72 | + |
| 73 | +# Some default useful extensions- use platform.add_extension() to use, e.g. |
| 74 | +# from mibuild.platforms import mercury |
| 75 | +# plat = mercury.Platform() |
| 76 | +# plat.add_extension(mercury.gpio_sram) |
| 77 | + |
| 78 | +# SRAM and 5V-tolerant I/O share a parallel bus on 200k gate version. The SRAM |
| 79 | +# controller needs to take care of switching the bus between the two. Meant to |
| 80 | +# be Cat() into one GPIO bus, and combined with gpio_ctl. |
| 81 | +gpio_sram = [ |
| 82 | + ("gpio_sram_bus", 0, |
| 83 | + Subsignal("a", Pins("""GPIO:0 GPIO:1 GPIO:2 GPIO:3 |
| 84 | + GPIO:4 GPIO:5 GPIO:6 GPIO:7 |
| 85 | + GPIO:8 GPIO:9 GPIO:10 GPIO:11 |
| 86 | + GPIO:12 GPIO:13 GPIO:14 GPIO:15 |
| 87 | + GPIO:16 GPIO:17 GPIO:18 GPIO:19""")), |
| 88 | + # A19 is actually unused- free for GPIO |
| 89 | + # 8-bit data bus |
| 90 | + Subsignal("d", Pins("""GPIO:20 GPIO:21 GPIO:22 GPIO:23 |
| 91 | + GPIO:24 GPIO:25 GPIO:26 GPIO:27""")), |
| 92 | + Subsignal("we_n", Pins("GPIO:28")), |
| 93 | + Subsignal("unused", Pins("GPIO:29")), # Only used by GPIO. |
| 94 | + # Subsignal("oe_n", Pins()), # If OE wasn't tied to ground on Mercury, |
| 95 | + # this pin would be here. |
| 96 | + IOStandard("LVTTL"), Misc("SLEW=FAST") |
| 97 | + ) |
| 98 | +] |
| 99 | + |
| 100 | +# The "serial port" is in fact over SPI. The creators of the board provide a |
| 101 | +# VHDL file for talking over this interface. In light of space constraints and |
| 102 | +# the fact that both the FT245RL and FPGA can BOTH be SPI primaries, however, |
| 103 | +# it may be necessary to sacrifice two "high-speed" (DIO, INPUT) pins instead. |
| 104 | +serial = [ |
| 105 | + ("serial", 0, |
| 106 | + Subsignal("tx", Pins("DIO:0"), IOStandard("LVCMOS33")), # FTDI D1 |
| 107 | + Subsignal("rx", Pins("INPUT:0"), IOStandard("LVCMOS33")) |
| 108 | + ) # FTDI D0 |
| 109 | +] |
| 110 | + |
| 111 | +leds = [ |
| 112 | + ("user_led", 0, Pins("LED:0"), IOStandard("LVTTL")), |
| 113 | + ("user_led", 1, Pins("LED:1"), IOStandard("LVTTL")), |
| 114 | + ("user_led", 2, Pins("LED:2"), IOStandard("LVTTL")), |
| 115 | + ("user_led", 3, Pins("LED:3"), IOStandard("LVTTL")) |
| 116 | +] |
| 117 | + |
| 118 | +# See: http://www.micro-nova.com/mercury-baseboard/ |
| 119 | +# Not implemented yet. |
| 120 | +baseboard = [ |
| 121 | +] |
| 122 | + |
| 123 | + |
| 124 | +class Platform(XilinxPlatform): |
| 125 | + default_clk_name = "clk50" |
| 126 | + default_clk_period = 20 |
| 127 | + |
| 128 | + def __init__(self, device="xc3s200a-4-vq100", programmer="xc3sprog"): |
| 129 | + XilinxPlatform.__init__(self, device, _io, _connectors) |
| 130 | + # Small device- optimize for AREA instead of SPEED (LM32 runs at about |
| 131 | + # 60-65MHz in AREA configuration). |
| 132 | + self.toolchain.xst_opt = """-ifmt MIXED |
| 133 | +-use_new_parser yes |
| 134 | +-opt_mode AREA |
| 135 | +-register_balancing yes""" |
| 136 | + |
| 137 | + def create_programmer(self): |
| 138 | + raise NotImplementedError |
| 139 | + # Not actually supported right now- add FT245RL support to xc3sprog. |
| 140 | + # Alternatively, use the JTAG pins instead of USB with another |
| 141 | + # supported programmer. |
| 142 | + if self.programmer == "xc3sprog": |
| 143 | + return XC3SProg("mercury", "bscan_spi_mercury.bit") |
| 144 | + else: |
| 145 | + raise ValueError("""{} programmer is not |
| 146 | + supported""".format(programmer)) |
0 commit comments