[dorkbotpdx-blabber] How does the AT90USB162 bootloader know of which method

Paul Stoffregen paul at pjrc.com
Mon Jun 30 16:59:33 EDT 2008


> I was just wondering how does the AT90USB162 know which particular
> programming method is to be used?

There are 3 fuse bytes and 1 lock byte that configure the chip.

There is a parallel programming option which can never be disabled.  It 
is activated by +12 volts on the reset pin, and nearly all the pins are 
required for programming the chip.  If the chip is locked, it must be 
erased before changes can be made.  Once unlocked, the fuse bits and all 
memory can be changed.  Almost nobody uses the parallel mode, except 
dedicated eprom programmers.

If enabled by the fuse bits (and it is enabled by default), the chip can 
be programmed using ISP mode, which the datasheet calls "serial 
downloading".  While the chip is in reset, the MISO, MOSI and SCLK pins 
are used to program the chip.  This mode has complete access, just like 
the parallel mode, including changing the fuses.  It is possible to 
change the fuse bit that disables this mode, and if you do that after 
rebooting this mode will be permanently disabled (unless you use the 
parallel mode to change the fuse bit disabling it).

There are 2 other fuse bit that configure if the boot loader will always 
run after reset, or the main application will always run after reset, or 
if the HWB (PD7) pin will control which one gets run.  Atmel ships the 
chip with a default setting of HWB controlling which gets run after 
reset.  If you have not changed the fuse bits, that is what your chip 
will do.

The bootloader can not change the fuse bits.  If you have only ever 
programmed the chip using the bootloader Atmel ships pre-programmed into 
the chip, you can be sure the fuse bits are still in their default 
configuration.

There is also a fuse that enables DebugWire mode.  By default it is 
disabled.


>  If I hold nHWB low and pulse the RESET
> line, how does it know it is supposed to talk to the PC with the USB
> port and not JTAG or ICSP?

There is no JTAG port, so that is never an option.

So, how exactly does it "know" which mode?  First, if the reset pin has 
+12 volts, you're in parallel mode.  If reset is low (the chip is not 
running), and the serial mode is enabled by the fuse bits, then it 
listens for programming on the SPI pins.  Likewise, if DebugWire mode is 
enabled by the fuse bits, it listens for the (closed, proprietary, 
undocumented) debugwire activity on the reset pin.

Even if the fuse bit enables the "serial downloading" mode (ICSP or 
ISP), that mode is only active while reset remains low.  Once your reset 
pulse ends, that mode is no longer available.

When reset allows the chip to start running (or the brownout or startup 
timer acts as reset, also configured by fuse bits), the 2 fuse bits 
determine if it will run starting at 0x0000 or the bootloader start 
address (which is programmable via fuse bits in 4 different bootloader 
sizes), or if the HWB pin is checked to determine which to run.

While the chip is running in the bootloader section, and if the lock 
bits permit it, the SPM instruction can be executed to write to the 
flash memory.  The SPM instruction is never enabled if code is running 
in the application section.


If the fuses are still in their default state, your holding HWB low will 
cause the bootloader to run when reset goes high.  If Atmel's DFU 
bootloader is still in the memory, it will begin talking on the USB port 
and your PC will enumerate the USB device.  If you have only ever used 
the bootloader, there is no way you could have ever changed the fuses, 
and my limited understanding of Atmel's default bootloader is that it 
doesn't allow overwriting itself.

If you've programmed a different bootloader (as I do) and/or changed the 
fuse bits, the chip will do whatever you have configured.  The 
documentation for all this, by the way, is in chapter 25 of the datasheet.


-Paul




More information about the dorkbotpdx-blabber mailing list