[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-libc-dev] Problem writing to flash - atmega644
From: |
Patrick Mahoney |
Subject: |
RE: [avr-libc-dev] Problem writing to flash - atmega644 |
Date: |
Tue, 21 Aug 2007 10:42:16 -0400 |
Good morning Brian,
Thanks for getting back to me.
It is true that my code snippet was iterating over a page number whereas
the required parameter is the full address.
But still... Erasing the page containing address 0 should blank the
first 256 bytes in memory, which contain the reset vector and the
interrupt vector table. The processor should NOT be functional after
such an operation.
Also, I tried using your code snippet as is and didn't work either. I
even tried:
for (i=0; i<FLASH_PROGRAM_SIZE; i++)
boot_program_page(i);
... without anymore success.
As I mentioned yesterday, doing a boot_page_erase_safe(i) within the
previous loop gets executed way too fast. The spm instruction must be
aborting early for some reason...
Best regards,
Pat
-----Original Message-----
From: address@hidden
[mailto:address@hidden On
Behalf Of Brian Sidebotham
Sent: August 21, 2007 10:09 AM
To: Patrick Mahoney
Cc: address@hidden
Subject: Re: [avr-libc-dev] Problem writing to flash - atmega644
> 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.
_______________________________________________
AVR-libc-dev mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-libc-dev