Tag: DorkBotPDX

  • Running Paul Stoffregons’s teensy_serial arduino core on DFU based chips.

    das blinkin
    das blinkin

    With a lot of my projects I have done my prototyping with Paul Stoffregon’s Teensy series of boards before moving them onto their own codebases. On those occasions where the “prototype was all I needed” I would compile the code using the teensyduino and then manually load the .hex file onto the target. As I am looking at using the arduino for more projects I decided to take a look at how paul interacts with the Arduino IDE and see if I could load code directly onto my chips.

    boards.txt

    The arduino allows for different chips and configurations through the boards.txt and the programmers.txt files. Each configuration usually will also have a “core” which maps the pins and handles the particulars of that chip. When you run paul’s teensyduino installer it adds several entrys to the boards.txt file including the entry below.

    teensy_ser.name=Teensy 1.0 (USB Serial)
    teensy_ser.upload.protocol=halfkay
    teensy_ser.upload.maximum_size=15872
    teensy_ser.upload.speed=38400
    teensy_ser.upload.disable_flushing=true
    teensy_ser.upload.avrdude_wrapper=teensy_reboot
    teensy_ser.build.mcu=at90usb162
    teensy_ser.build.f_cpu=16000000L
    teensy_ser.build.core=teensy_serial
    teensy_ser.build.post_compile_script=teensy_post_compile
    teensy_ser.name=Teensy 1.0 (USB Serial)
    teensy_ser.upload.protocol=halfkay
    teensy_ser.upload.maximum_size=15872
    teensy_ser.upload.speed=38400
    teensy_ser.upload.disable_flushing=true
    teensy_ser.upload.avrdude_wrapper=teensy_reboot
    teensy_ser.build.mcu=at90usb162
    teensy_ser.build.f_cpu=16000000L
    teensy_ser.build.core=teensy_serial
    ...
    Looking at pauls additions to the boards.txt I see that he is using the teensy_serial core  that he has written to create a simple usb to serial interface and to map the usb avr pins and other peripherals to the arduino conventions. He is also adds an entry to the arduino uploader class which lets him use a wrapper for avrdude which lets him use his proprietary bootloader. This wrapper is installed by the Paul’s installer and  lives in the Arduino’s bin directory. After looking to see if this wrapper was a script I replaced the entry in the boards.txt and put a script into the bin directory called “dfume”, after seeing that my replacement wrapper worked I added two new entries for each class of avr that I wanted to use the atmega32u2 and the atmega32u4
    #############################################################
    fouryou.name = atMega32U4
    fouryou.upload.protocol=atmega32u4<
    fouryou.upload.maximum_size=32256
    fouryou.upload.speed=38400
    fouryou.upload.disable_flushing=true
    fouryou.upload.avrdude_wrapper=dfume
    fouryou.build.mcu=atmega32u4
    fouryou.build.f_cpu=16000000L
    fouryou.build.core=teensy_serial
    #############################################################
    tooyou.name = atMega32u2
    tooyou.upload.protocol=atmega32u2
    tooyou.upload.maximum_size=32256
    tooyou.upload.speed=38400
    tooyou.upload.disable_flushing=true
    tooyou.upload.avrdude_wrapper=dfume
    tooyou.build.mcu=at90usb162
    tooyou.build.f_cpu=16000000L
    tooyou.build.core=teensy_serial
    #############################################################
    
    fouryou.name = atMega32U4
    fouryou.upload.protocol=atmega32u4
    fouryou.upload.maximum_size=32256
    fouryou.upload.speed=38400
    fouryou.upload.disable_flushing=true
    fouryou.upload.avrdude_wrapper=dfume
    fouryou.build.mcu=atmega32u4
    fouryou.build.f_cpu=16000000L
    fouryou.build.core=teensy_serial
    
    #############################################################
    
    tooyou.name = atMega32u2
    tooyou.upload.protocol=atmega32u2
    tooyou.upload.maximum_size=32256
    tooyou.upload.speed=38400
    tooyou.upload.disable_flushing=true
    tooyou.upload.avrdude_wrapper=dfume
    tooyou.build.mcu=at90usb162
    tooyou.build.f_cpu=16000000L
    tooyou.build.core=teensy_serial
    

    I started with a blank script that just printed the arguments passed to the wrapper and then called it by restarting my Arduino (to reload the boards.txt) And then selecting one of the new boards and “Uploading” my code. This gave me a window to interactively work through my script. Since the avrdude_wrapper code just pretends to be an avrdude most of the script is munging the arguments passed to avrdude to get the commands to pass to dfu-programmer.

    #!/usr/bin/perl
    use Getopt::Std;
    print @ARGV;
    my %args;
    my $hexfile;
    my $dfu = "/usr/local/bin/dfu-programmer";
    my $cpu;
    my $hexfile;
    
    getopt('pUc',%args);
    $hexfile=$args{U};
    $hexfile =~ s/flash:w://;
    $hexfile =~ s/:i//;
    $cpu=$args{c};
    
    print "n[" . $hexfile . "]";
    print "n[" . $cpu . "]n";
    print "$dfu $cpu erasen";
    system "$dfu $cpu erase";
    print "$dfu $cpu flash $hexfilen";
    system"$dfu $cpu flash $hexfile";
    print "$dfu $cpu startn";
    system "$dfu $cpu start 1>&2";
    print "n";
     

    There is one tricky bit. The current avr-gcc doesnt support the atmega32u2 correctly but the code for the at90usb162 is binary compatible so the build.mcu is set to the at90usb162. But then dfu-programmer supports the correct chip and wont find the device so we use the fact that the upload.protocol argument is passed directlyalong using the -c argument and everything works fine.

    So now we just use the hwb and reset buttons to get the system into dfu mode and upload our code directly from the arduino. Its not as slick as the teensy in “auto” mode but it works.

  • Reprogramming your avr-usb device using atmel’s built in bootloader

    Getting code onto the MidiMonster or Benito device.

    Midi Monster Button Locations.
    Midi Monster Button Locations.

    Benito 7g Switch Positions.
    Benito 7g Switch Positions.

    Benito 2010 Switch Locations
    Benito 2010 Switch Locations

    Benito Without Buttons.
    Benito Without Buttons.

    All of the code on the Benito and MidiMonster devices is open source and references an open source library called the Lightweight Usb For Avr (lufa). Getting the code compiled and onto the device requires a few other open source tools.

    AVR-GCC

    The most current and stable release of the toochain for the AVR has untill recently been maintained by Eric Wedddington and released as WinAvr (http://sourceforge.net/projects/winavr/) Winaver integrates nicely into atmels avr studio http://www.atmel.com/dyn/Products/tools_card.asp?tool_id=2725 and I reccomend that you get both if you are running windows. Each Winavr Release is closely followed by objective developments CrossPack for avr http://www.obdev.at/products/crosspack/index.html and a script for building the current toolchain on linux which is hosted by AvrFreaks at present there is also a debian package that was put out last month http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=90172

    HWB? DFU?

    Most Atmel “atmega” devices have a pin dedicated to determining weather or not the device goes into the bootloader depending on the devices flag settings. This pin is labled HWB (for hardware boot) on most of  the datasheets. The usb avr family has this mode set up by default. When you hold the hwb pin low and reset the device it goes into the bootloader. On these devices the built in bootloader uses a usb device class called the Device Firmware Uploader (DFU). Atmel provides a tool called flip for programming DFU devices on  windows and linux. There is an open source programmer called dfu-programmer http://dfu-programmer.sourceforge.net/

    That other guys stuff.

    Those of you who have worked with the teensy boards from paul stoffregon will notice some subtle differences. Paul wrote his own (closed source) bootloader rather than use the bootloader tha comes installed on the chips. Then he uses a hardware trick similar to the auto reset hack to make a single button manipulate both the reset and the hwb pins to put his boards into the bootloader. I didnt feel that either the two button arrangement or the builtin bootloaders were broken so I like most people working with these chips dont fix them.

    Using the dfu-programmer

    All of the programs in Dean Cameras Lightweight Usb for Avr have a “dfu” target. Once you have the target into the DFU mode you can simply

    $make dfu

    This will cause the dfu-programmer to erase the flash reprogramm it with a new hex file and restart the chip. You can also do this manually with the following commands

    $dfu-programmer atmega32u2 erase
    $dfu-programmer atmega32u2 flash mycode.hex
    $dfu-programmer atmega32u2 start

    This will cause the dfu-programmer to erase the flash reprogramm it with a new hex file and restart the chip.

  • 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

  • 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%
     

  • 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!