View previous topic :: View next topic |
Author |
Message |
manekinen
Joined: 21 Oct 2007 Posts: 34
|
Posted: Wed Apr 06, 2011 8:31 pm Post subject: |
|
|
AdrianJ - yes i know, its not that hard to do it, it just need a non-fragmented file copied just after formatting the card. But i want it to be simple for someone who make my ciruit
Also, bigger chip is not an option. TQFP32 is max that i can put into board. Also, M328P is cheaper and more available than her bigger sisters.
Good news. I compiled code with AVR-DOS.LBX version 3.0.
Used Config file from basc-avr 1.11.7.7, changed only the Cfileget_mode const to allow reading "input" file mode with GET function.
No errors, only 60 bytes too long
Code (with avr-dos 3.0 included) in attachment, please take a look if i did not made any stupid mistake
I want to ask what do this part of program:
Code: |
If Eof(fn) <> 0 Then
If Wrd <> 0 Then
Wrd = 0
Spmcrval = 5 : Gosub Do_spm
Spmcrval = 17 : Gosub Do_spm
End If
Goto _reset
End If
|
When we get End Of File flag (eof<>0), it means that whole flash was written, and what for is this additional code in IF-THEN condition?. Can i delete it?
PS. disable code optimalisation in compiler options, it will generate bigger code
What else can i do to reduce it more?[/code]
Best regards _________________ µProg – tiny, fast, portable AVR programmer with SD - bascom powered |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Thu Apr 07, 2011 12:48 am Post subject: |
|
|
When you get the eof() flag set, the whole file has been transferred to the internal buffer. But in case the buffer still has program in it ( Wrd>0) which has not been written to actual Flash, you must erase the last page ( spmcrval=5), and then write from buffer to Flash ( spmcrval=17). The only way of avoiding this would be to make absolutely certain that the code was exactly an integer number of program pages long. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
manekinen
Joined: 21 Oct 2007 Posts: 34
|
Posted: Mon Apr 11, 2011 7:04 am Post subject: |
|
|
Edited compiled LBX library, code has 4096 bytes and it rarely fits into 4kB boot memory (4096 with software spi, chosing hardware will give even shorter code but did not test it).
Code works great, flashing 16kB in about 3 seconds. Tested with Mega32. Works with 128, 512, 1gb, 2gb, 2gb micro sd cards and probably others too.
I tried to contact the author of avr-dos but he doesn't answer, don't know if i can publicate this modified stuff. _________________ µProg – tiny, fast, portable AVR programmer with SD - bascom powered |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Apr 11, 2011 9:51 am Post subject: |
|
|
Nice you got it working.
The author is very busy. if you are not a customer of the lib, it could take some time till he replies.
You may not distribute lbx/lib files which you did not wrote yourself.
So for that you indeed do need his permission. _________________ Mark |
|
Back to top |
|
|
manekinen
Joined: 21 Oct 2007 Posts: 34
|
Posted: Tue Apr 12, 2011 6:24 pm Post subject: |
|
|
Got permission from author, to publish code with modified lbx
So, here it is, the 4kB SD bootloader for mega32, mega328, etc.
Loader works only with BIN files. Change the confirmation button to any pin. Hit it to confirm flashing. If file is not present, code will exit and go to address of main program.
This uses old 3.0 library without directories and FAT32 support. Also contains some bugs which have been fixed in newer versions.
Compiled with 2.0.4.0 gives 4096 bytes - enabling code optimalizations will give bigger code!
File name is "flash.bin" but you can change it to whatever you want.
"avr-dos3_modified.lbx" must be copied to LIB folder of basc-avr.
Works very nice for me If you put the "flash.bin" into root folder and bootloader will exit to main program, this means that your card is not supported in avr-dos 3.0.
Please give some feedback how its works for you guys _________________ µProg – tiny, fast, portable AVR programmer with SD - bascom powered |
|
Back to top |
|
|
reinhars
Joined: 29 Nov 2009 Posts: 114
|
Posted: Sat Apr 16, 2011 10:42 am Post subject: |
|
|
Finally i got bootloader working for atxmega256a3. Version >= 2.0.5.0 is needed. I will post the code in some days after cleaning it up.
Edit ->
Code is with support for lcd output but can be disabled with editing the constant. I still have problems with graphic elements on display - text is working great but with graphic the display sometimes clears and hang up... haven't solved the problem yet.
Here is working code now:
Code: |
$regfile = "xm256a3def.dat"
$crystal = 16000000
$hwstack = 256
$swstack = 512
$framesize = 512
$loader = &H20000
$lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014
'Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 ' we will use 32 MHz and divide by 1 to end up with 32 MHz
Config Osc = Enabled , Extosc = Enabled , Range = 12mhz_16mhz , Startup = Xtal_16kclk
Config Sysclock = External
Disable Interrupts 'we do not use ints
Const Maxwordbit = 7 ' Z7 is maximum bit '
Const Maxword =(2 ^ Maxwordbit) * 2 '128
Const Maxwordshift = Maxwordbit + 1
Const Loadsize = &H1EFFF * 2 'xmega256 application flash in words * 2
Const Filenamebin = "Master.bin"
'Const Filenamebindone = "M.Bin"
'Const Maxpages = Loadsize / Maxword
Const Lcdoutput = 1
#if Lcdoutput = 1
Dim Loopcounter As Word
Dim Linecounter As Byte
Display_controlport Alias Porte 'PORTE.2 - PORTE.7
Display_dataport Alias Portf 'PORTF.0 - PORTF.7
Config Graphlcd = 240 * 64 , Dataport = Display_dataport , Controlport = Display_controlport , Ce = 4 , Cd = 5 , Wr = 2 , Rd = 3 , Reset = 6 , Fs = 7 , Mode = 8
Cls
Cursor Off
#endif
Dim Btemp1 As Byte
Dim Strname1 As String * 12
Dim Strname2 As String * 12
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 Buf(128) As Byte
Dim Lfilelen As Long
Dim Initfilesystemerror As Byte
Dim W1 As Word , B1 As Byte
'(
' TWI (I2C)
Dim Twi_start As Byte 'This Variable is used by the I2C functions
Open "TWIE" For Binary As #2 'Pull-Up resistor (4K7) on SDA and SCL to Vcc = 3,3V
Config Twie = 40000 'Set TWI Baud Rate and Enable TWI Master
I2cinit #2 'set i2c pins to right state , open collector , pull up activated
')
$include "include/xmega/Config_MMC.bas"
If Gbdriveerror <> 0 Then
#if Lcdoutput = 1
Cls
Locate 1 , 1
Lcd "SD-Karte fehlerhaft"
Wait 3
#endif
Goto Startmain
End If
$include "include/xmega/CONFIG_AVR-DOS.bas"
Btemp1 = Initfilesystem(1) ' Get File system
' use 0 for drive without Master boot record
If Btemp1 <> 0 Then
#if Lcdoutput = 1
Cls
Locate 1 , 1
Lcd "Dateisystem fehlerhaft"
Wait 3
#endif
Goto Startmain
End If
Lfilelen = Filelen(filenamebin)
If Lfilelen > 0 And Lfilelen < Loadsize Then
#if Lcdoutput = 1
Cls
Locate 1 , 1
Lcd "Lade Softwareaktualisierung"
Locate 2 , 1
Lcd "Bitte warten..."
Wait 1
#endif
Gosub Flashbin ' Size OK
End If
#if Lcdoutput = 1
If Lfilelen > Loadsize Then
Cls
Locate 1 , 1
Lcd "Aktualisierungsdatei fehlerhaft"
Wait 5
End If
#endif
'--- Jump to mainprogram -------------------------------------------------------
Startmain:
Rampz = 0
Goto _reset
End
'--- Subroutines - -------------------------------------------------------------
'--- BIN-File Part -------------------------------------------------------------
Flashbin:
Open Filenamebin For Binary As #1
If Gbdoserror > 0 Then
#if Lcdoutput = 1
Cls
Locate 1 , 1
Lcd "Fehler beim oeffnen der Datei"
Wait 3
#endif
Goto Startmain
End If
Page = 0
Wrd = 0
Spmcrval = &H20 : Gosub Do_spm ' erase all app pages
#if Lcdoutput = 1
' Dim Loopcounter As Byte
' Dim Linecounter As Byte
' Cls
Locate 3 , 1
' Box(20 , 20) -(220 , 30) , 255
' Line(19 , 20) -(220 , 20) , 255
' Line(19 , 30) -(220 , 30) , 255
' Line(220 , 21) -(220 , 29) , 255
Linecounter = 0
Loopcounter = 0
#endif
Do
Get #1 , Buf(1) , , 128
#if Lcdoutput = 1
Incr Loopcounter
If Loopcounter >= 330 Then
Loopcounter = 0
Incr Linecounter
Lcd "."
Waitms 100
' Line(linecounter , 21) -(linecounter , 29) , 255
End If
#endif
Gosub Writepage
If Eof(#1) > 0 Then
If Wrd > 0 Then 'if there was something left in the page
Wrd = 0 'Z pointer needs wrd to be 0
Spmcrval = &H24 : Gosub Do_spm 'write page
End If
Close #1
#if Varexist( "FileNameBinDone")
Strname1 = Filenamebin
Strname2 = Filenamebindone
Kill Strname2
Name Strname1 As Strname2
#endif
#if Lcdoutput = 1
Do
Incr Linecounter
' Line(linecounter , 21) -(linecounter , 29) , 255
Waitms 100
Lcd "."
Loop Until Linecounter = 29
Locate 1 , 1
Lcd "Softwareaktualisierung "
Locate 2 , 1
Lcd "erfolgreich "
Wait 5
#endif
Exit Do
End If
Loop
Return
'--- Ende BIN-File Part --------------------------------------------------------
'--- Programming Part ----------------------------------------------------------
'write one or more pages
Writepage:
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 = &H23 : 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 = &H24 : Gosub Do_spm 'write page
Page = Page + 1 'next page
End If
Next
Return
Do_spm:
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
Nvm_cmd = Spmcrval
Cpu_ccp = &H9D
spm 'this is an asm instruction
Do_spm_busy:
lds r23, NVM_STATUS
sbrc r23,7 ;if busy bit is cleared skip next instruc tion
rjmp do_spm_busy
Return
'--- Ende Programming Part -----------------------------------------------------
|
|
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Fri Apr 29, 2011 10:02 am Post subject: |
|
|
A question about the xmega SD bootloader is this using the dedicated flash that is for this purpose? |
|
Back to top |
|
|
reinhars
Joined: 29 Nov 2009 Posts: 114
|
Posted: Fri Apr 29, 2011 4:05 pm Post subject: |
|
|
Do you mean a special type of file to load?
It is just loading .bin files created by bascom. |
|
Back to top |
|
|
Tubeampman
Joined: 27 Feb 2006 Posts: 100 Location: Bodo
|
Posted: Fri Apr 29, 2011 9:47 pm Post subject: |
|
|
Hi
Is there a sizelimit on how big an SD-card can be for use with AVR-DOS?
I have some 4GB i going to try out.
Regards
Řyvind |
|
Back to top |
|
|
reinhars
Joined: 29 Nov 2009 Posts: 114
|
Posted: Sat Apr 30, 2011 9:23 am Post subject: |
|
|
4gb card should be a sdhc card. with standard avr-dos you can not use sdhc card - but there is a mmcsd_hc.lib somewhere in this forum.
with the lib you can use big cards. This lib is only for atmega - not for atxmega. |
|
Back to top |
|
|
manekinen
Joined: 21 Oct 2007 Posts: 34
|
|
Back to top |
|
|
Tubeampman
Joined: 27 Feb 2006 Posts: 100 Location: Bodo
|
Posted: Thu Sep 29, 2011 4:54 pm Post subject: |
|
|
Hi
Mr. manekinen`s bootloader works great on M32.
I need a chip with more space so i have bought a few M1284P.
I was wondering if someone please can help me with wich lines i have to edit to get the 1284 to work
-----------------------------------------------
$regfile = "m32def.dat"
$crystal = 16000000
$hwstack = 128
$swstack = 128
$framesize = 128
'select your chip:
Const Loaderchip = 32
#if Loaderchip = 32 ' Mega32
$loader = &H3800 ' 2048 words
Const Maxwordbit = 6 ' Z6 is maximum bit '
Const Loadsize = &H3800 * 2 ' highest Number of bytes to
#endif
-----------------------------------
lds r30,{Z}
lds r31,{Z+1}
#if Loaderchip = 128
lds r24,{Z+2}
sts rampz,r24 ' we need to set rampz also for the M128
#endif
lds r0, {vl} 'store them into r0 and r1 registers
lds r1, {vh}
Spmcsr = Spmcrval 'assign register
spm 'this is an asm instruction
nop
nop
Return
BestRegards
Fixmann |
|
Back to top |
|
|
Tubeampman
Joined: 27 Feb 2006 Posts: 100 Location: Bodo
|
Posted: Fri Sep 30, 2011 8:27 am Post subject: |
|
|
Hi
I found the solution
Fixmann |
|
Back to top |
|
|
george2002
Joined: 23 Nov 2005 Posts: 74 Location: Krakow
|
Posted: Tue Oct 04, 2011 10:57 pm Post subject: |
|
|
Hello
If anyone can write/help how to set values for Atmega128 manekinen's bootloader ?
I need 4kB MMC bootloader on my atmega128.
Is those settings are ok ?:
Code: |
$regfile = "m128def.dat"
$crystal = 11059200
$hwstack = 128
$swstack = 128
$framesize = 128
'select your chip:
Const Loaderchip = 128
#if Loaderchip = 128 ' Mega128
$loader = &H0000 ' 4096 words
Const Maxwordbit = 7 ' Z7 is maximum bit
Const Loadsize = &H1000 * 2 ' highest Number of bytes to load
#endif
|
Do i have to change something else in below manekinen's bootloader code to get it working ?
Code: |
'set your confirmation button here:
Config Pina.3 = Input
Set Porta.3
'name of flash file, put it in root directory:
Const Filenamebin = "update.bin"
'_______________________________________________________________________________
Dim Btemp1 As Byte
$include "Config_MMC.bas"
$include "Config_AVR-DOS3.BAS"
Btemp1 = Initfilesystem(1) ' Get File system
Const Maxword =(2 ^ Maxwordbit) * 2 '128
Const Maxwordshift = Maxwordbit + 1
Const Maxpages = Loadsize / Maxword
Const Fn = 10 ' file-number
Dim J As Byte , Spmcrval As Byte ' self program command byte value
Dim Bprog As Byte
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 Buf(128) As Byte
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
Bprog = 1
Open Filenamebin For Input As #fn
If Gbdoserror <> 0 Then Goto _reset
'set your confirmation button here:
Bitwait Pina.3 , Reset
Spmcrval = 3 : Gosub Do_spm ' erase the first page
Spmcrval = 17 : Gosub Do_spm ' re-enable page
Do
Get #fn , Buf(1) , , 128
Gosub Writepage
If Eof(fn) <> 0 Then
If Wrd <> 0 Then
Wrd = 0
Spmcrval = 5 : Gosub Do_spm
Spmcrval = 17 : Gosub Do_spm
End If
Goto _reset
End If
Loop
'-------------------------------------------------------------------------------
'write one or more pages
Writepage:
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
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
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
If Page <= Maxpages Then ' avoid to erase first page of bootlaoder
Spmcrval = 3 : Gosub Do_spm ' erase next page
Spmcrval = 17 : Gosub Do_spm ' re-enable page
End If
End If
Next
Return
'-------------------------------------------------------------------------------
Do_spm:
Z = Page 'make equal to page
Shift Z , Left , Maxwordshift 'shift to proper place
Z = Z + Wrd
If Bprog <> 1 Then Return
Bitwait Spmcsr.0 , Reset ' check for previous SPM complete
Bitwait Eecr.1 , Reset
'wait for eeprom 'add word
lds r30,{Z}
lds r31,{Z+1}
#if Loaderchip = 128
lds r24,{Z+2}
sts rampz,r24 ' we need to set rampz also for the M128
#endif
lds r0, {vl} 'store them into r0 and r1 registers
lds r1, {vh}
Spmcsr = Spmcrval 'assign register
spm 'this is an asm instruction
nop
nop
Return
|
Of course i set up Config_MMC.bas file appropriately
Regards
George2002
Last edited by george2002 on Tue Oct 04, 2011 11:54 pm; edited 1 time in total |
|
Back to top |
|
|
Tubeampman
Joined: 27 Feb 2006 Posts: 100 Location: Bodo
|
Posted: Tue Oct 04, 2011 11:52 pm Post subject: |
|
|
Hi
The card must be formated in FAT (not FAT32)
These settings should work:
#if Loaderchip = 128 ' Mega128
$loader = &HF000 ' 4096 words (startvektor of the bootloader, you will find the startaddress of the different bootloadersizes in the datasheet page 284 of the M128)
Const Maxwordbit = 7 ' Z7 is maximum bit '
Const LoadSize = &HF000 * 2 ' highest Number of bytes to load
#endif
The rest looks ok.
Tubeampman |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|