filosofo wrote:Avevo chiesto un aiutino a proposito del bootloader per atmega32.
Ho trovato il sample relativo al boot per mega32 ma non riesco ad utilizzarlo!
Non so se è il .bas o il programma per scaricare il bin sul chip
qualcuno che mi può aiutare?
grazie
Scusa il ritardo con cui ti sto rispondendo... ma sono stato molto occupato in questo periodo.
Intanto ti allego il sorgente del firmware per il boot loader da utilizzare esclusivamente con il micro
ATmega32 con xtal da 14745600
e baudrate da 115200
- Code: Select all
'*******************************************************************************
' (c) 1995-2009, MCS
' Bootloader per ATMEGA32
' Versione Bascom: 2.7.0.4
' Modificato da : Giovanni De Luca
'*******************************************************************************
$crystal = 14745600
$baud = 115200
$regfile = "m32def.dat"
Const Loaderchip = 32
$loader = $3c00
Const Maxwordbit = 6 '
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Const Maxword =(2 ^ Maxwordbit) * 2
Const Maxwordshift = Maxwordbit + 1
Const Cdebug = 0
'Dim the used variables
Dim Bstatus As Byte , Bretries As Byte , Bblock As Byte , Bblocklocal As Byte
Dim Bcsum1 As Byte , Bcsum2 As Byte , Buf(128) As Byte , Csum As Byte
Dim J As Byte , Spmcrval As Byte
Dim Z As Long
Dim Vl As Byte , Vh As Byte
Dim Wrd As Word , Page As Word
Dim Bkind As Byte , Bstarted As Byte
Disable Interrupts
Const Nak = &H15
Const Ack = &H06
Const Can = &H18
Config Pinb.2 = Output
Portb.2 = 1
Config Pinb.3 = Output
Portb.3 = 1
$timeout = 200000
Bretries = 5
Testfor123:
Bstatus = Waitkey()
Print Chr(bstatus);
If Bstatus = 123 Then
Bkind = 0
Goto Loader
Elseif Bstatus = 124 Then
Bkind = 1
Goto Loader
Elseif Bstatus <> 0 Then
Decr Bretries
If Bretries <> 0 Then Goto Testfor123
End If
For J = 1 To 10
Toggle Portb.2 : Waitms 100
Next
Goto _reset
Loader:
Do
Bstatus = Waitkey()
Loop Until Bstatus = 0
For J = 1 To 3
Toggle Portb.2 : Waitms 50
Next
If Bkind = 0 Then
Spmcrval = 3 : Gosub Do_spm
Spmcrval = 17 : Gosub Do_spm
End If
Bretries = 10
Do
Bstarted = 0
Csum = 0
Print Chr(nak);
Do
Bstatus = Waitkey()
Select Case Bstatus
Case 1:
Incr Bblocklocal
Csum = 1
Bblock = Waitkey() : Csum = Csum + Bblock
Bcsum1 = Waitkey() : Csum = Csum + Bcsum1
For J = 1 To 128
Buf(j) = Waitkey() : Csum = Csum + Buf(j)
Next
Bcsum2 = Waitkey()
If Bblocklocal = Bblock Then
If Bcsum2 = Csum Then
Gosub Writepage
Print Chr(ack);
Else
Print Chr(nak);
End If
Else
Print Chr(nak);
End If
Case 4:
If Wrd > 0 And Bkind = 0 Then
Wrd = 0
Spmcrval = 5 : Gosub Do_spm
Spmcrval = 17 : Gosub Do_spm
End If
' Waitms 100
Print Chr(ack);
Portb.3 = 0
Waitms 20
Goto _reset
Case &H18:
Goto _reset
Case 123 : Exit Do
Case 124 : Exit Do
Case Else
Exit Do
End Select
Loop
If Bretries > 0 Then
Waitms 1000
Decr Bretries
Else
Goto _reset
End If
Loop
'write one or more pages
Writepage:
If Bkind = 0 Then
For J = 1 To 128 Step 2
Vl = Buf(j) : Vh = Buf(j + 1)
lds r0, {vl}
lds r1, {vh}
Spmcrval = 1 : Gosub Do_spm
Wrd = Wrd + 2
If Wrd = Maxword Then
Wrd = 0
Spmcrval = 5 : Gosub Do_spm
Spmcrval = 17 : Gosub Do_spm
Page = Page + 1
Spmcrval = 3 : Gosub Do_spm
Spmcrval = 17 : Gosub Do_spm
End If
Next
Else
For J = 1 To 128
Writeeeprom Buf(j) , Wrd
Wrd = Wrd + 1
Next
End If
Toggle Portb.2 : Waitms 10 : Toggle Portb.2
Return
Do_spm:
Bitwait Spmcsr.0 , Reset
Bitwait Eecr.1 , Reset
Z = Page
Shift Z , Left , Maxwordshift
Z = Z + Wrd
lds r30,{Z}
lds r31,{Z+1}
#if _romsize > 65536
lds r24,{Z+2}
sts rampz,r24
#endif
Spmcsr = Spmcrval
spm
nop
nop
Return
Questo è il codice da compilare con la versione 2.0.7.4 di BascomAVR ....
Prova a programmare il chip con il file bin generato con questo codice.... se tutto OK andiamo a avanti