this is my first post so please forgive me for my mistakes (if any). I was looking at a tutorial on how to use the SPM, I hardly found two tutorials on this. one was more complicated so I went with this. here the author uses a ATmega 16 but I use atmega328p. The problem is the function
boot_page_fill(address, data)
uses a byte address right ?. but the author says that he is trying with the address 0x0100 (ie 256), he is not mentioning whether its byte address or word address. but in this diagram
the author uses word address right ? because the ending addres 0x1FFF is word address. In the program he just directly uses the address 256.
#define F_CPU 8000000 #include <avr/io.h> #include <util/delay.h> #include <avr/boot.h> #include <inttypes.h> #include <avr/interrupt.h> #include <avr/pgmspace.h> #include <stdio.h> int main ( void ) { uint16_t i; uint8_t A [ 300 ]; uint8_t sreg; uint32_t page = 256; unsigned char *buf = A; //------------------------------------------------------------------------------- DDRD |= 0x80; PORTD |= 0x7F; //led on. bootloader ok. _delay_ms ( 2000 ); PORTD |= 0x80; //turn off led now. We hope the application will turn on the LED again _delay_ms ( 2000 ); //-------------------------------------------------------------------------------- // storing the bytes from ith location of flash memory to ith variable of array A// for ( i = 0; i < 300; i ++ ) A [ i ] = pgm_read_byte ( i ); // storing the bytes from ith location of flash memory to ith variable of array A// //================================= SPM ==========================================// sreg = SREG; // store the current interrupt status in sreg cli(); // clear interrupts eeprom_busy_wait (); // wait till the eeprom is free. boot_page_erase (page); // erase the page in the flash which we are about to write into boot_spm_busy_wait (); // Wait until the memory is erased. //---- fill the bytes of the page into temperory page buffer before wriying into flash ----// for (i=0; i<SPM_PAGESIZE; i+=2) { //convert the bytes to little-endian word// uint16_t w = *buf++; w += (*buf++) << 8; //convert the bytes to little-endian word// boot_page_fill (page + i, w); // fill the temperory page buffer byte by byte } //---- fill the bytes of the page into temperory page buffer before wriying into flash ----// //--------------------------------------------------------------------// boot_page_write (page); // Store buffer in flash page. //--------------------------------------------------------------------// boot_spm_busy_wait(); // Wait until the memory is written. boot_rww_enable (); // Reenable RWW-section again SREG = sreg; // Re-enable interrupts //================================= SPM ==========================================// asm ( "jmp 0x0100" ); // jump to application programmed at 0x0100 }
my question is dont we need to convert to byte address ? or the author is wrong somewhere ?