Solving the USB Only Chicken or Egg Problem

Not rated 29,430

Circuit Image

Numerous effective In-System Programming (ISP) designs are available for 8-bit AVR microcontrollers. However, many of these designs necessitate a pre-programmed microcontroller, presenting the "Chicken or Egg" dilemma: programming microcontrollers requires having one that is already programmed. While solutions utilizing Parallel or Serial Ports have been available, modern computers often lack these interfaces. The FTDI USB-to-serial chip offers a potential alternative. Historically, it has been considered unfeasible to resolve the Chicken or Egg problem using USB alone, without pre-programmed or specialized USB chips. USB specifications define a device reset state, where a hub shorts both data lines to ground for 10 milliseconds. Additionally, USB hubs provide a disable feature that prevents data from being routed to the disabled port, maintaining both data lines in a high impedance state. Devices include a pull-up resistor that the hub uses to detect device arrival at a disabled port. Typically, these features are managed automatically by the operating system. However, by controlling a hub and keeping its ports disabled, each port can function as a single bit input and/or a momentary active-low "open collector" pulsable output. Two pulsable outputs can drive a set-reset latch to create a steady-state output, which is sufficient for AVR ISP programming. For those new to AVR microcontrollers, ISP programming is not an ideal starting point, even with a pre-made programmer, and certainly not when attempting to build one’s own. Ready-to-use boards like Teensy or Arduino connect directly to any USB port and are ready for use with user-friendly software tools. Troubleshooting electronics and software can be challenging, even for seasoned engineers, thus it is advisable to begin with a setup that minimizes complications. HUB ISP is not a suitable substitute for conventional "chicken or egg" AVR ISP programmers, which tend to be faster, more reliable, and potentially more economical, such as the Teensy running the ArduinoISP code. However, for those who enjoy experimentation or are curious about achieving this solely with USB and without programmable chips—using only logic gates and resistors—further exploration is warranted. Editing the config.h file and including the appropriate ID numbers is necessary, followed by compiling with "make." If an error regarding "usb.h" arises, it may indicate that a "devel" libusb library package needs installation. The most straightforward yet labor-intensive task involves cutting and preparing the USB cables. The plastic jackets can be tough to remove, while the internal wires are often delicate. Each of the four cables requires the green wire, and at least one red and one black wire are necessary (these wires are sourced from the same power supply within the hub). It is advisable to cut the extra white, red, and black wires to slightly varying lengths, avoiding proximity to the frayed metal shield to prevent accidental short-circuits. Tinning the wire ends with a soldering iron will facilitate insertion into breadboard holes; otherwise, tightly twisting the wires is an alternative, but caution for stray wire fragments is necessary. It should be noted that while the schematic incorrectly depicts ports 1 and 2 with red wires and ports 3 and 4 with black wires, the actual connections used black wires for ports 1 and 2 and red wires for ports 3 and 4. This distinction is less critical, as all four red wires connect to the same +5 volt power source within the hub, and all grounds are interconnected. Nonetheless, it is essential that each green wire is correctly assigned to its designated location. A test program is available to confirm proper connections before risking damage to an actual AVR chip. A close-up image of the circuitry reveals the presence of a 4.7K resistor connected between pin 11 and the green wire of port 4, concealed behind one of the USB cables.

The schematic for this setup typically involves a USB hub with its ports configured to operate in a disabled state, allowing for the manipulation of the data lines for programming purposes. The FTDI chip interfaces with the USB hub, providing a bridge for communication with the AVR microcontroller. The design incorporates resistors, particularly the 4.7K resistor, which is crucial for pull-up functionality, ensuring reliable data transmission. The connections between the USB ports and the microcontroller must be meticulously arranged to prevent signal interference and ensure that the programming signals are accurately transmitted. The use of logic gates in this design allows for the generation of the necessary control signals required for programming the microcontroller, thereby overcoming the limitations typically imposed by the lack of a pre-programmed chip. This innovative approach showcases the versatility of USB technology in microcontroller programming applications, enabling enthusiasts and engineers alike to explore the capabilities of AVR microcontrollers without the need for traditional programming hardware.Many excellent ISP (In System Programming) designs exist for 8 bit AVR microcontrollers. However, most require a pre-programmed microcontroller, or the "Chicken or Egg" problem: you can`t program microcontrollers unless you have one already programmed. Parallel Port or Serial Port solutions have existed, but many modern computers no longer have these ports.

The FTDI USB-to-serail chip can be used as well. Until now it`s been widely thought impossible to solve the Chicken or Egg problem using only USB, without preprogrammed or specialized USB chips. USB defines a device reset state, where a hub shorts both data lines to ground for 10 milliseconds. USB hubs also implement a disable feature, where no data is routed to the disabled port, and both data lines are kept at high impedance.

Devices contain a pullup resistor, which is used by the hub to detect device arrival, at a disabled port. Normally these features are managed automatically by your operating system. But by taking control of a hub and keeping its ports disabled, each port can be used as a single bit input, and/or a momentary active-low "open collector" pulsable output.

Two pulsable outputs can drive a set-reset latch to create a single steady-state output. These I/O capabilities are sufficient for AVR ISP programming! If you are just getting started with AVR microcontrollers, ISP programming is not a good place to begin, even if you buy a ready made programmer, and certainly not by trying to build your own! Ready-to-use boards like Teensy (yes, a shameless plug, as I make this one) or Arduino just plug into any USB port and are ready to go, with easy to use software tools.

Troubleshooting electronics and software can be taxing even for experienced engineers, so it`s highly recommended to start with a foundation that`s as trouble-free as possible. HUB ISP is, well. not. HUB ISP is certainly not a viable replacement for regular "chicken or egg" AVR ISP programmers, which are much faster and more reliable, and maybe even cheaper.

eg, Teensy running the ArduinoISP code (yup, another shameless plug). However, if you love to tinker or you`re just curious how this could possibly work with only USB and no programmable chip, without even any parts designed for USB, only logic gates and resistors, then read on! You must edit config. h and include those ID numbers. Then just compile with "make". If you get an error about "usb. h" missing, you probably need to install a "devel" libusb library package. Probably the simplest but most tedious step is cutting and preparing the USB cables. On these 4, the plastic jacket was really tough, and the wires inside really delicate. All four cables need the green wire, and at least one red and one black are needed (they`re from the same power inside the hub).

It`s a good idea to cut the extra white, red and black lines at slightly different lengths, and not close to the frayed metal shield, so they don`t accidentally short to each other. If you have a soldering iron, tinning the ends of the wires will make them much nicer for sticking into the breadboard holes.

Otherwise, just twist them tightly and watch for stray bits of wire later on. Opps, I drew ports 1 and 2 with red wires and ports 3 and 4 with black wires on this schematic, but I actually used the cables with black wires on ports 1 and 2, and the cables with red wires on ports 3 and 4. It doesn`t really matter, as all 4 red wires connect to the same +5 volt power inside the hub and all grounds are connected together.

Even just 1 red wire and 1 black wire from any of the 4 cables is enough. Of course, it DOES matter that each green wire goes to the correct place. The test program will help you make sure it`s all hooked up properly before risking a real AVR chip. Here is a closeup photo of the circuitry. There is a 4. 7K resistor, the one attached between pin 11 and port 4`s green wire, hiding behind one of the USB cables! 🔗 External reference