Skip to content

Instantly share code, notes, and snippets.

@makestuff
Created November 19, 2013 17:35
Show Gist options
  • Select an option

  • Save makestuff/7549194 to your computer and use it in GitHub Desktop.

Select an option

Save makestuff/7549194 to your computer and use it in GitHub Desktop.
Strange behaviour with programmatic launching of the bootloader with firmware larger than 8KiB.
$ avr-gcc -v
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.5.3/lto-wrapper
Target: avr
Configured with: ../src/configure -v --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-libssp --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=avr
Thread model: single
gcc version 4.5.3 (GCC)
$
$ # Fetch the code
$ mkdir $HOME/avr
$ cd $HOME/avr
$ wget -q http://www.swaton.ukfsn.org/temp/main.c
$
$ # Compile & link to 8192 bytes...
$ avr-gcc -mmcu=at90usb162 -DF_CPU=16000000UL -DFLASH_SIZE_BYTES=16384 -DBOOTLOADER_SEC_SIZE_BYTES=4096 -O2 -funsigned-char -funsigned-bitfields -ffunction-sections -fno-inline-small-functions -fpack-struct -fshort-enums -fno-strict-aliasing -Wall -Wstrict-prototypes -std=c99 main.c --output firmware.elf -Wl,-Map=firmware.map,--cref -Wl,--relax -Wl,--gc-sections
$ avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock firmware.elf firmware.hex
$ lsusb | grep 03eb:2ffa
Bus 002 Device 074: ID 03eb:2ffa Atmel Corp.
$ dfu-programmer at90usb162 erase
$ dfu-programmer at90usb162 flash firmware.hex
Validating...
8192 bytes used (66.67%)
$ dfu-programmer at90usb162 reset
$ sleep 5; lsusb | grep 03eb:2ffa
Bus 002 Device 075: ID 03eb:2ffa Atmel Corp.
$
$ # Now compile & link to 8194 bytes...
$ avr-gcc -mmcu=at90usb162 -DTHE_LAST_STRAW -DF_CPU=16000000UL -DFLASH_SIZE_BYTES=16384 -DBOOTLOADER_SEC_SIZE_BYTES=4096 -O2 -funsigned-char -funsigned-bitfields -ffunction-sections -fno-inline-small-functions -fpack-struct -fshort-enums -fno-strict-aliasing -Wall -Wstrict-prototypes -std=c99 main.c --output firmware.elf -Wl,-Map=firmware.map,--cref -Wl,--relax -Wl,--gc-sections
$ avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock firmware.elf firmware.hex
$ dfu-programmer at90usb162 erase
$ dfu-programmer at90usb162 flash firmware.hex
Validating...
8194 bytes used (66.68%)
$ dfu-programmer at90usb162 reset
$ sleep 5; lsusb | grep 03eb:2ffa
$ sleep 5; lsusb | grep 03eb:2ffa
$ sleep 5; lsusb | grep 03eb:2ffa
$ sleep 5; lsusb | grep 03eb:2ffa
$ # Never returns to bootloader...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment