fsmc_nand.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
  2. * File Name : fsmc_nand.h
  3. * Author : MCD Application Team
  4. * Version : V3.1.0
  5. * Date : 10/30/2009
  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. uint8_t Maker_ID;
  24. uint8_t Device_ID;
  25. uint8_t Third_ID;
  26. uint8_t Fourth_ID;
  27. }NAND_IDTypeDef;
  28. typedef struct
  29. {
  30. uint16_t Zone;
  31. uint16_t Block;
  32. uint16_t Page;
  33. } NAND_ADDRESS;
  34. /* Exported constants --------------------------------------------------------*/
  35. /* NAND Area definition for STM3210E-EVAL Board RevD */
  36. #define CMD_AREA (uint32_t)(1<<16) /* A16 = CLE high */
  37. #define ADDR_AREA (uint32_t)(1<<17) /* A17 = ALE high */
  38. #define DATA_AREA ((uint32_t)0x00000000)
  39. /* FSMC NAND memory command */
  40. #define NAND_CMD_AREA_A ((uint8_t)0x00)
  41. #define NAND_CMD_AREA_B ((uint8_t)0x01)
  42. #define NAND_CMD_AREA_C ((uint8_t)0x50)
  43. #define NAND_CMD_AREA_TRUE1 ((uint8_t)0x30)
  44. #define NAND_CMD_WRITE0 ((uint8_t)0x80)
  45. #define NAND_CMD_WRITE_TRUE1 ((uint8_t)0x10)
  46. #define NAND_CMD_ERASE0 ((uint8_t)0x60)
  47. #define NAND_CMD_ERASE1 ((uint8_t)0xD0)
  48. #define NAND_CMD_READID ((uint8_t)0x90)
  49. #define NAND_CMD_STATUS ((uint8_t)0x70)
  50. #define NAND_CMD_LOCK_STATUS ((uint8_t)0x7A)
  51. #define NAND_CMD_RESET ((uint8_t)0xFF)
  52. /* NAND memory status */
  53. #define NAND_VALID_ADDRESS ((uint32_t)0x00000100)
  54. #define NAND_INVALID_ADDRESS ((uint32_t)0x00000200)
  55. #define NAND_TIMEOUT_ERROR ((uint32_t)0x00000400)
  56. #define NAND_BUSY ((uint32_t)0x00000000)
  57. #define NAND_ERROR ((uint32_t)0x00000001)
  58. #define NAND_READY ((uint32_t)0x00000040)
  59. /* FSMC NAND memory parameters */
  60. #define NAND_PAGE_SIZE ((uint16_t)0x0200) /* 512 bytes per page w/o Spare Area */
  61. #define NAND_BLOCK_SIZE ((uint16_t)0x0020) /* 32x512 bytes pages per block */
  62. #define NAND_ZONE_SIZE ((uint16_t)0x0400) /* 1024 Block per zone */
  63. #define NAND_SPARE_AREA_SIZE ((uint16_t)0x0010) /* last 16 bytes as spare area */
  64. #define NAND_MAX_ZONE ((uint16_t)0x0004) /* 4 zones of 1024 block */
  65. /* FSMC NAND memory address computation */
  66. #define ADDR_1st_CYCLE(ADDR) (uint8_t)((ADDR)& 0xFF) /* 1st addressing cycle */
  67. #define ADDR_2nd_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF00) >> 8) /* 2nd addressing cycle */
  68. #define ADDR_3rd_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF0000) >> 16) /* 3rd addressing cycle */
  69. #define ADDR_4th_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF000000) >> 24) /* 4th addressing cycle */
  70. /* Exported macro ------------------------------------------------------------*/
  71. /* Exported functions ------------------------------------------------------- */
  72. void FSMC_NAND_Init(void);
  73. void FSMC_NAND_ReadID(NAND_IDTypeDef* NAND_ID);
  74. uint32_t FSMC_NAND_WriteSmallPage(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToWrite);
  75. uint32_t FSMC_NAND_ReadSmallPage (uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToRead);
  76. uint32_t FSMC_NAND_WriteSpareArea(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumSpareAreaTowrite);
  77. uint32_t FSMC_NAND_ReadSpareArea(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumSpareAreaToRead);
  78. uint32_t FSMC_NAND_EraseBlock(NAND_ADDRESS Address);
  79. uint32_t FSMC_NAND_Reset(void);
  80. uint32_t FSMC_NAND_GetStatus(void);
  81. uint32_t FSMC_NAND_ReadStatus(void);
  82. uint32_t FSMC_NAND_AddressIncrement(NAND_ADDRESS* Address);
  83. #endif /* __FSMC_NAND_H */
  84. /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/