From af173431f61796ac61f4095624bd0c5778e217a9 Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Sun, 2 Sep 2018 15:41:43 +0200 Subject: [PATCH 1/4] boards/TinyFPGA_BX: Don't rely on tristate inference This doesn't work in recent yosys/{arachnepnr,nextpnr}, so manually instantiate SB_IO Signed-off-by: Sylvain Munaut --- boards/TinyFPGA_BX/bootloader.v | 44 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/boards/TinyFPGA_BX/bootloader.v b/boards/TinyFPGA_BX/bootloader.v index 89e3f2b..bf7a601 100644 --- a/boards/TinyFPGA_BX/bootloader.v +++ b/boards/TinyFPGA_BX/bootloader.v @@ -79,6 +79,8 @@ module bootloader ( wire usb_n_tx; wire usb_p_rx; wire usb_n_rx; + wire usb_p_rx_io; + wire usb_n_rx_io; wire usb_tx_en; tinyfpga_bootloader tinyfpga_bootloader_inst ( @@ -98,10 +100,44 @@ module bootloader ( ); assign pin_pu = 1'b1; - assign pin_usbp = usb_tx_en ? usb_p_tx : 1'bz; - assign pin_usbn = usb_tx_en ? usb_n_tx : 1'bz; - assign usb_p_rx = usb_tx_en ? 1'b1 : pin_usbp; - assign usb_n_rx = usb_tx_en ? 1'b0 : pin_usbn; + assign usb_p_rx = usb_tx_en ? 1'b1 : usb_p_rx_io; + assign usb_n_rx = usb_tx_en ? 1'b0 : usb_n_rx_io; + + SB_IO #( + .PIN_TYPE(6'b101001), + .PULLUP(1'b0), + .NEG_TRIGGER(1'b0), + .IO_STANDARD("SB_LVCMOS") + ) io_dp_I ( + .PACKAGE_PIN(pin_usbp), + .LATCH_INPUT_VALUE(1'b0), + .CLOCK_ENABLE(1'b1), + .INPUT_CLK(1'b0), + .OUTPUT_CLK(1'b0), + .OUTPUT_ENABLE(usb_tx_en), + .D_OUT_0(usb_p_tx), + .D_OUT_1(1'b0), + .D_IN_0(usb_p_rx_io), + .D_IN_1() + ); + + SB_IO #( + .PIN_TYPE(6'b101001), + .PULLUP(1'b0), + .NEG_TRIGGER(1'b0), + .IO_STANDARD("SB_LVCMOS") + ) io_dn_I ( + .PACKAGE_PIN(pin_usbn), + .LATCH_INPUT_VALUE(1'b0), + .CLOCK_ENABLE(1'b1), + .INPUT_CLK(1'b0), + .OUTPUT_CLK(1'b0), + .OUTPUT_ENABLE(usb_tx_en), + .D_OUT_0(usb_n_tx), + .D_OUT_1(1'b0), + .D_IN_0(usb_n_rx_io), + .D_IN_1() + ); assign reset = 1'b0; endmodule From 09f170360d70c17520bba0398a8010abbb5dd83f Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Sun, 2 Sep 2018 15:42:14 +0200 Subject: [PATCH 2/4] common/serial: Fix syntax error Signed-off-by: Sylvain Munaut --- common/serial.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/serial.v b/common/serial.v index 360d204..b776c70 100644 --- a/common/serial.v +++ b/common/serial.v @@ -11,7 +11,7 @@ module width_adapter #( output data_out_put, input data_out_free, - output [OUTPUT_WIDTH-1:0] data_out, + output [OUTPUT_WIDTH-1:0] data_out ); generate From a3f7a71c20be242dc4b199b18d77050d2a712097 Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Sun, 2 Sep 2018 15:44:02 +0200 Subject: [PATCH 3/4] common: Make sure RAM inference works with yosys icecube doesn't care about init values, but yosys does and you can't satisfy them with HW RAM module. So here we remove all the init values and we make sure the reads are not dependent on the reset line Signed-off-by: Sylvain Munaut --- common/usb_fs_in_pe.v | 7 ++++--- common/usb_fs_out_pe.v | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common/usb_fs_in_pe.v b/common/usb_fs_in_pe.v index d999de4..da64b84 100644 --- a/common/usb_fs_in_pe.v +++ b/common/usb_fs_in_pe.v @@ -51,7 +51,7 @@ module usb_fs_in_pe #( // Data payload to send if any output tx_data_avail, input tx_data_get, - output reg [7:0] tx_data = 0 + output reg [7:0] tx_data ); //////////////////////////////////////////////////////////////////////////////// @@ -344,6 +344,9 @@ module usb_fs_in_pe #( endcase end + always @(posedge clk) + tx_data <= in_data_buffer[buffer_get_addr]; + integer j; always @(posedge clk) begin if (reset) begin @@ -352,8 +355,6 @@ module usb_fs_in_pe #( end else begin in_xfr_state <= in_xfr_state_next; - tx_data <= in_data_buffer[buffer_get_addr]; - if (setup_token_received) begin data_toggle[rx_endp] <= 1; end diff --git a/common/usb_fs_out_pe.v b/common/usb_fs_out_pe.v index 2e43be5..c9307af 100644 --- a/common/usb_fs_out_pe.v +++ b/common/usb_fs_out_pe.v @@ -14,7 +14,7 @@ module usb_fs_out_pe #( output [NUM_OUT_EPS-1:0] out_ep_data_avail, output reg [NUM_OUT_EPS-1:0] out_ep_setup = 0, input [NUM_OUT_EPS-1:0] out_ep_data_get, - output reg [7:0] out_ep_data = 0, + output reg [7:0] out_ep_data, input [NUM_OUT_EPS-1:0] out_ep_stall, output reg [NUM_OUT_EPS-1:0] out_ep_acked = 0, From 96d5c72f87fe336593fa90e1e9f9610d8bb34b02 Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Sun, 2 Sep 2018 15:46:17 +0200 Subject: [PATCH 4/4] common: Make sure to always assign all 'reg's in processes to avoid latches If you don't assign all 'reg's in a process, this effectively describes a latch, and the HW doesn't have any HW latches which leads yosys to create a logic loop, which is definitely not good in FPGA ! Signed-off-by: Sylvain Munaut --- common/usb_fs_in_arb.v | 6 ++---- common/usb_fs_in_pe.v | 4 ++++ common/usb_fs_out_pe.v | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/common/usb_fs_in_arb.v b/common/usb_fs_in_arb.v index a331406..186a272 100644 --- a/common/usb_fs_in_arb.v +++ b/common/usb_fs_in_arb.v @@ -20,6 +20,8 @@ module usb_fs_in_arb #( always @* begin grant = 0; + arb_in_ep_data <= 0; + for (i = 0; i < NUM_IN_EPS; i = i + 1) begin in_ep_grant[i] <= 0; @@ -29,9 +31,5 @@ module usb_fs_in_arb #( grant = 1; end end - - if (!grant) begin - arb_in_ep_data <= 0; - end end endmodule diff --git a/common/usb_fs_in_pe.v b/common/usb_fs_in_pe.v index da64b84..16b9faf 100644 --- a/common/usb_fs_in_pe.v +++ b/common/usb_fs_in_pe.v @@ -166,6 +166,8 @@ module usb_fs_in_pe #( always @* begin in_ep_acked[ep_num] <= 0; + ep_state_next[ep_num] <= ep_state[ep_num]; + if (in_ep_stall[ep_num]) begin ep_state_next[ep_num] <= STALL; @@ -277,9 +279,11 @@ module usb_fs_in_pe #( reg rollback_in_xfr; always @* begin + in_xfr_state_next <= in_xfr_state; in_xfr_start <= 0; in_xfr_end <= 0; tx_pkt_start <= 0; + tx_pid <= 4'b0000; rollback_in_xfr <= 0; case (in_xfr_state) diff --git a/common/usb_fs_out_pe.v b/common/usb_fs_out_pe.v index c9307af..26d0802 100644 --- a/common/usb_fs_out_pe.v +++ b/common/usb_fs_out_pe.v @@ -154,6 +154,8 @@ module usb_fs_out_pe #( for (ep_num = 0; ep_num < NUM_OUT_EPS; ep_num = ep_num + 1) begin always @* begin + ep_state_next[ep_num] <= ep_state[ep_num]; + if (out_ep_stall[ep_num]) begin ep_state_next[ep_num] <= STALL; @@ -272,7 +274,9 @@ module usb_fs_out_pe #( //////////////////////////////////////////////////////////////////////////////// always @* begin + out_ep_acked <= 0; out_xfr_start <= 0; + out_xfr_state_next <= out_xfr_state; tx_pkt_start <= 0; tx_pid <= 0; new_pkt_end <= 0;