Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
danni
PostPosted: Jun 01, 2009 - 02:42 PM
Raving lunatic


Joined: Sep 05, 2001
Posts: 2499


AndersAnd wrote:
I don't think I have ever seen a bootloader that supports AVRs without "Read-While-Write Self-Programming" (AVRs with BOOTRST fuse).
Is is actually possible to make a bootloader for devices without BOOTRST? And if so, why don't we see any bootloaders supporting these devices? OR does anyone have a link to a bootloader supporting an AVR without BOOTRST fuse?


Why you not look on the projects page?

Bootloader for ATtiny13 ... ATmega2561:

http://www.avrfreaks.net/index.php?modu ... em_id=1008


Peter
 
 View user's profile Send private message  
Reply with quote Back to top
hayashi_leo
PostPosted: Jun 14, 2009 - 09:25 PM
Rookie


Joined: Sep 24, 2008
Posts: 37


Hi,

I'm not able to download the pdf file. The browser is pointing to index.php,

Leo;
 
 View user's profile Send private message  
Reply with quote Back to top
schickb
PostPosted: Jun 14, 2009 - 09:37 PM
Hangaround


Joined: May 07, 2007
Posts: 291
Location: Seattle

hayashi_leo wrote:

I'm not able to download the pdf file. The browser is pointing to index.php


It still works find for me. I assume you are clicking the "Download" link in the very first post on page 1 of this topic. You can also try right clicking that link and selecting "save link as".

_________________
-Brad
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jun 14, 2009 - 10:14 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62354
Location: (using avr-gcc in) Finchingfield, Essex, England

The board used to have this problem but if the downloaded file gets called index.php just rename it to boot.pdf and it should still work

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
hayashi_leo
PostPosted: Jun 14, 2009 - 10:20 PM
Rookie


Joined: Sep 24, 2008
Posts: 37


Thanks! it works!!

Leo;
 
 View user's profile Send private message  
Reply with quote Back to top
AndersAnd
PostPosted: Jun 15, 2009 - 10:27 AM
Posting Freak


Joined: Apr 23, 2003
Posts: 1126
Location: Denmark

danni wrote:
AndersAnd wrote:
I don't think I have ever seen a bootloader that supports AVRs without "Read-While-Write Self-Programming" (AVRs with BOOTRST fuse).
Is is actually possible to make a bootloader for devices without BOOTRST? And if so, why don't we see any bootloaders supporting these devices? OR does anyone have a link to a bootloader supporting an AVR without BOOTRST fuse?

Why you not look on the projects page?
Bootloader for ATtiny13 ... ATmega2561:
http://www.avrfreaks.net/index.php?modu ... em_id=1008

Thank's for the heads up Peter, I missed that.
Does this bootloader use a software UART for all devices?
ATtiny13 and ATtiny45 doesn't have hardware UART, ATtiny2313 is the only ATtiny with UART.

Code:
AVR-----------user size--programming time
-----------------------------------------
ATtiny13-------606 Byte---0.77 seconds
ATtiny2313----1630 Byte---2.86 seconds
ATtiny45------3646 Byte---3.52 seconds
ATmega8-------7680 Byte---1.81 seconds
ATmega16-----15872 Byte---3.35 seconds
ATmega32-----32256 Byte---5.33 seconds
ATmega644----64512 Byte---8.19 seconds
ATmega2561--261120 Byte--32.75 seconds
At what BAUD-rate is this measured?


I guess "user size" is the same as the maximum program space flash left with the bootlaoder installed?
So this bootlaoader takes up this much flash in the different devices:
Code:
AVR-----------user size--------bootlaoder size------
----------------------------------------------------
ATtiny13-------606 Byte----1*1024-606    =  418 Byte
ATtiny2313----1630 Byte----2*1024-1630   =  418 Byte
ATtiny45------3646 Byte----2*1024-1630   =  450 Byte
ATmega8-------7680 Byte----8*1024-7680   =  512 Byte
ATmega16-----15872 Byte---16*1024-15872  =  512 Byte
ATmega32-----32256 Byte---32*1024-32256  =  512 Byte
ATmega644----64512 Byte---64*1024-64512  = 1024 Byte
ATmega2561--261120 Byte--256*1024-261120 = 1024 Byte
 
 View user's profile Send private message  
Reply with quote Back to top
jgiers
PostPosted: Jun 22, 2009 - 10:56 PM
Newbie


Joined: Jun 15, 2009
Posts: 13


Quote:
typedef void (*PF_VOID)(void);
typedef void (*PF_WHATEVER)(uint8_t);

...

static __inline__ void call_func3(uint8_t arg)
{ ((PF_WHATEVER) (0x3FE2/2))(arg); }


What are functions like this called, and how do I create them for functions that need multiple parameters? Thanks, and great tutorial.
 
 View user's profile Send private message  
Reply with quote Back to top
schickb
PostPosted: Jun 22, 2009 - 11:23 PM
Hangaround


Joined: May 07, 2007
Posts: 291
Location: Seattle

jgiers wrote:
Quote:
typedef void (*PF_VOID)(void);
typedef void (*PF_WHATEVER)(uint8_t);

...

static __inline__ void call_func3(uint8_t arg)
{ ((PF_WHATEVER) (0x3FE2/2))(arg); }


What are functions like this called, and how do I create them for functions that need multiple parameters? Thanks, and great tutorial.

Those are call function pointers. Here is an entire tutorial about function pointers in C/C++ http://www.newty.de/fpt/index.html

To add more parameters, just add them to the declaration and the call. The declaration would look something like
Code:
typedef void (*PF_WHATEVER2)(uint8_t, uint8_t);

_________________
-Brad
 
 View user's profile Send private message  
Reply with quote Back to top
hayashi_leo
PostPosted: Jun 24, 2009 - 05:49 PM
Rookie


Joined: Sep 24, 2008
Posts: 37


Hi;

question for FAQ #8, Can a bootloader use interrupts?

I would like to use interrupt with USART on my bootloader rather than polling.

So before the bootloader main(); I set
MCUCR = (1<<IVCE);
MCUCR = (1<<1VSEL);

this allocates the interrupt table into the BLS.

my question is how to restore the interrupt table to the application section?

is this the right method? place this code before jumping to application section;

MCUCR = (1<<IVCE);
MCUCR = (0<<IVSEL);

??

Thanks!!

Leo;
 
 View user's profile Send private message  
Reply with quote Back to top
schickb
PostPosted: Jun 24, 2009 - 10:04 PM
Hangaround


Joined: May 07, 2007
Posts: 291
Location: Seattle

hayashi_leo wrote:

my question is how to restore the interrupt table to the application section?

is this the right method? place this code before jumping to application section;

MCUCR = (1<<IVCE);
MCUCR = (0<<IVSEL);

That should work, although shifting zero isn't going to do anything. The code below is the same as yours. See faq #11 for an example of this:
Code:
MCUCR = (1<<IVCE);
MCUCR = 0;

If you want to be sure to clear only the IVSEL bit you'll need:
Code:
MCUCR = (1<<IVCE);
MCUCR &= ~(1<<IVSEL);

But you'll need to make sure the second write finished within 4 instructions of the first write (look at the ASM to know). The compiler should reduce "~(1<<IVSEL)" to a constant, and you'll be fine. But check to be sure.

_________________
-Brad
 
 View user's profile Send private message  
Reply with quote Back to top
hayashi_leo
PostPosted: Jun 25, 2009 - 02:41 AM
Rookie


Joined: Sep 24, 2008
Posts: 37


Thanks!!!
 
 View user's profile Send private message  
Reply with quote Back to top
HGunther
PostPosted: Nov 14, 2009 - 08:44 AM
Newbie


Joined: Jul 02, 2008
Posts: 19


I didn't find Download in this post.
Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Nov 14, 2009 - 10:46 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18581
Location: Lund, Sweden

HGunther wrote:
I didn't find Download in this post.
Thanks!

There are so many posts in the thread so that it is divided into two pages. At the top and bottom of the pages there are page selectors. Click the "1" and in the ultimately first post there is an attachement.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: Nov 14, 2009 - 12:20 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62354
Location: (using avr-gcc in) Finchingfield, Essex, England

Also note that I don't think your see attachments if you are not logged in. But the first post definitely has a PDF in it.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
wvangulik
PostPosted: Feb 04, 2010 - 08:38 PM
Newbie


Joined: Jul 28, 2007
Posts: 5
Location: Amsterdam

clawson wrote:

So whether anyone has ever achieved a complete self-reprogram in either the entire flash of a single section AVR or within the NRWW section of a dual section AVR is one of the great unsolved mysteries.

Some folks suggest that things like hard coding boot routine addresses in the app is a "dangerous thing" in case the bootloader itself is ever replaced but until someone actually manages to replace an AVR's own bootloader I think it's a moot point.

Cliff


Well we did... We had a bogus bootloader in a mega32?. (something with interrupts still enabled during programming). So sometimes it would not update correctly and the system would hang, luckily we could reboot it remote and re-upload the software.
So this is (roughly) what we did:
We figured out where our SPM function was.
Created special software containing a new bootloader as payload.
Used the existing bootloader to upload it.
Using the existing SPM function to flash a new SPM function to the end of the bootloader section.
Use the new SPM function to update the entire bootloader.
Reboot and let the bootloader load the normal software.
Yes it involved hard coded addresses, some special tricks to harden the flow against powerdowns etc. There was only one moment where we could not recover if we should have had a power failure.
It was some pretty nasty coding, but we now have a defined SPM function at the very end of our bootloader. And the bootloader has at least one bug less Wink

We also did bootloaders for Atmega48. (we did multiple actually) The code to do it is dead ugly and I was looking for pretty ways of doing it when came across this topic. Just wanted to let you know.
 
 View user's profile Send private message  
Reply with quote Back to top
TracerH
PostPosted: Feb 09, 2010 - 08:21 PM
Newbie


Joined: Oct 09, 2008
Posts: 8


I'm attempting to write my first bootloader and this the best explaination I've seen so far on the subject. However I have a question about setting up the environment to compile one. I use AVR Studio with a WinAVR installation, and have never had to muck around with the make files. Is there a way to specify to AVR Studio what changes need to be made to the make file to insure the code gets placed at the proper base address?

I also have another question that is outside of the scope of your fantastic document, but maybe somebody can point me in the right direction. I have a VB.NET app that communicates with my ATMEGA168, and I would like to be able to have it update the controller code if necessary. I don't expect anybody to give code examples, but if you know of any examples out in the wild, please let me know.

And thanks again for the great write up!

Wayne
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Feb 09, 2010 - 08:32 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62354
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

Is there a way to specify to AVR Studio what changes need to be made to the make file to insure the code gets placed at the proper base address?

Project menu
Configuration Options
Memory Settings
[Add]
Type = Flash (already selected)
Name = .text
Address = 0x1C00 (for example)
[OK]
[OK]

In this example (for mega16) I specified the address as 0x1C00 which is the WORD address for the BLS boundary address. When the code is built this can be seen as:
Code:
avr-gcc -mmcu=atmega16 -Wl,-Map=test.map -Wl,-section-start=.text=0x3800 empty.o test.o    -lm  -o test.elf

during the link. Notice how Studio has passed the 0x1C00 (word) address that was entered as 0x3800 (byte = 2* word) address because while Studio uses word addresses for flash GCC needs byte addresses.

The result of this is:
Code:
Disassembly of section .text:

00003800 <__vectors>:
    3800:   0c 94 2a 1c    jmp   0x3854   ; 0x3854 <__ctors_end>
    3804:   0c 94 47 1c    jmp   0x388e   ; 0x388e <__bad_interrupt>
    3808:   0c 94 47 1c    jmp   0x388e   ; 0x388e <__bad_interrupt>
    380c:   0c 94 47 1c    jmp   0x388e   ; 0x388e <__bad_interrupt>
    3810:   0c 94 47 1c    jmp   0x388e   ; 0x388e <__bad_interrupt>
etc.

which confirms that everything including the reset jump and the ISR vector table have been moved to byte address 0x3800

As for the VB thing I guess what you are asking is "how do I do COM ports from a VB program?" See examples written by Joe Pardue (smileymicros). I think he used to use VB and now uses C# but the M$ APIs you use are virtually identical (as is the case with all the .Net languages)

Cliff

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
smileymicros
PostPosted: Feb 09, 2010 - 08:43 PM
Raving lunatic


Joined: Nov 17, 2004
Posts: 6137
Location: Great Smokey Mountains.

TracerH wrote:
I'm attempting to write my first bootloader and this the best explaination I've seen so far on the subject. However I have a question about setting up the environment to compile one. I use AVR Studio with a WinAVR installation, and have never had to muck around with the make files. Is there a way to specify to AVR Studio what changes need to be made to the make file to insure the code gets placed at the proper base address?
I've done this using the Project Options without a special makefile (AVRStudio now generates it for you) but I don't remember all the details at the moment other than that I always had to double check that the bootloader address was correct. It seemed to want to randomly reset or not remember it properly between uses. IIRC the problem was in the Memory Settings of the Project Options.

TracerH wrote:
I also have another question that is outside of the scope of your fantastic document, but maybe somebody can point me in the right direction. I have a VB.NET app that communicates with my ATMEGA168, and I would like to be able to have it update the controller code if necessary. I don't expect anybody to give code examples, but if you know of any examples out in the wild, please let me know.
Are you looking for some sort of GUI that creates the parameter list for avrdude and then calls it to upload a hex file to your bootloader? If so, I am just now tying up loose ends on a C# .NEt project that does this. I plan to post the code here in a week so be on the lookout for AVRUP-V1. Look that over and if you really need me to, I can do an auto port from C# to VB. Let's not hyjack this thread so if you are interested either start a new thread 'avrdude GUI in .NET?' or wait till I post my code.

[edit]AND along comes Cliff while I'm fumbling around.[/edit]

Smiley

_________________
FREE TUTORIAL: 'Quick Start Guide for Using the WinAVR C Compiler with ATMEL's AVR Butterfly' AVAILABLE AT: http://www.smileymicros.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
TracerH
PostPosted: Feb 09, 2010 - 09:56 PM
Newbie


Joined: Oct 09, 2008
Posts: 8


Wow, you guys are fast and informative! Many thanks for the information. Since reviewing the docs here, I have found the AVR109/AVR911 app notes. I will look at the setup in AVR Studio when I try this.

As for the VB.NET end, I will review the existing code and eagerly await the new version. (C# and VB are basically the same.) I am hoping to recreate the download code without using AVRDUDE. I am quite experienced in using the RS-232 port from .NET code, so more looking for information on parsing the hex file format for download. Maybe I can find what I need in the source to AVROSP.

So, again, my humble thanks to you guys for the speedy help. And sorry for the thread hijacking!

Wayne
 
 View user's profile Send private message  
Reply with quote Back to top
Dbazinet
PostPosted: Mar 01, 2010 - 07:28 AM
Wannabe


Joined: Dec 23, 2008
Posts: 79
Location: Montréal, Canada

Hello,

Thanks for this tutorial! But I still have a problem concerning question #1. Not gone far yet...

I want to write a bootloader for Mega168. I set the BOOTRST and BOOTSZ to 1024 words. I use AVR Studio with WinAVR, gcc and JTAG ICE MKII.

I need to write the bootloader in the bootloader section so I did as in the FAQ. In the custom options, I added "-Wl,--section-start=.text=0x3800". When I load the code, it is still at 0x00. I look in the view memory to see where it is. I load it with the JTAG MKII using Debug Wire (start debugging).

Questions:

1- Is it ok to load a bootloader with JTAG MKII and DW?

2- If not, wich tool to use?

3- In my bootloader program, I make a normal AVR project with a "int main (void) {}" function. Is this ok?

4- Am I missing something to put the code at 0x3800 (0x1C00 word adress)?

Thanks a lot!
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits