avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Problems programming flash


From: Martin Bammer
Subject: [avr-gcc-list] Problems programming flash
Date: Sun, 6 Feb 2005 20:22:41 +0100
User-agent: KMail/1.7.1

Hi list!

I'm trying to write a bootloader for the ATMega128 in C.
Everything works fine, but the programming of the flash.
I've taken the subroutine from the avr-libc page which is listed below.
The version of the avr-libc I'm using is 1.0.5 (Debian Package).
What is wrong with the subroutine below?

uint8_t flash_wr_page(uint32_t page, uint8_t *buf)
{
    uint16_t i, w;
    uint8_t  sreg, ret = 0;

    sreg = SREG;
    cli();
    eeprom_busy_wait();
    boot_page_erase(page);
    boot_spm_busy_wait();
    for (i = 0; i < SPM_PAGESIZE; i += 2) {
        // Set up little-endian word.
        w = buf[i] | (buf[i + 1] << 8);
        boot_page_fill(page + i, i);
    }
    boot_page_write(page);     // Store buffer in flash page.
    boot_spm_busy_wait();

    // Reenable RWW-section again. We need this if we want to jump back
    // to the application after bootloading.
    boot_rww_enable();

    for (i = 0; i < SPM_PAGESIZE; i += 2)
        if (pgm_read_byte_far(page + i) != buf[i]) {
            ret = 1;
            break;
        }

    // Re-enable interrupts (if they were ever enabled).
    SREG = sreg;
    return ret;
}

Cheers, Martin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]