Category: Avr Development

  • Benito#7 The next big thing.

    There were a few lessons that I learned at the Arduino Cult induction workshop that I put together this month. One of which was that I needed to simplify my programmer design on the cable end and not wait until I had a full blown product. Revisiting the original I first revised the ftdi boards to use a pinout compatible with the programming end of the rbba. Then I went back to the AT90USB162 based programmer modified the schematic to reduce the parts count.

    Then I made it fit into a similar profile.

    Then I put together a parts manifest at q25 and found that in spite of the increased parts count it is actually cheaper than the ftdi boards.

    Index Quantity Part Number Description Customer Reference Backorder Quantity Unit Price
    USD Extended Price
    USD
    1 50 RHM10KARCT-ND RES 10K OHM 1/8W 5% 0805 SMD 0 0.02340 $1.17
    2 25 AT90USB162-16AURCT-ND IC AVR MCU 16K FLASH 32TQFP 0 3.15000 $78.75
    3 25 631-1099-ND CRYSTAL 8.0 MHZ SERIES 0 0.48900 $12.23
    4 30 PCC220CNCT-ND CAP 22PF 50V CERM CHIP 0805 SMD 0 0.06900 $2.07
    5 200 RHM220ACT-ND RES 220 OHM 1/8W 5% 0805 SMD 0 0.02340 $4.68
    6 50 RHM22ACT-ND RES 22 OHM 1/8W 5% 0805 SMD 0 0.04080 $2.04
    7 100 399-1168-1-ND CAP .10UF 25V CERAMIC X7R 0805 0 0.02670 $2.67
    8 50 399-1284-1-ND CAP 1.0UF 16V CERAMIC X7R 0805 0 0.09500 $4.75
    9 30 475-1401-ND LED 3MM 570NM GREEN DIFF RADIAL 0 0.05600 $1.68
    10 1 AT43301-SU-ND IC USB HUB CTRLR 4PORT 24SOIC 0 1.83000 $1.83
    11 25 609-1039-ND CONN RCPT USB TYPE B R/A PCB 0 0.54200 $13.55
    Subtotal $125.42

  • MyUsb and the DTR pin.

    It seems like all I do nowadays is to try to decipher other peoples code.

    Which make a body feel a lot like a teething toddler.

    One of my projects is an an avr programmer based on the new AT90USB  using Dean Camera’s MyUSB library. In it there are two examples using the driverless serial class (CDC/ACM). The examples are deceptively straightforward.

    I was able to bring up a functioning serial port which works on OSX, Windows, and Linux in a very short time. The problem was that I needed to implement the DTR and what I eventually want to wind up with is a reset pulse where the DTR pin used to be.

    My present understanding of the way that the USB CDC Modem class handles RTS and DTR is that the host computer sends a control packet to the device telling it the state of those lines. This is described in  the document entitled “Universal Serial Bus Class Definitions for Communication Devices”
    http://www.usb.org/developers/devclass_docs/usbcdc11.pdf. and should be handled in the USBtoSerial code in the file USBtoSerial.c

    After much wrestling to understand Deans implementation of “handlers” I came up with the following fragment of code  which turns on led3 when the dtr line should be pulled low.

    #define SET_CONTROL_LINE_STATE_RTS_MASK 0x0002
    #define SET_CONTROL_LINE_STATE_DTR_MASK 0x0001
    EVENT_HANDLER(USB_UnhandledControlPacket)
    {
    uint8_t* LineCodingData = (uint8_t*)&LineCoding;
    uint16_t wValue;
    //Endpoint_Ignore_Word(); <- cant do this
    wValue = Endpoint_Read_Word_LE();
    /* Process CDC specific control requests */
    switch (Request)
    {
     case ....
     .... break;
     case SET_CONTROL_LINE_STATE:
     if (RequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
     {
      if (wValue & SET_CONTROL_LINE_STATE_DTR_MASK) {
        LEDs_TurnOnLEDs(LEDS_LED3); //handle DTR
      } else {
        LEDs_TurnOffLEDs(LEDS_LED3);
      }
      if (wValue & SET_CONTROL_LINE_STATE_RTS_MASK) {
         LEDs_TurnOnLEDs(LEDS_LED1); //handle RTS
      } else {
         LEDs_TurnOffLEDs(LEDS_LED1);
      }
      Endpoint_ClearSetupReceived();
      Endpoint_Setup_In_Clear();
      while (!(Endpoint_Setup_In_IsReady()));
     }
     break;
    }

    Two problems I had with grocking the original code were the presence of the mystery variables “Request” and “RequestType”. These variables are created by the macro EVENT_HANDLER(USB_UnhandledControlPacket). As this is a new library the documentation doesnt cover the nuances of the public interfaces build into it.

    The other was finding the data. I never did really figure out how I was supposed to figure this out but what I did find in the file DevChapter9.c was a comment

    Endpoint_Ignore_Word(); // Ignore unused Value word

    Which I realized was the wValue word from the usb documentation.

    Now I need to figure out enough about MyUSBs task manager to make a pulse and let the blinking lights stay on long enough to see them when sending and receiving data.

  • Breadboard Thingy (rethinking the ft323rl board)

    I sent my son to his mom’s with one of the USB Serial boards I built along with a breadboard, an RBBA a pile of resistors and an led array. I thought about this arrangement and decided that I would try to build a breadboard attached programmer that would not be dangling off the edge of the board and in the way.

    Board Positive (link to board at 600%)

  • A single sided ft232rl based arduino programming board.

    I was so happy with the boards I did the other day that I decided to make some small boards for the ft232 so that aidan would have a programmer for his breadboard RBBA. I made 20 of these boards .

    QTY Supplier Part number description cost
    1 DIGIKEY 604-00043-ND IC FTDI FT232RL USB-SRL 28-SSOP 4.02
    1 DIGIKEY 151-1121-ND CONN USB JACK TYPE B HORIZON R/A .85
    1 DIGIKEY 490-1035-1-ND FERRITE CHIP 30 OHM 1000MA 0603 .06
    3 DIGIKEY 399-1169-1-ND CAP .10UF 50V CERAMIC X7R 0805 .15
    2 DIGIKEY RHM220ARCT-ND RES 220 OHM 1/8W 5% 0805 SMD .07
    2 DIGIKEY 475-1400-ND LED 3MM 570NM GREEN CLR RADIAL .12


    Link to board image at 600%
     

  • Benito: My first at90USB162 project.

    Introduction.

    The Benito Board is an at90USB162 board intended for use in programming and communicating with microcontrollers which have serial based bootloaders.

    Among those are the Phillips lpc21xx series ARM chips, the Dallas Semiconductor, DS500x family and Atmels using any number of STK500 compatible bootloaders.

    In the case of the Atmel and Phillips chips, a reset pulse is required to put the device into programming mode. A logical trigger for this pulse is the DTR signal which is pulled low when the computer begins to talk to a given device.

    Background

    Recently on avrfreaks.net….

    Smileymicros wrote:

    Now that they have the AT90USB82 for $2,17 each per hundred at DigiKey, I’m forced to reconsider. Why the f*ck would I continue using the FTDI part which costs $3.89 each per hundred?Smiley

    It was not the first time I had had this question posed. Paul Stoffregen was talking about the new at90usb82/162 chips a few months back, its cheaper than the ftdi232 and has at least 2 driverless public usb-serial implementations: Dean Camera’s and Atmel’s. The best part is that it has a built in usb based bootloader and its a fully programmable AVR microcontroller. I thought it would be perfect to replace the ftdi ft232 series chips and to build an stk500 programmer with built in usb to boot. It seemed like the thing to do for many reasons.

    Hardware

    The sample code from both Atmel and MyUSB are based mostly on the AT90USBKey so I started with the schematic from that and cut out everything that I didn’t need. (a careful rereading of the datasheet says I am missing a 1uf cap here can you find it?).

    A little hard to read

    Click for larger image.

    Compared to the the ftdi boards I have been working on the parts count is pretty high but I am banking on flexibility to make it worth while.

    board positive

    Click for link to positive at 600%

    For the prototype I used my usual 1.5 sided board technique where the ground plain is brought to the top of the board and the alignment can be off by a couple of mm. The leds are some super bright ones in a plcc4 package that I have several hundred of. The pads in the eagle library for the are HUGE. I turned over the eagle files to Monty Goodson of bittybot.com who has lots of experience at getting things to be small so hopefully the final board will be a lot smaller.

    In the mean time feel free to use the Positive image above to create your own board

    The Programming Header

    At the moment I have a very Avr centric view of the universe. For that reason the programming header that made the most sense was a combination of a serial connection with the 6 pin isp connection. For target boards based on other processors such as the DS5000 and the LP21xxx the SPI pins can be repurposed and the software adjusted accordingly.

    Using the built-in boot-loader

    When you get power, usb, crystal, reset and hwb wired you can enter the chips usb boot-loader by holding HWB low during reset. If you have a mac like me and look look at the usb section of your system profiler you should see the following:

    device AT90USB162DFU:Version:    0.00
    
    Bus Power (mA):    500
    
    Speed:    Up to 12 Mb/sec
    
    Manufacturer:    ATMEL
    
    Product ID:    0x2ffa
    
    Serial Number:    1.0.5
    
    Vendor ID:    0x03eb

    You can now program the chip using FLIP if you are running winblows (sic) or dfu-programmer from sourceforge http://dfu-programmer.sourceforge.net/DFU stands for Device Firmware Update.

    Running dfu-programmer looks like this.

    $ dfu-programmer at90usb162 erase$ dfu-programmer at90usb162 flash --debug 20 USBtoSerial.a90
    
    target: at90usb162
    
    chip_id: 0x2ffa
    
    vendor_id: 0x03eb
    
    command: flash
    
    quiet: false
    
    debug: 20
    
    device_type: AVR
    
    ------ command specific below ------
    
    validate: true
    
    hex file: USBtoSerial.a90
    
    Validating...3182 bytes used (25.90%)
    
    $ dfu-programmer at90usb162 start

    I made the .a90 file from my modifications to Dean Camera’s sample code (to be described later) with the following voodoo.

    avr-objcopy -R .eeprom -O ihex USBtoSerial.elf USBtoSerial.a90

    Now on top of the blinking lights on the board an entirely different device is attatched to my usb port.

    
    

    The “Driverless” Serial Device.

    The USB standard is a lot about throwing several thousand dollars down so you can play as a member. Fortunately for the rest of us there are a couple of generalized devices that have generic definitions. one is the HID (human interface device) and the other is a CDC communications device under the CDC a class of devices is defined which looks like a modem (ACM). If a device says its one of these and acts accordingly most well developed operating systems will load a generic driver for them and just work. (and then there is windows which still requires a .inf file to load the generic driver). 

    Atmel’s Code Samples.

    As much as I love Atmels processors it is a constant source of irritation that their best tools are only made avaliable on the windows operating system. It was nice to see that the sample code for Atmel was avaliable for avr-gcc and I ran it up only to find myself picking through 5 layers of slashes “”. This is not just a preference it is bad coding practice. (to quote an old co-worker of mine “Its Rubbish — Bin it!)

    So I ran it up made it work and started looking at alternatives.

    This lead me to Dean Camera’s MyUSB library. Though it is still in development it is still easier to understand and work with than Atmel’s Code.

    crtusb162.o

    When compiling Atmel’s CDC code I wound up with a linker error complaining that crtusb162.o did not exist After recommending AVRMackPack for nearly 6 months I thought I had found my first bug. After rebuilding my own version of tool chain and digging around I found that it is a known bug and should be fixed in future releases. In the mean time the fix is easy. Either copy it from the avr3 library into your source or link the directory to avr35 where the linker should find it.

    #cd  /usr/local/AVRMacPack/avr-4/lib/#ln -s avr3 avr35
    
    

    Building the Firmware with MyUSB

    The firmware linked below under resources implements a USB serial port which produces a 2ms *reset pulse instead of DTR. It is based on the USBtoSerial Demo from version 1.3.2 of the MyUSB library. To build it unpack the MyUSB library into your work area. Then under the MyUSB library directory create a directory called Projects and unpack the Benito firmware into the Projects directory. If you have xcode (v>2.4) and AvrMacPack you can open the project and build it. Other platforms will have to adjust the Makefile to match their environment. the “make program” target defined in the make file uses the dfu-programmer utility so you can program the device using its built in bootloader.

    Results:

    By using Dean Camera’s MyUSB library I was able to create a serial programmer which plugs into Linux and OSX and it “just works”. I was able to produce the reset pulse in firmware and it continued to “Just Work”. You can see it above plugged into a modern device RBBA board running Limor Frieds AdaBoot. I was able to do this in a very short amount of time and while the hardware is slightly more complicated than the ft232 boards the cost at 100 boards is actually cheaper.

    Moving Forward

    In the photo below you can see my prototype boards (both sides) next to an ft232rl based programmer with a capacitor based “auto reset hack”. The board on the bottom shows the connection between an at90USB82 and a phillips Arm chip.

    On the Atmel side the next step is to implement an STK500 based programmer using the SPI port on the at90USB162. I expect that this will be a farely easy adaptation however I may revisit the DS500x chips that I have first and work out the best way to switch between the software modes. first. From there it would also be a no brainer to adapt the firmware for the lpc21xx chip pictured above.

    Resources

    
    
  • Arduino Programmer

    This was started at http://www.thing-a-day.com/2008/02/04/day-4-thing-4-aduino-adaboot-programmer/My Bulky Prototype

    It is part of the way that I do programming on the avr platform and the Arduino.

    I was using the programming half of a a bulky prototype that I have been working on to program an RBBa based maze solving mouse and I looked at the pile hanging precariously off of the coffee table and thought to myself.

    “I need to just build one of these. “

    The finished product
    Modifying Sparkfun Board. to fit in the box the input side
    flea assembly blinkin lights in place
    test run Translucence done  

    So I did.

    The programmer is based on the Auto-Reset Hack and the AdaBoot bootloader. The reset is pulled by putting a capacitor on the DTR line of the serial interface which is also the bootloader interface. Most people put the cap on the Arduino but I put it on the programmer (where it belongs). This programmer was built using the ftdi ft232rl breakout board sold by sparkfun. I had to trim it down to get it to fit in the pretty blue box i bought at Tap Plastics. The chip out of the box presents two of its 4 gpio (general pourpose i/o) pins to indicate when serial is being sent and recieved. I wired a pair of very bright leds that I had to them and then tried to pipe the light to the corners using some translucent plastic tubes and hot glue. It looks pretty cool!

  • The $15 Wiring Board

    This was started out as one of my things for Thing-A-Day (2008) (http://www.thing-a-day.com/2008/02/22/day-22-thing-22-the-15-wiring-board/)

    This follows my work getting the wiring software platform working on some generic mega128 boards. It is somehow related to my work on reducing the costs of the Arduino runtime to less than $4

    I recently found the code for an Stk500v2 based bootloader at http://www.avride.com/article/wiring/ for the new wiring platform. I have wanted to run wiring on several of the systems I have using the mega128 and the olimex header board that sparkfun sells. Between sparkfun and Ebay my per board cost is about 11 bucks. With the ftdi ft232rl usb to serial chip at $4 that would make the wiring platform affordable :)

    My initial attempt was using Wiring 0014 which seemed pretty darned broken. It didnt take long for 0015 to come out fortunately. Once I got the bootloader to work with wiring I realized that the wiring platform requires a 32khz clock crystal to be connected to tosc1 and tosc2. On the Olimex boards there is a space for this crystal. On some other boards like the Futulec ET-AVR-stamp this had to be soldered to the legs of the processor.

    Once this was added to the boards things started working. Below you can see the Futurelec ET-AVR-STAMP running my “antisocial” wiring program.

  • NDA Rolls (Apple Verses its Developers)

    I have spent more of last week wondering why X-Code wasnt signing my code and loading it onto the phone than successfully

    The introduction of the Iphone and the apple SDK for it seems to have created massive confusion and hurt for the two communities most effected by it.

    [Moderator] Re: Controlling Preferences on iPhone


    • Subject: [Moderator] Re: Controlling Preferences on iPhone
    • From: Scott Anguish <email@hidden>
    • Date: Fri, 18 Jul 2008 15:56:41 -0400
    • Delivered-to: email@hidden
    • Delivered-to: email@hidden


    iPhone SDK
    ----------

    Until an announcement is made otherwise, developers should be aware that the iPhone SDK is still under non-disclosure (section 5.3 of the iPhone Development Agreement). It can't be discussed here, or anywhere publicly. This includes other mailing lists, forums, and definitely blogs.

    This situation is somewhat different than a Mac OS X release, in that a Mac OS X release includes a copy of the developer tools with the distribution. The iPhone OS 2.0 release on devices and as an upgrade does _not_ include the development tools. As a result, the SDK is not automatically considered public because the release has occurred.

    Section 5.3 of the iPhone Development Agreement remains in force at this time, and will so remain until iPhone Developer Program members are specifically and personally notified by an authorized representative of Apple.

    On 18-Jul-08, at 10:07 AM, Aaron L'Heureux wrote:

    I have done some preliminary searching, but as I am still relatively new to the platform, I've not come up with an answer to this question. If anyone could help me out or point me in the right direction, I'd really appreciate it.

    Is it possible to programmatically change system preferences on the iPhone? Say I wanted to be able to turn location services on (at the request of the user of course) or to enable Bluetooth, or toggle a few of the sound alerts. Utilitarian stuff. Can this be done from an App Store application?

    _______________________________________________