Skip to content

Commit

Permalink
Merge pull request #38 from wpmed92/fix-uart-tx
Browse files Browse the repository at this point in the history
Fix uart tx
  • Loading branch information
wpmed92 authored Jan 2, 2023
2 parents 20fc80a + 99a080b commit 72e7cdd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion chip/rtl/mem.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module mem
//--------------------------------------------------------------------------
parameter NUM_COL = 4,
parameter COL_WIDTH = 8,
parameter ADDR_WIDTH = 15,
parameter ADDR_WIDTH = 14,
// Addr Width in bits : 2 *ADDR_WIDTH = RAM Depth
parameter DATA_WIDTH = NUM_COL*COL_WIDTH // Data Width in bits
//----------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions chip/rtl/mmio.v
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module mmio(
output uart_rxd_out,
input [3:0] sw
);
wire en_bram = (address >= 0) && (address < 'h8000);
wire en_bram = (address >= 0) && (address < 'h32000);
wire en_gpio = (address >= 'h32000);
wire [31:0] _bram_out;
wire [31:0] _gpio_out;
Expand Down Expand Up @@ -72,14 +72,14 @@ module mmio(
.clkA(clk),
.enaA(1'd1),
.weA(4'd0),
.addrA(pc[16:2]),
.addrA(pc[15:2]),
.dinA(32'd0),
.doutA(instr_out),
//Port B is for memory
.clkB(clk),
.enaB(en_bram),
.weB(weB_calc),
.addrB(address[16:2]),
.addrB(address[15:2]),
.dinB(data_in_calc),
.doutB(_bram_out)
);
Expand Down
4 changes: 4 additions & 0 deletions chip/rtl/uart_tx.v
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ always @(posedge clk) begin
tx_counter <= 0;
_tx_ready <= 1;
end
end else begin
_uart_rxd_out <= 1;
tx_counter <= 0;
_tx_ready <= 0;
end
end else begin
uart_tick <= uart_tick + 1;
Expand Down
16 changes: 16 additions & 0 deletions tools/listen2d2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import serial

with serial.Serial("/dev/tty.usbserial-210319B4A2F21", baudrate=9600, parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS, timeout=1000) as ser:
s = ser.read(1)
out = ""

while (True):
out += s.decode("utf-8")
if (s == b'\n'):
print(out)
out = ""

s = ser.read(1)

11 changes: 6 additions & 5 deletions tools/talk2d2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ def send_exe(path):

# First 4 bytes are size of the exe
print("Len=" + str(len(exe_bytes)))
exe_bytes.insert(0, len(exe_bytes))
exe_bytes.insert(1, 0)
exe_bytes.insert(2, 0)
exe_bytes.insert(3, 0)
len_exe = len(exe_bytes)
exe_bytes.insert(0, len_exe & 0xFF)
exe_bytes.insert(1, (len_exe >> 8) & 0xFF)
exe_bytes.insert(2, (len_exe >> 16) & 0xFF)
exe_bytes.insert(3, (len_exe >> 24) & 0xFF)

ser.write(exe_bytes)

time.sleep(2)
time.sleep(200)

if __name__ == "__main__":
args = parser.parse_args()
Expand Down

0 comments on commit 72e7cdd

Please sign in to comment.