- LiFePO4 Speicher Test         
Ergebnis 1 bis 10 von 25

Thema: UART-Bootloader in Bascom AVR

Hybrid-Darstellung

Vorheriger Beitrag Vorheriger Beitrag   Nächster Beitrag Nächster Beitrag
  1. #1
    Erfahrener Benutzer Begeisterter Techniker
    Registriert seit
    25.03.2006
    Ort
    Hinsdorf
    Alter
    50
    Beiträge
    381
    Hi,
    hast Du die Vollversion von Bascom? Ohne die geht das leider nicht.

    Code:
    '----------------------------------------------------------------
    '                          (c) 1995-2007, MCS
    '                        Bootloader.bas
    '  This sample demonstrates how you can write your own bootloader
    '  in Bascom BASIC
    '  VERSION 2 of the BOOTLOADER. The waiting for the NAK is stretched
    '  further a bug was resolved for the M64/M128 that have a big page size
    '-----------------------------------------------------------------
    'This sample will be extended to support other chips with bootloader
    'The loader is supported from the IDE
    
    $crystal = 8000000
    $crystal = 8000000
    '$crystal = 14745600
    $baud = 9600                                                                                                                                         'this loader uses serial com
    'It is VERY IMPORTANT that the baud rate matches the one of the boot loader
    'do not try to use buffered com as we can not use interrupts
    
    
    $regfile = "m8def.dat"
    $loader = $c00                                                                                                                                        ' 1024 words
    Const Maxwordbit = 5                                                                                                                                  'Z6 is maximum bit                                   '
    Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
    
    Const Maxword =(2 ^ Maxwordbit) * 2                                                                                                                   '128
    Const Maxwordshift = Maxwordbit + 1
    Const Cdebug = 0                                                                                                                                      ' leave this to 0
    
    #if Cdebug
       Print Maxword
       Print Maxwordshift
    #endif
    
    
    
    '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                                                                                                                      ' self program command byte value
    
    Dim Z As Long                                                                                                                                         'this is the Z pointer word
    Dim Vl As Byte , Vh As Byte                                                                                                                           ' these bytes are used for the data values
    Dim Wrd As Word , Page As Word                                                                                                                        'these vars contain the page and word address
    Dim Bkind As Byte , Bstarted As Byte
    
    Disable Interrupts                                                                                                                                    'we do not use ints
    
    
    'Waitms 100                                                  'wait 100 msec sec
    'We start with receiving a file. The PC must send this binary file
    
    'some constants used in serial com
    Const Nak = &H15
    Const Ack = &H06
    Const Can = &H18
    
    '(we use some leds as indication in this sample , you might want to remove it
    Config Pina.7 = Output
    Porta.7 = 1                                                                                                                                           'the stk200 has inverted logic for the leds
    Config Pina.6 = Output
    Porta.6 = 1
    ')
    
    $timeout = 400000                                                                                                                                     'we use a timeout
    'When you get LOADER errors during the upload, increase the timeout value
    'for example at 16 Mhz, use 200000
    
    Bretries = 5                                                                                                                                          'we try 5 times
    Testfor123:
    #if Cdebug
        Print "Try " ; Bretries
        Print "Wait"
    #endif
    Bstatus = Waitkey()                                                                                                                                   'wait for the loader to send a byte
    #if Cdebug
       Print "Got "
    #endif
    
    Print Chr(bstatus);
    
    If Bstatus = 123 Then                                                                                                                                 'did we received value 123 ?
       Bkind = 0                                                                                                                                          'normal flash loader
       Goto Loader
    Elseif Bstatus = 124 Then                                                                                                                             ' EEPROM
       Bkind = 1                                                                                                                                          ' EEPROM loader
       Goto Loader
    Elseif Bstatus <> 0 Then
       Decr Bretries
       If Bretries <> 0 Then Goto Testfor123                                                                                                              'we test again
    End If
    
    
    
    #if Cdebug
      Print "RESET"
    #endif
    Goto _reset                                                                                                                                           'goto the normal reset vector at address 0
    
    
    'this is the loader routine. It is a Xmodem-checksum reception routine
    Loader:
      #if Cdebug
          Print "Clear buffer"
      #endif
      Do
         Bstatus = Waitkey()
      Loop Until Bstatus = 0
      If Bkind = 0 Then
         Spmcrval = 3 : Gosub Do_spm                                                                                                                      ' erase  the first page
         Spmcrval = 17 : Gosub Do_spm                                                                                                                     ' re-enable page
      End If
    
    Bretries = 10                                                                                                                                         'number of retries
    
    Do
      Bstarted = 0                                                                                                                                        ' we were not started yet
      Csum = 0                                                                                                                                            'checksum is 0 when we start
      Print Chr(nak);                                                                                                                                     ' firt time send a nack
      Do
    
        Bstatus = Waitkey()                                                                                                                               'wait for statuse byte
    
        Select Case Bstatus
           Case 1:                                                                                                                                        ' start of heading, PC is ready to send
                Incr Bblocklocal                                                                                                                          'increase local block count
                Csum = 1                                                                                                                                  'checksum is 1
                Bblock = Waitkey() : Csum = Csum + Bblock                                                                                                 'get block
                Bcsum1 = Waitkey() : Csum = Csum + Bcsum1                                                                                                 'get checksum first byte
                For J = 1 To 128                                                                                                                          'get 128 bytes
                  Buf(j) = Waitkey() : Csum = Csum + Buf(j)
                Next
                Bcsum2 = Waitkey()                                                                                                                        'get second checksum byte
                If Bblocklocal = Bblock Then                                                                                                              'are the blocks the same?
                   If Bcsum2 = Csum Then                                                                                                                  'is the checksum the same?
                      Gosub Writepage                                                                                                                     'yes go write the page
                      Print Chr(ack);                                                                                                                     'acknowledge
                   Else                                                                                                                                   'no match so send nak
                      Print Chr(nak);
                   End If
                Else
                   Print Chr(nak);                                                                                                                        'blocks do not match
                End If
           Case 4:                                                                                                                                        ' end of transmission , file is transmitted
                 If Wrd > 0 And Bkind = 0 Then                                                                                                            'if there was something left in the page
                     Wrd = 0                                                                                                                              'Z pointer needs wrd to be 0
                     Spmcrval = 5 : Gosub Do_spm                                                                                                          'write page
                     Spmcrval = 17 : Gosub Do_spm                                                                                                         ' re-enable page
                 End If
                 Print Chr(ack);                                                                                                                          ' send ack and ready
    
                 Portb.3 = 0                                                                                                                              ' simple indication that we are finished and ok
                 Waitms 20
                 Goto _reset                                                                                                                              ' start new program
           Case &H18:                                                                                                                                     ' PC aborts transmission
                 Goto _reset                                                                                                                              ' ready
           Case 123 : Exit Do                                                                                                                             'was probably still in the buffer
           Case 124 : Exit Do
           Case Else
              Exit Do                                                                                                                                     ' no valid data
        End Select
      Loop
      If Bretries > 0 Then                                                                                                                                'attempte left?
         Waitms 1000
         Decr Bretries                                                                                                                                    'decrease attempts
      Else
         Goto _reset                                                                                                                                      'reset chip
      End If
    Loop
    
    
    
    'write one or more pages
    Writepage:
     If Bkind = 0 Then
       For J = 1 To 128 Step 2                                                                                                                            'we write 2 bytes into a page
          Vl = Buf(j) : Vh = Buf(j + 1)                                                                                                                   'get Low and High bytes
          lds r0, {vl}                                                                                                                                    'store them into r0 and r1 registers
          lds r1, {vh}
          Spmcrval = 1 : Gosub Do_spm                                                                                                                     'write value into page at word address
          Wrd = Wrd + 2                                                                                                                                   ' word address increases with 2 because LS bit of Z is not used
          If Wrd = Maxword Then                                                                                                                           ' page is full
              Wrd = 0                                                                                                                                     'Z pointer needs wrd to be 0
              Spmcrval = 5 : Gosub Do_spm                                                                                                                 'write page
              Spmcrval = 17 : Gosub Do_spm                                                                                                                ' re-enable page
    
              Page = Page + 1                                                                                                                             'next page
              Spmcrval = 3 : Gosub Do_spm                                                                                                                 ' erase  next page
              Spmcrval = 17 : Gosub Do_spm                                                                                                                ' re-enable page
          End If
       Next
    
     Else                                                                                                                                                 'eeprom
         For J = 1 To 128
           Writeeeprom Buf(j) , Wrd
           Wrd = Wrd + 1
         Next
     End If
    Return
    
    
    Do_spm:
      Bitwait Spmcsr.0 , Reset                                                                                                                            ' check for previous SPM complete
      Bitwait Eecr.1 , Reset                                                                                                                              'wait for eeprom
    
      Z = Page                                                                                                                                            'make equal to page
      Shift Z , Left , Maxwordshift                                                                                                                       'shift to proper place
      Z = Z + Wrd                                                                                                                                         'add word
      lds r30,{Z}
      lds r31,{Z+1}
    
      #if _romsize > 65536
          lds r24,{Z+2}
          sts rampz,r24                                                                                                                                   ' we need to set rampz also for the M128
      #endif
    
      Spmcsr = Spmcrval                                                                                                                                   'assign register
      spm                                                                                                                                                 'this is an asm instruction
      nop
      nop
    Return

    Klicke auf die Grafik für eine größere Ansicht

Name:	AVR-Options.jpg
Hits:	52
Größe:	32,2 KB
ID:	20584



    Was meinst Du mit com4? Der<M8 hat nur eine serielle Schnittstelle. So Sollte die Einstellung in Bascom für den Programmer stehen, wenn Du, nach dem Du per ISP geflasht hast, wieder Code dann per RS232 übertragen willst.

    MAT
    Miniaturansichten angehängter Grafiken Miniaturansichten angehängter Grafiken AVR-Options.jpg   AVR-Options.jpg  

  2. #2
    Erfahrener Benutzer Roboter Experte
    Registriert seit
    07.01.2010
    Ort
    Deutschland
    Beiträge
    739
    Danke MAT!!
    Allerdings habe ich schon das nächste Problem.
    Also ich bin schonmal weiter als vorher. Nach dem Reset des µC fängt er an das Programm zu übertragen, aber sagt wenig später:
    Open Com
    Sending Init byte
    Loader returned : 123
    Error : -6006
    Finish code : -6006


    Was soll ich tun. Ich weiß ja garnich was jetzt der Error ist. Im Netz hab ich auch noch nix gefunden.

    Mfg
    bnitram

  3. #3
    Erfahrener Benutzer Begeisterter Techniker
    Registriert seit
    25.03.2006
    Ort
    Hinsdorf
    Alter
    50
    Beiträge
    381
    hallo,

    wie flasht Du deinen Mikrokontroller?
    Also.... nach dem Du Dein Programm compiliert hast , drückst Du doch bestimmt den Button in Bascom für das Übertragen des Programms. Daraufhin öffnet sich ein Bildschirm, in dem Du den verlauf des Brennvorganges siehst. Was passiert dort genau bei Dir? Kannst Du den Balken sehen wie er voranschreitet und bei welchem Stand des Balken bricht er ab? Ich könnte mir jetzt nur vorstellen, dass irgendwie etwas mit Deiner seriellen Schnittstelle nicht richtig funktioniert. Wie ist diese an Deinem M8 aufgebaut? Schreib mir mal nen bischen über Dein Board, welches Du verwendest.
    Das Problem werden wir schon finden...

    Bis denne!
    MAT

  4. #4
    Erfahrener Benutzer Robotik Einstein
    Registriert seit
    08.01.2006
    Beiträge
    4.555
    Zitat Zitat von bnitram Beitrag anzeigen
    Danke MAT!!
    Allerdings habe ich schon das nächste Problem.
    Also ich bin schonmal weiter als vorher. Nach dem Reset des µC fängt er an das Programm zu übertragen, aber sagt wenig später:
    Open Com
    Sending Init byte
    Loader returned : 123
    Error : -6006
    Finish code : -6006


    Was soll ich tun. Ich weiß ja garnich was jetzt der Error ist. Im Netz hab ich auch noch nix gefunden.

    Mfg
    bnitram
    Da bist Du leider nicht der Erste und wo um Himmels Willen eine Liste der Fehler wir (hier) 6006 zu finden ist, hat anscheinend auch noch niemand herausbekommen?

    Gruß Richard

  5. #5
    Erfahrener Benutzer Roboter Experte
    Registriert seit
    18.05.2007
    Ort
    Berlin
    Alter
    54
    Beiträge
    765
    Fehler 6006 "riecht" nach einem Timeout. Ich würde mal mit der Baudrate experimentieren, vorher vielleicht nochmals die Fuses checken. Evtl. Stört auch etwas die Kommunikation. Erstmal nur ein kurzes "LED-Blinkprogramm" probieren.
    Wenn das Herz involviert ist, steht die Logik außen vor! \/

  6. #6
    Erfahrener Benutzer Robotik Einstein Avatar von Searcher
    Registriert seit
    07.06.2009
    Ort
    NRW
    Beiträge
    1.715
    Blog-Einträge
    133
    Zitat Zitat von peterfido
    Fehler 6006 "riecht" nach einem Timeout
    Paßt wohl. 6006 in der Bascom Hilfe als Suchberiff in "Search" findet den Bootloader. Ganz unten steht, das man $timout im Bootloader erhöhen sollte (oder daß überhaupt kein Bootloader vorhanden ist)

    Gruß
    Searcher
    Hoffentlich liegt das Ziel auch am Weg
    ..................................................................Der Weg zu einigen meiner Konstruktionen

  7. #7
    Erfahrener Benutzer Begeisterter Techniker
    Registriert seit
    25.03.2006
    Ort
    Hinsdorf
    Alter
    50
    Beiträge
    381
    Moin,

    wenn die Fehlermeldung tatsächlich ein Timeout ist, dann kann irgendetwas mit der Schnittstelle nicht stimmen. Ich nutze den Bootloader schon lange und musste an der Variable $timeout noch nichts ändern. Ob ein funktionierender Bootloader auf dem Chip ist, kann ganz einfach getestet werden. Man nehme ein Terminalprogramm und verbindet es mit dem Chip und geht online. Dann resettet man den chip und es sollte dann im Terminal einige Meldungen zu sehen sein, kommen diese nicht springt entweder der Chip nicht in den Bereich des Bootloader oder es ist keiner drauf....

    MAT

  8. #8
    Erfahrener Benutzer Roboter Experte
    Registriert seit
    07.01.2010
    Ort
    Deutschland
    Beiträge
    739
    Hallo und Danke nochmal an alle die hier nochetwas gepostet haben.
    Sorry das ich mich so lange nich mehr gemeldet habe aber ich hatte ein paar Probleme.
    Also ich habe jetzt nochmal alles getestet, hat aber nichts gebracht.
    @mat-sche:
    Habe deinen Test mal durchgeführt und glaube jetzt das meine UART nich mehr funktioniert. Ich bekomme nur manchmal etwas im terminal und dann auch nur 3(Zahlen, Buchstarben, komische Zeichen).
    Vielen Dank nochmal

    Mfg
    bnitram

Ähnliche Themen

  1. Bascom Bootloader
    Von fiatx im Forum Basic-Programmierung (Bascom-Compiler)
    Antworten: 3
    Letzter Beitrag: 21.03.2011, 10:12
  2. BASCOM 2te UART oder software UART
    Von Snecx im Forum Basic-Programmierung (Bascom-Compiler)
    Antworten: 5
    Letzter Beitrag: 18.02.2009, 23:25
  3. bascom bootloader problem
    Von Rasieel im Forum Basic-Programmierung (Bascom-Compiler)
    Antworten: 4
    Letzter Beitrag: 20.10.2008, 19:56
  4. bascom bootloader installiern
    Von aphex-world im Forum Basic-Programmierung (Bascom-Compiler)
    Antworten: 8
    Letzter Beitrag: 21.09.2008, 17:24
  5. BASCOM-Bootloader M8 AN#141
    Von stupsi im Forum Basic-Programmierung (Bascom-Compiler)
    Antworten: 2
    Letzter Beitrag: 17.12.2005, 17:53

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

fchao-Sinus-Wechselrichter AliExpress