#MEMORY_SIZE=393216
#RAM_INIT_FILE=micropython/firmware.hex
+# Linux
+#MEMORY_SIZE=16777216 # 268435456
+#RAM_INIT_FILE=dtbImage.microwatt.hex
+SIM_MAIN_BRAM=true
+
FPGA_TARGET ?= ORANGE-CRAB
# OrangeCrab with ECP85
endif
GHDL_IMAGE_GENERICS=-gMEMORY_SIZE=$(MEMORY_SIZE) -gRAM_INIT_FILE=$(RAM_INIT_FILE) \
- -gRESET_LOW=$(RESET_LOW) -gCLK_INPUT=$(CLK_INPUT) -gCLK_FREQUENCY=$(CLK_FREQUENCY)
+ -gRESET_LOW=$(RESET_LOW) -gCLK_INPUT=$(CLK_INPUT) -gCLK_FREQUENCY=$(CLK_FREQUENCY) \
+ -gSIM_MAIN_BRAM=$(SIM_MAIN_BRAM)
+
clkgen=fpga/clk_gen_ecp5.vhd
toplevel=fpga/top-generic.vhdl
clkgen=fpga/clk_gen_bypass.vhd
endif
+FPGA_MAIN_BRAM=fpga/main_bram.vhdl
+#FPGA_MAIN_BRAM=
+
fpga_files = $(core_files) $(soc_files) fpga/soc_reset.vhdl \
- fpga/pp_fifo.vhd fpga/pp_soc_uart.vhd fpga/main_bram.vhdl \
+ fpga/pp_fifo.vhd fpga/pp_soc_uart.vhd $(FPGA_MAIN_BRAM) \
nonrandom.vhdl
synth_files = $(core_files) $(soc_files) $(fpga_files) $(clkgen) $(toplevel) $(dmi_dtm)
# Need to investigate why yosys is hitting verilator warnings, and eventually turn on -Wall
microwatt-verilator: microwatt.v verilator/microwatt-verilator.cpp verilator/uart-verilator.c
- verilator -O3 -CFLAGS "-DCLK_FREQUENCY=$(CLK_FREQUENCY)" --assert --cc microwatt.v --exe verilator/microwatt-verilator.cpp verilator/uart-verilator.c -o $@ -Iuart16550 -Wno-fatal -Wno-CASEOVERLAP -Wno-UNOPTFLAT #--trace
+ verilator -O3 -CFLAGS "-DCLK_FREQUENCY=$(CLK_FREQUENCY)" --assert --cc microwatt.v --exe verilator/microwatt-verilator.cpp verilator/uart-verilator.c -o $@ -Iuart16550 -Wno-fatal -Wno-CASEOVERLAP -Wno-UNOPTFLAT --trace
make -C obj_dir -f Vmicrowatt.mk
@cp -f obj_dir/microwatt-verilator microwatt-verilator
library work;
use work.wishbone_types.all;
+use work.utils.all;
entity toplevel is
generic (
MEMORY_SIZE : positive := (384*1024);
RAM_INIT_FILE : string := "firmware.hex";
RESET_LOW : boolean := true;
+ SIM_MAIN_BRAM : boolean := false;
CLK_INPUT : positive := 100000000;
CLK_FREQUENCY : positive := 100000000;
HAS_FPU : boolean := true;
-- UART0 signals:
uart0_txd : out std_ulogic;
- uart0_rxd : in std_ulogic
+ uart0_rxd : in std_ulogic;
+
+ -- BRAM verilator access
+ bram_we : out std_ulogic;
+ bram_re : out std_ulogic;
+ bram_addr : out std_logic_vector(log2ceil(MEMORY_SIZE) - 3- 1 downto 0);
+ bram_di : inout std_logic_vector(63 downto 0);
+ bram_do : out std_logic_vector(63 downto 0);
+ bram_sel : out std_logic_vector(7 downto 0)
);
end entity toplevel;
soc0: entity work.soc
generic map(
MEMORY_SIZE => MEMORY_SIZE,
+ SIM_MAIN_BRAM => SIM_MAIN_BRAM,
RAM_INIT_FILE => RAM_INIT_FILE,
SIM => false,
CLK_FREQ => CLK_FREQUENCY,
system_clk => system_clk,
rst => soc_rst,
uart0_txd => uart0_txd,
- uart0_rxd => uart0_rxd
+ uart0_rxd => uart0_rxd,
+ bram_we => bram_we,
+ bram_re => bram_re,
+ bram_addr => bram_addr,
+ bram_di => bram_di,
+ bram_do => bram_do,
+ bram_sel => bram_sel
);
end architecture behaviour;
library work;
use work.common.all;
+use work.utils.all;
use work.wishbone_types.all;
HAS_BTC : boolean := true;
DISABLE_FLATTEN_CORE : boolean := false;
HAS_DRAM : boolean := false;
+ SIM_MAIN_BRAM : boolean := false;
DRAM_SIZE : integer := 0;
DRAM_INIT_SIZE : integer := 0;
HAS_SPI_FLASH : boolean := false;
-- External interrupts
ext_irq_eth : in std_ulogic := '0';
+ -- BRAM verilator access
+ bram_we : out std_ulogic;
+ bram_re : out std_ulogic;
+ bram_addr : out std_logic_vector(log2ceil(MEMORY_SIZE) - 3- 1 downto 0);
+ bram_di : inout std_logic_vector(63 downto 0);
+ bram_do : out std_logic_vector(63 downto 0);
+ bram_sel : out std_logic_vector(7 downto 0);
+
-- UART0 signals:
uart0_txd : out std_ulogic;
uart0_rxd : in std_ulogic := '0';
bram0: entity work.wishbone_bram_wrapper
generic map(
MEMORY_SIZE => MEMORY_SIZE,
- RAM_INIT_FILE => RAM_INIT_FILE
+ RAM_INIT_FILE => RAM_INIT_FILE,
+ SIM_MAIN_BRAM => SIM_MAIN_BRAM
)
port map(
clk => system_clk,
rst => rst_bram,
wishbone_in => wb_bram_in,
- wishbone_out => wb_bram_out
+ wishbone_out => wb_bram_out,
+ bram_we => bram_we,
+ bram_re => bram_re,
+ bram_addr => bram_addr,
+ bram_di => bram_di,
+ bram_do => bram_do,
+ bram_sel => bram_sel
);
end generate;
#include <stdlib.h>
+#include <stdio.h>
#include "Vmicrowatt.h"
#include "verilated.h"
#include "verilated_vcd_c.h"
uart_tx(top->uart0_txd);
top->uart0_rxd = uart_rx();
+ if (top->bram_we) {
+ printf("bram wr addr %x dout %x sel %x\n",
+ top->bram_addr, top->bram_di, top->bram_sel);
+ }
+ if (top->bram_re) {
+ printf("bram rd addr %x din %x sel %x\n",
+ top->bram_addr, top->bram_do, top->bram_sel);
+ }
}
#if VM_TRACE
entity wishbone_bram_wrapper is
generic(
MEMORY_SIZE : natural := 4096; --! Memory size in bytes.
- RAM_INIT_FILE : string
+ RAM_INIT_FILE : string;
+ SIM_MAIN_BRAM : boolean := false
);
port(
clk : in std_logic;
-- Wishbone interface:
wishbone_in : in wishbone_master_out;
- wishbone_out : out wishbone_slave_out
+ wishbone_out : out wishbone_slave_out;
+
+ -- BRAM verilator access
+ bram_we : out std_ulogic;
+ bram_re : out std_ulogic;
+ bram_addr : out std_logic_vector(log2ceil(MEMORY_SIZE) - 3- 1 downto 0);
+ bram_di : inout std_logic_vector(63 downto 0);
+ bram_do : out std_logic_vector(63 downto 0);
+ bram_sel : out std_logic_vector(7 downto 0)
+
);
end entity wishbone_bram_wrapper;
begin
-- Actual RAM template
- ram_0: entity work.main_bram
- generic map(
- WIDTH => 64,
- HEIGHT_BITS => ram_addr_bits,
- MEMORY_SIZE => MEMORY_SIZE,
- RAM_INIT_FILE => RAM_INIT_FILE
- )
- port map(
- clk => clk,
- addr => ram_addr,
- di => wishbone_in.dat,
- do => wishbone_out.dat,
- sel => wishbone_in.sel,
- re => ram_re,
- we => ram_we
- );
+ sim_ram: if SIM_MAIN_BRAM = true generate
+ ram_0: entity work.main_bram
+ generic map(
+ WIDTH => 64,
+ HEIGHT_BITS => ram_addr_bits,
+ MEMORY_SIZE => MEMORY_SIZE,
+ RAM_INIT_FILE => RAM_INIT_FILE
+ )
+ port map(
+ clk => clk,
+ addr => ram_addr,
+ di => wishbone_in.dat,
+ do => wishbone_out.dat,
+ sel => wishbone_in.sel,
+ re => ram_re,
+ we => ram_we
+ );
+ end generate;
+
+ -- Verilator access to bram signals
+ bram_sel <= wishbone_in.sel;
+ bram_do <= wishbone_out.dat;
+ bram_di <= wishbone_in.dat;
+ bram_addr <= ram_addr;
+ bram_we <= ram_we;
+ bram_re <= ram_re;
-- Wishbone interface
ram_addr <= wishbone_in.adr(ram_addr_bits + 2 downto 3);