No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

388 líneas
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. This parameter could be ENABLE or DISABLE
  89. Please check the Read Mode sequence in the NAND device datasheet */
  90. } NAND_DeviceConfigTypeDef;
  91. /**
  92. * @brief NAND handle Structure definition
  93. */
  94. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  95. typedef struct __NAND_HandleTypeDef
  96. #else
  97. typedef struct
  98. #endif /* USE_HAL_NAND_REGISTER_CALLBACKS */
  99. {
  100. FMC_NAND_TypeDef *Instance; /*!< Register base address */
  101. FMC_NAND_InitTypeDef Init; /*!< NAND device control configuration parameters */
  102. HAL_LockTypeDef Lock; /*!< NAND locking object */
  103. __IO HAL_NAND_StateTypeDef State; /*!< NAND device access state */
  104. NAND_DeviceConfigTypeDef Config; /*!< NAND physical characteristic information structure */
  105. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  106. void (* MspInitCallback)(struct __NAND_HandleTypeDef *hnand); /*!< NAND Msp Init callback */
  107. void (* MspDeInitCallback)(struct __NAND_HandleTypeDef *hnand); /*!< NAND Msp DeInit callback */
  108. void (* ItCallback)(struct __NAND_HandleTypeDef *hnand); /*!< NAND IT callback */
  109. #endif /* USE_HAL_NAND_REGISTER_CALLBACKS */
  110. } NAND_HandleTypeDef;
  111. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  112. /**
  113. * @brief HAL NAND Callback ID enumeration definition
  114. */
  115. typedef enum
  116. {
  117. HAL_NAND_MSP_INIT_CB_ID = 0x00U, /*!< NAND MspInit Callback ID */
  118. HAL_NAND_MSP_DEINIT_CB_ID = 0x01U, /*!< NAND MspDeInit Callback ID */
  119. HAL_NAND_IT_CB_ID = 0x02U /*!< NAND IT Callback ID */
  120. } HAL_NAND_CallbackIDTypeDef;
  121. /**
  122. * @brief HAL NAND Callback pointer definition
  123. */
  124. typedef void (*pNAND_CallbackTypeDef)(NAND_HandleTypeDef *hnand);
  125. #endif /* USE_HAL_NAND_REGISTER_CALLBACKS */
  126. /**
  127. * @}
  128. */
  129. /* Exported constants --------------------------------------------------------*/
  130. /* Exported macro ------------------------------------------------------------*/
  131. /** @defgroup NAND_Exported_Macros NAND Exported Macros
  132. * @{
  133. */
  134. /** @brief Reset NAND handle state
  135. * @param __HANDLE__ specifies the NAND handle.
  136. * @retval None
  137. */
  138. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  139. #define __HAL_NAND_RESET_HANDLE_STATE(__HANDLE__) do { \
  140. (__HANDLE__)->State = HAL_NAND_STATE_RESET; \
  141. (__HANDLE__)->MspInitCallback = NULL; \
  142. (__HANDLE__)->MspDeInitCallback = NULL; \
  143. } while(0)
  144. #else
  145. #define __HAL_NAND_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_NAND_STATE_RESET)
  146. #endif /* USE_HAL_NAND_REGISTER_CALLBACKS */
  147. /**
  148. * @}
  149. */
  150. /* Exported functions --------------------------------------------------------*/
  151. /** @addtogroup NAND_Exported_Functions NAND Exported Functions
  152. * @{
  153. */
  154. /** @addtogroup NAND_Exported_Functions_Group1 Initialization and de-initialization functions
  155. * @{
  156. */
  157. /* Initialization/de-initialization functions ********************************/
  158. HAL_StatusTypeDef HAL_NAND_Init(NAND_HandleTypeDef *hnand, FMC_NAND_PCC_TimingTypeDef *ComSpace_Timing,
  159. FMC_NAND_PCC_TimingTypeDef *AttSpace_Timing);
  160. HAL_StatusTypeDef HAL_NAND_DeInit(NAND_HandleTypeDef *hnand);
  161. HAL_StatusTypeDef HAL_NAND_ConfigDevice(NAND_HandleTypeDef *hnand, const NAND_DeviceConfigTypeDef *pDeviceConfig);
  162. HAL_StatusTypeDef HAL_NAND_Read_ID(NAND_HandleTypeDef *hnand, NAND_IDTypeDef *pNAND_ID);
  163. void HAL_NAND_MspInit(NAND_HandleTypeDef *hnand);
  164. void HAL_NAND_MspDeInit(NAND_HandleTypeDef *hnand);
  165. void HAL_NAND_IRQHandler(NAND_HandleTypeDef *hnand);
  166. void HAL_NAND_ITCallback(NAND_HandleTypeDef *hnand);
  167. /**
  168. * @}
  169. */
  170. /** @addtogroup NAND_Exported_Functions_Group2 Input and Output functions
  171. * @{
  172. */
  173. /* IO operation functions ****************************************************/
  174. HAL_StatusTypeDef HAL_NAND_Reset(NAND_HandleTypeDef *hnand);
  175. HAL_StatusTypeDef HAL_NAND_Read_Page_8b(NAND_HandleTypeDef *hnand, const NAND_AddressTypeDef *pAddress,
  176. uint8_t *pBuffer, uint32_t NumPageToRead);
  177. HAL_StatusTypeDef HAL_NAND_Write_Page_8b(NAND_HandleTypeDef *hnand, const NAND_AddressTypeDef *pAddress,
  178. const uint8_t *pBuffer, uint32_t NumPageToWrite);
  179. HAL_StatusTypeDef HAL_NAND_Read_SpareArea_8b(NAND_HandleTypeDef *hnand, const NAND_AddressTypeDef *pAddress,
  180. uint8_t *pBuffer, uint32_t NumSpareAreaToRead);
  181. HAL_StatusTypeDef HAL_NAND_Write_SpareArea_8b(NAND_HandleTypeDef *hnand, const NAND_AddressTypeDef *pAddress,
  182. const uint8_t *pBuffer, uint32_t NumSpareAreaTowrite);
  183. HAL_StatusTypeDef HAL_NAND_Read_Page_16b(NAND_HandleTypeDef *hnand, const NAND_AddressTypeDef *pAddress,
  184. uint16_t *pBuffer, uint32_t NumPageToRead);
  185. HAL_StatusTypeDef HAL_NAND_Write_Page_16b(NAND_HandleTypeDef *hnand, const NAND_AddressTypeDef *pAddress,
  186. const uint16_t *pBuffer, uint32_t NumPageToWrite);
  187. HAL_StatusTypeDef HAL_NAND_Read_SpareArea_16b(NAND_HandleTypeDef *hnand, const NAND_AddressTypeDef *pAddress,
  188. uint16_t *pBuffer, uint32_t NumSpareAreaToRead);
  189. HAL_StatusTypeDef HAL_NAND_Write_SpareArea_16b(NAND_HandleTypeDef *hnand, const NAND_AddressTypeDef *pAddress,
  190. const uint16_t *pBuffer, uint32_t NumSpareAreaTowrite);
  191. HAL_StatusTypeDef HAL_NAND_Erase_Block(NAND_HandleTypeDef *hnand, const NAND_AddressTypeDef *pAddress);
  192. uint32_t HAL_NAND_Address_Inc(const NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress);
  193. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  194. /* NAND callback registering/unregistering */
  195. HAL_StatusTypeDef HAL_NAND_RegisterCallback(NAND_HandleTypeDef *hnand, HAL_NAND_CallbackIDTypeDef CallbackId,
  196. pNAND_CallbackTypeDef pCallback);
  197. HAL_StatusTypeDef HAL_NAND_UnRegisterCallback(NAND_HandleTypeDef *hnand, HAL_NAND_CallbackIDTypeDef CallbackId);
  198. #endif /* USE_HAL_NAND_REGISTER_CALLBACKS */
  199. /**
  200. * @}
  201. */
  202. /** @addtogroup NAND_Exported_Functions_Group3 Peripheral Control functions
  203. * @{
  204. */
  205. /* NAND Control functions ****************************************************/
  206. HAL_StatusTypeDef HAL_NAND_ECC_Enable(NAND_HandleTypeDef *hnand);
  207. HAL_StatusTypeDef HAL_NAND_ECC_Disable(NAND_HandleTypeDef *hnand);
  208. HAL_StatusTypeDef HAL_NAND_GetECC(NAND_HandleTypeDef *hnand, uint32_t *ECCval, uint32_t Timeout);
  209. /**
  210. * @}
  211. */
  212. /** @addtogroup NAND_Exported_Functions_Group4 Peripheral State functions
  213. * @{
  214. */
  215. /* NAND State functions *******************************************************/
  216. HAL_NAND_StateTypeDef HAL_NAND_GetState(const NAND_HandleTypeDef *hnand);
  217. uint32_t HAL_NAND_Read_Status(const NAND_HandleTypeDef *hnand);
  218. /**
  219. * @}
  220. */
  221. /**
  222. * @}
  223. */
  224. /* Private types -------------------------------------------------------------*/
  225. /* Private variables ---------------------------------------------------------*/
  226. /* Private constants ---------------------------------------------------------*/
  227. /** @defgroup NAND_Private_Constants NAND Private Constants
  228. * @{
  229. */
  230. #if defined(FMC_Bank2_3)
  231. #define NAND_DEVICE1 0x70000000UL
  232. #define NAND_DEVICE2 0x80000000UL
  233. #else
  234. #define NAND_DEVICE 0x80000000UL
  235. #endif /* FMC_Bank2_3 */
  236. #define NAND_WRITE_TIMEOUT 0x01000000UL
  237. #define CMD_AREA (1UL<<16U) /* A16 = CLE high */
  238. #define ADDR_AREA (1UL<<17U) /* A17 = ALE high */
  239. #define NAND_CMD_AREA_A ((uint8_t)0x00)
  240. #define NAND_CMD_AREA_B ((uint8_t)0x01)
  241. #define NAND_CMD_AREA_C ((uint8_t)0x50)
  242. #define NAND_CMD_AREA_TRUE1 ((uint8_t)0x30)
  243. #define NAND_CMD_WRITE0 ((uint8_t)0x80)
  244. #define NAND_CMD_WRITE_TRUE1 ((uint8_t)0x10)
  245. #define NAND_CMD_ERASE0 ((uint8_t)0x60)
  246. #define NAND_CMD_ERASE1 ((uint8_t)0xD0)
  247. #define NAND_CMD_READID ((uint8_t)0x90)
  248. #define NAND_CMD_STATUS ((uint8_t)0x70)
  249. #define NAND_CMD_LOCK_STATUS ((uint8_t)0x7A)
  250. #define NAND_CMD_RESET ((uint8_t)0xFF)
  251. /* NAND memory status */
  252. #define NAND_VALID_ADDRESS 0x00000100UL
  253. #define NAND_INVALID_ADDRESS 0x00000200UL
  254. #define NAND_TIMEOUT_ERROR 0x00000400UL
  255. #define NAND_BUSY 0x00000000UL
  256. #define NAND_ERROR 0x00000001UL
  257. #define NAND_READY 0x00000040UL
  258. /**
  259. * @}
  260. */
  261. /* Private macros ------------------------------------------------------------*/
  262. /** @defgroup NAND_Private_Macros NAND Private Macros
  263. * @{
  264. */
  265. /**
  266. * @brief NAND memory address computation.
  267. * @param __ADDRESS__ NAND memory address.
  268. * @param __HANDLE__ NAND handle.
  269. * @retval NAND Raw address value
  270. */
  271. #define ARRAY_ADDRESS(__ADDRESS__ , __HANDLE__) ((__ADDRESS__)->Page + \
  272. (((__ADDRESS__)->Block + \
  273. (((__ADDRESS__)->Plane) * \
  274. ((__HANDLE__)->Config.PlaneSize))) * \
  275. ((__HANDLE__)->Config.BlockSize)))
  276. /**
  277. * @brief NAND memory Column address computation.
  278. * @param __HANDLE__ NAND handle.
  279. * @retval NAND Raw address value
  280. */
  281. #define COLUMN_ADDRESS( __HANDLE__) ((__HANDLE__)->Config.PageSize)
  282. /**
  283. * @brief NAND memory address cycling.
  284. * @param __ADDRESS__ NAND memory address.
  285. * @retval NAND address cycling value.
  286. */
  287. #define ADDR_1ST_CYCLE(__ADDRESS__) (uint8_t)(__ADDRESS__) /* 1st addressing cycle */
  288. #define ADDR_2ND_CYCLE(__ADDRESS__) (uint8_t)((__ADDRESS__) >> 8) /* 2nd addressing cycle */
  289. #define ADDR_3RD_CYCLE(__ADDRESS__) (uint8_t)((__ADDRESS__) >> 16) /* 3rd addressing cycle */
  290. #define ADDR_4TH_CYCLE(__ADDRESS__) (uint8_t)((__ADDRESS__) >> 24) /* 4th addressing cycle */
  291. /**
  292. * @brief NAND memory Columns cycling.
  293. * @param __ADDRESS__ NAND memory address.
  294. * @retval NAND Column address cycling value.
  295. */
  296. #define COLUMN_1ST_CYCLE(__ADDRESS__) (uint8_t)((__ADDRESS__) & 0xFFU) /* 1st Column addressing cycle */
  297. #define COLUMN_2ND_CYCLE(__ADDRESS__) (uint8_t)((__ADDRESS__) >> 8) /* 2nd Column addressing cycle */
  298. /**
  299. * @}
  300. */
  301. /**
  302. * @}
  303. */
  304. /**
  305. * @}
  306. */
  307. /**
  308. * @}
  309. */
  310. #endif /* FMC_Bank3) || defined(FMC_Bank2_3) || defined(FSMC_Bank2_3 */
  311. #ifdef __cplusplus
  312. }
  313. #endif
  314. #endif /* STM32F4xx_HAL_NAND_H */