Skip to content

Commit

Permalink
fpga: Start working on SPI driver
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilKoe committed Jul 28, 2023
1 parent 103bdf2 commit 04b39fe
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 52 deletions.
5 changes: 4 additions & 1 deletion cheshire.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ BENDER ?= bender
VLOG_ARGS ?= -suppress 2583 -suppress 13314
VSIM ?= vsim

# Define board for FPGA flow and/or device tree selection
BOARD ?= vcu128

# Define used paths (prefixed to avoid name conflicts)
CHS_ROOT ?= $(shell $(BENDER) path cheshire)
CHS_REG_DIR := $(shell $(BENDER) path register_interface)
Expand Down Expand Up @@ -55,7 +58,7 @@ chs-clean-deps:
######################

CHS_NONFREE_REMOTE ?= [email protected]:pulp-restricted/cheshire-nonfree.git
CHS_NONFREE_COMMIT ?= b11f9e5fbc97209da75e77c93a1e4e0460dddf6c
CHS_NONFREE_COMMIT ?= a1a4efa289fe67cd28f0056fb2030aee5edd3ad2

chs-nonfree-init:
git clone $(CHS_NONFREE_REMOTE) $(CHS_ROOT)/nonfree
Expand Down
12 changes: 4 additions & 8 deletions sw/boot/cheshire.dts → sw/boot/cheshire.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
// Axel Vanoni <[email protected]>

/dts-v1/;

/ {
#address-cells = <2>;
#size-cells = <2>;
compatible = "eth,cheshire-dev";
model = "eth,cheshire";

chosen {
stdout-path = "/soc/serial@3002000:115200";
};
Expand Down Expand Up @@ -74,22 +76,16 @@
interrupts = <2 3 4 5 6 7 8 9 10 11 12 13 14 15 16>;
reg = <0x0 0x3003000 0x0 0x1000>;
};
spi@3004000 {
spi: spi@3004000 {
compatible = "opentitan,spi-host", "lowrisc,spi";
interrupt-parent = <&PLIC0>;
interrupts = <17 18>;
reg = <0x0 0x3004000 0x0 0x1000>;
num-cs = <2>;
clock-frequency = <50000000>;
max-frequency = <25000000>;
#address-cells = <1>;
#size-cells = <0>;
mmc@0 {
compatible = "mmc-spi-slot";
reg = <0>;
spi-max-frequency = <25000000>;
voltage-ranges = <3300 3300>;
disable-wp;
};
};
vga@3007000 {
compatible = "eth,axi-vga";
Expand Down
17 changes: 17 additions & 0 deletions sw/boot/cheshire_genesys2.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2022 ETH Zurich and University of Bologna.
// Solderpad Hardware License, Version 0.51, see LICENSE for details.
// SPDX-License-Identifier: SHL-0.51
//
// Cyril Koenig <[email protected]>

#include "sw/boot/cheshire.dtsi"

&spi {
mmc@0 {
compatible = "mmc-spi-slot";
reg = <0>; // CS
spi-max-frequency = <25000000>;
voltage-ranges = <3300 3300>;
disable-wp;
};
};
25 changes: 25 additions & 0 deletions sw/boot/cheshire_vcu128.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2022 ETH Zurich and University of Bologna.
// Solderpad Hardware License, Version 0.51, see LICENSE for details.
// SPDX-License-Identifier: SHL-0.51
//
// Cyril Koenig <[email protected]>

/include/ "cheshire.dtsi"

&spi {
nor@1 {
#address-cells = <0x1>;
#size-cells = <0x1>;
// Note : u-boot does not find mt25qu02g
compatible = "mt25qu02g", "jedec,spi-nor";
reg = <0x1>; // CS
spi-max-frequency = <25000000>;
spi-rx-bus-width = <0x1>;
spi-tx-bus-width = <0x1>;
partition@0 {
label = "all";
reg = <0x0 0x6000000>; // 96 MB
read-only;
};
};
};
4 changes: 2 additions & 2 deletions sw/sw.mk
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ $(foreach link,$(patsubst $(CHS_SW_LD_DIR)/%.ld,%,$(wildcard $(CHS_SW_LD_DIR)/*.
$(CHS_SW_OBJCOPY) -O binary $< $@

%.dtb: %.dts
$(CHS_SW_DTC) -I dts -O dtb -o $@ $<
$(CHS_SW_DTC) -I dts -O dtb -i $(CHS_SW_DIR)/boot -o $@ $<

%.memh: %.elf
$(CHS_SW_OBJCOPY) -O verilog $< $@
Expand All @@ -138,7 +138,7 @@ $(foreach link,$(patsubst $(CHS_SW_LD_DIR)/%.ld,%,$(wildcard $(CHS_SW_LD_DIR)/*.
$(CHS_SW_OBJCOPY) -I binary -O verilog $< $@

# Create full Linux disk image
$(CHS_SW_DIR)/boot/linux.gpt.bin: $(CHS_SW_DIR)/boot/zsl.rom.bin $(CHS_SW_DIR)/boot/cheshire.dtb $(CHS_SW_DIR)/boot/install64/fw_payload.bin $(CHS_SW_DIR)/boot/install64/uImage
$(CHS_SW_DIR)/boot/linux.gpt.bin: $(CHS_SW_DIR)/boot/zsl.rom.bin $(CHS_SW_DIR)/boot/cheshire_$(BOARD).dtb $(CHS_SW_DIR)/boot/install64/fw_payload.bin $(CHS_SW_DIR)/boot/install64/uImage
truncate -s $(CHS_SW_DISK_SIZE) $@
sgdisk --clear -g --set-alignment=1 \
--new=1:64:96 --typecode=1:$(CHS_SW_ZSL_TGUID) \
Expand Down
7 changes: 6 additions & 1 deletion target/xilinx/scripts/run.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ if ($DEBUG) {
write_debug_probes -force probes.ltx
}

# Incremental implementation
if {[info exists $::env(ROUTED_DCP)] && [file exists $::env(ROUTED_DCP)]} {
set_property incremental_checkpoint $ $::env(ROUTED_DCP) [get_runs impl_1]
}

# Implementation
launch_runs impl_1
wait_on_run impl_1
Expand All @@ -112,7 +117,7 @@ if {[info exists ::env(CHECK_TIMING)] && $::env(CHECK_TIMING)==1} {
# Output Verilog netlist + SDC for timing simulation
write_verilog -force -mode funcsim out/${project}_funcsim.v
write_verilog -force -mode timesim out/${project}_timesim.v
write_sdf -force out/${project}_timesim.sdf
# write_sdf -force out/${project}_timesim.sdf

# Reports
exec mkdir -p reports/
Expand Down
61 changes: 26 additions & 35 deletions target/xilinx/src/cheshire_top_xilinx.sv
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ module cheshire_top_xilinx
`endif

`ifdef USE_SD
input logic sd_cd_i,
output logic sd_cmd_o,
inout wire [3:0] sd_d_io,
output logic sd_reset_o,
output logic sd_sclk_o,
(* mark_debug = "true" *) input logic sd_cd_i,
(* mark_debug = "true" *) output logic sd_cmd_o,
(* mark_debug = "true" *) inout wire [3:0] sd_d_io,
(* mark_debug = "true" *) output logic sd_reset_o,
(* mark_debug = "true" *) output logic sd_sclk_o,
`endif

`ifdef USE_FAN
Expand All @@ -62,12 +62,7 @@ module cheshire_top_xilinx

`ifdef USE_QSPI
`ifndef USE_STARTUPE3
output logic qspi_clk,
input logic qspi_dq0,
input logic qspi_dq1,
input logic qspi_dq2,
input logic qspi_dq3,
output logic qspi_cs_b,
// TODO: off-chip qspi interface
`endif // USE_STARTUPE3
`endif // USE_QSPI

Expand Down Expand Up @@ -361,17 +356,15 @@ module cheshire_top_xilinx
// SPI Adaption //
//////////////////

logic spi_sck_soc;
logic [1:0] spi_cs_soc;
logic [3:0] spi_sd_soc_out;
logic [3:0] spi_sd_soc_in;
(* mark_debug = "true" *) logic spi_sck_soc;
(* mark_debug = "true" *) logic [1:0] spi_cs_soc;
(* mark_debug = "true" *) logic [3:0] spi_sd_soc_out;
(* mark_debug = "true" *) logic [3:0] spi_sd_soc_in;

(* mark_debug = "true" *) logic spi_sck_en;
(* mark_debug = "true" *) logic [1:0] spi_cs_en;
(* mark_debug = "true" *) logic [3:0] spi_sd_en;

logic spi_sck_en;
logic [1:0] spi_cs_en;
logic [3:0] spi_sd_en;
logic spi_sck_en_n;
logic [1:0] spi_cs_en_n;
logic [3:0] spi_sd_en_n;

//////////////////
// SD //
Expand Down Expand Up @@ -401,24 +394,24 @@ module cheshire_top_xilinx
//////////////////

`ifdef USE_QSPI
logic qspi_clk;
logic qspi_clk_ts;
logic [3:0] qspi_dqi;
logic [3:0] qspi_dqo_ts;
logic [3:0] qspi_dqo;
logic [SpihNumCs-1:0] qspi_cs_b;
logic [SpihNumCs-1:0] qspi_cs_b_ts;
(* mark_debug = "true" *) logic qspi_clk;
(* mark_debug = "true" *) logic qspi_clk_ts;
(* mark_debug = "true" *) logic [3:0] qspi_dqi;
(* mark_debug = "true" *) logic [3:0] qspi_dqo_ts;
(* mark_debug = "true" *) logic [3:0] qspi_dqo;
(* mark_debug = "true" *) logic [SpihNumCs-1:0] qspi_cs_b;
(* mark_debug = "true" *) logic [SpihNumCs-1:0] qspi_cs_b_ts;

assign qspi_clk = spi_sck_soc;
assign qspi_cs_b = spi_cs_soc;
assign qspi_dqo = spi_sd_soc_out;
assign spi_sd_soc_in = qspi_dqi;
// Tristate - Enable
assign qspi_clk_ts = ~(spi_sck_en);
assign qspi_cs_b_ts = ~(spi_cs_en);
assign qspi_dqo_ts = ~(spi_sd_en);
assign qspi_clk_ts = ~spi_sck_en;
assign qspi_cs_b_ts = ~spi_cs_en;
assign qspi_dqo_ts = ~spi_sd_en;

// On VCU128, SPI ports are not directly available
// On VCU128/ZCU102, SPI ports are not directly available
`ifdef USE_STARTUPE3
STARTUPE3 #(
.PROG_USR("FALSE"),
Expand All @@ -444,9 +437,7 @@ module cheshire_top_xilinx
.USRDONETS (1'b1)
);
`else
assign qspi_clk_o = qspi_clk;
assign qspi_dqi = qspi_dq_i;
assign qspi_cs_b_o = qspi_cs_b;
// TODO: off-chip qspi interface
`endif // USE_STARTUPE3

`endif // USE_QSPI
Expand Down
4 changes: 2 additions & 2 deletions target/xilinx/src/dram_wrapper.sv
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ module dram_wrapper #(
`DDR3_INTF
`endif
// Dram axi interface
(* mark_debug = "true" *) input axi_soc_req_t soc_req_i,
(* mark_debug = "true" *) output axi_soc_resp_t soc_rsp_o
input axi_soc_req_t soc_req_i,
output axi_soc_resp_t soc_rsp_o
);

////////////////////////////////////
Expand Down
11 changes: 8 additions & 3 deletions target/xilinx/xilinx.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ CHS_XIL_DIR ?= $(CHS_ROOT)/target/xilinx
VIVADO ?= vitis-2020.2 vivado

PROJECT ?= cheshire
BOARD ?= vcu128
ip-dir := $(CHS_XIL_DIR)/xilinx

# Select board specific variables
Expand All @@ -32,6 +31,9 @@ ifeq ($(BOARD),zcu102)
XILINX_PART ?= xczu9eg-ffvb1156-2-e
XILINX_BOARD ?= xilinx.com:zcu102:part0:3.4
ips-names := xlnx_mig_ddr4 xlnx_clk_wiz xlnx_vio
ifeq ($(INT_JTAG),1)
xilinx_targs += -t bscane
endif
endif

# Location of ip outputs
Expand All @@ -55,7 +57,9 @@ VIVADOENV ?= PROJECT=$(PROJECT) \
HOST=$(XILINX_HOST) \
FPGA_PATH=$(FPGA_PATH) \
BIT=$(bit) \
IP_PATHS="$(foreach ip-name,$(ips-names),xilinx/$(ip-name)/$(ip-name).srcs/sources_1/ip/$(ip-name)/$(ip-name).xci)"
IP_PATHS="$(foreach ip-name,$(ips-names),xilinx/$(ip-name)/$(ip-name).srcs/sources_1/ip/$(ip-name)/$(ip-name).xci)" \
ROUTED_DCP=$(ROUTED_DCP) \
CHECK_TIMING=$(CHECK_TIMING)

MODE ?= gui
VIVADOFLAGS ?= -nojournal -mode $(MODE)
Expand All @@ -72,6 +76,7 @@ $(bit): $(ips) $(CHS_XIL_DIR)/scripts/add_sources.tcl
cd $(CHS_XIL_DIR) && $(VIVADOENV) $(VIVADO) $(VIVADOFLAGS) -source scripts/prologue.tcl -source scripts/run.tcl
cp $(CHS_XIL_DIR)/$(PROJECT).runs/impl_1/*.bit $(out)
cp $(CHS_XIL_DIR)/$(PROJECT).runs/impl_1/*.ltx $(out)
cp $(CHS_XIL_DIR)/$(PROJECT).runs/impl_1/*.dcp $(out)

# Generate ips
%.xci:
Expand Down Expand Up @@ -105,4 +110,4 @@ chs-xil-flash: $(CHS_SW_DIR)/boot/linux.gpt.bin
$(CHS_XIL_DIR)/scripts/add_sources.tcl: Bender.yml
$(BENDER) script vivado $(xilinx_targs) > $@

.PHONY: chs-xil-gui chs-xil-program chs-xil-clean chs-xil-rebuild-top chs-xil-all
.PHONY: chs-xil-gui chs-xil-program chs-xil-clean chs-xil-rebuild-top chs-xil-all

0 comments on commit 04b39fe

Please sign in to comment.