NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Loading the "Bootloader"

November 18, 2010
by Ralphxyz
Ralphxyz's Avatar

Starting at the very beginning how does one load the bootloader? Does/do the fuses need to be set or is this done in loading the bootloader .hex file. What IDE is used on the pc?

I have a ATmel AVR Dragon

Programming Interfaces
 - In-System Programming
 - High Voltage Serial Programming
 - Parallel Programming
 - JTAG Programming

Emulation Interfaces
 - JTAG
 - debugWIRE

The AVR Dragon cost $49.00 and is fully supported by ATmel so any new devices will be supported.

I need to start at the very basics, I have loaded the bootloader.hex on to a ATmega168P mcu using AVRStudio, but it does not "appear" to work. I see the two black bars when in programming mode but if I load a project (tempsensor) the LCD is blank in run mode. So that is why I am asking for a start from the beginning hopefully step by step.

Thanks,

Ralph

November 18, 2010
by Ralphxyz
Ralphxyz's Avatar

In conjunction with loading the bootloader how would I set the Extended Fuse Bytes?

I have some mcu's which I have reported here in the forum as always staying in Programming Mode, that is the black bars always appear on the LCD when in the run mode. The only difference from the fuses_mike.txt document is the Extended Fuse Bytes so I need to set the Extended Fuse Bytes to 0x00 (00000000) to see if that solves the problem.

Thanks, Ralph

November 19, 2010
by Ralphxyz
Ralphxyz's Avatar

RE: Extended Fuse Byte there is no way using AVRStudio to set the Extended Fuse Bytes to 0x00 as illustrated in the fuses_mike.txt document.

EFUSE = 0x00
0   -
0   -
0   -
0   -
0   -
0   BOOTSZ1 (1024 word boot size)
0   BOOTSZ0     ""
0   BOOTRST (jump to bootloader)

In looking at the ATmega168 specsheet I see Extended Fuse Bytes Bit 7 - 3 are not used and default to 1 (not programmed) therefore having a value of 0xF8 satisfies (should satisfy) Mike's intent. The 0x00 listing is misleading and does not appear to be valid. Possible using avrdude one could do a setting of 0x00 but it does not appear to be the ATmel method.

Of course this is all my interpretation so is completely lacking any validation, but so far that is all I have and will proceed from here with what I think (which is always dangerous, much better to proceed on what one knows than thinks, thoughts tend to change).

Thanks to the support at AVRFreaks.net I am starting to understand this.

Ralph

November 19, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Ralph,

We are not very familiar with AVRStudio and its capabilities since we tend to run things on Linux. The fuse bits according to the datasheet default to 1 (unprogrammed), so I'm not too surprised that it doesn't give you a way to 0 (program) bits that are unused. 0xF8 will have the exact same effect. Glad you are making progress.

Humberto

November 19, 2010
by Ralphxyz
Ralphxyz's Avatar

Ok I have actually made measurable progress!!

Once I had the correct (or close to correct) FUSE settings than the bootloader loaded as expected and I am able to load and run programs.

The mcus I had been having a problem with would not go into "Programming Mode". They are now working. I set the correct fuse settings and voila they work. These were working mcus that just would not run a program loaded when I would switch to RUN mode, I got the two black bars no matter the switch position or USB cable.

Now I need to play around with loading a program without the Bootloader being install, I am supposed to be able to do that I believe.

I am sure getting a good education on FUSE settings, I still need to understand the clock settings but at least now my mcus are accepting programs and running with them.

Ralph

May 18, 2011
by amartinez
amartinez's Avatar

Ralph, I was looking at some threads and found yours. Perfect for my needs which will resolve the com speed issue and bootloader.

Since you seem to have gone through this please help me out. Anyone else, please feel free to jump in as well. Anticipating any response...

I'm now at the bootloader level because I need more chips and I need the chips to talk at 9600 baud. I'm looking to use the STK500 dev kit from Atmel as a bootloader platform, it's all self contained and not that expensive.

You used AVR Studio. How did that work out for you? Do I need that software or can I connect and bootload using the AVR programmer software supplied by Nerdkits?

Once I change the com speed to 9600baud, can I still connect using the Nerdkits USB interface? My com settings to the Nerdkit are already at 9600baud but the chip communicates at 115K

About the com speed.... Here's the scenario.

In the bootloader168 folder, a part of the footloader.c program (seen hereunder) starting from line 109, the baud settings are seen, but I see that the UBBR is set to 8. Please correct me if I'm wrong but this is what I came up with.

I looked at the data sheet, page 175 has this formula for the baud setting BAUD = fOSC / 2(UBRRn + 1) where fOSC is the crystal frequency and UBRRn is the register. 7+1=8 so that's where on page 198 of the datasheet you get 7 under the U2XN=0 column for the 14.7MHz crystal to communicate at 115.2Kbps. So if I want this chip to communicate at 9600 baud, I would need to set the UBRRn to 95.

Is this what is referred to as a fuse setting?

/** init the hardware uart */
static inline void init_uart(void)
/*{{{*/ {

    /* set baud rate */ I would change the 8 to 95
    _UBRRH_UART0 = (uint8_t)(UART_UBRR >> 8);  /* high byte */
    _UBRRL_UART0 = (uint8_t)UART_UBRR;         /* low byte */

    /* set mode */
    _UCSRC_UART0 = UART_UCSRC;

    /* enable transmitter, receiver */
    _UCSRB_UART0 = _BV(_TXEN_UART0) | _BV(_RXEN_UART0);

Thanks again for any info you might have on this. My goal is to make these chips all talk at 9600 because I have another chip which cannot talk at 115Kbps

May 18, 2011
by Rick_S
Rick_S's Avatar

Firstly, if you want to load a bootloader onto a new chip, you will need a different programmer than was supplied with the NerdKit. See my Bootloader Installation Tutorial for more details on that.

Secondly, you don't need to replace the bootloader to communicate at 9600 baud. All you have to do is write your program to change the baud to whatever you need. How your program communicates with the outside world VS. how the bootloader communicates do not have to be the same and often aren't. In your program, you have full control of all external communications.

Rick

May 18, 2011
by amartinez
amartinez's Avatar

Rick, thanks for jumping in.

I have your excellent post but am trying to circumvent making my own programmer. By programmer I assume you mean hardware, not software.

Here is your quote from the post "Programming a bootloader on a micro-controller requires additional hardware that was not provided with your NerdKit." Unless I mis-read, I see no mention of additional software.

Your post mentioned the STK500 dev kit from Atmel. There's also one called the AVR Dragon by Atmel which Ralph used. By reading your post I was under the impression that the WIN_AVR software provided with the Nerdkit will interface with the hardware (programmer), that was one of my basic questions here.

Another basic question I had was on speed change connectivity. I thought I would kill 2 birds with one stone since I'm in need of bootloading chips that eventually communicate in 9600, why not do everything all at once?

For now I am trying to find some code to change the com speed to 9600 baud without using the bootloader as you mentioned above. Any help on this would be most appreciated.

Thanks again

Al

May 18, 2011
by Rick_S
Rick_S's Avatar

The serial port on your PC may default to 9600bps, but when talking with the your chip, it is at 115200bps. Changing the baud of your bootloader will cause longer program load times and require modification to your makefile to slow things down. Also, there is no real need to do this at all since you can communicate at any baud you choose to in your own program. The bootloader does not effect your ability to communicate at speeds different than it does.

WinAVR is a bundle of pre-configured programs. AVRdude is one of them. It is used to communicate to the chip via many different methods. One of which is the software bootloader installed on your micro. Others are hardware options that talk to the chip through either an SPI port or High Voltage. The AVR Dragon, STK-500, AVRISP MkII, USBASP, are hardware options for programming. They can be used to load bootloaders, change fuse settings, or just program the chip without a bootloader. They are not as foolproof though and if you don't know what you are doing (especially when playing with fuse settings) you can mess your chip up.

So to answer your question, Yes, you have the software needed to use hardware based programmers.

However, before I got into all that, I would recommend learning to program the chip to do what you want the way it is. There is no real reason to change the bootloader and doing so without having a good understanding of what you are doing could do more harm than good.

Rick

May 18, 2011
by Ralphxyz
Ralphxyz's Avatar

Al I'll just reinforce what Rick said:

You do not need to change the bootloader!!

To change the communication baud you change a register in the mcu.

Starts around page 195 Section 19 in the datasheet.

You can just search for baud to see all of the references.

You do not need a programmer which is too bad as I wish someone else had a Dragon or STK600 that I could commiserate with.

Ralph

May 18, 2011
by Noter
Noter's Avatar

Am I missing something here? Why do you need to have everything at 9600 baud?

May 18, 2011
by amartinez
amartinez's Avatar

Noter, I need 9600 baud to speak to another chip I purchased which does not take 115Kbps. Other posts of mine explain further but basically I'm trying to send character data to this chip is all. Just putting the 168 through its paces.

Rick, you convinced me not to change the bootloader at all. I now see the errors of my ways. I try to catch up in between work hours and days off. It's slow going but I'm getting it down thanks to all of you. Lots to absorb...

Ralph. You may have someone to commiserate with after all. I purchased the Dragon from Atmel. I just want to see what they have to offer is all. I may also purchase the STK500 just for kicks. I didn't see an SDK600 at Atmel's site. I already have several 168s waiting for a bootloader. So far so good. In learning I anticipate making mistakes, that's why they make fire extinguishers. :)

Al

May 18, 2011
by Ralphxyz
Ralphxyz's Avatar

Al that's great. Don't worry about getting a STK500 the Dragon will do everything you need.

The STK500 is the old primary Atmel programmer the STK600 is now the replacement.

Of course the STK600 has not yet (after two years) been documented where as the STK500 is extremely well documented.

You can get add on kit for the Dragon like the Dragon Rider

this essentially makes a STK500 out of the Dragon. Of course it will cost as much as a STK500 would maybe even more and you have to assemble it.

You have to solder the header pins and zif socket to the dragon PCB. Also you have to make up your own wiring harnesses.

Once you have the Dragon up and running it is very robust and does it's job well.

It does not come with a case so it is an exposed PCB board which caused problems with earlier versions. Apparently you were not supposed to touch it when it was powered up, it would short out and be ruined.

Atmel really wanted to make it as powerful as they could for the least amount of money. Which is what they did.

I am pleased with the Dragon but as I have said in the past it does have it's issues.

You can directly load the foodloader.hex bootloader using AVR Studio, so you'll want to down load that. There is a AVR Studio 5 beta

also.

Ralph

May 19, 2011
by Noter
Noter's Avatar

Since you have ISP programmer(s) you don't even need the bootloader. Don't use it and that way you can keep your Rx/Tx wired to the target chip all the time instead of disconnecting/connecting every time to load vs test.

May 19, 2011
by Ralphxyz
Ralphxyz's Avatar

Yes, Paul you are correct (as usual :-) but since I "normally" work on my Mac I have to fire up my Windows pc in order to use AVR Studio to load the .hex without the bootloader so it is just more convenient for me to load the bootloader onto the mcus. That way I can load new programs from my Mac Terminal.

Of course I also occasionally buy my mcu's from the Nerdkits store, with the preloaded bootloader, in order to further support Humberto and Mike. I might lose a couple of dollars but the support I have received from the Nerdkits guys has been priceless!!

Ralph

May 19, 2011
by Noter
Noter's Avatar

Do you use avrdude on the mac?

May 20, 2011
by Ralphxyz
Ralphxyz's Avatar

I believe so, but that shows you what I know.

This is from a Makefile so I'd say yes avrdude is used on the Mac:

AVRDUDEFLAGS= -c avr109 -p m328p -F -b 115200 -P /dev/cu.PL2303-0000101D # USB1

I quickly looked at the AVRDUDE documentation while reading Rick's great Bootloader Tutorial in the Nerdkit Library.

I could not get the USB to connect to the Dragon I do not know if there is a driver missing or what.

My Mac definitely does not like the Dragon, in fact it will not even pass the USB port off to Parallels (the OSX Virtual PC) to use with my virtual XP pc.

The AVRDUDE documentation is really interesting. I can see how to tell it to use the Dragon as the programming device and other programmers.

I only spent a little time playing around with AVRDUDE trying to get something to happen on the Mac I'll spend some more time on it one of these days.

Ralph

May 20, 2011
by amartinez
amartinez's Avatar

Ralph,

Many many thanks again for the info. I may have some questions for you once I get this up and running if you don't mind as I'm sure it will help others reading this in the future as well. I trust Atmel has documentation to aid me in getting it to work. Not having a case is not a problem, that's what they make cigar boxes for :). I line them with anti static foil taken from component bags over the years. It's not pretty, but very effective.

As for the AVR Studio 5. I was going to download the bootloader initially using the WIN-AVR app. It should be straight forward right? So far I haven't had issues with it. I use XP mainly on this experimental system here so I don't have to worry about compatibility issues. Do I really need AVR Studio 5 for the bootloader upload?

Noter, your post mentions I don't need a bootloader. I don't know enough yet but now that I see it's possible I will lean towards that way when I get the Dragon. I hope to post my findings once I do a few chips. I got a handful of 168s ready to load. I expected to fry the one I got from Nerdkits but it's still ticking.

I like the idea of getting them from Nerdkits in the future, it's a matter of a few dollars more but they will come all ready to program. Great idea and I'm all for supporting this awesome educational site. Although Humberto and Mike are younger than me, when I grow up I want to be just like them!

Thanks again for all your posts everyone

Al

May 20, 2011
by Ralphxyz
Ralphxyz's Avatar

Al you would use AVRDUDE to load the bootloader or other program .hex file using just the Dragon and XP.

You do not need to use AVR Studio for this. You might not ever specifically need AVR Studio. It's a personal choice

in how you want to get things done, there always are a number of methods to do anything.

Using AVR Studio you can load program .hex files in two or three easy steps so you can run a program without having the bootloader on the mcu saving I think 2k of memory. You can also do this from the command line using AVRDUDE!

It is all great learning, somethings like AVRDUDE are absolutely fascinating that someone (group of someones actually) could orchestrate such a neat application. I quickly read the AVRDUDE documentation and was really blown away.

It will be really good to have someone else with a Dragon. I have had issues with it like not being able to do ISP programming but the HVPP (High Voltage Parallel Programming) works so I have gotten a lot of use out of my Dragon.

I also purchased the Dragon Rider kit which essentially turns the Dragon into a STK500. I have not assembled the Dragon Rider kit so I just use the barebones Dragon.

Ralph

May 20, 2011
by Noter
Noter's Avatar

If you have a programmer, ISP or High Voltage, you can load any program on the chip. The bootloader is just a special little program that resides in high memory and will load another program in low memory using the usart serial interface thus eliminating the need for an ISP or High Voltage programmer. But since you are going to have a programmer, you can just load your programs with it instead of the bootloader.

I would not load AVR Studio as it is just that much more stuff to deal with and learn. Avrdude will work fine with your programmer on an XP system. I think there may be problems with drivers on the Mac that keep it from working and that is why Ralph goes back to his windows box to use the ISP/HV programmer. On his Mac the only way he can load is via the bootloader. But you won't have that problem on an XP system.

May 21, 2011
by Rick_S
Rick_S's Avatar

Quote: amartinez said


  • I line them with anti static foil taken from component bags over the years. It's not pretty, but very effective.

As long as your components do not touch the bags while in operation... Antistatic bags are conductive and can short out working circuitry.

Quote: amartinez said


  • Noter, your post mentions I don't need a bootloader. I don't know enough yet but now that I see it's possible I will lean towards that way when I get the Dragon.

Noter is correct on this one, however even though I have a couple of ISP programmers, I rarely use them. I breakdown and rebuild lot's of different small "see if I can make it work" type projects. An ISP programmer requires the connection of 5 wires to work (Reset, MOSI, MISO, SCK, GND) Where the bootloader serial connection is only 3 (RX, TX, GND) Add one more to either if you tie in VCC. So for me the physical connection is just simpler. But everyone has their preferences and either way works fine.

Quote: amartinez said


  • Although Humberto and Mike are younger than me, when I grow up I want to be just like them!

They are younger than many of us... I think that's one of the reasons this board stays so civilized. And like you, many of us have the utmost respect for them.

Quote: Noter said


  • I would not load AVR Studio as it is just that much more stuff to deal with and learn. Avrdude will work fine with your programmer on an XP system.

I agree completely with Noter. Avr Studio is not needed unless you want to throw even more confusion into your initial learning. Unless you want to learn AVR assembler... It's great for that. Otherwise, while you can build your C programs with it, the NK way is pretty easy the way it is.

Rick

May 21, 2011
by Ralphxyz
Ralphxyz's Avatar

Well one thing about AVR Studio is that there is a virtual Debugger!!

I have not figured how or if it works with a ATmega168 or ATmega328 but I have used it for another mcu (just to see if it worked).

Also the Dragon is "supposed " to be able to do live debugging, I assume in conjunction with AVR Studio.

I have not spent any time getting any of this to work.

I sure would love a debugger so one of these days I'll look into it.

You would think there would be an advantage to using all Atmel, or at least I thought so. That was why I bought the STK600 with it's various cards.

I think I must have $500.00 invested in it now and never use it. Turns out ATmel still heavily documents and references the STK500 but has not gotten around to fully documenting the STK600 or referencing one in their Application Notes.

The STK600 was released three years ago without documentation besides real basic stuff.

Ralph

May 21, 2011
by Noter
Noter's Avatar

I have only one isp programmer but I use it most of the time. Mainly because many of my projects require setting fuses and that can't be done with the bootloader. One reason is I like to use the internal 8mhz clock whenever possible to eliminate the need for an external crystal. Hooking up a couple of extra wires doesn't bother me. Another reason is that ISP is multi-drop and my programmer can be connected to 4 targets at once and program any of them without moving wires. This has been very handy for master/slave type projects.

May 21, 2011
by amartinez
amartinez's Avatar

Are you guys telling me that I can just plug in my brand new 168 from an electronics supply company and program the chip without a bootloader? If my proto board wasn't full of wires right now I would try it myself but I have to trace out a schematic of what I have before I disturb anything.

Ralph, I noticed the AVR Studio has a simulator, is that what I'm thinking? Since the chip is software driven that makes sense to me. That function alone would be worth the download! Have you used the simulator part? It's a shame you haven't been able to use the full system, hopefully I will be posting on the Dragon and the AVR Studio 5 soon. It's about a 600 meg download. OUCH! I looked at the videos on the Studio from the Atmel site and maybe previous versions of AVR Studios had other languages proprietary to its needs, but this one definitely does C according to the videos. It's free anyway, what the heck?

Rick, I should have said the grey antistatic plastic bags, they are not conductive. Foil is conductive, you are correct Sir! Bad choice of words on my part.

Thanks fellers

Al

May 21, 2011
by Noter
Noter's Avatar

You have to have an ISP programmer like the AVRISP but otherwise yes. With an ISP programmer you can also put the bootloader on your new chips if you prefer to use the bootloader for programming.

May 23, 2011
by amartinez
amartinez's Avatar

So the bootloader is optional. This raises more questions... I will have to do research on the use of a bootloader.

May 25, 2011
by Ralphxyz
Ralphxyz's Avatar

Not using the bootloader gives you 2k more of program space.

I am gong get back to using ISP again, I like the utility that Noter is expressing.

I had a BETA ISP programmer that worked great, I never have heard any mention of it since.

Ralph

May 27, 2011
by amartinez
amartinez's Avatar

Ralph, thanks for writing back.

2K more space? So what's the use of the bootloader? Is it a way of setting global variables? Not had time to research due to heavy work load but if you can help me out with this question I would appreciate it.

I just got the AVR Dragon in the mail. I have to solder the headers and the ZIF socket once I get them from the supply company, I found them on elexp.com. AVR Studio 5 is very extensive but I can see how it will be useful, specifically if I screw up the chip and need to do an HV... still have to learn about that too. I have some time with the holiday and all so in between Family stuff I'm going to "nerd out" on the Dragon.

I haven't tried the new chips I got in the mail yet because I'm waiting for another proto board to come in but once it does I'll try working with them without the bootloader...

Happy Memorial day All

May 27, 2011
by bretm
bretm's Avatar

The bootloader allows you to update the program on the chip without using a programmer, e.g. by just using a serial port. It's ideal if you're already connected to the PC anyway, for example.

May 27, 2011
by Noter
Noter's Avatar

The bootloader only lets you put a program on the chip and doesn't require any other type of programmer. However, the bootloader must be preloaded on the chip by someone with a regular ISP or high voltage programmer. And then it is also restricted to a particular clock/crystal frequency and baud rate to be programmed via the serial/usb line.

Another thing is you can't change fuse settings with a bootloader. Fuses are used for things like specifing the clock source and in some cases the rate, the size of a bootloader if present, startup time, and lock bits. You can find details on fuse settings in the datasheet. There are also several fuse calculator sites on the internet. Here's the one I typically use http://www.engbedded.com/fusecalc.

One of the fuse settings disables the reset pin which means the chip can no longer be programmed with an ISP programmer. That's when you'll need the high voltage programmer because it enables programming with 12v on the reset pin and works whether or not the reset pin has been disabled.

Your new dragon programmer should do anything and everything you will ever need when it comes to loading programs onto the chips.

May 28, 2011
by Ralphxyz
Ralphxyz's Avatar

Al, before you solder the headers and zif in place you might want to consider the Dragon Rider. It will add another $50-60.00 dollars but you will essentially end up with a STK500. You will have prewired buttons and LEDs plus there is a LCD option.

The advantage of the Dragon Rider is that you can run your program without having to move your mcu to a breadboard.

AVR Studio is really robust especially with the simulator for debug. I hope you learn how to use the debugger then you can help me :-).

That 2k more space could be important, if not critical for some applications.

Ralph

May 28, 2011
by bretm
bretm's Avatar

A bootloader does not restrict you to particular clock/crystal frequency. The Nerdkits bootloader does, and many others do, too, because they're easier to write that way. But a bootloader can communicate by any means/logic that it is designed to, and a bootloader can autodetect the communication rate if written to do so.

May 28, 2011
by Noter
Noter's Avatar

Yes, Bretm, that is correct. A bootloader doesn't necessarily have to restrict you to a particular baud rate or clock frequency or even use the usart for communication with the PC. But the bootloader that is part of the nerdkit as most others certainly does. Obviously I was refering to the bootloader that is provided with the nerdkit.

May 28, 2011
by Noter
Noter's Avatar

Another note on bootloaders - the maximum size allowed for the bootloader on the 168/328 is 2k but the bootloader that is provided with the nerdkit fits in only 1k. So it costs only 1k of flash to use the nerdkit bootloader.

June 14, 2011
by amartinez
amartinez's Avatar

Ralph, Too late, just got my ZIF and headers. That's ok, thanks anyway.

Here's the clincher, I've been busy at work and now I'm moving so I won't be in the forum for a while. We're still looking for a place. As for the bootloader info, all of your posts were extremely helpful, thank you.

Next time I post I will be sending packets from a new IP address.

Al

August 03, 2011
by kayrock
kayrock's Avatar

Hey ralph, are you now able to use your dragon with OSX? I just put together an adafruit USBtinyISP, but I can't get either of my mac's to recognize the usb device, ( perhaps I didn't put it together correctly... )

Post a Reply

Please log in to post a reply.

Did you know that you can connect digital calipers to a microcontroller? Learn more...