View previous topic :: View next topic |
Author |
Message |
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Thu Dec 12, 2019 6:55 am Post subject: |
|
|
Hello Andre,
I'm sorry I didnt get back to youn sooner - i missed seeing the email notification.
Yes the bootloader does work and attaching the two lines of code as shown does work, and does allow you to program a chip with the bootloader AND the main code all in one hit.
It just doesn't allow this be be done OTA, for the reasons pointed out by MWS. _________________ Neil |
|
Back to top |
|
|
andro
Joined: 12 Mar 2007 Posts: 94 Location: Ljubljana
|
Posted: Thu Dec 12, 2019 7:14 am Post subject: |
|
|
Hello
Thanks for the answer. Did You try it also with Xmega ?
BR
andrej |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Thu Dec 12, 2019 8:37 pm Post subject: |
|
|
No only atmega _________________ Neil |
|
Back to top |
|
|
andro
Joined: 12 Mar 2007 Posts: 94 Location: Ljubljana
|
Posted: Thu Dec 12, 2019 10:24 pm Post subject: |
|
|
Thanks Neil.
When I'll have time to 'play' with this issue I will make a post. It might be interesting also for others.
BR
Andrej |
|
Back to top |
|
|
Pzx
Joined: 05 May 2015 Posts: 39
|
Posted: Sun Jun 14, 2020 7:52 pm Post subject: Bootloader in the main program |
|
|
Hello, I spent hours trying to include my bootloader into the main program using the method from this post and still not succeded.
I use Atmega 328p and tryied also 328pb, slghtly modified MCS Bootloder (with OLED display).
Structure of My_bootloder is as follows:
$regfile = "m328pbdef.dat"
$crystal = 14745600
$loader = $3800 '2048 ATMEGA328 this address you can find in the datasheet
$timeout = 300000
$prog &HCC , &HC6 , &HC8 , &HFD 'Vector Bootloader 2048
$lib "glcdSSD1309-SPI.lib"
Config Graphlcd = 128x64sed , Si = Portc.5 , Sclk = Portc.2 , A0 = Portc.1 , Rst = Portc.0
Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'***
' Bootloader body here, no interrupts
'***
$include "Update.font" ' this is a true type font with variable spacing
My main program structure is as follows:
$regfile = "m328pbdef.dat"
$crystal = 14745600
$timeout = 20000
$hwstack = 100
$swstack = 100
$framesize = 100
Config Graphlcd = 128x64sed , Si = Portc.5 , Sclk = Portc.2 , A0 = Portc.1 , Rst = Portc.0
Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'***
' Main program body here, interrupts from Com1 and Timer0
'***
$include "Normal.font" ' this is a true type font with variable spacing
When I program Atmega with My_bootloader using STK500 programmer it works well
When I program Atmega with the main program using STK500 programmer it also works well
When I program Atmega with the main program using My_bootloder over bluetooth it also works well
But, when I try to include in the very end of my main program (after $include "Normal.font"):
$boot = $3800 'bootloader address
$inc Bootloader , Nosize , "My_bootloader.bin" 'bootloade bin
The compiler shows error:
Error : 344 Program will overwrite flash memory (or bootloader) [ 27528 too long]
What I am doing wrong? |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Mon Jun 15, 2020 9:34 am Post subject: |
|
|
When you compiling bootloader program Bascom will create BIN file for ENTIRE flash so everything from $00 to $3800 will be filled with zeros. So you get info about 99% flash used and BIN probably have 32KB.
You must use some Hex/Bin editor/software and cut those zeros (for example from some external programmer or HexWork, WinHex etc.)
In the new version of Bascom will be option for "$loader [bootonly]" so Bascom can create only bootloader code without zeros on the begining of flash |
|
Back to top |
|
|
Pzx
Joined: 05 May 2015 Posts: 39
|
Posted: Thu Jun 18, 2020 9:58 pm Post subject: |
|
|
Thanks EDC, your hints are very heplful, as usual
I downloaded HexWorkshop, its nice and easy.
I wanted to cut off FF data at the begening of my bootloader bin file.
And here I found the first problem.
I programmed ATMEGA328PB with my bootloder alone to be sure that everything is ok. Bootloader works well.
Then I read the ATMEGA328PB flash buffer by STK500 programmer (memory lock fusebists are temporary unprogrammed).
The result you can see on picture1
Then I loaded my bootloader bin file into HexWorkshop. The result you can see on picture2.
The data starts at the same address, but looks direfently.
The question is why?
|
|
Back to top |
|
|
Netzman
Joined: 25 Nov 2005 Posts: 127 Location: Graz
|
|
Back to top |
|
|
Pzx
Joined: 05 May 2015 Posts: 39
|
Posted: Fri Jun 19, 2020 8:20 pm Post subject: |
|
|
Thanks Netzman for the hex word swap explanation.
I prepared my bootloader mini version without FFs at the begining using HexWorksop
I compared this bin file with "normal" bootloader bin, its identical, but without these first FFs
Then I prepared a simple program:
$regfile = "m328pbdef.dat"
$crystal = 14745600
$prog &HFF , &HFF , &HD8 , &HFE 'Atmega328PB: FLASH unlocked, ext XTAL slow setup time, Watchdog soft, Vector adres Botl 2048, Brownout 1,8V
Config Portd.1 = Output 'LED
Do
Toggle Portd.1 'blinking LED
Waitms 100
Loop
End
$boot = $3800 'adres bootloadera (double byte) no FF data at the begening
$inc Bootloader , Nosize , "BootLoader_pcb_15_3Kropki_v1_mini.bin" 'bin bootloadera mini HexWorkshop
Compiler displayed 96% Flash usage (it is ok, like loading my bootloader alone), LED blinks, but there is no bootloader code around the end of Flash memory.
There is the main program short code at the very berining of the Flash, the rest is filled with FFs.
I also tryed the same with older Atmega 328P. The result is the same.
What is still wrong? |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
Pzx
Joined: 05 May 2015 Posts: 39
|
Posted: Tue Jun 30, 2020 4:21 pm Post subject: |
|
|
Motivated by the success of EDC with blinking LED I tried to do the same one more time
My code is nearly the same. The diference migth be 2048 bootloader lengh with Oled driver and some fonts.
After several tests I gave up. Unfortunately it still doesnt include Bootloader code into the Flash memory.
My tests were held with Bascom 2082 and ATMEGA 328PB chip.
I did the same with older Bascom 2079 and older ATMEGA 328P chip.
And tadam, it works! Bootloader code is included in the Flash memory, LED blinks.
Unfortunately Bascom 2079 can not program newer ATMEGA 328PB chip.
EDC, which Bascom version have you used? |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Tue Jun 30, 2020 9:01 pm Post subject: |
|
|
Always newest
Please try whole folder compiled on 2082. |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Tue Jun 30, 2020 9:26 pm Post subject: |
|
|
This is wierd...why use previous(2078) versions for newest chips?
?
Last edited by EDC on Tue Jun 30, 2020 9:29 pm; edited 1 time in total |
|
Back to top |
|
|
|