Skip to content

Commit be4e420

Browse files
committed
Added support for Atmega328PB bootloader
1 parent a7ac827 commit be4e420

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

Diff for: Atmega_Board_Programmer/Atmega_Board_Programmer.ino

+39-28
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
/* ----------------------------------------------------------------------------
2020
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
2222
Micro or Esplora it will be identified as a Leonardo in the Tools -> Serial Port menu.
2323
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
2525
Tools -> Boards menu.
2626
------------------------------------------------------------------------------ */
2727

@@ -56,16 +56,17 @@ Tools -> Boards menu.
5656
// Version 1.27: Made bootloaders conditional, so you can omit some to save space
5757
// Version 1.28: Changed _BV () macro to bit () macro.
5858
// Version 1.29: Display message if cannot enter programming mode.
59-
// Version 1.30: Various tidy-ups
59+
// Version 1.30: Various tidy-ups
6060
// Version 1.31: Fixed bug in doing second lot of programming under IDE 1.6.0
6161
// Version 1.32: Bug fixes, added support for At90USB82, At90USB162 signatures
6262
// Version 1.33: Added support for ATMEGA256RFR2 (Pinoccio Scout)
6363
// Version 1.34: Added support for high-voltage programming mode for Atmega328 / ATtiny25 family
6464
// Version 1.35: Updated bootloader for Leonardo/Micro to Leonardo-prod-firmware-2012-12-10.hex
6565
// Version 1.36: Got rid of compiler warnings in IDE 1.6.7
6666
// 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
6768

68-
#define VERSION "1.37"
69+
#define VERSION "1.38"
6970

7071
// make true to use the high-voltage parallel wiring
7172
#define HIGH_VOLTAGE_PARALLEL false
@@ -76,14 +77,14 @@ Tools -> Boards menu.
7677

7778
#if HIGH_VOLTAGE_PARALLEL && HIGH_VOLTAGE_SERIAL
7879
#error Cannot use both high-voltage parallel and serial at the same time
79-
#endif
80+
#endif
8081

8182
#if (HIGH_VOLTAGE_PARALLEL || HIGH_VOLTAGE_SERIAL) && ICSP_PROGRAMMING
8283
#error Cannot use ICSP and high-voltage programming at the same time
8384
#endif
8485

8586
#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
8788
#endif
8889

8990
const int ENTER_PROGRAMMING_ATTEMPTS = 50;
@@ -131,7 +132,7 @@ const byte CLOCKOUT = 9;
131132
#else
132133
const byte RESET = 10; // --> goes to reset on the target board
133134
#endif
134-
135+
135136
#if ARDUINO < 100
136137
const byte SCK = 13; // SPI clock
137138
#endif
@@ -193,7 +194,7 @@ const bootloaderType bootloaders [] PROGMEM =
193194
// If not compiled into this particular version the bootloader address will be zero.
194195

195196
// ATmega168PA
196-
{ { 0x1E, 0x94, 0x0B },
197+
{ { 0x1E, 0x94, 0x0B },
197198
0x3E00, // start address
198199
#if USE_ATMEGA168
199200
atmega168_optiboot, // loader image
@@ -207,7 +208,7 @@ const bootloaderType bootloaders [] PROGMEM =
207208
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
208209

209210
// ATmega328P
210-
{ { 0x1E, 0x95, 0x0F },
211+
{ { 0x1E, 0x95, 0x0F },
211212
0x7E00, // start address
212213
atmega328_optiboot, // loader image
213214
sizeof atmega328_optiboot,
@@ -217,7 +218,17 @@ const bootloaderType bootloaders [] PROGMEM =
217218
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
218219

219220
// 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 },
221232
0x7E00, // start address
222233
atmega328_optiboot, // loader image
223234
sizeof atmega328_optiboot,
@@ -227,7 +238,7 @@ const bootloaderType bootloaders [] PROGMEM =
227238
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
228239

229240
// ATmega1280
230-
{ { 0x1E, 0x97, 0x03 },
241+
{ { 0x1E, 0x97, 0x03 },
231242
0x1FC00, // start address
232243
#if USE_ATMEGA1280
233244
optiboot_atmega1280_hex,
@@ -241,7 +252,7 @@ const bootloaderType bootloaders [] PROGMEM =
241252
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
242253

243254
// ATmega2560
244-
{ { 0x1E, 0x98, 0x01 },
255+
{ { 0x1E, 0x98, 0x01 },
245256
0x3E000, // start address
246257
#if USE_ATMEGA2560
247258
atmega2560_bootloader_hex,// loader image
@@ -269,7 +280,7 @@ const bootloaderType bootloaders [] PROGMEM =
269280
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
270281

271282
// ATmega16U2
272-
{ { 0x1E, 0x94, 0x89 },
283+
{ { 0x1E, 0x94, 0x89 },
273284
0x3000, // start address
274285
#if USE_ATMEGA16U2
275286
Arduino_COMBINED_dfu_usbserial_atmega16u2_Uno_Rev3_hex,// loader image
@@ -283,7 +294,7 @@ const bootloaderType bootloaders [] PROGMEM =
283294
0xCF }, // lock bits
284295

285296
// ATmega32U4
286-
{ { 0x1E, 0x95, 0x87 },
297+
{ { 0x1E, 0x95, 0x87 },
287298
0x7000, // start address
288299
#if USE_ATMEGA32U4
289300
leonardo_hex,// loader image
@@ -297,9 +308,9 @@ const bootloaderType bootloaders [] PROGMEM =
297308
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
298309

299310
// ATmega1284P family
300-
311+
301312
// ATmega1284P
302-
{ { 0x1E, 0x97, 0x05 },
313+
{ { 0x1E, 0x97, 0x05 },
303314
0x1FC00, // start address
304315
#if USE_ATMEGA1284
305316
optiboot_atmega1284p_hex,
@@ -313,9 +324,9 @@ const bootloaderType bootloaders [] PROGMEM =
313324
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
314325

315326
// Atmega8A family
316-
327+
317328
// ATmega8A
318-
{ { 0x1E, 0x93, 0x07 },
329+
{ { 0x1E, 0x93, 0x07 },
319330
0x1C00, // start address
320331
#if USE_ATMEGA8
321332
atmega8_hex,
@@ -353,25 +364,25 @@ bootloaderType currentBootloader;
353364
void writeBootloader ()
354365
{
355366
bool foundBootloader = false;
356-
367+
357368
for (unsigned int j = 0; j < NUMITEMS (bootloaders); j++)
358369
{
359-
370+
360371
memcpy_P (&currentBootloader, &bootloaders [j], sizeof currentBootloader);
361-
372+
362373
if (memcmp (currentSignature.sig, currentBootloader.sig, sizeof currentSignature.sig) == 0)
363374
{
364375
foundBootloader = true;
365376
break;
366377
} // end of signature found
367378
} // end of for each signature
368-
379+
369380
if (!foundBootloader)
370381
{
371382
Serial.println (F("No bootloader support for this device."));
372383
return;
373384
}
374-
385+
375386
// if in the table, but with zero length, we need to enable a #define to use it.
376387
if (currentBootloader.loaderLength == 0)
377388
{
@@ -544,14 +555,14 @@ void getSignature ()
544555
readSignature (sig);
545556
for (byte i = 0; i < 3; i++)
546557
showHex (sig [i]);
547-
558+
548559
Serial.println ();
549560

550561
for (unsigned int j = 0; j < NUMITEMS (signatures); j++)
551562
{
552-
563+
553564
memcpy_P (&currentSignature, &signatures [j], sizeof currentSignature);
554-
565+
555566
if (memcmp (sig, currentSignature.sig, sizeof sig) == 0)
556567
{
557568
foundSig = j;
@@ -590,13 +601,13 @@ void loop ()
590601
{
591602
getSignature ();
592603
getFuseBytes ();
593-
604+
594605
// if we found a signature try to write a bootloader
595606
if (foundSig != -1)
596607
writeBootloader ();
597608
stopProgramming ();
598609
} // end of if entered programming mode OK
599-
610+
600611

601612
Serial.println (F("Type 'C' when ready to continue with another chip ..."));
602613
while (toupper (Serial.read ()) != 'C')

0 commit comments

Comments
 (0)