[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [partial-reconfig] Access Flash on MemecP160 Communication Module



Hi all,
Sorry for that post.The dust has settled. I just mixed up some pins of the opb-emc. Now it works fine.....
Cheers Christian
 
----- Original Message -----
Sent: Monday, May 23, 2005 10:34 AM
Subject: [partial-reconfig] Access Flash on MemecP160 Communication Module

Hi all,
I'm a bit desperate because I can't manage to write or read data to a flash memory. I want to use it to store partial bitstreams which I load into flash during runtime.
I'm using the  Memec Virtex-II V2MB1000  Development Board with the P160 Communication Module. It provides 8MB of Flash and 1MB of SRAM. In my design the memory is connected to the MicroBlaze via the emc-opb - controller which is configured to serve 2 banks of memory.Each bank has its own base address:
SRAM : XPAR_SRAM_256KX32_FLASH_1MX32_MEM0_BASEADDR
FLASH: XPAR_SRAM_256KX32_FLASH_1MX32_MEM1_BASEADDR
 
Here is the c-code I used to access the flash memory. I copied parts of it from the xmdflash.tcl script which I got from John's uclinux project page as they use the same board for the example uxlinux project. It was written by Jan-Hendrik Schunke.
--snip--

///////////////////////////////////////////////////////////////////////////////
// define the toshiba flash commands
#define FLASH_COMMAND_AA               0x00AA00AA
#define FLASH_COMMAND_55               0x00550055
#define FLASH_COMMAND_READ_RESET       0x00F000F0
#define FLASH_COMMAND_FAST_PROG_RESET  0x00900090
#define FLASH_COMMAND_ERASE            0x00800080
#define FLASH_COMMAND_AUTO_CHIP_ERASE  0x00100010
#define FLASH_COMMAND_AUTO_BLOCK_ERASE 0x00300030
#define FLASH_COMMAND_AUTO_PROGRAM     0x00A000A0
#define FLASH_DQ7                      0x00800080
#define FLASH_DQ5                      0x00200020

-snip--


///////////////////////////////////////////////////////////////////////////////
// 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