Ejemplo n.º 1
0
 def addMemories(self, **kwargs):
     # spi flash
     if kwargs["spiflash"] != "None":
         csr_map_update(SoCCore.csr_map, ["spiflash"])
         # (default shadow @0xa0000000)
         self.mem_map.update({"spiflash": 0x20000000})
         spiflash_pads = platform.request(kwargs["spiflash"])
         spiflash_pads.clk = Signal()
         self.specials += Instance("STARTUPE2",
                                   i_CLK=0,
                                   i_GSR=0,
                                   i_GTS=0,
                                   i_KEYCLEARB=0,
                                   i_PACK=0,
                                   i_USRCCLKO=spiflash_pads.clk,
                                   i_USRCCLKTS=0,
                                   i_USRDONEO=1,
                                   i_USRDONETS=1)
         spiflash_dummy = {
             "spiflash_1x": 9,
             "spiflash_4x": 11,
         }
         self.submodules.spiflash = spi_flash.SpiFlash(
             spiflash_pads, dummy=spiflash_dummy[kwargs["spiflash"]], div=2)
         self.add_constant("SPIFLASH_PAGE_SIZE", 256)
         self.add_constant("SPIFLASH_SECTOR_SIZE", 0x10000)
         self.add_wb_slave(mem_decoder(self.mem_map["spiflash"]),
                           self.spiflash.bus)
         self.add_memory_region("spiflash",
                                self.mem_map["spiflash"] | self.shadow_base,
                                16 * 1024 * 1024)
Ejemplo n.º 2
0
    def __init__(self, platform, **kwargs):
        clk_freq = 80*1000000
        SoCSDRAM.__init__(self, platform, clk_freq,
            integrated_rom_size=0x8000,
            integrated_sram_size=0x8000,
            **kwargs)
        self.submodules.crg = _CRG(platform, clk_freq)
        self.platform.add_period_constraint(self.crg.cd_sys.clk, 1e9/clk_freq)

        self.submodules.cas = cas.ControlAndStatus(platform, clk_freq)

        self.submodules.info = info.Info(platform, "opsis", self.__class__.__name__[:8])


        self.submodules.spiflash = spi_flash.SpiFlash(
            platform.request("spiflash2x"),
            dummy=platform.spiflash_read_dummy_bits,
            div=platform.spiflash_clock_div)
        self.add_constant("SPIFLASH_PAGE_SIZE", platform.spiflash_page_size)
        self.add_constant("SPIFLASH_SECTOR_SIZE", platform.spiflash_sector_size)
        self.flash_boot_address = self.mem_map["spiflash"]+platform.gateware_size
        self.register_mem("spiflash", self.mem_map["spiflash"],
            self.spiflash.bus, size=platform.spiflash_total_size)

        # sdram
        sdram_module = AS4C16M16(self.clk_freq, "1:1")
        self.submodules.ddrphy = gensdrphy.GENSDRPHY(platform.request("sdram"))
        self.register_sdram(self.ddrphy,
                            sdram_module.geom_settings,
                            sdram_module.timing_settings)
Ejemplo n.º 3
0
    def __init__(self, platform, **kwargs):
        clk_freq = (83 + Fraction(1, 3)) * 1000 * 1000
        SoCSDRAM.__init__(self,
                          platform,
                          clk_freq,
                          integrated_rom_size=0x8000,
                          integrated_sram_size=0x4000,
                          with_uart=False,
                          **kwargs)
        self.submodules.crg = _CRG(platform, clk_freq)
        self.platform.add_period_constraint(self.crg.cd_sys.clk,
                                            1e9 / clk_freq)

        self.submodules.info = info.Info(platform, "pipi",
                                         self.__class__.__name__[:8])

        #        self.submodules.fx2_reset = gpio.GPIOOut(platform.request("fx2_reset"))
        #        self.submodules.fx2_hack = i2c_hack.I2CShiftReg(platform.request("opsis_eeprom"))

        self.submodules.suart = shared_uart.SharedUART(self.clk_freq, 115200)
        self.suart.add_uart_pads(platform.request('fx2_serial'))
        self.submodules.uart = self.suart.uart

        self.submodules.spiflash = spi_flash.SpiFlash(
            platform.request("spiflash4x"),
            dummy=platform.spiflash_read_dummy_bits,
            div=platform.spiflash_clock_div)
        self.add_constant("SPIFLASH_PAGE_SIZE", platform.spiflash_page_size)
        self.add_constant("SPIFLASH_SECTOR_SIZE",
                          platform.spiflash_sector_size)
        self.flash_boot_address = self.mem_map[
            "spiflash"] + platform.gateware_size
        self.register_mem("spiflash",
                          self.mem_map["spiflash"],
                          self.spiflash.bus,
                          size=platform.spiflash_total_size)

        # sdram
        sdram_module = MT46H32M16(self.clk_freq, "1:2")
        self.submodules.ddrphy = s6ddrphy.S6HalfRateDDRPHY(
            platform.request("ddram"),
            sdram_module.memtype,
            rd_bitslip=1,
            wr_bitslip=3,
            dqs_ddr_alignment="C1")
        controller_settings = ControllerSettings(with_bandwidth=True)
        self.register_sdram(self.ddrphy,
                            sdram_module.geom_settings,
                            sdram_module.timing_settings,
                            controller_settings=controller_settings)
        self.comb += [
            self.ddrphy.clk4x_wr_strb.eq(self.crg.clk4x_wr_strb),
            self.ddrphy.clk4x_rd_strb.eq(self.crg.clk4x_rd_strb),
        ]
Ejemplo n.º 4
0
    def __init__(self, platform, **kwargs):
        clk_freq = 75 * 1000000
        SoCSDRAM.__init__(self,
                          platform,
                          clk_freq,
                          integrated_rom_size=0x8000,
                          integrated_sram_size=0x4000,
                          with_uart=True,
                          **kwargs)
        self.submodules.crg = _CRG(platform, clk_freq)
        self.platform.add_period_constraint(self.crg.cd_sys.clk,
                                            1e9 / clk_freq)

        self.submodules.info = info.Info(platform, "atlys",
                                         self.__class__.__name__[:8])

        self.submodules.spiflash = spi_flash.SpiFlash(
            platform.request("spiflash4x"),
            dummy=platform.spiflash_read_dummy_bits,
            div=platform.spiflash_clock_div)
        self.add_constant("SPIFLASH_PAGE_SIZE", platform.spiflash_page_size)
        self.add_constant("SPIFLASH_SECTOR_SIZE",
                          platform.spiflash_sector_size)
        self.register_mem("spiflash",
                          self.mem_map["spiflash"],
                          self.spiflash.bus,
                          size=platform.spiflash_total_size)

        bios_size = 0x8000
        self.flash_boot_address = self.mem_map[
            "spiflash"] + platform.gateware_size + bios_size

        #self.submodules.cas = cas.ControlAndStatus(platform, clk_freq)

        # sdram
        sdram_module = P3R1GE4JGF(self.clk_freq, "1:2")
        self.submodules.ddrphy = s6ddrphy.S6HalfRateDDRPHY(
            platform.request("ddram"),
            sdram_module.memtype,
            rd_bitslip=0,
            wr_bitslip=4,
            dqs_ddr_alignment="C0")
        controller_settings = ControllerSettings(with_bandwidth=True)
        self.register_sdram(self.ddrphy,
                            sdram_module.geom_settings,
                            sdram_module.timing_settings,
                            controller_settings=controller_settings)
        self.comb += [
            self.ddrphy.clk4x_wr_strb.eq(self.crg.clk4x_wr_strb),
            self.ddrphy.clk4x_rd_strb.eq(self.crg.clk4x_rd_strb),
        ]
Ejemplo n.º 5
0
    def __init__(self, platform, **kwargs):

        # We need at least a serial port peripheral
        platform.add_extension(tinyfpga_bx.serial)

        sys_clk_freq = int(1e9 / platform.default_clk_period)
        SoCCore.__init__(self,
                         platform,
                         clk_freq=sys_clk_freq,
                         integrated_rom_size=0,
                         integrated_main_ram_size=0,
                         integrated_sram_size=10 * 1024,
                         cpu_reset_address=0x20050000,
                         **kwargs)

        # Configure the clock and reset generator
        self.submodules.crg = CRG(platform.request(platform.default_clk_name))

        # Configure the TinyFPGA BX SPI flash
        self.submodules.spiflash = spi_flash.SpiFlash(
            platform.request("spiflash"), dummy=8, div=2, endianness="little")
        self.config["SPIFLASH_PAGE_SIZE"] = 256
        self.config["SPIFLASH_SECTOR_SIZE"] = 0x10000

        # Map the entire SPI flash
        spiflash_total_size = int((8 / 8) * 1024 * 1024)
        self.register_mem("spiflash",
                          self.mem_map["spiflash"],
                          self.spiflash.bus,
                          size=spiflash_total_size)

        # Configure a special region for the ROM (bootloader/bios)
        self.flash_boot_address = 0x20050000 + 0x8000
        self.add_memory_region("rom", self.cpu_reset_address, 0x8000)

        # Configure a special region for our user code (firmware)
        self.add_memory_region(
            "user_flash",
            self.flash_boot_address,
            # Leave a grace area- possible one-by-off bug in add_memory_region?
            # Possible fix: addr < origin + length - 1
            spiflash_total_size -
            (self.flash_boot_address - self.mem_map["spiflash"]) - 0x100)

        # Configure the board LED
        leds = platform.request("user_led", 0)
        self.submodules.leds = GPIOOut(leds)

        # Need to specify '-s' flash isn't put into deep-sleep power down after bitstream loads
        platform.toolchain.nextpnr_build_template[
            2] = "icepack -s {build_name}.txt {build_name}.bin"
Ejemplo n.º 6
0
    def __init__(self, platform, **kwargs):
        clk_freq = 50 * 1000000

        if 'tofe_board' in kwargs:
            tofe_board_name = kwargs.get('tofe_board')
            del kwargs['tofe_board']
        else:
            tofe_board_name = None

        SoCSDRAM.__init__(self,
                          platform,
                          clk_freq,
                          integrated_rom_size=0x8000,
                          integrated_sram_size=0x4000,
                          with_uart=False,
                          **kwargs)
        self.submodules.crg = _CRG(platform, clk_freq)
        self.platform.add_period_constraint(self.crg.cd_sys.clk,
                                            1e9 / clk_freq)

        self.submodules.info = info.Info(platform, "opsis",
                                         self.__class__.__name__[:8])

        self.submodules.opsis_i2c = opsis_i2c.OpsisI2C(platform)

        self.submodules.suart = shared_uart.SharedUART(self.clk_freq, 115200)
        self.suart.add_uart_pads(platform.request('fx2_serial'))
        self.submodules.uart = self.suart.uart

        self.submodules.spiflash = spi_flash.SpiFlash(
            platform.request("spiflash4x"),
            dummy=platform.spiflash_read_dummy_bits,
            div=platform.spiflash_clock_div)
        self.add_constant("SPIFLASH_PAGE_SIZE", platform.spiflash_page_size)
        self.add_constant("SPIFLASH_SECTOR_SIZE",
                          platform.spiflash_sector_size)
        self.register_mem("spiflash",
                          self.mem_map["spiflash"],
                          self.spiflash.bus,
                          size=platform.spiflash_total_size)

        bios_size = 0x8000
        self.flash_boot_address = self.mem_map[
            "spiflash"] + platform.gateware_size + bios_size

        # front panel (ATX)
        self.submodules.front_panel = FrontPanelGPIO(platform, clk_freq)
        self.comb += self.crg.reset.eq(self.front_panel.reset)

        # sdram
        sdram_module = MT41J128M16(self.clk_freq, "1:4")
        self.submodules.ddrphy = s6ddrphy.S6QuarterRateDDRPHY(
            platform.request("ddram"),
            rd_bitslip=0,
            wr_bitslip=4,
            dqs_ddr_alignment="C0")
        controller_settings = ControllerSettings(with_bandwidth=True)
        self.register_sdram(self.ddrphy,
                            sdram_module.geom_settings,
                            sdram_module.timing_settings,
                            controller_settings=controller_settings)
        self.comb += [
            self.ddrphy.clk8x_wr_strb.eq(self.crg.clk8x_wr_strb),
            self.ddrphy.clk8x_rd_strb.eq(self.crg.clk8x_rd_strb),
        ]

        if tofe_board_name:
            if tofe_board_name == 'lowspeedio':
                self.submodules.tofe = tofe.TOFEBoard(tofe_board_name)(
                    platform, self.suart)
            else:
                self.submodules.tofe = tofe.TOFEBoard(tofe_board_name)(
                    platform)
Ejemplo n.º 7
0
    def __init__(self,
                 pnr_placer="heap",
                 pnr_seed=0,
                 debug=True,
                 boot_vector=0x20020000,
                 **kwargs):
        """Create a basic SoC for iCEBreaker.

        Create a basic SoC for iCEBreaker.  The `sys` frequency will run at 12 MHz.

        Args:
            pnr_placer (str): Which placer to use in nextpnr
            pnr_seed (int): Which seed to use in nextpnr
        Returns:
            Newly-constructed SoC
        """
        platform = Platform()

        if "cpu_type" not in kwargs:
            kwargs["cpu_type"] = None
            kwargs["cpu_variant"] = None
        else:
            kwargs["cpu_reset_address"] = boot_vector

        clk_freq = int(12e6)

        # Force the SRAM size to 0, because we add our own SRAM with SPRAM
        kwargs["integrated_sram_size"] = 0
        kwargs["integrated_rom_size"] = 0

        if debug:
            kwargs["uart_name"] = "crossover"
            if kwargs["cpu_type"] == "vexriscv":
                kwargs["cpu_variant"] = kwargs["cpu_variant"] + "+debug"

        SoCCore.__init__(self,
                         platform,
                         clk_freq,
                         with_uart=True,
                         with_ctrl=True,
                         **kwargs)

        # If there is a VexRiscv CPU, add a fake ROM that simply tells the CPU
        # to jump to the given address.
        if hasattr(self, "cpu") and self.cpu.name == "vexriscv":
            self.add_memory_region("rom", 0, 16)
            self.submodules.rom = JumpToAddressROM(16, boot_vector)

        self.submodules.crg = _CRG(platform)

        # UP5K has single port RAM, which is a dedicated 128 kilobyte block.
        # Use this as CPU RAM.
        spram_size = 128 * 1024
        self.submodules.spram = up5kspram.Up5kSPRAM(size=spram_size)
        self.register_mem("sram", self.mem_map["sram"], self.spram.bus,
                          spram_size)

        # The litex SPI module supports memory-mapped reads, as well as a bit-banged mode
        # for doing writes.
        spi_pads = platform.request("spiflash4x")
        self.submodules.lxspi = spi_flash.SpiFlash(spi_pads,
                                                   dummy=6,
                                                   endianness="little")
        self.register_mem("spiflash",
                          self.mem_map["spiflash"],
                          self.lxspi.bus,
                          size=16 * 1024 * 1024)
        self.add_csr("lxspi")

        # In debug mode, add a UART bridge.  This takes over from the normal UART bridge,
        # however you can use the "crossover" UART to communicate with this over the bridge.
        if debug:
            self.submodules.uart_bridge = UARTWishboneBridge(
                platform.request("serial"), clk_freq, baudrate=115200)
            self.add_wb_master(self.uart_bridge.wishbone)
            if hasattr(self, "cpu") and self.cpu.name == "vexriscv":
                self.register_mem("vexriscv_debug", 0xf00f0000,
                                  self.cpu.debug_bus, 0x100)

        ledsignals = Signal(2)
        self.submodules.leds = GPIOOut(ledsignals)
        self.comb += platform.request("user_ledr_n").eq(ledsignals[0])
        self.comb += platform.request("user_ledg_n").eq(ledsignals[1])
        self.add_csr("leds")

        # Override default LiteX's yosys/build templates
        assert hasattr(platform.toolchain, "yosys_template")
        assert hasattr(platform.toolchain, "build_template")
        platform.toolchain.yosys_template = [
            "{read_files}",
            "attrmap -tocase keep -imap keep=\"true\" keep=1 -imap keep=\"false\" keep=0 -remove keep=0",
            "synth_ice40 -json {build_name}.json -top {build_name}",
        ]
        platform.toolchain.build_template = [
            "yosys -q -l {build_name}.rpt {build_name}.ys",
            "nextpnr-ice40 --json {build_name}.json --pcf {build_name}.pcf --asc {build_name}.txt \
            --pre-pack {build_name}_pre_pack.py --{architecture} --package {package}",
            "icepack {build_name}.txt {build_name}.bin"
        ]

        # Add "-relut -dffe_min_ce_use 4" to the synth_ice40 command.
        # The "-reult" adds an additional LUT pass to pack more stuff in,
        # and the "-dffe_min_ce_use 4" flag prevents Yosys from generating a
        # Clock Enable signal for a LUT that has fewer than 4 flip-flops.
        # This increases density, and lets us use the FPGA more efficiently.
        platform.toolchain.yosys_template[
            2] += " -relut -abc2 -dffe_min_ce_use 4 -relut"
        # if use_dsp:
        #     platform.toolchain.yosys_template[2] += " -dsp"

        # Disable final deep-sleep power down so firmware words are loaded
        # onto softcore's address bus.
        platform.toolchain.build_template[
            2] = "icepack -s {build_name}.txt {build_name}.bin"

        # Allow us to set the nextpnr seed
        platform.toolchain.build_template[1] += " --seed " + str(pnr_seed)

        if pnr_placer is not None:
            platform.toolchain.build_template[1] += " --placer {}".format(
                pnr_placer)
Ejemplo n.º 8
0
    def __init__(self,
                 platform,
                 with_sdram_bist=True,
                 bist_async=True,
                 bist_random=True,
                 spiflash="spiflash_1x",
                 **kwargs):
        clk_freq = int(100e6)
        SoCSDRAM.__init__(self,
                          platform,
                          clk_freq,
                          integrated_rom_size=0x8000,
                          integrated_sram_size=0x8000,
                          with_uart=False,
                          **kwargs)

        self.submodules.crg = CRG(platform)
        self.submodules.dna = dna.DNA()
        self.submodules.xadc = xadc.XADC()

        uart_interfaces = [RS232PHYInterface() for i in range(2)]
        self.submodules.uart = UART(uart_interfaces[0])
        self.submodules.bridge = WishboneStreamingBridge(
            uart_interfaces[1], self.clk_freq)
        self.add_wb_master(self.bridge.wishbone)

        self.submodules.uart_phy = RS232PHY(platform.request("serial"),
                                            self.clk_freq, 115200)
        self.submodules.uart_multiplexer = UARTMultiplexer(
            uart_interfaces, self.uart_phy)
        self.comb += self.uart_multiplexer.sel.eq(
            platform.request("user_sw", 0))

        self.crg.cd_sys.clk.attr.add("keep")
        self.platform.add_period_constraint(self.crg.cd_sys.clk,
                                            period_ns(100e6))

        self.submodules.leds = led.ClassicLed(
            Cat(platform.request("user_led", i) for i in range(4)))
        self.submodules.rgb_leds = led.RGBLed(platform.request("rgb_leds"))

        # sdram
        self.submodules.ddrphy = a7ddrphy.A7DDRPHY(platform.request("ddram"))
        self.add_constant("A7DDRPHY_BITSLIP", 3)
        self.add_constant("A7DDRPHY_DELAY", 14)
        sdram_module = MT41K128M16(self.clk_freq, "1:4")
        self.register_sdram(
            self.ddrphy,
            sdram_module.geom_settings,
            sdram_module.timing_settings,
            controller_settings=ControllerSettings(cmd_buffer_depth=8))

        # sdram bist
        if with_sdram_bist:
            generator_user_port = self.sdram.crossbar.get_port(
                mode="write", cd="clk50" if bist_async else "sys")
            self.submodules.generator = LiteDRAMBISTGenerator(
                generator_user_port, random=bist_random)

            checker_user_port = self.sdram.crossbar.get_port(
                mode="read", cd="clk50" if bist_async else "sys")
            self.submodules.checker = LiteDRAMBISTChecker(checker_user_port,
                                                          random=bist_random)

        # spi flash
        spiflash_pads = platform.request(spiflash)
        spiflash_pads.clk = Signal()
        self.specials += Instance("STARTUPE2",
                                  i_CLK=0,
                                  i_GSR=0,
                                  i_GTS=0,
                                  i_KEYCLEARB=0,
                                  i_PACK=0,
                                  i_USRCCLKO=spiflash_pads.clk,
                                  i_USRCCLKTS=0,
                                  i_USRDONEO=1,
                                  i_USRDONETS=1)
        spiflash_dummy = {
            "spiflash_1x": 9,
            "spiflash_4x": 11,
        }
        self.submodules.spiflash = spi_flash.SpiFlash(
            spiflash_pads, dummy=spiflash_dummy[spiflash], div=2)
        self.add_constant("SPIFLASH_PAGE_SIZE", 256)
        self.add_constant("SPIFLASH_SECTOR_SIZE", 0x10000)
        self.add_wb_slave(mem_decoder(self.mem_map["spiflash"]),
                          self.spiflash.bus)
        self.add_memory_region("spiflash",
                               self.mem_map["spiflash"] | self.shadow_base,
                               16 * 1024 * 1024)
Ejemplo n.º 9
0
    def __init__(self, debug=True, boot_vector=0x20040000, **kwargs):
        """Create a basic SoC for iCEBreaker.

        Create a basic SoC for iCEBreaker.  The `sys` frequency will run at 12 MHz.

        Returns:
            Newly-constructed SoC
        """
        platform = Platform()

        kwargs["cpu_variant"] = "lite"
        kwargs["cpu_reset_address"] = boot_vector
        if debug:
            kwargs["uart_name"] = "crossover"
            kwargs["cpu_variant"] = "lite+debug"

        clk_freq = int(12e6)

        # Force the SRAM size to 0, because we add our own SRAM with SPRAM
        kwargs["integrated_sram_size"] = 0
        kwargs["integrated_rom_size"] = 0

        SoCCore.__init__(self, platform, clk_freq, **kwargs)

        # If there is a VexRiscv CPU, add a fake ROM that simply tells the CPU
        # to jump to the given address.
        if hasattr(self, "cpu") and self.cpu.name == "vexriscv":
            self.add_memory_region("rom", 0, 16)
            self.submodules.rom = JumpToAddressROM(16, boot_vector)

        self.submodules.crg = _CRG(platform)

        # UP5K has single port RAM, which is a dedicated 128 kilobyte block.
        # Use this as CPU RAM.
        spram_size = 128 * 1024
        self.submodules.spram = up5kspram.Up5kSPRAM(size=spram_size)
        self.register_mem("sram", self.mem_map["sram"], self.spram.bus,
                          spram_size)

        # The litex SPI module supports memory-mapped reads, as well as a bit-banged mode
        # for doing writes.
        spi_pads = platform.request("spiflash4x")
        self.submodules.lxspi = spi_flash.SpiFlash(spi_pads,
                                                   dummy=6,
                                                   endianness="little")
        self.register_mem("spiflash",
                          self.mem_map["spiflash"],
                          self.lxspi.bus,
                          size=16 * 1024 * 1024)
        self.add_csr("lxspi")

        # In debug mode, add a UART bridge.  This takes over from the normal UART bridge,
        # however you can use the "crossover" UART to communicate with this over the bridge.
        if debug:
            self.submodules.uart_bridge = UARTWishboneBridge(
                platform.request("serial"), clk_freq, baudrate=115200)
            self.add_wb_master(self.uart_bridge.wishbone)
            if hasattr(self, "cpu") and self.cpu.name == "vexriscv":
                self.register_mem("vexriscv_debug", 0xf00f0000,
                                  self.cpu.debug_bus, 0x100)

        self.submodules.leds = Leds(
            Cat(platform.request("user_ledr_n"),
                platform.request("user_ledg_n")),
            led_polarity=0x03,
            led_name=[["ledr", "The Red LED on the main iCEBreaker board."],
                      ["ledg", "The Green LED on the main iCEBreaker board."]])

        self.add_csr("leds")