#!/bin/sh #-*-tcl-*- # de volgende regel start met wish8.4 \ exec wish8.4 "$0" -- ${1+"$@"} # ©2005 ir drs E.J Boks # Hogeschool van Arnhem en Nijmegen # The BSD License applies to this software # Please visit http://www.nl.freebsd.org/copyright/freebsd-license.html for more information # When copying or distributing this software, please retain this copyright message # Versie informatie # 30-05-2005 1.0 Initial Release # 06-06-2005 1.1 Bugfix # 11-01-2006 1.2 Adaptation to FreeBSD 6 (serial ports changed) and avrdude 5.0 # van tkcvs geleend if {! [info exists tk_version] } { puts "Initialization failed" exit 1 } if {$tk_version < 8.3} { tk_dialog .wrongversion "Tcl/Tk too old" \ "gccStudio requires Tcl/Tk 8.3 or higher!" \ error 0 {Bye Bye} exit 1 } # controleer de versie van avrdude proc identificeerAvrdude { } { catch {exec avrdude -v } uitvoer if { -1 == [string first "Version 5.0" $uitvoer] } { tk_dialog .wrongversion "avrdude too old" \ "gccStudio requires avrdude 5.0" \ error 0 {Bye Bye} exit 2 } catch {exec avarice -h } uitvoer if { -1 == [string first "version 2." $uitvoer] } { tk_dialog .wrongversion "avarice too old" \ "gccStudio requires avarice 2.0 or higher!" \ error 0 {Bye Bye} exit 2 } } # globale variabelen # host set allePoorten { /dev/cuad0 /dev/cuad1 /dev/cuad2 /dev/cuad3 /dev/cuad4 /dev/cuad5 /dev/cuad6 } set hostType {FreeBSD6} set HostVersieType {Release-6.0} # avrdude set progNaam "" set processorName {m_onbekend} set serPoort {cuad_onbekend} set programmerName {stk500v2} set targetMemType {flash} set showDebug 1 set debugKnopTekst "Hide avrdude output" set fileType i set flashErase 1 set hfuse 0 set lfuse 0 set efuse 0 catch { exec pwd } huidigeDir set eFuseTekst " " set hFuseTekst " " set lFuseTekst " " # avarice set avarDebugGereed 0 set avarSerPoort {cuad_onbekend} set avarBitRate {1MHz} set avarHostNaam {localhost} set avarPortNumber 4242 set avrdudeSyncAvarice 0 proc gccStudioInit { } { global HostType HostVersieType progNaam processorName serPoort programmerName showDebug debugKnopTekst global avarSerPoort avarBitRate avarHostNaam avarPortNumber set bestandNaam "~/.gccStudio" # check de host catch { exec uname } HostType switch $HostType { FreeBSD { # controleer de versie , in 6 andere serieele poortnamen dan in 5 en 4 ! catch { exec uname -r } HostTypeVersie if { -1 != [string first "6" $HostTypeVersie 0 ] } { # puts "6 release init" # avrdude .program.vraag.comdevice.cuad0 configure -value {/dev/cuad0} .program.vraag.comdevice.cuad1 configure -value {/dev/cuad1} .program.vraag.comdevice.cuad2 configure -value {/dev/cuad2} .program.vraag.comdevice.cuad3 configure -value {/dev/cuad3} .program.vraag.comdevice.cuad4 configure -value {/dev/cuad4} .program.vraag.comdevice.cuad5 configure -value {/dev/cuad5} .program.vraag.comdevice.cuad6 configure -value {/dev/cuad6} .program.vraag.comdevice.cuad7 configure -value {/dev/cuad7} # avarice .avar.comdevice.cuad0 configure -value {/dev/cuad0} .avar.comdevice.cuad1 configure -value {/dev/cuad1} .avar.comdevice.cuad2 configure -value {/dev/cuad2} .avar.comdevice.cuad3 configure -value {/dev/cuad3} .avar.comdevice.cuad4 configure -value {/dev/cuad4} .avar.comdevice.cuad5 configure -value {/dev/cuad5} .avar.comdevice.cuad6 configure -value {/dev/cuad6} .avar.comdevice.cuad7 configure -value {/dev/cuad7} set allePoorten { /dev/cuad0 /dev/cuad1 /dev/cuad2 /dev/cuad3 /dev/cuad4 /dev/cuad5 /dev/cuad6 } } else { # avrdude .program.vraag.comdevice.cuad0 configure -value {/dev/cuaa0} .program.vraag.comdevice.cuad1 configure -value {/dev/cuaa1} .program.vraag.comdevice.cuad2 configure -value {/dev/cuaa2} .program.vraag.comdevice.cuad3 configure -value {/dev/cuaa3} .program.vraag.comdevice.cuad4 configure -value {/dev/cuaa4} .program.vraag.comdevice.cuad5 configure -value {/dev/cuaa5} .program.vraag.comdevice.cuad6 configure -value {/dev/cuaa6} .program.vraag.comdevice.cuad7 configure -value {/dev/cuaa7} # avarice .avar.comdevice.cuad0 configure -value {/dev/cuaa0} .avar.comdevice.cuad1 configure -value {/dev/cuaa1} .avar.comdevice.cuad2 configure -value {/dev/cuaa2} .avar.comdevice.cuad3 configure -value {/dev/cuaa3} .avar.comdevice.cuad4 configure -value {/dev/cuaa4} .avar.comdevice.cuad5 configure -value {/dev/cuaa5} .avar.comdevice.cuad6 configure -value {/dev/cuaa6} .avar.comdevice.cuad7 configure -value {/dev/cuaa7} set allePoorten { /dev/cuaa0 /dev/cuaa1 /dev/cuaa2 /dev/cuaa3 /dev/cuaa4 /dev/cuaa5 /dev/cuaa6 } } } Linux { # avrdude .program.vraag.comdevice.cuad0 configure -value {/dev/ttyS0} .program.vraag.comdevice.cuad1 configure -value {/dev/ttyS1} .program.vraag.comdevice.cuad2 configure -value {/dev/ttyS2} .program.vraag.comdevice.cuad3 configure -value {/dev/ttyS3} .program.vraag.comdevice.cuad4 configure -value {/dev/ttyS4} .program.vraag.comdevice.cuad5 configure -value {/dev/ttyS5} .program.vraag.comdevice.cuad6 configure -value {/dev/ttyS6} .program.vraag.comdevice.cuad7 configure -value {/dev/ttyS7} # avarice .avar.comdevice.cuad0 configure -value {/dev/ttyS0} .avar.comdevice.cuad1 configure -value {/dev/ttyS1} .avar.comdevice.cuad2 configure -value {/dev/ttyS2} .avar.comdevice.cuad3 configure -value {/dev/ttyS3} .avar.comdevice.cuad4 configure -value {/dev/ttyS4} .avar.comdevice.cuad5 configure -value {/dev/ttyS5} .avar.comdevice.cuad6 configure -value {/dev/ttyS6} .avar.comdevice.cuad7 configure -value {/dev/ttyS7} # voor identificatie bij onbekende poort set allePoorten { /dev/ttyS0 /dev/ttyS1 /dev/ttyS2 /dev/ttyS3 /dev/ttyS4 /dev/ttyS5 /dev/ttyS6 /dev/ttyS7 } } Darwin { tk_messageBox -title "Mac OS X" -message "Mac OS X : Don't know what your serial ports are !" -icon error -type ok exit } NetBSD { tk_messageBox -title "NetBSD" -message "NetBSD : assuming your serial ports are the same as FreeBSD" -type ok } SunOS { # avrdude .program.vraag.comdevice.cuad0 configure -value {/dev/ttya} .program.vraag.comdevice.cuad1 configure -value {/dev/ttyb} .program.vraag.comdevice.cuad2 configure -value {/dev/ttyc} .program.vraag.comdevice.cuad3 configure -value {/dev/ttyd} .program.vraag.comdevice.cuad4 configure -value {/dev/ttye} .program.vraag.comdevice.cuad5 configure -value {/dev/ttyf} .program.vraag.comdevice.cuad6 configure -value {/dev/ttyg} .program.vraag.comdevice.cuad7 configure -value {/dev/ttyh} # avarice .avar.comdevice.cuad0 configure -value {/dev/ttya} .avar.comdevice.cuad1 configure -value {/dev/ttyb} .avar.comdevice.cuad2 configure -value {/dev/ttyc} .avar.comdevice.cuad3 configure -value {/dev/ttyd} .avar.comdevice.cuad4 configure -value {/dev/ttye} .avar.comdevice.cuad5 configure -value {/dev/ttyf} .avar.comdevice.cuad6 configure -value {/dev/ttyg} .avar.comdevice.cuad7 configure -value {/dev/ttyh} # voor identificatie bij onbekende poort set allePoorten { /dev/ttya /dev/ttyb /dev/ttyc /dev/ttyd /dev/ttye /dev/ttyf /dev/ttyg /dev/ttyh } } Solaris { # avrdude .program.vraag.comdevice.cuad0 configure -value {/dev/term/a} .program.vraag.comdevice.cuad1 configure -value {/dev/term/b} .program.vraag.comdevice.cuad2 configure -value {/dev/term/c} .program.vraag.comdevice.cuad3 configure -value {/dev/term/d} .program.vraag.comdevice.cuad4 configure -value {/dev/term/e} .program.vraag.comdevice.cuad5 configure -value {/dev/term/f} .program.vraag.comdevice.cuad6 configure -value {/dev/term/g} .program.vraag.comdevice.cuad7 configure -value {/dev/term/h} # avarice .avar.comdevice.cuad0 configure -value {/dev/term/a} .avar.comdevice.cuad1 configure -value {/dev/term/b} .avar.comdevice.cuad2 configure -value {/dev/term/c} .avar.comdevice.cuad3 configure -value {/dev/term/d} .avar.comdevice.cuad4 configure -value {/dev/term/e} .avar.comdevice.cuad5 configure -value {/dev/term/f} .avar.comdevice.cuad6 configure -value {/dev/term/g} .avar.comdevice.cuad7 configure -value {/dev/term/h} # voor identificatie bij onbekende poort set allePoorten { /dev/term/a /dev/term/b /dev/term/c /dev/term/d /dev/term/e /dev/term/f /dev/term/g /dev/term/h } } } # check de dude en avarice versies identificeerAvrdude if { 1 == [file exists $bestandNaam] } { set configBestand [open $bestandNaam r] # globale variabelen inlezen # avrdude gets $configBestand progNaam gets $configBestand processorName gets $configBestand serPoort gets $configBestand programmerName gets $configBestand debugKnopTekst gets $configBestand showDebug # avarice gets $configBestand avarSerPoort gets $configBestand avarBitRate gets $configBestand avarHostNaam gets $configBestand avarPortNumber close $configBestand } tekenTekstveld } proc gccStudioAfsluiten { } { global progNaam processorName serPoort programmerName showDebug debugKnopTekst global avarSerPoort avarBitRate avarHostNaam avarPortNumber set bestandNaam "~/.gccStudio" set configBestand [open $bestandNaam w] # globale variabelen inlezen # avrdude puts $configBestand $progNaam puts $configBestand $processorName puts $configBestand $serPoort puts $configBestand $programmerName puts $configBestand $debugKnopTekst puts $configBestand $showDebug # avarice puts $configBestand $avarSerPoort puts $configBestand $avarBitRate puts $configBestand $avarHostNaam puts $configBestand $avarPortNumber close $configBestand exit } proc sluitAfKnoppen { } { } proc sluitAanKnoppen { } { # zet de knoppen aan nu het target bekend is .progFuses.knoppen.lees configure -state normal .progFuses.knoppen.prog configure -state normal .program.program.schrijf configure -state normal .program.program.lees configure -state normal .program.program.erase configure -state normal } proc identificeerDoel { handTekening } { global processorName set procLijst { .atmega8 .atmega64 .atmega128 } # zet alle extra venstertjes uit foreach processor $procLijst { wm state $processor withdrawn } switch $handTekening { 0x1e9307 { set processorName m8 wm state .atmega8 normal } 0x1e9403 { set processorName m16 } 0x1e9502 { set processorName m32 } 0x1e9602 { set processorName m64 wm state .atmega64 normal } 0x1e9702 { set processorName m128 wm state .atmega128 normal } } } proc leesHandtekening { } { global serPoort programmerName processorName global memSchrijfStaat allePoorten set succes 0 .tekstveld.tekst delete 1.0 end if {$processorName == {m_onbekend} } { set processorName {m88} } if { $serPoort == {cuad_onbekend} } { foreach poort $allePoorten { catch {exec avrdude -P $poort -c $programmerName -p $processorName } uitvoer # catch {exec avrdude -P /dev/cuad0 -c stk500v2 -p $processorName } uitvoer .tekstveld.tekst insert end $uitvoer .tekstveld.tekst insert end "\n" if { -1 == [string first "AVR device initialized" $uitvoer] } { continue } else { set serPoort $poort set handTekening [lrange $uitvoer 19 19] identificeerDoel $handTekening set succes 1 break } } } else { catch {exec avrdude -P $serPoort -c $programmerName -p $processorName } uitvoer .tekstveld.tekst insert end $uitvoer .tekstveld.tekst insert end "\n" if { -1 != [string first "AVR device initialized" $uitvoer] } { set handTekening [lrange $uitvoer 19 19] identificeerDoel $handTekening set succes 1 } } if { $succes == 0 } { tk_messageBox -icon error -message "Target failed initialization.\nIs your board connected?" -type ok } else { sluitAanKnoppen } } proc leesZekeringen { } { global processorName programmerName serPoort ocd jtag spi eeprom bootSize brownOut klokSel hfuse lfuse efuse global atmega8_pc6reset atmega8_wd atmega64_mega103 atmega64_wd atmega128_mega103 atmega128_wd global eFuseTekst hFuseTekst lFuseTekst set lBestandNaam {/tmp/lfuse} set hBestandNaam {/tmp/hfuse} set eBestandNaam {/tmp/efuse} if {$processorName == {m_onbekend} } { leesHandtekening } if { $processorName == {m64} || $processorName == {m128} } { catch {exec avrdude -P $serPoort -c $programmerName -p $processorName -U lfuse:r:$lBestandNaam:r -U hfuse:r:$hBestandNaam:r -U efuse:r:$eBestandNaam:r } uitvoer catch {exec od -D $eBestandNaam } tempZekering set efuse [lrange $tempZekering 1 1] } else { catch {exec avrdude -P $serPoort -c $programmerName -p $processorName -U lfuse:r:$lBestandNaam:r -U hfuse:r:$hBestandNaam:r } uitvoer set efuse 0 } catch {exec od -D $lBestandNaam } tempZekering set lfuse [lrange $tempZekering 1 1] catch {exec od -D $hBestandNaam } tempZekering set hfuse [lrange $tempZekering 1 1] # formatteer de strings set eFuseTekst [format "The extended fuse byte is 0x%x" $efuse] set hFuseTekst [format "The high fuse byte is 0x%x" $hfuse] set lFuseTekst [format "The low fuse byte is 0x%x" $lfuse] .tekstveld.tekst delete 1.0 end .tekstveld.tekst insert end $uitvoer # eerst de signature lezen en target zetten set handTekening [lrange $uitvoer 19 19] identificeerDoel $handTekening if { $hfuse & 32 } { set spi 0 } else { set spi 1 } if { $hfuse & 8 } { set eeprom 0 } else { set eeprom 1 } # boot size fuses if { $hfuse & 4 && $hfuse&2 } { set bootSize 0 } elseif { $hfuse & 4 } { set bootSize 1 } elseif { $hfuse & 2 } { set bootSize 2 } else { set bootSize 3 } # brown out if { $lfuse & 64 } { set brownOut 0 } else { if { $lfuse & 128 } { set brownOut 1 } else { set brownOut 2 } } #klok opties # ext crystal resonator if { $lfuse & 9 } { set klokSel 1 } # Controleer ckopt if { $hfuse & 16 } { # ckopt staat uit # extern crystal resonator if { $lfuse & 8 && $lfuse &2 } { set klokSel 2 } elseif { $lfuse & 8 && $lfuse & 4 } { set klokSel 3 } elseif { $lfuse & 8 && $lfuse & 4 && $lfuse &2 } { set klokSel 4 # intern RC } elseif { $lfuse & 2 && $lfuse & 1 } { set klokSel 12 } elseif { $lfuse & 2 } { set klokSel 11 } elseif { $lfuse & 1 } { set klokSel 10 } elseif { $lfuse & 4 } { set klokSel 13 } # ckopt staat aan --> kloksel } else { # extern RC switch [expr $lfuse & 0xf] { 5 { set klokSel 6 } 6 { set klokSel 7 } 7 { set klokSel 8 } 8 { set klokSel 9 } 10 { set klokSel 5 } 11 { set klokSel 5 } 12 { set klokSel 5 } 13 { set klokSel 5 } 14 { set klokSel 5 } 15 { set klokSel 5 } } } # Hier de optionele, niet standaard dingen invullen voor spec processoren switch $processorName { m8 { if $hfuse & 128 } { set atmega8_pc6reset 0 } else { set atmega8_pc6reset 1 } if { $hfuse & 64 } { set atmega8_wd 0 } else { set atmega8_wd 1 } m16 { if { $hfuse & 128 } { set ocd 0 } else { set ocd 1 } if { $hfuse & 64 } { set jtag 0 } else { set jtag 1 } } m32 { if { $hfuse & 128 } { set ocd 0 } else { set ocd 1 } if { $hfuse & 64 } { set jtag 0 } else { set jtag 1 } } m64 { if { $hfuse & 128 } { set ocd 0 } else { set ocd 1 } if { $hfuse & 64 } { set jtag 0 } else { set jtag 1 } if { $efuse & 2 } { set atmega64_mega103 0 } else { set atmega64_mega103 1 } if { $efuse & 1 } { set atmega64_wd 0 } else { set atmega64_wd 1 } } m128 { if { $hfuse & 128 } { set ocd 0 } else { set ocd 1 } if { $hfuse & 64 } { set jtag 0 } else { set jtag 1 } if { $efuse & 2 } { set atmega128_mega103 0 } else { set atmega128_mega103 1 } if { $efuse & 1 } { set atmega128_wd 0 } else { set atmega128_wd 1 } } } } proc schrijfZekeringen { } { global processorName programmerName ocd jtag spi eeprom bootSize brownOut klokSel hfuse lfuse serPoort global atmega8_pc6reset atmega8_wd atmega64_mega103 atmega64_wd atmega128_mega103 atmega128_wd .tekstveld.tekst delete 1.0 end set lfuse 0 set hfuse 0 set efuse 252 if {$processorName == {m_onbekend} } { leesHandtekening } switch $processorName { m8 { #hfuse if {atmega8_pc6reset == 0} { set hfuse [expr $hfuse | 128 ] } if {atmega8_wd == 0} { set hfuse [expr $hfuse | 64 ] } } m16 { if {$ocd == 0} { set hfuse [expr $hfuse | 128 ] } if {$jtag == 0} { set hfuse [expr $hfuse | 64 ] } } m32 { if {$ocd == 0} { set hfuse [expr $hfuse | 128 ] } if {$jtag == 0} { set hfuse [expr $hfuse | 64 ] } } m64 { # efuse if {$atmega64_mega103 == 0} { set efuse [expr $efuse | 2 ] } if {$atmega64_wd == 0} { set efuse [expr $efuse | 1 ] } # schrijf de efuse meteen weg catch { exec avrdude -P $serPoort -c $programmerName -p $processorName -u -U efuse:w:$efuse:m } uitvoer .tekstveld.tekst insert end $uitvoer # hfuse if {$ocd == 0} { set hfuse [expr $hfuse | 128 ] } if {$jtag == 0} { set hfuse [expr $hfuse | 64 ] } } m128 { # efuse if {$atmega128_mega103 == 0} { set efuse [expr $efuse | 2 ] } if {$atmega128_wd == 0} { set efuse [expr $efuse | 1 ] } # schrijf de efuse meteen weg catch { exec avrdude -P $serPoort -c $programmerName -p $processorName -u -U efuse:w:$efuse:m } uitvoer # catch { exec avrdude -P $serPoort -c $programmerName -p $processorName -u -U lfuse:w:$lfuse:m -U hfuse:w:$hfuse:m } uitvoer .tekstveld.tekst insert end $uitvoer # hfuse if {$ocd == 0} { set hfuse [expr $hfuse | 128 ] } if {$jtag == 0} { set hfuse [expr $hfuse | 64 ] } } } # algemeen if {$spi == 0} { set hfuse [expr $hfuse | 32 ] } if {$eeprom == 0} { set hfuse [expr $hfuse | 8 ] } switch $bootSize { 0 { set hfuse [expr $hfuse | 6 ] } 1 { set hfuse [expr $hfuse | 4 ] } 2 { set hfuse [expr $hfuse | 2 ] } } # lfuse switch $brownOut { 0 { set lfuse [expr $lfuse | 192 ] } 1 { set lfuse [expr $lfuse | 128 ] } } switch $klokSel { 1 { # lf ext crystal < 0.4 set lfuse [expr $lfuse | 9] set hfuse [expr $hfuse | 16] } 2 { # hf ext crystal 0.4-0.9 set lfuse [expr $lfuse | 10] set hfuse [expr $hfuse | 16] } 3 { # hf ext crystal 0.9-3.0 set lfuse [expr $lfuse | 12] set hfuse [expr $hfuse | 16] } 4 { # hf ext crystal 3.0 -8.0 set lfuse [expr $lfuse | 14] set hfuse [expr $hfuse | 16] } 5 { # hf ext crystal 8.0 -16.0 set lfuse [expr $lfuse | 14 ] } # voor ext rc oscillator moet ckopt fuse gezet zijn vanwege extra condensatoren 6 { # ext rc oscillator 0.1-0.9 set lfuse [expr $lfuse | 5 ] } # ext rc oscillator 0.9-3.0 7 { set lfuse [expr $lfuse | 6 ] } # ext rc oscillator 3.0-8.0 8 { set lfuse [expr $lfuse | 7 ] } # ext rc oscillator 8.0-12.0 9 { set lfuse [expr $lfuse | 8 ] } # ckopt niet geprogrammeerd 10 { set lfuse [expr $lfuse | 1 ] set hfuse [expr $hfuse | 16] } # ckopt niet geprogrammeerd 11 { set lfuse [expr $lfuse | 2 ] set hfuse [expr $hfuse | 16] } # ckopt niet geprogrammeerd 12 { set lfuse [expr $lfuse | 3 ] set hfuse [expr $hfuse | 16] } # ckopt niet geprogrammeerd 13 { set lfuse [expr $lfuse | 4 ] set hfuse [expr $hfuse | 16] } } # toon de uitvoer in het venstertje catch { exec avrdude -P $serPoort -c $programmerName -p $processorName -u -U lfuse:w:$lfuse:m -U hfuse:w:$hfuse:m } uitvoer .tekstveld.tekst insert end $uitvoer } proc veegUitMem { } { global serPoort programmerName processorName .program.program.status configure -background yellow catch {exec avrdude -P $serPoort -c $programmerName -p $processorName -e } uitvoer .tekstveld.tekst delete 1.0 end .tekstveld.tekst insert end $uitvoer if { -1 == [string first "avrdude done. Thank you." $uitvoer ] } { .program.program.status configure -background red } else { .program.program.status configure -background green } } proc progMem { } { global progNaam flashErase serPoort programmerName processorName targetMemType fileType global avrdudeSyncAvarice if {$processorName == {m_onbekend} } { leesHandtekening } if [string match $progNaam ""] { tk_messageBox -message "No file name supplied" -type ok } else { .program.program.status configure -background yellow if { $flashErase == 0 } { catch {exec nice -n 0 avrdude -P $serPoort -c $programmerName -p $processorName -v -D -U $targetMemType:w:$progNaam:$fileType } uitvoer } else { catch {exec nice -n 0 avrdude -P $serPoort -c $programmerName -p $processorName -v -U $targetMemType:w:$progNaam:$fileType } uitvoer } .tekstveld.tekst delete 1.0 end .tekstveld.tekst insert end $uitvoer if { -1 == [string first "failed" $uitvoer ] } { .program.program.status configure -background green } else { .program.program.status configure -background red } } # Indien debugging gewenst na flash programmeren if { $avrdudeSyncAvarice == 1 && $targetMemType == {flash} } { startAvariceServerMode } } proc leesMem { } { global serPoort progNaam processorName programmerName targetMemType fileType if {$processorName == {m_onbekend} } { leesHandtekening } if [string match $progNaam ""] { tk_messageBox -message "No file name supplied" -type ok } else { .program.program.status configure -background yellow catch {exec touch $progNaam } uitvoer catch {exec nice -n 0 avrdude -P $serPoort -c $programmerName -p $processorName -U $targetMemType:r:$progNaam:$fileType } uitvoer .tekstveld.tekst delete 1.0 end .tekstveld.tekst insert end $uitvoer if { -1 == [string first "failed" $uitvoer ] } { .program.program.status configure -background green } else { .program.program.status configure -background red } } } proc zetBestand { } { global progNaam fileType switch $fileType { i { set types { {{Intel Hex} {.hex} } {{Motorola S Record} {.srec} } {{Raw Binary} {.bin} } {{All Files} * } } } s { set types { {{Motorola S Record} {.srec} } {{Intel Hex} {.hex} } {{Raw Binary} {.bin} } {{All Files} * } } } r { set types { {{Raw Binary} {.bin} } {{Motorola S Record} {.srec} } {{Intel Hex} {.hex} } {{All Files} * } } } } set progNaam [tk_getOpenFile -filetypes $types] cd [file dirname $progNaam] } proc tekenTekstveld {} { global showDebug # Tekst veld om de uitvoer van avrdude weer te geven toplevel .tekstveld -relief groove -bd 2 scrollbar .tekstveld.scroll -command ".tekstveld.tekst yview" text .tekstveld.tekst -relief groove -bd 2 -yscrollcommand ".tekstveld.scroll set " pack .tekstveld.tekst .tekstveld.scroll -side left -fill y -expand 1 wm title .tekstveld "AVR Dude output" if {$showDebug == 0} { wm state .tekstveld withdrawn } } proc debugshow {} { global showDebug debugKnopTekst if { 0 == [winfo exists .tekstveld] } { tekenTekstveld } if {$showDebug == 0} { set showDebug 1 wm state .tekstveld normal set debugKnopTekst "Hide avrdude output" } else { set showDebug 0 wm state .tekstveld withdrawn set debugKnopTekst "Show avrdude output" } } proc geefAuteur {} { set boodschap [format "gcc Studio - a Tk interface to avrdude\nversion 1.2\ \n\n\ ©2006 Ewout Boks\nHogeschool van Arnhem en Nijmegen, Netherlands\n\nemail:ewout.boks@han.nl\n\nThe BSD copyright applies to this software.\n" ] tk_messageBox -title "About gccStudio" -message $boodschap -type ok } ###### Globale grafische code en instellingen # Menu frame .mbar -relief raised -bd 2 # file menu menubutton .mbar.file -text File -underline 0 -menu .mbar.file.menu menu .mbar.file.menu .mbar.file.menu add command -label "About" -command geefAuteur .mbar.file.menu add command -label Exit -command exit # processor menu menubutton .mbar.proc -text Processor -underline 0 -menu .mbar.proc.menu menu .mbar.proc.menu .mbar.proc.menu add radiobutton -label ATMega8 -variable processorName -value m8 .mbar.proc.menu add radiobutton -label ATMega16 -variable processorName -value m16 .mbar.proc.menu add radiobutton -label ATMega32 -variable processorName -value m32 .mbar.proc.menu add radiobutton -label ATMega64 -variable processorName -value m64 .mbar.proc.menu add radiobutton -label ATMega128 -variable processorName -value m128 # programmer menu menubutton .mbar.prog -text Programmer -underline 0 -menu .mbar.prog.menu menu .mbar.prog.menu .mbar.prog.menu add radiobutton -label STK500 -variable programmerName -value stk500 .mbar.prog.menu add radiobutton -label STK500v2 -variable programmerName -value stk500v2 .mbar.prog.menu add radiobutton -label Parallel -variable programmerName -value par -state disabled .mbar.prog.menu add radiobutton -label AVR910 -variable programmerName -value avr910 # debugger menu menubutton .mbar.avarice -text "Avarice" -underline 0 -menu .mbar.avarice.menu menu .mbar.avarice.menu .mbar.avarice.menu add command -label "Avarice interface" -command [list wm state .avar normal] pack .mbar.file .mbar.proc .mbar.prog .mbar.avarice -side left frame .kopTekst -relief groove -bd 2 button .kopTekst.ontdek -text "Identify target" -command leesHandtekening frame .kopTekst.processor -relief raised -bd 2 radiobutton .kopTekst.processor.m8 -text "Atmega8" -variable processorName -value m8 radiobutton .kopTekst.processor.m16 -text "Atmega16" -variable processorName -value m16 radiobutton .kopTekst.processor.m32 -text "Atmega32" -variable processorName -value m32 radiobutton .kopTekst.processor.m64 -text "Atmega64" -variable processorName -value m64 radiobutton .kopTekst.processor.m128 -text "Atmega128" -variable processorName -value m128 pack .kopTekst.processor.m8 .kopTekst.processor.m16 .kopTekst.processor.m32 .kopTekst.processor.m64 .kopTekst.processor.m128 -side left -fill y pack .kopTekst.ontdek .kopTekst.processor -side left -fill both -expand 1 # chip, boot en reset samen frame .chipboot -relief groove -bd 2 # chip opties frame .chipboot.fuse -relief raised -bd 2 checkbutton .chipboot.fuse.ocd -text "OCD debugging" -variable ocd -anchor w checkbutton .chipboot.fuse.jtag -text "JTAG interface " -variable jtag -anchor w checkbutton .chipboot.fuse.spi -text "SPI flash programming" -variable spi -anchor w checkbutton .chipboot.fuse.eeprom -text "Save Eeprom through erase" -variable eeprom -anchor w pack .chipboot.fuse.ocd .chipboot.fuse.jtag .chipboot.fuse.spi .chipboot.fuse.eeprom -side top -fill x # Boot opties frame .chipboot.boot -relief raised -bd 2 radiobutton .chipboot.boot.boot256 -text "Boot size small " -variable bootSize -value 0 -anchor w radiobutton .chipboot.boot.boot512 -text "Boot size medium " -variable bootSize -value 1 -anchor w radiobutton .chipboot.boot.boot1024 -text "Boot size large " -variable bootSize -value 2 -anchor w radiobutton .chipboot.boot.boot2048 -text "Boot size extra large " -variable bootSize -value 3 -anchor w pack .chipboot.boot.boot256 .chipboot.boot.boot512 .chipboot.boot.boot1024 .chipboot.boot.boot2048 -side top -fill x # Brown out detector frame .chipboot.brown -relief raised -bd 2 radiobutton .chipboot.brown.disabled -text "Brown out disabled" -variable brownOut -value 0 -anchor w radiobutton .chipboot.brown.enabled_27 -text "Brown out at 2.7 V" -variable brownOut -value 1 -anchor w radiobutton .chipboot.brown.enabled_4 -text "Brown out at 4.0 V" -variable brownOut -value 2 -anchor w pack .chipboot.brown.disabled .chipboot.brown.enabled_27 .chipboot.brown.enabled_4 -side top -fill both -expand 1 pack .chipboot.fuse .chipboot.boot .chipboot.brown -side left -fill both -expand 1 #-padx 2m # Klok opties frame .klok -relief groove -bd 2 frame .klok.osc -relief raised -bd 2 radiobutton .klok.osc.extern -text "External clock" -variable klokSel -value 0 -anchor w radiobutton .klok.osc.lfcryst -text "External low frequency (< 0.4 MHz) crystal oscillator" -variable klokSel -value 1 -anchor w radiobutton .klok.osc.hf1cryst -text "External high frequency (0.4 - 0.9 MHz) crystal oscillator" -variable klokSel -value 2 -anchor w radiobutton .klok.osc.hf2cryst -text "External high frequency (0.9 - 3.0 MHz) crystal oscillator" -variable klokSel -value 3 -anchor w radiobutton .klok.osc.hf3cryst -text "External high frequency (3.0 - 8 MHz) crystal oscillator" -variable klokSel -value 4 -anchor w radiobutton .klok.osc.hf4cryst -text "External high frequency (8 - 16 MHz) crystal oscillator" -variable klokSel -value 5 -anchor w pack .klok.osc.extern .klok.osc.lfcryst .klok.osc.hf1cryst .klok.osc.hf2cryst .klok.osc.hf3cryst .klok.osc.hf4cryst -side top -fill x frame .klok.rc -relief raised -bd 2 radiobutton .klok.rc.rc1 -text "External RC Oscillator at 0.1-0.9 MHz" -variable klokSel -value 6 -anchor w radiobutton .klok.rc.rc2 -text "External RC Oscillator at 0.9-3.0 MHz" -variable klokSel -value 7 -anchor w radiobutton .klok.rc.rc3 -text "External RC Oscillator at 3.0-8.0 MHz" -variable klokSel -value 8 -anchor w radiobutton .klok.rc.rc4 -text "External RC Oscillator at 8.0-12.0 MHz" -variable klokSel -value 9 -anchor w radiobutton .klok.rc.rc5 -text "Internal RC Oscillator at 1 MHz" -variable klokSel -value 10 -anchor w radiobutton .klok.rc.rc6 -text "Internal RC Oscillator at 2 MHz" -variable klokSel -value 11 -anchor w radiobutton .klok.rc.rc7 -text "Internal RC Oscillator at 4 MHz" -variable klokSel -value 12 -anchor w radiobutton .klok.rc.rc8 -text "Internal RC Oscillator at 8 MHz" -variable klokSel -value 13 -anchor w pack .klok.rc.rc1 .klok.rc.rc2 .klok.rc.rc3 .klok.rc.rc4 .klok.rc.rc5 .klok.rc.rc6 .klok.rc.rc7 .klok.rc.rc8 -side top -fill x pack .klok.osc .klok.rc -side left -expand 1 -fill both # Programmeer en lees de fuses frame .progFuses -relief groove -bd 2 frame .progFuses.knoppen -relief raised -bd 2 button .progFuses.knoppen.lees -text "Read fuses" -command leesZekeringen -state disabled button .progFuses.knoppen.prog -text "Program fuses" -command schrijfZekeringen -state disabled pack .progFuses.knoppen.lees .progFuses.knoppen.prog -side top -expand 1 -fill both frame .progFuses.fuses -relief raised -bd 2 label .progFuses.fuses.efuse -textvariable eFuseTekst label .progFuses.fuses.hfuse -textvariable hFuseTekst label .progFuses.fuses.lfuse -textvariable lFuseTekst pack .progFuses.fuses.efuse .progFuses.fuses.hfuse .progFuses.fuses.lfuse -side top -fill y -anchor w pack .progFuses.knoppen .progFuses.fuses -side left -expand 1 -fill x # laad programma frame .program -relief groove -bd 2 frame .program.program -relief raised -bd 2 button .program.program.schrijf -text "Write memory" -command progMem -state disabled button .program.program.lees -text "Read memory" -command leesMem -state disabled button .program.program.erase -text "Erase memory" -command veegUitMem -state disabled button .program.program.status -text "Transfer Status" -command [list .program.program.status configure -background DarkKhaki] -bg DarkKhaki -activebackground DarkKhaki pack .program.program.schrijf .program.program.lees .program.program.erase .program.program.status -side top -fill both -expand 1 # file laad en opslaan sectie frame .program.vraag # naam en verander mogelijkheid frame .program.vraag.naam -relief raised -bd 2 label .program.vraag.naam.tekst -text "File Name: " entry .program.vraag.naam.vraag -width 40 -relief sunken -bd 2 -textvariable progNaam button .program.vraag.naam.verander -text "Change file" -command zetBestand pack .program.vraag.naam.tekst .program.vraag.naam.vraag .program.vraag.naam.verander -side left -fill both -expand 1 # com device waar naar toe moet worden gestuurd frame .program.vraag.comdevice -relief raised -bd 2 label .program.vraag.comdevice.tekst -text "Programming port" radiobutton .program.vraag.comdevice.auto -text "auto" -variable serPoort -value {cuad_onbekend} radiobutton .program.vraag.comdevice.cuad0 -text "ser 0" -variable serPoort -value {/dev/cuad0} radiobutton .program.vraag.comdevice.cuad1 -text "ser 1" -variable serPoort -value {/dev/cuad1} radiobutton .program.vraag.comdevice.cuad2 -text "ser 2" -variable serPoort -value {/dev/cuad2} radiobutton .program.vraag.comdevice.cuad3 -text "ser 3" -variable serPoort -value {/dev/cuad3} radiobutton .program.vraag.comdevice.cuad4 -text "ser 4" -variable serPoort -value {/dev/cuad4} radiobutton .program.vraag.comdevice.cuad5 -text "ser 5" -variable serPoort -value {/dev/cuad5} radiobutton .program.vraag.comdevice.cuad6 -text "ser 6" -variable serPoort -value {/dev/cuad6} radiobutton .program.vraag.comdevice.cuad7 -text "ser 7" -variable serPoort -value {/dev/cuad7} pack .program.vraag.comdevice.tekst .program.vraag.comdevice.auto .program.vraag.comdevice.cuad0 .program.vraag.comdevice.cuad1 .program.vraag.comdevice.cuad2\ .program.vraag.comdevice.cuad3 .program.vraag.comdevice.cuad4 .program.vraag.comdevice.cuad5 .program.vraag.comdevice.cuad6 \ .program.vraag.comdevice.cuad7 -side left -fill y # file type frame .program.vraag.type -relief raised -bd 2 label .program.vraag.type.tekst -text "File format :" radiobutton .program.vraag.type.ihex -text "Intel Hex" -variable fileType -value i radiobutton .program.vraag.type.srec -text "Motorola S Record" -variable fileType -value s radiobutton .program.vraag.type.rawBin -text "Raw binary" -variable fileType -value r pack .program.vraag.type.tekst .program.vraag.type.ihex .program.vraag.type.srec .program.vraag.type.rawBin -side left -fill y # target type frame .program.vraag.geheugentype -relief raised -bd 2 label .program.vraag.geheugentype.tekst -text "Target memory :" radiobutton .program.vraag.geheugentype.flash -text "Flash" -variable targetMemType -value flash radiobutton .program.vraag.geheugentype.eeprom -text "EEPROM" -variable targetMemType -value eeprom pack .program.vraag.geheugentype.tekst .program.vraag.geheugentype.flash .program.vraag.geheugentype.eeprom -side left -fill y frame .program.vraag.progOpties -relief raised -bd 2 checkbutton .program.vraag.progOpties.chiperase -text "Erase flash before programming" -variable flashErase checkbutton .program.vraag.progOpties.synchro -text "Start JTAG connection after Flash programming" -variable avrdudeSyncAvarice -state disabled pack .program.vraag.progOpties.chiperase .program.vraag.progOpties.synchro -side left -fill y # pack de vraag sektie pack .program.vraag.naam .program.vraag.type .program.vraag.geheugentype .program.vraag.progOpties .program.vraag.comdevice -side top -fill both -expand 1 # pack de gehele bestand sektie pack .program.program .program.vraag -side left -fill both -expand 1 # exit en debug info frame frame .debugeinde -relief groove -bd 2 button .debugeinde.einde -text "Exit" -command gccStudioAfsluiten button .debugeinde.avarice -text "Avarice" -command [list wm state .avar normal] button .debugeinde.debug -textvariable debugKnopTekst -command debugshow pack .debugeinde.einde .debugeinde.avarice .debugeinde.debug -side left -fill x -expand 1 # Het gehele venster pack .mbar .kopTekst .chipboot .klok .progFuses .program .debugeinde -side top -fill x -padx 2m -pady 2m # extra venstertjes voor avrdude uitvoer en de afwijkende AVRs toplevel .atmega8 checkbutton .atmega8.reset -text "PC6 is Reset pin" -variable atmega8_pc6reset -anchor w checkbutton .atmega8.wd -text "Watchdog always on" -variable atmega8_wd -anchor w pack .atmega8.reset .atmega8.wd -side top -fill x wm title .atmega8 "ATMega8 extra options" wm state .atmega8 withdrawn toplevel .atmega64 checkbutton .atmega64.reset -text "ATMega103 compatibility on" -variable atmega64_mega103 -anchor w checkbutton .atmega64.wd -text "Watchdog always on" -variable atmega64_wd -anchor w pack .atmega64.reset .atmega64.wd -side top -fill x -expand 1 wm title .atmega64 "ATMega64 extra options" wm state .atmega64 withdrawn toplevel .atmega128 checkbutton .atmega128.reset -text "ATMega103 compatibility on" -variable atmega128_mega103 -anchor w checkbutton .atmega128.wd -text "Watchdog always on" -variable atmega128_wd -anchor w pack .atmega128.reset .atmega128.wd -side top -fill x -expand 1 wm title .atmega128 "ATMega128 extra options" wm state .atmega128 withdrawn ##################### Avarice interface ########################## proc setAvariceServerMode {} { global avarDebugGereed avarSerPoort serPoort processorName if { $avarSerPoort == $serPoort } { tk_messageBox -title "Doubly used serial port" -message "Avarice cannot share a serial port with Avrdude!" -type ok -icon error } elseif { $avarSerPoort == {cuad_onbekend} } { tk_messageBox -title "Select a serial port" -message "Avarice needs a valid serial port" -type ok -icon error } elseif { $processorName == {m_onbekend} || $processorName == {m8} } { tk_messageBox -title "Wrong processor" -message "Avarice needs a JTAG equipped AVR processor type.\nPlease use option \"Identify target\"" -type ok -icon error } else { # debug gereed set avarDebugGereed 1 # Zet de debug knop aan - dat kan nu .avar.controle.start configure -state normal # Zet de sunchro knop aan - dat kan nu .avar.controle.synchro configure -state normal .program.vraag.progOpties.synchro configure -state normal } } proc startAvariceServerMode {} { global processorName avarDebugGereed avarSerPoort avarBitRate avarHostNaam avarPortNumber if { $avarDebugGereed == 0 } { setAvariceServerMode } .tekstveld.tekst delete 1.0 end set avarProcessorName {m_onbekend} switch $processorName { m16 { set avarProcessorName atmega16 } m32 { set avarProcessorName atmega32 } m64 { set avarProcessorName atmega64 } m128 { set avarProcessorName atmega128 } } if { $avarProcessorName == {m_onbekend} } { tk_messageBox -title "Wrong processor" -message "Avarice needs a valid AVR processor type.\nPlease use option \"Identify target\"" -type ok -icon error } elseif { $avarDebugGereed == 1 } { catch { exec avarice -j $avarSerPoort -B $avarBitRate -P $avarProcessorName $avarHostNaam:$avarPortNumber } uitvoer .tekstveld.tekst insert end $uitvoer .tekstveld.tekst insert end "\n" } } toplevel .avar # serieele poort # com device waar naar toe moet worden gestuurd frame .avar.comdevice -relief raised -bd 2 label .avar.comdevice.tekst -text "JTAG port" radiobutton .avar.comdevice.cuad0 -text "ser 0" -variable avarSerPoort -value {/dev/cuad0} radiobutton .avar.comdevice.cuad1 -text "ser 1" -variable avarSerPoort -value {/dev/cuad1} radiobutton .avar.comdevice.cuad2 -text "ser 2" -variable avarSerPoort -value {/dev/cuad2} radiobutton .avar.comdevice.cuad3 -text "ser 3" -variable avarSerPoort -value {/dev/cuad3} radiobutton .avar.comdevice.cuad4 -text "ser 4" -variable avarSerPoort -value {/dev/cuad4} radiobutton .avar.comdevice.cuad5 -text "ser 5" -variable avarSerPoort -value {/dev/cuad5} radiobutton .avar.comdevice.cuad6 -text "ser 6" -variable avarSerPoort -value {/dev/cuad6} radiobutton .avar.comdevice.cuad7 -text "ser 7" -variable avarSerPoort -value {/dev/cuad7} pack .avar.comdevice.tekst .avar.comdevice.cuad0 .avar.comdevice.cuad1 .avar.comdevice.cuad2\ .avar.comdevice.cuad3 .avar.comdevice.cuad4 .avar.comdevice.cuad5 .avar.comdevice.cuad6 \ .avar.comdevice.cuad7 -side left -fill y # JTAG snelheid frame .avar.snelheid -relief raised -bd 2 label .avar.snelheid.tekst -text "JTAG bitrate" radiobutton .avar.snelheid.langzaam -text "125 KHz" -variable avarBitRate -value {125KHz} radiobutton .avar.snelheid.gemiddeld -text "250 KHz" -variable avarBitRate -value {250KHz} radiobutton .avar.snelheid.snel -text "500 KHz" -variable avarBitRate -value {500KHz} radiobutton .avar.snelheid.snelst -text "1 MHz" -variable avarBitRate -value {1MHz} pack .avar.snelheid.tekst .avar.snelheid.langzaam .avar.snelheid.gemiddeld .avar.snelheid.snel\ .avar.snelheid.snelst -side left -fill y # Debug mode control frame .avar.debug -relief raised -bd 2 frame .avar.debug.host label .avar.debug.host.tekst -text "Host Name: " entry .avar.debug.host.vraag -width 20 -relief sunken -bd 2 -textvariable avarHostNaam pack .avar.debug.host.tekst .avar.debug.host.vraag -side left -fill y frame .avar.debug.poort label .avar.debug.poort.tekst -text "Port: " entry .avar.debug.poort.vraag -width 4 -relief sunken -bd 2 -textvariable avarPortNumber pack .avar.debug.poort.tekst .avar.debug.poort.vraag -side left -fill y pack .avar.debug.host .avar.debug.poort -side left -fill y # Debug Controle frame .avar.controle -relief raised -bd 2 button .avar.controle.pastoe -text "Apply" -command setAvariceServerMode button .avar.controle.start -text "Start JTAG debug session" -command startAvariceServerMode -state disabled button .avar.controle.ok -text "OK" -command [list wm state .avar withdrawn] checkbutton .avar.controle.synchro -text "Start JTAG connection after Flash programming" -variable avrdudeSyncAvarice -state disabled pack .avar.controle.pastoe .avar.controle.start .avar.controle.ok .avar.controle.synchro -side left -fill both -expand 1 # pak alles van avarice tezamen pack .avar.comdevice .avar.snelheid .avar.debug .avar.controle -side top -fill x -padx 2m -pady 1m wm title .avar "Avarice JTAG interface" wm state .avar withdrawn # start de zaak op gccStudioInit