Change Bootloader to Serial1 for Atmega1280

Long story short I designed a board around the Atmega1280. Everything works perfectly with the Arduino environment save for one thing... I connected my USB to Serial1 instead of Serial0 so I can't upload code via USB (only with my AVRISPmkII). So... I need to modify the bootloader.

If someone has (or can make) a bootloader identical to the Arduino Mega with the exception of this small change I would really appreciate it.

Alternatively - if someone is willing to hold my hand I am eager to figure out how to mod the bootloader myself.

Any help is appreciated.

thanks,
-methods

P.S. Modifying the hardware is unfortunately not a viable option... my PCB is totally optimized and I would have to destroy it to swap Serial0/Serial1

Are you using hardware/arduino/bootloaders/atmega/ATmegaBoot_168_atmega1280.hex ?
The source for that (ATmegaBOOT_168.c) has a piece:

#if defined __AVR_ATmega1280__
	/* the mega1280 chip has four serial ports ... we could eventually use any of them, or not? */
	/* however, we don't wanna confuse people, to avoid making a mess, we will stick to RXD0, TXD0 */
	bootuart = 1;
#endif

It looks to me like if you change that to "bootuart = 2" and rebuild, you should get what you want...

Thanks!!!

Ok, here is exactly what I did (for the next guy)

Windows 7

  1. Try to run "make" from the command prompt, if it wont run add these to your PATH
    C:\arduino-0022\hardware\tools\avr\bin
    C:\arduino-0022\hardware\tools\avr\utils\bin

  2. Navigate to
    C:\arduino-0022\hardware\arduino\bootloaders\atmega

  3. delete the old hex file, make the change suggested above, and run "make mega" from cmd

Just as easy as pie with a little help.... I have not tested the change yet but that is the easy part XD

-methods

Hmmmm.... Maybe not that simple.

Poking around I found some other code.... This part seems simple enough and follows from above.

	/* initialize UART(s) depending on CPU defined */
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
	if(bootuart == 1) {
		UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
		UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
		UCSR0A = 0x00;
		UCSR0C = 0x06;
		UCSR0B = _BV(TXEN0)|_BV(RXEN0);
	}
	if(bootuart == 2) {
		UBRR1L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
		UBRR1H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
		UCSR1A = 0x00;
		UCSR1C = 0x06;
		UCSR1B = _BV(TXEN1)|_BV(RXEN1);

If bootuart == 2 you are golden. BUT -> there is some hard coding (poor coding) later on....

#if defined __AVR_ATmega1280__
	/* Enable internal pull-up resistor on pin D0 (RX), in order
	to supress line noise that prevents the bootloader from
	timing out (DAM: 20070509) */
	/* feature added to the Arduino Mega --DC: 080930 */
	DDRE &= ~_BV(PINE0);
	PORTE |= _BV(PINE0);
#endif

Looks like I am going to be spending some time digging on this one to find and check every instance.....

I will report back when it works.

-methods

Ok - I thought that would take a while but I got it.

Official success<<<<<<< :stuck_out_tongue:

Two lines of code must be changed
DDRx sets the direction of the port
PINxx is a const

Change the port from E to D on both
Change the pin from E0 to D2 on both
Apply the change with standard ~&|

#if defined __AVR_ATmega1280__
	/* Enable internal pull-up resistor on pin D0 (RX), in order
	to supress line noise that prevents the bootloader from
	timing out (DAM: 20070509) */
	/* feature added to the Arduino Mega --DC: 080930 */
	//DDRE &= ~_BV(PINE0);  
	//PORTE |= _BV(PINE0);
	DDRD &= ~_BV(PIND2);
	PORTD |= _BV(PIND2);
#endif

Soooo glad I learned assembly back in the day. Who said it would never come in handy???

thanks again for the help - and your welcome to whoever finds this in the future.

-methods

You should make your patch compatible with the "if (bootuart == 1)" code so that it will work in either case...