tools: add litex_jtag_uart to create a virtual uart for the jtag uart.
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 25 May 2020 08:21:06 +0000 (10:21 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 25 May 2020 08:21:06 +0000 (10:21 +0200)
litex/build/openocd.py
litex/tools/litex_jtag_uart.py [new file with mode: 0755]

index d3680d60990fc6aff8d657711ebb3df8f287d154..392f16a6bc9818045f690b8eeda8fcd599c625e3 100644 (file)
@@ -85,9 +85,9 @@ proc jtagstream_drain {tap tx chunk_rx max_rx} {
         lassign [jtagstream_poll $tap "" $chunk_rx] rxi readable writable
         append rx $rxi
     }
-    if {!$writable} {
-        echo "write overflow"
-    }
+    #if {!$writable} {
+    #    echo "write overflow"
+    #}
     return $rx
 }
 
@@ -140,4 +140,5 @@ proc jtagstream_serve {tap port} {
             "jtagstream_serve $_CHIPNAME.tap {:d}".format(port),
             "exit",
         ])
-        subprocess.call(["openocd", "-f", self.config, "-f", "stream.cfg", "-c", script])
+        config = self.find_config()
+        subprocess.call(["openocd", "-f", config, "-f", "stream.cfg", "-c", script])
diff --git a/litex/tools/litex_jtag_uart.py b/litex/tools/litex_jtag_uart.py
new file mode 100755 (executable)
index 0000000..715a5ef
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env python3
+
+# This file is Copyright (c) 2020 Florent Kermarrec <florent@enjoy-digital.fr>
+# License: BSD
+
+# Proof of Concept to use the JTAG UART with lxterm.
+
+import os
+import pty
+import threading
+import telnetlib
+import time
+
+from litex.build.openocd import OpenOCD
+
+telnet_port = 20000
+
+def openocd_jtag_telnet():
+       prog = OpenOCD("openocd_xc7_ft2232.cfg")
+       prog.stream(telnet_port)
+
+m, s = pty.openpty()
+print("LiteX JTAG UART created: {}".format(os.ttyname(s)))
+
+openocd_jtag_telnet_thread = threading.Thread(target=openocd_jtag_telnet)
+openocd_jtag_telnet_thread.start()
+
+time.sleep(1)
+
+t = telnetlib.Telnet("localhost", telnet_port)
+
+def pty2telnet(m):
+    while True:
+        r = os.read(m, 1)
+        t.write(r)
+        if r == bytes("\n".encode("utf-8")):
+               t.write("\r".encode("utf-8"))
+        t.write("\n".encode("utf-8"))
+
+def telnet2pty(m):
+       while True:
+               r = t.read_some()
+               os.write(m, bytes(r))
+
+pty2telnet_thread = threading.Thread(target=pty2telnet, args=[m])
+pty2telnet_thread.start()
+
+telnet2pty(m)