DSPRelated.com
Forums

Writing data to flash memory

Started by isni...@gmail.com July 8, 2008
Hi,
I have written a small piece of code to write data to flash. I am using a BF534 processor. The flash is connected to the bank 0 of the BF534 Here is the piece of code :
----------------------------start of code ----------------------------
#define START_ADDR 0x20000000
#define FLASH_555 0x0AAA //these 2 values were obtained from #define FLASH_2AA 0x0554 //flash driver program provided by AD

int write_flash(unsigned long offset,const short *buffer,int num){
for(int i=0;i //flash write sequence
wr_flash((START_ADDR+FLASH_555),0xAA);
wr_flash((START_ADDR+FLASH_2AA ),0x55);
wr_flash((START_ADDR+FLASH_555),0xA0);
//end of flash write squence

//writing the actual data
wr_flash((START_ADDR+offset+i*2),*(buffer+i));

for(int j=0;j<0x200;j++){
asm("nop;");
}
}
}
static inline ERROR_CODE wr_flash(unsigned long wr_addr,short data){

unsigned int uiSaveInts = cli();
short *flash_addr=(short *) wr_addr;
*flash_addra;
sti(uiSaveInts);
return NO_ERR;

}
---------------------end of code --
But when I use this code.. After writing to the flash if i check the memory location i am writing, it is filled with junk data. Not only that when I write a single location, the other locations are also getting written by junk data. Has anybody encountered such a problem before.?
Regards,
Nithin
Howdy Nithin,

Check the timing of your write sequence. You may need to wait several
microseconds between each write. Look at the data sheet for the flash
and monitor your writes by o'scope to make sure all the timing is correct.

Some flash devices allow you to read back status by watching the D0 or D7
bit. You may be able to write, then read until a bit is set (or clear)
and then do the next step.

In any case, watch the write strobe, chip select and other control lines
to make sure you are hitting the flash the way it wants.

Patience, persistence, truth,
Dr. mike

On Tue, 8 Jul 2008 i...@gmail.com wrote:

> Hi,
> I have written a small piece of code to write data to flash. I am using a BF534 processor. The flash is connected to the bank 0 of the BF534 Here is the piece of code :
> ----------------------------start of code ----------------------------
> #define START_ADDR 0x20000000
> #define FLASH_555 0x0AAA //these 2 values were obtained from #define FLASH_2AA 0x0554 //flash driver program provided by AD
>
> int write_flash(unsigned long offset,const short *buffer,int num){
> for(int i=0;i > //flash write sequence
> wr_flash((START_ADDR+FLASH_555),0xAA);
> wr_flash((START_ADDR+FLASH_2AA ),0x55);
> wr_flash((START_ADDR+FLASH_555),0xA0);
> //end of flash write squence
>
> //writing the actual data
> wr_flash((START_ADDR+offset+i*2),*(buffer+i));
>
> for(int j=0;j<0x200;j++){
> asm("nop;");
> }
> }
> }
> static inline ERROR_CODE wr_flash(unsigned long wr_addr,short data){
>
> unsigned int uiSaveInts = cli();
> short *flash_addr=(short *) wr_addr;
> *flash_addra;
> sti(uiSaveInts);
> return NO_ERR;
>
> }
> ---------------------end of code --
> But when I use this code.. After writing to the flash if i check the memory location i am writing, it is filled with junk data. Not only that when I write a single location, the other locations are also getting written by junk data. Has anybody encountered such a problem before.?
> Regards,
> Nithin
>