Skip to content

Commit a0d00b4

Browse files
committed
http://code.google.com/p/arduino/issues/detail?id=368
Optiboot does not support ArduinoasISP programmer. When avrdude runs and talks to an arduino running ArduinoISP, it needs the optiboot (entered due to auto-reset) to abort and start the ArduinoISP "application" when it sees communications at the wrong serial speed. Unfortunately, optiboot treats all unrecognized command characters as "no-ops" and responds/loops for more commands, leading to a nice loop that never gets to the sketch. This patch causes characters received with Framing errors (the most likely error for speed mis-matches) to NOT reset the watchdog timer (normally done in getch()), which will cause the application to start if it continues for "a while." (tested. Works! Running ArduinoISP at speeds as high as 57600 still causes the bootloader to start the sketch (although it fails later on for other reasons.))
1 parent 5c27dd9 commit a0d00b4

21 files changed

+863
-752
lines changed

bootloaders/optiboot/README.TXT

+17-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ this may change if compiler versions drift apart between CrossPack and
2727
the Arduino IDE.)
2828

2929

30-
Building optiboot in the arduino IDE install.
30+
Building Optiboot in the Arduino IDE Install.
3131

3232
Work in the .../hardware/arduino/bootloaders/optiboot/ and use the
3333
"omake <targets>" command, which just generates a command that uses
@@ -44,7 +44,7 @@ the programs it needs, so you need to work in the existing optiboot
4444
directory (or something created at the same "level") for it to work.
4545

4646

47-
Building optiboot in the arduino source development install.
47+
Building Optiboot in the Arduino Source Development Install.
4848

4949
In this case, there is no special shell script, and you're assumed to
5050
have "make" installed somewhere in your path.
@@ -53,3 +53,18 @@ expected directory.
5353
Work in Arduino/hardware/arduino/bootloaders/optiboot and use
5454
make OS=windows ENV=arduinodev <targets>
5555
or make OS=macosx ENV=arduinodev <targets>
56+
57+
58+
Programming Chips Using the _isp Targets
59+
60+
The CPU targets have corresponding ISP targets that will actuall
61+
program the bootloader into a chip. "atmega328_isp" for the atmega328,
62+
for example. These will set the fuses and lock bits as appropriate as
63+
well as uploading the bootloader code.
64+
65+
The makefiles default to using a USB programmer, but you can use
66+
a serial programmer like ArduinoISP by changing the appropriate
67+
variables when you invoke make:
68+
69+
make ISPTOOL=stk500v1 ISPPORT=/dev/tty.usbserial-A20e1eAN \
70+
ISPSPEED=-b19200 atmega328_isp

bootloaders/optiboot/optiboot.c

+18-4
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,16 @@
132132
/**********************************************************/
133133
/* Edit History: */
134134
/* */
135+
/* 4.3 WestfW: catch framing errors in getch(), so that */
136+
/* AVRISP works without HW kludges. */
137+
/* http://code.google.com/p/arduino/issues/detail?id=368n*/
135138
/* 4.2 WestfW: reduce code size, fix timeouts, change */
136139
/* verifySpace to use WDT instead of appstart */
137140
/* 4.1 WestfW: put version number in binary. */
138141
/**********************************************************/
139142

140143
#define OPTIBOOT_MAJVER 4
141-
#define OPTIBOOT_MINVER 2
144+
#define OPTIBOOT_MINVER 3
142145

143146
#define MAKESTR(a) #a
144147
#define MAKEVER(a, b) MAKESTR(a*256+b)
@@ -512,8 +515,6 @@ void putch(char ch) {
512515
uint8_t getch(void) {
513516
uint8_t ch;
514517

515-
watchdogReset();
516-
517518
#ifdef LED_DATA_FLASH
518519
#ifdef __AVR_ATmega8__
519520
LED_PORT ^= _BV(LED);
@@ -547,7 +548,20 @@ uint8_t getch(void) {
547548
"r25"
548549
);
549550
#else
550-
while(!(UCSR0A & _BV(RXC0)));
551+
while(!(UCSR0A & _BV(RXC0)))
552+
;
553+
if (!(UCSR0A & _BV(FE0))) {
554+
/*
555+
* A Framing Error indicates (probably) that something is talking
556+
* to us at the wrong bit rate. Assume that this is because it
557+
* expects to be talking to the application, and DON'T reset the
558+
* watchdog. This should cause the bootloader to abort and run
559+
* the application "soon", if it keeps happening. (Note that we
560+
* don't care that an invalid char is returned...)
561+
*/
562+
watchdogReset();
563+
}
564+
551565
ch = UDR0;
552566
#endif
553567

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1-
:107E0000112484B714BE81FFE3D085E08093810004
1+
:107E0000112484B714BE81FFE7D085E08093810000
22
:107E100082E08093C00088E18093C10086E0809377
3-
:107E2000C20080E18093C4008EE0BCD0259A86E039
3+
:107E2000C20080E18093C4008EE0C0D0259A86E035
44
:107E300020E33CEF91E0309385002093840096BBD3
55
:107E4000B09BFECF1D9AA8958150A9F799249394D1
66
:107E5000A5E0AA2EF1E1BF2E9DD0813421F481E06E
7-
:107E6000AFD083E01FC0823411F484E103C08534B5
8-
:107E700019F485E0A5D083C0853579F48BD0E82E40
7+
:107E6000B3D083E01FC0823411F484E103C08534B1
8+
:107E700019F485E0A9D083C0853579F48BD0E82E3C
99
:107E8000FF2488D0082F10E0102F00270E291F296B
10-
:107E9000000F111F8DD0680172C0863529F484E06F
11-
:107EA0008FD080E06FD06BC0843609F042C072D0B2
10+
:107E9000000F111F91D0680172C0863529F484E06B
11+
:107EA00093D080E06FD06BC0843609F042C072D0AE
1212
:107EB00071D0082F6FD080E0C81680E7D80620F474
1313
:107EC00083E0F60187BFE895C0E0D1E063D08993F5
1414
:107ED0000C17E1F7F0E0CF16F0E7DF0620F083E0C3
15-
:107EE000F60187BFE89564D007B600FCFDCFA60178
15+
:107EE000F60187BFE89568D007B600FCFDCFA60174
1616
:107EF000A0E0B1E02C9130E011968C91119790E0C8
1717
:107F0000982F8827822B932B1296FA010C0197BE8B
1818
:107F1000E89511244E5F5F4FF1E0A038BF0751F79D
1919
:107F2000F601A7BEE89507B600FCFDCFB7BEE89501
20-
:107F300026C08437B1F42ED02DD0F82E2BD038D0D7
20+
:107F300026C08437B1F42ED02DD0F82E2BD03CD0D3
2121
:107F4000F601EF2C8F010F5F1F4F84911BD0EA9435
2222
:107F5000F801C1F70894C11CD11CFA94CF0CD11CB4
23-
:107F60000EC0853739F424D08EE10CD085E90AD0D3
24-
:107F70008FE098CF813511F488E014D019D080E1DA
23+
:107F60000EC0853739F428D08EE10CD085E90AD0CF
24+
:107F70008FE098CF813511F488E018D01DD080E1D2
2525
:107F800001D06ACF982F8091C00085FFFCCF9093DD
26-
:107F9000C6000895A8958091C00087FFFCCF80910E
27-
:107FA000C6000895E0E6F0E098E1908380830895AC
28-
:107FB000F1DF803219F088E0F5DFFFCF84E1E2CF16
29-
:107FC0001F93182FE7DF1150E9F7F2DF1F91089593
30-
:0A7FD00080E0E8DFEE27FF270994A8
31-
:027FFE0002047B
26+
:107F9000C60008958091C00087FFFCCF8091C0008B
27+
:107FA00084FD01C0A8958091C6000895E0E6F0E048
28+
:107FB00098E1908380830895EDDF803219F088E0A6
29+
:107FC000F5DFFFCF84E1DECF1F93182FE3DF1150E1
30+
:107FD000E9F7F2DF1F91089580E0E8DFEE27FF2741
31+
:027FE000099402
32+
:027FFE0003047A
3233
:0400000300007E007B
3334
:00000001FF

0 commit comments

Comments
 (0)