Bootloader per atmega32

Sezione dedicata al sistema di sviluppo BASCOM-AVR per i micro AVR
At90s, Attiny, Atmega e Xmega

Bootloader per atmega32

Postby filosofo » 24 Jan 2012, 20:48

salve a tutti,
avrei bisogno di un bootloader per atmega32 in modo da programmare il chip senza l'ausilio del programmatore esterno,
bensì attraverso la seriale uart con un baud rate di 115200.
cè qualcosa in tal senso?, cè qualcuno che mi può aiutare?


grazie tante
filosofo
 
Posts: 74
Joined: 23 Oct 2011, 09:52
Location: Dintorni di Roma

Re: Bootloader per atmega32

Postby filosofo » 19 Feb 2012, 20:20

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
filosofo
 
Posts: 74
Joined: 23 Oct 2011, 09:52
Location: Dintorni di Roma

Re: Bootloader per atmega32

Postby flz47655 » 19 Feb 2012, 20:30

Purtroppo non ho esperienza a riguardo
flz47655
 
Posts: 639
Joined: 19 Jan 2012, 21:16

Re: Bootloader per atmega32

Postby deluca » 21 Feb 2012, 14:28

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
Ciao
Il mio sito: http://www.delucagiovanni.com ......e la chat: chat/
User avatar
deluca
Site Admin
 
Posts: 1104
Joined: 19 Jun 2011, 10:44
Location: 95123 - Catania (Italy)

Re: Bootloader per atmega32

Postby filosofo » 06 Mar 2012, 21:19

Grazie per avermi risposto,
ho provato il tuo listato ed è tutto ok.
sbagliavo sul fatto che utilizzavo un xtal diverso da quello indicato sul file boot.bas e quindi
specificando il baud rate di 115200 la comunicazione non andava.

Cqm grazie molte per l'aiuto
a presto
filosofo
 
Posts: 74
Joined: 23 Oct 2011, 09:52
Location: Dintorni di Roma


Return to BASCOM-AVR

Who is online

Users browsing this forum: No registered users and 8 guests

cron