<?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>Stephen&#039;s Weblog</title>
	<atom:link href="http://blog.akkit.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.akkit.org</link>
	<description>Everything is hackable</description>
	<lastBuildDate>Sun, 22 Aug 2010 20:47:52 +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>Another two weeks&#8230;</title>
		<link>http://blog.akkit.org/2010/08/22/another-two-weeks/</link>
		<comments>http://blog.akkit.org/2010/08/22/another-two-weeks/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 20:46:45 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=287</guid>
		<description><![CDATA[I haven&#8217;t done anything worth mentioning, so here&#8217;s a picture of some PCBs! :) This is the USB Jtag PCB I previously mentioned, and I had it produced in a group PCB order managed by Laen &#8211; They turned out nice and came back pretty quickly, I&#8217;ll definitely be sending him more PCBs As I [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t done anything worth mentioning, so here&#8217;s a picture of some PCBs! :)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/08/usbjtag_rev1_pcb.jpg"><img class="alignnone size-medium wp-image-288" title="usbjtag_rev1_pcb" src="http://blog.akkit.org/wp-content/uploads/2010/08/usbjtag_rev1_pcb-300x136.jpg" alt="Front and Back of USB Jtag PCB" width="300" height="136" /></a></p>
<p>This is the USB Jtag PCB I previously mentioned, and I had it produced in a <a href="http://dorkbotpdx.org/wiki/pcb_order">group PCB order managed by Laen</a> &#8211; They turned out nice and came back pretty quickly, I&#8217;ll definitely be sending him more PCBs</p>
<p>As I was on vacation though, I just recently ordered the parts to complete these boards, and haven&#8217;t got them yet. I&#8217;ve also been thinking about priorities and am working more heavily on some projects which I won&#8217;t blog about :)</p>
<p>Things are still developing though, keep watching and I should have more to talk about in 2 weeks.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/08/22/another-two-weeks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oops.</title>
		<link>http://blog.akkit.org/2010/08/10/oops/</link>
		<comments>http://blog.akkit.org/2010/08/10/oops/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 01:32:41 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=284</guid>
		<description><![CDATA[Ah right, I was planning to post last weekend; I haven&#8217;t actually done anything too interesting though :) just messing around with some stuff while I&#8217;m away on vacation; Mostly doing less than usual though &#8211; that&#8217;s ok every now and then.]]></description>
			<content:encoded><![CDATA[<p>Ah right, I was planning to post last weekend;</p>
<p>I haven&#8217;t actually done anything too interesting though :) just messing around with some stuff while I&#8217;m away on vacation; Mostly doing less than usual though &#8211; that&#8217;s ok every now and then.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/08/10/oops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generic USB JTAG/etc Programmer</title>
		<link>http://blog.akkit.org/2010/07/25/generic-usb-jtagetc-programmer/</link>
		<comments>http://blog.akkit.org/2010/07/25/generic-usb-jtagetc-programmer/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 07:03:33 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[PCB Layout]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=273</guid>
		<description><![CDATA[Despite having 2 weeks for this, I haven&#8217;t actually completed anything notable; So I&#8217;m just going to post some WIP images of a PCB I&#8217;ve designed to do general purpose programming (Generally jtag, but also AVR) I&#8217;ve been working out the concepts in software using the modified USB stick (as I mentioned previously) but just [...]]]></description>
			<content:encoded><![CDATA[<p>Despite having 2 weeks for this, I haven&#8217;t actually completed anything notable; So I&#8217;m just going to post some WIP images of a PCB I&#8217;ve designed to do general purpose programming (Generally jtag, but also AVR)</p>
<p>I&#8217;ve been working out the concepts in software using the modified USB stick (as I mentioned previously) but just haven&#8217;t had enough time to allocate to it yet. Soon, though.</p>
<p><span id="more-273"></span></p>
<p>This design is pretty simple; I have the microcontroller (ATMega32U2), a RGB LED, switch, and crystal &#8211; Then around that I am building a set of voltage level translation circuits for the jtag signals, and for additional inputs, outputs, and &#8220;pump&#8221; signals (which can strongly connect to a target&#8217;s V+ level, and drive a significant amount of current)</p>
<p>I&#8217;m including the JTAG interfaces I use commonly  on the board, and I have another additional &#8220;expansion&#8221; slot which I&#8217;ll be building new boards for to connect to yet other interfaces</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip1.png"><img class="alignnone size-medium wp-image-276" title="usbjtag_wip1" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip1-300x282.png" alt="" width="300" height="282" /></a></p>
<p>Schematic done, decided on a rough layout and started placing parts.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip2.png"><img class="alignnone size-medium wp-image-277" title="usbjtag_wip2" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip2-300x256.png" alt="" width="300" height="256" /></a></p>
<p>I got the core signals routed, and routed the level shifted jtag signals around the board, connecting to the side connectors as they go.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip3.png"><img class="alignnone size-medium wp-image-278" title="usbjtag_wip3" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip3-297x300.png" alt="" width="297" height="300" /></a></p>
<p>Added most of the other level shifting signals</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip4.png"><img class="alignnone size-medium wp-image-279" title="usbjtag_wip4" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip4-287x300.png" alt="" width="287" height="300" /></a></p>
<p>And now the design is essentially complete!</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_rev1.png"><img class="alignnone size-medium wp-image-274" title="usbjtag_rev1" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_rev1-285x300.png" alt="" width="285" height="300" /></a></p>
<p>Added ground planes, and vias to keep them well connected / allow plenty of return paths.</p>
<p>At this point I thought I was done&#8230;. Only, oops, I connected the top 3 headers backwards;  I had gone off of the pinout of the socket they plug into. Fortunately I noticed this before trying to produce the board :)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_rev1a.png"><img class="alignnone size-medium wp-image-275" title="usbjtag_rev1a" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_rev1a-287x300.png" alt="" width="287" height="300" /></a></p>
<p>Ahh, now they&#8217;re correct.</p>
<p>So I&#8217;m having this board produced pretty soon and will write up more on JTAG once I have done some stuff with this.</p>
<p>In other news I&#8217;m taking a vacation in about 2 weeks! No, I&#8217;m not going anywhere interesting, just visiting family, but perhaps I&#8217;ll have something fun to write about by then :) I certainly have plenty of things I want to do!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/07/25/generic-usb-jtagetc-programmer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Format Change</title>
		<link>http://blog.akkit.org/2010/07/17/format-change/</link>
		<comments>http://blog.akkit.org/2010/07/17/format-change/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 05:29:53 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=270</guid>
		<description><![CDATA[I&#8217;ve been writing weekly now for a while &#8211; I&#8217;ve decided, though, that it&#8217;s unsustainable. Writing these posts has been a great motivator for getting some of my projects done, but they also don&#8217;t leave me a lot of time to do so. So, I&#8217;m shifting the format and will write blog posts every other [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing weekly now for a while &#8211; I&#8217;ve decided, though, that it&#8217;s unsustainable. Writing these posts has been a great motivator for getting some of my projects done, but they also don&#8217;t leave me a lot of time to do so.</p>
<p>So, I&#8217;m shifting the format and will write blog posts every other week &#8211; I&#8217;ll continue next week.</p>
<p>Thanks for reading! I hope some of this material has been useful to you, and please do let me know if you&#8217;d like to see something specific, or if anything isn&#8217;t clear.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/07/17/format-change/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JTAG</title>
		<link>http://blog.akkit.org/2010/07/11/jtag/</link>
		<comments>http://blog.akkit.org/2010/07/11/jtag/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 07:10:27 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware Hacking]]></category>
		<category><![CDATA[Reference Material]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=255</guid>
		<description><![CDATA[So, many of you use JTAG? I&#8217;ve been using JTAG for many years now, which started with FPGAs, and has mostly been for CPLDs and FPGAs since- but it&#8217;s also a pretty widely used protocol for programming and debugging mid range microcontrollers all the way up to high end CPUs. I&#8217;ve always wanted to look [...]]]></description>
			<content:encoded><![CDATA[<p>So, many of you use <a href="http://en.wikipedia.org/wiki/JTAG">JTAG</a>?</p>
<p>I&#8217;ve been using JTAG for many years now, which started with FPGAs, and has mostly been for CPLDs and FPGAs since- but it&#8217;s also a pretty widely used protocol for programming and debugging mid range microcontrollers all the way up to high end CPUs. I&#8217;ve always wanted to look into how JTAG worked in more depth, but never really had the time.</p>
<p>Now, I do have some time (and some projects which depend on JTAG hacking) &#8211; so this post will go into the world of JTAG.<span id="more-255"></span></p>
<p>Many of you have probably seen the following diagram, usually in some CPU or FPGA datasheet where it talks about the JTAG port. And it probably clicks to a degree, you see there&#8217;s a state model you can move around in, and the TMS signal causes that &#8211; but what doesn&#8217;t really get said is really a lot simpler than all that.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/jtag-state-machine-large.png"><img class="alignnone size-medium wp-image-256" title="jtag-state-machine-large" src="http://blog.akkit.org/wp-content/uploads/2010/07/jtag-state-machine-large-300x262.png" alt="(Sourced from some random site, but this diagram is pretty much everywhere - in datasheets, etc)" width="300" height="262" /></a></p>
<p>There are really only a few core truths and fundamental operations to know about when working with JTAG:</p>
<ul>
<li>There are 4 data lines important to JTAG: TDI, TDO, TMS, TCK &#8211; All of them are expected to be pulled up with resistors (either in the chip or externally). Some devices provide a &#8220;TRST&#8221; signal, which just does essentially the same as navigating to &#8220;Reset&#8221; through the state machine (only possibly without the side effect of committing a register change)</li>
<li>Pins are named in a Chip-Centric way. TDI goes into the chip, TDO is data out of the chip. TMS and TCK are controlled by the programmer</li>
<li>The device samples on the rising edge of TCK, and you should listen for its response on the falling edge.</li>
<li>A JTAG Reset should reset the test circuitry. Enter the reset state by cycling with TMS = 1 for 6 cycles (or more) &#8211; and then usually move to the &#8220;run/test/idle&#8221; state.</li>
<li>Idle in the  &#8221;run/test/idle&#8221; state by cycling the clock when TMS=0. Some devices depend on having idle clocks like this in order to perform their programming functions.</li>
<li>Write to the Instruction register &#8211; you do this by entering the Shift-IR state, Stay in this and shift bits (set TDI to your value, and listen on TDO). You need to set TMS = 1 for the last bit you shift.</li>
<li>Write to the Data register &#8211; Exactly the same way, just by entering Shift-DR</li>
<li>Another rule which it helps to know, is bitstreams are usually sent bottom-bit first &#8211; and are almost always represented with first sent bit on the right side. Important strings in documentation have been always specified in this form, in my experience (though it&#8217;s anybody&#8217;s guess what order the manufacturer will use to push their data into the port.</li>
<li>JTAG is inherently a multi-chip protocol. You can chain multiple chips by connecting TMS and TCK to all chips in the chain, Connect TDI to the first device, and connect the first device&#8217;s TDO to the second device&#8217;s TDI &#8211; And so on, finally connecting the last chip&#8217;s TDO to the header.</li>
</ul>
<p>Most of the other logic in the state machine is for devices that are tied to a fixed clock, and need to be wedged for a while if the host can&#8217;t keep up with shifting data.</p>
<p>At this point though, you can think of the JTAG system as memory mapped I/O, except for that the read/write widths are variable. Each transaction (Traveling through Capture-DR, shifting data, and then returning through Update-DR) has an impact on the system, which could be very small or very big. Everything is hardware specified, and every bit -could- have a meaning. That being said though, there are a few rules that make this manageable!</p>
<p>First, the Instruction register is typically very small. It exists so you can tell the device what mode to work in &#8211; And usually the size (Bit width) of the data register is fixed and based on the mode you are in.</p>
<p>There are a few mandated modes &#8211; The boundary scan modes were the original intent of the JTAG system &#8211; they exist so you can control and listen on the I/O pins of the device. JTAG was primarily designed as a way to test electrical connections on circuit boards between chips &#8211; This is implemented as the EXTEST and SAMPLE modes, for which the specific instruction register values are not rigidly specified (it varies per device)</p>
<p>There is a mandated &#8220;Bypass&#8221; mode, which is defined as an instruction word filled with ones &#8211; so you can technically use it even with chips that you don&#8217;t know anything about in the JTAG chain. When a chip is in BYPASS mode, it&#8217;s data register is a single bit. (Which will always clear itself to 0 when you start a new data transaction by entering Capture-DR)</p>
<p>When you enter JTAG Reset, the chip will automatically enter either IDCODE or BYPASS. IDCODE is an optional mode which is usually implemented; Its data register is a fixed 32bit value uniquely identifying the chip type, which MUST start with a &#8217;1&#8242; bit. The (slightly inobvious) advantage to this, is after resetting a JTAG chain, you can easily identify the number of devices in the chain and their types, if they entered the IDCODE state, just by shifting some bits through the data register! Based on whether the bit you receive is 0 or 1, either you know there is a bypassed device, or you will have 31 additional IDCODE bits to identify the current device with. Provided that you&#8217;re shifting in &#8217;1&#8242; bits into TDI, you can also identify the end of the chain when you encounter an IDCODE of all ones.</p>
<p>Another thing defined for your convenience, is the instruction register doubles as a status register.  The (variable size) instruction word is required to shift out as &#8220;xxxx01&#8243;; where one is sent *first* (rightmost first), and the &#8220;x&#8221; bits could be status from the device. This also gives you some clue as to how big the instruction registers are, if you didn&#8217;t know about all the devices in your chain. Though, even with this it may not be possible to concretely identify the sizes of the instruction registers in your chain. Well, there may be another trick/requirement but I don&#8217;t know it &#8211; I have been working entirely off of public documentation :)</p>
<p>It&#8217;s definitely easiest to work with chains that only have one device, but it is not too hard to set all the uninteresting devices to BYPASS if you can identify their instruction register sizes.</p>
<p>As for actually doing stuff with JTAG? Well, I think I&#8217;ll have to go over that some other time. The idea is to set some instruction, and then you get to send a data word, which is some data, some control bits, and some very strange logic sometimes. The device also trades you back a value in the exchange, and frequently you receive the results of the previous command you entered.</p>
<p>I have been starting to reverse engineer the JTAG protocols used by some Xilinx FPGAs and CPLDs (just in order to build my own programmer for them) &#8211; it&#8217;s been an interesting project that has repeatedly broken many of my assumptions about how JTAG is used. I&#8217;ll post more about this when I have worked it all out. Some things are very simple, others seem to be highly complex and mysterious, littered with commands that don&#8217;t make much sense and (apparently) unused data. (Seems I&#8217;m mostly interested in the complex ones &#8211; oh well.)</p>
<p>On the bright side, I have found a new use for my <a href="http://blog.akkit.org/2010/06/06/project-avr-usb-stick/">AVR USB Stick</a>, it currently has a bundle of wires attached to it for JTAG purposes :) I&#8217;ve written a simple protocol on the virtual serial port that lets me do JTAG stuff easily, and am probably going to set up a new PCB for dedicated USB programming, just because it&#8217;s so much faster than my existing serial port based programmer.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/07/11/jtag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PCI Card Revisited</title>
		<link>http://blog.akkit.org/2010/07/04/pci-card-revisited/</link>
		<comments>http://blog.akkit.org/2010/07/04/pci-card-revisited/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 07:00:02 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware Hacking]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=239</guid>
		<description><![CDATA[Remember the PCI card from a few weeks ago? Not too long after that, I did send out an order to manufacture some boards &#8211; and this last week they finally arrived! I&#8217;ve assembled a few, tested them, run into a few problems, solved them, and finally got a pretty basic PCI Port-80h debug card [...]]]></description>
			<content:encoded><![CDATA[<p>Remember the <a title="Project: PCI Card" href="http://blog.akkit.org/2010/06/13/project-pci-card/">PCI card</a> from a few weeks ago?</p>
<p>Not too long after that, I did send out an order to manufacture some boards &#8211; and this last week they finally arrived! I&#8217;ve assembled a few, tested them, run into a few problems, solved them, and finally got a pretty basic PCI Port-80h debug card working.</p>
<p>In this post I&#8217;ll walk through these things, and talk some more about the PCI interface.</p>
<p><span id="more-239"></span></p>
<p>So; Early this week I received a package from <a title="MyroPCB" href="http://www.myropcb.com/">MyroPCB</a> &#8211; A cheap outsourced PCB manufacturer; I&#8217;m rather happy with the quality of these boards &#8211; it&#8217;s a reasonably simple design to produce these days I suppose, but it is still pretty neat.</p>
<div id="attachment_242" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_scan.jpg"><img class="size-medium wp-image-242  " title="pcipost_scan" src="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_scan-300x221.jpg" alt="Scan of the PCI_POST circuit board" width="300" height="221" /></a><p class="wp-caption-text">(A Scan of some of the boards I received)</p></div>
<p>It takes some time to assemble this PCB, due to all the parts; The most annoying parts have been ones with pads strongly attached to the ground fill; Those pads have thermals seperating them from the fill, so they are not completely embedded in copper, but they&#8217;re still too well connected, and very troublesome to solder as all the heat is sucked away by the large mass of copper. Also the capacitors take some time to solder just by virtue of there being a large number of them. (And also that a large number of them have one pad attached too well to the ground fill)</p>
<div id="attachment_243" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_populated.jpg"><img class="size-medium wp-image-243 " title="pcipost_populated" src="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_populated-300x225.jpg" alt="The PCI_POST board populated with components" width="300" height="225" /></a><p class="wp-caption-text">(After some soldering)</p></div>
<p>At this point I didn&#8217;t do much else with this project until today;</p>
<p>Unfortunately, I had made a serious miscalculation &#8211; Note that the PCI edge connector on this card is 3.3V only&#8230; Now, I had built this card not long after seeing a PCI 3.3V only slot in a server system; so I made the assumption this would work great for me. In fact the PCI 3.0 specification (released in 1994!) no longer even includes the 5V PCI card slot</p>
<p>So that means it&#8217;s gone, right?</p>
<p>Well, No.</p>
<p>And, in fact my assumption proved to be wrong in the most incredible sense; There are literally no desktop-class motherboards on the market with 3.3V PCI slots! I spent an hour or two looking through motherboards on <a title="Newegg" href="http://www.newegg.com/">Newegg</a>, and the cheapest motherboard I could find with 3.3V PCI slots was $200. (And, only had 3.3V PCI slots by virtue of them being part of 3.3V PCI-X slots)</p>
<p>All was not lost though, first, this board was also built to be general purpose  - so it will have other uses. Also, as it turns out, it isn&#8217;t impossible to use it in modern 5V PCI slots.</p>
<p>Apparently,  system board manufacturers don&#8217;t want to sacrifice compatibility &#8211; so while modern PCI busses are all driven with 3.3V signals, they are still using the 5V connectors and maintaining 5V compatibility &#8211; This is really annoying for my project, because my FPGA isn&#8217;t 5V tolerant like their bus controllers are, but I can work on a 3.3V bus just fine. So, to actually be able to test, I have cut out the second key slot in the PCI connector and broken the VCCIO traces that would otherwise connect 5V to my 3.3V rail in the 5V slot. The PCI connector has a bundle of different voltage rails &#8211; but in a 3.3V-only card, like I made, the I/O voltage levels are intended to be connected to the 3.3V rail &#8211; so I did connect them &#8211; Unfortunately, being compatible with a 5V slot means those I/O voltage levels are 5V. It&#8217;s not ideal to just disconnect them, as they are supposed to have bypass capacitors in order to reduce noise, but I didn&#8217;t have many options with this, so I have just disconnected my card from the I/O voltages completely.</p>
<div id="attachment_244" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_scratched.jpg"><img class="size-medium wp-image-244  " title="pcipost_scratched" src="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_scratched-300x97.jpg" alt="PCI_POST card with cut out slot and scratched out I/O voltage traces" width="300" height="97" /></a><p class="wp-caption-text">(Chopped traces and a new slot)</p></div>
<p>With this modification, my card is quite happy to work in the motherboards I have around &#8211; The caveat is, since my FPGA isn&#8217;t 5V tolerant, if I put it in with a 5V device (which does typically drive the bus up to 5V), it will likely damage my device. However, for what I&#8217;d like to do, I can live with this, and I can redesign the board if I ever actually need 5V tolerance.</p>
<p>After resolving how to test my board as a PCI device, I set out to write a first simple test firmware, to verify that the core functionality worked- This just drives the display and sets the LED values based on the switches present on the system.</p>
<div id="attachment_245" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_test.jpg"><img class="size-medium wp-image-245 " title="pcipost_test" src="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_test-300x225.jpg" alt="pci_post test program" width="300" height="225" /></a><p class="wp-caption-text">(Test program)</p></div>
<p>It was at this point that I noticed the green &#8220;programming done&#8221; LED had accidentally been populated with a red LED on this board &#8211; oops. I will have to go back and fix that later.</p>
<p>A few short steps further, and I converted the test program to firmware for watching the port 80h I/O Writes on the PCI bus &#8211; I had an old motherboard around from a system upgrade some time ago, connected it up, and it does appear to be working! After powering up the system, the display cycled through a number of values exactly the way it should; In the image below you can see the last 2 values it observed written to port 80h.</p>
<div id="attachment_246" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_victory.jpg"><img class="size-medium wp-image-246 " title="pcipost_victory" src="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_victory-300x225.jpg" alt="pci_post operating as a POST code display card" width="300" height="225" /></a><p class="wp-caption-text">(Victory!)</p></div>
<p>So,A few short notes about PCI devices &#8211; First, this isn&#8217;t actually a full PCI device; It does not interfere with the bus any more than is necessary to make electrical contact- it is only listening to the bus in order to see this information (as such it&#8217;s out of spec). It is actually possible to make a full PCI device with this card, and that&#8217;s on my list of  things to do eventually as well.</p>
<p>The PCI bus though, is essentially a collection of signals &#8211; there are 32 address/data lines, and a number of control signals; At its core though are the PCI Clock signal, a FRAME signal (each transaction on the bus is a frame), the 32 address/data lines, 4 lines which are used as both a control word, and as 4 individual byte enables (to enable byte granularity in the 32bit value) &#8211; Beyond these are some handshaking signals (IRDY/TRDY), sanity checking (Parity), error reporting (PERR/SERR), transaction abort (STOP), System reset (RST), and location-based device identification (IDSEL/DEVSEL)</p>
<p>In order to listen for a specific port write on the bus though, you only really need the CLK, FRAME, data lines, and the 4-bit control word / byte enable &#8211; All PCI signals are sampled on a rising clock edge, the controller starts a frame by asserting FRAME on a clock edge. When it does this, it also sets the 4-bit control word to the transaction type, and for some types of transactions also sets the address lines to the related address.</p>
<p>What my card is doing, is waiting for reset to finish; then every frame that starts, it checks if it is an I/O write with address = 0&#215;00000080; If so, it listens on the next cycle, and if byte enable 0 is set, it will accept the data in the bottom 8 bits of the data lines as a new port 80h write &#8211; In any case, it waits for the frame to finish, and then continues waiting for another frame to start.</p>
<p>Sounds simple? It really is.</p>
<p>Making a real PCI device though will be a lot more challenging, and I&#8217;ll be sure to document that when I get around to it :)</p>
<p>Small update: I should probably also mention the significance of Port 80h &#8211; System BIOS manufacturers have standardized on using port 80h as a debug port of sorts, they write a byte to that port to indicate which section of the BIOS code is running; As such, there are a number of cheaply available &#8220;PC Diagnostic&#8221; boards, which do essentially what I&#8217;m doing here, just listen for Port 80h accesses and display the values. The capability to see this code is helpful when diagnosing a difficult motherboard problem, to be sure&#8230; but it&#8217;s also helpful when writing and debugging low-level code when little else on the system is running, as you can add writes to 80h that give you information about what stage of execution your program is in.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/07/04/pci-card-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>USB Stick: Part 2</title>
		<link>http://blog.akkit.org/2010/06/27/usb-stick-part-2/</link>
		<comments>http://blog.akkit.org/2010/06/27/usb-stick-part-2/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 05:18:34 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=233</guid>
		<description><![CDATA[Oh, finally&#8230; So, this post is a little bit late as well, I almost didn&#8217;t manage to make this work :) I&#8217;ve been now tinkering with writing a USB device stack for my USB stick for literally the past two weeks now; Being a new space, I&#8217;m used to the idea of having issues, but [...]]]></description>
			<content:encoded><![CDATA[<p>Oh, finally&#8230;</p>
<p>So, this post is a little bit late as well, I almost didn&#8217;t manage to make this work :) I&#8217;ve been now tinkering with writing a USB device stack for my USB stick for literally the past two weeks now; Being a new space, I&#8217;m used to the idea of having issues, but between incredibly stupid bugs, very minimal documentation, and errors in some critical hardware documentation, this has been quite a challenging project.</p>
<p>On the plus side, I now have my <a href="http://blog.akkit.org/2010/06/06/project-avr-usb-stick/">USB stick</a> behaving as a virtual com port &#8211; so it will be trivial to write extensions and make it start to do really useful stuff (haven&#8217;t quite got around to that yet, so expect a part 3)</p>
<p>Additionally, in the process I&#8217;ve become pretty familiar with  how USB works, and I&#8217;ll try to more simply define it for those who are interested in getting started.</p>
<p><span id="more-233"></span></p>
<p>First, some detail about how I managed to make it to this point; I&#8217;ve wanted to play around with USB for quite a long time &#8211; the first time I tried was many many years ago, around the time I had mastered several much simpler serial protocols&#8230; That didn&#8217;t particularly go anywhere as I had no idea where to start with the USB specification, and every part of it seemed equally irrelevant and incomprehensible.</p>
<p>As you might imagine, I&#8217;ve since become a lot better at reading specifications &#8211; and while the USB specification is still by no means trivial, it makes quite a bit of sense now, and have been able to identify the important parts and work through the process of actually building a compatible device.</p>
<p>Since I&#8217;m using an AVR with USB support, some level of this is done for me;  the entire electrical communication layer is done, and the vast majority of the protocol work &#8211; all that remains is to handle the high level messages and instruct the hardware on how to proceed. This was indeed a pretty easy thing to do, just bugs caused quite a lot of pain.</p>
<p>One thing I&#8217;ve found very helpful in this process is USB protocol tracing; There are a number of tools out there that can capture USB traffic, and if you&#8217;re using Windows 7, a mechanism to do this exists built into the OS&#8217;s USB stack itself (take a look <a title="USB Tracing in Windows 7" href="http://blogs.msdn.com/b/usbcoreblog/archive/2009/12/04/etw-in-the-windows-7-usb-core-stack.aspx">here</a> for more information). In general the bugs I&#8217;ve hit were mainly packets that didn&#8217;t complete properly (returned an inappropriate response, or didn&#8217;t return at all), and those things are pretty easy to find in a protocol trace.</p>
<p>So, let&#8217;s start with a broad question: What is USB?</p>
<p>The USB specification defines the behavior and allowed interactions of all parts of the USB ecosystem. It provides a framework for building devices which require data transfer between the device and host, in a number of ways. The specifications for USB are available from<a href="http://www.usb.org/home"> usb.org</a> &#8211; Most modern devices are USB 2.0, and USB 3.0 is out of the scope of what I&#8217;m talking about here :)</p>
<p>It&#8217;s actually a very  wide specification, and the USB specification and related specifications seek to define a lot of things, such as:</p>
<ul>
<li>How a USB device physically attaches to a host system (Mechanical, chapter 6)</li>
<li>How a USB device electrically communicates to a host system (Electrical, chapter 7)</li>
<li>What specific sorts of message types should be sent between the host and device, and the bit patterns they map to (Protocol layer, Chapter 8)</li>
<li>How the device uses those messages to interact with the host and expose data about itself (USB Device Framework, Chapter 9)</li>
<li>How the host should behave in general</li>
<li>How hubs should work, to allow a single USB port to drive multiple devices</li>
<li>And additionally the USB Device Class specifications specify in more detail how certain types of devices should behave, in a standardized way.</li>
</ul>
<p>For what I have been doing with the USB stick and general microcontroller USB development (when hardware support is available), only the parts about the Device Framework and device class specifications are really important &#8211; it&#8217;s good to know about the protocol layer but that is for the most part taken care of for you.</p>
<p>Still, it is pretty complex &#8211; but only because there are a number of details to attend to. I&#8217;m omitting a few of the details, but I&#8217;ll go over the major points individually:</p>
<p>First, a device is a logical object composed of endpoints &#8211; There are 16 endpoint numbers and 0 is always a special number for sending control messages to the device. Everything about USB is host-centric, the host initiates all transactions, the device must only respond. So the majority of what happens in USB, is the host sends a packet of a certain type, to a specific endpoint, and then the device responds to that request with data, acknowledgement, or some error condition.</p>
<p>An endpoint is really just a buffer to send or receive data &#8211; the endpoints in USB microcontrollers typically only operate in one direction, though the USB standard allows an endpoint to both send and receive data. Typically you will have to configure your endpoint with a specific size (which will be communicated to the host via descriptors, see further below)  - Then either you will make an IN endpoint write data to the buffer, and hardware will happily send it to the host the next time the host asks about that endpoint &#8211; or you will create an OUT endpoint, wait for it to be filled by the host, and the process the incoming data. Endpoint 0 must operate in both directions, and that balance is a little elaborate to maintain.</p>
<p>The big three request packets the host uses to control the flow of data are: SETUP, IN, and OUT. IN commands are the host asking for data, OUT commands are the host sending data, and SETUP packets are slightly more complicated &#8211; a SETUP packet must only be sent to endpoint 0, and it is always followed by an 8-byte data packet, which is a data structure specifying a request. As part of the setup transaction, the host may send additional data (with an OUT), or may ask for data (with an IN); and a third stage with the opposite direction will give the device a chance to acknowledge or reject the transaction.</p>
<p>Here&#8217;s another representation&#8230;</p>
<p>Host sending data to device:  OUT &#8211; &lt;host sends data&gt; &#8211; [device ACK, handled by hardware]</p>
<p>Host requesting data from device: IN &#8211; &lt;device sends data&gt; &#8211; [host ACK, or retry logic handled by hardware]</p>
<p>Host sending a SETUP request with no extra data: SETUP &#8211; &lt;host sends 8 bytes&gt; &#8211; [Device ACK in hardware] &#8211; IN &#8211; &lt;Device sends zero-length data packet to acknowledge&gt; &#8211; [host ACK]</p>
<p>Host sending a SETUP request and requesting extra data: SETUP &#8211; &lt;host sends 8 bytes&gt; &#8211; [Device ACK] &#8211; IN &#8211; &lt;Device sends extra data&gt; &#8211; [host ACK] &#8211; OUT &#8211; &lt;Host sends zero length packet&gt; &#8211; [Device ACK to acknowledge]</p>
<p>Host sending a SETUP request and sending extra data: SETUP &#8211; &lt;host sends 8 bytes&gt; &#8211; [Device ACK] &#8211; OUT &#8211; &lt;Host sends additional data&gt; &#8211; [Device ACK]  - IN &#8211; &lt;Devices sends zero-length packet to acknowledge&gt; &#8211; [Host ACK]</p>
<p>Alternately, the device may send a STALL response instead of data / ack if it does not support a SETUP operation (or if the endpoint has an error); (to add another detail,  USB hardware will also send NAK packets to delay requests until the device is ready to respond- which I haven&#8217;t included for the sake of simplicity)</p>
<p>Another small complexity in the SETUP phase is that if your data payload exceeds the maximum endpoint length, multiple packets will be sent/requested, finally terminating with a packet less than the maximum endpoint size.</p>
<p>So, did I say this was simple? I&#8217;m sorry :)</p>
<p>That&#8217;s the very outer shell &#8211; the information you need to know to interface with the hardware; Next comes the requests themselves.</p>
<p>The requests are completely documented in the USB specification, in  sections 9.3 and 9.4; The specification leaves a little bit to be desired in the clarity of what exactly needs to be handled, but most importantly you need to focus on the &#8220;type&#8221; field in the bmRequestType and also the request code itself. If the type is a standard request, the table of standard device request IDs is in that area, If the type is a class, or vendor request, a different table of request codes applies. It is necessary to handle several of the standard requests in order for a device to work. Most importantly though, are set_address, get_descriptor, and set_configuration. Several of the others are required, but not all of them (I&#8217;m not elaborating further because the descriptions in section 9.4 are actually not bad)</p>
<p>For set_address, some interesting logic is usually required, After receiving the set_address packet, you must complete the ACK phase before actually setting the address (or else your address will change before the host commits to your new address, and it will not be possible to complete the ACK ) &#8211; the Atmel datasheet went into some detail on how it should be done. The entire transaction is done without extra data (the address is passed in one of the fields of that 8-byte SETUP data packet), so it is the software&#8217;s responsibility only to receive that, process it, and then instruct the hardware to send a zero-length data packet in response to the host&#8217;s IN (and set the address AFTER that packet completes)</p>
<p>Get_Descriptor is the most important command to get right, and you only absolutely have to handle two types of requests here. First: for descriptor type 1 and descriptor index 0 (the Device descriptor), and second: descriptor type 2 and descriptor index 0 (The first Configuration descriptor) &#8211; The descriptors I will cover in a moment, but they are relatively large data structures that describe the structure of your device, among other important details. This is probably the only setup request that is likely to need multiple packets in response (My setup endpoint is 32 bytes, and my configuration descriptor is 67 bytes &#8211; so 3 packets for me). In this case the idea is to process the SETUP data structure, reject it with STALL if it&#8217;s not one of the supported types, but otherwise send packets of max length followed by waiting for those packets to complete until  you get to the end (you either send a zero length packet or non-max-length packet as the last one). Note as well that the get_descriptor request includes a maximum length, so you may have to stop early sometimes.</p>
<p>By default, your device is in an unconfigured state, essentially all of the endpoints are supposed to be turned off (Except endpoint 0), the device should not be doing anything notable. &#8211; set_configuration allows the host to turn on a device to one of potentially several operating modes (each one of these modes gets a configuration descriptor)</p>
<p>If you can implement those three, the others will follow pretty naturally, and Class requests when implementing class devices follow the same pattern.</p>
<p>One last subject for this blog post: Descriptors!</p>
<p>The USB descriptor definitions in Section 9.6  are pretty well documented structures. The device descriptor is simple enough &#8211; when you are asked to provide a device descriptor, they mean you should send a string of bytes that correspond to the USB device descriptor (9.6.1) &#8211; Note that some of the numeric fields are a bit&#8230; distant &#8211; descriptor type numbers are in table 9-5 back in section 9.4.</p>
<p>The configuration descriptor is the tricky one. If you read about the get_descriptor device request (9.4.3) you&#8217;ll find that the configuration descriptor should actually be a configuration descriptor, followed by one or more interface descriptors, and each interface descriptor may be followed by one or more endpoint descriptors (think of a tree). In the USB world, A configuration is thought of as a mode of operation, and an interface is thought of as a logical unit  that serves a specific function. That specific function is associated with the Zero endpoint for control (typically as Vendor type requests, which you can define yourself if you want to write a driver), and possibly one or more endpoints, which serve as data pipes for interfacing with the device.</p>
<p>How should you define a configuration? Well, any way you want if you are writing your own driver&#8230; But USB-IF noticed that this wasn&#8217;t ideal, and so the notion of Class devices was brought into the world.</p>
<p>I&#8217;m not going to cover this here (this post is already so very long!), but  in addition to the USB core specification there are a large number of official class specifications, which define how specific types of devices should operate &#8211; To be more specific, they define what things you should have in your configuration, and they provide a list of class requests, notifications, and custom descriptors related to describing various types of devices. The upshoot of all this is you simply have to implement a class device, and likely the driver to make your device work on whatever computer you plug it into has already been written for you.</p>
<p>In re-reading this, I doubt I will have answered everyone&#8217;s questions, I&#8217;m happy to answer further questions if you post them; USB does seem pretty simple after wading through it for a week or two, but it is still a large array of moving parts, regardless of how simple as they may be individually.</p>
<p>I&#8217;m planning to continue this, another time, and I have been working on a USB cribsheet for my own reference that I&#8217;ll also link here sometime.</p>
<p>(And now, I am off, to implement a USB bootloader, and USB jtag programming and&#8230; )</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/06/27/usb-stick-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Skipping a week</title>
		<link>http://blog.akkit.org/2010/06/20/skipping-a-week/</link>
		<comments>http://blog.akkit.org/2010/06/20/skipping-a-week/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 09:12:01 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=229</guid>
		<description><![CDATA[Well, it was my intention to talk about USB in more detail today, but my USB project has been a little sidetracked &#8211; today I wrote the majority of my USB Device implementation but am still stuck debugging a hardware feature that&#8217;s not quite working how I think it should&#8230; I have a pretty good [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it was my intention to talk about USB in more detail today, but my USB project has been a little sidetracked &#8211; today I wrote the majority of my USB Device implementation but am still stuck debugging a hardware feature that&#8217;s not quite working how I think it should&#8230; I have a pretty good understanding of USB now from this project, but do actually want to make sure all of my assertions hold before documenting it ;)</p>
<p>So, nothing too interesting this week; Next week should be good though. (and the week after, and the week after. I have quite a bit lined up now, just not all done yet)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/06/20/skipping-a-week/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project: PCI Card</title>
		<link>http://blog.akkit.org/2010/06/13/project-pci-card/</link>
		<comments>http://blog.akkit.org/2010/06/13/project-pci-card/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 07:00:56 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=213</guid>
		<description><![CDATA[Another week has gone by already? Well, I do at least have something to show for it. So the thing I spent the most spare time on this last week has been designing a FPGA-based PCI card. This is something I&#8217;ve wanted to do for some time now (and have an earlier unfinished attempt that [...]]]></description>
			<content:encoded><![CDATA[<p>Another week has gone by already? Well, I do at least have something to show for it.</p>
<p>So the thing I spent the most spare time on this last week has been designing a FPGA-based PCI card. This is something I&#8217;ve wanted to do for some time now (and have an earlier unfinished attempt that was far more complex), but I have recently encountered some inspiration for a board that will be somewhat useful, or at least interesting.</p>
<p>This board isn&#8217;t really much of anything special, but it will fill a specific niche, and will be sufficient to try out a lot of interesting things I&#8217;ve been thinking of in the PCI space.</p>
<p>So, This isn&#8217;t going to be an exceptionally impressive post, but I did collect screenshots from various stages of the board&#8217;s development, and  I&#8217;ll also discuss the design decisions behind this board.</p>
<p><span id="more-213"></span></p>
<p>On with the screenshots!</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip1.png"><img class="alignnone size-medium wp-image-214" title="pcipost_wip1" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip1-300x185.png" alt="" width="300" height="185" /></a></p>
<p>(Just getting started, have finished the core of the schematic, have all the power and parts set up)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip2.png"><img class="alignnone size-medium wp-image-215" title="pcipost_wip2" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip2-300x191.png" alt="" width="300" height="191" /></a></p>
<p>(After working out the pin mappings from FPGA to PCI card, adding some PCI-related capacitors)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip3.png"><img class="alignnone size-medium wp-image-216" title="pcipost_wip3" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip3-300x186.png" alt="" width="300" height="186" /></a></p>
<p>(Fixed the PCI &#8211; fpga mappings slightly and started routing. This is a few hours of progress, but it takes a lot of effort&#8230;)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip4.png"><img class="alignnone size-medium wp-image-217" title="pcipost_wip4" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip4-300x188.png" alt="" width="300" height="188" /></a></p>
<p>(Continuing to route PCI-FPGA traces)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip5.png"><img class="alignnone size-medium wp-image-218" title="pcipost_wip5" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip5-300x183.png" alt="" width="300" height="183" /></a></p>
<p>(Ah. Done with that. A few things move around to pack better)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip6.png"><img class="alignnone size-medium wp-image-219" title="pcipost_wip6" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip6-300x161.png" alt="" width="300" height="161" /></a></p>
<p>(A lot of other stuff gets routed! It&#8217;s not as hard as the PCI stuff :)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip7.png"><img class="alignnone size-medium wp-image-221" title="pcipost_wip7" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip7-300x155.png" alt="" width="300" height="155" /></a></p>
<p>And the final part done: Routing the power pins on the FPGA. (And a few pesky remaining traces due to an error)</p>
<p>The signals on the board are now 100% routed, but the board is still not complete, I have a number of cosmetic things to do still, moving component text around and adding some descriptive text. Also planning to add ground fills to unused board space.</p>
<p>So, some of you may have guessed my inspiration for this board, it&#8217;s pretty similar to those &#8220;BIOS POST code display&#8221; boards &#8211; Yup, and that is one of the intended uses of this board, but by no means all it can do. This board has been designed so it can also easily work as a standalone development board for general purpose FPGA experimentation, and it is also my intention to build a full PCI Device using this board as well. Of course it&#8217;s not going to do much with this board alone, but the I/O header should allow for some interesting external devices if I want to try anything specific.</p>
<p>Some more specific details of the design:</p>
<ul>
<li>The PCB is routed with 8 mil traces (and 8 mil spacing) &#8211; this makes it pretty challenging to route, but it was fun.</li>
<li>If operating only as a PCI card, it would be possible to remove several components (the power supply stuff and clock  on the right side of the board), without affecting anything</li>
<li>The FPGA in this case is a Spartan-3AN (XC3S50AN &#8211; not incredibly big but will work here) &#8211; the 3AN series, as opposed to most other Spartan-3 FPGAs, have onboard flash memory to store configuration data (otherwise an external chip would be needed to configure from, eating up more I/O pins)</li>
<li>There are 4 I/O pushbutton switches, and an 8-switch dipswitch</li>
<li>The PRSNT1# and PRSNT2# lines on the PCI connector are used to indicate to the system board whether or not a PCI card is present in a given slot. This board has solder-bridge jumpers potentially connecting those to ground (to indicate presence); In the case of a BIOS POST card we don&#8217;t actually want to indicate to the system that there is a board present, as we can get what we want without being a &#8220;full&#8221; pci device. But bridging those jumpers will also allow a full PCI device to be designed.</li>
<li>The PCI connector has been routed by flipping back-side signals to the top side, and trying to align the PCI signals to the FPGA pins before even starting that; On the back side, I have a thick 3.3V trace running along the length of the connector, and a GND trace above that, which makes it relatively easy to keep all the power lines connected properly. This is the fourth or so revision of my process for doing this, and it&#8217;s pretty effective &#8211; but I noticed yet another optimization&#8230; If I also were to match up the FPGA 3.3V pins with the front-side PCI 3.3V pins, it would further reduce the complexity of routing the connector, and I&#8217;d get better connected power pins as well &#8211; Something to consider for next time, the time that goes into planning and routing the PCI connector to a FPGA is pretty significant.</li>
</ul>
<p>I am planning to finish up the design work and get some of these boards produced in the next few days &#8211; and when I get them back and get some stuff working on them, I&#8217;ll post again on how it went, how PCI works, and other sorts of interesting things :)</p>
<p>Update: After a little bit more effort, I have deemed the board &#8220;complete&#8221;. Now working on getting it fabricated&#8230;</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_rev1.png"><img class="alignnone size-medium wp-image-227" title="pcipost_rev1" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_rev1-300x151.png" alt="" width="300" height="151" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/06/13/project-pci-card/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Project: AVR USB Stick</title>
		<link>http://blog.akkit.org/2010/06/06/project-avr-usb-stick/</link>
		<comments>http://blog.akkit.org/2010/06/06/project-avr-usb-stick/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 07:00:30 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=202</guid>
		<description><![CDATA[Hi again, As promised, this week&#8217;s project entry is much less entertaining; I did attempt to get this project a bit further today but distractions have taken their toll. Expect this one to come up again in the future :) So, not too long ago I had the bright idea to build a little USB [...]]]></description>
			<content:encoded><![CDATA[<p>Hi again,</p>
<p><a href="http://blog.akkit.org/2010/05/30/project-chip-decapping/">As promised</a>, this week&#8217;s project entry is much less entertaining;</p>
<p>I did attempt to get this project a bit further today but distractions have taken their toll. Expect this one to come up again in the future :)</p>
<p>So, not too long ago I had the bright idea to build a little USB stick; My motives at the time were apparently highly questionable, so I am here about a month later with a fairly limited use USB stick</p>
<p>One of my major goals behind this project was to have an excuse to work out the details of USB, and try some stuff out, which I&#8217;m still doing now. Once I get that done with, I will attempt to explain just how all that works; USB is a bit elaborate, but it&#8217;s increasingly interesting and important these days, as serial and parallel ports are becoming more rare. I have another project along these lines too, but it&#8217;s quite a bit more low-level.</p>
<p>For this post though, I&#8217;m just talking about the hardware design of this project. <span id="more-202"></span></p>
<p>The board was really quickly designed; I thought (for some reason) that it would be neat to have a little USB stick that had an RGB LED, and a speaker to output audio. So, that&#8217;s what I made :)</p>
<p>This stick is based around a <a href="http://www.atmel.com/dyn/products/product_card_v2.asp?part_id=4602">Atmel ATMega32U2 microcontroller</a>, which has  built-in USB device support. It requires a pretty stable clock source in order to use USB, so I picked an 8MHz crystal for it. I found a <a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&amp;name=475-2855-1-ND">reasonably cheap RGB LED</a> on digikey, and added some passives, an op amp, and a tiny speaker I had around for sound.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/usb_play1.png"><img class="alignnone size-medium wp-image-203" title="usb_play1" src="http://blog.akkit.org/wp-content/uploads/2010/06/usb_play1-300x124.png" alt="" width="300" height="124" /></a></p>
<p>PCB design for the board (It looks confusing because I&#8217;ve included a lot of layers, but you don&#8217;t usually work with all of those layers on, you can just look at the front/back individually)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/usb_playbrd1.jpg"><img class="alignnone size-medium wp-image-204" title="usb_playbrd1" src="http://blog.akkit.org/wp-content/uploads/2010/06/usb_playbrd1-300x105.jpg" alt="" width="300" height="105" /></a></p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/usb_playbrd2.jpg"><img class="alignnone size-medium wp-image-205" title="usb_playbrd2" src="http://blog.akkit.org/wp-content/uploads/2010/06/usb_playbrd2-300x98.jpg" alt="" width="300" height="98" /></a></p>
<p>And, actual implementation of the board!</p>
<p>I&#8217;m sure you can see the mistakes in this one, but probably not quite all of them. Things to check for next time I make a really rushed design:</p>
<ul>
<li>Make sure TFQFP package reflects reality. Not sure how but my pads start at the very tip of the pins :) I must have been looking at the wrong package type for spacing info.</li>
<li>Enhance font size on 0402 components (see the 2 tiny capacitors by the crystal? They&#8217;re C1 and C2 in the PCB design image.)</li>
<li>Make sure crystal doesn&#8217;t overlap other components (fortunately the crystal body isn&#8217;t connected to anything, so it can be near / short against USB V+ without issue.)</li>
<li>Pay closer attention to drill sizes. USB header shield doesn&#8217;t actually fit through the holes I designed it for. I have a caliper so these sorts of mistakes are just silly :)</li>
</ul>
<p>Some other miscellaneous design notes</p>
<ul>
<li>This AVR has a 3 PWM channels based on one 16bit timer &#8211; this is being used for the RGB LED</li>
<li>The audio output is a PWM channel on another 8bit timer &#8211; it&#8217;s feeding through a resistor into a cap, which produces a pretty stable voltage level based on the PWM duty cycle. Then the opamp is buffering that voltage level and outputting it to the speaker. It should be able to do 8bit audio with good quality, though it&#8217;s certainly not a perfect DAC.</li>
</ul>
<p>So, not bad for a few hours of looking for parts and hacking some weekend, I&#8217;m not actually sure if the utter lack of any serious purpose makes this a good or bad project :)</p>
<p>Anyway, I&#8217;m off now, as I have some other project ideas calling me now&#8230;  Perhaps this motivation drought has ended.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/06/06/project-avr-usb-stick/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
