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 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 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 d999de4..16b9faf 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 ); //////////////////////////////////////////////////////////////////////////////// @@ -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) @@ -344,6 +348,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 +359,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..26d0802 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, @@ -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;