Write to Flash - atxmega256a3u

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

Hi,

I tried Atmel's code: AVR1316: Using the XMEGA Self-programming (http://www.atmel.com/images/AVR1316.zip)

on my atxmega256a3u device.

 

When I write it, it works well until the write command, and it doesn't enter to the success section:

int main(void)
{
	/* Assume success until proven otherwise. */
	bool success = true;

	/* Erase first page. */
	EraseAppTablePage(0);

	/* Load 100 bytes. */
	for (uint8_t i = 0; i < 100; i += 2) {
		uint8_t lowByte = 0xFF - i;
		uint8_t highByte = 0xFE - i;
		LoadAppTableWord(i, lowByte, highByte);
	}

	/* Write page. */
	WriteAppTablePage(0);

	/* Verify Flash contents. */
	for (uint8_t i = 0; i < 100; i++) {
		if (appTable(i) != (0xFF - i)) {
			success = 0;
			break;
		}
	}

	/*  If success, try with another method using load/read flash page function
	 *  and an erase-write of the page.
	 */
	if (success) {

		/* Fill up a test buffer with 512 bytes with other values. */
		for (uint16_t i = 0; i < FLASH_PAGE_SIZE; i++) {
			WriteBuffer[i] = (uint8_t) i;
		}

		/* Load the flashbuffer with the test buffer. */
		SP_LoadFlashPage(WriteBuffer);

		/* Do a Erase-Write of the page. */
		EraseWriteAppTablePage(1);

		/* Read a flashpage into the read buffer. */
		ReadFlashPage(ReadBuffer, 1);

		/* Verify Flash contents. */
		for (uint16_t i = 0; i < FLASH_PAGE_SIZE; i++) {
			if (ReadBuffer[i] != WriteBuffer[i]){
				success = 0;
				break;
			}
		}
	}
}

 

What can be the problem?

This topic has a solution.

Last Edited: Wed. Jan 6, 2016 - 07:34 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey,

It was my mistake, I didn't add in the Linker the argument:

-Wl,--section-start=.text=0x40000

To put it in the boot section. (BOOT_SECTION_START     (0x40000) )

 

More info about it is in the article: https://www.avrfreaks.net/sites/default/files/bootloader_faq.pdf