ATMega USB Bootloader

Short description

This project is a software USB Bootloader for Atmel© ATMega µControllers. It is based on a software USB project v-usb .
This project includes build-scripts that are optimized for Windows Visual Studio nmake utility, you will have to modify the makefiles, if you intend to use another make-utility.
The Bootloader requires some definitions from the main project, such as the clock speed and the µController, that means the bootloader is not a standalone project, but it is intended to be included in another project, which will create the main application, and the bootloader.
The BootLoader is compatible with 'Usb Bootloader' in FirmwareUI, use FirmwareUI to communicate with this boot loader.
I have tested this bootloader with ATMega328p and with ATMega1284p devices, all running with a 12MHz crystal. The software USB also supports CPU frequencies 12.8 MHz, 15MHz, 16MHz, 16.5MHz, 18MHz and 20MHz, however the 18MHz version might need some modifications in avr/BootLoader/usbconfig.h, may have to set USB_CFG_CHECK_CRC = 1.
Please also read the data sheet for the specific µController, some devices specify lower clock speeds when operated at power less than 5 V.
A sample project using the bootloader can be found in 'ATMega Tutorial 1' and 'ATMega Tutorial 2' on this web site.
Note The compiled size of the USB Bootloader is about 3 KBytes, that means the target device must support bootloader with 4 KBytes or more (ATMega members with 32 KBytes Flash and more allow for 4 KBytes bootloader size), in other words you cannot use this bootloader with ATMega 8 or ATMega16 devices.

Directory Structure

I save all my µController projects in a base-folder, e. g. avr-development; Unpack the contents of the zip file into the base-folder, which will result in the subfolders

BASE_FOLDER\avr\BootLoader contains the specific files for the USB Bootloader, BASE_FOLDER\avr\SoftUsb contains all the files to build the software USB device from obdev, v-usb .
The application project should be located in a subfolder under BASE_FOLDER, e. g. BASE_FOLDER\MyApplication. The buildfile will be executed from BASE_FOLDER, e. g. nmake -f MyApplication\makefile, which should call nmake -f ./avr/BootLoader/UsbBootLoader.mak with all required parameters, see list below.

Build Parameters

The main buildfile must pass some parameters to the BootLoader build scripts. These Parameters are required:


The file usbbootconfig.h should reside in the application folder, it defines the hardware pin assignement for the USB socket. There is s sample file defusbbootconfig.h in the BootLoader-folder which describes the settings.

Communication Protocol

This bootloader implements a HID device using public vendor and product id's, VID = 0x16c0, PID = 0xdf05. The vendor name is "www.loewenwasser.de", and the Device name is "CUsbBootLdr".
The HID report descriptor defines two Report IDs, Report 1 has a length of 16 Bytes, Report 2 has a length of 34 Bytes.

Report 1 read:


Report 1 write:
Report 2 read:
Report 2 write:

Installation

Download UsbBootLoader.zip and unpck the contents to your BASE_FOLDER as described above.

Known issues

It may happen very rare that the software USB disconnects while flashing the application on ATMega 1284p devices (never saw it with ATMega 328p). I guess that this is a timing issue when disabling interrupts to write the device, but I could not yet fix it, all interrupts are re-enabled as fast as possible...
I therefor recommend to burn the BOOTRST fuse (please also set the parameter BUILD_OPTIONS="-DBOOTRST=1") to start the µController in the bootsection.
Reset the µController if this happens, the USB should reconnect, and you may flash the application again.

Version Info


Comments


Rate this page
You may rate this page in the range 1 (not useful) ... 5 (very useful)
Hit the ´Submit´ button to save your rating (the numbers in brackets equal the actual count).

1[0]   2[0]   3[0]   4[0]   5[0]