[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 Terminal Mode Examples

Enter terminal, display part parameters, modify EEPROM, perform a chip erase and quit:

 
$ avrdude -qq -c usbasp -p atmega328p -t

avrdude> part
ATmega328P with programming modes ISP, HVPP, debugWIRE, SPM

Memory        Size  Pg size
---------------------------
eeprom        1024        4
flash        32768      128
efuse            1        1
hfuse            1        1
lfuse            1        1
lock             1        1
signature        3        1
calibration      1        1
io             224        1
sram          2048        1

Variants         Package  F max   T range         V range
----------------------------------------------------------------
ATmega328P       N/A      20 MHz  [-40 C,   N/A]  [1.8 V, 5.5 V]
ATmega328P-15MZ  MLF32    20 MHz  [-40 C,  85 C]  [1.8 V, 5.5 V]
ATmega328P-AN    TQFP32   20 MHz  [-40 C, 105 C]  [1.8 V, 5.5 V]
ATmega328P-ANR   TQFP32   20 MHz  [-40 C, 105 C]  [1.8 V, 5.5 V]
ATmega328P-AU    TQFP32   20 MHz  [-40 C,  85 C]  [1.8 V, 5.5 V]
ATmega328P-AUR   TQFP32   20 MHz  [-40 C,  85 C]  [1.8 V, 5.5 V]
ATmega328P-MMH   MLF28    20 MHz  [-40 C,  85 C]  [1.8 V, 5.5 V]
ATmega328P-MMHR  MLF28    20 MHz  [-40 C,  85 C]  [1.8 V, 5.5 V]
ATmega328P-MN    QFN32    20 MHz  [-40 C, 105 C]  [1.8 V, 5.5 V]
ATmega328P-MNR   MLF32    20 MHz  [-40 C, 105 C]  [1.8 V, 5.5 V]
ATmega328P-MU    MLF32    20 MHz  [-40 C,  85 C]  [1.8 V, 5.5 V]
ATmega328P-MUR   MLF32    20 MHz  [-40 C,  85 C]  [1.8 V, 5.5 V]
ATmega328P-PN    PDIP28   20 MHz  [-40 C, 105 C]  [1.8 V, 5.5 V]
ATmega328P-PU    PDIP28   20 MHz  [-40 C,  85 C]  [1.8 V, 5.5 V]

avrdude> dump eeprom 0 16
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> write eeprom 0 1 2 3 4 0xcafe "Avrdude"

avrdude> dump eeprom 0 16
0000  01 02 03 04 fe ca 41 76  72 64 75 64 65 00 ff ff  |......Avrdude...|

avrdude> flush

avrdude> erase
erasing chip ...

avrdude> dump eeprom 0 16
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> quit

Program the fuse bits of an ATmega328P with a fuse calculator

First display the factory defaults, then consult an external fuse calculator, select the ATmega328P part, find above settings, note the ensuinig new values for the three fuses and reprogram:

 
$ avrdude -c usbasp -p atmega328p -t

avrdude> dump efuse
Reading | ################################################## | 100% 0.00 s
0000  ff                                                |.               |

avrdude> dump hfuse
Reading | ################################################## | 100% 0.00 s
0000  d9                                                |.               |

avrdude> dump lfuse
Reading | ################################################## | 100% 0.00 s
0000  62                                                |b               |

avrdude> #
avrdude> # Consult external fuse calculator
avrdude> #
avrdude> #

avrdude> write efuse 0xfd
Writing | ################################################## | 100% 0.01 s

avrdude> write hfuse 0xde
Writing | ################################################## | 100% 0.01 s

avrdude> write lfuse 0xf7
Writing | ################################################## | 100% 0.01 s

avrdude> quit

Avrdude done.  Thank you.

Program the fuse bits of an ATmega328P with the config command

 
$ avrdude -qq -c usbasp -p atmega328p -t

avrdude> # Show all configurations
avrdude> config
config sut_cksel=intrcosc_8mhz_6ck_14ck_65ms # 34
config ckout=co_disabled # 1
config ckdiv8=by_8 # 0
config bootrst=application # 1
config bootsz=bs_2048w # 0
config eesave=ee_erased # 1
config wdton=wdt_programmable # 1
config spien=isp_enabled # 0
config dwen=dw_off # 1
config rstdisbl=external_reset # 1
config bodlevel=bod_disabled # 7
config lb=no_lock # 3
config blb0=no_lock_in_app # 3
config blb1=no_lock_in_boot # 3

avrdude> # Show possible values for full-swing external crystal
avrdude> config sut_cksel=extfs
avrdude warning: (config) ambiguous; known sut_cksel extfs symbols are:
 - sut_cksel=extfsxtal_258ck_14ck_4ms1 #  6
 - sut_cksel=extfsxtal_1kck_14ck_65ms  #  7
 - sut_cksel=extfsxtal_258ck_14ck_65ms # 22
 - sut_cksel=extfsxtal_16kck_14ck_0ms  # 23
 - sut_cksel=extfsxtal_1kck_14ck_0ms   # 38
 - sut_cksel=extfsxtal_16kck_14ck_4ms1 # 39
 - sut_cksel=extfsxtal_1kck_14ck_4ms1  # 54
 - sut_cksel=extfsxtal_16kck_14ck_65ms # 55

avrdude> # Set the one with appropriate startup times
avrdude> c su=55

avrdude> # Unprogram clock division by 8, make reset jump to boot loader
avrdude> c ckdiv8=1
avrdude> c bootrst=boot
avrdude> c bootsz=bs_256w

avrdude> # Query which bod levels exist; set brown-out at 2.7 V
avrdude> c bodlevel=
# conf bodlevel=bod_4v3      # 4
# conf bodlevel=bod_2v7      # 5
# conf bodlevel=bod_1v8      # 6
config bodlevel=bod_disabled # 7 (factory)
avrdude> c bod=*2v7

avrdude> quit

Show and change registers

 
$ avrdude -c xplainedmini_updi -p ATtiny817 \
  -T "reg ctrlc" -T "reg usart0.baud=0x1234" -T "reg -asv usart0"

Processing -T reg ctrlc
0x00 portmux.ctrlc
0x00 adc0.ctrlc
0x03 usart0.ctrlc
0x00 tca0.ctrlc
0x00 tcd0.ctrlc

Processing -T reg usart0.baud=0x1234

Processing -T reg -asv usart0
I/O 0x800: (1)   0x00 usart0.rxdatal  # Receive data low byte
I/O 0x801: (1)   0x00 usart0.rxdatah  # Receive data high byte
I/O 0x802: (1)   0x00 usart0.txdatal  # Transmit data low byte
I/O 0x803: (1)   0x00 usart0.txdatah  # Transmit data high byte
I/O 0x804: (1)   0x20 usart0.status   # Status register
I/O 0x805: (1)   0x00 usart0.ctrla    # Control register A
I/O 0x806: (1)   0x00 usart0.ctrlb    # Control register B
I/O 0x807: (1)   0x03 usart0.ctrlc    # Control register C
I/O 0x808: (2) 0x1234 usart0.baud     # Baud rate register (16 bits)
I/O 0x80b: (1)   0x00 usart0.dbgctrl  # Debug control register
I/O 0x80c: (1)   0x00 usart0.evctrl   # Event control register
I/O 0x80d: (1)   0x00 usart0.txplctrl # IRCOM transmitter pulse length control register
I/O 0x80e: (1)   0x00 usart0.rxplctrl # IRCOM receiver pulse length control register

Avrdude done.  Thank you.

Show register file of a classic part

 
$ avrdude -qq -p ATtiny11 -c dryrun -T "regfile -av"

I/O 0x08: ac.acsr     # Analog comparator control and status register
I/O 0x16: portb.pinb  # Port B input register
I/O 0x17: portb.ddrb  # Port B data direction register
I/O 0x18: portb.portb # Port B data register
I/O 0x21: wdt.wdtcr   # Watchdog timer control register
I/O 0x32: tc0.tcnt0   # Timer/counter 0
I/O 0x33: tc0.tccr0   # T/C 0 control register
I/O 0x34: cpu.mcusr   # MCU status register
I/O 0x35: cpu.mcucr   # MCU control register
I/O 0x38: tc0.tifr    # T/C interrupt flag register
I/O 0x39: tc0.timsk   # T/C interrupt mask register
I/O 0x3a: exint.gifr  # General interrupt flag register
I/O 0x3b: exint.gimsk # General interrupt mask register
I/O 0x3f: cpu.sreg    # Status register

The following example demonstrates negative address and length bytes, and the fill form of the write command using an ellipis ... where the last data item provided is used to fill up the indicated memory range.

 
$ avrdude -c usbasp -p atmega328p -t

avrdude> dump flash -64 -33
Reading | ################################################## | 100% 0.02 s
7fc0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
7fd0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> dump flash -32 -1
Reading | ################################################## | 100% 0.00 s
7fe0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
7ff0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> write flash -64 1234567890 'A' 'V' 'R' 2.718282 0xaa 0xbb 0xcc "Hello World!"
Caching | ################################################## | 100% 0.00 s

avrdude> write flash -32 -1 0x01 0b00000010 0b11 0x04 0x05 ...
Caching | ################################################## | 100% 0.00 s

avrdude> read flash -64 -33
Reading | ################################################## | 100% 0.00 s
7fc0  d2 02 96 49 41 56 52 55  f8 2d 40 aa bb cc 48 65  |...IAVRU.-@...He|
7fd0  6c 6c 6f 20 57 6f 72 6c  64 21 00 ff ff ff ff ff  |llo World!......|

avrdude> read flash -32 -1
Reading | ################################################## | 100% 0.00 s
7fe0  01 02 03 04 05 05 05 05  05 05 05 05 05 05 05 05  |................|
7ff0  05 05 05 05 05 05 05 05  05 05 05 05 05 05 05 05  |................|

avrdude> flush
Synching cache to device ...
Writing | ################################################## | 100% 0.05 s

avrdude> quit

Avrdude done.  Thank you.

Disassembe the flash contents of an ATtiny13A, write the output to file blink.S, compile to ‘blink.elf‘ and verify that the flash contents of the ATtiny13A is the same as the one given by the compiled blink.elf. Then cat the disassembled blink.S to stdout.

 
$ avrdude -qq -p t13a -c avrisp2 -T "disasm -g flash 0 -1" >blink.S
$ avr-gcc -mmcu=attiny13a -nostdlib -Wl,--section-start=.text=0x0000 blink.S -o bl.elf
$ avrdude -qq -p t13a -c avrisp2 -U flash:v:bl.elf && echo OK
OK

$ cat blink.S

       .equ    io.pinb, 0x16
       .equ    io.ddrb, 0x17

       .text
main:
L000:  rjmp    Label1               ; L016
L002:  rjmp    Label0               ; L014
L004:  rjmp    Label0               ; L014
L006:  rjmp    Label0               ; L014
L008:  rjmp    Label0               ; L014
L00a:  rjmp    Label0               ; L014
L00c:  rjmp    Label0               ; L014
L00e:  rjmp    Label0               ; L014
L010:  rjmp    Label0               ; L014
L012:  rjmp    .+0                  ; L014

; Rjmp from L002, L004, L006, L008, L00a, L00c, L00e, L010
Label0:
L014:  reti

Label1:                             ; Rjmp from L000
L016:  sbi     io.ddrb, 2           ; Bit 2 = 0x04

Label2:                             ; Rjmp from L024
L018:  ldi     r29, 0x1e            ; 30

Label3:                             ; Brne from L01c, L020
L01a:  sbiw    r30, 0x01            ; 1
L01c:  brne    Label3               ; L01a
L01e:  dec     r29
L020:  brne    Label3               ; L01a
L022:  sbi     io.pinb, 2           ; Bit 2 = 0x04
L024:  rjmp    Label2               ; L018

L026:  .fill   493, 2, 0xffff

Mixing terminal commands and -U memory operations: the example below burns a bootloader, uses a terminal line to write application data to flash, loads the application, configures the brownout detection level to 2.7 V and, finally, stores the full flash as new hex file. Note the use of different quotation marks in bash to pass the terminal command lines as single entity to AVRDUDE.

 
$ avrdude -qc dryrun -p m328p \
          -U urboot_m328p_1s_autobaud_uart0_pr_ee_ce.hex \
          -T 'write flash 0x7D00 0xc0cac01a 0xcafe "secret Coca Cola recipe"' \
          -U flash:w:cola-vending-machine.hex \
          -T "config -v bod=*2v7" \
          -U flash:r:app+data.hex:I

Processing -U flash:w:urboot_m328p_1s_autobaud_uart0_pr_ee_ce.hex:i
Reading 368 bytes for flash from input file urboot_m328p_1s_autobaud_uart0_pr_ee_ce.hex
Writing 368 bytes to flash, 368 bytes written, 368 verified

Processing -T write flash 0x7D00 0xc0cac01a 0xcafe "secret Coca Cola recipe"
Synching cache to device ... done

Processing -U flash:w:cola-vending-machine.hex:i
Reading 736 bytes for flash from input file cola-vending-machine.hex
Writing 736 bytes to flash, 736 bytes written, 736 verified

Processing -T config -v bod=*2v7
config bodlevel=bod_2v7 # 5

Processing -U flash:r:app+data.hex:I
Reading flash memory ...
Writing 32768 bytes to output file app+data.hex

Avrdude done.  Thank you.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Stefan Rueger on August 24, 2024 using texi2html 1.82.