|
| 1 | +import os |
| 2 | + |
| 3 | +from chipflow_lib.platforms.sim import SimPlatform |
| 4 | + |
| 5 | +from amaranth import Module, Instance, ClockSignal, ResetSignal |
| 6 | +from amaranth.lib import wiring |
| 7 | +from amaranth.lib.wiring import In, Out, flipped, connect |
| 8 | + |
| 9 | +# We don't actually use these peripherals - they are just imported for the pin signatures |
| 10 | +from amaranth_orchard.memory import QSPIFlash |
| 11 | +from amaranth_orchard.io import GPIOPeripheral |
| 12 | +from amaranth_orchard.io import UARTPeripheral |
| 13 | + |
| 14 | +from chipflow_lib.platforms import InputPinSignature, OutputPinSignature |
| 15 | + |
| 16 | +__all__ = ["MySoC"] |
| 17 | + |
| 18 | + |
| 19 | +class MySoC(wiring.Component): |
| 20 | + def __init__(self): |
| 21 | + # Top level interfaces |
| 22 | + |
| 23 | + super().__init__({ |
| 24 | + "flash": Out(QSPIFlash.Signature()), |
| 25 | + "uart_0": Out(UARTPeripheral.Signature()), |
| 26 | + "gpio_0": Out(GPIOPeripheral.Signature(pin_count=8)), |
| 27 | + }) |
| 28 | + |
| 29 | + def elaborate(self, platform): |
| 30 | + m = Module() |
| 31 | + |
| 32 | + base = os.path.dirname(__file__) |
| 33 | + |
| 34 | + verilog_sources = [ |
| 35 | + f"{base}/picosoc_asic_top.v", |
| 36 | + f"{base}/picorv32/picosoc/spimemio.v", |
| 37 | + f"{base}/picorv32/picosoc/simpleuart.v", |
| 38 | + f"{base}/picorv32/picosoc/picosoc.v", |
| 39 | + f"{base}/picorv32/picorv32.v", |
| 40 | + ] |
| 41 | + |
| 42 | + for verilog_file in verilog_sources: |
| 43 | + with open(verilog_file, 'r') as f: |
| 44 | + platform.add_file(verilog_file, f) |
| 45 | + |
| 46 | + m.submodules.soc = soc = Instance("picosoc_asic_top", |
| 47 | + # Clock and reset |
| 48 | + i_clk=ClockSignal(), |
| 49 | + i_resetn=~ResetSignal(), |
| 50 | + |
| 51 | + # UART |
| 52 | + o_ser_tx=self.uart_0.tx.o, |
| 53 | + i_ser_rx=self.uart_0.rx.i, |
| 54 | + |
| 55 | + # SPI flash |
| 56 | + o_flash_csb=self.flash.csn.o, |
| 57 | + o_flash_clk=self.flash.clk.o, |
| 58 | + |
| 59 | + o_flash_io0_oe=self.flash.d.oe[0], |
| 60 | + o_flash_io1_oe=self.flash.d.oe[1], |
| 61 | + o_flash_io2_oe=self.flash.d.oe[2], |
| 62 | + o_flash_io3_oe=self.flash.d.oe[3], |
| 63 | + |
| 64 | + o_flash_io0_do=self.flash.d.o[0], |
| 65 | + o_flash_io1_do=self.flash.d.o[1], |
| 66 | + o_flash_io2_do=self.flash.d.o[2], |
| 67 | + o_flash_io3_do=self.flash.d.o[3], |
| 68 | + |
| 69 | + i_flash_io0_di=self.flash.d.i[0], |
| 70 | + i_flash_io1_di=self.flash.d.i[1], |
| 71 | + i_flash_io2_di=self.flash.d.i[2], |
| 72 | + i_flash_io3_di=self.flash.d.i[3], |
| 73 | + |
| 74 | + # LEDs |
| 75 | + o_leds=self.gpio_0.gpio.o |
| 76 | + ) |
| 77 | + |
| 78 | + # Hardwire GPIO to output enabled |
| 79 | + m.d.comb += self.gpio_0.gpio.oe.eq(0xFF) |
| 80 | + |
| 81 | + return m |
0 commit comments