avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] Problem writing to flash - atmega644


From: Brian Sidebotham
Subject: Re: [avr-libc-dev] Problem writing to flash - atmega644
Date: Tue, 21 Aug 2007 15:08:37 +0100
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)

I am using the boot_program_page routine taken 'verbatim' from the
avrlibc docs:
http://www.nongnu.org/avr-libc/user-manual/group__avr__boot.html#g7249d1
2e06789cd306583abf7def8176

I would expect the following code to blank all of flash. Yet it doesn't
happen, since the routine completes and returns as if nothing had
happened. The application runs perfectly after reset/reboot.

--------------------

void  __attribute__((section (".bootloader"))) CopyMemory(void){

    int i;
    char buffer[ 256 ];

    memset( buffer , '\0' , 256 );
    for( i=0 ; i<256 ; i++ ){
        boot_program_page( i , buffer );
    }

I struck this same problem when I first used these functions, and I think there is a case for adding a note in the documentation for this example.

If you look carefully at the definition of boot_program_page(uint32_t page, uint8_t *buf) you'll notice that page is of type uint32_t - clue number one!

The second clue is the boot_page_erase(page); line in the example of boot_program_page, because the definition of boot_page_erase(...) is
#define boot_page_erase(address) __boot_page_erase_normal(address)

The important thing is that where page has been used as a variable name in the example, it should really be address, or page_address. You do not pass the page number to the function, but an address contained within the page.

instead, something like the following

int i;
#define FLASH_PROGRAM_SIZE 32768
...
for (i=0; i<FLASH_PROGRAM_SIZE; i+= SPM_PAGESIZE)
   boot_program_page(i);
...

Best Regards,

Brian Sidebotham.






reply via email to

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