0

I am trying to write a customized boot-loader for ATmega AVR's. I write a code, and it work perfectly in small AVR's like ATmega32A and ATmega8A. But when i want to use it in ATmega128A, it writes nothing in flash segment. I'm sure Fuses are correct, ATmega103 mode is disabled, and the program starts at boot section, but it does nothing.. Before calling function "boot_program_page" I set PORTC and turn some LED's on, and after that I cleared PORTC and LED's goes off. so the code in executing completely too. The function I am using is an example provided in avr/boot.h. It should write some data ( 0x00 actually ) in page 0 of flash memory.. here is my code :

#define F_CPU 8000000UL

#include <inttypes.h>
#include <avr/io.h>
#include <avr/boot.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>

void boot_program_page (uint32_t page, uint8_t *buf);


int main(void)
{
    uint8_t data[SPM_PAGESIZE] = {0};
    uint32_t page = 0;

    DDRC = 255;
    PORTC = 255;

    page *= (uint32_t)SPM_PAGESIZE;
    boot_program_page(page,data);

    _delay_ms(1000);
    PORTC = 0;
    while (1)
    {
    }
}

void 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<SPM_PAGESIZE; i+=2)
    {
        // Set up little-endian word.

        uint16_t w = *buf++;
        w += (*buf++) << 8;

        boot_page_fill (page + i, w);
    }

    boot_page_write (page);     // Store buffer in flash page.
    boot_spm_busy_wait();       // Wait until the memory is written.

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

    boot_rww_enable ();

    // Re-enable interrupts (if they were ever enabled).

    SREG = sreg;
}
  • Its not "a code", just "code". Code is a mass noun and cannot combine with an indefinite article. – Rev Jan 28 '16 at 10:06
  • 1
    Thank you, English is not my first language so I made these mistakes.. but any help with my problem ? – Ali Ghasemi Jan 28 '16 at 11:05
  • No problem, just wanted to point it out because it is a very common mistake. Wasn't meant to sound harsh ;) Regarding your question: "but it does nothing" is not very helpful. How did you verify what happened? Is the program executed at all? Is just the flash write failing? You probably need to be more specific for someone to help you. – Rev Jan 28 '16 at 11:21

0 Answers0