Go Down

Topic: How to create new optiboot hex file for ATmega328p using Atmel Studio (Read 812 times) previous topic - next topic


Sep 03, 2014, 01:14 am Last Edit: Sep 03, 2014, 01:16 am by drew_startech Reason: 1

I am currently trying to use AVR studio to flash the optiboot code to my 328p on my Arduino Uno. I know that the optiboot folder contains the hex file optiboot_atmega328.hex and that I could go to device program inside Atmel studio and just upload that hex file to the chip, but I want to compile and generate a new hex file. Has anyone created a new project and added optiboot.c plus the necessary header files to generate a new hex file? I have questions on what parameters need to be set in the compiler to create a successful bootloader hex file. The only thing that I have changed is the symbols, such as F_CPU, BAUD_RATE, and LED_START_FLASHES. The project compiles and I am able to flash it to the 328p. I can also confirm that the led start flashes are working. The problem is when trying to upload a application from the arduino IDE I keep getting a verification error. So I must be missing something I need to set in Atmel Studio. Anyone have any ideas, or done this before? Any help would be greatly appreciated!


Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter


Do you have the link options set up to properly locate the bootloader at the end of FLASH?


Do you have the link options set up to properly locate the bootloader at the end of FLASH?

I'm guessing that I don't. How do I go about doing that?

Thanks for your reply!


I want to compile and generate a new hex file

I've only created sketches, never a bootloader.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Coding Badly


Why do you not want to use the makefile?

Well eventually I want to flash an altered version of the optiboot to a different chip, then the 328p. I already have that altered version up on Atmel Studio so I figured it would be easier to flash it from there to test it instead adding another chip to the makefile. But due to some other issues, I'm adding it to the makefile now and will try it that way :).


I'm guessing that I don't [have the link options set up].  How do I go about doing that?

Beats me.  I find the way that AS spreads out options and actions across dozens of buttons, menus, and panels, to be close to incomprehensible.   I'm a CLI dinosaur - at least if I have to go searching through man pages, I can actually search...
And while AS may have tutorials and features to aid the beginning developer, aiding the importation of legacy-tool-based code doesn't seem to be very high on the priority list.

Try this:
  Use the "Project Properties" menu to open up the project properties panel.
  Select the "Toolchain" sub-panel.
    Select the "General" sub-option under the AVR/GNU Linker option.
      check the -nostartfiles checkbox
      check the -nodefaultlibs checkbox
      check the -nostdlib checkbox
   Select the "Optimization" sub-option
     un-check the "gc-section" checkbox
  Select the "Memory Settings" sub-option
   click on "add-item" box next to "FLASH sgement"
     add ".text=0x7e00"
   click on "add-item" box next to "FLASH sgement"
     add ".version=0x7ffe"

Or it might be easier to do the "Use external Makefile" option under "Build"; but a lot of the Makefile options are not really compatible with the way that AS thinks of a "project"  ("one project builds for multiple different devices?  The horror!")

I'll do a little more experimenting to see if I can import the files to an AS project and actually get it to compile...


add ".text=0x7e00"
     add ".version=0x7ffe"

Sigh.  Of course not.  It the Atmel world, code addresses are WORD address, so you have to divide everything by two.
add ".text=0x3f00"
   click on "add-item" box next to "FLASH sgement"
     add ".version=0x3fff"

You'll also need to add the "relax" option to compile and link commands, or the resulting bootloader won't fit.
I've attached a .cproj file that I think contains the options necessary to get optiboot to compile to the same binary (for m328p) as it does with "make atmega328"...


Thanks & and really very much useful information.!
i have got optiboot.c and other all required header files and with the help of above information provided by Westfw, i have created a project in atmel studio 6.2. i am facing following difficulties.

1> still at the end of burning the generated .hex file, it says  the code will not  fit to the target device.

i have one ready made .hex file for optiboot bootloader, and that works fine with the atmelstudio 6.2  to burn into my atmega328p chip. but not  the compiled one.

please suggest the remedy....
thanks in advance

P.S-- PLEASE may i let to know, the  exact fuse bits settings for burning the boot loader?
thanks again.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131