[SOLVED]Reading/Writing data in NVM

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

Hello There,

 

I am using ATSAMD10C14A and wants to store data for persistency in NV Memory.

 

Since I am new to Smart Processors, I would appreciate if some one can points me to the right document to understand how nvm works.

 

I see that it has 16KB of Flash size, 256 pages with 64bytes per page.

 

Datasheet says that the base address for NVMCTRL is ox41004000, is this the NVM Base address? ( I guess not)

For writing data, can I write a single byte in a given page? Is the sytax for that is as shown below or does it require some sequence of commands to be followed?

 

byte_location = page(n*4)+0;     //for writing first byte in the page, =0 for first byte in first page

NVM_BASE_ADDR + byte_location = 0x55;

 

How do I identify if my NVRAM location is never written? basically I want to check if my mcu is first time powered up? I can do this by writing some pattern on first boot but just curious

 

Thanks in advance!

 

/SPanara

This topic has a solution.
Last Edited: Tue. Nov 22, 2016 - 03:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would appreciate if some one could give me some pointers!!

 

/SPanara

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

"can I write a single byte in a given page" - good question, I would like to have a definitive answer to that too. Anyway, you probably want start with the at03265 application note that describes eeprom emulation.

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

What I understand is,

 

for ATSAMD10C14A,

NVM Memory starts at 0x000000

It has total 16KB of memory so I THINK total memory address space is (0x000000 to 0x 0x00004000)

 

16KB ==> 256 Pages * 64 (bytes /pages)

 

Total Rows = 256/4 = 64.

 

- Operations are recommended to be 16bit or 32bit

 

- For reading the values, I guess individual locations between the address space can be read directly  (pls correct me if I am wrong)

 

- For writing data, first page has to be erased (erase command is per row i.e 4 pages at a time).

  write the 64byte in to page buffer and then issue the write command.

 

Here, where does page buffer residing? is it any of my array of 64Byte, if so what is the command to configure the page buffer address?

 

Thanks in advance!

 

/SPanara

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

Are you familiar with ASF? Even if choose to write your own code at the register level (as I do), you still could use ASF as an example.

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

I am not much familier with ASF However I used Atmel Start and added Flash driver to access the NVM Memory.

I could see it added .c and .h files related to NVM added to solution.

For ATSAMD10C14A the page size is 64bytes so I created a buffer of 64bytes and called flash_write.

I see that it has created page_buffer at location 0x000000 and updates using that.
If I read the memory immediately after write, I get the values I wrote but,

When I try to see the flash memory using debugger, I dont see the values getting updated to the memory.

Also, If I restart the mpu and try to just read, it gives me garbage values

- Can someone help me confirm the memory layout for NVM for ATSAMD10C14A, where does exactly the NVM memory starts?

- Is the one page memory at 0x00000000 is reserved for page_buffer?

 

Following is the code snippet ( it will not compile as I have not copied the full code)

 

- For flash_write function, I am writing data for first page so the second Argument I am passing is page number (as per my understanding)

 

void test_nvm()
{
	volatile uint16_t nvmp = NVMCTRL->PARAM.bit.NVMP;

	volatile uint8_t page_size = NVMCTRL->PARAM.bit.PSZ;

	uint64_t user_row = 0x804000;		//user row
	uint64_t calib_row = 0x806020;		//calib row
//	erase_row(0);
	uint8_t page_data[64];
	
	uint8_t read_data[64];
#if 1	//write
	for (int i=0; i<64; i++)
	{
		page_data[i] = 65;
	}
	
	flash_write(&FLASH_0, 0x00, page_data, 64);
#endif	//write
	
	flash_read(&FLASH_0, 0x00, read_data, 64);
	
}


int main(void)
{
	system_init();

	/* Initializes MCU, drivers and middleware */
#if 1	//nvm testing
	test_nvm();
#endif
}

 

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

What is flash_write? Is it yours or from Atmel Start? If it is yours, then I suggest that you start with a working example, be it Atmel Start or ASF.

NVM memory is basically your main flash memory, i.e., the same memory where you program is located. Therefore, you definitely don't want to writing anything at FLASH_0.

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

Yes, flash_write is Atmel Start routine.

 

However I am now able to write and read it back.

 

The problem was I that I was overwriting my program data and next time it was overwritten by debugger while launching the program.

Also, I was not aware that this is the same memory where my program is located.

 

It works.

 

Thanks for your help and suggestions!!

 

Cheers!!

/SP

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

Hi sureshpanara,

 

I am dealing with a problem similar to the subject of your post of last november, that is reading and writing from/to the NVM of SAMD10D14A.

I see that you found a solution but I'm not able to implement the same since I can't find the flash_write and flash_read routines from Atmel Start.

 

Can you please help me?

 

Thanks in advance

 

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

Hi sureshpanara

 

I am struggling with the same problem. Would you mind to send me your code? br