PlatformIO Community

Atmega 328 - Internal 8MHZ oscillator - Atmel ICE upload troubles

I have an Atmega 328p on a breadboard that is configured to run off of the internal 8 MHz clock. I am unsuccessfully trying to upload a simple hello world to it from PlatformIO. I have verified that I am able to use the Atmel ICE programmer to upload a program via the VisualMicro Visual Studios Plugin and the Arduino IDE, but I am totally flailing around trying to figure out how to make it work in PlatformIO.

I’ve spent some time trying to understand the solution found in this post:

And I’m a little embarrassed that I am so lost after all of the instructions in that post.

Here is my “platformio.ini”:

[env:Breadboard ATMega328]
platform = atmelavr
board = 328p8m
framework = arduino
board_build.mcu = atmega328p
board_build.f_cpu = 8000000L
upload_protocol = atmel-ice

Result:

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/328p8m.html
PLATFORM: Atmel AVR 1.15.0 > Microduino Core (Atmega328P@8M,3.3V)
HARDWARE: ATMEGA328P 8MHz, 2KB RAM, 31.50KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), framework-arduinoavr 4.1.2, tool-avrdude 1.60300.190424 (6.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies…
No dependencies
Building in release mode
Compiling .pio\build\Breadboard ATMega328\src\main.cpp.o
Archiving .pio\build\Breadboard ATMega328\libFrameworkArduinoVariant.a
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\CDC.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\HardwareSerial.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\HardwareSerial0.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\HardwareSerial1.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\HardwareSerial2.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\HardwareSerial3.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\IPAddress.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\PluggableUSB.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\Print.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\Stream.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\Tone.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\USBCore.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\WInterrupts.c.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\WMath.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\WString.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\abi.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\hooks.c.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\main.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\new.cpp.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\wiring.c.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\wiring_analog.c.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\wiring_digital.c.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\wiring_pulse.S.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\wiring_pulse.c.o
Compiling .pio\build\Breadboard ATMega328\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\Breadboard ATMega328\libFrameworkArduino.a
Linking .pio\build\Breadboard ATMega328\firmware.elf
Checking size .pio\build\Breadboard ATMega328\firmware.elf
Building .pio\build\Breadboard ATMega328\firmware.hex
Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
DATA: [= ] 10.0% (used 204 bytes from 2048 bytes)
PROGRAM: [= ] 5.3% (used 1724 bytes from 32256 bytes)
Configuring upload protocol…
AVAILABLE: atmel-ice
CURRENT: upload_protocol = atmel-ice
Looking for upload port…
Auto-detected: COM84
Uploading .pio\build\Breadboard ATMega328\firmware.hex

avrdude: Can’t find programmer id “atmel-ice”

Valid programmers are:
2232HIO = FT2232H based generic programmer
4232h = FT4232H based generic programmer
arduino = Arduino
arduino-ft232r = Arduino: FT232R connected to ISP
arduinoisp = Arduino ISP Programmer
arduinoisporg = Arduino ISP Programmer
atmelice = Atmel-ICE (ARM/AVR) in JTAG mode
atmelice_dw = Atmel-ICE (ARM/AVR) in debugWIRE mode
atmelice_isp = Atmel-ICE (ARM/AVR) in ISP mode
atmelice_pdi = Atmel-ICE (ARM/AVR) in PDI mode
avr109 = Atmel AppNote AVR109 Boot Loader
avr910 = Atmel Low Cost Serial Programmer
avr911 = Atmel AppNote AVR911 AVROSP
avrftdi = FT2232D based generic programmer
avrisp = Atmel AVR ISP
avrisp2 = Atmel AVR ISP mkII
avrispmkII = Atmel AVR ISP mkII

avrispv2 = Atmel AVR ISP V2
buspirate = The Bus Pirate
buspirate_bb = The Bus Pirate (bitbang interface, supports TPI)
butterfly = Atmel Butterfly Development Board
butterfly_mk = Mikrokopter.de Butterfly
bwmega = BitWizard ftdi_atmega builtin programmer
C232HM = FT232H based module from FTDI and Glyn.com.au
c2n232i = serial port banging, reset=dtr sck=!rts mosi=!txd miso=!cts
dasa = serial port banging, reset=rts sck=dtr mosi=txd miso=cts
dasa3 = serial port banging, reset=!dtr sck=rts mosi=txd miso=cts
diecimila = alias for arduino-ft232r
dragon_dw = Atmel AVR Dragon in debugWire mode
dragon_hvsp = Atmel AVR Dragon in HVSP mode
dragon_isp = Atmel AVR Dragon in ISP mode
dragon_jtag = Atmel AVR Dragon in JTAG mode
dragon_pdi = Atmel AVR Dragon in PDI mode
dragon_pp = Atmel AVR Dragon in PP mode
flip1 = FLIP USB DFU protocol version 1 (doc7618)
flip2 = FLIP USB DFU protocol version 2 (AVR4023)
ft232r = FT232R Synchronous BitBang
ft245r = FT245R Synchronous BitBang
jtag1 = Atmel JTAG ICE (mkI)
jtag1slow = Atmel JTAG ICE (mkI)
jtag2 = Atmel JTAG ICE mkII
jtag2avr32 = Atmel JTAG ICE mkII im AVR32 mode
jtag2dw = Atmel JTAG ICE mkII in debugWire mode
jtag2fast = Atmel JTAG ICE mkII
jtag2isp = Atmel JTAG ICE mkII in ISP mode
jtag2pdi = Atmel JTAG ICE mkII PDI mode
jtag2slow = Atmel JTAG ICE mkII
jtag3 = Atmel AVR JTAGICE3 in JTAG mode
jtag3dw = Atmel AVR JTAGICE3 in debugWIRE mode
jtag3isp = Atmel AVR JTAGICE3 in ISP mode
jtag3pdi = Atmel AVR JTAGICE3 in PDI mode
jtagkey = Amontec JTAGKey, JTAGKey-Tiny and JTAGKey2
jtagmkI = Atmel JTAG ICE (mkI)
jtagmkII = Atmel JTAG ICE mkII
jtagmkII_avr32 = Atmel JTAG ICE mkII im AVR32 mode
lm3s811 = Luminary Micro LM3S811 Eval Board (Rev. A)
mib510 = Crossbow MIB510 programming board
mkbutterfly = Mikrokopter.de Butterfly
nibobee = NIBObee
o-link = O-Link, OpenJTAG from www.100ask.net
openmoko = Openmoko debug board (v3)
pavr = Jason Kyle’s pAVR Serial Programmer
pickit2 = MicroChip’s PICkit2 Programmer
ponyser = design ponyprog serial, reset=!txd sck=rts mosi=dtr miso=cts
siprog = Lancos SI-Prog http://www.lancos.com/siprogsch.html
stk500 = Atmel STK500
stk500hvsp = Atmel STK500 V2 in high-voltage serial programming mode
stk500pp = Atmel STK500 V2 in parallel programming mode
stk500v1 = Atmel STK500 Version 1.x firmware
stk500v2 = Atmel STK500 Version 2.x firmware
stk600 = Atmel STK600
stk600hvsp = Atmel STK600 in high-voltage serial programming mode
stk600pp = Atmel STK600 in parallel programming mode
ttl232r = FTDI TTL232R-5V with ICSP adapter
tumpa = TIAO USB Multi-Protocol Adapter
UM232H = FT232H based module from FTDI and Glyn.com.au
uncompatino = uncompatino with all pairs of pins shorted
usbasp = USBasp, http://www.fischl.de/usbasp/
usbasp-clone = Any usbasp clone with correct VID/PID
usbtiny = USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
wiring = Wiring
xplainedmini = Atmel AVR XplainedMini in ISP mode
xplainedmini_dw = Atmel AVR XplainedMini in debugWIRE mode
xplainedpro = Atmel AVR XplainedPro in JTAG mode

*** [upload] Error 1

I have edited the “328p8m.json” file to:

{
  "build": {
    "core": "arduino",
    "extra_flags": "-DARDUINO_AVR_MICRODUINO_CORE",
    "f_cpu": "8000000L",
    "mcu": "atmega328p",
    "variant": "standard"
  },
  "frameworks": [
    "arduino"
  ],
  "name": "Microduino Core (Atmega328P@8M,3.3V)",
  "upload": {
    "maximum_ram_size": 2048,
    "maximum_size": 32256
    },
  "url": "http://wiki.microduinoinc.com/Microduino-Module_Core",
  "vendor": "Microduino"
}

Which removed some upload parameters I thought might be getting in the way:

  "upload": {
    "maximum_ram_size": 2048,
    "maximum_size": 32256,
    "protocol": "arduino",
    "require_upload_port": true,
    "speed": 57600
  },

I feel like this line of the upload terminal output is the problem:

Looking for upload port…
Auto-detected: COM84
Uploading .pio\build\Breadboard ATMega328\firmware.hex

Because COM 84 is not the ICE programmer…

Does anyone see what I am doing wrong?

Thanks for reading,
-Dave

So you have tried upload_protocol = atmelice or atmelice_dw instead? What’s the output for that?

Hi Max,

Thanks a lot for the impressively quick response. I made a few changes since I was here last, and I think I am making a little progress.

My board file:

{
“build”: {
“core”: “arduino”,
“extra_flags”: “-DARDUINO_AVR_MICRODUINO_CORE”,
“f_cpu”: “8000000L”,
“mcu”: “atmega328p”,
“variant”: “standard”
},
“frameworks”: [
“arduino”
],
“fuses”: {
“efuse”: “0xFD”,
“hfuse”: “0xDA”,
“lfuse”: “0xE2”
},
“name”: “Supervisor_A328_8mhz”,
“upload”: {
“maximum_ram_size”: 2048,
“maximum_size”: 32256
},
“url”: “http://wiki.microduinoinc.com/Microduino-Module_Core”,
“vendor”: “Dave”
}

My “platformio.ini”:

[env:My_328p8m]
platform = atmelavr
board = My_328p8m
framework = arduino
upload_protocol = atmelice

upload_protocol = atmelice

avrdude: jtag3_initialize(): part ATmega328P has no JTAG interface
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

avrdude done. Thank you.

upload_protocol = atmelice_dw

avrdude: bad response to AVR sign-on command: 0xa0
avrdude: retrying with external reset applied
avrdude: bad response to AVR sign-on command: 0xa0
avrdude: retrying with external reset applied
avrdude: JTAGEN fuse disabled?
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

avrdude done. Thank you.

upload_protocol = atmelice_isp

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/My_328p8m.html
PLATFORM: Atmel AVR 1.15.0 > Supervisor_A328_8mhz
HARDWARE: ATMEGA328P 8MHz, 2KB RAM, 31.50KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), framework-arduinoavr 4.1.2, tool-avrdude 1.60300.190424 (6.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies…
No dependencies
Building in release mode
Checking size .pio\build\My_328p8m\firmware.elf
Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
DATA: [ ] 0.4% (used 9 bytes from 2048 bytes)
PROGRAM: [ ] 1.4% (used 444 bytes from 32256 bytes)
Configuring upload protocol…
AVAILABLE: atmelice_isp
CURRENT: upload_protocol = atmelice_isp
Looking for upload port…
Uploading .pio\build\My_328p8m\firmware.hex

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file “.pio\build\My_328p8m\firmware.hex”
avrdude: writing flash (444 bytes):

Writing | ################################################## | 100% 1.82s

avrdude: 444 bytes of flash written
avrdude: verifying flash memory against .pio\build\My_328p8m\firmware.hex:
avrdude: load data flash data from input file .pio\build\My_328p8m\firmware.hex:
avrdude: input file .pio\build\My_328p8m\firmware.hex contains 444 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.10s

avrdude: verifying …
avrdude: verification error, first mismatch at byte 0x0002
0x14 != 0x34
avrdude: verification error; content mismatch

avrdude: safemode: Fuses OK (E:FD, H:DA, L:E2)

avrdude done. Thank you.

1 Like

Meh. That is the right upload_protocol, but now please try additionally adding

upload_flags = -e 
1 Like

YES MAX!

Uploading .pio\build\My_328p8m\firmware.hex

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: erasing chip
avrdude: reading input file “.pio\build\My_328p8m\firmware.hex”
avrdude: writing flash (444 bytes):

Writing | ################################################## | 100% 1.83s

avrdude: 444 bytes of flash written
avrdude: verifying flash memory against .pio\build\My_328p8m\firmware.hex:
avrdude: load data flash data from input file .pio\build\My_328p8m\firmware.hex:
avrdude: input file .pio\build\My_328p8m\firmware.hex contains 444 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.10s

avrdude: verifying …
avrdude: 444 bytes of flash verified

avrdude: safemode: Fuses OK (E:FD, H:DA, L:E2)

avrdude done. Thank you.

You’re the best. I am really grateful for your help. I don’t know if you are on the dev team, but I will up my bountysource donation this month. This forum is top notch.

1 Like