Burning the Arduino Bootloader with an AVR STK500 Development Board

I recently discovered that we had an old AVR STK500 development board lying around at work and when I had some free time I decided to play with it and see if I could use it to burn the Arduino Bootloader onto some old ATmega168 chips we had lying around. I was somewhat overwhelmed by this board as it had so many jumpers and connectors on it that I didn’t have a clue where to begin, on top of that there was no manual to be found or even a model number on it to look up — the only identifier it had on the board was the Atmel AVR logo. I was only able to find a model number for it after digging through pages of images that came up on a Google search, once I found a picture of the same board I found my way back to this page which gave me the information I needed. From there I was able to dig up the manual as well as a few extremely outdated guides on setting it up to program an ATmega chip with a bootloader. After much frustration I finally managed to get the code to flash.

You Will Need

Configuring the STK-500

This is the trickiest part of the setup, if you have the manual you’ll be following the directions for the ATmega8 device. The configuration is exactly the same for the ATmega168 as well as the ATmega328. To make sure there is no confusion, if I say to the right I’m referring to the side with the power and two RS232 ports, and the left would be the opposite side where you’ll see a row of push buttons. Though this should go without saying, make sure you have the power disconnected from the board and you are properly grounded so that you do not cause any E.S.D. damage to your board or components.

First you’ll be setting some jumpers. Place a jumper across the pins for VTARGET, AREF, RESET and XTAL1. Next you’ll place a jumper over the two right-most pins of OSCSEL. You’ll also be installing two jumpers on the PJUMP pins, be sure to connect the top two pins with one jumper and the bottom two with another, so the jumpers will be running left to right. The next jumper will be one of the trickier ones, you will need a longer jumper wire and you will be running it from the right most pin of BSEL2 to the pin labeled PC2 which is located in the bank of pins labeled PORTC which is to the bottom left side of the development board.

Next you’ll be running two ribbon cables across the board (as seen in section 3.7.2.1 of the manual). You’ll be connecting the PROG DATA header to the PORTB header as well as connecting the PROG CTRL header to the PORTD header. I’ve included figure 3-17 from the manual to demonstrate this:

Arduino STK500

Finish up by placing the chip into the socket labeled SCKT3200A2 which is the one outlined in Green. Pay attention to the small notch on the left edge of the socket, this will match up with a notch on one end of the chip.

Burning the Bootloader

Quick Sheet:

  • Tools
  • Program AVR
  • Connect…
  • Platform: STK500
  • Port: COM1
  • Connect…
  • Tab: Main
  • Device: ATMega168 (or as desired)
  • Programming Mode and Target Settings: PP/HVSP mode
  • Tab: Program
  • Select the HEX file for your chip
  • Click Program
  • Tab: Fuses
  • Extended: 0xF8
  • High: 0xDF
  • Low: 0xFF
  • Program
  • Tab: LockBits
  • Lockbit: 0xFF
  • Program

Unlike when using an ISP programmer through the Arduino software there are a few more things to do than just click “Burn Bootloader.” For just the cliff notes follow the list on the right, or to jump to the video, otherwise keep reading. If you’ve just opened the software for the first time and it’s asking you to start a new project or open one, you’ll actually want to hit cancel. Now in your IDE select the Tools menu and then Program AVR and then select Connect… Now you’ll be presented with a screen asking about the LockBits, click back to the Main tab and select your Device and set the programming mode to HVSP. Before leaving this tab I recommend hitting Read Signature to to see if it reads the device fine, if it’s not hooked up right it will likely fail at this point.

Move on to the Program tab and then load your hex file. You’re going to need the right hex file for the chip and board you’re going to be working with. So go into your Arduino folder (e.g. C:\Program Files\Arduino\) under the Hardware\arduino\bootloaders\ and start looking for one that makes the most sense. If you don’t have the Arduino software installed yet or on this computer then another good source is LeafLabs on Google Code. To be honest I’m not sure what the difference is between all the bootloaders, I just use the one in the atmega8 folder and have had no issues. It’s also only 3kb verses 30kb which is the one whose name best maches the ATMega168 chips I’m using in this example. Once you’ve loaded the file into the AVR Studio under the Flash heading you can go ahead and hit program. I always have the options to erase the chip and verify afterwards, so if you don’t you may want to do that manually. If there are no errors in the bottom text move on to the Fuses tab.

Under the Fuses tab you will have to set some hex values. For the ATMega18 I was using in this example I had to set Extended to 0xF8 then High to 0xDF and Low to 0xFF. This may vary depending on the chip so make sure to look it up before hand. Before moving on click Program and check the log for errors.

Finally, check the LockBits page. These seem to reset to 0xFF after every program action so set them to 0xCF and hit Program.

At this point your bootloader should be burnt onto your ATMega chip and you should now be able to use it in your Arduino board. So pop it out of the STK500 and back into your Arduino board and fire up the software. From the examples menu select Blink and upload it to your device. If the LED alternates between on and off endlessly then you are ready to rock.

Tags: , , , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS
read comments

Burning the Arduino Bootloader with the AVR Dragon

The AVR Dragon is a little more of an expensive route to go if you’re looking to burn Arduino Bootloaders. They can ring in around $50 per unit, though they do come in a beautiful red box with a dragon painted on it. The USBTinyISP is about $10, for comparison, and will get the job done just as easily — actually, it’s easier. So if you’re going out to buy a programmer I’d recommend the USBTinyISP, however, if you’re lucky like me and have tons of gadgets like this lying around at work to play with then it’s certainly a viable option. I found this unit hiding in a dusty box on a shelf, seemingly forgotten as no one in knew what it was or why we had it, even though I already had an STK500 hooked up and ready to go as well as a USBTinyISP at home I thought I’d fire it up just for the experience.

The first thing you’re going to need is AVR Studio. Even if you’ll be burning your bootloader through the Arduino program you’ll still need AVR Studio for the drivers. Unfortunately I could not locate stand alone drivers and was forced to download all 600mb of AVR Studio for this purpose only, so I suggest starting that process first so you can get everything else ready while it downloads.

You Will Need

Setup the AVR Dragon

In this example I’ll be using the 6 pin ISP header which I will connect to my Arduino board. The AVR Dragon can do High Voltage Programming (HVSP) if you solder on a DIP or ZIF socket on the breadboard area to the right side. See this Instructables Guide for instructions on how to do that.

Unlike setting up the STK500 for HVSP programming the setup for the AVR Dragon in ISP mode is a breeze. The only “gotchya” is when hooking up the ISP cable make sure to align the cable so the wire with the red stripe matches the Pin 1 marker on each end. The AVR Dragon does provide power to the destination board via the VCC headers but I found it’s easier to power the Arduino by hooking it up to another USB cable or via a walwart adapter. Once both boards have power and are connected via the ISP header you are ready to fire up AVR Studio and program the bootloader onto the chip.

Programming it in AVR Studio 4

AVR Studio is a free program that only requires you register with AVR in order to download it. AVR Studio 5 is now available, and is the recommended software for this task, but this guide will stand for all who have not yet chosen to update.

After loading the program you will be prompted to create a new project or load an old one. We will do neither so hit Cancel and then on the main menu select Tools -> Program AVR -> Connect…. Now select the AVR Dragon as your platform and the USB Port and then click Connect again.

On the next screen select your device, in this case the ATmega168, and select ISP as your Programming Mode. I always hit Read Signature to make sure everything is connected properly. Now move on to the Program tab and under the Flash section select your HEX file. They can be found in your Arduino installation directory, check /hardware/arduino/bootloaders and you will find several variations there, more can be found online. After you have loaded the correct one hit Program and then when complete move to the next tab.

Next you’ll sit the Fuse settings. The correct settings for the ATmega168 chip are 0xF8, 0xDF, 0xFF but make sure to use the correct settings for the chip you are using. Click Program then go to the Fuse Bits tab and set it to 0xCF and hit Program again.

At this point your Arduino is ready. You can plug it in as per usual and upload a Sketch in the Arduino software. I usually start by loading the Blink program as it is a quick and easy way to test the bootloader as the built in LED on Pin 13 will allow you to easily access if the program is running. Make sure to upload a sketch again to make sure your lock bits were set properly, as if they are not the sketch will overwrite the bootloader and a subsequent upload will fail.

Programming it in AVR Studio 5

AVR Studio 5 is the new and improved way to build your AVR programs. It runs off the Visual Studio Shell which gives .Net developers an “at home” feeling when using the software. Beyond that I couldn’t tell you what the extra features are as I only use it for programming the bootloaders and everything else I do right in the Arduino software. The software can still be downloaded for free after registering, and is unfortunately about 600mb to download, which is a lot for what we’ll be doing today.

Uploading the bootloader is pretty much the same. Start off by going to Tools then AVR Programming. On the next window select AVR Dragon as your Tool and ATmega168 as your Device. Then ISP as your Interface then click Apply. Click Read for both Device ID and Target Voltage to make sure everything is hooked up correctly and to initialize some settings.

Jump to the Memories tab and under Flash select your HEX file from the Arduino folder. They can be found in /hardware/arduino/bootloaders or easily found online. Make sure to load the proper HEX file for the chip you are working with, in this case we are using an ATmega168 chip so the file I use is ATmegaBOOT_168_atmega328.hex since I was too lazy to complile the ATmegaBOOT_168.c file. Once the proper file is loaded click Program.

Now move on to the Fuses tab and set them to 0xF8, 0xDF, 0xFF and then hit Program before moving on to the Lockbits tab where you will set it to 0xCF before hitting Program again. Once again, verify the settings for your chip as they will vary. You may also want to tweak them to your own needs, for instance you may want to use the internal oscillator to run the chip at 8 MHz instead of the 16 MHz you get with the external crystal. The lockbits will be configured to prevent the bootloader from being wiped each time you upload a sketch, so if you’re bootloaded chip only works once through the Arduino software’s upload method, then you likely forgot to set the lockbits or didn’t set them correctly.

Testing Your Bootloaded Chip

After flashing the bootloader you can disconnect the ISP header and plug the Arduino board into your USB port before loading the Arduino software. Once it is loaded open the Blink sketch and then select your board and port before uploading. The blink sketch is the best tool for testing a chip as Arduinos now come with a mini LED and a resistor already installed on Pin 13 which this sketch is configured to use. Please note that older versions of the Arduino only had the 1k ohm resistor preinstalled so it will still need an external LED on Pin 13. If your sketch uploads without an error you shouldn’t have any problems, but either way I suggest watching the LED for a few seconds to ensure that it alternates between on and off, if it does this then upload the sketch one more time to make sure you didn’t set the lockbits wrong. If it works the second time then your bootloaded ATmega is ready to go!

Tags: , , , , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS
read comments

How to Reset a Drupal 7 Password

After abandoning one of my Drupal 7 sites for some time I decided to buy a domain for it and start working on it again. I immediately ran into a case of “Oops I forgot the password” and could not log in, eventually getting my account locked out. This is what happens every time I try and come up with a more clever password. Unlike in previous versions of Drupal it’s not a matter of just slapping an MD5 around a password when updating the database. With Drupal 7 you have to make use of a salted sha512 hash, the easiest way to do that is to create a file in your installation server with the password you want to convert and when you run it you will get your encrypted password echoed out to you. Simple enough! So here’s the code:

<?php
// $Id: index.php,v 1.99 2009/10/15 14:07:25 dries Exp $

/**
 * @file
 * The PHP page that serves all page requests on a Drupal installation.
 *
 * The routines here dispatch control to the appropriate handler, which then
 * prints the appropriate page.
 *
 * All Drupal code is released under the GNU General Public License.
 * See COPYRIGHT.txt and LICENSE.txt.
 */

/**
 * Root directory of Drupal installation.
 */
define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

require_once 'includes/password.inc';
echo user_hash_password('your_new_password');
die();

menu_execute_active_handler();

?>

Simple browse to this file in your web browser and it will output your new salted password. Take that password and then go into PHPMyAdmin (or your favourite MySQL client) and then browse to your users table, there you can paste it in as the new password. Make sure not to use the password() or md5() functions when editing the field as it needs to be stored as plain text.

Thanks to Conclusion on Drupal.org for presenting this conclusion.

Tags: , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS
read comments
 Page 3 of 51 « 1  2  3  4  5 » ...  Last »