From 31347a54ac571ded6177b68e24aa2d0c2f2cab28 Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Tue, 3 Nov 2020 22:01:29 +0100 Subject: incorporate SPI module into main design --- design/pins.pcf | 9 ++-- design/soc.v | 37 +++++++++++-- models/soc_with_peripherals.v | 111 ++++++++++++++++++++++++++++++++++++++ tests/soc_simple_display/Makefile | 3 +- tests/soc_simple_display/test.v | 64 ++++------------------ 5 files changed, 159 insertions(+), 65 deletions(-) create mode 100644 models/soc_with_peripherals.v diff --git a/design/pins.pcf b/design/pins.pcf index fabcd9c..7786c27 100644 --- a/design/pins.pcf +++ b/design/pins.pcf @@ -58,8 +58,7 @@ set_io sram_cs_n T6 set_io sram_oe_n L9 set_io sram_we_n T7 -# SPI to on-board chip -#set_io sdo P12 -#set_io sdi P11 -#set_io sck R11 -#set_io ss_n R12 +set_io spi_sdo P12 +set_io spi_sdi P11 +set_io spi_sck R11 +set_io spi_ss_n R12 diff --git a/design/soc.v b/design/soc.v index d4a5962..c7312f3 100644 --- a/design/soc.v +++ b/design/soc.v @@ -13,7 +13,12 @@ * h100A00 - h100A01 - VGA power-on register * h100A02 - h100FFF - undefined (actually, repetitions of VGA power-on reg) * h101000 - h17FFFF - undefined (actually, repetitions of VGA memory) - * h180000 - h1FFFFF - read as 0, write as don't care + * h180000 - h1801FF - SPI data transfer memory + * h180200 - h180201 - SPI bytes_to_output reg + * h180202 - h180203 - SPI bytes_to_receive reg + * h180204 - h180207 - SPI operating reg + * h180208 - h1803FF - undefined (actually, repetitions of SPI regs) + * h180400 - h1FFFFF - undefined (actually, repetitions of SPI memory) */ `default_nettype none @@ -43,6 +48,11 @@ module soc output wire [2:0] vga_green, output wire [2:0] vga_blue, + output wire spi_sdo, + input wire spi_sdi, + output wire spi_sck, + output wire spi_ss_n, + input wire button1, input wire button2, @@ -168,10 +178,27 @@ module soc .blue(vga_blue) ); - /* Slave 3 will be SPI controller, but for now - it's omitted */ - assign S3_ACK_O = 1; - assign S3_DAT_O = 0; - assign S3_STALL_O = 0; + spi_slave + #( + .MEMORY_BLOCKS(1) + ) slave3 + ( + .ACK_O(S3_ACK_O), + .CLK_I(CLK), + .ADR_I(S3_ADR_I[8:0]), + .DAT_I(S3_DAT_I), + .DAT_O(S3_DAT_O), + .RST_I(RST), + .STB_I(S3_STB_I), + .WE_I(S3_WE_I), + .STALL_O(S3_STALL_O), + + /* Non-wishbone */ + .sdo(spi_sdo), + .sdi(spi_sdi), + .sck(spi_sck), + .ss_n(spi_ss_n) + ); intercon intercon ( diff --git a/models/soc_with_peripherals.v b/models/soc_with_peripherals.v new file mode 100644 index 0000000..975c002 --- /dev/null +++ b/models/soc_with_peripherals.v @@ -0,0 +1,111 @@ +`default_nettype none + +`include "messages.vh" + +`ifndef SIMULATION + `error_SIMULATION_not_defined +; /* Cause syntax error */ +`endif + +module soc_with_peripherals + #( + parameter FONT_FILE = "../design/font.mem", + parameter EMBEDDED_ROM_FILE = "../design/rom.mem", + parameter SPI_ROM_WORDS_COUNT = 0, + parameter SPI_ROM_FILE = "/dev/zero" + ) + ( + input wire clock_100mhz, + + input wire button1, + input wire button2, + + output wire led1, + output wire led2, + + output wire [9:0] image_writes + ); + + wire [17:0] sram_addr; + wire [15:0] sram_io; + wire sram_cs_n; + wire sram_oe_n; + wire sram_we_n; + + wire vga_hs; + wire vga_vs; + wire [2:0] vga_red; + wire [2:0] vga_green; + wire [2:0] vga_blue; + + wire spi_sdo; + wire spi_sdi; + wire spi_sck; + wire spi_ss_n; + + W25Q16BV_flash + #( + .BYTES_TO_INITIALIZE(SPI_ROM_WORDS_COUNT * 2), + .INITIAL_CONTENTS_FILE(SPI_ROM_FILE) + ) flash + ( + .sdo(spi_sdo), + .sdi(spi_sdi), + .sck(spi_sck), + .ss_n(spi_ss_n) + ); + + VGA_640_480_60Hz vga_display + ( + .horizontal_sync(vga_hs), + .vertical_sync(vga_vs), + + .red(vga_red), + .green(vga_green), + .blue(vga_blue), + + .image_writes(image_writes) + ); + + K6R4016V1D_TC10_sram sram + ( + .sram_addr(sram_addr), + .sram_io(sram_io), + .sram_cs_not(sram_cs_n), + .sram_oe_not(sram_oe_n), + .sram_we_not(sram_we_n) + ); + + soc + #( + .FONT_FILE(FONT_FILE), + .ROM_FILE(EMBEDDED_ROM_FILE) + ) soc + ( + .clock_100mhz(clock_100mhz), + + .sram_addr(sram_addr), + .sram_io(sram_io), + + .sram_cs_n(sram_cs_n), + .sram_oe_n(sram_oe_n), + .sram_we_n(sram_we_n), + + .vga_hs(vga_hs), + .vga_vs(vga_vs), + .vga_red(vga_red), + .vga_green(vga_green), + .vga_blue(vga_blue), + + .spi_sdo(spi_sdo), + .spi_sdi(spi_sdi), + .spi_sck(spi_sck), + .spi_ss_n(spi_ss_n), + + .button1(button1), + .button2(button2), + + .led1(led1), + .led2(led2) + ); +endmodule // soc_with_peripherals diff --git a/tests/soc_simple_display/Makefile b/tests/soc_simple_display/Makefile index 4506ff7..06bced1 100644 --- a/tests/soc_simple_display/Makefile +++ b/tests/soc_simple_display/Makefile @@ -1,6 +1,7 @@ VGA_TEST = 1 -DEPENDS = instructions.mem sram.v vga_display.v ../../design/*.v messages.vh +DEPENDS = instructions.mem sram.v vga_display.v flash_memory.v \ + soc_with_peripherals.v ../../design/*.v messages.vh IVFLAGS = -DROM_WORDS_COUNT=$(call FILE_LINES,instructions.mem) diff --git a/tests/soc_simple_display/test.v b/tests/soc_simple_display/test.v index de05ff0..75c2b36 100644 --- a/tests/soc_simple_display/test.v +++ b/tests/soc_simple_display/test.v @@ -9,74 +9,30 @@ `endif module soc_test(); - wire [17:0] sram_addr; - wire [15:0] sram_io; - wire sram_cs_n; - wire sram_oe_n; - wire sram_we_n; - - wire vga_hs; - wire vga_vs; - wire [2:0] vga_red; - wire [2:0] vga_green; - wire [2:0] vga_blue; - - wire led1; - wire led2; - wire [9:0] image_writes; - reg clock_100mhz; - reg reset; - - VGA_640_480_60Hz vga_display - ( - .horizontal_sync(vga_hs), - .vertical_sync(vga_vs), - - .red(vga_red), - .green(vga_green), - .blue(vga_blue), + reg clock_100mhz; + reg reset; - .image_writes(image_writes) - ); + wire led1; + wire led2; - K6R4016V1D_TC10_sram sram - ( - .sram_addr(sram_addr), - .sram_io(sram_io), - .sram_cs_not(sram_cs_n), - .sram_oe_not(sram_oe_n), - .sram_we_not(sram_we_n) - ); - - soc + soc_with_peripherals #( .FONT_FILE("../../design/font.mem"), - .ROM_FILE("instructions.mem") + .EMBEDDED_ROM_FILE("instructions.mem") ) soc ( .clock_100mhz(clock_100mhz), - .sram_addr(sram_addr), - .sram_io(sram_io), - - .sram_cs_n(sram_cs_n), - .sram_oe_n(sram_oe_n), - .sram_we_n(sram_we_n), - - .vga_hs(vga_hs), - .vga_vs(vga_vs), - .vga_red(vga_red), - .vga_green(vga_green), - .vga_blue(vga_blue), - .button1(!reset), .button2(1'b1), .led1(led1), - .led2(led2) - ); + .led2(led2), + + .image_writes(image_writes) + ); integer i; -- cgit v1.2.3