Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
DISCONTINUED:openSUSE:11.2:Update
avr-libc
avr_isp.pl
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File avr_isp.pl of Package avr-libc
#! /usr/bin/perl -w # # avr_isp.pl - In-circuit-programmer script for atmega and attiny CPUs. # using either avrdude or uisp. # # (C) Copyright 2008, Juergen Weigert, jw@suse.de # Distribute under GPLv2, use with care. # # This collects all the intricate cases from my monstereous Makefiles. # # 2007-07-11, jw, v0.3 -- tested: upload download clock # 2008-01-28, jw, v0.4 -- added: output of cpu_mhz.h to clock command. my $version = '0.4'; my $parport = '/dev/parport0'; my $dongle_type = 'stk200'; my $verify = 1; my $verbose = 1; my $noop = 0; my $programmer = '--none--'; my $cpu = 'auto'; my $avrdude_ee_count = 0; my $avrdude_opt = ''; # keep this table in sync with eeprom.h # keep this table in sync with include/avr/io*.h RAMEND,E2END,FLASHEND my %cpu = ( tiny11 => { flashsz => 1024, eesz => 0, ramsz => 0 }, tiny12 => { flashsz => 1024, eesz => 64, ramsz => 0 }, tiny13 => { flashsz => 1024, eesz => 64, ramsz => 64 }, tiny2313 => { flashsz => 2*1024, eesz => 128, ramsz => 128 }, tiny24 => { flashsz => 2*1024, eesz => 128, ramsz => 128 }, tiny25 => { flashsz => 2*1024, eesz => 128, ramsz => 128 }, tiny26 => { flashsz => 2*1024, eesz => 128, ramsz => 128 }, tiny44 => { flashsz => 4*1024, eesz => 256, ramsz => 256 }, tiny45 => { flashsz => 4*1024, eesz => 256, ramsz => 256 }, tiny84 => { flashsz => 8*1024, eesz => 512, ramsz => 512 }, tiny85 => { flashsz => 8*1024, eesz => 512, ramsz => 512 }, mega48 => { flashsz => 4*1024, eesz => 256, ramsz => 512 }, mega88 => { flashsz => 8*1024, eesz => 512, ramsz => 1024 }, mega8 => { flashsz => 8*1024, eesz => 512, ramsz => 1024 }, mega168 => { flashsz => 16*1024, eesz => 512, ramsz => 1024 }, mega128 => { flashsz =>128*1024, eesz =>4*1024, ramsz =>4*1024 }, auto => { flashsz => -1, eesz => -1, ramsz => -1 }, ); $ENV{SHELL} = '/bin/sh'; ## see what is available $programmer = 'avrdude' if `sh -c "type -t avrdude"`; $programmer = 'uisp' if `sh -c "type -t uisp"`; while (defined (my $arg = shift)) { if ($arg !~ m{^-}) { unshift @ARGV, $arg; last; } if ($arg eq '-q') { $verbose = 0; } elsif ($arg eq '-v') { $verbose++; } elsif ($arg eq '-V') { $verify = shift; } elsif ($arg eq '-n') { $noop = 1; } elsif ($arg eq '-F') { $verify = 0; } elsif ($arg eq '-c') { $dongle_type = shift; } elsif ($arg eq '-y') { $avrdude_ee_count = 1; } elsif ($arg eq '-s') { $programmer = shift; } elsif ($arg eq '-P') { $parport = shift; $serport = ''; } elsif ($arg eq '-p') { $cpu = shift; } elsif ($arg eq '-S') { $serport = shift; $parport = ''; } else { usage("no such option: $arg"); } } $cpu =~ s{^at}{}i; $cpu = lc $cpu; my $opcode = shift or usage("no command given."); my $cmd = ''; if ($opcode eq 'list') { print "Known CPUs are:\n\n"; print join ' ', keys %cpu; print "\n\n"; exit 0; } elsif ($opcode eq 'flashsize') { print "$cpu{$cpu}{flashsz}\n"; exit 0; } elsif ($opcode =~ m{^e\w+size}) { print "$cpu{$cpu}{eesz}\n"; exit 0; } elsif ($opcode eq 'ramsize') { print "$cpu{$cpu}{ramsz}\n"; exit 0; } if ($programmer =~ m{dude}i) { usage("please specify -p cpu for $programmer") if $cpu eq 'auto' && $opcode ne 'version'; $cmd = "avrdude -c $dongle_type -p AT$cpu -P $parport"; $cmd .= " -y" if $avrdude_ee_count; $cmd .= " -F" unless $verify; $cmd .= " -q" if $verbose < 2; $cmd .= " -q" if $verbose < 1; if ($opcode =~ m{^up\w+ee}) { my $filename = shift || 'main.hex'; $cmd .= qq{ -U "eeprom:w:$filename"}; } elsif ($opcode =~ m{^up}) { my $filename = shift || 'main.hex'; $cmd .= qq{ -U "flash:w:$filename"}; } elsif ($opcode =~ m{^down\w+ee}) { my $filename = shift || 'download.hex'; $cmd .= qq{ -U "eeprom:r:$filename:i"}; } elsif ($opcode =~ m{^down}) { my $filename = shift || 'download.hex'; $cmd .= qq{ -U "flash:r:$filename:i"}; } elsif ($opcode =~ m{^reset}) { $cmd .= qq{ -E noreset}; } elsif ($opcode =~ m{^erase}) { $cmd .= qq{ -e}; } elsif ($opcode =~ m{^version}) { $verbose = 0; print "$0 version $version\n"; $cmd = qq{avrdude -v 2>&1 | head -4}; } elsif ($opcode =~ m{^clock}) { my $f = clock_fuses($cpu, @ARGV); $cmd .= join '', map { sprintf " -U %sfuse:w:0x%02x:m", $_, $f->{$_} } keys %$f; } elsif ($opcode =~ m{^rd_?fuse}) { $cmd .= qq{ -q -U lfuse:r:-:r -U hfuse:r:-:r -U efuse:r:-:r 2>/dev/null | xxd -i}; } else { usage("command not implemented: $opcode"); } } elsif ($programmer =~ m{uisp}i) { $cmd = "uisp -dprog=$dongle_type"; $cmd .= " --hash=128" if $verbose && $opcode =~ m{^(up|down)}; $cmd .= " -dpart=at$cpu" if $cpu && $cpu ne 'auto'; $cmd .= " -v=0" if $verbose < 1; $cmd .= " -v=$verbose" if $verbose > 1; if ($opcode =~ m{^up\w+ee}) { my $filename = shift || 'main.hex'; $cmd .= qq{ --verify} if $verify; $cmd .= qq{ --segment=eeprom --erase --upload if=$filename}; } elsif ($opcode =~ m{^up}) { my $filename = shift || 'main.hex'; $cmd .= qq{ --verify} if $verify; $cmd .= qq{ --segment=flash --erase --upload if=$filename}; } elsif ($opcode =~ m{^down\w+ee}) { my $filename = shift || 'download.hex'; my $s = ''; $s = " --size=$cpu{$cpu}{eesz}" if $cpu{$cpu}{eesz} > 0; $cmd .= qq{ --segment=eeprom --download$s of=$filename}; } elsif ($opcode =~ m{^down}) { my $filename = shift || 'download.hex'; $cmd .= qq{ --segment=flash --download of=$filename}; } elsif ($opcode =~ m{^reset}) { $cmd .= qq{ }; } elsif ($opcode =~ m{^erase}) { $cmd .= qq{ --erase}; } elsif ($opcode =~ m{^version}) { $verbose = 0; print "$0 version $version\n\n"; $cmd = qq{uisp --version 2>&1 | head -3}; } elsif ($opcode =~ m{^clock}) { my $f = clock_fuses($cpu, @ARGV); $cmd .= join '', map { sprintf " --wr_fuse_%s=0x%02x", $_, $f->{$_} } keys %$f; } elsif ($opcode =~ m{^rd_?fuse}) { $cmd .= qq{ --rd_fuses}; } else { usage("command not implemented: $opcode"); } } else { usage("programmer $programmer is unknown"); } print "$cmd\n" if $verbose or $noop; exit 0 if $noop; system $cmd and die "command failed: $cmd: $! $@\n"; exit 0; ################################################################### sub usage { my ($msg) = @_; print qq{ avr-isp Version $version Usage: $0 [options] <command> args... Valid options are: -v Be more verbose. Default: $verbose -q Be quiet. Not verbose. -c pgm_dongle Specify hardware dongle type. Default: $dongle_type -s programmer Select 'avrdude' or 'uisp'. Default: $programmer -P parport Specify parallel-port with dongle. Default: $parport -S serport Specify serial-port with dongle. Default: $serport -n No operation. Print the suggested command line only. -F Disable verify. Default: verify=$verify -y Avrdude only: use last 4 bytes as flashcount. -p cpu Specify the CPU type. Use 'list' to get a list. Avrdude: mandatory; Uisp: default auto-detect. Valid commands are: upload file.hex Upload hex record file.hex to the device flash. upload_ee file.hex Upload hex record file.hex to the device eeprom. download file.hex Download device flash to hex record file.hex. download_ee file.hex Download device eeropm to hex record file.hex. list List known device CPUs. flashsize Print size of flash memory in bytes. Use with -p ramsize Print size of ram memory in bytes. Use with -p eesize Print size of eeprom memory in bytes. Use with -p erase Erase the device, flash and eeprom. reset Reset the device. version Print version numbers. clock NNmhz Program device fuses to run at NN Megahertz. clock NNmhz file.h As above, but also write F_CPU, CPU_MHZ to file.h. rdfuses Read the fuses from device. }; print "\nError: $msg\n" if $msg; exit 1; } sub clock_fuses { my ($cpu, $mhz, $file, @opt) = @_; $mhz =~ s{mhz$}{}i; $mhz *= 0.001 if $mhz =~ s{khz$}{}i; my $f = do_clock_fuses($cpu, $mhz); if (defined $file) { open my $fd, ">", $file or die "$0: open($file) failed: $!\n"; printf $fd qq{// autogenerated by $0 #ifndef CPU_MHZ # define CPU_MHZ %d # define CPU_MHZ_10 %d # define F_CPU %ldL #endif }, $mhz, 10*$mhz, 1000000*$mhz; close $fd or die "$0: write($file) failed: $!\n"; } } sub do_clock_fuses { my ($cpu, $mhz) = @_; if ($cpu =~ m{^mega8$}) { # factory default: l => 0xe1, h => 0xd9, e => 0xff print "using external crystal\n" if $verbose and $mhz =~ m{^(16)}; return { l => 0xff, h => 0xc1 } if $mhz == 16; return { l => 0xe4, h => 0xd1 } if $mhz == 8; return { l => 0xe3, h => 0xd1 } if $mhz == 4; return { l => 0xe2, h => 0xd1 } if $mhz == 2; return { l => 0xe1, h => 0xd1 } if $mhz == 1; usage("$cpu $mhz MHZ not impl. Try 16, 8, 4, 2, 1"); } elsif ($cpu =~ m{^mega(4|8|16)8$}) { # factory default: l => 0x62, h => 0xdf, e => 0xff, lock=0xff print "using external crystal\n" if $verbose and $mhz =~ m{^(20|16)}; return { l => 0xf7, h => 0xdf } if $mhz == 20; return { l => 0xe4, h => 0xdf } if $mhz == 16; return { l => 0xe2, h => 0xdf } if $mhz == 8; return { l => 0x62, h => 0xdf } if $mhz == 1; return { l => 0xe3, h => 0xdf } if $mhz == 0.128; usage("$cpu $mhz MHZ not impl. Try 20, 16, 8, 1, 128khz"); } elsif ($cpu =~ m{^tiny2313$}) { # factory default: l => 0x62, h => 0xdf print "using external crystal\n" if $verbose and $mhz =~ m{^(20|16|2.5)}; return { l => 0xef } if $mhz == 20; return { l => 0xe4 } if $mhz == 8; return { l => 0xe2 } if $mhz == 4; return { l => 0x6f } if $mhz == 2.5; return { l => 0x64 } if $mhz == 1; return { l => 0x62 } if $mhz == 0.5; return { l => 0xe6 } if $mhz == 0.128; return { l => 0x66 } if $mhz == 0.016; usage("$cpu $mhz MHZ not impl. Try 20, 8, 4, 2.5, 1, 500khz, 128khz, 16khz"); } elsif ($cpu =~ m{^tiny24$}) { # factory default: l => 0x62, h => 0xdf print "using external crystal\n" if $verbose and $mhz =~ m{^(20|16)}; return { l => 0xe2 } if $mhz == 8; return { l => 0x62 } if $mhz == 1; usage("$cpu $mhz MHZ not impl. Try 8, 1"); } elsif ($cpu =~ m{^auto}) { usage("clock_fuses: cpu autodetect not impl."); } usage("$cpu: clock setting not impl."); }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor