训练营PLSR题目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

389 lines
14 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_nand.h
  4. * @author MCD Application Team
  5. * @brief Header file of NAND HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32F4xx_HAL_NAND_H
  20. #define STM32F4xx_HAL_NAND_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if defined(FMC_Bank3) || defined(FMC_Bank2_3) || defined(FSMC_Bank2_3)
  25. /* Includes ------------------------------------------------------------------*/
  26. #if defined(FSMC_Bank2_3)
  27. #include "stm32f4xx_ll_fsmc.h"
  28. #else
  29. #include "stm32f4xx_ll_fmc.h"
  30. #endif /* FSMC_Bank2_3 */
  31. /** @addtogroup STM32F4xx_HAL_Driver
  32. * @{
  33. */
  34. /** @addtogroup NAND
  35. * @{
  36. */
  37. /* Exported typedef ----------------------------------------------------------*/
  38. /* Exported types ------------------------------------------------------------*/
  39. /** @defgroup NAND_Exported_Types NAND Exported Types
  40. * @{
  41. */
  42. /**
  43. * @brief HAL NAND State structures definition
  44. */
  45. typedef enum
  46. {
  47. HAL_NAND_STATE_RESET = 0x00U, /*!< NAND not yet initialized or disabled */
  48. HAL_NAND_STATE_READY = 0x01U, /*!< NAND initialized and ready for use */
  49. HAL_NAND_STATE_BUSY = 0x02U, /*!< NAND internal process is ongoing */
  50. HAL_NAND_STATE_ERROR = 0x03U /*!< NAND error state */
  51. } HAL_NAND_StateTypeDef;
  52. /**
  53. * @brief NAND Memory electronic signature Structure definition
  54. */
  55. typedef struct
  56. {
  57. /*<! NAND memory electronic signature maker and device IDs */
  58. uint8_t Maker_Id;
  59. uint8_t Device_Id;
  60. uint8_t Third_Id;
  61. uint8_t Fourth_Id;
  62. } NAND_IDTypeDef;
  63. /**
  64. * @brief NAND Memory address Structure definition
  65. */
  66. typedef struct
  67. {
  68. uint16_t Page; /*!< NAND memory Page address */
  69. uint16_t Plane; /*!< NAND memory Zone address */
  70. uint16_t Block; /*!< NAND memory Block address */
  71. } NAND_AddressTypeDef;
  72. /**
  73. * @brief NAND Memory info Structure definition
  74. */
  75. typedef struct
  76. {
  77. uint32_t PageSize; /*!< NAND memory page (without spare area) size measured in bytes
  78. for 8 bits addressing or words for 16 bits addressing */
  79. uint32_t SpareAreaSize; /*!< NAND memory spare area size measured in bytes
  80. for 8 bits addressing or words for 16 bits addressing */
  81. uint32_t BlockSize; /*!< NAND memory block size measured in number of pages */
  82. uint32_t BlockNbr; /*!< NAND memory number of total blocks */
  83. uint32_t PlaneNbr; /*!< NAND memory number of planes */
  84. uint32_t PlaneSize; /*!< NAND memory zone size measured in number of blocks */
  85. FunctionalState ExtraCommandEnable; /*!< NAND extra command needed for Page reading mode. This
  86. parameter is mandatory for some NAND parts after the read
  87. command (NAND_CMD_AREA_TRUE1) and before DATA reading sequence.
  88. Example: Toshiba THTH58BYG3S0HBAI6.
  89. This parameter could be ENABLE or DISABLE
  90. Please check the Read Mode sequnece in the NAND device datasheet */
  91. } NAND_DeviceConfigTypeDef;
  92. /**
  93. * @brief NAND handle Structure definition
  94. */
  95. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  96. typedef struct __NAND_HandleTypeDef
  97. #else
  98. typedef struct
  99. #endif /* USE_HAL_NAND_REGISTER_CALLBACKS */
  100. {
  101. FMC_NAND_TypeDef *Instance; /*!< Register base address */
  102. FMC_NAND_InitTypeDef Init; /*!< NAND device control configuration parameters */
  103. HAL_LockTypeDef Lock; /*!< NAND locking object */
  104. __IO HAL_NAND_StateTypeDef State; /*!< NAND device access state */
  105. NAND_DeviceConfigTypeDef Config; /*!< NAND phusical characteristic information structure */
  106. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  107. void (* MspInitCallback)(struct __NAND_HandleTypeDef *hnand); /*!< NAND Msp Init callback */
  108. void (* MspDeInitCallback)(struct __NAND_HandleTypeDef *hnand); /*!< NAND Msp DeInit callback */
  109. void (* ItCallback)(struct __NAND_HandleTypeDef *hnand); /*!< NAND IT callback */
  110. #endif /* USE_HAL_NAND_REGISTER_CALLBACKS */
  111. } NAND_HandleTypeDef;
  112. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  113. /**
  114. * @brief HAL NAND Callback ID enumeration definition
  115. */
  116. typedef enum
  117. {
  118. HAL_NAND_MSP_INIT_CB_ID = 0x00U, /*!< NAND MspInit Callback ID */
  119. HAL_NAND_MSP_DEINIT_CB_ID = 0x01U, /*!< NAND MspDeInit Callback ID */
  120. HAL_NAND_IT_CB_ID = 0x02U /*!< NAND IT Callback ID */
  121. } HAL_NAND_CallbackIDTypeDef;
  122. /**
  123. * @brief HAL NAND Callback pointer definition
  124. */
  125. typedef void (*pNAND_CallbackTypeDef)(NAND_HandleTypeDef *hnand);
  126. #endif /* USE_HAL_NAND_REGISTER_CALLBACKS */
  127. /**
  128. * @}
  129. */
  130. /* Exported constants --------------------------------------------------------*/
  131. /* Exported macro ------------------------------------------------------------*/
  132. /** @defgroup NAND_Exported_Macros NAND Exported Macros
  133. * @{
  134. */
  135. /** @brief Reset NAND handle state
  136. * @param __HANDLE__ specifies the NAND handle.
  137. * @retval None
  138. */
  139. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  140. #define __HAL_NAND_RESET_HANDLE_STATE(__HANDLE__) do { \
  141. (__HANDLE__)->State = HAL_NAND_STATE_RESET; \
  142. (__HANDLE__)->MspInitCallback = NULL; \
  143. (__HANDLE__)->MspDeInitCallback = NULL; \
  144. } while(0)
  145. #else
  146. #define __HAL_NAND_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_NAND_STATE_RESET)
  147. #endif /* USE_HAL_NAND_REGISTER_CALLBACKS */
  148. /**
  149. * @}
  150. */
  151. /* Exported functions --------------------------------------------------------*/
  152. /** @addtogroup NAND_Exported_Functions NAND Exported Functions
  153. * @{
  154. */
  155. /** @addtogroup NAND_Exported_Functions_Group1 Initialization and de-initialization functions
  156. * @{
  157. */
  158. /* Initialization/de-initialization functions ********************************/
  159. HAL_StatusTypeDef HAL_NAND_Init(NAND_HandleTypeDef *hnand, FMC_NAND_PCC_TimingTypeDef *ComSpace_Timing,
  160. FMC_NAND_PCC_TimingTypeDef *AttSpace_Timing);
  161. HAL_StatusTypeDef HAL_NAND_DeInit(NAND_HandleTypeDef *hnand);
  162. HAL_StatusTypeDef HAL_NAND_ConfigDevice(NAND_HandleTypeDef *hnand, NAND_DeviceConfigTypeDef *pDeviceConfig);
  163. HAL_StatusTypeDef HAL_NAND_Read_ID(NAND_HandleTypeDef *hnand, NAND_IDTypeDef *pNAND_ID);
  164. void HAL_NAND_MspInit(NAND_HandleTypeDef *hnand);
  165. void HAL_NAND_MspDeInit(NAND_HandleTypeDef *hnand);
  166. void HAL_NAND_IRQHandler(NAND_HandleTypeDef *hnand);
  167. void HAL_NAND_ITCallback(NAND_HandleTypeDef *hnand);
  168. /**
  169. * @}
  170. */
  171. /** @addtogroup NAND_Exported_Functions_Group2 Input and Output functions
  172. * @{
  173. */
  174. /* IO operation functions ****************************************************/
  175. HAL_StatusTypeDef HAL_NAND_Reset(NAND_HandleTypeDef *hnand);
  176. HAL_StatusTypeDef HAL_NAND_Read_Page_8b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint8_t *pBuffer,
  177. uint32_t NumPageToRead);
  178. HAL_StatusTypeDef HAL_NAND_Write_Page_8b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint8_t *pBuffer,
  179. uint32_t NumPageToWrite);
  180. HAL_StatusTypeDef HAL_NAND_Read_SpareArea_8b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress,
  181. uint8_t *pBuffer, uint32_t NumSpareAreaToRead);
  182. HAL_StatusTypeDef HAL_NAND_Write_SpareArea_8b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress,
  183. uint8_t *pBuffer, uint32_t NumSpareAreaTowrite);
  184. HAL_StatusTypeDef HAL_NAND_Read_Page_16b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint16_t *pBuffer,
  185. uint32_t NumPageToRead);
  186. HAL_StatusTypeDef HAL_NAND_Write_Page_16b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint16_t *pBuffer,
  187. uint32_t NumPageToWrite);
  188. HAL_StatusTypeDef HAL_NAND_Read_SpareArea_16b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress,
  189. uint16_t *pBuffer, uint32_t NumSpareAreaToRead);
  190. HAL_StatusTypeDef HAL_NAND_Write_SpareArea_16b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress,
  191. uint16_t *pBuffer, uint32_t NumSpareAreaTowrite);
  192. HAL_StatusTypeDef HAL_NAND_Erase_Block(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress);
  193. uint32_t HAL_NAND_Address_Inc(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress);
  194. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  195. /* NAND callback registering/unregistering */
  196. HAL_StatusTypeDef HAL_NAND_RegisterCallback(NAND_HandleTypeDef *hnand, HAL_NAND_CallbackIDTypeDef CallbackId,
  197. pNAND_CallbackTypeDef pCallback);
  198. HAL_StatusTypeDef HAL_NAND_UnRegisterCallback(NAND_HandleTypeDef *hnand, HAL_NAND_CallbackIDTypeDef CallbackId);
  199. #endif /* USE_HAL_NAND_REGISTER_CALLBACKS */
  200. /**
  201. * @}
  202. */
  203. /** @addtogroup NAND_Exported_Functions_Group3 Peripheral Control functions
  204. * @{
  205. */
  206. /* NAND Control functions ****************************************************/
  207. HAL_StatusTypeDef HAL_NAND_ECC_Enable(NAND_HandleTypeDef *hnand);
  208. HAL_StatusTypeDef HAL_NAND_ECC_Disable(NAND_HandleTypeDef *hnand);
  209. HAL_StatusTypeDef HAL_NAND_GetECC(NAND_HandleTypeDef *hnand, uint32_t *ECCval, uint32_t Timeout);
  210. /**
  211. * @}
  212. */
  213. /** @addtogroup NAND_Exported_Functions_Group4 Peripheral State functions
  214. * @{
  215. */
  216. /* NAND State functions *******************************************************/
  217. HAL_NAND_StateTypeDef HAL_NAND_GetState(NAND_HandleTypeDef *hnand);
  218. uint32_t HAL_NAND_Read_Status(NAND_HandleTypeDef *hnand);
  219. /**
  220. * @}
  221. */
  222. /**
  223. * @}
  224. */
  225. /* Private types -------------------------------------------------------------*/
  226. /* Private variables ---------------------------------------------------------*/
  227. /* Private constants ---------------------------------------------------------*/
  228. /** @defgroup NAND_Private_Constants NAND Private Constants
  229. * @{
  230. */
  231. #if defined(FMC_Bank2_3)
  232. #define NAND_DEVICE1 0x70000000UL
  233. #define NAND_DEVICE2 0x80000000UL
  234. #else
  235. #define NAND_DEVICE 0x80000000UL
  236. #endif
  237. #define NAND_WRITE_TIMEOUT 0x01000000UL
  238. #define CMD_AREA (1UL<<16U) /* A16 = CLE high */
  239. #define ADDR_AREA (1UL<<17U) /* A17 = ALE high */
  240. #define NAND_CMD_AREA_A ((uint8_t)0x00)
  241. #define NAND_CMD_AREA_B ((uint8_t)0x01)
  242. #define NAND_CMD_AREA_C ((uint8_t)0x50)
  243. #define NAND_CMD_AREA_TRUE1 ((uint8_t)0x30)
  244. #define NAND_CMD_WRITE0 ((uint8_t)0x80)
  245. #define NAND_CMD_WRITE_TRUE1 ((uint8_t)0x10)
  246. #define NAND_CMD_ERASE0 ((uint8_t)0x60)
  247. #define NAND_CMD_ERASE1 ((uint8_t)0xD0)
  248. #define NAND_CMD_READID ((uint8_t)0x90)
  249. #define NAND_CMD_STATUS ((uint8_t)0x70)
  250. #define NAND_CMD_LOCK_STATUS ((uint8_t)0x7A)
  251. #define NAND_CMD_RESET ((uint8_t)0xFF)
  252. /* NAND memory status */
  253. #define NAND_VALID_ADDRESS 0x00000100UL
  254. #define NAND_INVALID_ADDRESS 0x00000200UL
  255. #define NAND_TIMEOUT_ERROR 0x00000400UL
  256. #define NAND_BUSY 0x00000000UL
  257. #define NAND_ERROR 0x00000001UL
  258. #define NAND_READY 0x00000040UL
  259. /**
  260. * @}
  261. */
  262. /* Private macros ------------------------------------------------------------*/
  263. /** @defgroup NAND_Private_Macros NAND Private Macros
  264. * @{
  265. */
  266. /**
  267. * @brief NAND memory address computation.
  268. * @param __ADDRESS__ NAND memory address.
  269. * @param __HANDLE__ NAND handle.
  270. * @retval NAND Raw address value
  271. */
  272. #define ARRAY_ADDRESS(__ADDRESS__ , __HANDLE__) ((__ADDRESS__)->Page + \
  273. (((__ADDRESS__)->Block + \
  274. (((__ADDRESS__)->Plane) * \
  275. ((__HANDLE__)->Config.PlaneSize))) * \
  276. ((__HANDLE__)->Config.BlockSize)))
  277. /**
  278. * @brief NAND memory Column address computation.
  279. * @param __HANDLE__ NAND handle.
  280. * @retval NAND Raw address value
  281. */
  282. #define COLUMN_ADDRESS( __HANDLE__) ((__HANDLE__)->Config.PageSize)
  283. /**
  284. * @brief NAND memory address cycling.
  285. * @param __ADDRESS__ NAND memory address.
  286. * @retval NAND address cycling value.
  287. */
  288. #define ADDR_1ST_CYCLE(__ADDRESS__) (uint8_t)(__ADDRESS__) /* 1st addressing cycle */
  289. #define ADDR_2ND_CYCLE(__ADDRESS__) (uint8_t)((__ADDRESS__) >> 8) /* 2nd addressing cycle */
  290. #define ADDR_3RD_CYCLE(__ADDRESS__) (uint8_t)((__ADDRESS__) >> 16) /* 3rd addressing cycle */
  291. #define ADDR_4TH_CYCLE(__ADDRESS__) (uint8_t)((__ADDRESS__) >> 24) /* 4th addressing cycle */
  292. /**
  293. * @brief NAND memory Columns cycling.
  294. * @param __ADDRESS__ NAND memory address.
  295. * @retval NAND Column address cycling value.
  296. */
  297. #define COLUMN_1ST_CYCLE(__ADDRESS__) (uint8_t)((__ADDRESS__) & 0xFFU) /* 1st Column addressing cycle */
  298. #define COLUMN_2ND_CYCLE(__ADDRESS__) (uint8_t)((__ADDRESS__) >> 8) /* 2nd Column addressing cycle */
  299. /**
  300. * @}
  301. */
  302. /**
  303. * @}
  304. */
  305. /**
  306. * @}
  307. */
  308. /**
  309. * @}
  310. */
  311. #endif /* FMC_Bank3) || defined(FMC_Bank2_3) || defined(FSMC_Bank2_3 */
  312. #ifdef __cplusplus
  313. }
  314. #endif
  315. #endif /* STM32F4xx_HAL_NAND_H */