Writing to External Flash
Company  
ST Home | Microcontrollers

Index  »  ARM Cortex-M3 STM32  »  Writing to External Flash
     
   Writing to External Flash
 Moderated by :   »  STOne-32

Author
beginning argument    ( No reply )
siddj   Posted 20-11-2008 at 21:50   



Registered on :
11-03-2009

Messages : 16

 OFF-Line

I am writing to external flash using STM32F103. I am trying to understand the FSMC_NAND example in the sample code library of FW LIB. I am stuck at the following code/functions.

/* FSMC NAND memory address computation */
#define ADDR_1st_CYCLE(ADDR) (u8)((ADDR)& 0xFF) /* 1st addressing cycle */
#define ADDR_2nd_CYCLE(ADDR) (u8)(((ADDR)& 0xFF00) >> 8) /* 2nd addressing cycle */
#define ADDR_3rd_CYCLE(ADDR) (u8)(((ADDR)& 0xFF0000) >> 16) /* 3rd addressing cycle */
#define ADDR_4th_CYCLE(ADDR) (u8)(((ADDR)& 0xFF000000) >> 24) /* 4th addre

It takes four address cycles to write to this 512Mb chip. Can someone please explain to me why aretheir shifts in the 2nd,3rd,and 4th cycle.
Also ADDR is not defined anywhere, in terms of syntax, what does it mean?

u32 FSMC_NAND_ReadSmallPage(u8 *pBuffer, NAND_ADDRESS Address, u32 NumPageToRead)
{
u32 index = 0x00, numpageread = 0x00, addressstatus = NAND_VALID_ADDRESS;
u32 status = NAND_READY, size = 0x00;

while((NumPageToRead != 0x0) && (addressstatus == NAND_VALID_ADDRESS))
{
/* Page Read command and page address */
*(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_A;

*(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
*(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
*(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
*(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);

*(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_TRUE1;

/* Calculate the size */
size = NAND_PAGE_SIZE + (NAND_PAGE_SIZE * numpageread);

/* Get Data into Buffer */
for(; index < size; index++)
{
pBuffer[index]= *(vu8 *)(Bank_NAND_ADDR | DATA_AREA);
}

numpageread++;

NumPageToRead--;


Definitions:
#define NAND_CMD_AREA_A ((u8)0x00)
#define CMD_AREA (u32)(1<<16) /* A16 = CLE high */
#define ADDR_AREA (u32)(1<<17) /* A17 = ALE high */

/* FSMC NAND memory parameters */
#define NAND_PAGE_SIZE ((u16)0x0200) /* 512 bytes per page w/o Spare Area */
#define NAND_BLOCK_SIZE ((u16)0x0020) /* 32x512 bytes pages per block */
#define NAND_ZONE_SIZE ((u16)0x0400) /* 1024 Block per zone */
#define NAND_SPARE_AREA_SIZE ((u16)0x0010) /* last 16 bytes as spare area */
#define NAND_MAX_ZONE ((u16)0x0004) /* 4 zones of 1024 block */


In this code it reads a page. Again "ROW_ADDRESS" is not defined anywhere. Can someone please explain the syntax. Also the "or" operator keeps on beating me. What does it exactly do when you are equating it to another variable or constant?
Please,please help! If you need more info I will gladly provide it.



 Profile   Quote  
On Top

Search in the forums
 
Jump To