Problem with AVR109 bootloader on ATMEGA1280

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've got the AVR109 Bootloader source code from somewhere and I intend to use it on ATMEGA1280. 

I've compiled the source using IAR and made necessary changes in "defines.h" but I'm not sure about some values like "PAGESIZE" and "APP_END"and "LARGE_MEMORY" and so on. 

Anyway I managed to build the project and I was able to communicate to the bootloader through AVRDUDE just fine. I'm using UART1 and can send and or receive data correctly. 

But apparently the program can not verify the written code in the flash after erasing and writing the flash. 

 

I got the source from here : http://www.atmel.com/dyn/resources/prod_documents/avr109.zip

In IAR folder there is 3 different projects (a project for ATMEGA128 and a project named Modified_for_Butterfly and the last one is named ATmega2560). So I chose ATmega2560 and made necessary changes for ATMEGA1280. I'm not sure if I did the right thing. 

 

This is the command I ran: 

avrdude.exe -c avr109 -p m1280 -P COM1 -b 9600 -e -U flash:w:"D:\Test_Application\Debug\Exe\main.hex":i 

 

And here is the log : 

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 

Connecting to programmer: .
Found programmer: Id = "AVRBOOT"; type = S
    Software Version = 1.5; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x44

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude.exe: Device signature = 0x1e9703
avrdude.exe: erasing chip
avrdude.exe: reading input file "D:\Test_Application\Debug\Exe\main.hex"
avrdude.exe: writing flash (692 bytes):

Writing | ################################################## | 100% 0.88s

avrdude.exe: 692 bytes of flash written
avrdude.exe: verifying flash memory against D:\Test_Application\Debug\Exe\main.hex:
avrdude.exe: load data flash data from input file D:\Test_Application\Debug\Exe\main.hex:
avrdude.exe: input file D:\Test_Application\Debug\Exe\main.hex contains 692 bytes
avrdude.exe: reading on-chip flash data:

Reading | ################################################## | 100% 0.86s

avrdude.exe: verifying ...
avrdude.exe: verification error, first mismatch at byte 0x0002
             0xc3 != 0x72
avrdude.exe: verification error; content mismatch

avrdude.exe done.  Thank you.

 

I don't know what is wrong. Maybe there is something wrong with some defines in "defines.h" file. For example I've set SIGNATURE_BYTE correctly according to ATMEGA1280 datasheet but I didn't know what to set for PARTCODE cause I couldn't find anything so I set it to 0x44 which is for ATMEGA128 . 

There is a preprocessor.xls in the source which contains necessary values for some ATMEGA chips but not ATMEGA1280 .

 

Could you please help me out here or please give me a full working source for AVR109 bootloader ? 

Last Edited: Sat. Sep 17, 2016 - 10:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys does anybody have any ideas why I'm getting such error ? 

AVR109 was supposed to be much more simpler to get it to work but I tried everything and a couple of programs out there still getting nowhere. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Personally, I would just steal the Arduino bootloader used for MEGA1280 / MEGA2560 boards. You will be able to run Arduino sketches too!

If you are determined to write an avr109 bootloader, please ZIP up and attach your whole project.
Or post the diffs between your code and the original code in your link.
.
Note that if you make a problem 'reproducible' i.e. easily buildable, readers might fix it for you.
.
David.

Last Edited: Sun. Sep 18, 2016 - 07:32 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

Personally, I would just steal the Arduino bootloader used for MEGA1280 / MEGA2560 boards. You will be able to run Arduino sketches too!

 

+1 what David said.

 

Just because you use an Arduino bootloader doesn't mean that you must use Arduino IDE to write the application programs for it.

 

You can use Atmel Studio (or IAR) to create your application programs and use avrdude to download the firmware to it using the Arduino bootloader.

 

 

mostafanfs wrote:

In IAR folder there is 3 different projects (a project for ATMEGA128 and a project named Modified_for_Butterfly and the last one is named ATmega2560).

So I chose ATmega2560.

 

Isn't the ATmega128 the same Flash size as the ATmega1280?

Why don't you try using that one since it would probably have the same "PAGESIZE" and "APP_END"and "?????_MEMORY".

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
Personally, I would just steal the Arduino bootloader used for MEGA1280 / MEGA2560 boards. You will be able to run Arduino sketches too! If you are determined to write an avr109 bootloader, please ZIP up and attach your whole project. Or post the diffs between your code and the original code in your link. . Note that if you make a problem 'reproducible' i.e. easily buildable, readers might fix it for you. . David.

 

Yeah that would be a good idea to use Arduino bootloader. I don't insist on anything. I'm just looking for my problem to be solved no matter how. I just didn't want to use the IDE but it's not that much of a problem now and I can use the IDE. Cause I have never used a Arduino and I'm not planning to. I wrote my applications in CodeVisionAVR. 

 

Could you point me to some valid and good code ? 

 

I'm sorry I didn't your last sentence. What do you mean by reproducible ? 

Last Edited: Sun. Sep 18, 2016 - 09:26 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Chuck99 wrote:

Isn't the ATmega128 the same Flash size as the ATmega1280?

Why don't you try using that one since it would probably have the same "PAGESIZE" and "APP_END"and "?????_MEMORY".

 

Well actually I did. I used the defines for ATMEGA128. But didn't solve the problem. 

 

I want a open source bootloader so I would be able to change the code cause the controller shares the UART with some camera and I have to disable the camera somehow. 

Well for IDE, AVRDUDE would be just fine. Even Arduino IDE could be used. Like I said I'm just not into Arduino that much and I thought my board should be some sort of a Arduino board. But now you're saying that it doesn't have to be. It's good. But I use UART1 on ATMEGA1280 so I figured maybe that is a problem and it may not be compatible with a Arduino board. These are why I had doubts with a Arduino bootloader. 

 

So if you know a working source I would be more than happy to see a link. Or I just upload my AVR109 source to continue working on AVR109. 

Last Edited: Sun. Sep 18, 2016 - 09:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What I meant was:   Provide all the information so that a reader can reproduce your problem i.e.

Software e.g. Complete AS7 project

Hardware e.g. schematic / photo / drawing of your wiring.

 

If something is interesting,  you would be surprised what effort might be made to help you.

 

Most readers can build an AS7 project.  Many can build full-size Codevision projects.   Most can build Arduino projects in the regular Arduino IDE.

 

If you are "porting" a proven project from one Compiler or target to another,   I would like a link to the original proven project rather than just your hacked code.

 

If you make it easy, people may make an effort.   If information is like "getting blood out of a stone",   they just ignore you.    Just look at some of the monster threads on this site.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok. I see. 

This is my code. This is the original code and I just made some changes like set Baud Rate to 9600, made ATMEGA1280 changes and so on. 

It is for IAR AVR. 

Right know it can recognize Device Signature ID, Erase device, but not sure about writing cause it fails when it comes to Verifying. This is why it is so frustrating.

For the Schematic it is not a big deal. The Atmega1280 is connected to PC using serial cable and a MAX232.  

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well I tried to get a Arduino bootloader to work but no success at all. actually I don't know what they are. 

I got this: https://github.com/nickgammon/arduino_sketches  and couldn't realize which one is which. there are some .ino files (that I suppose you call Sketch) included

I'm not sure I'm in the right path. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You go to the Arduino website, you download the Arduino IDE, within the installation you now have pre-built bootloaders and their source.  Go play. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One way to burn the Arduino Bootloader into an ATmega1280 is to download and install the Arduino IDE.

 

Start the Arduino IDE, select the Tools tab, and set the following items:

Board: "Arduino/Genuino Mega or Mega 2560"

Processor: "ATmega1280"

Programmer: <Select the ISP programmer you are using from list>

 

Now just click "Burn Bootloader" and the appropriate one should be downloaded to your uC.

 

 

Edit: Here is the list of ISP programmers:

Last Edited: Sun. Sep 18, 2016 - 11:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well I don't have access to the board right now and I'll give it a try the first thing tomorrow but I'm sort of unsure. 

As I said before I'm not using an Arduino board and I used UART1 in MEGA1280 but I'm not sure if a "Arduino/Genuino board" has done the same. Maybe they used another port. I don't know I haven't checked. Or other settings like the XTAL frequency for one. So you see what I'm talking about here. 

That's why I was unsure from the first place. Cause this is a custom board that I designed in a pretty large scale and I can not do this sort of modification. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The board choice is fairly immaterial - it's just making sure the right entry in Arduino's boards.txt (with fuse settings and name of bootloader .hex file etc) gets selected during the "burn .hex" process. It's not saying your own circuit has to be a clone of the name board choice. (though the clock will want to be the same).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mostafanfs wrote:

As I said before I'm not using an Arduino board and I used UART1 in MEGA1280 but I'm not sure if a "Arduino/Genuino board" has done the same. 

 

The Arduino Mega (ATmega1280) uses USART0 to talk to the USB Virstual Serial (FT232RL).  So the Arduino Boot Loader will be looking at USART0.

 

Edit: The Arduino Mega schematic (pdf)

Last Edited: Sun. Sep 18, 2016 - 09:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Chuck99 wrote:

mostafanfs wrote:

As I said before I'm not using an Arduino board and I used UART1 in MEGA1280 but I'm not sure if a "Arduino/Genuino board" has done the same. 

 

The Arduino Mega (ATmega1280) uses USART0 to talk to the USB Virstual Serial (FT232RL).  So the Arduino Boot Loader will be looking at USART0.

 

Edit: The Arduino Mega schematic (pdf)

Well where is the source of this bootloader you're talking about located ? Couldn't I just change it somehow to get it to work with UART1 ? I mean there should be a way to do this if it is a open source bootloader. And for the PC side you said its possible to work with AVRDUDE if this is a problem for Arduino IDE . You know what I'm talking about.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually I just found a bootloader directory in where Arduino is installed and there are some makefiles but I don't know which bootloader to use and how to compile them. Maybe I could modify the source and make a suitable hex file to work with avrdude . What do you say ?

Last Edited: Mon. Sep 19, 2016 - 03:10 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think this is the correct bootloader to use for the ATmega1280:

  C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\stk500v2

 

The source code in that directory is for multiple uCs - I'm not sure how to specify the ATmega1280.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Chuck99 wrote:

I think this is the correct bootloader to use for the ATmega1280:

  C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\stk500v2

 

The source code in that directory is for multiple uCs - I'm not sure how to specify the ATmega1280.

 

 

Well I have installed WinAVR-20100110 and have its path in system variable and able to run avr-gcc

But when I execute make command in that folder I get errors : 

 

C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\stk500v2>make
      0 [main] sh 7540 proc_subproc: Couldn't duplicate my handle<0x118> for pid 6056, Win32 error 5
    268 [main] sh 7540 sync_with_child: child 6056(0x1F0) died before initialization with status code 0xC0000142
    332 [main] sh 7540 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

-------- begin --------
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Compiling: stk500boot.c
avr-gcc -c -mmcu=atmega1280 -I. -gdwarf-2 -DF_CPU=16000000UL  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-jump-tables -Wall -Wstrict-prototypes -Wa,-adhlns=stk500boot.lst  -std=gnu99 -D_MEGA_BOARD_ -MD -MP -MF .dep/stk500boot.o.d stk500boot.c -o stk500boot.o 
stk500boot.c:2119: fatal error: opening dependency file .dep/stk500boot.o.d: No such file or directory
compilation terminated.
make: *** [stk500boot.o] Error 1

Is there some specific dependency or what ? 

Do I have to use avr-gcc included in Arduino or WinAVR is fine ? 

Could you please help me figure this out ? 

 

What are those lines before -------- begin --------  ?!      (I'm not a stranger with makefiles and make command cause I have worked in linux with all sort of gcc compilers. I'm just not much into Windows when it comes to work with terminal and make command)

 

EDIT: Forget it. I managed to compile it in Ubuntu. Now I have to check it out see if it's working. I'll get back to you. 

Last Edited: Mon. Sep 19, 2016 - 05:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I modified the source (stk500boot.c and the makefile) and changed F_CPU, Baud Rate, Enabling or Disabling some features in the code like I don't need LED blinking and I need Serial Debug at first to check my connection by sending stk500 from board to PC. Everything works. Connection is OK. I got stk500 string from board at power-up and then there is no problem with the Frequency or Baud Rate or connections and things like that. 

I even query device part number using avrdude and it does recognize the controller as ATmega1280. 

And this is my CMD for programming a sample hex file: 

avrdude -c stk500v2 -p m1280 -P COM1 -b 9600 -v -U flash:w:"D:\HNA\BootLoader_Controller\Test_Application\Debug\Exe\main.hex":a 

 

But it does not do the programming and it says something like this : 

avrdude.exe: Version 6.1, compiled on Mar 13 2014 at 00:09:49
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2014 Joerg Wunsch

             System wide configuration file is "C:\Program Files (x86)\AVRDUDESS\avrdude.conf"

             Using Port                    : COM1
             Using Programmer              : stk500v2
             Overriding Baud Rate          : 9600
             AVR Part                      : ATmega1280
             Chip Erase delay              : 9000 us
             PAGEL                         : PD7
             BS2                           : PA0
             RESET disposition             : dedicated
             RETRY pulse                   : SCK
             serial program mode           : yes
             parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             ByteDelay                     : 0
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               eeprom        65    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
               flash         65    10   256    0 yes    131072  256    512  4500  4500 0x00 0x00
               lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
               signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

             Programmer Type : STK500V2
             Description     : Atmel STK500 Version 2.x firmware
             Programmer Model: AVRISP
             Hardware Version: 15
             Firmware Version Master : 2.10
             Vtarget         : 0.0 V
             SCK period      : 0.1 us

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.10s

avrdude.exe: Device signature = 0x1e9703
avrdude.exe: NOTE: "flash" memory has been specified, an erase cycle will be performed
             To disable this feature, specify the -D option.
avrdude.exe: erasing chip
avrdude.exe: stk500v2_command(): command failed

avrdude.exe done.  Thank you.

You guys have any idea ?

Why would this happen ?

 

I swear this is like the fifth bootloader I'm working on and still no success. I'm going out of my mind.  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mostafanfs wrote:
You guys have any idea ? Why would this happen ?
Add up to four lots of -v to the arvdude command line. the more you add the more verbose it gets. When set to very verbose it will show all the bytes that are being sent and received. If you have a copy of Atmel's PDF that documents the STK500v2 protocol to hand you will be able to see what commands/responses are expected and compare to what is being sent. It does seem very odd that the read of signature worked but that the following conversation did not.

 

(Of course there are millions of Arduinos out there and 100's of ,000's are based on mega1280 or, more likely mega2560 so this bootloader is widely tested and there's little doubt that when built and used correctly it is error free)

 

BTW contact user "westfw" here on Freaks. He is the current maintainer of the Arduino bootloader and will know all about this!

 

Oh and while :a should work as the format on -U I would set it to :i as there is no doubt it's going to be Intel Hex.

 

Final thought - get a $5 mega2560 based Arduino Mega from ebay. That way you will have a known working copy of this bootloader. You can then compare how it behaves to how your modified copy behaves and see what is different (easier still if you have a logic analyser).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mostafanfs wrote:

And this is my CMD for programming a sample hex file: 

avrdude -c stk500v2 -p m1280 -P COM1 -b 9600 -v -U flash:w:"D:\HNA\BootLoader_Controller\Test_Application\Debug\Exe\main.hex":a 

 

But it does not do the programming

 

Since you installed the Arduino IDE, why not try using it to download a program (sketch)?

 

 

Edit: 

 

Example command line for avrdude programming arduino nano
---------------------------------------------------------

  avrdude -c arduino -b 57600 -P COM16 -p atmega328p -vv -U flash:w:E:\Test_1.hex:i

 

 

Last Edited: Mon. Sep 19, 2016 - 10:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Chuck99 wrote:

mostafanfs wrote:

And this is my CMD for programming a sample hex file: 

avrdude -c stk500v2 -p m1280 -P COM1 -b 9600 -v -U flash:w:"D:\HNA\BootLoader_Controller\Test_Application\Debug\Exe\main.hex":a 

 

But it does not do the programming

 

Since you installed the Arduino IDE, why not try using it to download a program (sketch)?

 

 

Edit: 

 

Example command line for avrdude programming arduino nano
---------------------------------------------------------

  avrdude -c arduino -b 57600 -P COM16 -p atmega328p -vv -U flash:w:E:\Test_1.hex:i

 

 

 

Cause the IDE expects the bootloader to be on UART0 I guess. While it is not. I tried something but it didn't work.

You mean using its terminal or something?

Besides what differences does that make? After all they all use AVRDUDE. And the command is the same.  

I'm not using an Arduino nano or a sketch or any Arduino for that matter. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mostafanfs wrote:

Cause the IDE expects the bootloader to be on UART0 I guess. While it is not. I tried something but it didn't work.

You mean using its terminal or something?

Besides what differences does that make? After all they all use AVRDUDE. And the command is the same.  

I'm not using an Arduino nano or a sketch or any Arduino for that matter. 

 

Cause the IDE expects the bootloader to be on UART0 I guess. While it is not.

 When downloading application programs to the board, the IDE doesn't know or care which UART the uC is using - the bootloader does, which is why you modified the bootloader source.

 

My suggestion was that you use the Arduino IDE to write a small sketch to blink a led, build it and download it using the IDE which would talk to the bootloader that is now in your uC.

See my post #11, where it shows under "Tools" where you specify the Board and Processor.  The IDE will think you are using the Arduino Mega with the ATmega1280 uC.

 

Once you have specified the board and processor, Verify/Compile the Sketch and then Upload it to your board.

 

I don't know if this will work, but if it does then that would be a step in the right direction.

 

After all they all use AVRDUDE. And the command is the same.  

 No, they're not.  Your command used "-c stk500v2" whereas the example I showed used "-c arduino".