Loading schetches on a fresh atmega8 with no bootloader.

Can I use my Uno and load the Arduino as ISP sketch on it.
Then use that Uno board to load a sketch to a fresh atmega8 (or any other) without any bootloader on it

If so...How would I do that?

If I understand things, the bootloader is used to program the controler without an ISP. Witch is great when developing with Uno board.

But after all is done and I want to put my sketch on a stand alone chip I'm going to use in my final build.
I don't really need a bootloader.......right?

Please educate me :blush:

I don't really need a bootloader.......right?

No you don't. However many of us develop our sketches on our arduino board and when done just pop the chip and install it in our standalone project and just install a fresh $6 328 chip (with bootloader) in the arduino. If a later update is needed, just pop the chip from the project and reinstall on the arduino board. That way no ISP programmer required nor a lot of thinking about how to burn the sketch into the chip without a bootloader.

So there are different methods of accomplishing the same task, and unless one needs the small space that the bootloader code takes up, I think it's just a choice made by the user on how they want to manage their projects.

Lefty

Sketches should work if programmed via ISP, as long as you have the fuses set NOT to start in the bootloader section.

@westfw... Is that the "Boot Reset vector Enabled (default address=$0000); [BOOTRST=0]" fuse?

Yes. Note that fuse value 1 is "not programmed", so you want BOOTRST=1 to disable the bootloader.

OK (please excuse my ignorance).

So If I wanted to use the Arduino IDE, load the Arduino as ISP to the Uno.
Then open my sketch and load it to a new chip (on a breadboard) that as no bootloader.
What do I need to do?

I guess it's a lot like loading the bootloader ..... but that is done by simply selecting the "Burn bootloader /w Arduino as ISP" option.

I guess what I'm trying to do would be more complicated........but I'm willing to try. :blush:

Wait... I thought we had to have the Arduino bootloader on the chip to read the compiled sketches because I thought the firmware translated a few things..... Damn. If this is the case I just wasted a whole lot of time on well... Actually not wasted but could have been doing something else semi-productive $)

But you do have to have the bootloader to interact through rx and tx over serial with the IDE though correct? I was wondering if there was a hack to make the IDE use an avr programmer instead of just sending straight to serial.

No, the bootloader and the Arduino core are entirely separate, and the bootloader is not needed to run any sketches.

You can probably edit boards.txt and have the IDE use any programmer supported by AVRDUDE (which is a lot of choices!) It already uses different protocols for Uno vs Mega...

westfw:
Sketches should work if programmed via ISP, as long as you have the fuses set NOT to start in the bootloader section.

Sorry.....but I'm lost :blush:

alparent:

westfw:
Sketches should work if programmed via ISP, as long as you have the fuses set NOT to start in the bootloader section.

Sorry.....but I'm lost :blush:

1st - westfw, again thank you for clearing up some things man. I truly appreciate your knowledge.
2nd - on to help this guy out.

When dealing with avr microcontrollers you have what are called switches that are just codes that do certain things to the chip to either help it operate in certain ways, lock people from trying to reflash the chip or to try to pull code from the chip, or make it skip things, and etc.

There are 3 types of switches - high, low, and e-lock fuses.

Per each chip model, they differ both in what switches the chip comes with, and what address each switch is located (in software. you'll see in this example)

So say you want to make an Atmega8 use an external oscillator/crystal of 8 to 12mhz, you would set that fuse by writing the binary address -
0xF8

These switches are also referred to as lock bits

You can find a calculator to set them what you want them to be here:
http://frank.circleofcurrent.com/fusecalc/fusecalc.php

BE CAREFUL WHEN USING THIS! If you don't know what you want to use or don't understand certain sections that you chose for your chip, consult with us in the forums to ensure the settings are proper. One error can efficiently lock you out of the chip (which you could only unlock with an HVP (High Voltage Programmer) which are easy enough to make, but it'll cost you some cash in making one, and set you back a little while waiting on the parts to get to you unless you have them laying around.

Now on to bootloaders and etc.

Bootloaders are basically applications that can reside in a section of the chip you can "lock" into place (in the very beginning of the chip memory). You have to essentially "unlock" that portion of the chip first before you can burn the bootloader into place, and then you have to "lock" that bootloader into memory because if you do not, then when you try to upload a sketch to the chip, it will erase the bootloader *if you need that extra memory that a bootloader would take up, you could just unlock it, and just not re-lock the bootloader section so you could have more application space available to upload to the chip.

What does a bootloader do? Essentially they can be used for a number of reasons, but one of the more prominent reasons are to run a predefined set of instructions on boot to set the system up to help do a defined task. It could be to test the components it runs to ensure there are no errors, or even to expand the functionality of a chip.

Think of it like the bios of a computer. Basically same difference.

Computer
1/Turn on power
2/Bios run (start bootloader)
3/Bios test (ensure no big errors are going on with internal hardware)
4/provide user interface for changing hard drive on the fly or going into bios settings
5/point to the hard drive set as the master 1st boot drive as defined in settings
6/point to run the boot program on 1st boot drive at the start of the boot partition.

Atmega Chip
1/Turn on power
2/Is fuse selected to run bootloader first?
3a/If above bootloader fuse = no, then skip bootloader and run sketch (or hex file)
3b/If above bootloader fuse = yes, then run bootloader
4/do defined instructions in bootloader
5/point to start of unprotected (non-bootloader) memory
6/run sketch(or hex file.)

Good explanation.

Bootloaders are basically applications that can reside in a section of the chip you can "lock" into place (in the very beginning of the chip memory).

Chips like the atmega328 (with "boot section support") have the ability to put the bootloader at the END of memory, where it interferes less with a normal application (which will assume that IT is at the beginning of memory.) So these chips have fuse bits that tell the chip just how much space at the end of memory is used by the bootloader (its size), AND there is an additional fuse bit that says "start at the beginning of the bootloader instead of at the address indicated by the reset vector" (which is at the beginning of memory.) This makes both writing the bootloader easier, AND using it is much easier. (You can implement a bootloader for a system that lacks this feature, but it gets complicated figuring out where the user's application starts, or you have to change the compilation to hard-wire that.)

Thanks for all the help you guys. :wink:

After a bit of research this is what I think I need to do.

To upload sketches to atmega8 with no bootloader, modify the high fuse in the board.txt.
It is now at 0xca (with bootloader activated) and I should change it to 0xcb to turn the bootloader off.

Is that right?

And for the atmega328p.......from 0xde to 0xdf.......right?

hexskrew:
When dealing with avr microcontrollers you have what are called switches that are just codes that do certain things to the chip to either help it operate in certain ways, lock people from trying to reflash the chip or to try to pull code from the chip, or make it skip things, and etc.

Lock people from trying to pull code from the chip.......interesting! I need to look into that.

As far as modifying boards.txt to unlock and ignore the bootloader, I will leave that answer to westfw because I am really not sure if that is correct or not and i am not on my computer with the ide to find out.

On locking (all the flash) on the chip, it is used by manufacturers to deter people from removing the chip from whatever product it's in and either wiping it and using it as a multipurpose chip (like we use it for) or pulling their closed source code for hacking.

and either wiping it and using it as a multipurpose chip (like we use it for)

No matter how the fuses are set, using a high-voltage programmer an AVR processor can always be erased.

Oh yeah, this is true. But it's just a slight deterant from doing so. Most people who are not that big into electronics wouldn't know how to unlock it. Tell you what though, it's good to have a HVP handi anyways, cause if you ever do accidentally lock yourself out of a chip (or do something like select the wrong oscillator type), you can always fix it :slight_smile:

On locking (all the flash) on the chip, it is used by manufacturers to deter people from removing the chip from whatever product it's in and either wiping it and using it as a multipurpose chip (like we use it for) or pulling their closed source code for hacking.

The main purpose would be to prevent reading the (proprietary) binary code and using it to flash innumerable copies (piracy.)

OK lest say I take the board.txt section you gave me for a optiboot for a atmega8.

The high fuses (this is where I activate/deactivate the bootloader, I think?) is 0xdc. The deactivate the bootloader I should change it to 0xdd....right?

The low fuses (this is where I chose between external 16mhz or internal 8mhz, I think?) is 0xbf. To use the chips internal clock I should change it to ???? I'm a bit confused with this one.

The bootloader uses the Lock bits:
To unlock bootloader for the Atmega8, it's 0xFF
To lock bootloader for the Atmega8, it's 0x0F

The oscillator and brownout detection uses the Low bits.
And the bootflash size, and misc. other stuff uses the High bits.