Can't upload program to custom ATmega2560 with Arduino Bootloader

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

I have built a custom ATmega2560 with some extra features and program it via Arduino ISP. When I burn the bootloader on it I manage to upload a new program via TX, RX but when I try to upload a new one I get an error and can't program it until I burn the bootloader again. The bootloader that I use is from the Arduino IDE. Can anyone help?

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

BOOTRST

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

What do you mean by BOOTRST? I see that BOOTRST is in the High fuse and when I read the high fuse before and after burning the bootloader it has the same value which is 0xD8 which means that the BOOTRST bit is enabled (0 is written to it).

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

OK, just checking.

 

What can occur is this (if BOOTRST is not activated):

 

You start with a blank AVR, it is full of 0xFFFF (erased flash, an opcode like SBRS R13,7 which in most cases behaves like NOP).

You program the bootloader.

You reset the AVR. There is no app at 0x000 but the lack of BOOTRST means it starts to execute at 0x000 anyway.

Because the device is 0xFFFF all the way up to the base of the bootloader it "NOPs" its way all the way up til it hits the bootloader code.

So the bootloader runs this time.

You then deliver some app code using the bootloader that appears to be "active".

That app code puts a second program down at 0x0000.

You now reset the AVR and at the next start it finds code at 0x0000 so only ever executes the delivered app.

It never gets back to the bootloader as there is no an app "in the way".

 

With BOOTRST active it will jump to the start of the bootloader at every power on

Many times it will decide to do nothing and run the app anyway

Sometimes you provide the trigger that the bootloader is looking for so it starts app replacement instead.

 

All that is why I said "BOOTRST". But just checking!

 

(and yes, it's much easier to type on a PC keyboard than on a mobile phone that tends to lead to "brief" answers!)

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

I think that I understand what you say but forgive me that I don't really understand how to solve my problem. I see that BOOTRST with 0xD8 is active so the program should always go to the bootloader at a power on but the thing is that after uploading the first application with the bootloader burned it works fine, and the second program can't be uploaded. Could it be something with the BLB bits?

 

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

I was just guessing. Looks like my hunch was wrong.

 

I put your D8 value into:

 

 

which confirms that D8 has BOOTRST active for 2560 - so that does not explain what's going on.

 

I think you need to use ISP to read out the entire 256K from the chip and look at what is located where inside. Are the programmed sections only where you planned for them to be?

 

Forget about stuff like lock bits (that will just "get in the way") until you have everything else working.

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

For the programmed sections I see that the BOOTSZ0 & BOOTSZ1 bits are enabled in my bootloader so their value is '00'. When I read the high fuse from an Arduino Mega these bits are disabled (high fuse is 0xD6 instead of 0xD8 that i read)

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

Oh right. Getting BOOTSZ wrong would have pretty much the same effect as I described in #4

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

i changed both the BOOTSZ bits and the BOOTRST bit but I still can't load the second program to the microcontroller. Is there anything else that I can do to solve this problem?

 

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

Look at the bootloader for the Arduino Mega2560 board.

 

The boards.txt entry shows you the hex file, fuse values, lock value.

 

I suggest that you just run the Arduino IDE and get it to "Burn Bootloader" for you.

 

David.

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

vamoirid wrote:
I have built a custom ATmega2560
Does that include the option to trigger a reset over the serial connection (with DTR)? If not, are you aware that you have to do the reset and the start of the programming within a short timeframe? 

Stefan Ernst

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

david.prentice wrote:

Look at the bootloader for the Arduino Mega2560 board.

 

The boards.txt entry shows you the hex file, fuse values, lock value.

 

I suggest that you just run the Arduino IDE and get it to "Burn Bootloader" for you.

 

David.

 

I already did that. The boards.txt file says: lfuse=0xFF, hfuse=0xD8, efuse=0xFD, unlock_bits=0x3F, lock_bits=0x0F. The way that I burn the bootloader is through the Arduino IDE I have never done it in another way.

 

sternst wrote:

vamoirid wrote:
I have built a custom ATmega2560
Does that include the option to trigger a reset over the serial connection (with DTR)? If not, are you aware that you have to do the reset and the start of the programming within a short timeframe? 

 

yeah the DTR line connects directly with the reset line without the 0.1uF cap. My custom ATmega2560 board has all the peripherals of the arduino mega (except these for the serial communication with the 16u2) and an interface for CAN protocol.

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

Well,  you should replace the direct DTR link with a 100nF as God had originally intended.

 

It is always wise to copy a proven design.   Then cripple it in stages.

 

David.

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

I think that I don't need to add this capacitor because it is already on the Arduino board. I mean that the microcontroller in the Arduino mega which uploads the program to the main microcontroller (atmega2560) has already the 100nF capacitor so i don't need to add another one in my board.

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

We have no idea what your hardware is like.   You have never posted a schematic.

 

Or even explained what you are trying to do.

 

I am guessing that you have a CAN project.   The AT90CAN128 has a CAN controller.   Many ARM chips have a CAN controller.    Many PIC chips have a CAN controller.

 

Or you can use an external CAN chip.

 

David.

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

vamoirid wrote:
I mean that the microcontroller in the Arduino mega which uploads the program to the main microcontroller (atmega2560) has already the 100nF capacitor
I have the impression that you are talking about the ISP uploading of the bootloader here. I was talking about the serial connection to your own board used to upload the application. Does that  connection include the ability to reset the Mega2560 on your board?

Stefan Ernst

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

Well maybe I am misunderstood. My custom ATmega2560 board can be programed with an arduino with 2 ways. Either via arduino as isp or by burning a bootloader to my custom board and then upload it again with arduino via tx rx and rst lines. The problem with the second method is that after the first upload of the program with the serial communication I can't upload a program with the serial interface. I need to burn again a bootloader with arduinoisp and then upload another program.

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

vamoirid wrote:
upload it again with arduino via tx rx and rst lines.
That's the part we need more information about. What and how is RST connected to? What role does the Arduino play? Does it do the upload by itself, or is it merely a USB-Serial adapter?

 

vamoirid wrote:
The problem with the second method is that after the first upload of the program with the serial communication I can't upload a program with the serial interface. I need to burn again a bootloader with arduinoisp and then upload another program.

And a possible reason for that symptoms is that the reset being part of the upload don't work (or if you do the reset by hand that the timing is wrong).

Stefan Ernst