From 8742a10a3d22eb1b9792b3d69f8710601000cd31 Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 2 May 2022 10:26:36 -0400 Subject: [PATCH] Add UART test code --- Makefile | 22 ++++++++++++++++++++++ build/.gitignore | 4 ++++ io.pcf | 25 +++++++++++++++++++++++++ top.v | 28 ++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 Makefile create mode 100644 build/.gitignore create mode 100644 io.pcf create mode 100644 top.v diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e064253 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +buildpath = build/ +filename = uart_test +files = top.v +pcf_file = io.pcf + +.PHONY: build prog prog_flash clean + +build: + #yosys -p "synth_ice40 -blif $(buildpath)$(filename).blif -top top" $(files) + #arachne-pnr -r -d 5k -P sg48 -p $(pcf_file) $(buildpath)$(filename).blif -o $(buildpath)$(filename).asc + yosys -p "synth_ice40 -json $(buildpath)$(filename).json -top top" $(files) + nextpnr-ice40 --up5k --json $(buildpath)$(filename).json --pcf $(pcf_file) --asc $(buildpath)$(filename).asc + icepack $(buildpath)$(filename).asc $(buildpath)$(filename).bin + +prog: build #for sram + iceprog -S $(buildpath)$(filename).bin + +prog_flash: build + iceprog $(buildpath)$(filename).bin + +clean: + rm -rf $(buildpath)/* \ No newline at end of file diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..b7aad7a --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,4 @@ +# ignore everything here +* +# let the gitignore stay +!.gitignore \ No newline at end of file diff --git a/io.pcf b/io.pcf new file mode 100644 index 0000000..319c3df --- /dev/null +++ b/io.pcf @@ -0,0 +1,25 @@ +# 12 MHz clock +set_io clk 35 + +# RS232 +set_io ser_rx 26 +set_io ser_tx 27 + +# SPI Flash +set_io flash_clk 15 +set_io flash_csb 16 +set_io flash_io0 14 +set_io flash_io1 17 +#set_io flash_io2 12 +#set_io flash_io3 13 + +# LEDs (PMOD 2) +set_io led1 39 +set_io led2 40 +set_io led3 41 +set_io led4 23 +set_io led5 25 + +# Onboard LEDs +set_io ledr_n 11 +set_io ledg_n 37 \ No newline at end of file diff --git a/top.v b/top.v new file mode 100644 index 0000000..ffbd7c9 --- /dev/null +++ b/top.v @@ -0,0 +1,28 @@ +// Simple test of the UART pins and clock, no CPU needed + +module top(input clk, output ser_tx, input ser_rx); + //assign ser_tx = test_chars; // uncomment for a bunch of ASCII "U" characters + assign ser_tx = ser_rx; // uncomment first for serial echo + + wire serclk; + reg test_chars; + + clkdiv clock_generator (clk, serclk); + + always @(posedge serclk) begin + test_chars = !test_chars; + end +endmodule + +module clkdiv(input clock_in, output reg clock_out); + reg[15:0] counter=16'd0; + parameter DIVISOR = 16'd104; //set according to desired baudrate for test characters (e.g. 12,000,000 Hz / 115200 baud ~= clock divider 104) + + always @(posedge clock_in) begin + counter <= counter + 16'd1; + if(counter>=(DIVISOR-1)) + counter <= 16'd0; + + clock_out <= (counter