Compiling Optiboot for ATmega328PB

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey guys,

 

Trying to compile Optiboot for an ATmega328PB.

 

I just downloaded AVR toolchain v3.6.1 from Microchip and did a fresh clone of the Optiboot repo onto my local hard drive.

 

Path to avr toolchain files on my computer is: `C:\avr8-gnu-toolchain-win32_x86`

 

I also downloaded WinAVR (latest version from 2010) in order to get Make.exe and any other required utilities for compiling which aren't included in the Microchip download.

 

I modified my PATH variable (Windows 10) such that the compiler path that WinAVR automatically adds is replaced with the path for the latest avr toolcahin that I downloaded.

 

Here's my PATH variables:

 

 

Now, if I open a command terminal in the `optiboot\bootloaders\optiboot` directory, here is what happens when I test compiler version, compile for atmega328, and then again for atmega328pb:

 

Boompy@TOMS_TOWER MINGW64 /c/PARTICLE_LOCAL/optiboot/optiboot/bootloaders/optibo                                                                                                                                                                                                                                                                                           ot (master)
$ avr-gcc -v
Using built-in specs.
Reading specs from c:/avr8-gnu-toolchain-win32_x86/bin/../lib/gcc/avr/5.4.0/device-specs/specs-avr2
COLLECT_GCC=C:\avr8-gnu-toolchain-win32_x86\bin\avr-gcc.exe
COLLECT_LTO_WRAPPER=c:/avr8-gnu-toolchain-win32_x86/bin/../libexec/gcc/avr/5.4.0/lto-wrapper.exe
Target: avr
Configured with: /home/toolsbuild/workspace/avr8-gnu-toolchain/src/gcc/configure LDFLAGS=-L/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs/lib CPPFLAGS= --target=avr --host=i686-w64-mingw32 --build=x86_64-pc-linux-gnu --prefix=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86 --libdir=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86/lib --enable-languages=c,c++ --with-dwarf2 --enable-doc --disable-shared --disable-libada --disable-libssp --disable-nls --with-avrlibc=yes --with-mpfr=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --with-gmp=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --with-mpc=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --enable-win32-registry=avrtoolchain --with-pkgversion=AVR_8_bit_GNU_Toolchain_3.6.1_1752 --with-bugurl=http://www.atmel.com
Thread model: single
gcc version 5.4.0 (AVR_8_bit_GNU_Toolchain_3.6.1_1752)

Boompy@TOMS_TOWER MINGW64 /c/PARTICLE_LOCAL/optiboot/optiboot/bootloaders/optiboot (master)
$ make atmega328
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.1_1752) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

BAUD RATE CHECK: Desired: 115200, Real: 117647, UBRRL = 16, Difference=2.1%
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=16000000L  -DBAUD_RATE=115200 -DLED_START_FLASHES=3            -c -o optiboot.o optiboot.c
optiboot.c:355:6: warning: #warning BAUD_RATE off by greater than 2% [-Wcpp]
     #warning BAUD_RATE off by greater than 2%
      ^
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=16000000L  -DBAUD_RATE=115200 -DLED_START_FLASHES=3          -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe -Wl,--relax -nostartfiles -o optiboot_atmega328.elf optiboot.o
avr-size optiboot_atmega328.elf
   text    data     bss     dec     hex filename
    478       0       0     478     1de optiboot_atmega328.elf
avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_atmega328.elf optiboot_atmega328.hex
avr-objdump -h -S optiboot_atmega328.elf > optiboot_atmega328.lst
rm optiboot.o optiboot_atmega328.elf

Boompy@TOMS_TOWER MINGW64 /c/PARTICLE_LOCAL/optiboot/optiboot/bootloaders/optiboot (master)
$ make AVR_FREQ=8000000L BAUD_RATE=38400L LED=D2 atmega328pb
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.1_1752) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

BAUD RATE CHECK: Desired: 38400, Real: 38461, UBRRL = 25, Difference=0.1%
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328pb -DF_CPU=8000000L  -DBAUD_RATE=38400L -DLED_START_FLASHES=3    -DLED=D2         -c -o optiboot.o optiboot.c
In file included from optiboot.c:272:0:
c:\avr8-gnu-toolchain-win32_x86\avr\include\avr\io.h:623:6: warning: #warning "device type not defined" [-Wcpp]
 #    warning "device type not defined"
      ^
In file included from optiboot.c:274:0:
c:\avr8-gnu-toolchain-win32_x86\avr\include\avr\eeprom.h:41:3: warning: #warning "Device does not have EEPROM available." [-Wcpp]
 # warning "Device does not have EEPROM available."
   ^
In file included from boot_opt.h:2:0,
                 from optiboot.c:296:
c:\avr8-gnu-toolchain-win32_x86\avr\include\avr\boot.h:116:6: error: #error AVR processor does not provide bootloader support!
 #    error AVR processor does not provide bootloader support!
      ^
c:\avr8-gnu-toolchain-win32_x86\avr\include\avr\boot.h:127:4: error: #error Cannot find SPM Enable bit definition!
 #  error Cannot find SPM Enable bit definition!
    ^
In file included from optiboot.c:306:0:
pin_defs.h:1384:2: error: #error Unrecognized LED name. Should be like "B5"
 #error Unrecognized LED name.  Should be like "B5"
  ^
pin_defs.h:1387:2: error: #error Nonexistent LED PORT. Check datasheet.
 #error Nonexistent LED PORT.  Check datasheet.
  ^
compilation terminated due to -Wfatal-errors.
make: *** [optiboot.o] Error 1

 

 

So, it appears that the toolchain that Microchip provides for download does not support the ATmega328PB.

 

Digging around the forums, it would appear that support for the ATmega328PB only seems to be available by tweaking Arduino IDE core files, or by compiling from within Atmel Studio 7 with the appropriate "pack" downloaded (which provides support files for the 328pb, though they are buried within AS7's esoteric structure).  Indeed, if I do a search for *328pb* within the AS7 install folder, I find a folder that contains a file named iom328pb.h located in the following folder: `C:\Program Files (x86)\Atmel\Studio\7.0\packs\atmel\ATmega_DFP\1.2.209\include\avr`

 

Soooooo......

 

How does one compile Optiboot for ATmega328PB?  Is this best done through AS7?  If so, how do I set up that project?  Is it possible to compile Optiboot for ATmega328PB from the command line?

 

Is there any difference in compiling optiboot for ATmega328, ATmega328P, and ATmega328PB that I should be worried about, or can I just compile optiboot for ATmega328?

 

If I simply compile targeting ATmega328, how do I then make avrdude work?  Here is what I get when I try and upload Optiboot compiled for ATmega328 to the ATmega328PB by specifying avrdude device type m328:

 

 


PS C:\PARTICLE_LOCAL\optiboot\optiboot\bootloaders\optiboot> avrdude -v -p m328p -c usbtiny -U flash:w:C:\PARTICLE_LOCAL\optiboot\optiboot\bootloaders\optiboot\optiboot_atmega328.hex:i

avrdude.exe: Version 5.10, compiled on Jan 19 2010 at 10:45:23
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2009 Joerg Wunsch

             System wide configuration file is "C:\WinAVR-20100110\bin\avrdude.conf"

             Using Port                    : lpt1
             Using Programmer              : usbtiny
             AVR Part                      : ATMEGA328P
             Chip Erase delay              : 9000 us
             PAGEL                         : PD7
             BS2                           : PC2
             RESET disposition             : dedicated
             RETRY pulse                   : SCK
             serial program mode           : yes
             parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             ByteDelay                     : 0
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               eeprom        65     5     4    0 no       1024    4      0  3600  3600 0xff 0xff
               flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
               lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
               hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
               efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
               lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
               calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
               signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

             Programmer Type : USBtiny
             Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude.exe: programmer operation not supported

avrdude.exe: Using SCK period of 10 usec
avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude.exe: Device signature = 0x1e9516
avrdude.exe: Expected signature for ATMEGA328P is 1E 95 0F
             Double check chip, or use -F to override this check.

avrdude.exe done.  Thank you.

 

 

If I force avrdude to upload (ignore the signature byte mismatch) using the -F option, I am able to upload Optiboot, however it takes about 2 minutes (why is that?) !!!

 

 

PS C:\PARTICLE_LOCAL\optiboot\optiboot\bootloaders\optiboot> avrdude -v -p m328p -c usbtiny -U flash:w:C:\PARTICLE_LOCAL\optiboot\optiboot\bootloaders\optiboot\optiboot_atmega328.hex:i -F

avrdude.exe: Version 5.10, compiled on Jan 19 2010 at 10:45:23
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2009 Joerg Wunsch

             System wide configuration file is "C:\WinAVR-20100110\bin\avrdude.conf"

             Using Port                    : lpt1
             Using Programmer              : usbtiny
             AVR Part                      : ATMEGA328P
             Chip Erase delay              : 9000 us
             PAGEL                         : PD7
             BS2                           : PC2
             RESET disposition             : dedicated
             RETRY pulse                   : SCK
             serial program mode           : yes
             parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             ByteDelay                     : 0
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               eeprom        65     5     4    0 no       1024    4      0  3600  3600 0xff 0xff
               flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
               lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
               hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
               efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
               lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
               calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
               signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

             Programmer Type : USBtiny
             Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude.exe: programmer operation not supported

avrdude.exe: Using SCK period of 10 usec
avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude.exe: Device signature = 0x1e9516
avrdude.exe: Expected signature for ATMEGA328P is 1E 95 0F
avrdude.exe: safemode: lfuse reads as E2
avrdude.exe: safemode: hfuse reads as D6
avrdude.exe: safemode: efuse reads as 5
avrdude.exe: NOTE: FLASH memory has been specified, an erase cycle will be performed
             To disable this feature, specify the -D option.
avrdude.exe: erasing chip
avrdude.exe: Using SCK period of 10 usec
avrdude.exe: reading input file "C:\PARTICLE_LOCAL\optiboot\optiboot\bootloaders\optiboot\optiboot_atmega328.hex"
avrdude.exe: writing flash (32768 bytes):

Writing | ################################################## | 100% 69.95s



avrdude.exe: 32768 bytes of flash written
avrdude.exe: verifying flash memory against C:\PARTICLE_LOCAL\optiboot\optiboot\bootloaders\optiboot\optiboot_atmega328.hex:
avrdude.exe: load data flash data from input file C:\PARTICLE_LOCAL\optiboot\optiboot\bootloaders\optiboot\optiboot_atmega328.hex:
avrdude.exe: input file C:\PARTICLE_LOCAL\optiboot\optiboot\bootloaders\optiboot\optiboot_atmega328.hex contains 32768 bytes
avrdude.exe: reading on-chip flash data:

Reading | ################################################## | 100% 45.35s



avrdude.exe: verifying ...
avrdude.exe: 32768 bytes of flash verified

avrdude.exe: safemode: lfuse reads as E2
avrdude.exe: safemode: hfuse reads as D6
avrdude.exe: safemode: efuse reads as 5
avrdude.exe: safemode: Fuses OK

avrdude.exe done.  Thank you.

 

I love the smell of burning silicon in the morning

Last Edited: Mon. Sep 24, 2018 - 06:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Update:

 

Tried to compile from within AS7... not sure if I set the project up correctly though.. Still getting compiler errors:

 

------ Build started: Project: JP2_Optiboot, Configuration: Debug AVR ------
Build started.
Project "JP2_Optiboot.cppproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "C:\Users\Boompy\Desktop\JP2_Optiboot\JP2_Optiboot\JP2_Optiboot\JP2_Optiboot.cppproj" (target "Build" depends on it):
	Using "RunCompilerTask" task from assembly "C:\Program Files (x86)\Atmel\Studio\7.0\Extensions\Application\AvrGCC.dll".
	Task "RunCompilerTask"
		Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils
		C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe -C "C:\Users\Boompy\Desktop\JP2_Optiboot\JP2_Optiboot\JP2_Optiboot" -f "Makefile" atmega328pb AVR_FREQ=8000000L BAUD_RATE=38400L LED_START_FLASHES=10 LED=D2 
		make: Entering directory 'C:/Users/Boompy/Desktop/JP2_Optiboot/JP2_Optiboot/JP2_Optiboot'
		avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.1_1750) 5.4.0
		Copyright (C) 2015 Free Software Foundation, Inc.
		This is free software; see the source for copying conditions.  There is NO
		warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\Users\Boompy\Desktop\JP2_Optiboot\JP2_Optiboot\JP2_Optiboot\Makefile(622,1): error: recipe for target 'baudcheck' failed
		process_begin: CreateProcess(NULL, bash baudcheck.tmp.sh, ...) failed.
		make (e=2): The system cannot find the file specified.
		make: [baudcheck] Error 2 (ignored)
		avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328pb -DF_CPU=8000000L  -DBAUD_RATE=38400L -DLED_START_FLASHES=10    -DLED=D2         -c -o optiboot.o optiboot.c
		In file included from optiboot.c:272:0:
c:\program files (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\io.h(623,6): warning: #warning "device type not defined" [-Wcpp]
		 #    warning "device type not defined"
		      ^
		In file included from optiboot.c:274:0:
c:\program files (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\eeprom.h(41,3): warning: #warning "Device does not have EEPROM available." [-Wcpp]
		 # warning "Device does not have EEPROM available."
		   ^
		In file included from boot_opt.h:2:0,
		                 from optiboot.c:296:
c:\program files (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\boot.h(116,6): error: #error AVR processor does not provide bootloader support!
		 #    error AVR processor does not provide bootloader support!
		      ^
c:\program files (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\boot.h(127,4): error: #error Cannot find SPM Enable bit definition!
		 #  error Cannot find SPM Enable bit definition!
		    ^
		In file included from optiboot.c:306:0:
C:\Users\Boompy\Desktop\JP2_Optiboot\JP2_Optiboot\JP2_Optiboot\pin_defs.h(1384,2): error: #error Unrecognized LED name. Should be like "B5"
		 #error Unrecognized LED name.  Should be like "B5"
		  ^
C:\Users\Boompy\Desktop\JP2_Optiboot\JP2_Optiboot\JP2_Optiboot\pin_defs.h(1387,2): error: #error Nonexistent LED PORT. Check datasheet.
		 #error Nonexistent LED PORT.  Check datasheet.
		  ^
		compilation terminated due to -Wfatal-errors.
		<builtin>: recipe for target 'optiboot.o' failed
		make: *** [optiboot.o] Error 1
		make: Leaving directory 'C:/Users/Boompy/Desktop/JP2_Optiboot/JP2_Optiboot/JP2_Optiboot'
	Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "JP2_Optiboot.cppproj" -- FAILED.
Done building project "JP2_Optiboot.cppproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

 

I love the smell of burning silicon in the morning

Last Edited: Mon. Sep 24, 2018 - 07:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See this tip for how to install the "Packs" upgrades in a cli toolchain environment:

https://www.avrfreaks.net/comment/2526416#comment-2526416

 

Compiling within AS7 won't help because it will still use the optiboot makefile, which doesn't have the magic commands to deal with packs added to it by AS.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
See this tip for how to install the "Packs" upgrades in a cli toolchain environment: https://www.avrfreaks.net/commen...

 

OK thanks for the tip!

 

I'll try this in a bit and report back!

I love the smell of burning silicon in the morning