Society of Robots - Robot Forum

Software => Software => Topic started by: sonictj on July 05, 2009, 01:00:29 PM

Title: atmega640 bootloader troubles
Post by: sonictj on July 05, 2009, 01:00:29 PM
I'm developing a product that is similar to the arduino mega.  I'm considering using the atmega640 to save on cost, but I'm having trouble tweaking the arduino Mega bootloader for the 640.  It seems simple due to the chips being nearly identical, but I've run into problems.  1 I found there is an instruction ELPM not available on the 640. This seems to be preventing the bootloader code from being a simple port via a few defines.  I wondering if anyone could explain what portion of the bootloader code I have to adjust in order to make the 640 work.  I believe that the elpm instruction deals with extended memory.

I think this is the problem code

Code: [Select]
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)  || defined(__AVR_ATmega640__) || defined(__AVR_ATmega1281__)
RAMPZ = address_high;
#endif
address.word = address.word << 1;   //address * 2 -> byte location
/* if ((length.byte[0] & 0x01) == 0x01) length.word++; //Even up an odd number of bytes */
if ((length.byte[0] & 0x01)) length.word++; //Even up an odd number of bytes
cli(); //Disable interrupts, just to be sure

I don't think the RAMPZ register is available in the atmega640 which is why I think the elpm instruction does not exist.  I only generally know what going on here any help would be greatly appreciated.
Title: Re: atmega640 bootloader troubles
Post by: billhowl on July 05, 2009, 07:19:08 PM
You may check on the sanguino which using atmega644 which also about the same as atmega640


http://sanguino.cc/ (http://sanguino.cc/)
http://sanguino.googlecode.com/svn/trunk/code/bootloaders/ADABootLoader/ (http://sanguino.googlecode.com/svn/trunk/code/bootloaders/ADABootLoader/)
Title: Re: atmega640 bootloader troubles
Post by: sonictj on July 05, 2009, 07:50:48 PM
Thanks for the suggestion.  I've actually tried hacking that boot loader already.  I still wasn't able to get it to work. 

Quote
You may check on the sanguino which using atmega644 which also about the same as atmega640
Really?  The 640 and 644 are from completely different families.  How are they similar?
Title: Re: atmega640 bootloader troubles
Post by: sonictj on July 05, 2009, 11:56:54 PM
how do I determine the address for LDSECTION.  I can't find it anywhere in the datasheet.
Title: Re: atmega640 bootloader troubles
Post by: billhowl on July 06, 2009, 12:32:52 AM
ref to datasheet page 323
Note that the RAMPZ register is only implemented when the program space is larger than 64K bytes.

So atmega640 only 64K, you can don't care the RAMPZ section of code.


For LDSECTION
ref to datasheet page 329
at 1024 words boot size you can find start address 0x7C00 words, for bytes will be 0xF800
Title: Re: atmega640 bootloader troubles
Post by: sonictj on July 06, 2009, 02:58:30 AM
Thanks,  I now have my atmega640 bootloader functioning. Your also right about the rampz.  I figured that out just about an hour ago reading over the whole bootloader program.
Title: Re: atmega640 bootloader troubles
Post by: billhowl on July 06, 2009, 03:44:56 AM
Congratulations that you can have your atmega640 bootloader functioning, mind sharing the code?
Title: Re: atmega640 bootloader troubles
Post by: sonictj on July 06, 2009, 09:30:40 AM
Here is the software. its real ghetto at the moment. I'll clean it up before I make my product. for instance I think the hex is labeled as 168.  Its actually for the 640 I just didn't know how to change the make file to fix that.