Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Pesticide
PostPosted: Mar 25, 2009 - 10:41 AM
Rookie


Joined: Mar 16, 2009
Posts: 43
Location: Switzerland

Hi,
Can somebody give me an example how to read and write the user page (flashc.c) of an AT32UC3A?

I do not understand how I can write data to the so called "page buffer" or how I can read from it.

Is the page buffer given or how can I create/address it correctly?

My try:
Code:
// Clear page buffer
flashc_clear_page_buffer();
// Write data to page buffer
// Where and how to write the data to???
// Write user page
flashc_write_user_page();


Code:
// Read data from user page
if (flashc_quick_user_page_read()) {
// Where and how to get the read data???
}


Thanks!
Mathias
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: Mar 25, 2009 - 02:34 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13849
Location: Vancouver, BC

Wrong forum. This one is for 8 bit AVRs, try one of the AVR32 forums.

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
dl8dtl
PostPosted: Mar 25, 2009 - 03:04 PM
Raving lunatic


Joined: Dec 20, 2002
Posts: 7277
Location: Dresden, Germany

Moving it...

_________________
Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.
Please read the `General information...' article before.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
certsoft
PostPosted: Mar 25, 2009 - 08:37 PM
Wannabe


Joined: May 21, 2007
Posts: 88
Location: John Day, Oregon, US

Pesticide wrote:

I do not understand how I can write data to the so called "page buffer" or how I can read from it.

Is the page buffer given or how can I create/address it correctly?


I was confused by that as well. The page buffer is 512 bytes located wherever you want it to be Smile

For instance, for the user page it is located at AVR32_FLASHC_USER_PAGE_ADDRESS but when writing normal flash it is located at whatever 512 byte block you want to write to. Keep in mind that the page buffer must be written with 32 bit writes only. For instance:
Code:

unsigned int *psrc, *pdest ;
integer wordcount ;

psrc = (pvoid) &<the source data structure> ;
pdest = (pvoid) AVR32_FLASHC_USER_PAGE_ADDRESS ;
wordcount = (sizeof(<source data structure>) + 3) >> 2 ;
while (wordcnt--)
  *pdest++ = *psrc++ ;
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Pesticide
PostPosted: Mar 26, 2009 - 06:19 AM
Rookie


Joined: Mar 16, 2009
Posts: 43
Location: Switzerland

Thank you very much! Sorry for having chosen the wrong forum.

Mathias
 
 View user's profile Send private message  
Reply with quote Back to top
kalbun
PostPosted: Jun 10, 2010 - 10:54 AM
Hangaround


Joined: Mar 02, 2010
Posts: 103
Location: Firenze, Italy

certsoft wrote:

you want to write to. Keep in mind that the page buffer must be written with 32 bit writes only. For instance:


Strange enough, the flash controller example written for the EVK1100 uses yet another method to access userpage, with no calls to flashc_write_user_page or flashc_quick_user_page_read.

Indeed the example defines a variable residing in the flash user page with a special attribute
Code:
__attribute__((__section__(".userpage")))
static <variable type> variable;

To write a variable you use
Code:
flashc_memcpy((void *)&dst,(void*)&src,sizeof(CParameters),TRUE);

where <dst> is your flash variable, while <src> could be a temporary buffer in SRAM.
You can read the variable directly. That's all.
The architecture manual of the UC3A declares somewhere that flash can be accessed word by word, sort of EEPROM emulation.
So I really don't understand what all these functions in flashc.h are for... I surely missed something Confused
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
sma
PostPosted: Jun 10, 2010 - 11:52 AM
Posting Freak


Joined: Jan 14, 2007
Posts: 1836
Location: Nantes, France

Which function in particular?

-sma
 
 View user's profile Send private message  
Reply with quote Back to top
vamsi_vvk
PostPosted: Jun 11, 2010 - 09:17 AM
Wannabe


Joined: Aug 02, 2008
Posts: 98


We have a very good example given in software frame work. Check it out.
 
 View user's profile Send private message  
Reply with quote Back to top
sma
PostPosted: Jun 11, 2010 - 01:06 PM
Posting Freak


Joined: Jan 14, 2007
Posts: 1836
Location: Nantes, France

see in DRIVERS/FLASHC Smile

-sma
 
 View user's profile Send private message  
Reply with quote Back to top
mittie
PostPosted: Jul 12, 2010 - 03:14 PM
Newbie


Joined: Jul 12, 2010
Posts: 1


certsoft wrote:
Pesticide wrote:

I do not understand how I can write data to the so called "page buffer" or how I can read from it.

Is the page buffer given or how can I create/address it correctly?


I was confused by that as well. The page buffer is 512 bytes located wherever you want it to be Smile

For instance, for the user page it is located at AVR32_FLASHC_USER_PAGE_ADDRESS but when writing normal flash it is located at whatever 512 byte block you want to write to. Keep in mind that the page buffer must be written with 32 bit writes only. For instance:
Code:

unsigned int *psrc, *pdest ;
integer wordcount ;

psrc = (pvoid) &<the source data structure> ;
pdest = (pvoid) AVR32_FLASHC_USER_PAGE_ADDRESS ;
wordcount = (sizeof(<source data structure>) + 3) >> 2 ;
while (wordcnt--)
  *pdest++ = *psrc++ ;

Hello could you please give an example how can I write to say page 100 using page buffer but without any framework stuff. Where should I allocate the buffer? and how flash controller would know where to fetch data?
 
 View user's profile Send private message  
Reply with quote Back to top
kblomqvist
PostPosted: Jul 15, 2012 - 03:29 PM
Hangaround


Joined: Dec 11, 2011
Posts: 191
Location: Finland

mittie wrote:
Where should I allocate the buffer? and how flash controller would know where to fetch data?
Did you figure that out? Particularly I would like to know how the flash controller knows where the "page buffer" is located. I cannot understand how it could be in any place I want it to be allocated. For example, struggling through ASF. How flashc_clear_page_buffer() call within the flashc_memcpy() function knows where the buffer has been allocated?

Code:
// Clear the page buffer in order to prepare data for a flash page write.
flashc_clear_page_buffer();
error_status |= flashc_error_status;


Code snippet from flashc.c, http://pastie.org/4260763
 
 View user's profile Send private message  
Reply with quote Back to top
mstevens84713
PostPosted: Oct 11, 2012 - 04:15 PM
Newbie


Joined: Oct 11, 2012
Posts: 2


With Atmel Studio 6.0.1938 (SP1), I see:
bool flashc_quick_user_page_read(void)
{
flashc_issue_command(AVR32_FLASHC_FCMD_CMD_QPRUP, -1);
return flashc_is_page_erased();
}

bool flashc_erase_user_page(bool check)
{
flashc_issue_command(AVR32_FLASHC_FCMD_CMD_EUP, -1);
return (check) ? flashc_quick_user_page_read() : true;
}

NOTE that the page read routine returns "flashc_is_page_erased()", and the erase user page routine returns "flashc_quick_user_page_read()"! Has anyone verified that the code is correct????
 
 View user's profile Send private message  
Reply with quote Back to top
catweax
PostPosted: Oct 11, 2012 - 07:32 PM
Hangaround


Joined: Aug 25, 2011
Posts: 392
Location: Europe

flashc_quick_user_page_read() reads the whole user page and checks whether it’s erased. Triggered by AVR32_FLASHC_FCMD_CMD_QPRUP a status flag is set that indicates whether the page is erased or not. It can be read via flashc_is_page_erased().

So why shouldn’t flashc_erase_user_page() call flashc_quick_user_page_read() to check whether the page was successfully erased? Looks fine to me.
 
 View user's profile Send private message  
Reply with quote Back to top
mstevens84713
PostPosted: Oct 11, 2012 - 08:58 PM
Newbie


Joined: Oct 11, 2012
Posts: 2


I would expect flashc_quick_user_page_read() to actually read the page and drop it into the page buffer, not return a boolean that says the page had been erased.
 
 View user's profile Send private message  
Reply with quote Back to top
catweax
PostPosted: Oct 11, 2012 - 09:01 PM
Hangaround


Joined: Aug 25, 2011
Posts: 392
Location: Europe

No, that would be a normal read. Have a look at “Quick Page Read” in the datasheet.
 
 View user's profile Send private message  
Reply with quote Back to top
abelinschi
PostPosted: Feb 19, 2013 - 04:11 AM
Newbie


Joined: Oct 10, 2011
Posts: 1


Hi,

If not answered, I am using this code to save and read user page without using the framework:

Code:
//
// Write to Flash Controller register with an offset and value provided
//
void FlashController::writeRegister(uint16_t offset, int32_t value) {
   int32_t *p = (int32_t *)(AVR32_FLASHC_ADDRESS + offset);
   *p = value;
}

//
// Read from Flash Controller register with an offset
//
int32_t FlashController::readRegister(uint16_t offset) {
   int32_t *p = (int32_t *)(AVR32_FLASHC_ADDRESS + offset);
   return *p;
}
//
// Write words into Flash user page
//
void FlashController::writeUserData(uint32_t *src, int words) {
   // Send Clear Buffer Page command to the Flash controller
   writeRegister(AVR32_FLASHC_FCMD, (AVR32_FLASHC_FCMD_KEY_KEY << AVR32_FLASHC_FCMD_KEY_OFFSET) | AVR32_FLASHC_FCMD_CMD_CPB);
   waitForFlashReady();
   // Copy data to buffer page
   uint32_t *dst = (uint32_t *)AVR32_FLASHC_USER_PAGE_ADDRESS;
   while (words--) {
      *dst++ = *src++;
   }
   // Send Write User Page command to the Flash controller
   writeRegister(AVR32_FLASHC_FCMD, (AVR32_FLASHC_FCMD_KEY_KEY << AVR32_FLASHC_FCMD_KEY_OFFSET) | AVR32_FLASHC_FCMD_CMD_WUP);
   waitForFlashReady();
}
//
// Read words from Flash user page
//
void FlashController::readUserData(uint32_t *dst, int words) {
   // Copy data from buffer page
   uint32_t *src = (uint32_t *)AVR32_FLASHC_USER_PAGE_ADDRESS;
   while (words--) {
      *dst++ = *src++;
   }
}
//
// Wait for Flash Controller Ready status
//
void FlashController::waitForFlashReady() {
   while (!readRegister(AVR32_FLASHC_FSR) & AVR32_FLASHC_FSR_FRDY_MASK);
}
 
 View user's profile Send private message  
Reply with quote Back to top
kblomqvist
PostPosted: Mar 04, 2013 - 06:47 AM
Hangaround


Joined: Dec 11, 2011
Posts: 191
Location: Finland

abelinschi wrote:
Hi,

If not answered, I am using this code to save and read user page without using the framework:
Code:
// See above ...

And I'm using this https://github.com/aery32/aery32/blob/m ... flashc.cpp
 
 View user's profile Send private message  
Reply with quote Back to top
mikech
PostPosted: Mar 12, 2013 - 07:20 AM
Hangaround


Joined: Aug 19, 2003
Posts: 398
Location: Australia

To abelinschi and kblomqvist, I thank you for those flash-memory routines.
They helped me understand how the FLASHC actually works.

I have also saved almost 2.5 kbytes of codespace by not using the ASF FLASHC routines. Smile
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits