msproul / arduino-stk500v2-bootloader Goto Github PK
View Code? Open in Web Editor NEWSTk500v2 bootloader for AVR 2560 and otherchips
Home Page: http://www.avr-developers.com/
STk500v2 bootloader for AVR 2560 and otherchips
Home Page: http://www.avr-developers.com/
The attached patch allows one to enter "#3c00 " ('#', followed by a hex number, followed by space (or any non-hex digit, actually)) to set the initial address used by 'E', 'F', and 'R' commands.
Arduino ships with gcc4.3.2, but when you compile the stk500v2 with this version, the resulting image exceeds the max bootloader size.
Suggest adding "-fno-inline-small-functions", which reduces the compile code size for all compiler versions.
See also http://code.google.com/p/arduino/issues/detail?id=822 (where there is a patch.)
If an application program enables the watchdog, and an external or WDT-caused reset occurs, stk500v2 will not disable (nor reset) the WDT, causing it to go off again while it is waiting to decide whether there is bootloader-related serial activity. Looping infinitely.
http://code.google.com/p/arduino/issues/detail?id=181&q=watchdog has a patch attached.
On a atmega2560 the usable flash is meant to be 256k-8k bootloader. Ie 0-0x3E000 (253952 bytes.) but in the code is
#if FLASHEND > 0x0F000
#define BOOTSIZE 8192
#else
#define BOOTSIZE 2048
#endif
#define APP_END (FLASHEND -(2*BOOTSIZE) + 1)
FLASHEND is 0x3FFFF on mega2560's so the the BOOTSIZE is set to 8192, but the APP_END is set to (0x3FFFF - (2*0x2000)) + 1 = 0x3C000
The code then uses "if (eraseAddress < APP_END )" so uploading over serial will only erase bytes from 0x00000 to 0x3C000. So 0x3C000--0x3E000 is not erased and can't be reused till a full erase is done.
This has been causing headaches for years.
It looks (form code inspection) like the "load address" command left-shifts the provided address (assuming a word address for flash programming), but the Write EEPROM code doesn't shift that back, which should cause EEPROM programming that starts at any location other than zero to end up in the wrong place.
Hi, I got a warning: cannot set sck period. please check for usbasp firmware update.
Yet, it seems like other upload logs are fine as attached.
$ avrdude -p atmega2560 -c usbasp -P /dev/ttyUSB0 -B 115200 -e -u -Ulock:w:0x3f:m -U flash:w:./stk500boot_v2_mega2560.hex -Ulock:w:0x0F:m
avrdude: set SCK frequency to 0 Hz
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9801
avrdude: erasing chip
avrdude: set SCK frequency to 0 Hz
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "0x3f"
avrdude: writing lock (1 bytes):
Writing | ################################################## | 100% 0.00s
avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3f:
avrdude: load data lock data from input file 0x3f:
avrdude: input file 0x3f contains 1 bytes
avrdude: reading on-chip lock data:
Reading | ################################################## | 100% 0.00s
avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "./stk500boot_v2_mega2560.hex"
avrdude: input file ./stk500boot_v2_mega2560.hex auto detected as Intel Hex
avrdude: writing flash (255720 bytes):
Writing | ################################################## | 100% 0.00s
avrdude: 255720 bytes of flash written
avrdude: verifying flash memory against ./stk500boot_v2_mega2560.hex:
avrdude: load data flash data from input file ./stk500boot_v2_mega2560.hex:
avrdude: input file ./stk500boot_v2_mega2560.hex auto detected as Intel Hex
avrdude: input file ./stk500boot_v2_mega2560.hex contains 255720 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.00s
avrdude: verifying ...
avrdude: 255720 bytes of flash verified
avrdude: reading input file "0x0F"
avrdude: writing lock (1 bytes):
Writing | ################################################## | 100% 0.01s
avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x0F:
avrdude: load data lock data from input file 0x0F:
avrdude: input file 0x0F contains 1 bytes
avrdude: reading on-chip lock data:
Reading | ################################################## | 100% 0.00s
avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude done. Thank you.
When I try to upload sketch or dump flash, it showed up as nothing is uploaded:
wenhui-2:Compile WenhuiZhang$ avrdude -p atmega2560 -c usbasp -P /dev/ttyUSB0 -c usbasp -t
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9801
avrdude> dump
>>> dump
Usage: dump <memtype> [<addr> <len>]
avrdude> dump flash
>>> dump flash
0000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
0010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
0020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
0030 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
avrdude> dump flash 0x3eff
>>> dump flash 0x3eff
Usage: dump <memtype> [<addr> <len>]
avrdude> dump flash 0x3eff 100
>>> dump flash 0x3eff 100
3eff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
3f0f ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
3f1f ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
3f2f ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
3f3f ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
3f4f ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
3f5f ff ff ff ff
On lines 517/518, both address and eraseAddress are set to zero:
https://github.com/msproul/Arduino-stk500v2-bootloader/blob/master/stk500boot.c#L517
When we get a CMD_CHIP_ERASE_ISP, eraseAddress is reset to zero (properly):
https://github.com/msproul/Arduino-stk500v2-bootloader/blob/master/stk500boot.c#L903
When we get either a CMD_PROGRAM_FLASH_ISP or a CMD_PROGRAM_EEPROM_ISP, both address and eraseAddress will be zero.
https://github.com/msproul/Arduino-stk500v2-bootloader/blob/master/stk500boot.c#L919
This is, I would argue, incorrect behavior. Not all programs are uploaded to location zero. We specifically encountered this in our work with a small virtual machine (http://concurrency.cc/), where we upload the VM to address zero, and then upload the bytecode somewhere else in flash separately. This way, users can upload the VM once (~20K), and upload new programs (bytecode) many times without having to reflash the VM every time.
On the 168, 328, and 1280 everything has (in the past) worked fine. With the introduction of the 2560, our bytecode started clobbering the VM from address zero, despite providing location information to avrdude. We believe that the problem is in the bootloader. It seems like the bootloader puts the bytecode at the correct location (having extracted 'address' properly), but 'eraseAddress' remains initialized to zero, and therefore blocks are erased starting from address zero, while our bytecode is written into the correct location. Thus, the VM gets destroyed in the process of uploading bytecode.
I had a patch started, but do not have an ISP that works reliably on the Mac. If someone tells me what ISP to buy, I'll work on a patch.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.