Learning how to use AVRDUDE?

Hi,

For no other reason that "it just took my fancy", I wanted to try using AVRDUDE from the command line.
Up to now, if I wanted to do this, I had used an ISP Programmer (Pololu) and this simple command:

./avrdude  -v -p atmega328p -c stk500 -P /dev/ttyACM0

... gives an output like this:

avrdude: Version 6.3-20190619
         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/mprowe/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : stk500
         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    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 : STK500V2
         Description     : Atmel STK500
         Programmer Model: STK500
         Hardware Version: 15
         Firmware Version Master : 2.10
         Topcard         : Unknown
         Vtarget         : 4.7 V
         SCK period      : 0.5 us
         Varef           : 0.0 V
         Oscillator      : Off

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as FD

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:DA, L:FF)
avrdude done.  Thank you.

However, if I wanted to use the USB/Serial programming interface, I issue this command (cribbed from the Arduino IDE Action window) which replaces the stk500 controller (-c) with the arduino controller:

./avrdude  -v -p atmega328p -c arduino -P /dev/ttyACM2 -b 115200

... but this gives:

avrdude: Version 6.3-20190619
         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/mprowe/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM2
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         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    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 : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 4.4
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK (E:00, H:00, L:00)
avrdude done.  Thank you.

Note: No fuse information?

Is this correct?

Regards, M.

PS: ./avrdue is a soft link to: /bin/avrdude -C etc/avrdude.conf $*
OS is openSUSE 15.2

AVRDUDE has an odd behavior where it is in "safemode" by default, but when it is "run from a script" (whatever that means), "safemode" is automatically disabled:

$ avrdude --help
...
-u                         Disable safemode, default when running from a script.

The manual provides different information on the subject, which makes things more clear:

-u
Disables the default behaviour of reading out the fuses three times before programming, then verifying at the end of programming that the fuses have not changed.

When you do an upload in the Arduino IDE, AVRDUDE considers this as being "run from a script", so safemode is disabled.

But when you are using AVRDUDE from the command line, safemode is on by default. So you will get different results from running the same command as the IDE from the command line.

Thank you for the suggestion. However, I suspect that I did not make the question clear?
The test situation is this:

Avrdude running from the command line in both cases and talking to the same AT328P. Like this:

./avrdude  -v -p atmega328p -c stk500 -P /dev/ttyACM0   //First test...

./avrdude  -v -p atmega328p -c arduino -P /dev/ttyACM1  //Second test

The output of the first test shows (and in this case correct) values for the three fuses.
However, the output from the second test shows all zeros for the fuses?

In the first test, the programming is via the ISP protocol and in the second it is using the Serial/OptiBoot services.
Can avrdude via the bootloader (-c arduino) read and/or write the ATMega328 fuses?

Regards, M

Arduino bootloader (Optiboot) (-c arduino) cannot access fuses of ATmega.
From: Home · Optiboot/optiboot Wiki · GitHub

Optiboot implements a small subset of the "STK500 communications protocol" (version 1) ... In order to conserve code space, many of the protocol commands are ignored and receive "lies" rather than correct response codes.

You can read/set fuses via ISP.

Or you can read fuses with a sketch like this:

#include <avr/boot.h>

void setup() {
    Serial.begin(9600);

    cli();
    uint8_t lowBits      = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS);
    uint8_t highBits     = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
    uint8_t extendedBits = boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS);
    uint8_t lockBits     = boot_lock_fuse_bits_get(GET_LOCK_BITS);
    sei();

    Serial.print("Low:  0x");
    Serial.println(lowBits, HEX);
    Serial.print("High: 0x");
    Serial.println(highBits, HEX);
    Serial.print("Ext:  0x");
    Serial.println(extendedBits, HEX);
    Serial.print("Lock: 0x");
    Serial.println(lockBits, HEX);
}

void loop() { }