Atmega8 with STK500 ISP

Hi all,

I try to program a Atmega8 with the STK500 ISP. Unfortunately I’m getting the following error.

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x12 != 0x3f
avrdude: verification error; content mismatch

avrdude: safemode: hfuse reads as D9
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: safemode: hfuse reads as D9
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: safemode: Sorry, reading back fuses was unreliable. I have given up and exited programming mode

avrdude done.  Thank you.

*** [upload] Error 1

If I read this correct, it tries to do something with the efuse, but the Atmega8 has no efuse as far as I could find out.

My ini looks like this

[env:ATmega8]
platform = atmelavr
board = ATmega8
framework = arduino
board_build.f_cpu = 8000000L
upload_protocol = stk500
upload_port = COM5

BTW: I tried programing with the Atmel Studio and it just worked fine.

How can I make it work?

Thanks
Sascha

Hm if it goes to the verification then the programming part must have been done. But seems like the chip wasn’t erased before.

Can you add

upload_flags = -e

to the platformio.ini, then Build the project once and then execute a “Verbose Upload” (Project tasks → Default → Advanced → Verbose Upload All" and post the log here, starting from Use manually specified: COM5?

Hey, thanks for the quick reply.

I adjusted the upload_flags and here is the log. The verification error is gone, but still fails. :frowning:

Use manually specified: COM5
avrdude -e -v -p atmega8 -C "C:\Users\Sascha Thiel\.platformio\packages\tool-avrdude\avrdude.conf" -c stk500 -b 115200 -D -P "COM5" -U flash:w:.pio\build\ATmega8\firmware.hex:i

avrdude: Version 6.3, compiled on Sep 12 2016 at 17:24:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Sascha Thiel\.platformio\packages\tool-avrdude\avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : stk500
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega8
         Chip Erase delay              : 10000 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         4    20   128    0 no        512    4      0  9000  9000 0xff 0xff
           flash         33    10    64    0 yes      8192   64    128  4500  4500 0xff 0x00
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           efuse          0     0     0    0 no          0    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500V2
         Description     : Atmel STK500
         Programmer Model: STK500
         Hardware Version: 2
         Firmware Version Master : 2.10
         Topcard         : Unknown
         Vtarget         : 5.2 V
         SCK period      : 8.7 us
         Varef           : 0.2 V
         Oscillator      : 450.000 Hz

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x1e9307 (probably m8)
avrdude: safemode: hfuse reads as D9
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: safemode: Fuse reading not support by programmer.
              Safemode disabled.
avrdude: erasing chip
avrdude: reading input file ".pio\build\ATmega8\firmware.hex"
avrdude: writing flash (718 bytes):

Writing | ################################################## | 100% 0.75s

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

Reading | ################################################## | 100% 0.57s

avrdude: verifying ...
avrdude: 718 bytes of flash verified

avrdude: safemode: hfuse reads as D9
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: safemode: hfuse reads as D9
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: safemode: Sorry, reading back fuses was unreliable. I have given up and exited programming mode

avrdude done.  Thank you.

*** [upload] Error 1
====================================================================================================================== [FAILED] Took 5.77 seconds ======================================================================================================================

Yeah avrdude definitely needed the -e argument there in order to erase the chip and then flash the new firmware. Didn’t auto-erase.

I think the firmware has been flashed correctly, even though fuses could not be verified correctly. Can you see that e.g. with a LED blinky and changing intervals to see if the firmware updates correctly?

As I’m reading up on [avrdude-dev] [bug #49082] avrdude 6.3 fails with AT90S8515 and [avrdude-dev] [patch #9110] Let reserved fuse bits to be read as *don't and lock/unlock bits fail to verify with Atmel AVRISP mkII and avrdude 6.3.0-arduino2 · Issue #2 · arduino/avrdude-build-script · GitHub this sounds like an actual bug in avrdude.

Since a poster says that 6.3 is not working but 6.1 did work, you may as an experimant want to replace the used avrdude. For that you may try it with 6.1 and 6.2 as follows:

  • download that avrdude version from Index of /releases/avrdude/, e.g. avrdude-6.2-mingw32.zip for the 6.2 versions and Windows (win32)
  • go to the path C:\Users\Sascha Thiel\.platformio\packages\tool-avrdude\
  • once, make a backup copy of the original avrdude.exe file as e.g. avrdude.bak
  • unpack the avrdude.exe (only that, not the config file) in the opened directory, overriding the existing avrdude.exe
  • retry uploading. The avrdude: Version 6.3 output text should change accordingly.

If this confirmed works with an older version of AVRDude, then this tool is the fault and a bug report needs to be opened for them.

I downloaded the 6.2 and 6.1 according your steps.

The output with 6.2 is:

Use manually specified: COM5
avrdude -e -v -p atmega8 -C "C:\Users\Sascha Thiel\.platformio\packages\tool-avrdude\avrdude.conf" -c stk500 -b 115200 -D -P "COM5" -U flash:w:.pio\build\ATmega8\firmware.hex:i

avrdude: Version 6.2, compiled on Nov 20 2015 at 23:33:37
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Sascha Thiel\.platformio\packages\tool-avrdude\avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : stk500
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega8
         Chip Erase delay              : 10000 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         4    20   128    0 no        512    4      0  9000  9000 0xff 0xff
           flash         33    10    64    0 yes      8192   64    128  4500  4500 0xff 0x00
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           efuse          0     0     0    0 no          0    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500V2
         Description     : Atmel STK500
         Programmer Model: STK500
         Hardware Version: 2
         Firmware Version Master : 2.10
         Topcard         : Unknown
         Vtarget         : 5.2 V
         SCK period      : 8.7 us
         Varef           : 0.2 V
         Oscillator      : 450.000 Hz

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x1e9307 (probably m8)
avrdude: safemode: hfuse reads as D9
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: safemode: Fuse reading not support by programmer.
              Safemode disabled.
avrdude: erasing chip
avrdude: reading input file ".pio\build\ATmega8\firmware.hex"
avrdude: writing flash (92 bytes):

Writing | ################################################## | 100% 0.11s

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

Reading | ################################################## | 100% 0.09s

avrdude: verifying ...
avrdude: 92 bytes of flash verified

avrdude: safemode: hfuse reads as D9
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: safemode: hfuse reads as D9
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: stk500isp_read_byte(): invalid operation AVR_OP_READ on efuse memory
avrdude: safemode: Sorry, reading back fuses was unreliable. I have given up and exited programming mode

avrdude done.  Thank you.

*** [upload] Error 1
====================================================================================================================== [FAILED] Took 3.17 seconds ======================================================================================================================

The output with 6.1 is:

Use manually specified: COM5
avrdude -e -v -p atmega8 -C "C:\Users\Sascha Thiel\.platformio\packages\tool-avrdude\avrdude.conf" -c stk500 -b 115200 -D -P "COM5" -U flash:w:.pio\build\ATmega8\firmware.hex:i

avrdude: Version 6.1, compiled on Mar 13 2014 at 00:09:49
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Sascha Thiel\.platformio\packages\tool-avrdude\avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : stk500
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega8
         Chip Erase delay              : 10000 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         4    20   128    0 no        512    4      0  9000  9000 0xff 0xff
           flash         33    10    64    0 yes      8192   64    128  4500  4500 0xff 0x00
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           efuse          0     0     0    0 no          0    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500V2
         Description     : Atmel STK500
         Programmer Model: STK500
         Hardware Version: 2
         Firmware Version Master : 2.10
         Topcard         : Unknown
         Vtarget         : 5.2 V
         SCK period      : 8.7 us
         Varef           : 0.2 V
         Oscillator      : 450.000 Hz

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x1e9307
avrdude: safemode: lfuse reads as E1
avrdude: safemode: hfuse reads as D9
avrdude: safemode: Fuse reading not support by programmer.
              Safemode disabled.
avrdude: erasing chip
avrdude: reading input file ".pio\build\ATmega8\firmware.hex"
avrdude: writing flash (92 bytes):

Writing | ################################################## | 100% 0.11s

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

Reading | ################################################## | 100% 0.09s

avrdude: verifying ...
avrdude: 92 bytes of flash verified

avrdude done.  Thank you.

====================================================================================================================== [SUCCESS] Took 2.93 seconds ======================================================================================================================

Even with the 6.1 the blink programm did not work.

#include <Arduino.h>

void setup() {
    pinMode(PB0, OUTPUT);
}

void loop() {
    digitalWrite(PB0, HIGH);
    delay(500);
    digitalWrite(PB0, LOW);
    delay(500);
}

So I tried it without the arduino framework. I commented the line ;framework = arduino and changed the program like this

#include <avr/io.h>
#include <util/delay.h>

int main(void) {

    DDRB = 1 << PB0;

    while (1) {
        _delay_ms(500);
        PORTB ^= 1 << PB0;
    }
}

I tried again with all 3 versions of avrdude and it was working fine with all of those, even with the error present. To verify I changed the time on each upload.

Thats already a partial success, thanks for this. Maybe we could now find out why the arduino framework does not work. A few days ago I played around with an ATtiny85 and with and without arduino framework was working fine.

Okay so 6.1 works and doesn’t verify non-existing fuses, although all avrdude versions flash the program correctly anyways. And I understand you correctly the native program with PORTB access worked also in all 3 cases?

This code is wrong. Arduino has a pin mapping in place and you can’t directly input a macro from avr/iom8.h.

When I compile the code (and follow the Intellisense definitions) I see that the Arduino core Minicore used with the variant “standard” is being used. There it defines pin PB0 as digital I/O number 8.

So you have to write PIN_B0 instead of PB0 everywhere, otherwise you’re writing to digital I/O number 0 which is PD0 (since #define PB0 0 in header).

The core’s documentation also tells you the same thing.

Note that you don’t have to use the digital pin numbers to refer to the pins. You can also use some predefined macros that maps “Arduino pins” to the port and port number:

digitalWrite(PIN_PB5, HIGH);>

// Results in the exact same compiled code
digitalWrite(13, HIGH);

Correct!

Oh boy! That was the issue! I just expected it to work, because intellisense gave me the option.

With this change I tried again all 3 versions of avrdude and they all worked for framework = arduino as well.

Conclusion:

  1. The one and only real problem was the flag -e, even with the efuse warning and telling it failed, it did / does work. But I might stick to 6.1 just because I don’t like the FAILED message in the end.
  2. You are awesome!
  3. I love this board!

Thanks a lot!