For users of the Atmel AT91SAM7 and AT91SAM9 ARM CPU chips. Atmel has taken a new direction by combining on chip flash and ram with the ARM CPU on a single die. This provides low cost devices for small systems using the ARM CPU.
This group is to exchange information to help users get started and learn how to use the devices.
Flash Programming - rbdi...@gmail.com - Mar 17 3:07:46 2009
Hi I am very new to microcontrollers. Now my assignment is to write a program to store
data on the flash memory of the controller. I am using AT91SAM7s128. Can any one pls
send me the code.
------------------------------------

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )
Re: Flash Programming - Pietro Maggi - Mar 17 7:17:04 2009
On Tue, Mar 17, 2009 at 7:59 AM,
wrote:
> Hi I am very new to microcontrollers. Now my assignment is to write a
> program to store data on the flash memory of the controller. I am using
> AT91SAM7s128. Can any one pls send me the code.
>
Hi r...@gmail.com,
why don't you look on the Atmel site for some info?
The "AT91SAM7S-EK Software Package for IAR 5.2, Keil and GNU" that you
can find on the AT91SAM7S-EK page
(http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3784)
include some cute sample, like the one named:
"basic-internalflash-project-at91sam7s-ek"
Which:
/// !!!Description
///
/// The program performs the following set of commands:
/// - First, it unlocks the whole %flash
/// - It writes a pattern in the last page of the %flash, and checks it back
/// - It locks the last region of the %flash, and verifies that the status is
/// updated accordingly
/// - It unlocks the last region and verifies that it the status is updated
/// accordingly
/// - Lastly, GPNVM 1 is cleared and set, the status being checked for update
/// between the operations (the original state of the GPNVM is restored
/// after this step)
Have a nice day and keep up with your homework!
Regards
Pietro
------------------------------------

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )Re: Flash Programming - Ralph Hempel - Mar 17 8:48:30 2009
r...@gmail.com wrote:
> Hi I am very new to microcontrollers. Now my assignment is to write
> a program to store data on the flash memory of the controller. I am
> using AT91SAM7s128. Can any one pls send me the code.
Here is a link that might help. I put it on this
newsgroup once a year in the spring and it's
surprisingly useful:
Ralph
------------------------------------

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )Re: Flash Programming - soumendra satapathy - Mar 17 10:26:20 2009
Hi ,
i am stating at the cost of being misunderstood !!
Kindly use this forum to clear your doubts and learn as much as possible...
it is my earnest request not to use this forum to get univ assignments(or
something similiar ) done !!
Go ahead get your hands dirty ... ppl are here to help you out in case you
need any !!
Hope you got my point ...
regards,
som
On Tue, Mar 17, 2009 at 12:29 PM,
wrote:
> Hi I am very new to microcontrollers. Now my assignment is to write a
> program to store data on the flash memory of the controller. I am using
> AT91SAM7s128. Can any one pls send me the code.
>
>

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )Re: Flash Programming - tpuda - Mar 18 4:12:48 2009
Hi,
I have similar problem. I posted it on at91 forum but still no answer.
http://www.at91.com/samphpbb/viewtopic.php?f=15&t=5542
I have a problem when trying to write to flash on a AT91SAM7X256. I'm
running code from RAM and all interrupts are disabled. My oscillator frequency is
18.432MHz and MCK is 47923200 Hz. I have read all posts on forum concerning flash
read/write but I'm still can't get flash working.
I'm trying to write 0x12345678 at address 0x0013FF00 (last page of FLASH). It seems like
my flash read is working. So far, whatever value I write, I get 0xFFFFFFFF (default value
after FLASH erase). I always get "Programming Error" message so it looks like I didn't
configure FCR register on the right way.
I entered the write protection key 0x5A so this part should be OK. If I try to start page
programming in the same line where I entered write protection key and page number in FCR
register, program stops.
Every help will be appreciated.
void flashInit(void) {
AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN) & (72 << 16)) | AT91C_MC_FWS_1FWS ;
// Number Of MCK Cylcles in 1.5 us; 1.5 * 48 = 72
}
void flashWrite(void) {
unsigned long flashaddr = 0x0;
// beginning of write buffer
unsigned long *wrptr = flashaddr;
unsigned long status, temp;
*wrptr = 0x123456789;
AT91C_BASE_MC->MC_FMR &= ~AT91C_MC_NEBP;
// No Erase Before Programming
AT91C_BASE_MC->MC_FCR = ((0x5A << 24) & AT91C_MC_KEY) | ((1023 << 8) &
AT91C_MC_PAGEN);
AT91C_BASE_MC->MC_FCR = AT91C_MC_FCMD_START_PROG;
status = AT91C_BASE_MC->MC_FSR;
if(status & (0x1 << 2))
putc("Lock Error\n");
if(status & (0x1 << 3))
putc("Programming Error\n");
while(!(AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY));
}
void flashRead() {
int i;
unsigned long *flashaddr = 0x0013FF00;
nprintf(*flashaddr); putchar('\n');
Call from main:
flashInit();
flashWritePage();
flashRead();
------------------------------------
______________________________
controlSUITE software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )Re: Re: Flash Programming - Microbit_Ubuntu - Mar 18 4:29:54 2009
You're not properly initialising your pointer in the Write function.
Your code currently prepares your pointer to write to 0...
Try :
void flashWrite(void) {
unsigned long flashaddr = 0x0;
// beginning of write buffer
unsigned long *wrptr = &flashaddr;
Don't forget your "address-of" operator when you init a pointer this way !!!
HTH
Best regards,
Kris
On Wed, 2009-03-18 at 08:08 +0000, tpuda wrote:
> Hi,
>
> I have similar problem. I posted it on at91 forum but still no answer.
>
> http://www.at91.com/samphpbb/viewtopic.php?f=15&t=5542
>
> I have a problem when trying to write to flash on a AT91SAM7X256. I'm
> running code from RAM and all interrupts are disabled. My oscillator frequency is
18.432MHz and MCK is 47923200 Hz. I have read all posts on forum concerning flash
read/write but I'm still can't get flash working.
>
> I'm trying to write 0x12345678 at address 0x0013FF00 (last page of FLASH). It seems like
my flash read is working. So far, whatever value I write, I get 0xFFFFFFFF (default value
after FLASH erase). I always get "Programming Error" message so it looks like I didn't
configure FCR register on the right way.
>
> I entered the write protection key 0x5A so this part should be OK. If I try to start
page programming in the same line where I entered write protection key and page number in
FCR register, program stops.
>
> Every help will be appreciated.
> void flashInit(void) {
> AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN) & (72 << 16)) | AT91C_MC_FWS_1FWS ;
// Number Of MCK Cylcles in 1.5 us; 1.5 * 48 = 72
> }
>
> void flashWrite(void) {
> unsigned long flashaddr = 0x0;
// beginning of write buffer
> unsigned long *wrptr = flashaddr;
> unsigned long status, temp;
>
> *wrptr = 0x123456789;
>
> AT91C_BASE_MC->MC_FMR &= ~AT91C_MC_NEBP;
// No Erase Before Programming
>
> AT91C_BASE_MC->MC_FCR = ((0x5A << 24) & AT91C_MC_KEY) | ((1023 << 8) &
AT91C_MC_PAGEN);
>
>
> AT91C_BASE_MC->MC_FCR = AT91C_MC_FCMD_START_PROG;
>
> status = AT91C_BASE_MC->MC_FSR;
>
> if(status & (0x1 << 2))
> putc("Lock Error\n");
>
> if(status & (0x1 << 3))
> putc("Programming Error\n");
>
>
> while(!(AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY));
>
> }
>
> void flashRead() {
> int i;
> unsigned long *flashaddr = 0x0013FF00;
> nprintf(*flashaddr); putchar('\n');
>
> Call from main:
>
> flashInit();
> flashWritePage();
> flashRead();
>
> ------------------------------------

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )
Re: Re: Flash Programming - louie ouano - Mar 18 8:41:37 2009
I have only worked with the internal flash of the at91sam7se but taking a look from the
AT91SAM7X256 datasheet, they seem to be similar. So comparing my code to yours, here are
my observations/suggestions:
1.) You need checking of status bits after issuing flash commands and not executing
another command if the flash controller is still busy processing the old command.
2.) You need to properly configure the FMCN field.
3.) AT91C_MC_FCMD_ START_PROG should include the proper page number and KEY
If you want to know more of my code, register to www.sharingbrain.com and post your
problem there. It's a very new forum and no members yet, I created it as a way for people
to share their knowledge to others. I'm also inviting other members to join the forum
there and post/share their knowledge.
--- On Wed, 3/18/09, tpuda
wrote:
From: tpuda
Subject: [AT91SAM] Re: Flash Programming
To: A...@yahoogroups.com
Date: Wednesday, March 18, 2009, 4:08 PM
Hi,
I have similar problem. I posted it on at91 forum but still no answer.
http://www.at91. com/samphpbb/ viewtopic. php?f=15& t=5542
I have a problem when trying to write to flash on a AT91SAM7X256. I'm
running code from RAM and all interrupts are disabled. My oscillator frequency is
18.432MHz and MCK is 47923200 Hz. I have read all posts on forum concerning flash
read/write but I'm still can't get flash working.
I'm trying to write 0x12345678 at address 0x0013FF00 (last page of FLASH). It seems like
my flash read is working. So far, whatever value I write, I get 0xFFFFFFFF (default value
after FLASH erase). I always get "Programming Error" message so it looks like I didn't
configure FCR register on the right way.
I entered the write protection key 0x5A so this part should be OK. If I try to start page
programming in the same line where I entered write protection key and page number in FCR
register, program stops.
Every help will be appreciated.
void flashInit(void) {
AT91C_BASE_MC- >MC_FMR = ((AT91C_MC_FMCN) & (72 << 16)) | AT91C_MC_FWS_ 1FWS ;
// Number Of MCK Cylcles in 1.5 us; 1.5 * 48 = 72
}
void flashWrite(void) {
unsigned long flashaddr = 0x0;
// beginning of write buffer
unsigned long *wrptr = flashaddr;
unsigned long status, temp;
*wrptr = 0x123456789;
AT91C_BASE_MC- >MC_FMR &= ~AT91C_MC_NEBP;
// No Erase Before Programming
AT91C_BASE_MC- >MC_FCR = ((0x5A << 24) & AT91C_MC_KEY) | ((1023 << 8) & AT91C_MC_PAGEN)
;
AT91C_BASE_MC- >MC_FCR = AT91C_MC_FCMD_ START_PROG;
status = AT91C_BASE_MC- >MC_FSR;
if(status & (0x1 << 2))
putc("Lock Error\n");
if(status & (0x1 << 3))
putc("Programming Error\n");
while(!(AT91C_ BASE_MC-> MC_FSR & AT91C_MC_FRDY) );
}
void flashRead() {
int i;
unsigned long *flashaddr = 0x0013FF00;
nprintf(*flashaddr) ; putchar('\n' );
Call from main:
flashInit();
flashWritePage( );
flashRead();

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )Re: Flash Programming - tpuda - Mar 18 11:56:04 2009
Thanks, but still no progress. I have modified my flash write function. Now im pretty
that I'm writing on right address. My program stops after "start programming" command.
void flashWrite(void) {
unsigned long flashaddr = 0x0013FF00;
unsigned long *wrptr;
unsigned long status;
wrptr = flashaddr;
*wrptr = 0x12345678;
AT91C_BASE_MC->MC_FMR &= ~AT91C_MC_NEBP; // No Erase Before Programming
while(!(AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY)); // check if FRDY flag is set
putc("FRDY flag set; executing next instruction\n");
AT91C_BASE_MC->MC_FCR = ((0x5A << 24) & AT91C_MC_KEY) | ((1023 << 8) & AT91C_MC_PAGEN) |
AT91C_MC_FCMD_START_PROG;
status = AT91C_BASE_MC->MC_FSR;
if(status & (0x1 << 2))
putc("Lock Error\n");
if(status & (0x1 << 3))
putc("Programming Error\n");
while(!(AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY));
}
--- In A...@yahoogroups.com, Microbit_Ubuntu
wrote:
>
> You're not properly initialising your pointer in the Write function.
> Your code currently prepares your pointer to write to 0...
>
> Try :
>
> void flashWrite(void) {
> unsigned long flashaddr = 0x0;
// beginning of write buffer
> unsigned long *wrptr = &flashaddr;
>
> Don't forget your "address-of" operator when you init a pointer this way !!!
>
> HTH
> Best regards,
> Kris
>
------------------------------------
______________________________
controlSUITE software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )Re: Flash Programming - tpuda - Mar 18 11:56:09 2009
Re: Flash Programming - tpuda - Mar 18 11:56:49 2009
Thanks louie but I have already change my code and posted it again. I posted it on
SharingBrain.com. Here is an update.
I have a problem when trying to write on internal flash of AT91SAM7X256. All interrupts
are disabled and I'm only using USART to check results. My oscillator frequency is
18.432MHz and MCK is 47923200 Hz. I have read all posts on forum concerning flash
read/write but I'm still can't get flash working.
I'm trying to write 0x12345678 at address 0x0013FF00 (last page of FLASH). It seems like
my flash read is working. So far, whatever value I try to write my program stops after
"start programming" command. It is the same for other flash address locations. If I set
the wrong write protection key, I get Programming Error message (PROGE flag) and
0xFFFFFFFF after flashRead is executed. If i split "start programming" command in two
parts, I get same result. I also get the same result when I remove "No Erase Before
Programming" part of code.
Part of code that executes program but Programming Error occurs:
[code]
AT91C_BASE_MC->MC_FCR = ((0x5A << 24) & AT91C_MC_KEY) | ((1023 << 8) &
AT91C_MC_PAGEN);
AT91C_BASE_MC->MC_FCR = AT91C_MC_FCMD_START_PROG;
[/code]
[code]
__attribute__ ((section (".ramfunc"))) void flashInit(void) {
AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN) & (72 << 16)) | AT91C_MC_FWS_1FWS ;
// Number Of MCK Cylcles in 1.5 us; 1.5 * 48 = 72
}
[/code]
[code]
__attribute__ ((section (".ramfunc"))) void flashWrite(void) {
unsigned long flashaddr = 0x0013FF00;
unsigned long *wrptr;
unsigned long status;
wrptr = (unsigned long*) flashaddr;
*wrptr = 0x12345678;
AT91C_BASE_MC->MC_FMR &= ~AT91C_MC_NEBP; // No Erase Before Programming
while(!(AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY)); // check if FRDY flag is set
putc("FRDY flag set; executing next instruction\n");
AT91C_BASE_MC->MC_FCR = ((0x5A << 24) & AT91C_MC_KEY) | ((1023 << 8) & AT91C_MC_PAGEN) |
AT91C_MC_FCMD_START_PROG;
status = AT91C_BASE_MC->MC_FSR;
if(status & (0x1 << 2))
putc("Lock Error\n");
if(status & (0x1 << 3))
putc("Programming Error\n");
while(!(AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY));
}
[/code]
[code]
__attribute__ ((section (".ramfunc"))) void flashRead() {
int i;
unsigned long *flashaddr = 0x0013FF00;
nprintf(*flashaddr); putchar('\n');
[/code]
Call from main:[code]
flashInit();
flashWritePage();
flashRead();
[/code]
--- In A...@yahoogroups.com, louie ouano
wrote:
>
> I have only worked with the internal flash of the at91sam7se but taking a look from the
AT91SAM7X256 datasheet, they seem to be similar. So comparing my code to yours, here are
my observations/suggestions:
>
> 1.) You need checking of status bits after issuing flash commands and not executing
another command if the flash controller is still busy processing the old command.
> 2.) You need to properly configure the FMCN field.
> 3.) AT91C_MC_FCMD_ START_PROG should include the proper page number and KEY
>
> If you want to know more of my code, register to www.sharingbrain.com and post your
problem there. It's a very new forum and no members yet, I created it as a way for people
to share their knowledge to others. I'm also inviting other members to join the forum
there and post/share their knowledge.
------------------------------------

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )Re: Re: Flash Programming - Ralph Hempel - Mar 18 13:31:54 2009
Re: Re: Flash Programming - chip - Mar 18 13:45:38 2009
Re: Re: Flash Programming - Ralph Hempel - Mar 18 13:47:49 2009
chip wrote:
> *On Wed, 18 Mar 2009 13:31:36 -0400, Ralph Hempel wrote*
> > tpuda wrote:
> > > Thanks, but still no progress. I have modified my flash write
> > > function. Now im pretty that I'm writing on right address. My program
> > > stops after "start programming" command.
> >
> > You are, of course running the FLASH write routine from RAM, right?
> >
> > Ralph
OK, I'll bite. What's in the zip file that you attached to this
note?
Ralph
------------------------------------

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )
Re: Re: Flash Programming - chip - Mar 18 13:56:21 2009
Sorry, believe it or not I'm working with a guy named Ralf Hempfling who just sent me an
e-mail and got confused...
On Wed, 18 Mar 2009 13:47:32 -0400, Ralph Hempel wrote
> chip wrote:
> > *On Wed, 18 Mar 2009 13:31:36 -0400, Ralph Hempel wrote*
> > > tpuda wrote:
> > > > Thanks, but still no progress. I have modified my flash write
> > > > function. Now im pretty that I'm writing on right address. My program
> > > > stops after "start programming" command.
> > >
> > > You are, of course running the FLASH write routine from RAM, right?
> > >
> > > Ralph
>
> OK, I'll bite. What's in the zip file that you attached to this
> note?
>
> Ralph
--
______________________________
controlSUITE software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )Re: Flash Programming - tpuda - Mar 19 20:05:47 2009
Solved! I had a hardware specific problem.
------------------------------------

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )