You are on page 1of 6

lOMoARcPSD

Seminar assignments - Week 2 lab - AVR Bootloader


Installation

Mechatronic System Design I (University of Newcastle (Australia))

Distributing prohibited | Downloaded by Chloe Warner (chloe.jaide@gmail.com)


lOMoARcPSD

School of Engineering, Discipline of Mechanics and Mechatronics, pp. 15

AVR bootloader lab


MCHA3000

Semester 2 2013

The University of Newcastle, AUSTRALIA MCHA3000 S2 2013

Distributing prohibited | Downloaded by Chloe Warner (chloe.jaide@gmail.com)


lOMoARcPSD

School of Engineering, Discipline of Mechanics and Mechatronics

1 Introduction

In this lab, you will compile and install a bootloader, onto the Atmel AVR ATmega32 microcontroller.
The bootloader is a small piece of software that resides in the flash memory of the microcontroller
that allows the remainder of the flash memory to be programmed via the serial interface. Once the
bootloader is installed, there should be no further need to use a hardware programming tool.

2 Preparing the hardware

You will be provided with the items listed in this section. The breadboard and the three breakout
boards must be returned at the end of the semester. The remaining components may be transferred
to your PCB once it has been manufactured.

Breadboard w/ breakout boards (on loan): 1 0.1F monolithic capacitor


1 Breadboard with 1660 tie points 3 100 resistor
1 DB9 breakout board Serial interface components:
1 AVR ISP breakout board 1 MAX232 or equivalent driver IC
1 PSU breakout board
5 1F tantalum capacitor
Microcontroller components:
Bootloader and reset switch:
1 AVR ATmega32 or ATmega32A micro-
controller 1 Large SPST tactile switch (BTLDR)

1 14.7456MHz crystal 1 Small SPST tactile switch (RESET)

2 22pF or 33pF ceramic capacitor 2 10k resistor

Prototype the the basic microcontroller circuit and serial communication interface from the given AVR
circuit reference design (see atmega2010_v1.2.pdf on Blackboard). There are extra features on the
reference design that are not required for this lab, such as the additional breakout pins, 3.3V regulator
and IMU interface. Some component values in the reference design may differ from those provided,
seek clarification from your tutor if you are unsure.

3 Preparing the software

We will be using Atmel AVR Studio 4 and WinAVR as our development environment. These should
already be installed on the computers in ES313, however there are some known issues. If you are on
campus, or otherwise have access to the University intranet, the latest installation and troubleshooting
instructions can be found at
http://mtronics.newcastle.edu.au/wiki/index.php/WinAVR_and_AVR_Studio_installation_and_
troubleshooting.
If you would like to setup these tools on you own PC to bring to the lab, do the following:

Distributing prohibited | Downloaded by Chloe Warner (chloe.jaide@gmail.com)


lOMoARcPSD

MCHA3000 - AVR bootloader lab

1) Download and install WinAVR 20100110


http://sourceforge.net/projects/winavr/files/WinAVR/20100110/WinAVR?20100110?install.
exe/download
2) Download and install Atmel AVR Studio 4
http://www.atmel.com/dyn/resources/prod_documents/AvrStudio4Setup.exe
3) Download and unzip CoolTerm
http://freeware.the-meiers.org/CoolTermWin.zip
4) Download and install the Olimex AVR-ISP500 USB driver
https://www.olimex.com/Products/AVR/Programmers/AVR-ISP500/resources/AVR-ISP500-Drivers.
zip
5) Download and install the ATEN UC232A USB driver
http://www.aten.com/download/export.php?mid=20130621160333002&type=driver
Note: If AVR Studio will not start after the installation, you may need to restart your computer.

4 Compiling the bootloader

1) Download avrprog_boot_v0_85.zip from Blackboard and extract to a local folder.


2) Open AVR Studio 4 and at the welcome screen click the Open button and navigate to
main.aps in the folder you extracted the bootloader to, and then click Open.
3) From the left treeview pane, navigate to Other Filesmakefile and double click to open.
4) Find the MCU block and make sure that the only uncommented line is the one which contains
atmega32.
5) Save the file (Ctrl+S).
6) From the left treeview pane, navigate to Source filesmain.c and double click to open.
7) Locate the #define F_CPU line and change the frequency to 14745600.
8) Locate the #define BAUDRATE line and set it to 115200.
9) Locate the 4 lines which #define the bootloader start pin and start port (BLPORT, BLDDR, BLPIN
and BLPNUM). Modify these to suit the pin that is connected to the BTLDR button.
10) Save the file (Ctrl+S).
11) Compile the project using BuildBuild or by pressing F7. If successful, the compilation
should finish with Build succeeded with 1 Warnings. . . . The output file is main.hex.

5 Using the programmer

1) Connect the programmer to the 10 pin ISP breakout board, and the computers USB port.
2) Using device manager (Win+Pause), find the COM port number the programmer is using.

Distributing prohibited | Downloaded by Chloe Warner (chloe.jaide@gmail.com)


lOMoARcPSD

School of Engineering, Discipline of Mechanics and Mechatronics

3) Within AVR Studio, click ToolsProgram AVRConnect. . . and select STK500 on the
left pane, and the appropriate COM port in the right pane. Click Connect. . . .
4) From the Main tab, click Read Signature to confirm the ATmega32 is correctly identified.
5) From the Fuses tab, set the fuse bits as shown in Figure 1.

Figure 1: Correct fuse settings.

If correct, the fuse bits should be HIGH=0xD2 and LOW=0xEF.


Note: If you dont have these correct, you may brick the microcontroller. Double-check the fuse
bits before you continue.
6) Once the fuse bits are set correctly, click Program. It should automatically verify the fuse bits
after programming and report OK!.
7) From the Program tab, set the Input HEX file (in the Flash control group) to main.hex

Distributing prohibited | Downloaded by Chloe Warner (chloe.jaide@gmail.com)


lOMoARcPSD

MCHA3000 - AVR bootloader lab

you compiled earlier.


8) Click Program (within the Flash control group). It should automatically verify the program
flash after programming and report OK!.
9) Close the programmer dialog box and disconnect the programmer.
10) Connect a serial cable from the DB9 breakout board to the PCs serial port (or a USB to RS232
adaptor if you are using your own laptop).
11) Open a terminal application (e.g., CoolTerm) and connect via serial using 115200 baud, 8 data
bits, 1 stop bit, no parity and no hardware handshaking.
12) While holding down the BTLDR button, press and release the RESET button and then release
the BTLDR button. This restarts the microcontroller and runs the bootloader, which is used to
program the application flash memory.
13) Send a capital S character, and the microcontroller should reply with the string AVRBOOT.
Demonstrate this to your tutor.
Note: Try to avoid sending other characters as you may inadvertently modify the fuse or lock
bits on the microcontroller.

Recommendations

Here are some suggestions on what you should work on next:


Consult the ATmega32 datasheet to see what function the various fuse and lock bits have.
Explore the bootloader source code to see other ways to configure the bootloader (e.g., startup
delay instead of pulling a pin low).
Have a look at how RS232 communication is performed in the bootloader source code. Hint:
This may be a useful example to study for a future lab.
Familiarise yourself with the avr-libc documentation (http://www.nongnu.org/avr-libc/user-manual/).

Distributing prohibited | Downloaded by Chloe Warner (chloe.jaide@gmail.com)

You might also like