0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[AVR] AVRDUDE ターミナルモードの勧め(AVRのヒューズ確認/設定)

Last updated at Posted at 2025-08-04

はじめに

 AVRDUDE は AVR マイコンの Flash や Fuse などを書き込むときによく使用されますが、普通は Makefile やバッチファイル内に記述されていていったん記述したものはあまり頻繁に書き換えることはないようです。

 ただし、コマンドラインが好きで Build から Debug まですべてコマンドラインで操作している人や、すでに書き込まれたデバイスの Fuse や Lock ビットだけ確認したいといったときは単独で AVRDUDE を使用することもあるでしょう。

実行環境

この記事では以下の環境で実行した状況について書いてあります。
・OS:Windows10
・AVRDUDE v8.1

いつもは…

D:\>avrdude -p attiny13a -c usbasp -U lfuse:r:-:b -U hfuse:r:-:b

Processing -U lfuse:r:-:b
Reading lfuse memory ...
Writing 1 byte to output file <stdout>
0b1101010

Processing -U hfuse:r:-:b
Reading hfuse memory ...
Writing 1 byte to output file <stdout>
0b11111111

Avrdude done.  Thank you.

D:\>

 こんな感じに16進か2進表示で読み出してあとはデータシートを見ながら確認という状況でしょうか。

ターミナルモードでの操作

 AVRDUDE のターミナルモードでのコマンド "config" を使用します。
config コマンドは AVRDUDE の v7.2 あたりから追加されているもののようなので、なるべく新しいバージョンを使用したほうがいいでしょう。
 ここでは v8.1 を使用してみました。

D:\>avrdude -p attiny13a -c usbasp -t
avrdude> ?
Valid commands:
  dump    : display a memory section as hex dump
  read    : alias for dump
  disasm  : disassemble a memory section
  write   : write data to memory; flash and EEPROM are cached
  save    : save memory segments to file
  backup  : backup memories to file
  restore : restore memories from file
  verify  : compare memories with file
  flush   : synchronise flash and EEPROM cache with the device
  abort   : abort flash and EEPROM writes, ie, reset the r/w cache
  erase   : perform a chip or memory erase
  config  : change or show configuration properties of the part
  factory : reset part to factory state
  regfile : I/O register addresses and contents
  include : include contents of named file as if it was typed
  sig     : display device signature bytes
  part    : display the current part information
  send    : send a raw command to the programmer
  sck     : set or get the SCK period or frequency
  verbose : display or set -v verbosity level
  quell   : display or set -q quell level for progress bars
  help    : show help message
  ?       : same as help
  quit    : synchronise flash/EEPROM cache with device and quit
  q       : abbreviation for quit

For more details about a terminal command cmd type cmd -?

Other:
  !<line> : run the shell <line> in a subshell, eg, !ls *.hex
  # ...   : ignore rest of line (eg, used as comments in scripts)

Note that not all programmer derivatives support all commands. Flash and
EEPROM type memories are normally read and written using a cache via paged
read and write access; the cache is synchronised on quit or flush commands.
The part command displays valid memories for use with dump and write.
avrdude>

 "-t" オプションを付けてターミナルモードで起動します。
 "?" か ”help” で使用できるコマンド一覧が表示されます。
 各コマンドの後ろに "-?" をつけるとコマンドごとの Help が表示されます。
 ここでは "config" コマンドを使用しますので必要に応じて "config -?" を実行しておくといいでしょう。

avrdude> config
config sut_cksel=intrcosc_9mhz6_14ck_64ms # 10
config ckdiv8=by_8 # 0
config wdton=wdt_programmable # 1
config eesave=ee_erased # 1
config spien=isp_enabled # 0
config rstdisbl=external_reset # 1
config bodlevel=bod_disabled # 3
config dwen=dw_off # 1
config selfprgen=spm_disabled # 1
config lb=no_lock # 3
avrdude>

 "config" コマンドだけでもある程度把握できますが "config -v" や "config -a" のようにするとさらに詳細な情報が表示されます。
 "config -a" では表示が多すぎて目的のものが探しにくい場合は特定のプロパティのみ表示することもできます。

avrdude> config sut_cksel= -v
# Clock source
# conf sut_cksel=extclk_14ck_0ms           #  0 = 0b0000
# conf sut_cksel=intrcosc_4mhz8_14ck_0ms   #  1 = 0b0001
# conf sut_cksel=intrcosc_9mhz6_14ck_0ms   #  2 = 0b0010
# conf sut_cksel=intrcosc_128khz_14ck_0ms  #  3 = 0b0011
# conf sut_cksel=extclk_14ck_4ms           #  4 = 0b0100
# conf sut_cksel=intrcosc_4mhz8_14ck_4ms   #  5 = 0b0101
# conf sut_cksel=intrcosc_9mhz6_14ck_4ms   #  6 = 0b0110
# conf sut_cksel=intrcosc_128khz_14ck_4ms  #  7 = 0b0111
# conf sut_cksel=extclk_14ck_64ms          #  8 = 0b1000
# conf sut_cksel=intrcosc_4mhz8_14ck_64ms  #  9 = 0b1001
config sut_cksel=intrcosc_9mhz6_14ck_64ms  # 10 = 0b1010 (factory)
# conf sut_cksel=intrcosc_128khz_14ck_64ms # 11 = 0b1011
avrdude> 
avrdude> 
avrdude> c ck= -v
# Clock prescaled
config ckdiv8=by_8 # 0 (factory)
# conf ckdiv8=by_1 # 1
avrdude>

 "#"(コメント記号)のついていない行がそのプロパティに現在設定されている値で、"(factory)"は工場出荷時のデフォルト値になります。
 ここで、 コマンド名やプロパティ名は一意に決定できるところまで省略可能なので
"config sut_cksel= -v" は "c su= -v"でも可能です。
 また、「現在の設定値」以外の選択肢の行に "#" が付いているのはこのままファイルに保存して必要に応じて編集すればそれがスクリプトファイルのようになり "include" コマンドで読み込んで実行できるためです。

 hFuseやlFuseなどを意識せずにビットの機能で表示/設定できるとデータシート無しでもかなりのところまで把握することができて非常に便利です。

 ※ 注意としてターミナルモード内では "flash" や "eeprom" の書き込みは一旦キャッシュされた後、"flush" コマンドや "q" コマンドでデバイスに書き込まれるのに対し、ヒューズはコマンド入力と同時に書き込まれるという違いがあります。"lock" ビットや "rstdisbl" などの書き換えは慎重に行う必要があります。

追記 ヒューズビットの多い "ATtiny202" でテストしてみました。

"ATtiny202" は従来の "lFuse"、"hFuse"、"eFuse" という形式ではなく "fuse0" ~ "fuse9" (一部予約済み)のように数多くあり、fuse以外にも "userrow" など非破壊メモリがいくつもあります。
 このように複雑な状況でもターミナルモードならば比較的わかりやすく確認/設定を行うことができます。

D:\>avrdude -p t202 -c serialupdi -P com13 -t
avrdude> part
ATtiny202 with programming modes SPM, UPDI

Memory           Size  Pg size  Offset
--------------------------------------
eeprom             64       32  0x1400
flash            2048       64  0x8000
fuses              10        1  0x1280
fuse0/wdtcfg        1        1  0x1280
fuse1/bodcfg        1        1  0x1281
fuse2/osccfg        1        1  0x1282
fuse4/tcd0cfg       1        1  0x1284
fuse5/syscfg0       1        1  0x1285
fuse6/syscfg1       1        1  0x1286
fuse7/append        1        1  0x1287
fuse8/bootend       1        1  0x1288
lock                1        1  0x128a
prodsig/sigrow     64       64  0x1100
signature           3        1  0x1100
sernum             10        1  0x1103
osccal16            2        1  0x1118
osccal20            2        1  0x111a
tempsense           2        1  0x1120
osc16err            2        1  0x1122
osc20err            2        1  0x1124
userrow/usersig    32       32  0x1300
io               4352        1       0
sram              128        1  0x3f80
sib                32        1       0

Variants        Package  F max   T range         V range
---------------------------------------------------------------
ATtiny202-SSF   SOIC8    20 MHz  [-40 C, 125 C]  [1.8 V, 5.5 V]
ATtiny202-SSFR  SOIC8    20 MHz  [-40 C, 125 C]  [1.8 V, 5.5 V]
ATtiny202-SSN   SOIC8    20 MHz  [-40 C, 105 C]  [1.8 V, 5.5 V]
ATtiny202-SSNR  SOIC8    20 MHz  [-40 C, 105 C]  [1.8 V, 5.5 V]
avrdude>

"part" コマンドでメモリの一覧が表示されます。
必要なメモリエリアの "dump" や "write" を行うことができるし、上で記述したATtiny13Aのようにヒューズのバイト位置やビット位置を意識することなくプロパティ名でアクセスできます。

avrdude> config
config wdtperiod=t_off # 0
config wdtwindow=t_off # 0
config bodsleep=bod_disabled # 0
config bodactive=bod_disabled # 0
config bodsampfreq=bod_1khz # 0
config bodlevel=bod_1v8 # 0
config freqsel=fcpu_20mhz # 2
config osclock=olock_disabled # 0
config cmpa=v_0 # 0
config cmpb=v_0 # 0
config cmpc=v_0 # 0
config cmpd=v_0 # 0
config cmpaen=cpa_disabled # 0
config cmpben=cpb_disabled # 0
config cmpcen=cpc_disabled # 0
config cmpden=cpd_disabled # 0
config eesave=eex_erased # 0
config rstpincfg=updi # 1
config crcsrc=nocrc # 3
config sut=sut_64ms # 7
config append=0 # 0
config bootend=0 # 0
config lb=nolock # 197
avrdude>



avrdude> config bod= -v
# Brownout detection in sleep mode
config bodsleep=bod_disabled # 0 = 0b00 (factory)
# conf bodsleep=bod_enabled  # 1 = 0b01
# conf bodsleep=bod_sampled  # 2 = 0b10

# Brownout detection in active/idle mode
config bodactive=bod_disabled     # 0 = 0b00 (factory)
# conf bodactive=bod_enabled      # 1 = 0b01
# conf bodactive=bod_sampled      # 2 = 0b10
# conf bodactive=bod_enabled_wait # 3 = 0b11

# Brownout detection sampling frequency
config bodsampfreq=bod_1khz  # 0 (factory)
# conf bodsampfreq=bod_125hz # 1

# Brownout detection level
config bodlevel=bod_1v8 # 0 = 0b000 (factory)
# conf bodlevel=bod_2v6 # 2 = 0b010
# conf bodlevel=bod_4v2 # 7 = 0b111
avrdude>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?