{"id":1374,"date":"2020-03-04T23:19:07","date_gmt":"2020-03-04T23:19:07","guid":{"rendered":"http:\/\/retroramblings.net\/?p=1374"},"modified":"2020-03-04T23:19:07","modified_gmt":"2020-03-04T23:19:07","slug":"when-is-a-uart-not-a-uart","status":"publish","type":"post","link":"https:\/\/retroramblings.net\/?p=1374","title":{"rendered":"When is a UART not a UART?"},"content":{"rendered":"\n<p><strong>Tunneling debugging information over JTAG &#8211; 2020-03-04<\/strong><\/p>\n\n\n\n<p>One of my primary platforms for FPGA tinkering is the Turbo Chameleon 64 cartridge &#8211; which comes in two flavours: the original V1 hardware which features a Cyclone III FPGA and the V2 hardware which has a very similar Cyclone 10LP FPGA (basically the same thing in a newer package).<\/p>\n\n\n\n<p>While this cartridge is intended as an expansion for the venerable Commodore 64 8-bit computer from the 1980s, it can nonetheless run other more general-purpose cores, so most of my projects have Chameleon64 targets.  The one downside of this hardware is the lack of general purpose IOs.  It has no built-in serial port, and nowhere really convenient to attach a USB-serial dongle either.  It&#8217;s possible to misuse the IEC port for this purpose, but then I need to remember to disable it before distributing a finished core (I doubt a 1541 disk drive would appreciate having RS232 data spewed at it).  There&#8217;s also a USB debugging protocol built into the cartridge, which I haven&#8217;t yet explored &#8211; mostly because so many of my projects can be built for multiple platforms, I&#8217;m reluctant to put a large amount of effort into supporting features only available on one of them.<\/p>\n\n\n\n<p>I discovered the other day, however, that it&#8217;s possible to tunnel a UART-style connection over JTAG. <\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Since I always use the trusty USB Blaster (either external or built in the board) to upload designs while developing, I was keen to explore this.<\/p>\n\n\n\n<p>Unfortunately, it appears that the low level interface in question is completely undocumented &#8211; it&#8217;s clear that it&#8217;s intended to be used only with the higher-level NIOS2 and QSYS.<\/p>\n\n\n\n<p>Luckily the internet came to the rescue, and with the help of some example code I found in a forum, I now have a VHDL module which acts as a drop-in replacement for the simple_uart module I&#8217;ve been using so far.  This will be in the RTL\/Peripherals directory of my EightThirtyTwoDemos repo.<\/p>\n\n\n\n<p>The undocumented interface itself looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">component alt_jtag_atlantic is<br>  generic (<br>    INSTANCE_ID : integer;<br>    LOG2_RXFIFO_DEPTH : integer;<br>    LOG2_TXFIFO_DEPTH : integer;<br>    SLD_AUTO_INSTANCE_INDEX : string<br>  );<br>  port (<br>    clk : in std_logic;<br>    rst_n : in std_logic;<br>    r_dat : in std_logic_vector(7 downto 0); -- data from FPGA<br>    r_val : in std_logic; -- data valid<br>    r_ena : out std_logic; -- can accept data<br>    t_dat : out std_logic_vector(7 downto 0); -- data to FPGA<br>    t_dav : in std_logic; -- ready to receive more data<br>    t_ena : out std_logic; -- tx data valid<br>    t_pause : out std_logic -- ???<br>  );<br>  end component alt_jtag_atlantic<\/pre>\n\n\n\n<p>This component creates a virtual JTAG node which the nios2-terminal program (part of the Quartus distribution) can talk to.  You can still use signaltap while it&#8217;s connected, but it&#8217;s necessary to break the connection in order to reprogram the FPGA &#8211; for obvious reasons.<\/p>\n\n\n\n<p>I&#8217;ve plumbed in the alt_jtag_atlantic component based on these signal descriptions, but I&#8217;m not 100% sure they&#8217;re fully correct, because while it works correctly on every platform I&#8217;ve tested on so far (DE2, DE10Lite, Chameleon64, Chameleon64v2 and a cheap EBay Cyclone IV board) on all but the Chameleon64 v1 the link is significantly slower than I expected.  On the Chameleon V1, however, it&#8217;s the same speed or faster than actual RS232 @ 115,200 baud.  I&#8217;m not yet sure why.  I believe there are further generics related to the FIFOs, but I don&#8217;t know what they&#8217;re called, so can&#8217;t yet experiment with them!<\/p>\n\n\n\n<p>It&#8217;s also possible to write custom software to talk to the virtual JTAG node.  Again, the interface for doing this (libjtag_atlantic) is undocumented, but again the internet comes to the rescue &#8211; in this case via a downloadable archive in a random forum thread<a href=\"https:\/\/forums.intel.com\/s\/question\/0D50P00003yyHbuSAE\/de1-board-to-pc-communication?language=en_US\"> which can be found here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tunneling debugging information over JTAG &#8211; 2020-03-04 One of my primary platforms for FPGA tinkering is the Turbo Chameleon 64 cartridge &#8211; which comes in two flavours: the original V1 hardware which features a Cyclone III FPGA and the V2 &hellip; <a href=\"https:\/\/retroramblings.net\/?p=1374\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8],"tags":[],"class_list":["post-1374","post","type-post","status-publish","format-standard","hentry","category-fpga","category-hardware"],"_links":{"self":[{"href":"https:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/1374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1374"}],"version-history":[{"count":2,"href":"https:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/1374\/revisions"}],"predecessor-version":[{"id":1376,"href":"https:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/1374\/revisions\/1376"}],"wp:attachment":[{"href":"https:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}