Pages: [1]   Go Down
Author Topic: Using ATmega8 with Arduino and plain WinAVR  (Read 951 times)
0 Members and 1 Guest are viewing this topic.
Ukraine
Offline Offline
Full Member
***
Karma: 1
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good day!

I've ATmega8 on a breadboard with bootloader configured as "Arduino NG or older w/ ATmega8", the fuses settings

Code:
atmega8.bootloader.low_fuses=0xdf
atmega8.bootloader.high_fuses=0xca

So, the bootloader settings are "Boot Flash section size=512 words Boot start address=$0E00; [BOOTSZ=01]".
I use this chip with Arduino and with plain WinAVR with external programmer ("external programmer" is my actual Arduino with ArduinoISP smiley)

As far as I understand the booloader is placed inside flash memory at the very end of it.

So the question:
If I put the "big" program inside this chip using avrdude and external programmer, can my program "overlap" with bootloaders's start address, so the chip will try to execute some part at the end of my program as a bootloader?

Logged

Ukraine
Offline Offline
Full Member
***
Karma: 1
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've found this topic: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1184164498

and this:

Quote
Your sketch always starts at location 0 - the bootloader's actually at the end of memory - so you don't need to change anything.

Why?
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
can my program "overlap" with bootloaders's start address, so the chip will try to execute some part at the end of my program as a bootloader?
Yes.  That would be bad.  As far as I know, the "protection" bits that affect the bootloader only do anything to programmatic access to the flash memory (LPM, SPM instructions.)  There is nothing that protects the bootloader space when using ISP programming.

(also, I think that some ISP programming processes start out by doing a "chip erase" function, and that would wipe out the bootloader as well.)
Logged

Ukraine
Offline Offline
Full Member
***
Karma: 1
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply.

As far as I understand avrdude output, the entire flash is written when I use ISP programmer. So when I flash my program directly (I'll call it 'bare program' here) I overwrite bootloader anyway. That's not a problem while I can write it back smiley

The questions:

1. When I flash 'bare program' which is small (it ends before bootloader's address), the start address of bootloader contains nothing, so controller immediatelly starts from the beginning. Right?

2. What happens when I create a huge program which take all flash including addresses where bootloader starts. Will controller blindly execute instructions from the middle of the my program thinking that this is a bootloader?

This article says that I can use full flash size for programs while having fuses configured for bootloader:
http://arduino.cc/en/Hacking/Programmer
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This article says that I can use full flash size for programs while having fuses configured for bootloader:
http://arduino.cc/en/Hacking/Programmer
I don't see anything in there that specifically mentions the fuses.  I think it's wrong, and you MUST reprogram the fuses if you want to start at location 0 instead of the bootloader start.  But I haven't experimented...

If you start at the bootloader address and that memory is erased, the AVR will end up essentially executing harmless instructions until the program counter wraps around and it gets the the normal restart vector at location 0.

If you start at the bootloader address and that memory contains "random" segments of your main program, then behavior is likely to be random...
Logged

Ukraine
Offline Offline
Full Member
***
Karma: 1
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for the reply, have you any idea why author states in the forum that it should work anyway?
Logged

Pages: [1]   Go Up
Jump to: