Skip to content

Commit

Permalink
Merge pull request #74 from efabless/litex_integration
Browse files Browse the repository at this point in the history
Litex integration
  • Loading branch information
jeffdi authored Feb 15, 2022
2 parents ada7e4a + acb0af8 commit d64b919
Show file tree
Hide file tree
Showing 20 changed files with 267 additions and 545 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
precheck_results
precheck_results
*.hex*
*.lst
*.vcd
*.gtkw
26 changes: 18 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

CARAVEL_ROOT?=$(PWD)/caravel
PRECHECK_ROOT?=${HOME}/mpw_precheck
MCW_ROOT?=$(PWD)/mgmt_core_wrapper
SIM ?= RTL

# Install lite version of caravel, (1): caravel-lite, (0): caravel
Expand All @@ -24,11 +25,11 @@ CARAVEL_LITE?=1
ifeq ($(CARAVEL_LITE),1)
CARAVEL_NAME := caravel-lite
CARAVEL_REPO := https://github.com/efabless/caravel-lite
CARAVEL_TAG := 'mpw-5a'
CARAVEL_TAG := 'mpw-5b'
else
CARAVEL_NAME := caravel
CARAVEL_REPO := https://github.com/efabless/caravel
CARAVEL_TAG := 'mpw-5a'
CARAVEL_TAG := 'mpw-5b'
endif


Expand All @@ -53,13 +54,22 @@ PATTERNS=$(shell cd verilog/dv && find * -maxdepth 0 -type d)
DV_PATTERNS = $(foreach dv, $(PATTERNS), verify-$(dv))
TARGET_PATH=$(shell pwd)
VERIFY_COMMAND="cd ${TARGET_PATH}/verilog/dv/$* && export SIM=${SIM} && make"
$(DV_PATTERNS): verify-% : ./verilog/dv/%

.PHONY: dv_all
dv_all:$(DV_PATTERNS)

$(DV_PATTERNS): verify-% : ./verilog/dv/% check-env
docker run -v ${TARGET_PATH}:${TARGET_PATH} -v ${PDK_ROOT}:${PDK_ROOT} \
-v ${CARAVEL_ROOT}:${CARAVEL_ROOT} \
-e TARGET_PATH=${TARGET_PATH} -e PDK_ROOT=${PDK_ROOT} \
-e CARAVEL_ROOT=${CARAVEL_ROOT} \
-u $(id -u $$USER):$(id -g $$USER) efabless/dv_setup:latest \
sh -c $(VERIFY_COMMAND)
-v ${CARAVEL_ROOT}:${CARAVEL_ROOT} \
-e TARGET_PATH=${TARGET_PATH} -e PDK_ROOT=${PDK_ROOT} \
-e CARAVEL_ROOT=${CARAVEL_ROOT} \
-e TOOLS=/opt/riscv32i \
-e DESIGNS=$(TARGET_PATH) \
-e CORE_VERILOG_PATH=$(TARGET_PATH)/mgmt_core_wrapper/verilog \
-e GCC_PREFIX=riscv32-unknown-elf \
-e MCW_ROOT=$(MCW_ROOT) \
-u $$(id -u $$USER):$$(id -g $$USER) efabless/dv_setup:latest \
sh -c $(VERIFY_COMMAND)

# Openlane Makefile Targets
BLOCKS = $(shell cd openlane && find * -maxdepth 0 -type d)
Expand Down
1 change: 0 additions & 1 deletion caravel
Submodule caravel deleted from 793bf6
3 changes: 2 additions & 1 deletion docs/source/roundtrip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Complete roundtrip for caravel_user_project
git checkout -b <my_branch>
git push -u origin <my_branch>
4. Now that your git environment is setup, it's time to setup your local environment
4. Now that your git environment is setup, it's time to setup your local environment. (NOTE: docker is a prerequisite to setting up your environment)

.. code:: bash
Expand All @@ -69,6 +69,7 @@ Complete roundtrip for caravel_user_project
# Build the pdk
# make sure to change <directory_name> with the directory you created in step 1
# in this case it is caravel_tutorial
export PDK_ROOT=~/<directory_name>/pdks # you need to export this whenever you start a new shell
make pdk
Expand Down
2 changes: 2 additions & 0 deletions verilog/dv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
.SUFFIXES:
.SILENT: clean all


PATTERNS = io_ports la_test1 la_test2 wb_port mprj_stimulus

all: ${PATTERNS}

for i in ${PATTERNS}; do \
( cd $$i && make -f Makefile $${i}.vcd &> verify.log && grep Monitor verify.log) ; \
done
Expand Down
82 changes: 9 additions & 73 deletions verilog/dv/io_ports/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,83 +14,19 @@
#
# SPDX-License-Identifier: Apache-2.0

## PDK
PDK_PATH = $(PDK_ROOT)/sky130A

## Caravel Pointers
CARAVEL_ROOT ?= ../../../caravel
CARAVEL_PATH ?= $(CARAVEL_ROOT)
CARAVEL_FIRMWARE_PATH = $(CARAVEL_PATH)/verilog/dv/caravel
CARAVEL_VERILOG_PATH = $(CARAVEL_PATH)/verilog
CARAVEL_RTL_PATH = $(CARAVEL_VERILOG_PATH)/rtl
CARAVEL_BEHAVIOURAL_MODELS = $(CARAVEL_VERILOG_PATH)/dv/caravel

PWDD := $(shell pwd)
BLOCKS := $(shell basename $(PWDD))

## User Project Pointers
UPRJ_VERILOG_PATH ?= ../../../verilog
UPRJ_RTL_PATH = $(UPRJ_VERILOG_PATH)/rtl
UPRJ_BEHAVIOURAL_MODELS = ../
# ---- Include Partitioned Makefiles ----

## RISCV GCC
GCC_PATH?=/ef/apps/bin
GCC_PREFIX?=riscv32-unknown-elf
CONFIG = caravel_user_project

## Simulation mode: RTL/GL
SIM_DEFINES = -DFUNCTIONAL -DSIM
SIM?=RTL

.SUFFIXES:
include $(MCW_ROOT)/verilog/dv/make/env.makefile
include $(MCW_ROOT)/verilog/dv/make/var.makefile
include $(MCW_ROOT)/verilog/dv/make/cpu.makefile
include $(MCW_ROOT)/verilog/dv/make/sim.makefile

PATTERN = io_ports

all: ${PATTERN:=.vcd}

hex: ${PATTERN:=.hex}

%.vvp: %_tb.v %.hex
ifeq ($(SIM),RTL)
iverilog $(SIM_DEFINES) -I $(PDK_PATH) \
-I $(CARAVEL_BEHAVIOURAL_MODELS) -I $(CARAVEL_RTL_PATH) \
-I $(UPRJ_BEHAVIOURAL_MODELS) -I $(UPRJ_RTL_PATH) \
$< -o $@
else
iverilog $(SIM_DEFINES) -DGL -I $(PDK_PATH) \
-I $(CARAVEL_BEHAVIOURAL_MODELS) -I $(CARAVEL_RTL_PATH) -I $(CARAVEL_VERILOG_PATH) \
-I $(UPRJ_BEHAVIOURAL_MODELS) -I$(UPRJ_RTL_PATH) -I $(UPRJ_VERILOG_PATH) \
$< -o $@
endif

%.vcd: %.vvp
vvp $<

%.elf: %.c $(CARAVEL_FIRMWARE_PATH)/sections.lds $(CARAVEL_FIRMWARE_PATH)/start.s check-env
${GCC_PATH}/${GCC_PREFIX}-gcc -I $(CARAVEL_PATH) -march=rv32imc -mabi=ilp32 -Wl,-Bstatic,-T,$(CARAVEL_FIRMWARE_PATH)/sections.lds,--strip-debug -ffreestanding -nostdlib -o $@ $(CARAVEL_FIRMWARE_PATH)/start.s $<

%.hex: %.elf
${GCC_PATH}/${GCC_PREFIX}-objcopy -O verilog $< $@
# to fix flash base address
sed -i 's/@10000000/@00000000/g' $@

%.bin: %.elf
${GCC_PATH}/${GCC_PREFIX}-objcopy -O binary $< /dev/stdout | tail -c +1048577 > $@

check-env:
ifndef PDK_ROOT
$(error PDK_ROOT is undefined, please export it before running make)
endif
ifeq (,$(wildcard $(PDK_ROOT)/sky130A))
$(error $(PDK_ROOT)/sky130A not found, please install pdk before running make)
endif
ifeq (,$(wildcard $(GCC_PATH)/$(GCC_PREFIX)-gcc ))
$(error $(GCC_PATH)/$(GCC_PREFIX)-gcc is not found, please export GCC_PATH and GCC_PREFIX before running make)
endif
# check for efabless style installation
ifeq (,$(wildcard $(PDK_ROOT)/sky130A/libs.ref/*/verilog))
SIM_DEFINES := ${SIM_DEFINES} -DEF_STYLE
endif

# ---- Clean ----

clean:
rm -f *.elf *.hex *.bin *.vvp *.vcd *.log

.PHONY: clean hex all
10 changes: 7 additions & 3 deletions verilog/dv/io_ports/io_ports.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

// This include is relative to $CARAVEL_PATH (see Makefile)
#include "verilog/dv/caravel/defs.h"
#include "verilog/dv/caravel/stub.c"
#include <defs.h>
#include <stub.c>

/*
IO Test:
Expand Down Expand Up @@ -46,7 +46,11 @@ void main()
/* Set up the housekeeping SPI to be connected internally so */
/* that external pin changes don't affect it. */

reg_spimaster_config = 0xa002; // Enable, prescaler = 2,
// reg_spi_enable = 1;
// reg_spimaster_cs = 0x10001;
// reg_spimaster_control = 0x0801;

// reg_spimaster_control = 0xa002; // Enable, prescaler = 2,
// connect to housekeeping SPI

// Connect the housekeeping SPI to the SPI master
Expand Down
66 changes: 36 additions & 30 deletions verilog/dv/io_ports/io_ports_tb.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

`timescale 1 ns / 1 ps

`include "uprj_netlists.v"
`include "caravel_netlists.v"
`include "spiflash.v"
// `include "uprj_netlists.v"
// `include "caravel_netlists.v"
// `include "spiflash.v"

module io_ports_tb;
reg clock;
Expand All @@ -28,15 +28,15 @@ module io_ports_tb;
reg power1, power2;
reg power3, power4;

wire gpio;
wire [37:0] mprj_io;
wire gpio;
wire [37:0] mprj_io;
wire [7:0] mprj_io_0;

assign mprj_io_0 = mprj_io[7:0];
// assign mprj_io_0 = {mprj_io[8:4],mprj_io[2:0]};

assign mprj_io[3] = (CSB == 1'b1) ? 1'b1 : 1'bz;
// assign mprj_io[3] = 1'b1;
// assign mprj_io[3] = (CSB == 1'b1) ? 1'b1 : 1'bz;
// assign mprj_io[3] = CSB;

// External clock is used by default. Make this artificially fast for the
// simulation. Normally this would be a slow clock and the digital PLL
Expand Down Expand Up @@ -69,18 +69,18 @@ module io_ports_tb;

initial begin
// Observe Output pins [7:0]
wait(mprj_io_0 == 8'h01);
wait(mprj_io_0 == 8'h02);
wait(mprj_io_0 == 8'h03);
wait(mprj_io_0 == 8'h04);
wait(mprj_io_0 == 8'h05);
wait(mprj_io_0 == 8'h06);
wait(mprj_io_0 == 8'h07);
wait(mprj_io_0 == 8'h08);
wait(mprj_io_0 == 8'h09);
wait(mprj_io_0 == 8'h0A);
wait(mprj_io_0 == 8'hFF);
wait(mprj_io_0 == 8'h00);
wait(mprj_io_0 == 8'h01);
wait(mprj_io_0 == 8'h02);
wait(mprj_io_0 == 8'h03);
wait(mprj_io_0 == 8'h04);
wait(mprj_io_0 == 8'h05);
wait(mprj_io_0 == 8'h06);
wait(mprj_io_0 == 8'h07);
wait(mprj_io_0 == 8'h08);
wait(mprj_io_0 == 8'h09);
wait(mprj_io_0 == 8'h0A);
wait(mprj_io_0 == 8'hFF);
wait(mprj_io_0 == 8'h00);

`ifdef GL
$display("Monitor: Test 1 Mega-Project IO (GL) Passed");
Expand Down Expand Up @@ -123,30 +123,36 @@ module io_ports_tb;
wire flash_io0;
wire flash_io1;

wire VDD3V3 = power1;
wire VDD1V8 = power2;
wire USER_VDD3V3 = power3;
wire USER_VDD1V8 = power4;
wire VSS = 1'b0;
wire VDD3V3;
wire VDD1V8;
wire VSS;

assign VDD3V3 = power1;
assign VDD1V8 = power2;
assign VSS = 1'b0;

caravel uut (
.vddio (VDD3V3),
.vddio_2 (VDD3V3),
.vssio (VSS),
.vssio_2 (VSS),
.vdda (VDD3V3),
.vssa (VSS),
.vccd (VDD1V8),
.vssd (VSS),
.vdda1 (USER_VDD3V3),
.vdda2 (USER_VDD3V3),
.vdda1 (VDD3V3),
.vdda1_2 (VDD3V3),
.vdda2 (VDD3V3),
.vssa1 (VSS),
.vssa1_2 (VSS),
.vssa2 (VSS),
.vccd1 (USER_VDD1V8),
.vccd2 (USER_VDD1V8),
.vccd1 (VDD1V8),
.vccd2 (VDD1V8),
.vssd1 (VSS),
.vssd2 (VSS),
.clock (clock),
.clock (clock),
.gpio (gpio),
.mprj_io (mprj_io),
.mprj_io (mprj_io),
.flash_csb(flash_csb),
.flash_clk(flash_clk),
.flash_io0(flash_io0),
Expand Down
Loading

0 comments on commit d64b919

Please sign in to comment.