Write to flash with boot_page_write, seems like nothing gets written?

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I'm confused about writing to flash and have made a little test program (the boot_program_page is copy/paste from http://www.nongnu.org/avr-libc/u... ). My plan was to "simply" write the first flash page to some randomly selected character, and take a peek in the memory that it really got written. Which it unfortunately doesn't. Have I missed something obvious or am I doing something totally wrong?

 

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;
}

int main(void)
{
        uint8_t flash_buffer[SPM_PAGESIZE];

	for(unsigned int i = 0; i < SPM_PAGESIZE; i++){
		flash_buffer[i] = 'a';
	}
	boot_program_page(0, flash_buffer);
	while(1)
	    ;
}

I've added .text=0x3800 to the FLASH segment to place the code in the bootloader section, and set BOOTSZ=4096W_7000 in Avr Studio. Using an Atmega644P.

When pausing after stepping to the while-loop I open "memory 1" with ALT+6 and still see 0xFF for all bytes in the flash except in the bootloader section

When reading out the flash to file everything also is 0xFF except in the bootloader section.

I thought I would see the first 256 bytes from address 0 filled with 'a'? What am I doing wrong? (Using a JTAGICE3, jtag mode)

 

Thanks for any help! :)

/D

This topic has a solution.
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've added .text=0x3800 to the FLASH segment to place the code in the bootloader section...

Aren't addresses in bytes in GCC?  Byte address 14000 isn't in the bootloader section.  Hmmm--bootloader >>word<< address of 0x3800 wouldn't be in the bootloader area of a '644, would it? From "26.8.16 Atmel ATmega644A/ATmega644PA Boot Loader parameters" it would be 0x7nnn word address.  (Isn't there a hint in "BOOTSZ=4096W_7000"?)

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for you reply, but I don't think that's the problem in my case -> Avr Studio automatically translates addresses, so my linker gets: -section-start=.text=0x7000 (which seems correct to me, the boot loader is 0x7000 - 0x7FFF with BOOTSZ=4096W_7000)

 

I can run and step through the code in the debugger, but after executing the

boot_program_page(0, flash_buffer);

I thought the first page of flash (prog 0x0000 -> 256 bytes in avr studio memory debug, am I correct?) would contain 'a', but it still contains 0xff.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You were correct! I got confused by the automatic translation in Avr Studio and word vs. byte addresses. Setting the toolchain->AVR/GNU linker->Memory Settings->Flash segment .text=0x7000 solved the problem. Thanks!