<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MakeStuff</title>
	<atom:link href="http://www.makestuff.eu/wordpress/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.makestuff.eu/wordpress</link>
	<description>Make stuff, not war!</description>
	<lastBuildDate>Thu, 26 Aug 2010 22:12:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>New Version of Fx2tools</title>
		<link>http://www.makestuff.eu/wordpress/?p=959</link>
		<comments>http://www.makestuff.eu/wordpress/?p=959#comments</comments>
		<pubDate>Fri, 20 Aug 2010 09:55:10 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.makestuff.eu/wordpress/?p=959</guid>
		<description><![CDATA[<p>Recently I updated Fx2tools. Now you can: Upload SDCC-generated HEX records directly to an FX2LP chip's RAM and EEPROM Backup &#38; restore EEPROM (e.g firmware for Digilent's FX2-based FPGA development products) Send arbitrary commands to the chip's control endpoint Benchmark bulk writes to the FX2LP chip I have successfully tested it with My home-made FX2 [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>Recently I updated <a href="http://www.makestuff.eu/wordpress/?page_id=343">Fx2tools</a>. Now you can:</p>

<ul class="twikilist">
<li>Upload SDCC-generated HEX records <strong>directly</strong> to an FX2LP chip's RAM and EEPROM</li>
<li>Backup &amp; restore EEPROM (e.g firmware for Digilent's FX2-based FPGA development products)</li>
<li>Send arbitrary commands to the chip's control endpoint</li>
<li>Benchmark bulk writes to the FX2LP chip</li>
</ul>

<p>I have successfully tested it with</p>

<ul class="twikilist">
<li>My home-made <a href="http://www.makestuff.eu/wordpress/?page_id=446">FX2 board</a></li>
<li>The Digilent <a href="http://www.digilentinc.com/Products/Detail.cfm?Prod=NEXYS2">Nexys2</a> FPGA devkit</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.makestuff.eu/wordpress/?feed=rss2&amp;p=959</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UMDKv2 Prototype Works!</title>
		<link>http://www.makestuff.eu/wordpress/?p=936</link>
		<comments>http://www.makestuff.eu/wordpress/?p=936#comments</comments>
		<pubDate>Sun, 18 Jul 2010 23:05:23 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.makestuff.eu/wordpress/?p=936</guid>
		<description><![CDATA[<p>The Nexys2-based prototype of the forthcoming redesign of my USB MegaDrive DevKit seems to work! There is a custom PCB which plugs into the MegaDrive cartridge slot, and the Nexys2 FPGA board plugs into that, and draws its power from the MegaDrive. The custom PCB is pretty simple, it contains three 16-bit level converters for [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.digilentinc.com/Products/Detail.cfm?Prod=NEXYS2">Nexys2</a>-based prototype of the forthcoming redesign of my <a href="http://www.makestuff.eu/wordpress/?p=915">USB MegaDrive DevKit</a> seems to work!</p>

<p><img src="http://www.swaton.ukfsn.org/uploads/2010/07/umdkv2b.jpg" alt="" title="" width="925" height="641" class="aligncenter size-full wp-image-937" /></p>

<p>There is a custom PCB  which plugs into the MegaDrive cartridge slot, and the <a href="http://www.digilentinc.com/Products/Detail.cfm?Prod=NEXYS2">Nexys2</a> FPGA board plugs into that, and draws its power from the MegaDrive. The custom PCB is pretty simple, it contains three 16-bit level converters for converting the MegaDrive's 5V signals to the 3.3V signals needed by the FPGA. Despite being simple, it was pretty difficult to make because it has 0.5mm-pitch chips <a href="http://www.makestuff.eu/wordpress/?p=877">placed over vias</a>.</p>

<p>The game loads over <a href="http://en.wikipedia.org/wiki/Hi-Speed_USB#Signaling" onmouseover="return overlib('USB 2.0 added a 480 Mbit/s mode, usually called Hi-Speed, to distinguish it from the 12 Mbit/s of Full-Speed.');" onmouseout="return nd();">Hi-Speed USB</a> into the <a href="http://www.digilentinc.com/Products/Detail.cfm?Prod=NEXYS2">Nexys2's</a> onboard <a href="http://download.micron.com/pdf/datasheets/psram/128mb_burst_cr1_5_p26z.pdf">CellularRAM</a> whilst the MegaDrive is held in RESET. When the MegaDrive is released from RESET, the bus is taken from the USB controller and given to the MegaDrive, which begins executing the code.</p>

<p>One interesting problem I've noticed is that the sampled "Sega" song ditty at the start of <a href="http://en.wikipedia.org/wiki/Sonic_the_Hedgehog_(video_game)">Sonic the Hedgehog</a> is corrupt - it comes out as white noise. My guess is that the samples are being read directly from the cartridge memory by the Z80 somehow, and during those cycles the 68000's !AS line (which my memory controller uses to time its state transitions) is not strobing, so the Z80 is reading garbage samples. This is just a guess though, I need to do further investigation.</p>

<p><b>Update:</b> My theory was correct. The Z80 read cycles don't seem to strobe !AS like 68000 read cycles do. I eliminated !AS from the memory controller logic and now it works fine.</p>

<p>The VHDL needs a lot of tidying, and I need to implement the bus arbitration logic to allow USB and MegaDrive memory reads and writes to be interleaved seamlessly by the memory controller, and then I need to work on a DMA controller for doing efficient reads from an SD-card.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makestuff.eu/wordpress/?feed=rss2&amp;p=936</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Work Starts on USB MegaDrive DevKit v2 (UMDKv2)</title>
		<link>http://www.makestuff.eu/wordpress/?p=915</link>
		<comments>http://www.makestuff.eu/wordpress/?p=915#comments</comments>
		<pubDate>Sun, 11 Jul 2010 14:37:29 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.makestuff.eu/wordpress/?p=915</guid>
		<description><![CDATA[<p>It has been a long time since I put any thought into version 2 of my USB MegaDrive DevKit. I'm currently putting together a prototype based on a Digilent Nexys2 FPGA board. So far I have managed to: Power the Nexys2 from the MegaDrive's 5V supply. Buffer the MegaDrive's 7.6MHz clock using this board. Verify [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>It has been a long time since I put any thought into version 2 of my <a href="/wordpress/?page_id=398">USB MegaDrive DevKit</a>. I'm currently putting together a prototype based on a <a href="http://www.digilentinc.com/Products/Detail.cfm?Prod=NEXYS2">Digilent Nexys2</a> FPGA board. So far I have managed to:</p>

<ul class="twikilist">
<li>Power the Nexys2 from the MegaDrive's 5V supply.</li>
<li>Buffer the MegaDrive's 7.6MHz clock using <a href="/wordpress/?p=877">this board</a>.</li>
<li>Verify that the MegaDrive's clock is actually running at the expected rate (0x73F9XX ~ 7.6004MHz).</li>
<li>Use one of the <a href="http://www.xilinx.com/itp/xilinx7/books/data/docs/s3edl/s3edl0021_13.html">Digital Clock Managers</a> on the FPGA to multiply the 7.6MHz clock by 14 to give 106.4MHz.</li>
<li>Use this 106.4MHz to clock a memory controller state machine, running the on-board <a href="http://download.micron.com/pdf/datasheets/psram/128mb_burst_cr1_5_p26z.pdf">CellularRAM</a> at half that frequency.</li>
<li>Fix up the <a href="http://www.digilentinc.com/Data/Software/Adept/dpimref.vhd">host interface reference design</a> to eliminate the need to force FSM encoding.</li>
<li>Benchmark block writes using <a href="http://www.digilentinc.com/Products/Detail.cfm?Prod=ADEPT">the Adept tool</a> over USB to the CellularRAM at 3.94Mbyte/s.</li>
<li>Use a transistor switch to give the FPGA control of the MegaDrive's RESET line.</li>
</ul>

<p><img src="http://www.swaton.ukfsn.org/uploads/2010/07/umdkv2a.jpg" alt="" title="" width="925" height="661" class="aligncenter size-full wp-image-918" /></p>

<p align="center"><i>This 0x73F9 is the top 16 bits of a 24-bit counter giving MegaDrive clocks per second: 0x73F9XX ~ 7.6004MHz</i></p>

<p>Still to do on this prototype:</p>

<ul class="twikilist">
<li>Build a MegaDrive cartridge PCB with an <a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?WT.z_header=search_go&amp;lang=en&amp;site=uk&amp;keywords=H10536-ND&amp;x=0&amp;y=0">FX2-100S-1.27SV(71)</a> edge connector for interfacing with the Nexys2.</li>
<li>Implement the 68000 bus reads and writes in the VHDL.</li>
<li>Build the SD-card interface PCB and write the VHDL for a DMA controller clocking the SD card in <a href="http://en.wikipedia.org/wiki/Secure_Digital#Transfer_modes">SPI mode</a> at ~25MHz.</li>
<li>Optimise the memory controller to use burst writes of data from the host - this should increase throughput to ~5Mbyte/s.</li>
</ul>

<p>If you want to look at the VHDL for the host interface and the memory controller, you can download it under a <a href="http://www.gnu.org/licenses/gpl-3.0.html">GPLv3 licence</a> from <a href="http://www.swaton.ukfsn.org/uploads/2010/07/umdkv2_vhdl.tar.bz2">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makestuff.eu/wordpress/?feed=rss2&amp;p=915</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Placing Vias Under Fine-Pitch SMDs on Home-Made PCBs</title>
		<link>http://www.makestuff.eu/wordpress/?p=877</link>
		<comments>http://www.makestuff.eu/wordpress/?p=877#comments</comments>
		<pubDate>Sun, 04 Jul 2010 20:09:43 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.makestuff.eu/wordpress/?p=877</guid>
		<description><![CDATA[<p>There are lots of interesting electronic components nowadays like FPGAs and powerful 32-bit microcontrollers. Unfortunately most have upwards of 100 pins and many are only available in packages like TQFP which are very tricky to design with at home. There are two main reasons for this: The layout of the pins usually requires vias to [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>There are lots of interesting electronic components nowadays like FPGAs and powerful 32-bit microcontrollers. Unfortunately most have upwards of 100 pins and many are only available in packages like <a href="http://en.wikipedia.org/wiki/Thin_Quad_Flat_Pack">TQFP</a> which are very tricky to design with at home. There are two main reasons for this:</p>

<ul class="twikilist">
<li>The layout of the pins usually requires vias to be placed <em>under</em> the chip to allow decoupling capacitors and power routing on the other side of the board, leaving the topside clear for signal fan-out. Unfortunately there is precious little clearance under SMD chips for the through-board conductor to make a good connection with the top-side tracks.</li>
<li>The <a href="http://en.wikipedia.org/wiki/List_of_electronics_package_dimensions#Surface-mount_dimension_reference" onmouseover="return overlib('The distance between the centres of two adjacent pins on the chip.');" onmouseout="return nd();">lead pitch</a> is tiny, typically 0.5mm.</li>
</ul>

<p>Today I was able to make my first PCB using a 0.5mm-pitch chip, with vias placed under it. The design was just an intelligent break-out board for the 48-pin SN74ALVC164245 level-shifter. It is available in the 0.635mm-pitch <a href="http://uk.farnell.com/texas-instruments/sn74alvc164245dl/transceiver-3-state-smd-soic48/dp/1287493">DL package</a> and the 0.5mm-pitch <a href="http://uk.farnell.com/texas-instruments/sn74alvc164245dggr/transceiver-level-shifter-smd/dp/1470921">DGG package</a>, which is what I used. I chose this design because the chips are cheap (~£1.50) so it wouldn't have been the end of the world if I failed a few times. The techniques should generalise to bigger, more expensive components.</p>

<p>The following method worked for me; I hope it's useful to someone else.</p>

<h3>Layout</h3>

<p>If you want to fabricate your latest PCB design at home, you need to start thinking about the implications at the design stage - and that potentially includes modifications to the library components you use. For successful home-made PCBs you need to be very conservative with the pad &amp; track sizes and spacing, particularly where drills are concerned. In <a href="http://www.cadsoft.de/">Eagle CAD</a>, I used 1.5mm octagons for the via pads, with 0.7mm drill-holes.</p>

<p><b>Note:</b> In retrospect, it looks like the etchant has made holes uniformly bigger than the 0.7mm specified by the design, so next time I will reduce the CAD drill size to 0.5mm to compensate. </p>

<h3>Making the PCB</h3>

<p>I used an HP LaserJet P2014 to print the upper and lower layers on to <a href="http://www.megauk.com/artwork_films.php">LaserStar</a> film (upper layer mirrored), aligned the two sides using four pieces of blu-tac to hold the film in place (the ink facing inwards), then slid an appropriately-sized piece of <a href="http://www.megauk.com/pcb_laminates.php#PBL10">double-sided PCB laminate</a> between the sheets and exposed for 150s in an <a href="http://www.megauk.com/uv_exposure_units.php#UVE04">AZ210</a> double-sided UV box (pre-heated for 120s). Next I developed the board using an <a href="http://www.megauk.com/pcb_chemicals.php">SN110 applicator</a>, and etched with ferric chloride solution in a <a href="http://www.megauk.com/pcb_processing_tanks.php">PA210</a> bubble-tank. Then I used an <a href="http://www.megauk.com/pcb_chemicals.php">SN120 applicator</a> to strip off the remaining photoresist, scrubbed the board vigorously with steel wool and then used an <a href="http://www.megauk.com/pcb_chemicals.php">SN130 applicator</a> to remove any oxidisation from the copper.</p>

<h3>Drilling and Inserting Through-Hole Rivets</h3>

<p>To drill the vias I used a Dremel with a 0.7mm bit. In retrospect I think a 0.6mm drill bit would have been better. To make a conductive connection between the top and bottom layers I inserted one of these <a href="http://www.makestuff.eu/wordpress/?p=774">tiny rivets</a> into each via hole using a <a href="http://www.megauk.com/through_hole_rivets.php">Favorit rivet machine</a> from MegaUK. </p>

<p>Next I very carefully soldered both ends of each rivet using lots of flux and trying to avoid large blobs (remember that the chip goes over these vias, and there is only 0.25mm clearance).</p>

<p><img src="http://www.swaton.ukfsn.org/uploads/2010/06/drillAndVia.jpg" alt="" title="" width="925" height="347" class="aligncenter size-full wp-image-868" /></p>

<p align="center"><i>Drill the holes and insert the rivets, then solder both sides</i></p>

<p>Before placing the chip over the vias, I used a multimeter to check the connections between the upper and lower tracks.</p>

<h3>Soldering the Chip</h3>

<p>Soldering such fine-pitch components is difficult at the best of times, but on a home-made PCB it's harder still. For aligning the chip on the pads I used a <a href="http://www.makestuff.eu/wordpress/?p=732">USB microscope</a> and a steady hand - no <a href="http://www.relentlessenergy.com">Relentless</a> for me today! For the soldering itself, I used the <a href="http://www.youtube.com/watch?v=t06malVew40">drag soldering method</a> using a <a href="http://www.techni-tool.com/content/resources/demos/Weller/WellerWDSeries.pdf">Weller WD1</a> soldering station and an <a href="http://uk.farnell.com/cooper-tools-weller/ntgw/tip-smd/dp/4154794?Ntt=NTGW">Cooper NTGW</a> tip.</p>

<p><img src="http://www.swaton.ukfsn.org/uploads/2010/06/placeAndSolder.jpg" alt="" title="" width="925" height="347" class="aligncenter size-full wp-image-868" /></p>

<p align="center"><i>Align the chip carefully, solder two corners and then drag the iron down each row</i></p>

<p>Once I finished soldering I cleaned the flux-gunk off with methylated spirits.</p>

<h3>The Finished Product</h3>

<p>And here it is, the finished product:</p>

<p><img src="http://www.swaton.ukfsn.org/uploads/2010/06/finishedProduct.jpg" alt="" title="" width="462" height="465" class="aligncenter size-full wp-image-868" /></p>

<p>You can download the <a href="http://www.cadsoft.de/">Eagle CAD</a> design files for the board if you're interested:</p>

<ul class="twikilist">
<li><a href="http://www.swaton.ukfsn.org/uploads/2010/06/testVC.sch">testVC.sch</a></li>
<li><a href="http://www.swaton.ukfsn.org/uploads/2010/06/testVC.brd">testVC.brd</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.makestuff.eu/wordpress/?feed=rss2&amp;p=877</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Demoscene</title>
		<link>http://www.makestuff.eu/wordpress/?p=867</link>
		<comments>http://www.makestuff.eu/wordpress/?p=867#comments</comments>
		<pubDate>Wed, 09 Jun 2010 11:56:56 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.makestuff.eu/wordpress/?p=867</guid>
		<description><![CDATA[<p>Twenty years ago I used to write demos for the Commodore Amiga. The demos I wrote were primitive even by the standards of the time. It was hard to compete with crazy Swedish guys who were able to do such amazing things with a computer that after all had only a fraction of the power [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>Twenty years ago I used to write demos for the Commodore Amiga. The demos I wrote were primitive even by the standards of the time. It was hard to compete with crazy Swedish guys who were able to do such amazing things with a computer that after all had only a fraction of the power of a modern cellphone. Nevertheless, I am immensely proud to have played a small part in a scene which continues to this day. I discovered this demo today. It's less than 200kB, and it is truly amazing. Taken back in time to 1990, it would have made even the craziest Swedish genius's eyes pop out of his head:
<img src="http://www.swaton.ukfsn.org/uploads/2010/06/debris.jpg" alt="" title="" width="925" height="456" class="aligncenter size-full wp-image-868" /></p>

<p>If you have a Windows PC, you can download it from <a href="http://www.theprodukkt.com/debris">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makestuff.eu/wordpress/?feed=rss2&amp;p=867</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nanduino » JTAG</title>
		<link>http://www.makestuff.eu/wordpress/?page_id=817</link>
		<comments>http://www.makestuff.eu/wordpress/?page_id=817#comments</comments>
		<pubDate>Mon, 05 Apr 2010 12:36:43 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.makestuff.eu/wordpress/?page_id=817</guid>
		<description><![CDATA[<p>NanduinoJTAG is a USB JTAG dongle implemented with a Nanduino board and some supporting software. If you're not familiar with JTAG, have a look at this site. Currently it only supports the ATmega162 used in the S-AVR and the Xilinx XC9572 CPLD as target devices. I will add more devices incrementally. For programming the AVR [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>NanduinoJTAG is a USB JTAG dongle implemented with a Nanduino board and some supporting software. If you're not familiar with JTAG, have a look at <a href="http://www.fpga4fun.com/JTAG2.html">this site</a>.</p>

<p>Currently it only supports the <a href="http://www.atmel.com/dyn/resources/prod_documents/doc2513.pdf">ATmega162</a> used in the <a href="http://www.makestuff.eu/wordpress/?page_id=126">S-AVR</a> and the <a href="http://www.xilinx.com/support/documentation/data_sheets/ds065.pdf">Xilinx XC9572 CPLD</a> as target devices. I will add more devices incrementally. For programming the AVR it is extremely fast, programming and verifying the micro's 16 kbytes of flash in ~500ms. You can download the software from <a href="http://github.com/makestuff/nanduinoJtag/tarball/master">github</a>, and build it on Windows or Linux according to this <a href="http://www.makestuff.eu/wordpress/?p=811">blog post</a>. You can then query the JTAG chain like this:</p>

<pre><code>&gt; sudo host/nj
NanduinoJTAG Copyright (C) 2010 Chris McClelland
Found 2 devices in the JTAG chain:
  Device 0 (IDCODE=0x7940403F): ATMEL ATMEGA162 (rev H)
  Device 1 (IDCODE=0x29504093): XILINX XC9572 (rev C)</code></pre>

<p>The <code>nj</code> program supports a bunch of options:</p>

<pre><code>&gt; sudo host/nj --help
NanduinoJTAG Copyright (C) 2010 Chris McClelland
Usage: nj [-eh] [-d &lt;num&gt;] [-f &lt;fuses&gt;] [-i &lt;inFile&gt;] [-o &lt;outFile&gt;]

Interact with NanduinoJTAG.

  -d, --device=&lt;num&gt;     target device
  -e, --erase            erase the flash, lock bits &amp; maybe EEPROM
  -f, --fuses=&lt;fuses&gt;    set fuses (EX:HI:LO:LK)
  -i, --load=&lt;inFile&gt;    load flash from file
  -o, --save=&lt;outFile&gt;   save flash to file
  -h, --help             print this help and exit</code></pre>

<h3>Program an ATmega162</h3>

<p><img src="http://www.swaton.ukfsn.org/uploads/2010/04/savrJtag.jpg" alt="" title="" width="925" height="697" class="aligncenter size-full wp-image-818" usemap="#oneDevice"/>
<map name="oneDevice">
  <area shape="rect" coords="432,289,506,363" href="javascript:void(0);" onmouseover="return overlib('The four JTAG signals: TDI, TDO, TMS &amp; TCK.');" onmouseout="return nd();"/>
  <area shape="rect" coords="476,275,681,450" href="http://www.makestuff.eu/wordpress/?page_id=569" onmouseover="return overlib('The Nanduino (NanduinoJTAG hardware)');" onmouseout="return nd();"/>
  <area shape="rect" coords="85,129,446,435" href="http://www.makestuff.eu/wordpress/?page_id=126" onmouseover="return overlib('An S-AVR (example target device)');" onmouseout="return nd();"/>
  <area shape="rect" coords="489,44,888,267" href="http://www.makestuff.eu/wordpress/?page_id=216" onmouseover="return overlib('An S-AVR:LED (just to be sure the programming actually works!)');" onmouseout="return nd();"/>
</map></p>

<p>To load the example <a href="http://www.makestuff.eu/wordpress/?page_id=126">S-AVR</a> firmware described <a href="http://www.makestuff.eu/wordpress/?page_id=198">here</a>:</p>

<pre><code>&gt; mkdir simple
&gt; cd simple
&gt; wget http://www.swaton.ukfsn.org/uploads/2009/01/Makefile
&gt; wget http://www.swaton.ukfsn.org/uploads/2009/01/main.c
&gt; make
&gt; cp firmware.hex ..
&gt; cd ..
&gt; sudo host/nj --device=0 --erase --load=firmware.hex
NanduinoJTAG Copyright (C) 2010 Chris McClelland
Found one device in the JTAG chain:
  Device 0 (IDCODE=0x7940403F): ATMEL ATMEGA162 (rev H)
Fuses = 0xFF99FFFF (EX:HI:LO:LK)
Erasing chip...
Programming Atmel chip using HEX file firmware.hex...
Load operation completed with returncode 0x00000000, numfails=0</code></pre>

<h3>Program an XC9572</h3>

<p><img src="http://www.swaton.ukfsn.org/uploads/2010/04/chain.jpg" alt="" title="" width="925" height="705" class="aligncenter size-full wp-image-848" usemap="#twoDevices"/>
<map name="twoDevices">
  <area shape="rect" coords="85,108,362,340" href="javascript:void(0);" href="http://www.makestuff.eu/wordpress/?page_id=126" onmouseover="return overlib('First device in the chain: an ATmega162');" onmouseout="return nd();"/>
  <area shape="rect" coords="394,33,633,255" href="javascript:void(0);" onmouseover="return overlib('Second device in the chain: an XC9572');" onmouseout="return nd();"/>
  <area shape="rect" coords="461,359,623,500" href="http://www.makestuff.eu/wordpress/?page_id=569" onmouseover="return overlib('The Nanduino (NanduinoJTAG hardware)');" onmouseout="return nd();"/>
  <area shape="rect" coords="147,377,336,697" href="http://www.makestuff.eu/wordpress/?page_id=216" onmouseover="return overlib('A S-AVR:LED (just to be sure the programming actually works!)');" onmouseout="return nd();"/>
  <area shape="rect" coords="749,320,905,452" href="http://www.makestuff.eu/wordpress/?page_id=280" onmouseover="return overlib('A S-AVR:Serial (I used this for debugging)');" onmouseout="return nd();"/>
</map></p>

<p>Have a look at the VHDL in the <code>test000</code> subproject of <a href="http://github.com/makestuff/vhdl/tarball/master">this git repo</a>:</p>

<pre><code>entity test is
    Port ( a : in  STD_LOGIC;
        b : in  STD_LOGIC;
        x : out  STD_LOGIC);
end test;

architecture test_arch of test is
begin
    x &lt;= not a and not b;
end test_arch;</code></pre>

<p>The pin assignments of <code>a</code>, <code>b</code> and <code>x</code> are defined in the corresponding <code>ucf</code> file:</p>

<pre><code>NET a LOC=P1;
NET b LOC=P2;
NET x LOC=P3;</code></pre>

<p>In the above pic, input pins 1 and 2 of the CPLD are connected to the least significant two bits of port A, the one driven by the counter program I loaded previously. The CPLD's output on pin 3 is connected to an LED. The result is that the LED lights when both <code>PA0</code> and <code>PA1</code> lines from the micro are low. This condition is true immediately after reset, for one second, followed by three seconds where it is no longer true, and so on, a square wave with a 25% duty cycle.</p>

<p>Install <a href="http://www.xilinx.com/support/download">Xilinx ISE WebPack</a> and build it as described in the README. <strong>The first time you build, it's important to do it from within the WebPack GUI</strong>. The XSVF file generated by the <code>Makefile</code> is intended specifically for the JTAG chain you see in the above picture. It's a chain of two devices, the first being an Atmel ATmega162 microcontroller and the second being a Xilinx XC9572 CPLD. If your chain is different, you will need to change either the design or the <code>impact.batch</code> file.</p>

<pre><code>&gt; make flash
impact -batch impact.batch
Release 11.4 - iMPACT L.68 (nt)
Copyright (c) 1995-2009 Xilinx, Inc.  All rights reserved.
:
..\..\apps\nanduinoJtag\host\Debug\nj --load=test.xsvf
NanduinoJTAG Copyright (C) 2010 Chris McClelland
Found 2 devices in the JTAG chain:
  Device 0 (IDCODE=0x7940403F): ATMEL ATMEGA162 (rev H)
  Device 1 (IDCODE=0x29504093): XILINX XC9572 (rev C)
Playing XSVF file test.xsvf...
Load operation completed with returncode 0x00000000, numfails=0</code></pre>

<h3>How Does It Work?</h3>

<p>JTAG defines four signals:</p>

<table width="75%">
<tr><th>Signal</th><th>Description</th><th>Port</th><th>Port Direction</th></tr>
<tr><td>TCK</td><td>Test Clock</td><td>PB7</td><td>OUT</td></tr>
<tr><td>TMS</td><td>Test Mode Select</td><td>PB6</td><td>OUT</td></tr>
<tr><td>TDO</td><td>Test Data Output</td><td>PB5</td><td>IN</td></tr>
<tr><td>TDI</td><td>Test Data Input</td><td>PB4</td><td>OUT</td></tr>
</table>

<p>The signals are named from the point of view of the target device. For example the <code>TDO</code> signal is an output on the target device; it drives the Nanduino's <code>PB5</code> line, which must therefore be configured as an input:</p>

<p><img src="http://www.swaton.ukfsn.org/uploads/2010/04/njBlockDiagram.png" alt="" title="" width="635" height="360" class="aligncenter size-full wp-image-864" /></p>

<p>Each JTAG target device incorporates a sixteen-state finite state machine called the TAP controller:</p>

<p><img src="http://www.swaton.ukfsn.org/uploads/2010/04/jtagFSM.png" alt="" title="" width="745" height="585" class="aligncenter size-full wp-image-862" /></p>

<p>The state machine transitions according to the level of <code>TMS</code> at the rising edge of <code>TCK</code>. Some states allow data to be clocked into (and simultaneously out of) the target device using the <code>TDO</code> and <code>TDI</code> signals. There are a basic set of operations supported by all JTAG-capable devices, but to do any serious work you need to delve into the device-specific JTAG implementation documentation. For AVR microcontrollers this is described in the data sheets, and describes how to read &amp; write the device's flash, fuses &amp; EEPROM, and more advanced stuff like setting breakpoints and reading the device state.</p>

<p>This is all implemented in the NanduinoJTAG firmware. Each operation is triggered by a set of custom USB commands implemented by the NanduinoJTAG using <a href="http://www.fourwalledcubicle.com/LUFA.php">LUFA</a>. The host-side code interacts with the NanduinoJTAG using <a href="http://www.libusb.org">LibUSB</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makestuff.eu/wordpress/?feed=rss2&amp;page_id=817</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross-Platform Builds</title>
		<link>http://www.makestuff.eu/wordpress/?p=811</link>
		<comments>http://www.makestuff.eu/wordpress/?p=811#comments</comments>
		<pubDate>Mon, 05 Apr 2010 10:05:15 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.makestuff.eu/wordpress/?p=811</guid>
		<description><![CDATA[<p>For a while now I've been getting worried about the amount of boilerplate source code I'm copying around from one project to another, so yesterday I refactored all the general-interest code out of my current mini-project and wrote a cross-platform build infrastructure which can build and test each mini-library in isolation, and automatically integrate with [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>For a while now I've been getting worried about the amount of boilerplate source code I'm copying around from one project to another, so yesterday I refactored all the general-interest code out of my current mini-project and wrote a cross-platform build infrastructure which can build and test each mini-library in isolation, and automatically integrate with <a href="http://github.com">github</a> for fetching dependencies. Doing such a thing in a language like Java is very easy, but doing it in C is far harder.</p>

<p>Firstly the directory structure. Each project lives in a structure like this:</p>

<pre><code>src
|
+-apps
| |
| +-nanduinoJtag
|
+-libs
| |
| +-argtypes
| +-buffer
| +-dump
| +-hexreader
| +-usbwrap
|
+-3rd
  |
  +-argtable2-12
  +-LUFA091223
  +-UnitTest++</code></pre>

<p>The idea is to maintain a clear separation between 3rd-party ("<tt>3rd</tt>") code, my own library ("<tt>libs</tt>") code and my own application ("<tt>apps</tt>") code, and to automatically fetch any dependencies, downloading my own libs if necessary from <a href="http://github.com">github</a> and building them, and downloading 3rd-party libs and tools from wherever and building them.</p>

<p>The build infrastructure itself is based on GNU make, and it supports Linux and Windows builds.</p>

<h3>Windows Builds</h3>

<p>The Windows platform introduces some unique challenges. Tooling on Windows is characterised by large-scale tools, usually relying heavily on IDE integration, rather than the more expressive Unix environment which is based on a large number of small-scale tools which cooperate with eachother. So to get off the ground on Windows you will need a couple of prerequisites:</p>

<ul class="twikilist">
<li>A functional GNU environment. I do a lot of stuff using <a href="http://www.atmel.com/dyn/products/devices_v2.asp?family_id=607#760">Atmel AVR microcontrollers</a>, so I have <a href="http://winavr.sourceforge.net">WinAVR</a> installed, which comes with such an environment, but you will probably get away with a more minimal <a href="http://www.cygwin.com">cygwin</a> or <a href="http://www.mingw.org">mingw</a> installation, so long as it has basic stuff like <code>make</code>, <code>tar</code>, <code>mv</code>, <code>cp</code>, <code>wget</code>, etc.</li>
<li>An installation of <a href="http://www.microsoft.com/express/Downloads/#Visual_Studio_2008_Express_Downloads">Microsoft Visual C++ 2008 Express Edition</a> which is available from Microsoft as a free download. The 2010 edition will <strong>not</strong> work because <code>vcbuild.exe</code> has been deprecated.</li>
</ul>

<p>Once you have the prerequisites you can go ahead and build an application (this one really does need <a href="http://winavr.sourceforge.net">WinAVR</a> since it contains AVR code)...</p>

<pre><code>C:\temp&gt;mkdir foo-src
C:\temp&gt;cd foo-src
C:\temp\foo-src&gt;mkdir apps
C:\temp\foo-src&gt;cd apps
C:\temp\foo-src\apps&gt;wget http://github.com/makestuff/nanduinoJtag/tarball/master
C:\temp\foo-src\apps&gt;tar xvzf makestuff-nanduinoJtag-*.tar.gz
C:\temp\foo-src\apps&gt;cd makestuff-nanduinoJtag-*
C:\temp\foo-src\apps\makestuff-nanduinoJtag-c9d3c67&gt;make -f Makefile.win32
C:\temp\foo-src\apps\makestuff-nanduinoJtag-c9d3c67&gt;cd ..\..
C:\temp\foo-src&gt;find . -maxdepth 2 -type d
.
./3rd
./3rd/argtable2-12
./3rd/libusb-win32-device-bin-0.1.12.2
./3rd/LUFA091223
./3rd/UnitTest++
./3rd/unz600
./apps
./apps/makestuff-nanduinoJtag-c9d3c67
./libs
./libs/argtypes
./libs/buffer
./libs/dump
./libs/hexreader
./libs/usbwrap</code></pre>

<p>After the build completes you will notice that the requisite dependencies for this particular project have been downloaded and built for you. Where possible I have used the <code>vcbuild</code> tool rather than invoking the compiler and linker directly, so you should be able to run the apps in the Visual Studio IDE without problems.</p>

<h3>Linux Builds</h3>

<p>Achieving the same thing on Linux is considerably simpler. The requisite tools are usually already installed, and if not can easily be installed using your favourite package manager.</p>

<pre><code>&gt; mkdir foo-src
&gt; cd foo-src/
&gt; mkdir apps
&gt; cd apps/
&gt; wget http://github.com/makestuff/nanduinoJtag/tarball/master
&gt; tar xvzf makestuff-nanduinoJtag-*.tar.gz
&gt; cd makestuff-nanduinoJtag-*
&gt; make -f Makefile.linux
&gt; cd ../..
&gt; find . -maxdepth 2 -type d
.
./apps
./apps/makestuff-nanduinoJtag-c9d3c67
./libs
./libs/dump
./libs/usbwrap
./libs/hexreader
./libs/buffer
./libs/argtypes
./3rd
./3rd/UnitTest++
./3rd/argtable2-12
./3rd/LUFA091223</code></pre>

<p>After the build completes you will notice that the requisite dependencies for this particular project have been downloaded and built for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makestuff.eu/wordpress/?feed=rss2&amp;p=811</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Thoreau on Freedom</title>
		<link>http://www.makestuff.eu/wordpress/?p=799</link>
		<comments>http://www.makestuff.eu/wordpress/?p=799#comments</comments>
		<pubDate>Tue, 26 Jan 2010 23:12:15 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Politics]]></category>
		<category><![CDATA[Quotes]]></category>

		<guid isPermaLink="false">http://www.makestuff.eu/wordpress/?p=799</guid>
		<description><![CDATA[<p>"There will never be a really free and enlightened State until the State comes to recognize the individual as a higher and independent power, from which all its own power and authority are derived, and treats him accordingly."- Henry David Thoreau</p>
]]></description>
			<content:encoded><![CDATA[<blockquote>"There will never be a really free and enlightened State until the State comes to recognize the individual as a higher and independent power, from which all its own power and authority are derived, and treats him accordingly."<br/><br/>- Henry David Thoreau</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.makestuff.eu/wordpress/?feed=rss2&amp;p=799</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nanduino » USB Messaging</title>
		<link>http://www.makestuff.eu/wordpress/?page_id=780</link>
		<comments>http://www.makestuff.eu/wordpress/?page_id=780#comments</comments>
		<pubDate>Tue, 26 Jan 2010 00:54:39 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.makestuff.eu/wordpress/?page_id=780</guid>
		<description><![CDATA[<p>The AT90USB162 microcontroller on the Nanduino incorporates a full-speed USB peripheral allowing it to enumerate as any of the standard USB device classes or as a vendor-specific device like the bootloader you saw earlier. The standard device types include virtual serial port, mass-storage device, keyboard, mouse, MIDI port, audio input and output. They usually do [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>The AT90USB162 microcontroller on the <a href="http://www.makestuff.eu/wordpress/?page_id=569">Nanduino</a> incorporates a full-speed USB peripheral allowing it to enumerate as any of the standard USB device classes or as a vendor-specific device like the bootloader you saw earlier. The standard device types include virtual serial port, mass-storage device, keyboard, mouse, MIDI port, audio input and output. They usually do not require any drivers on the host side; the host recognises their device class and assumes certain capabilities as a result. Conversely, the vendor-specific devices need specific drivers to be loaded on the host side to facilitate communication with the device.</p>

<p>In some cases it's possible to (ab)use some standard device class for what you want to do, but often it's better to just drop down to the more fundamental messaging layer. There are two great libraries out there to facilitate this approach:</p>

<ul class="twikilist">
<li><a href="http://www.fourwalledcubicle.com/LUFA.php">LUFA</a> provides a nice framework for implementing USB device firmware on the AVR8 microcontrollers.</li>
<li><a href="http://www.libusb.org/">LibUSB</a> provides a similar framework for cross-platform host-side USB programming, crucially avoiding the need to learn the details of driver development on each platform.</li>
</ul>

<p>My aim here was to put together a very simple example of a vendor firmware running on a Nanduino and a simple host-side application. And here it is:</p>

<blockquote><a href="http://www.swaton.ukfsn.org/uploads/2010/01/avrcalc.tar.gz">avrcalc.tar.gz</a></blockquote>

<p>There's a README with instructions on how to build on Windows and Linux. Pay particular attention to the directory structure, which follows the build infrastructure described in <a href="http://www.makestuff.eu/wordpress/?p=811">this blog post</a>.</p>

<h3>Code Walkthrough</h3>

<p>If you have never done any USB programming before, it would be wise at this stage to familiarise yourself with its fundamental concepts. I learned all I needed from <a href="http://www.beyondlogic.org/usbnutshell/usb1.htm">this great tutorial on BeyondLogic</a>.</p>

<p>The firmware is about as simple as it can be. It accepts requests for IN transfers (from device to host) on <code>EP0</code> having <code>bRequest=0x80</code>, and returns eight bytes or four words: the four arithmetic operations on the <code>wValue</code> and <code>wIndex</code> parameters:</p>

<pre><code>void EVENT_USB_Device_UnhandledControlRequest(void) {
    switch ( USB_ControlRequest.bRequest ) {
        case 0x80:
            if ( USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR) ) {
                uint16 arith[4];
                arith[0] = USB_ControlRequest.wValue + USB_ControlRequest.wIndex;
                arith[1] = USB_ControlRequest.wValue - USB_ControlRequest.wIndex;
                arith[2] = USB_ControlRequest.wValue * USB_ControlRequest.wIndex;
                arith[3] = USB_ControlRequest.wValue / USB_ControlRequest.wIndex;
                Endpoint_ClearSETUP();
                Endpoint_Write_Control_Stream_LE(arith, 8);
                Endpoint_ClearOUT();
            }
            break;
    }
}</code></pre>

<p>The host side code is just a small utility called <code>ucm</code> ("USB Control Messager") that is bundled with <a href="http://www.makestuff.eu/wordpress/?page_id=343">fx2tools</a>. It too is fairly straightforward - most of the code is for accepting command-line arguments. And as you probably guessed, it is generic too - it allows you to send and receive control data from <strong>any</strong> USB device. The core of the code makes use of this <a href="http://libusb.sourceforge.net/doc/function.usbcontrolmsg.html">libusb function</a>:</p>

<pre><code>int usb_control_msg(
    usb_dev_handle *dev,  // the device we're talking to
    int bRequestType,     // whether IN or OUT (amongst other things)
    int bRequest,         // the request code, 0x80 in this example
    int wValue,           // the first parameter
    int wIndex,           // the second parameter
    char *buffer,         // a buffer with/for the data
    int size,             // the number of bytes to send/request
    int timeout           // the timeout in milliseconds
);</code></pre>

<p>From the firmware code above you can see that this firmware only accepts IN requests (i.e data sent from the device to the host). Any attempt to initiate an OUT request results in an error.</p>

<h3>Putting It All Together</h3>

<p>Once the calculator firmware is loaded into the Nanduino, either with <code>make&nbsp;flip</code> on Windows or <code>make&nbsp;dfu</code> on Linux (and installed the supplied <code>libusb</code> driver on Windows), you can interrogate it with the <code>ucm</code> utility from <a href="http://www.makestuff.eu/wordpress/?page_id=343">fx2tools</a>:</p>

<pre><code>&gt;../fx2tools/ucm/ucm -i -v 0x03EB -p 0x3002 0x80 0x0010 0x0002 0x0008 | ../fx2tools/hxd/hxd
00000000 12 00 0E 00 20 00 08 00                         .... ...</code></pre>

<p>The Nanduino takes the two numbers passed to it 0x0010 (16) and 0x0002 (2) and returns four words:</p>

<ul class="twikilist">
<li>Their sum:        16 + 2 = 18 (0x0012)</li>
<li>Their difference: 16 - 2 = 14 (0x000E)</li>
<li>Their product:    16 * 2 = 32 (0x0020)</li>
<li>Their quotient:   16 / 2 = 8  (0x0008)</li>
</ul>

<p>OK, so I admit that a Nanduino makes a poor math coprocessor, but this simple calculator example demonstrates a number of important concepts, which will hopefully serve to get you off the ground quicker.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makestuff.eu/wordpress/?feed=rss2&amp;page_id=780</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Through-Hole Rivets</title>
		<link>http://www.makestuff.eu/wordpress/?p=774</link>
		<comments>http://www.makestuff.eu/wordpress/?p=774#comments</comments>
		<pubDate>Mon, 18 Jan 2010 22:44:33 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.makestuff.eu/wordpress/?p=774</guid>
		<description><![CDATA[<p>Recently I bought a machine from Mega Electronics for inserting tiny rivets into 0.7mm diameter drill-holes in home-made PCBs. The result is a fairly low-profile via, with decent electrical conductivity even without soldering. I'm hoping they will be sufficiently flush with the surface of the board to allow me to place vias under the 0.5mm [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>Recently I bought a machine from <a href="http://www.megauk.com">Mega Electronics</a> for inserting tiny rivets into 0.7mm diameter drill-holes in home-made PCBs. The result is a fairly low-profile via, with decent electrical conductivity even without soldering. I'm hoping they will be sufficiently flush with the surface of the board to allow me to place vias under the 0.5mm lead-pitch <a href="http://en.wikipedia.org/wiki/TQFP">TQFP</a> packages used for <a href="http://www.xilinx.com/support/documentation/package_specs/tq144.pdf">Xilinx FPGAs</a>:</p>

<p><img src="http://www.swaton.ukfsn.org/uploads/2010/01/rivetAndUnderFpga.jpg" alt="" title="" width="925" height="347" class="aligncenter size-full wp-image-775"/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.makestuff.eu/wordpress/?feed=rss2&amp;p=774</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
