ATMEGA64 Bootloader

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

I am trying to write a bootloader for the ATMEGA64. I have also tried other peoples bootloaders but i am having alot of trouble getting it to write to the flash. I created a simple program that writes 0x00 to the first page of flash. It does nothing! when i read the flash the first page is is filled with 0xFF.

I have the bootloader sitting at 0x7800 and the bootloader size fuses blowen correctly. I have none of the lock bits program.

Can anyone help

	u16 i = 0;

    // move interrupt vector table to boot loader area
    myIVSELREG = _BV(IVCE);
    myIVSELREG = _BV(IVSEL);

	cli();

	boot_page_erase(0);  // do a page erase
	boot_spm_busy_wait();  // wait for page erase done

	for(i=0;i
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's a routine I know works that's kind of similar to yours:
void

#ifdef ENABLE_SPM
BOOTLOADER_SECTION
#endif
boot_program_page (
	uint32_t page,
	uint8_t *buf
){
    uint16_t i;
    uint8_t sreg;

    // Disable interrupts.

    sreg = SREG;
    cli();

    eeprom_busy_wait ();

    boot_page_erase (page);
    boot_spm_busy_wait ();      // Wait until the memory is erased.

    for (i=0; i

To be honest, apart from the fact that mine is designed to write ANY 'page' I'm having difficulty spotting what you have done differently.

Cliff

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

Thanks Cliff but i still dont know whats going on. I just did a quick little prrogram that uses your function to program 0's to the first page of the flash:

int main(void)
{
	u08 buffer[SPM_PAGESIZE];
	u16 i = 0;

    // move interrupt vector table to boot loader area
    MCUCR = _BV(IVCE);
    MCUCR= _BV(IVSEL);

	for(i=0;i

This is programed at 0x7800 on the atmega64. I confirmed this was correct in the hex file. I am running a 8M cloock and have the folling fuses:

BOOTsZ1 & BOOTRST = Programed
SPIEN = Programmed

Every other fuse is unprogrammed. Could there be anything else really simple i could be missing

Thanks

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

UPDATE: I just tried it again on a ATMEGA32. AHHHHHH still not working. This time i had BOOTSZ1, 0 and RST programmed for a 2K bootloader section. Programmed at 3800.

Im going insane!! ive been at this for over 24 hours. I cant take it much longer ;-)

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

In my case it runs on a Mega16 but is not a separate bootloader but just SPM routines that are called from the app section at 0000 so I don't have any fuses set apart from the default for BOOTSZ and the BOOTLOADER_SECTION routines (i.e. those in .bootloader) are positioned using the following in my Makefile:

BOOTLOAD = 0x3800

LDFLAGS += -Wl,--section-start=.bootloader=$(BOOTLOAD)

Note that the address is given as a BYTE not a word address in this!

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

Cheers. All my errors was from the Byte address and word address problems.... Geez that caused me alot of pain.