Reply by Jan-Bernd March 16, 20112011-03-16
Hi tpuda,

I have the same problem that I could only read 0xffffffff out of the flash.

In your thread I read that you have had the same problem some years ago.

You only wrote that you have solved it. Can you say me what the hardware
specific problem was?

With kind regards

jan

_____

Von: A... [mailto:A...] Im Auftrag von
tpuda
Gesendet: Donnerstag, 19. Mz 2009 23:44
An: A...
Betreff: [AT91SAM] Re: Flash Programming

Solved! I had a hardware specific problem.
Reply by tpuda March 19, 20092009-03-19
Solved! I had a hardware specific problem.

Reply by chip March 18, 20092009-03-18
Sorry, believe it or not I'm working with a guy named Ralf Hempfling who just sent me an e-mailand 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

--
Reply by Ralph Hempel March 18, 20092009-03-18
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
Reply by chip March 18, 20092009-03-18
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

--
Reply by Ralph Hempel March 18, 20092009-03-18
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
Reply by tpuda March 18, 20092009-03-18
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:





Call from main:

--- In A..., 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.

Reply by tpuda March 18, 20092009-03-18
I updated my code on AT91 forum. Please check it out.

http://www.at91.com/samphpbb/viewtopic.php?f&tU42&p341#p16341

Reply by tpuda March 18, 20092009-03-18
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..., 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
>

Reply by louie ouano March 18, 20092009-03-18
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...
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& tU42

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();