-
Notifications
You must be signed in to change notification settings - Fork 36
/
usbserial_tbx.v
77 lines (57 loc) · 1.63 KB
/
usbserial_tbx.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
USB Serial
Wrapping usb/usb_uart_ice40.v to create a loopback.
*/
module usbserial_tbx (
input pin_clk,
inout pin_usb_p,
inout pin_usb_n,
output pin_pu,
output pin_led,
output [3:0] debug
);
wire clk_48mhz;
wire clk_locked;
// Use an icepll generated pll
pll pll48( .clock_in(pin_clk), .clock_out(clk_48mhz), .locked( clk_locked ) );
// LED
reg [22:0] ledCounter;
always @(posedge clk_48mhz) begin
ledCounter <= ledCounter + 1;
end
assign pin_led = ledCounter[ 22 ];
// Generate reset signal
reg [5:0] reset_cnt = 0;
wire reset = ~reset_cnt[5];
always @(posedge clk_48mhz)
if ( clk_locked )
reset_cnt <= reset_cnt + reset;
// uart pipeline in
wire [7:0] uart_in_data;
wire uart_in_valid;
wire uart_in_ready;
// assign debug = { uart_in_valid, uart_in_ready, reset, clk_48mhz };
wire usb_p_tx;
wire usb_n_tx;
wire usb_p_rx;
wire usb_n_rx;
wire usb_tx_en;
// usb uart - this instanciates the entire USB device.
usb_uart uart (
.clk_48mhz (clk_48mhz),
.reset (reset),
// pins
.pin_usb_p( pin_usb_p ),
.pin_usb_n( pin_usb_n ),
// uart pipeline in
.uart_in_data( uart_in_data ),
.uart_in_valid( uart_in_valid ),
.uart_in_ready( uart_in_ready ),
.uart_out_data( uart_in_data ),
.uart_out_valid( uart_in_valid ),
.uart_out_ready( uart_in_ready )
//.debug( debug )
);
// USB Host Detect Pull Up
assign pin_pu = 1'b1;
endmodule