///////////////////////////////////////////////////////////////////////////////
//
declare variables used to access the flash
Xuint32
flashCommandAddr2AA;
Xuint32 flashCommandAddr555;
Xuint32
flashCommandBaseAddr;
Xuint32 flashMemBaseAddr;
-snip-
/******************************************************************************
*
*
Function Name:
FD_init
*
* *****************************************************************************/
void
FD_init(Xuint32 memBaseAddr){
flashCommandBaseAddr =
memBaseAddr;
// 2AA shifted by 2 because 2 lower address lines
are
// not connected (word access
mode)
flashCommandAddr2AA = flashCommandBaseAddr +
(0x2AA<<2);
// 555 shifted by 2 because 2 lower address
lines are
// not connectrd ( word access
mode)
flashCommandAddr555 = flashCommandBaseAddr +
(0x555<<2);
flashMemBaseAddr =
memBaseAddr;
}
/******************************************************************************
*
*
Function Name:
FD_setFastProgMode
*
*****************************************************************************/
void
FD_setFastProgMode(){
(*(volatile Xuint32
*)(flashCommandAddr555)) = FLASH_COMMAND_AA;
(*(volatile Xuint32
*)(flashCommandAddr2AA)) = FLASH_COMMAND_55;
(*(volatile Xuint32
*)(flashCommandAddr555)) = FLASH_DQ5;
}
/******************************************************************************
*
*
Function Name:
FD_exitFastProgMode()
*
*
*****************************************************************************/
void
FD_exitFastProgMode(){
(*(volatile Xuint32
*)(flashCommandBaseAddr)) =
FLASH_COMMAND_FAST_PROG_RESET;
(*(volatile Xuint32 *)
(flashCommandBaseAddr)) =
FLASH_COMMAND_READ_RESET;
}
/******************************************************************************
*
*
Function Name: FD_writeWord
*
* Description:
*
writes one word of data to the given word (4 byte)address.the flash address
* space starts with 0x0. the given address must be word alligend and
within
* the flash range. otherwise a XST_FAILURE will be
returned
*
* Calling Sequence:
*
addr - the word address
* data - the word data to be written to the
given address
*
*
* Returns:
*
XST_FAILURE -if wrong address
* XST_SUCCESS -if success
*
NOTE:
* FD_setFastProgMode must be called once before FD_writeWord
can be
called
*****************************************************************************/
XStatus
FD_writeWord(Xuint32 addr, Xuint32 data){
// check for word allinment
and range
if(((addr&0x3)==0x0) && (addr
<=MAX_FLASH_ADDR_SPACE)){
(*(volatile Xuint32
*)(flashCommandBaseAddr)) =
FLASH_COMMAND_AUTO_PROGRAM;
(*(volatile Xuint32
*)(flashMemBaseAddr+addr)) =
data;
}
else{
return
XST_FAILURE;
}
return XST_SUCCESS;
}
/******************************************************************************
*
*
Function Name: FD_readByte
*
* Description:
* reads one byte of data form the given address. the flash address
range starts
* with 0x0.
*
* Calling
Sequence:
*
* Returns:
* the byte of data from
the given byte address within the flash address range
*
*
NOTE:
*
*****************************************************************************/
Xuint8
FD_readByte(Xuint32 addr){
Xuint32
flashWord;
Xuint8 retVal;
//
check for range
if(addr <
MAX_FLASH_ADDR_SPACE){
// read the flash word; therefor
cut off the last two bits
flashWord =(*(volatile Xuint32
*)(flashMemBaseAddr+(addr&0xFFFFC)));
// get the
right byte form the word
retVal =
((flashWord&((0xFF)<<((addr&0x3)<<3)))>>((addr&0x3)<<3));
}
else{
retVal
= 0;
}
return
retVal;
}
/******************************************************************************
*
*
Function Name:
FD_readWord
*****************************************************************************/
Xuint32 FD_readWord(Xuint32 addr){
if(addr <
MAX_FLASH_ADDR_SPACE){
// read the flash word; therefor
cut off the last two bits
return (*(volatile Xuint32
*)(flashMemBaseAddr+(addr&0xFFFFC)));
}
else{
return
NULL;
}
}
/******************************************************************************
*
*
Function Name:
FD_AutoProgWriteWord
*****************************************************************************/
XStatus
FD_AutoProgWriteWord(Xuint32 addr, Xuint32 data){
// check for
word allinment and range
if(((addr&0x3)==0x0) && (addr
<=MAX_FLASH_ADDR_SPACE)){
(*(volatile Xuint32
*)(flashCommandAddr555)) = FLASH_COMMAND_AA;
(*(volatile
Xuint32 *)(flashCommandAddr2AA)) =
FLASH_COMMAND_55;
(*(volatile Xuint32 *)(flashCommandAddr555))
= FLASH_COMMAND_AUTO_PROGRAM;
(*(volatile Xuint32
*)(flashMemBaseAddr+addr)) =
data;
}
else{
return
XST_FAILURE;
}
return
XST_SUCCESS;
}
/******************************************************************************
*
*
Function Name: FD_readReset();
*
* Description: reset
the flash to read mode
*
* Calling Sequence:
*
* Returns:
*
* NOTE:
*
*****************************************************************************/
void
FD_readReset(){
(*(volatile Xuint32 *)(flashCommandAddr555)) =
FLASH_COMMAND_AA;
(*(volatile Xuint32 *)(flashCommandAddr2AA))
= FLASH_COMMAND_55;
(*(volatile Xuint32
*)(flashCommandAddr555)) = FLASH_COMMAND_READ_RESET;
}
/******************************************************************************
*
*
Function Name:
FD_autoChipErase();
*****************************************************************************/
void
FD_autoChipErase(){
(*(volatile Xuint32
*)(flashCommandAddr555)) = FLASH_COMMAND_AA;
(*(volatile
Xuint32 *)(flashCommandAddr2AA)) =
FLASH_COMMAND_55;
(*(volatile Xuint32 *)(flashCommandAddr555))
= FLASH_COMMAND_ERASE;
(*(volatile Xuint32
*)(flashCommandAddr555)) = FLASH_COMMAND_AA;
(*(volatile
Xuint32 *)(flashCommandAddr2AA)) =
FLASH_COMMAND_55;
(*(volatile Xuint32 *)(flashCommandAddr555))
= FLASH_COMMAND_AUTO_CHIP_ERASE;
}
I initialized the flash
driver with FD_init(XPAR_SRAM_256KX32_FLASH_1MX32_MEM1_BASEADDR).When I
start reading a word form flash memory using the function
FD_readWord it always returns 0xFFFFFFFF, even if I have written an other
value with the function FD_AutoProgWriteWord to the address before
followed by a FD_readReset. Can somebody tell me what I have done wrong ? Is
it right, that the flashCommadAddr555 and flashCommandAddr2AA are the
flashBaseAddr+given offset like I initialized it in FD_init ?
Or are there some special settings of the emc-opb memory controller which I
ignored ?
Thanks in advance for your help
Cheers Christian