I am trying to program a atmega328pb with the arduino boot loader use an arduino uno as an ISP.
Here is the command I am using, which is the command that is run with the Burn Bootloader action under Tools. The only difference is I modified it to work the pb version of the 328.
First of all, I have to state that you sent everything off to a good start.
This verification error; content mismatch is not easy to solve. Not so long ago:
However, in your case, the very first attempt to write failed. I would say the problem is reliability of your wiring so check it first.
The command is OK. That is exactly what it should be. You can try to read out the flash memory to check the connection reliability. It is better than trying to write because every erase/write cycle is wearing the flash memory (cca 10k cycles is the lifetime).
Try from the command line something like this: /usr/bin/avrdude -C/etc/avrdude.conf -v -patmega328pb -cstk500v1 -P/dev/ttyACM0 -b19200 -Uflash:r:FLASH.hex:i
It is the long read so it checks the connection, plus you can do it several times and compare the files.
Avrdude sometimes has a problem with non-existent bits in fuses and lock bytes. In this case, there are only 6bits of lock data, and 0x3f "clears" them all (unlocks the chip.) But all the communications is byte-wide, so there is a choice of 0x3f (non-existent bits are zero - compatible with human-style thinking) or 0xFF (non-existent bits are 1s - compatible with hardware, sort-of.)
So it's expecting 3f and getting ff, which really ought to be interpreted the same, but it's not. (I think the latest avrdude has a way of configuring "don't care" bits, but that doesn't mean that the database you're using has set up the 328PB correctly.)
(You do know that this is only about HALF of the "burn bootloader" operation, right? It erases the chip and sets the fuses. There's a second command to actually load the bootloader .hex file.)
Ya I know I have to add the hex file, I hadn't gotten past erasing the chip and setting the fuses so I haven't looked into that. Is there a good place to get the hex file for atmega328pb? I would assume it is the same as the atmega328p.
Here was my avrdude output:
avrdude: Version 6.3-20171130
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "/etc/avrdude.conf"
User configuration file is "/home/pi/.avrduderc"
User configuration file does not exist or is not a regular file, skipping
Using Port : /dev/ttyACM0
Using Programmer : stk500v1
Overriding Baud Rate : 19200
AVR Part : ATmega328PB
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 20 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 : STK500
Description : Atmel STK500 Version 1.x firmware
Hardware Version: 2
Firmware Version: 1.18
Topcard : Unknown
Vtarget : 0.0 V
Varef : 0.0 V
Oscillator : Off
SCK period : 0.1 us
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e9516 (probably m328pb)
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as F5
avrdude: erasing chip
avrdude: reading input file "0xFF"
avrdude: writing lock (1 bytes):
Writing | ################################################## | 100% 0.01s
avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0xFF:
avrdude: load data lock data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lock data:
Reading | ################################################## | 100% 0.01s
avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0xFD"
avrdude: writing efuse (1 bytes):
Writing | | 0% 0.00s ***failed;
Writing | ################################################## | 100% 0.07s
avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xFD:
avrdude: load data efuse data from input file 0xFD:
avrdude: input file 0xFD contains 1 bytes
avrdude: reading on-chip efuse data:
Reading | ################################################## | 100% 0.01s
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
0xf5 != 0xfd
avrdude: verification error; content mismatch
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as F5
avrdude: safemode: efuse changed! Was fd, and is now f5
Would you like this fuse to be changed back? [y/n]
Still getting a verification error. Its weird that when writing FD, F5 is maintained. I scoped the mosi pin to make sure data is going to the atmega and it looks like it is. So I am not sure why FD is not being written.
After installing it, you can select Tools > Board > MiniCore > ATmega328 and then Tools > Variant > 328PB to configure Arduino IDE for use with the ATmega328PB, including the correct bootloaders and fuses.
I see you are using a Raspberry Pi. Even though there isn't an official build of Arduino IDE 2.x for the ARM Linux host architecture, you can use Arduino IDE 1.8.19. The download link is listed here:
Me either. Could be another avrdude.conf file problem - your avrdude is quite old.
The 328pb has one new fuse bit compared to the 328p, to control the new clock failure detection. F5 has CFD turned off, FD would have it on. Either should work OK in use.
Is there a good place to get the hex file for atmega328pb? I would assume it is the same as the atmega328p.
It's NOT the same, unless you want the 328PB to "identify" as just a 328P (sometimes desirable, I guess.)
I second the recommendation for minicore. You'd be done by now!
I tried the install of minicore and I am running into a different issue now! The bootloader gets burned but then when I try to upload a modified version of the blink sketch (just changed the pin number) I get the error:
/usr/lib/avr/include/avr/sleep.h:224:6: error: #error "No SLEEP mode defined for this device."
#error "No SLEEP mode defined for this device."
Looking at that header file I believe this code is being run between lines 201 and 224
#if defined(SM2)
#define set_sleep_mode(mode) \
do { \
_SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1) | _BV(SM2))) | (mode)); \
} while(0)
#elif defined(SM1)
#define set_sleep_mode(mode) \
do { \
_SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \
} while(0)
#elif defined(SM)
#define set_sleep_mode(mode) \
do { \
_SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~_BV(SM)) | (mode)); \
} while(0)
#else
#error "No SLEEP mode defined for this device."
which tells me something is wrong with maybe the chip specific header files? Its weird to me that SM1, SM or SM0 is not defined.
Weird. Blink compiles fine here with minicore.
Have you updated the Arduino AVR Core? Core versions are separate from IDE versions...
For me, AVR core 1.8.3 and 1.8.6 and minicore 2.2.2 (the most recent versions) worked fine with IDE 1.8..13 (which is also a version I'm fond of.)
Well I finally got it working, in the end I used the cli to compile and then avrdude to upload the hex file. For minicore, it doesn't seem like there is a way to use the cli upload command and specify the PB version of the atmega328.
Here is my arduino console outputs during the compilation step.
Arduino: 1.8.13 (Linux), Board: "ATmega328, Yes (UART0), EEPROM retained, 328PB, BOD 2.7V, LTO disabled, External 16 MHz"
arduino-builder -dump-prefs -logger=machine -hardware /usr/share/arduino/hardware -hardware /home/pi/.arduino15/packages -tools /usr/share/arduino/hardware/tools/avr -tools /home/pi/.arduino15/packages -libraries /home/pi/Arduino/libraries -fqbn=MiniCore:avr:328:bootloader=uart0,eeprom=keep,variant=modelPB,BOD=2v7,LTO=Os,clock=16MHz_external -vid-pid=2341_0043 -ide-version=10813 -build-path /tmp/arduino_build_558751 -warnings=none -build-cache /tmp/arduino_cache_793054 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=/home/pi/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/pi/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.avrdude.path=/home/pi/.arduino15/packages/MiniCore/tools/avrdude/7.1-arduino.1 -prefs=runtime.tools.avrdude-7.1-arduino.1.path=/home/pi/.arduino15/packages/MiniCore/tools/avrdude/7.1-arduino.1 -verbose /home/pi/Arduino/sketch_jun27a/sketch_jun27a.ino
arduino-builder -compile -logger=machine -hardware /usr/share/arduino/hardware -hardware /home/pi/.arduino15/packages -tools /usr/share/arduino/hardware/tools/avr -tools /home/pi/.arduino15/packages -libraries /home/pi/Arduino/libraries -fqbn=MiniCore:avr:328:bootloader=uart0,eeprom=keep,variant=modelPB,BOD=2v7,LTO=Os,clock=16MHz_external -vid-pid=2341_0043 -ide-version=10813 -build-path /tmp/arduino_build_558751 -warnings=none -build-cache /tmp/arduino_cache_793054 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=/home/pi/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/pi/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.avrdude.path=/home/pi/.arduino15/packages/MiniCore/tools/avrdude/7.1-arduino.1 -prefs=runtime.tools.avrdude-7.1-arduino.1.path=/home/pi/.arduino15/packages/MiniCore/tools/avrdude/7.1-arduino.1 -verbose /home/pi/Arduino/sketch_jun27a/sketch_jun27a.ino
Using board '328' from platform in folder: /home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2
Using core 'MCUdude_corefiles' from platform in folder: /home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2
Warning: platform.txt from core 'MiniCore' contains deprecated compiler.path={runtime.tools.avr-gcc.path}/bin/, automatically converted to compiler.path=/usr/bin/. Consider upgrading this core.
Detecting libraries used...
"/usr/bin/avr-g++" -c -g -Os -w -std=gnu++17 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328pb -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_ATmega328 -DARDUINO_ARCH_AVR "-I/home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/cores/MCUdude_corefiles" "-I/home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/variants/pb-variant" "/tmp/arduino_build_558751/sketch/sketch_jun27a.ino.cpp" -o "/dev/null"
Generating function prototypes...
"/usr/bin/avr-g++" -c -g -Os -w -std=gnu++17 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328pb -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_ATmega328 -DARDUINO_ARCH_AVR "-I/home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/cores/MCUdude_corefiles" "-I/home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/variants/pb-variant" "/tmp/arduino_build_558751/sketch/sketch_jun27a.ino.cpp" -o "/tmp/arduino_build_558751/preproc/ctags_target_for_gcc_minus_e.cpp"
In file included from /home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/cores/MCUdude_corefiles/wiring_extras.h:14:0,
from /home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/cores/MCUdude_corefiles/Arduino.h:367,
from /tmp/arduino_build_558751/sketch/sketch_jun27a.ino.cpp:1:
/usr/lib/avr/include/avr/sleep.h:224:6: error: #error "No SLEEP mode defined for this device."
#error "No SLEEP mode defined for this device."
^
exit status 1
Error compiling for board ATmega328.
Here is what the the cli outputs for a successfully compile
FQBN: MiniCore:avr:328
Using board '328' from platform in folder: /home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2
Using core 'MCUdude_corefiles' from platform in folder: /home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2
Detecting libraries used...
/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++17 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega328 -DARDUINO_ARCH_AVR -I/home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/cores/MCUdude_corefiles -I/home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/variants/standard /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch/sketch_jun27a.ino.cpp -o /dev/null
Generating function prototypes...
/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++17 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega328 -DARDUINO_ARCH_AVR -I/home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/cores/MCUdude_corefiles -I/home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/variants/standard /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch/sketch_jun27a.ino.cpp -o /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/preproc/sketch_merged.cpp
/home/pi/.arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/preproc/sketch_merged.cpp
Compiling sketch...
/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++17 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega328 -DARDUINO_ARCH_AVR -I/home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/cores/MCUdude_corefiles -I/home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/variants/standard /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch/sketch_jun27a.ino.cpp -o /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch/sketch_jun27a.ino.cpp.o
Compiling libraries...
Compiling core...
Using precompiled core: /tmp/arduino/cores/MiniCore_avr_328_10025ebd6dd2801362ed43ae2be45441/core.a
Linking everything together...
/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc -w -Os -Wl,--gc-sections -mmcu=atmega328p -o /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch_jun27a.ino.elf /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch/sketch_jun27a.ino.cpp.o /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/../../cores/MiniCore_avr_328_10025ebd6dd2801362ed43ae2be45441/core.a -L/tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775 -lm
/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch_jun27a.ino.elf /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch_jun27a.ino.eep
/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy -O ihex -R .eeprom /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch_jun27a.ino.elf /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch_jun27a.ino.hex
chmod +x /home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/scripts/create_disassembler_listing.sh
/home/pi/.arduino15/packages/MiniCore/hardware/avr/2.2.2/scripts/create_disassembler_listing.sh /home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objdump "--disassemble --source --line-numbers --demangle --section=.text" /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch_jun27a.ino.elf /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch_jun27a.ino_atmega328p_16000000L.lst
/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-size -A /tmp/arduino/sketches/C54C3143563E1398C551788FC9AEB775/sketch_jun27a.ino.elf
Sketch uses 808 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
So ya it looks like two commands are being run . Well!
Note the difference between the avr-gcc paths in the two outputs.
I think the problem is that you used a package manager (e.g., Aptitude) to install Arduino IDE instead of using the real Arduino IDE downloaded from arduino.cc. The IDE you get from the package manager is modified, which causes some arbitrary version of avr-gcc to be used instead of using the 7.3.0-atmel3.6.1-arduino7 version that is required by MiniCore.
I strongly recommend always downloading Arduino IDE from the "Software" page of arduino.cc. If you want an older version, you can get those here: