mega2560 custom PCB - Bootloader and Fusebits

hi !!

i have build a custom board for mega2560 with reference of arduino original files :

i want to upload my sketch using UNO to mega2560, is it necessary to write a bootloader to mega2560?

at the first step must write bootloader and second write flash data? or reverse?

whats the fusebit configs for mega2560?

im using this library for making arduino-ISP :

Gammon Forum Electronics - github - arduino_sketches-master.zip (141 KB)

The bootloader is needed for programming via serial line. If you want upload sketch with UNO (Arduino as ISP, I suppose)
then the bootloader is not needed. Remember that each uploading is preceded by chip erase so anything was in the flash, it will be lost. Fuses depend on your needs. Search for ATmega fuse calculator on web. It could be useful for you.

Fuses used for the mega2560 board are in the boards.txt file - however, if you are not using a bootloader, those fusebits are not correct, and IIRC on the 256k boards, you can't just use the same fuses without a bootloader like you can on smaller chips - not certain about that.

I think MCUdude's MegaCore has support for atmega2560 without bootloader (in this case, you still need to do "burn bootloader" to set the fusebits, even with a non-bootloader configuration selected - fusebits are only ever set by the Arduino IDE when you do "burn bootloader" - unfortunately the IDE calls the option "burn bootloader" not "burn bootloader & set fuses", which is what it does)

If using bootloader, you upload that first, then use bootloader to write the sketch.

If not using bootloader, you select a no-bootloader configuration, and do burn bootloader (just to set fuses - or you can set the fuses with avrdude from command line) and then upload sketch via ISP.

i use my hex file generated by arduino IDE and with sd-card and uno program it with ICSP headers
but my program not running (flash verifying is ok and hex is uploaded)

DrAzzy:
If using bootloader, you upload that first, then use bootloader to write the sketch.

If not using bootloader, you select a no-bootloader configuration, and do burn bootloader (just to set fuses - or you can set the fuses with avrdude from command line) and then upload sketch via ISP.

i think select the uno board in IDE (programmed with arduino as ISP) and select "arduino as ISP" for programmer then connect the mega2560 board ICSP to UNO and program sketch to mega2560 ??? is it true? or need to change board to mega2560 before upload using programmer ?

Budvar10:
The bootloader is needed for programming via serial line. If you want upload sketch with UNO (Arduino as ISP, I suppose)
then the bootloader is not needed. Remember that each uploading is preceded by chip erase so anything was in the flash, it will be lost. Fuses depend on your needs. Search for ATmega fuse calculator on web. It could be useful for you.

yes i use ICSP headers (not rx/tx) and i want to program with "Arduino as ISP" but i cant connect/configure board in IDE correctly and its not uploaded so i decided to use the HEX files and upload it with hex uploader !

When you do upload-using-programmer, you must have the board you are uploading to selected (you'll get an error when you try to upload if not!)

but - if not using the bootloader on a '2560, like I said, I think you get screwed by the large flash size when the fuses are set to use a bootloader. On a board with less than 128k of flash (64k words), if there's no bootloader, but fuses tell it to use one, it jumps to the bootloader, slides along the empty flash for howevermany bytes are in the bootloader section (0xFFFF, ie, empty flash, is a no-op) and then wraps around to the start of the flash, hits the reset vector, and jumps to the application. But, unless I'm mistaken (I don't use the '2560 for anything - I don't know what you people do to waste that much flash!), on 256k+ AVR's, it will wrap around to 0x10000, not 0x00000, so it will sit there chasing itself in circles in the top half of the flash.

If that theory is correct (like I said, I don't use the '2560, so I'm not certain this is how it works, but I seem to remember it having come up before, and it seems very plausible considering how the large flash is handled on AVRs), just use MegaCore instead of the Arduino Mega2560 official board def - GitHub - MCUdude/MegaCore: Arduino hardware package for ATmega64, ATmega128, ATmega165, ATmega169, ATmega325, ATmega329, ATmega640, ATmega645, ATmega649, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega3250, ATmega3290, ATmega6450, ATmega6490, AT90CAN32, AT90CAN64 and AT90CAN128 - pick the 2560, set to no bootloader, and "burn bootloader", then upload with that board selected (you don't even need to tell it to "upload using programmer" if you have the '2560 with "no bootloader" option selected)

okay !!!
im try to use megacore lib. ....

just use MegaCore instead of the Arduino Mega2560 official board def - GitHub - MCUdude/MegaCore: Arduino hardware package for ATmega64, ATmega128, ATmega165, ATmega169, ATmega325, ATmega329, ATmega640, ATmega645, ATmega649, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega3250, ATmega3290, ATmega6450, ATmega6490, AT90CAN32, AT90CAN64 and AT90CAN128 - pick the 2560, set to no bootloader, and "burn bootloader", then upload with that board selected (you don't even need to tell it to "upload using programmer" if you have the '2560 with "no bootloader" option selected)

thanks !

hi again !

i used megacore and its working but today i cant use it more !
this is the error from arduino ide :

Sketch uses 68856 bytes (26%) of program storage space. Maximum is 262144 bytes.
Global variables use 1150 bytes (14%) of dynamic memory, leaving 7042 bytes for local variables. Maximum is 8192 bytes.
avrdude: Yikes! Invalid device signature.
** Double check connections and try again, or use -F to override**
** this check.**
An error occurred while uploading the sketch

now how can i use -F with ide ?
or how can i programe (.ino files) with command line (linux) and using avrdude commands ?

now how can i use -F with ide ?

The -F is not useful in your situation. Focus to the 1st part of this sentence instead.

or how can i programe (.ino files) with command line (linux) and using avrdude commands ?

You can run avrdude in Terminal. You can take a command from the top of log as inspiration for parameters.

Machine code is needed for upload into MCU. The .ino file is a source code. It have to be compiled so it create the .hex file which can be used with avrdude.