18
18
19
19
/* ----------------------------------------------------------------------------
20
20
WARNING: The Arduino Leonardo, Arduino Esplora and the Arduino Micro all use the same chip (ATmega32U4).
21
- They will all have the Leonardo bootloader burnt onto them. This means that if you have a
21
+ They will all have the Leonardo bootloader burnt onto them. This means that if you have a
22
22
Micro or Esplora it will be identified as a Leonardo in the Tools -> Serial Port menu.
23
23
This is because the PID (Product ID) in the USB firmware will be 0x0036 (Leonardo).
24
- This only applies during the uploading process. You should still select the correct board in the
24
+ This only applies during the uploading process. You should still select the correct board in the
25
25
Tools -> Boards menu.
26
26
------------------------------------------------------------------------------ */
27
27
@@ -56,16 +56,17 @@ Tools -> Boards menu.
56
56
// Version 1.27: Made bootloaders conditional, so you can omit some to save space
57
57
// Version 1.28: Changed _BV () macro to bit () macro.
58
58
// Version 1.29: Display message if cannot enter programming mode.
59
- // Version 1.30: Various tidy-ups
59
+ // Version 1.30: Various tidy-ups
60
60
// Version 1.31: Fixed bug in doing second lot of programming under IDE 1.6.0
61
61
// Version 1.32: Bug fixes, added support for At90USB82, At90USB162 signatures
62
62
// Version 1.33: Added support for ATMEGA256RFR2 (Pinoccio Scout)
63
63
// Version 1.34: Added support for high-voltage programming mode for Atmega328 / ATtiny25 family
64
64
// Version 1.35: Updated bootloader for Leonardo/Micro to Leonardo-prod-firmware-2012-12-10.hex
65
65
// Version 1.36: Got rid of compiler warnings in IDE 1.6.7
66
66
// Version 1.37: Got rid of compiler warnings in IDE 1.6.9, added more information about where bootloaders came from
67
+ // Version 1.38: Added Atmega328PB to list of supported bootloaders
67
68
68
- #define VERSION " 1.37 "
69
+ #define VERSION " 1.38 "
69
70
70
71
// make true to use the high-voltage parallel wiring
71
72
#define HIGH_VOLTAGE_PARALLEL false
@@ -76,14 +77,14 @@ Tools -> Boards menu.
76
77
77
78
#if HIGH_VOLTAGE_PARALLEL && HIGH_VOLTAGE_SERIAL
78
79
#error Cannot use both high-voltage parallel and serial at the same time
79
- #endif
80
+ #endif
80
81
81
82
#if (HIGH_VOLTAGE_PARALLEL || HIGH_VOLTAGE_SERIAL) && ICSP_PROGRAMMING
82
83
#error Cannot use ICSP and high-voltage programming at the same time
83
84
#endif
84
85
85
86
#if !(HIGH_VOLTAGE_PARALLEL || HIGH_VOLTAGE_SERIAL || ICSP_PROGRAMMING)
86
- #error Choose a programming mode: HIGH_VOLTAGE_PARALLEL, HIGH_VOLTAGE_SERIAL or ICSP_PROGRAMMING
87
+ #error Choose a programming mode: HIGH_VOLTAGE_PARALLEL, HIGH_VOLTAGE_SERIAL or ICSP_PROGRAMMING
87
88
#endif
88
89
89
90
const int ENTER_PROGRAMMING_ATTEMPTS = 50 ;
@@ -131,7 +132,7 @@ const byte CLOCKOUT = 9;
131
132
#else
132
133
const byte RESET = 10 ; // --> goes to reset on the target board
133
134
#endif
134
-
135
+
135
136
#if ARDUINO < 100
136
137
const byte SCK = 13 ; // SPI clock
137
138
#endif
@@ -193,7 +194,7 @@ const bootloaderType bootloaders [] PROGMEM =
193
194
// If not compiled into this particular version the bootloader address will be zero.
194
195
195
196
// ATmega168PA
196
- { { 0x1E , 0x94 , 0x0B },
197
+ { { 0x1E , 0x94 , 0x0B },
197
198
0x3E00 , // start address
198
199
#if USE_ATMEGA168
199
200
atmega168_optiboot, // loader image
@@ -207,7 +208,7 @@ const bootloaderType bootloaders [] PROGMEM =
207
208
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
208
209
209
210
// ATmega328P
210
- { { 0x1E , 0x95 , 0x0F },
211
+ { { 0x1E , 0x95 , 0x0F },
211
212
0x7E00 , // start address
212
213
atmega328_optiboot, // loader image
213
214
sizeof atmega328_optiboot,
@@ -217,7 +218,17 @@ const bootloaderType bootloaders [] PROGMEM =
217
218
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
218
219
219
220
// ATmega328
220
- { { 0x1E , 0x95 , 0x14 },
221
+ { { 0x1E , 0x95 , 0x14 },
222
+ 0x7E00 , // start address
223
+ atmega328_optiboot, // loader image
224
+ sizeof atmega328_optiboot,
225
+ 0xFF , // fuse low byte: external clock, max start-up time
226
+ 0xDE , // fuse high byte: SPI enable, boot into bootloader, 512 byte bootloader
227
+ 0x05 , // fuse extended byte: brown-out detection at 2.7V
228
+ 0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
229
+
230
+ // ATmega328PB
231
+ { { 0x1E , 0x95 , 0x16 },
221
232
0x7E00 , // start address
222
233
atmega328_optiboot, // loader image
223
234
sizeof atmega328_optiboot,
@@ -227,7 +238,7 @@ const bootloaderType bootloaders [] PROGMEM =
227
238
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
228
239
229
240
// ATmega1280
230
- { { 0x1E , 0x97 , 0x03 },
241
+ { { 0x1E , 0x97 , 0x03 },
231
242
0x1FC00 , // start address
232
243
#if USE_ATMEGA1280
233
244
optiboot_atmega1280_hex,
@@ -241,7 +252,7 @@ const bootloaderType bootloaders [] PROGMEM =
241
252
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
242
253
243
254
// ATmega2560
244
- { { 0x1E , 0x98 , 0x01 },
255
+ { { 0x1E , 0x98 , 0x01 },
245
256
0x3E000 , // start address
246
257
#if USE_ATMEGA2560
247
258
atmega2560_bootloader_hex,// loader image
@@ -269,7 +280,7 @@ const bootloaderType bootloaders [] PROGMEM =
269
280
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
270
281
271
282
// ATmega16U2
272
- { { 0x1E , 0x94 , 0x89 },
283
+ { { 0x1E , 0x94 , 0x89 },
273
284
0x3000 , // start address
274
285
#if USE_ATMEGA16U2
275
286
Arduino_COMBINED_dfu_usbserial_atmega16u2_Uno_Rev3_hex,// loader image
@@ -283,7 +294,7 @@ const bootloaderType bootloaders [] PROGMEM =
283
294
0xCF }, // lock bits
284
295
285
296
// ATmega32U4
286
- { { 0x1E , 0x95 , 0x87 },
297
+ { { 0x1E , 0x95 , 0x87 },
287
298
0x7000 , // start address
288
299
#if USE_ATMEGA32U4
289
300
leonardo_hex,// loader image
@@ -297,9 +308,9 @@ const bootloaderType bootloaders [] PROGMEM =
297
308
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
298
309
299
310
// ATmega1284P family
300
-
311
+
301
312
// ATmega1284P
302
- { { 0x1E , 0x97 , 0x05 },
313
+ { { 0x1E , 0x97 , 0x05 },
303
314
0x1FC00 , // start address
304
315
#if USE_ATMEGA1284
305
316
optiboot_atmega1284p_hex,
@@ -313,9 +324,9 @@ const bootloaderType bootloaders [] PROGMEM =
313
324
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
314
325
315
326
// Atmega8A family
316
-
327
+
317
328
// ATmega8A
318
- { { 0x1E , 0x93 , 0x07 },
329
+ { { 0x1E , 0x93 , 0x07 },
319
330
0x1C00 , // start address
320
331
#if USE_ATMEGA8
321
332
atmega8_hex,
@@ -353,25 +364,25 @@ bootloaderType currentBootloader;
353
364
void writeBootloader ()
354
365
{
355
366
bool foundBootloader = false ;
356
-
367
+
357
368
for (unsigned int j = 0 ; j < NUMITEMS (bootloaders); j++)
358
369
{
359
-
370
+
360
371
memcpy_P (¤tBootloader, &bootloaders [j], sizeof currentBootloader);
361
-
372
+
362
373
if (memcmp (currentSignature.sig , currentBootloader.sig , sizeof currentSignature.sig ) == 0 )
363
374
{
364
375
foundBootloader = true ;
365
376
break ;
366
377
} // end of signature found
367
378
} // end of for each signature
368
-
379
+
369
380
if (!foundBootloader)
370
381
{
371
382
Serial.println (F (" No bootloader support for this device." ));
372
383
return ;
373
384
}
374
-
385
+
375
386
// if in the table, but with zero length, we need to enable a #define to use it.
376
387
if (currentBootloader.loaderLength == 0 )
377
388
{
@@ -544,14 +555,14 @@ void getSignature ()
544
555
readSignature (sig);
545
556
for (byte i = 0 ; i < 3 ; i++)
546
557
showHex (sig [i]);
547
-
558
+
548
559
Serial.println ();
549
560
550
561
for (unsigned int j = 0 ; j < NUMITEMS (signatures); j++)
551
562
{
552
-
563
+
553
564
memcpy_P (¤tSignature, &signatures [j], sizeof currentSignature);
554
-
565
+
555
566
if (memcmp (sig, currentSignature.sig , sizeof sig) == 0 )
556
567
{
557
568
foundSig = j;
@@ -590,13 +601,13 @@ void loop ()
590
601
{
591
602
getSignature ();
592
603
getFuseBytes ();
593
-
604
+
594
605
// if we found a signature try to write a bootloader
595
606
if (foundSig != -1 )
596
607
writeBootloader ();
597
608
stopProgramming ();
598
609
} // end of if entered programming mode OK
599
-
610
+
600
611
601
612
Serial.println (F (" Type 'C' when ready to continue with another chip ..." ));
602
613
while (toupper (Serial.read ()) != ' C' )
0 commit comments