fsmc_nand.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
  2. * File Name : fsmc_nand.h
  3. * Author : MCD Application Team
  4. * Version : V2.0.3
  5. * Date : 09/22/2008
  6. * Description : Header for fsmc_nand.c file.
  7. ********************************************************************************
  8. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  9. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  10. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  11. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  12. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  13. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  14. *******************************************************************************/
  15. /* Define to prevent recursive inclusion -------------------------------------*/
  16. #ifndef __FSMC_NAND_H
  17. #define __FSMC_NAND_H
  18. /* Includes ------------------------------------------------------------------*/
  19. #include "stm32f10x.h"
  20. /* Exported types ------------------------------------------------------------*/
  21. typedef struct
  22. {
  23. u8 Maker_ID;
  24. u8 Device_ID;
  25. u8 Third_ID;
  26. u8 Fourth_ID;
  27. }NAND_IDTypeDef;
  28. typedef struct
  29. {
  30. u16 Zone;
  31. u16 Block;
  32. u16 Page;
  33. } NAND_ADDRESS;
  34. /* Exported constants --------------------------------------------------------*/
  35. /* NAND Area definition for STM3210E-EVAL Board RevD */
  36. #define CMD_AREA (u32)(1<<16) /* A16 = CLE high */
  37. #define ADDR_AREA (u32)(1<<17) /* A17 = ALE high */
  38. #define DATA_AREA ((u32)0x00000000)
  39. /* FSMC NAND memory command */
  40. #define NAND_CMD_AREA_A ((u8)0x00)
  41. #define NAND_CMD_AREA_B ((u8)0x01)
  42. #define NAND_CMD_AREA_C ((u8)0x50)
  43. #define NAND_CMD_AREA_TRUE1 ((u8)0x30)
  44. #define NAND_CMD_WRITE0 ((u8)0x80)
  45. #define NAND_CMD_WRITE_TRUE1 ((u8)0x10)
  46. #define NAND_CMD_ERASE0 ((u8)0x60)
  47. #define NAND_CMD_ERASE1 ((u8)0xD0)
  48. #define NAND_CMD_READID ((u8)0x90)
  49. #define NAND_CMD_STATUS ((u8)0x70)
  50. #define NAND_CMD_LOCK_STATUS ((u8)0x7A)
  51. #define NAND_CMD_RESET ((u8)0xFF)
  52. /* NAND memory status */
  53. #define NAND_VALID_ADDRESS ((u32)0x00000100)
  54. #define NAND_INVALID_ADDRESS ((u32)0x00000200)
  55. #define NAND_TIMEOUT_ERROR ((u32)0x00000400)
  56. #define NAND_BUSY ((u32)0x00000000)
  57. #define NAND_ERROR ((u32)0x00000001)
  58. #define NAND_READY ((u32)0x00000040)
  59. /* FSMC NAND memory parameters */
  60. //#define NAND_PAGE_SIZE ((u16)0x0200) /* 512 bytes per page w/o Spare Area */
  61. //#define NAND_BLOCK_SIZE ((u16)0x0020) /* 32x512 bytes pages per block */
  62. //#define NAND_ZONE_SIZE ((u16)0x0400) /* 1024 Block per zone */
  63. //#define NAND_SPARE_AREA_SIZE ((u16)0x0010) /* last 16 bytes as spare area */
  64. //#define NAND_MAX_ZONE ((u16)0x0004) /* 4 zones of 1024 block */
  65. /* FSMC NAND memory parameters */
  66. #define NAND_PAGE_SIZE ((u16)0x0800) /* 2K bytes per page w/o Spare Area */
  67. #define NAND_BLOCK_SIZE ((u16)0x0040) /* 64x2K bytes pages per block */
  68. #define NAND_ZONE_SIZE ((u16)0x0400) /* 1024 Block per zone */
  69. #define NAND_SPARE_AREA_SIZE ((u16)0x0040) /* last 64 bytes as spare area */
  70. #define NAND_MAX_ZONE ((u16)0x0002) /* 1 zones of 2048 block */
  71. /* FSMC NAND memory address computation */
  72. #define ADDR_1st_CYCLE(ADDR) (u8)((ADDR)& 0xFF) /* 1st addressing cycle */
  73. #define ADDR_2nd_CYCLE(ADDR) (u8)(((ADDR)& 0xFF00) >> 8) /* 2nd addressing cycle */
  74. #define ADDR_3rd_CYCLE(ADDR) (u8)(((ADDR)& 0xFF0000) >> 16) /* 3rd addressing cycle */
  75. #define ADDR_4th_CYCLE(ADDR) (u8)(((ADDR)& 0xFF000000) >> 24) /* 4th addressing cycle */
  76. #define ADDR_5fh_CYCLE(ADDR) (u8)(((ADDR)& 0xFF00000000) >> 32) /* 4th addressing cycle */
  77. /* Exported macro ------------------------------------------------------------*/
  78. /* Exported functions ------------------------------------------------------- */
  79. void FSMC_NAND_Init(void);
  80. void FSMC_NAND_ReadID(NAND_IDTypeDef* NAND_ID);
  81. u32 FSMC_NAND_WriteSmallPage(u8 *pBuffer, NAND_ADDRESS Address, u32 NumPageToWrite);
  82. u32 FSMC_NAND_ReadSmallPage (u8 *pBuffer, NAND_ADDRESS Address, u32 NumPageToRead);
  83. u32 FSMC_NAND_WriteSpareArea(u8 *pBuffer, NAND_ADDRESS Address, u32 NumSpareAreaTowrite);
  84. u32 FSMC_NAND_ReadSpareArea(u8 *pBuffer, NAND_ADDRESS Address, u32 NumSpareAreaToRead);
  85. u32 FSMC_NAND_EraseBlock(NAND_ADDRESS Address);
  86. u32 FSMC_NAND_Reset(void);
  87. u32 FSMC_NAND_GetStatus(void);
  88. u32 FSMC_NAND_ReadStatus(void);
  89. u32 FSMC_NAND_AddressIncrement(NAND_ADDRESS* Address);
  90. #endif /* __FSMC_NAND_H */
  91. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/