Wie lange wird denn gewartet bis das normale Programm anfängt wenn keine Daten gesendet werden ?
Druckbare Version
Wie lange wird denn gewartet bis das normale Programm anfängt wenn keine Daten gesendet werden ?
Kann man vor dem Compilieren selber einstellen.. da sind ein paar Waitms im Listing drin inkl. Kommentaren...
Hmm ... es scheint ich bin Bootloader resistent :)
Ich habe den Bootloader mit Bascom hochgeladen (Elektor Programmer).
Dann habe ich den Programmer auf MCS-Bootlader umgestellt und wollte mein Hauptprogramm flashen. Leider komme ich nur bis
OpenCOM
Sending Init Byte
Ich denke, ich stell mich nur grade blöd an, habe aber keine Idee mir das selbst bei zu bringen ;)
Könnte mir grad mal jemand helfen ?
Bascom Version ist die 1.11.93
Gruß
Jens
Wenn die Nachricht kommt, musst du den µC kurz reseten, der sendet dann das STartbyte.
Hi,
nicht vergessen, die richtigen Fuses zu setzen.
1. die Fuse für die Startadresse des Bootloaders
2. Boot Reset Vector enabled
Zu 2.
Der Bootloader sitzt ganz hinten im Flash.
Wird der Controller resettet, dann startet der Programmzähler von 0 und läuft dann hoch, bis er irgendwann zur Startadresse des Bootloaders kommt.
Schon kann man programmieren.
Aber.... das war' dann auch schon mit dem Programmieren.
Ab jetzt geht nämlich nichts mehr.
Ist ein Programm im Flash, kommt der Programmzähler gar nicht mehr bis zum Bootbereich, da eben das Anwendungsprogramm gestartet wird.
Deshalb ist die Boot Reset Vector Fuse zu setzen.
Dadurch startet der Controller bei der Adresse des Booloaders und nicht bei 0.
Somit ist sichergestellt, daß immer zuerst der Bootloader vor dem Anwenderprogramm gestartet wird.
Gruß
Christopher
Danke für eure Antworten, aber bei mir bleibt hartnäckig
Sending Init Byte stehen, auch nach einem Reset.
Wo find ich den die Fuse für die Startadresse ? Ist das Fusebit FE ? Das steht auf 1024 Words, C00.
Boot Reset Vector ist enabled.
Er will aber nicht ....
Hier der Bootloader:
Irgendwo steckt der Fehler ....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 = 14745600
$baud = 19200
'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 'Z5 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
'Mega 88 : 32 words, 128 pages
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
$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
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
'How you need to use this program:
'1- compile this program
'2- program into chip with sample elctronics programmer
'3- select MCS Bootloader from programmers
'4- compile a new program for example M88.bas
'5- press F4 and reset your micro
' the program will now be uploaded into the chip with Xmodem Checksum
' you can write your own loader.too
'A stand alone command line loader is also available
'How to call the bootloader from your program without a reset ???
'Do
' Print "test"
' Waitms 1000
' If Inkey() = 27 Then
' Print "boot"
' Goto &H1C00
' End If
'Loop
'The GOTO will do the work, you need to specify the correct bootloader address
'this is the same as the $LOADER statement.
Gruß
Jens
Irgendwie sieht das komisch aus.
Hast du da dran rumgebastelt? Ich vermisse die #-Teile für die verschiedenen µCs...
http://palmavr.sourceforge.net/cgi-bin/fc.cgi
Hier findet man die Infos zu den Fuses...
Ja hab ich, da ich das nur für den Mega8 benötige.
Danke für den link.
Edit: Klappt aber auch mit dem auf den Mega8 angepassten original File nicht.
Man muss da ein paar Sachen ein-/auskommentieren.
GND Verbindung von Progger zu Zielschaltung haste auch?
Die korrekte Größe des Bootloaders muss man u.U. auch noch eintragen.
Also ich habe alles relevante für den M8 aktiviert bzw. deaktiviert.
GND Verbindung ist da, normale serielle Ausgaben von meinem Programm funktionieren ja problemfrei, nur der Bootloader will nicht.