fsmc_nand.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
  2. * File Name : fsmc_nand.c
  3. * Author : MCD Application Team
  4. * Version : V2.0.3
  5. * Date : 09/22/2008
  6. * Description : This file provides a set of functions needed to drive the
  7. * NAND512W3A2 memory mounted on STM3210E-EVAL board.
  8. ********************************************************************************
  9. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  10. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  11. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  12. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  13. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  14. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  15. *******************************************************************************/
  16. /* Includes ------------------------------------------------------------------*/
  17. #include "fsmc_nand.h"
  18. /* Private typedef -----------------------------------------------------------*/
  19. /* Private define ------------------------------------------------------------*/
  20. #define FSMC_Bank_NAND FSMC_Bank2_NAND
  21. #define Bank_NAND_ADDR Bank2_NAND_ADDR
  22. #define Bank2_NAND_ADDR ((u32)0x70000000)
  23. /* Private macro -------------------------------------------------------------*/
  24. #define ROW_ADDRESS (Address.Page + (Address.Block + (Address.Zone * NAND_ZONE_SIZE)) * NAND_BLOCK_SIZE)
  25. /* Private variables ---------------------------------------------------------*/
  26. /* Private function prototypes -----------------------------------------------*/
  27. /* Private functions ---------------------------------------------------------*/
  28. /*******************************************************************************
  29. * Function Name : FSMC_NAND_Init
  30. * Description : Configures the FSMC and GPIOs to interface with the NAND memory.
  31. * This function must be called before any write/read operation
  32. * on the NAND.
  33. * Input : None
  34. * Output : None
  35. * Return : None
  36. *******************************************************************************/
  37. void FSMC_NAND_Init(void)
  38. {
  39. GPIO_InitTypeDef GPIO_InitStructure;
  40. FSMC_NANDInitTypeDef FSMC_NANDInitStructure;
  41. FSMC_NAND_PCCARDTimingInitTypeDef p;
  42. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
  43. RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE);
  44. /*-- GPIO Configuration ------------------------------------------------------*/
  45. /* CLE, ALE, D0->D3, NOE, NWE and NCE2 NAND pin configuration */
  46. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_14 | GPIO_Pin_15 |
  47. GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
  48. GPIO_Pin_7;
  49. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  50. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  51. GPIO_Init(GPIOD, &GPIO_InitStructure);
  52. /* D4->D7 NAND pin configuration */
  53. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
  54. GPIO_Init(GPIOE, &GPIO_InitStructure);
  55. /* NWAIT NAND pin configuration */
  56. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  57. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  58. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  59. GPIO_Init(GPIOD, &GPIO_InitStructure);
  60. /* INT2 NAND pin configuration */
  61. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  62. GPIO_Init(GPIOG, &GPIO_InitStructure);
  63. /*-- FSMC Configuration ------------------------------------------------------*/
  64. p.FSMC_SetupTime = 0x1;
  65. p.FSMC_WaitSetupTime = 0x3;
  66. p.FSMC_HoldSetupTime = 0x2;
  67. p.FSMC_HiZSetupTime = 0x1;
  68. FSMC_NANDInitStructure.FSMC_Bank = FSMC_Bank2_NAND;
  69. FSMC_NANDInitStructure.FSMC_Waitfeature = FSMC_Waitfeature_Enable;
  70. FSMC_NANDInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
  71. FSMC_NANDInitStructure.FSMC_ECC = FSMC_ECC_Enable;
  72. FSMC_NANDInitStructure.FSMC_ECCPageSize = FSMC_ECCPageSize_512Bytes;
  73. // FSMC_NANDInitStructure.FSMC_AddressLowMapping = FSMC_AddressLowMapping_Direct;
  74. FSMC_NANDInitStructure.FSMC_TCLRSetupTime = 0x00;
  75. FSMC_NANDInitStructure.FSMC_TARSetupTime = 0x00;
  76. FSMC_NANDInitStructure.FSMC_CommonSpaceTimingStruct = &p;
  77. FSMC_NANDInitStructure.FSMC_AttributeSpaceTimingStruct = &p;
  78. FSMC_NANDInit(&FSMC_NANDInitStructure);
  79. /* FSMC NAND Bank Cmd Test */
  80. FSMC_NANDCmd(FSMC_Bank2_NAND, ENABLE);
  81. }
  82. /******************************************************************************
  83. * Function Name : FSMC_NAND_ReadID
  84. * Description : Reads NAND memory's ID.
  85. * Input : - NAND_ID: pointer to a NAND_IDTypeDef structure which will hold
  86. * the Manufacturer and Device ID.
  87. * Output : None
  88. * Return : None
  89. *******************************************************************************/
  90. void FSMC_NAND_ReadID(NAND_IDTypeDef* NAND_ID)
  91. {
  92. u32 data = 0;
  93. /* Send Command to the command area */
  94. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = 0x90;
  95. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
  96. /* Sequence to read ID from NAND flash */
  97. data = *(vu32 *)(Bank_NAND_ADDR | DATA_AREA);
  98. NAND_ID->Maker_ID = ADDR_1st_CYCLE (data);
  99. NAND_ID->Device_ID = ADDR_2nd_CYCLE (data);
  100. NAND_ID->Third_ID = ADDR_3rd_CYCLE (data);
  101. NAND_ID->Fourth_ID = ADDR_4th_CYCLE (data);
  102. }
  103. /******************************************************************************
  104. * Function Name : FSMC_NAND_WriteSmallPage
  105. * Description : This routine is for writing one or several 512 Bytes Page size.
  106. * Input : - pBuffer: pointer on the Buffer containing data to be written
  107. * - Address: First page address
  108. * - NumPageToWrite: Number of page to write
  109. * Output : None
  110. * Return : New status of the NAND operation. This parameter can be:
  111. * - NAND_TIMEOUT_ERROR: when the previous operation generate
  112. * a Timeout error
  113. * - NAND_READY: when memory is ready for the next operation
  114. * And the new status of the increment address operation. It can be:
  115. * - NAND_VALID_ADDRESS: When the new address is valid address
  116. * - NAND_INVALID_ADDRESS: When the new address is invalid address
  117. *******************************************************************************/
  118. u32 FSMC_NAND_WriteSmallPage(u8 *pBuffer, NAND_ADDRESS Address, u32 NumPageToWrite)
  119. {
  120. u32 index = 0x00, numpagewritten = 0x00, addressstatus = NAND_VALID_ADDRESS;
  121. u32 status = NAND_READY, size = 2048;
  122. while((NumPageToWrite != 0x00) && (addressstatus == NAND_VALID_ADDRESS) && (status == NAND_READY))
  123. {
  124. /* Page write command and address */
  125. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_A;
  126. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE0;
  127. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
  128. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
  129. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
  130. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_4th_CYCLE(ROW_ADDRESS);
  131. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_5fh_CYCLE(ROW_ADDRESS);
  132. /* Calculate the size */
  133. size = NAND_PAGE_SIZE + (NAND_PAGE_SIZE * numpagewritten);
  134. /* Write data */
  135. for(; index < size; index++)
  136. {
  137. *(vu8 *)(Bank_NAND_ADDR | DATA_AREA) = pBuffer[index];
  138. }
  139. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE_TRUE1;
  140. /* Check status for successful operation */
  141. status = FSMC_NAND_GetStatus();
  142. if(status == NAND_READY)
  143. {
  144. numpagewritten++;
  145. NumPageToWrite--;
  146. /* Calculate Next small page Address */
  147. addressstatus = FSMC_NAND_AddressIncrement(&Address);
  148. }
  149. }
  150. return (status | addressstatus);
  151. }
  152. /******************************************************************************
  153. * Function Name : FSMC_NAND_ReadSmallPage
  154. * Description : This routine is for sequential read from one or several
  155. * 512 Bytes Page size.
  156. * Input : - pBuffer: pointer on the Buffer to fill
  157. * - Address: First page address
  158. * - NumPageToRead: Number of page to read
  159. * Output : None
  160. * Return : New status of the NAND operation. This parameter can be:
  161. * - NAND_TIMEOUT_ERROR: when the previous operation generate
  162. * a Timeout error
  163. * - NAND_READY: when memory is ready for the next operation
  164. * And the new status of the increment address operation. It can be:
  165. * - NAND_VALID_ADDRESS: When the new address is valid address
  166. * - NAND_INVALID_ADDRESS: When the new address is invalid address
  167. *******************************************************************************/
  168. u32 FSMC_NAND_ReadSmallPage(u8 *pBuffer, NAND_ADDRESS Address, u32 NumPageToRead)
  169. {
  170. u32 index = 0x00, numpageread = 0x00, addressstatus = NAND_VALID_ADDRESS;
  171. u32 status = NAND_READY, size = 2048, i = 0;
  172. /* Calculate the size */
  173. size = NAND_PAGE_SIZE + (NAND_PAGE_SIZE * numpageread);
  174. while((NumPageToRead != 0x0) && (addressstatus == NAND_VALID_ADDRESS))
  175. {
  176. /* Page Read command and page address */
  177. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_A;
  178. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
  179. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
  180. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
  181. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_4th_CYCLE(ROW_ADDRESS);
  182. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_5fh_CYCLE(ROW_ADDRESS);
  183. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_TRUE1;
  184. for(i = 0; i <= 10000; i++);
  185. /* Get Data into Buffer */
  186. for(; index < size; index++)
  187. {
  188. pBuffer[index]= *(vu8 *)(Bank_NAND_ADDR | DATA_AREA);
  189. }
  190. numpageread++;
  191. NumPageToRead--;
  192. /* Calculate page address */
  193. addressstatus = FSMC_NAND_AddressIncrement(&Address);
  194. }
  195. status = FSMC_NAND_GetStatus();
  196. return (status | addressstatus);
  197. }
  198. /******************************************************************************
  199. * Function Name : FSMC_NAND_WriteSpareArea
  200. * Description : This routine write the spare area information for the specified
  201. * pages addresses.
  202. * Input : - pBuffer: pointer on the Buffer containing data to be written
  203. * - Address: First page address
  204. * - NumSpareAreaTowrite: Number of Spare Area to write
  205. * Output : None
  206. * Return : New status of the NAND operation. This parameter can be:
  207. * - NAND_TIMEOUT_ERROR: when the previous operation generate
  208. * a Timeout error
  209. * - NAND_READY: when memory is ready for the next operation
  210. * And the new status of the increment address operation. It can be:
  211. * - NAND_VALID_ADDRESS: When the new address is valid address
  212. * - NAND_INVALID_ADDRESS: When the new address is invalid address
  213. *******************************************************************************/
  214. u32 FSMC_NAND_WriteSpareArea(u8 *pBuffer, NAND_ADDRESS Address, u32 NumSpareAreaTowrite)
  215. {
  216. u32 index = 0x00, numsparesreawritten = 0x00, addressstatus = NAND_VALID_ADDRESS;
  217. u32 status = NAND_READY, size = 0x00;
  218. while((NumSpareAreaTowrite != 0x00) && (addressstatus == NAND_VALID_ADDRESS) && (status == NAND_READY))
  219. {
  220. /* Page write Spare area command and address */
  221. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_C;
  222. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE0;
  223. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
  224. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
  225. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
  226. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_4th_CYCLE(ROW_ADDRESS);
  227. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_5fh_CYCLE(ROW_ADDRESS);
  228. /* Calculate the size */
  229. size = NAND_SPARE_AREA_SIZE + (NAND_SPARE_AREA_SIZE * numsparesreawritten);
  230. /* Write the data */
  231. for(; index < size; index++)
  232. {
  233. *(vu8 *)(Bank_NAND_ADDR | DATA_AREA) = pBuffer[index];
  234. }
  235. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE_TRUE1;
  236. /* Check status for successful operation */
  237. status = FSMC_NAND_GetStatus();
  238. if(status == NAND_READY)
  239. {
  240. numsparesreawritten++;
  241. NumSpareAreaTowrite--;
  242. /* Calculate Next page Address */
  243. addressstatus = FSMC_NAND_AddressIncrement(&Address);
  244. }
  245. }
  246. return (status | addressstatus);
  247. }
  248. /******************************************************************************
  249. * Function Name : FSMC_NAND_ReadSpareArea
  250. * Description : This routine read the spare area information from the specified
  251. * pages addresses.
  252. * Input : - pBuffer: pointer on the Buffer to fill
  253. * - Address: First page address
  254. * - NumSpareAreaToRead: Number of Spare Area to read
  255. * Output : None
  256. * Return : New status of the NAND operation. This parameter can be:
  257. * - NAND_TIMEOUT_ERROR: when the previous operation generate
  258. * a Timeout error
  259. * - NAND_READY: when memory is ready for the next operation
  260. * And the new status of the increment address operation. It can be:
  261. * - NAND_VALID_ADDRESS: When the new address is valid address
  262. * - NAND_INVALID_ADDRESS: When the new address is invalid address
  263. *******************************************************************************/
  264. u32 FSMC_NAND_ReadSpareArea(u8 *pBuffer, NAND_ADDRESS Address, u32 NumSpareAreaToRead)
  265. {
  266. u32 numsparearearead = 0x00, index = 0x00, addressstatus = NAND_VALID_ADDRESS;
  267. u32 status = NAND_READY, size = 0x00;
  268. while((NumSpareAreaToRead != 0x0) && (addressstatus == NAND_VALID_ADDRESS))
  269. {
  270. /* Page Read command and page address */
  271. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_C;
  272. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
  273. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
  274. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
  275. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_4th_CYCLE(ROW_ADDRESS);
  276. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_5fh_CYCLE(ROW_ADDRESS);
  277. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_TRUE1;
  278. /* Data Read */
  279. size = NAND_SPARE_AREA_SIZE + (NAND_SPARE_AREA_SIZE * numsparearearead);
  280. /* Get Data into Buffer */
  281. for ( ;index < size; index++)
  282. {
  283. pBuffer[index] = *(vu8 *)(Bank_NAND_ADDR | DATA_AREA);
  284. }
  285. numsparearearead++;
  286. NumSpareAreaToRead--;
  287. /* Calculate page address */
  288. addressstatus = FSMC_NAND_AddressIncrement(&Address);
  289. }
  290. status = FSMC_NAND_GetStatus();
  291. return (status | addressstatus);
  292. }
  293. /******************************************************************************
  294. * Function Name : FSMC_NAND_EraseBlock
  295. * Description : This routine erase complete block from NAND FLASH
  296. * Input : - Address: Any address into block to be erased
  297. * Output : None
  298. * Return : New status of the NAND operation. This parameter can be:
  299. * - NAND_TIMEOUT_ERROR: when the previous operation generate
  300. * a Timeout error
  301. * - NAND_READY: when memory is ready for the next operation
  302. *******************************************************************************/
  303. u32 FSMC_NAND_EraseBlock(NAND_ADDRESS Address)
  304. {
  305. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_ERASE0;
  306. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
  307. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
  308. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
  309. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_4th_CYCLE(ROW_ADDRESS);
  310. *(vu8 *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_5fh_CYCLE(ROW_ADDRESS);
  311. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_ERASE1;
  312. return (FSMC_NAND_GetStatus());
  313. }
  314. /******************************************************************************
  315. * Function Name : FSMC_NAND_Reset
  316. * Description : This routine reset the NAND FLASH
  317. * Input : None
  318. * Output : None
  319. * Return : NAND_READY
  320. *******************************************************************************/
  321. u32 FSMC_NAND_Reset(void)
  322. {
  323. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_RESET;
  324. return (NAND_READY);
  325. }
  326. /******************************************************************************
  327. * Function Name : FSMC_NAND_GetStatus
  328. * Description : Get the NAND operation status
  329. * Input : None
  330. * Output : None
  331. * Return : New status of the NAND operation. This parameter can be:
  332. * - NAND_TIMEOUT_ERROR: when the previous operation generate
  333. * a Timeout error
  334. * - NAND_READY: when memory is ready for the next operation
  335. *******************************************************************************/
  336. u32 FSMC_NAND_GetStatus(void)
  337. {
  338. u32 timeout = 0x1000000, status = NAND_READY;
  339. status = FSMC_NAND_ReadStatus();
  340. /* Wait for a NAND operation to complete or a TIMEOUT to occur */
  341. while ((status != NAND_READY) &&( timeout != 0x00))
  342. {
  343. status = FSMC_NAND_ReadStatus();
  344. timeout --;
  345. }
  346. if(timeout == 0x00)
  347. {
  348. status = NAND_TIMEOUT_ERROR;
  349. }
  350. /* Return the operation status */
  351. return (status);
  352. }
  353. /******************************************************************************
  354. * Function Name : FSMC_NAND_ReadStatus
  355. * Description : Reads the NAND memory status using the Read status command
  356. * Input : None
  357. * Output : None
  358. * Return : The status of the NAND memory. This parameter can be:
  359. * - NAND_BUSY: when memory is busy
  360. * - NAND_READY: when memory is ready for the next operation
  361. * - NAND_ERROR: when the previous operation gererates error
  362. *******************************************************************************/
  363. u32 FSMC_NAND_ReadStatus(void)
  364. {
  365. u32 data = 0x00, status = NAND_BUSY;
  366. /* Read status operation ------------------------------------ */
  367. *(vu8 *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_STATUS;
  368. data = *(vu8 *)(Bank_NAND_ADDR);
  369. if((data & NAND_ERROR) == NAND_ERROR)
  370. {
  371. status = NAND_ERROR;
  372. }
  373. else if((data & NAND_READY) == NAND_READY)
  374. {
  375. status = NAND_READY;
  376. }
  377. else
  378. {
  379. status = NAND_BUSY;
  380. }
  381. return (status);
  382. }
  383. /******************************************************************************
  384. * Function Name : NAND_AddressIncrement
  385. * Description : Increment the NAND memory address
  386. * Input : - Address: address to be incremented.
  387. * Output : None
  388. * Return : The new status of the increment address operation. It can be:
  389. * - NAND_VALID_ADDRESS: When the new address is valid address
  390. * - NAND_INVALID_ADDRESS: When the new address is invalid address
  391. *******************************************************************************/
  392. u32 FSMC_NAND_AddressIncrement(NAND_ADDRESS* Address)
  393. {
  394. u32 status = NAND_VALID_ADDRESS;
  395. Address->Page++;
  396. if(Address->Page == NAND_BLOCK_SIZE)
  397. {
  398. Address->Page = 0;
  399. Address->Block++;
  400. if(Address->Block == NAND_ZONE_SIZE)
  401. {
  402. Address->Block = 0;
  403. Address->Zone++;
  404. if(Address->Zone == NAND_MAX_ZONE)
  405. {
  406. status = NAND_INVALID_ADDRESS;
  407. }
  408. }
  409. }
  410. return (status);
  411. }
  412. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/