SAMD21 Internal flash read and write not retaining values

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

Hi,

 

I was using the atmel start example for reading and writing to flash as illustrated below:

 

The problem im seeing is that when I power off the system and power back on again the data written to addess 0x3200 is no longer retained.

 

I can see the memory being written to via the memory view window in Atmel studio (currently using the SAMD21 Xplained Pro) via USB.

 

Im sorry if I have isunderstood the example and the data sheet but as far as I was aware the SAMD21 between the regions 0x00000000 to 0x00040000 is available and non-volatile.

 

Can anyone please help?

 

#include <peripheral_clk_config.h>
#include <utils.h>
#include <hal_init.h>
#include <hpl_gclk_base.h>
#include <hpl_pm_base.h>

struct flash_descriptor FLASH_0;

void FLASH_0_CLOCK_init(void)
{
	_pm_enable_bus_clock(PM_BUS_APBB, NVMCTRL);
}

void FLASH_0_init(void)
{
	FLASH_0_CLOCK_init();
	flash_init(&FLASH_0, NVMCTRL);
}

void system_init(void)
{
	init_mcu();

	FLASH_0_init();
}

void FLASH_0_example(void)
{
	uint32_t page_size;
	uint16_t i;

	/* Init source data */
	page_size = flash_get_page_size(&FLASH_0);

	for (i = 0; i < page_size; i++) {
		src_data[i] = i;
	}

	/* Write data to flash */
	flash_write(&FLASH_0, 0x3200, src_data, page_size);

	/* Read data from flash */
	flash_read(&FLASH_0, 0x3200, chk_data, page_size);
}

 

This topic has a solution.
Last Edited: Wed. Mar 30, 2022 - 11:21 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you programming with erase as part of running the debugger maybe?

/Lars

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

Hi Lars, you were correct. I needed to adjust the memory region in the linker to prevent this from being over written during programming.

 

Many thanks for you help it is much appreciated

Last Edited: Wed. Mar 30, 2022 - 11:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just ran into a similar issue with the data flash on the SAML10.  Which file do I hack up to keep the debugger from overwriting the segment from 0x00400000 to 0x004007ff?  I tried selecting the project setting for the debugger to only erase program code, but when I did that it started failing to program while still well inside program code space.  The failure was at address 0x00002214 aka 8724 decimal - nb. the compiler reports the code size is 8744 bytes, and I've got it configured for a SAML10E14A with 16k of program flash that lives at 0x00000000 and 2k of data flash that lives at 0x00400000.  When I removed some writes to volatile debug variables, reducing the code size to 8696, the same error occurred though the message stated the problem was at 0x000021e4 (8676 decimal) instead.

 

I'm using Atmel Studio/Microchip Studio v7.0.2524 fwiw.  Any help that can get me on the right track would be appreciated, thanks!

Ask me how TI made me write my own asm routines, like an animal!

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

Not sure whats going on here but just note that while you just need restart you will get away with no programming at all for your debugging session.

/Lars