Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Programming A-Star 328PB using USB AVR Programmer V2 on PlatformIO

Sharing what did and didn’t work for me when programming an A-Star 328PB (5V, 16MHz) using the Pololu USB AVR Programmer V2 on PlatformIO.

Was trying to upload a simple blink program but kept receiving the following error

avrdude: verification error, first mismatch at byte 0x0002
         0x9c != 0x9d
avrdude: verification error; content mismatch

So avrdude connected properly, wrote successfully but verification failed. Seems like the platform.ini was missing the upload flag -e which erases the chip prior to write.

The following platform.ini worked successfully …

[env:ATmega328PB]
platform = atmelavr
board = ATmega328PB
framework = arduino
board_build.f_cpu = 16000000L
upload_protocol = stk500v2
upload_flags =
    -e

Perhaps someone who knows how can add this the PlatformIO AVR ecosystem. Also, I post on forums once a decade so sorry in advance.

Hello.

I am glad you were able to get it working, and thank you for posting what worked for you. I am not familiar with using PlatformIO to program hardware, but this thread on the PlatformIO forum suggests that you might try using the program target and avoid using the upload target.

–David

Hi Everyone!
I can’t seem to program a:

  • Pololu A-Star 328PB Micro (5V, 16Mhz variant)
  • via Pololu USB AVR v2.1 firm_v1.02
  • in PlatformIO extension in VScode.

I have verified operation of both the programmer and board by ‘Pololu Programmer Configuration Tool’ and by using Arduino IDE> Blink was successful with no errors.

We use VScode with PIO as it’s truly amazing in how it changed our work flow. (integrated GitHub) Anyone reading this who is still using the Arduino IDE, should give it a try.

Normally, with thousands of boards entered in the PIO ecosystem, a simple search by board maker sets us up. Pololu has one board there.(A-Star 32U4)
I found this forum thread and tried changing ‘platformio.ini’ as this is the way to add a custom board. The mods posted here didn’t work for me. After reading some other forums, I tried a few code additions, still failure.

  • I have not ruled out an incorrect setting in the Configuration Tool BUT these same settings allow Arduino IDE to function OK so I’m assuming they are the same via PlatformIO/avrdude.

I’d be really grateful for any help.
-Chris

note: COM6 is confirmed Pololu AVR TTL Serial Port
----- platformio.ini ------

[env:ATmega328PB]
platform = atmelavr
board = ATmega328PB
framework = arduino
board_build.f_cpu = 16000000L
upload_protocol = stk500v2
upload_port = COM6
upload_speed = 115200
upload_flags =
-e

---- COMPILE AND UPLOAD RESULTS -------
avrdude: stk500v2_ReceiveMessage(): timeout

---- FULL TERMINAL TEXT HERE ---------

Executing task in folder InteractiveSystem: C:\Users\Administrator.platformio\penv\Scripts\pio.exe run --target upload <
Processing ATmega328PB (platform: atmelavr; board: ATmega328PB; framework: arduino)
Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega328PB.html
PLATFORM: Atmel AVR (1.13.0) > Atmel ATmega328PB
HARDWARE: ATMEGA328PB 16MHz, 2KB RAM, 31.50KB Flash
PACKAGES:

  • framework-arduinoavr 3.10623.190424 (1.6.23)
  • tool-avrdude 1.60300.190424 (6.3.0)
  • toolchain-atmelavr 1.50400.0 (5.4.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\ATmega328PB\src\main.cpp.o
    Archiving .pio\build\ATmega328PB\libFrameworkArduinoVariant.a
    Compiling .pio\build\ATmega328PB\FrameworkArduino\CDC.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\HardwareSerial.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\HardwareSerial0.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\HardwareSerial1.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\HardwareSerial2.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\HardwareSerial3.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\IPAddress.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\PluggableUSB.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\Print.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\Stream.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\Tone.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\USBCore.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\WInterrupts.c.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\WMath.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\WString.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\abi.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\hooks.c.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\main.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\new.cpp.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\wiring.c.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\wiring_analog.c.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\wiring_digital.c.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\wiring_pulse.S.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\wiring_pulse.c.o
    Compiling .pio\build\ATmega328PB\FrameworkArduino\wiring_shift.c.o
    Archiving .pio\build\ATmega328PB\libFrameworkArduino.a
    Linking .pio\build\ATmega328PB\firmware.elf
    Building .pio\build\ATmega328PB\firmware.hex
    Checking size .pio\build\ATmega328PB\firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 0.4% (used 9 bytes from 2048 bytes)
    Flash: [ ] 3.6% (used 1154 bytes from 32256 bytes)
    Configuring upload protocol…
    AVAILABLE: stk500v2
    CURRENT: upload_protocol = stk500v2
    Looking for upload port…
    Use manually specified: COM6
    Uploading .pio\build\ATmega328PB\firmware.hex
    avrdude: stk500v2_ReceiveMessage(): timeout

Hello, Chris_J.

I am sorry you are having trouble using PlatformIO with your A-Star 328PB Micro and the Pololu USB AVR Programmer v2.1. Are you trying to program the A-Star using its serial bootloader (i.e. the TX or RX pins) or with its ISP interface? Can you send me the exact AVRDUDE command that PlatformIO is running so that I can check that all the arguments to AVRDUDE are correct?

–David

Hi David!
Thanks for your help. Please know that I’m very happy with Pololu. Your products, forums, support, website ordering and resources, even packaging are top notch. I will always check with you first for parts.
To this problem…

  • I’m programming via (TX/RX pins) not ISP. (I need ISP and secondary ISP pins for another part)
  • I’ve figured out how to run the compile process verbose in Platform IO.
    This made a mess specific to the build but not the avrdude command. I did find the avrdude.conf file that would make the command but can’t get a verbose version of the command BUT I’ve got the verbose output (below).
    Below is the section I think you want…but I’m going to follow in another post with the complete (long and horrible) 328 atmel section of that entire file.
    (I’m so sorry!! You deserve hazard pay!)
    Maybe you can make some sense out of it with your experienced eyes.

-Chris

— Suspected pertinent section of avrdude,.conf—

part parent “m328”
id = “m328pb”;
desc = “ATmega328PB”;
signature = 0x1e 0x95 0x16;
ocdrev = 1;

–Meanwhile in another section…

programmer
id = “stk500v2”;
desc = “Atmel STK500 Version 2.x firmware”;
type = “stk500v2”;
connection_type = serial;
;

------ Verbose avrdude runtime output --------

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_command(): failed miserably to execute command 0x03
avrdude: stk500v2_getparm(): failed to get parameter 0x91
avrdude: stk500v2_ReceiveMessage(): timeout

– Platform IO ‘avrdude.conf’ section for this build —

#------------------------------------------------------------
# ATmega328
#------------------------------------------------------------
part
    id      = "m328";
    desc    = "ATmega328";
    has_debugwire = yes;
    flash_instr   = 0xB6, 0x01, 0x11;
    eeprom_instr  = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00,
        0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF,
        0x99, 0xF9, 0xBB, 0xAF;
    stk500_devcode  = 0x86;
    # avr910_devcode  = 0x;
    signature   = 0x1e 0x95 0x14;
    pagel   = 0xd7;
    bs2     = 0xc2;
    chip_erase_delay  = 9000;
    pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
     "x x x x x x x x x x x x x x x x";
    chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x",
     "x x x x x x x x x x x x x x x x";
    timeout = 200;
    stabdelay = 100;
    cmdexedelay = 25;
    synchloops  = 32;
    bytedelay = 0;
    pollindex = 3;
    pollvalue = 0x53;
    predelay  = 1;
    postdelay = 1;
    pollmethod  = 1;
    pp_controlstack =
  0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F,
  0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F,
  0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B,
  0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00;
    hventerstabdelay  = 100;
    progmodedelay = 0;
    latchcycles   = 5;
    togglevtg   = 1;
    poweroffdelay = 15;
    resetdelayms  = 1;
    resetdelayus  = 0;
    hvleavestabdelay  = 15;
    resetdelay    = 15;
    chiperasepulsewidth = 0;
    chiperasepolltimeout = 10;
    programfusepulsewidth = 0;
    programfusepolltimeout = 5;
    programlockpulsewidth = 0;
    programlockpolltimeout = 5;
    ocdrev              = 1;
    memory "eeprom"
  paged   = no;
  page_size = 4;
  size    = 1024;
  min_write_delay = 3600;
  max_write_delay = 3600;
  readback_p1 = 0xff;
  readback_p2 = 0xff;
  read = " 1 0 1 0 0 0 0 0",
         " 0 0 0 x x x a9 a8",
         " a7 a6 a5 a4 a3 a2 a1 a0",
         " o o o o o o o o";
  write = " 1 1 0 0 0 0 0 0",
          " 0 0 0 x x x a9 a8",
    " a7 a6 a5 a4 a3 a2 a1 a0",
    " i i i i i i i i";
  loadpage_lo = " 1 1 0 0 0 0 0 1",
          " 0 0 0 0 0 0 0 0",
          " 0 0 0 0 0 0 a1 a0",
          " i i i i i i i i";
  writepage = " 1 1 0 0 0 0 1 0",
        " 0 0 x x x x a9 a8",
        " a7 a6 a5 a4 a3 a2 0 0",
        " x x x x x x x x";
  mode    = 0x41;
  delay   = 20;
  blocksize = 4;
  readsize  = 256;
    ;
    memory "flash"
  paged   = yes;
  size    = 32768;
  page_size = 128;
  num_pages = 256;
  min_write_delay = 4500;
  max_write_delay = 4500;
  readback_p1 = 0xff;
  readback_p2 = 0xff;
  read_lo = " 0 0 1 0 0 0 0 0",
      " 0 0 a13 a12 a11 a10 a9 a8",
      " a7 a6 a5 a4 a3 a2 a1 a0",
      " o o o o o o o o";
  read_hi = " 0 0 1 0 1 0 0 0",
      " 0 0 a13 a12 a11 a10 a9 a8",
      " a7 a6 a5 a4 a3 a2 a1 a0",
      " o o o o o o o o";
  loadpage_lo = " 0 1 0 0 0 0 0 0",
          " 0 0 0 x x x x x",
          " x x a5 a4 a3 a2 a1 a0",
          " i i i i i i i i";
  loadpage_hi = " 0 1 0 0 1 0 0 0",
          " 0 0 0 x x x x x",
          " x x a5 a4 a3 a2 a1 a0",
          " i i i i i i i i";
  writepage = " 0 1 0 0 1 1 0 0",
        " 0 0 a13 a12 a11 a10 a9 a8",
        " a7 a6 x x x x x x",
        " x x x x x x x x";
  mode    = 0x41;
  delay   = 6;
  blocksize = 128;
  readsize  = 256;
    ;
    memory "lfuse"
  size = 1;
  min_write_delay = 4500;
  max_write_delay = 4500;
  read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0",
         "x x x x x x x x o o o o o o o o";
  write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0",
          "x x x x x x x x i i i i i i i i";
    ;
    memory "hfuse"
  size = 1;
  min_write_delay = 4500;
  max_write_delay = 4500;
  read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0",
         "x x x x x x x x o o o o o o o o";
  write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0",
          "x x x x x x x x i i i i i i i i";
    ;
    memory "efuse"
  size = 1;
  min_write_delay = 4500;
  max_write_delay = 4500;
  read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0",
         "x x x x x x x x o o o o o o o o";
  write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0",
          "x x x x x x x x x x x x x i i i";
    ;
    memory "lock"
  size = 1;
  min_write_delay = 4500;
  max_write_delay = 4500;
  read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0",
         "x x x x x x x x x x o o o o o o";
  write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x",
          "x x x x x x x x 1 1 i i i i i i";
    ;
    memory "calibration"
  size = 1;
  read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x",
         "0 0 0 0 0 0 0 0 o o o o o o o o";
    ;
    memory "signature"
  size = 3;
  read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x",
         "x x x x x x a1 a0 o o o o o o o o";
    ;
;
part parent "m328"
    id      = "m328p";
    desc    = "ATmega328P";
    signature   = 0x1e 0x95 0x0F;
    ocdrev              = 1;
;
part parent "m328"
    id      = "m328pb";
    desc    = "ATmega328PB";
    signature   = 0x1e 0x95 0x16;
    ocdrev              = 1;
;
#------------------------------------------------------------

Hello, Chris.

Could you try changing the “type” from “stk500v2” to “arduino” and see if that helps? I suspect that PlatformIO is passing the argument “-cstk500v2” to AVRDUDE. That would be the right argument to use if you are using the ISP interface, but if you are talking to the serial bootloader on the A-Star 328PB, that argument needs to be “-carduino”.

If you continue having trouble, I still need to see your actual AVRDUDE command so I can check all of the arguments that PlatformIO is passing to AVRUDE. To give you an idea of what the AVRDUDE command looks like, here is the command that the Arduino IDE uses when I try to program an A-Star 328PB board on COM8:

C:\arduino-1.8.13\hardware\tools\avr/bin/avrdude -CC:\arduino-1.8.13\hardware\tools\avr/etc/avrdude.conf -C+C:\Users\david\AppData\Local\Arduino15\packages\pololu-a-star\hardware\avr\4.0.2/extra_avrdude.conf -v -patmega328pb -carduino -PCOM8 -b115200 -D -Uflash:w:C:\arduino_build/MySketch.ino.hex:i 

I was able to see this command by turning on verbose output in the Arduino Preferences window, which is accessible from the File menu.

–David

Hi David,
You have the solution!
I can also confirm that using a normal FTDI cable was also a solution.
(I don’t believe for the 3 Volt versions!)

So here’s the required platformio.ini portions needed to be successful with each scenario:

  • Pololu A-Star 328PB Micro (5V 16Mhz Variant)
    w/ FTDI Cable
[env:ATmega328PB] 
platform = atmelavr
board = ATmega328PB
framework = arduino
  • Pololu A-Star 328PB Micro
    w/ TTL Programmer> Pololu USB AVR v2.1 firm_v1.02
    (Note: First must have drivers installed, VCC enabled and voltage set correctly)
[env:ATmega328PB] 
platform = atmelavr
board = ATmega328PB
framework = arduino
upload_protocol = arduino
upload_port = COM5   ; YOUR AVR "TTL Serial" Port
  • Pololu A-Star 328PB Micro
    w/ ISP Programmer> Pololu USB AVR v2.1 firm_v1.02
    (Note: First must have drivers installed, VCC enabled and voltage set correctly)
[env:ATmega328PB] 
platform = atmelavr
board = ATmega328PB
framework = arduino
upload_protocol = stk500v2
upload_port = COM6   ; YOUR AVR "Programming" Port
  • Below are some default settings in the Atmega328 [env] but worth mentioning to try if trouble:
board_build.f_cpu = 16000000L
upload_speed = 115200

Thanks for your help! :grinning: