stm32f4xx_hal_nand.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_nand.c
  4. * @author MCD Application Team
  5. * @brief NAND HAL module driver.
  6. * This file provides a generic firmware to drive NAND memories mounted
  7. * as external device.
  8. *
  9. @verbatim
  10. ==============================================================================
  11. ##### How to use this driver #####
  12. ==============================================================================
  13. [..]
  14. This driver is a generic layered driver which contains a set of APIs used to
  15. control NAND flash memories. It uses the FMC/FSMC layer functions to interface
  16. with NAND devices. This driver is used as follows:
  17. (+) NAND flash memory configuration sequence using the function HAL_NAND_Init()
  18. with control and timing parameters for both common and attribute spaces.
  19. (+) Read NAND flash memory maker and device IDs using the function
  20. HAL_NAND_Read_ID(). The read information is stored in the NAND_ID_TypeDef
  21. structure declared by the function caller.
  22. (+) Access NAND flash memory by read/write operations using the functions
  23. HAL_NAND_Read_Page_8b()/HAL_NAND_Read_SpareArea_8b(),
  24. HAL_NAND_Write_Page_8b()/HAL_NAND_Write_SpareArea_8b(),
  25. HAL_NAND_Read_Page_16b()/HAL_NAND_Read_SpareArea_16b(),
  26. HAL_NAND_Write_Page_16b()/HAL_NAND_Write_SpareArea_16b()
  27. to read/write page(s)/spare area(s). These functions use specific device
  28. information (Block, page size..) predefined by the user in the HAL_NAND_Info_TypeDef
  29. structure. The read/write address information is contained by the Nand_Address_Typedef
  30. structure passed as parameter.
  31. (+) Perform NAND flash Reset chip operation using the function HAL_NAND_Reset().
  32. (+) Perform NAND flash erase block operation using the function HAL_NAND_Erase_Block().
  33. The erase block address information is contained in the Nand_Address_Typedef
  34. structure passed as parameter.
  35. (+) Read the NAND flash status operation using the function HAL_NAND_Read_Status().
  36. (+) You can also control the NAND device by calling the control APIs HAL_NAND_ECC_Enable()/
  37. HAL_NAND_ECC_Disable() to respectively enable/disable the ECC code correction
  38. feature or the function HAL_NAND_GetECC() to get the ECC correction code.
  39. (+) You can monitor the NAND device HAL state by calling the function
  40. HAL_NAND_GetState()
  41. [..]
  42. (@) This driver is a set of generic APIs which handle standard NAND flash operations.
  43. If a NAND flash device contains different operations and/or implementations,
  44. it should be implemented separately.
  45. *** Callback registration ***
  46. =============================================
  47. [..]
  48. The compilation define USE_HAL_NAND_REGISTER_CALLBACKS when set to 1
  49. allows the user to configure dynamically the driver callbacks.
  50. Use Functions @ref HAL_NAND_RegisterCallback() to register a user callback,
  51. it allows to register following callbacks:
  52. (+) MspInitCallback : NAND MspInit.
  53. (+) MspDeInitCallback : NAND MspDeInit.
  54. This function takes as parameters the HAL peripheral handle, the Callback ID
  55. and a pointer to the user callback function.
  56. Use function @ref HAL_NAND_UnRegisterCallback() to reset a callback to the default
  57. weak (surcharged) function. It allows to reset following callbacks:
  58. (+) MspInitCallback : NAND MspInit.
  59. (+) MspDeInitCallback : NAND MspDeInit.
  60. This function) takes as parameters the HAL peripheral handle and the Callback ID.
  61. By default, after the @ref HAL_NAND_Init and if the state is HAL_NAND_STATE_RESET
  62. all callbacks are reset to the corresponding legacy weak (surcharged) functions.
  63. Exception done for MspInit and MspDeInit callbacks that are respectively
  64. reset to the legacy weak (surcharged) functions in the @ref HAL_NAND_Init
  65. and @ref HAL_NAND_DeInit only when these callbacks are null (not registered beforehand).
  66. If not, MspInit or MspDeInit are not null, the @ref HAL_NAND_Init and @ref HAL_NAND_DeInit
  67. keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
  68. Callbacks can be registered/unregistered in READY state only.
  69. Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
  70. in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
  71. during the Init/DeInit.
  72. In that case first register the MspInit/MspDeInit user callbacks
  73. using @ref HAL_NAND_RegisterCallback before calling @ref HAL_NAND_DeInit
  74. or @ref HAL_NAND_Init function.
  75. When The compilation define USE_HAL_NAND_REGISTER_CALLBACKS is set to 0 or
  76. not defined, the callback registering feature is not available
  77. and weak (surcharged) callbacks are used.
  78. @endverbatim
  79. ******************************************************************************
  80. * @attention
  81. *
  82. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  83. * All rights reserved.</center></h2>
  84. *
  85. * This software component is licensed by ST under BSD 3-Clause license,
  86. * the "License"; You may not use this file except in compliance with the
  87. * License. You may obtain a copy of the License at:
  88. * opensource.org/licenses/BSD-3-Clause
  89. *
  90. ******************************************************************************
  91. */
  92. /* Includes ------------------------------------------------------------------*/
  93. #include "stm32f4xx_hal.h"
  94. /** @addtogroup STM32F4xx_HAL_Driver
  95. * @{
  96. */
  97. #ifdef HAL_NAND_MODULE_ENABLED
  98. #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
  99. defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  100. defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  101. /** @defgroup NAND NAND
  102. * @brief NAND HAL module driver
  103. * @{
  104. */
  105. /* Private typedef -----------------------------------------------------------*/
  106. /* Private define ------------------------------------------------------------*/
  107. /** @defgroup NAND_Private_Constants NAND Private Constants
  108. * @{
  109. */
  110. /**
  111. * @}
  112. */
  113. /* Private macro -------------------------------------------------------------*/
  114. /** @defgroup NAND_Private_Macros NAND Private Macros
  115. * @{
  116. */
  117. /**
  118. * @}
  119. */
  120. /* Private variables ---------------------------------------------------------*/
  121. /* Private function prototypes -----------------------------------------------*/
  122. /* Exported functions --------------------------------------------------------*/
  123. /** @defgroup NAND_Exported_Functions NAND Exported Functions
  124. * @{
  125. */
  126. /** @defgroup NAND_Exported_Functions_Group1 Initialization and de-initialization functions
  127. * @brief Initialization and Configuration functions
  128. *
  129. @verbatim
  130. ==============================================================================
  131. ##### NAND Initialization and de-initialization functions #####
  132. ==============================================================================
  133. [..]
  134. This section provides functions allowing to initialize/de-initialize
  135. the NAND memory
  136. @endverbatim
  137. * @{
  138. */
  139. /**
  140. * @brief Perform NAND memory Initialization sequence
  141. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  142. * the configuration information for NAND module.
  143. * @param ComSpace_Timing pointer to Common space timing structure
  144. * @param AttSpace_Timing pointer to Attribute space timing structure
  145. * @retval HAL status
  146. */
  147. HAL_StatusTypeDef HAL_NAND_Init(NAND_HandleTypeDef *hnand, FMC_NAND_PCC_TimingTypeDef *ComSpace_Timing, FMC_NAND_PCC_TimingTypeDef *AttSpace_Timing)
  148. {
  149. /* Check the NAND handle state */
  150. if(hnand == NULL)
  151. {
  152. return HAL_ERROR;
  153. }
  154. if(hnand->State == HAL_NAND_STATE_RESET)
  155. {
  156. /* Allocate lock resource and initialize it */
  157. hnand->Lock = HAL_UNLOCKED;
  158. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  159. if(hnand->MspInitCallback == NULL)
  160. {
  161. hnand->MspInitCallback = HAL_NAND_MspInit;
  162. }
  163. hnand->ItCallback = HAL_NAND_ITCallback;
  164. /* Init the low level hardware */
  165. hnand->MspInitCallback(hnand);
  166. #else
  167. /* Initialize the low level hardware (MSP) */
  168. HAL_NAND_MspInit(hnand);
  169. #endif
  170. }
  171. /* Initialize NAND control Interface */
  172. FMC_NAND_Init(hnand->Instance, &(hnand->Init));
  173. /* Initialize NAND common space timing Interface */
  174. FMC_NAND_CommonSpace_Timing_Init(hnand->Instance, ComSpace_Timing, hnand->Init.NandBank);
  175. /* Initialize NAND attribute space timing Interface */
  176. FMC_NAND_AttributeSpace_Timing_Init(hnand->Instance, AttSpace_Timing, hnand->Init.NandBank);
  177. /* Enable the NAND device */
  178. __FMC_NAND_ENABLE(hnand->Instance, hnand->Init.NandBank);
  179. /* Update the NAND controller state */
  180. hnand->State = HAL_NAND_STATE_READY;
  181. return HAL_OK;
  182. }
  183. /**
  184. * @brief Perform NAND memory De-Initialization sequence
  185. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  186. * the configuration information for NAND module.
  187. * @retval HAL status
  188. */
  189. HAL_StatusTypeDef HAL_NAND_DeInit(NAND_HandleTypeDef *hnand)
  190. {
  191. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  192. if(hnand->MspDeInitCallback == NULL)
  193. {
  194. hnand->MspDeInitCallback = HAL_NAND_MspDeInit;
  195. }
  196. /* DeInit the low level hardware */
  197. hnand->MspDeInitCallback(hnand);
  198. #else
  199. /* Initialize the low level hardware (MSP) */
  200. HAL_NAND_MspDeInit(hnand);
  201. #endif
  202. /* Configure the NAND registers with their reset values */
  203. FMC_NAND_DeInit(hnand->Instance, hnand->Init.NandBank);
  204. /* Reset the NAND controller state */
  205. hnand->State = HAL_NAND_STATE_RESET;
  206. /* Release Lock */
  207. __HAL_UNLOCK(hnand);
  208. return HAL_OK;
  209. }
  210. /**
  211. * @brief NAND MSP Init
  212. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  213. * the configuration information for NAND module.
  214. * @retval None
  215. */
  216. __weak void HAL_NAND_MspInit(NAND_HandleTypeDef *hnand)
  217. {
  218. /* Prevent unused argument(s) compilation warning */
  219. UNUSED(hnand);
  220. /* NOTE : This function Should not be modified, when the callback is needed,
  221. the HAL_NAND_MspInit could be implemented in the user file
  222. */
  223. }
  224. /**
  225. * @brief NAND MSP DeInit
  226. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  227. * the configuration information for NAND module.
  228. * @retval None
  229. */
  230. __weak void HAL_NAND_MspDeInit(NAND_HandleTypeDef *hnand)
  231. {
  232. /* Prevent unused argument(s) compilation warning */
  233. UNUSED(hnand);
  234. /* NOTE : This function Should not be modified, when the callback is needed,
  235. the HAL_NAND_MspDeInit could be implemented in the user file
  236. */
  237. }
  238. /**
  239. * @brief This function handles NAND device interrupt request.
  240. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  241. * the configuration information for NAND module.
  242. * @retval HAL status
  243. */
  244. void HAL_NAND_IRQHandler(NAND_HandleTypeDef *hnand)
  245. {
  246. /* Check NAND interrupt Rising edge flag */
  247. if(__FMC_NAND_GET_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_RISING_EDGE))
  248. {
  249. /* NAND interrupt callback*/
  250. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  251. hnand->ItCallback(hnand);
  252. #else
  253. HAL_NAND_ITCallback(hnand);
  254. #endif
  255. /* Clear NAND interrupt Rising edge pending bit */
  256. __FMC_NAND_CLEAR_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_RISING_EDGE);
  257. }
  258. /* Check NAND interrupt Level flag */
  259. if(__FMC_NAND_GET_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_LEVEL))
  260. {
  261. /* NAND interrupt callback*/
  262. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  263. hnand->ItCallback(hnand);
  264. #else
  265. HAL_NAND_ITCallback(hnand);
  266. #endif
  267. /* Clear NAND interrupt Level pending bit */
  268. __FMC_NAND_CLEAR_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_LEVEL);
  269. }
  270. /* Check NAND interrupt Falling edge flag */
  271. if(__FMC_NAND_GET_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_FALLING_EDGE))
  272. {
  273. /* NAND interrupt callback*/
  274. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  275. hnand->ItCallback(hnand);
  276. #else
  277. HAL_NAND_ITCallback(hnand);
  278. #endif
  279. /* Clear NAND interrupt Falling edge pending bit */
  280. __FMC_NAND_CLEAR_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_FALLING_EDGE);
  281. }
  282. /* Check NAND interrupt FIFO empty flag */
  283. if(__FMC_NAND_GET_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_FEMPT))
  284. {
  285. /* NAND interrupt callback*/
  286. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  287. hnand->ItCallback(hnand);
  288. #else
  289. HAL_NAND_ITCallback(hnand);
  290. #endif
  291. /* Clear NAND interrupt FIFO empty pending bit */
  292. __FMC_NAND_CLEAR_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_FEMPT);
  293. }
  294. }
  295. /**
  296. * @brief NAND interrupt feature callback
  297. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  298. * the configuration information for NAND module.
  299. * @retval None
  300. */
  301. __weak void HAL_NAND_ITCallback(NAND_HandleTypeDef *hnand)
  302. {
  303. /* Prevent unused argument(s) compilation warning */
  304. UNUSED(hnand);
  305. /* NOTE : This function Should not be modified, when the callback is needed,
  306. the HAL_NAND_ITCallback could be implemented in the user file
  307. */
  308. }
  309. /**
  310. * @}
  311. */
  312. /** @defgroup NAND_Exported_Functions_Group2 Input and Output functions
  313. * @brief Input Output and memory control functions
  314. *
  315. @verbatim
  316. ==============================================================================
  317. ##### NAND Input and Output functions #####
  318. ==============================================================================
  319. [..]
  320. This section provides functions allowing to use and control the NAND
  321. memory
  322. @endverbatim
  323. * @{
  324. */
  325. /**
  326. * @brief Read the NAND memory electronic signature
  327. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  328. * the configuration information for NAND module.
  329. * @param pNAND_ID NAND ID structure
  330. * @retval HAL status
  331. */
  332. HAL_StatusTypeDef HAL_NAND_Read_ID(NAND_HandleTypeDef *hnand, NAND_IDTypeDef *pNAND_ID)
  333. {
  334. __IO uint32_t data = 0U;
  335. __IO uint32_t data1 = 0U;
  336. uint32_t deviceaddress = 0U;
  337. /* Process Locked */
  338. __HAL_LOCK(hnand);
  339. /* Check the NAND controller state */
  340. if(hnand->State == HAL_NAND_STATE_BUSY)
  341. {
  342. return HAL_BUSY;
  343. }
  344. /* Identify the device address */
  345. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  346. {
  347. deviceaddress = NAND_DEVICE1;
  348. }
  349. else
  350. {
  351. deviceaddress = NAND_DEVICE2;
  352. }
  353. /* Update the NAND controller state */
  354. hnand->State = HAL_NAND_STATE_BUSY;
  355. /* Send Read ID command sequence */
  356. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_READID;
  357. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  358. /* Read the electronic signature from NAND flash */
  359. #ifdef FSMC_PCR2_PWID
  360. if (hnand->Init.MemoryDataWidth == FSMC_NAND_PCC_MEM_BUS_WIDTH_8)
  361. #else /* FMC_PCR2_PWID is defined */
  362. if (hnand->Init.MemoryDataWidth == FMC_NAND_PCC_MEM_BUS_WIDTH_8)
  363. #endif
  364. {
  365. data = *(__IO uint32_t *)deviceaddress;
  366. /* Return the data read */
  367. pNAND_ID->Maker_Id = ADDR_1ST_CYCLE(data);
  368. pNAND_ID->Device_Id = ADDR_2ND_CYCLE(data);
  369. pNAND_ID->Third_Id = ADDR_3RD_CYCLE(data);
  370. pNAND_ID->Fourth_Id = ADDR_4TH_CYCLE(data);
  371. }
  372. else
  373. {
  374. data = *(__IO uint32_t *)deviceaddress;
  375. data1 = *((__IO uint32_t *)deviceaddress + 4U);
  376. /* Return the data read */
  377. pNAND_ID->Maker_Id = ADDR_1ST_CYCLE(data);
  378. pNAND_ID->Device_Id = ADDR_3RD_CYCLE(data);
  379. pNAND_ID->Third_Id = ADDR_1ST_CYCLE(data1);
  380. pNAND_ID->Fourth_Id = ADDR_3RD_CYCLE(data1);
  381. }
  382. /* Update the NAND controller state */
  383. hnand->State = HAL_NAND_STATE_READY;
  384. /* Process unlocked */
  385. __HAL_UNLOCK(hnand);
  386. return HAL_OK;
  387. }
  388. /**
  389. * @brief NAND memory reset
  390. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  391. * the configuration information for NAND module.
  392. * @retval HAL status
  393. */
  394. HAL_StatusTypeDef HAL_NAND_Reset(NAND_HandleTypeDef *hnand)
  395. {
  396. uint32_t deviceaddress = 0U;
  397. /* Process Locked */
  398. __HAL_LOCK(hnand);
  399. /* Check the NAND controller state */
  400. if(hnand->State == HAL_NAND_STATE_BUSY)
  401. {
  402. return HAL_BUSY;
  403. }
  404. /* Identify the device address */
  405. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  406. {
  407. deviceaddress = NAND_DEVICE1;
  408. }
  409. else
  410. {
  411. deviceaddress = NAND_DEVICE2;
  412. }
  413. /* Update the NAND controller state */
  414. hnand->State = HAL_NAND_STATE_BUSY;
  415. /* Send NAND reset command */
  416. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = 0xFF;
  417. /* Update the NAND controller state */
  418. hnand->State = HAL_NAND_STATE_READY;
  419. /* Process unlocked */
  420. __HAL_UNLOCK(hnand);
  421. return HAL_OK;
  422. }
  423. /**
  424. * @brief Configure the device: Enter the physical parameters of the device
  425. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  426. * the configuration information for NAND module.
  427. * @param pDeviceConfig pointer to NAND_DeviceConfigTypeDef structure
  428. * @retval HAL status
  429. */
  430. HAL_StatusTypeDef HAL_NAND_ConfigDevice(NAND_HandleTypeDef *hnand, NAND_DeviceConfigTypeDef *pDeviceConfig)
  431. {
  432. hnand->Config.PageSize = pDeviceConfig->PageSize;
  433. hnand->Config.SpareAreaSize = pDeviceConfig->SpareAreaSize;
  434. hnand->Config.BlockSize = pDeviceConfig->BlockSize;
  435. hnand->Config.BlockNbr = pDeviceConfig->BlockNbr;
  436. hnand->Config.PlaneSize = pDeviceConfig->PlaneSize;
  437. hnand->Config.PlaneNbr = pDeviceConfig->PlaneNbr;
  438. hnand->Config.ExtraCommandEnable = pDeviceConfig->ExtraCommandEnable;
  439. return HAL_OK;
  440. }
  441. /**
  442. * @brief Read Page(s) from NAND memory block (8-bits addressing)
  443. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  444. * the configuration information for NAND module.
  445. * @param pAddress pointer to NAND address structure
  446. * @param pBuffer pointer to destination read buffer
  447. * @param NumPageToRead number of pages to read from block
  448. * @retval HAL status
  449. */
  450. HAL_StatusTypeDef HAL_NAND_Read_Page_8b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint8_t *pBuffer, uint32_t NumPageToRead)
  451. {
  452. __IO uint32_t index = 0U;
  453. uint32_t tickstart = 0U;
  454. uint32_t deviceaddress = 0U, size = 0U, numPagesRead = 0U, nandaddress = 0U;
  455. /* Process Locked */
  456. __HAL_LOCK(hnand);
  457. /* Check the NAND controller state */
  458. if(hnand->State == HAL_NAND_STATE_BUSY)
  459. {
  460. return HAL_BUSY;
  461. }
  462. /* Identify the device address */
  463. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  464. {
  465. deviceaddress = NAND_DEVICE1;
  466. }
  467. else
  468. {
  469. deviceaddress = NAND_DEVICE2;
  470. }
  471. /* Update the NAND controller state */
  472. hnand->State = HAL_NAND_STATE_BUSY;
  473. /* NAND raw address calculation */
  474. nandaddress = ARRAY_ADDRESS(pAddress, hnand);
  475. /* Page(s) read loop */
  476. while((NumPageToRead != 0U) && (nandaddress < ((hnand->Config.BlockSize) * (hnand->Config.BlockNbr))))
  477. {
  478. /* update the buffer size */
  479. size = (hnand->Config.PageSize) + ((hnand->Config.PageSize) * numPagesRead);
  480. /* Send read page command sequence */
  481. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_A;
  482. /* Cards with page size <= 512 bytes */
  483. if((hnand->Config.PageSize) <= 512U)
  484. {
  485. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  486. {
  487. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  488. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  489. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  490. }
  491. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  492. {
  493. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  494. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  495. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  496. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  497. }
  498. }
  499. else /* (hnand->Config.PageSize) > 512 */
  500. {
  501. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  502. {
  503. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  504. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  505. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  506. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  507. }
  508. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  509. {
  510. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  511. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  512. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  513. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  514. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  515. }
  516. }
  517. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_TRUE1;
  518. /* Check if an extra command is needed for reading pages */
  519. if(hnand->Config.ExtraCommandEnable == ENABLE)
  520. {
  521. /* Get tick */
  522. tickstart = HAL_GetTick();
  523. /* Read status until NAND is ready */
  524. while(HAL_NAND_Read_Status(hnand) != NAND_READY)
  525. {
  526. if((HAL_GetTick() - tickstart ) > NAND_WRITE_TIMEOUT)
  527. {
  528. return HAL_TIMEOUT;
  529. }
  530. }
  531. /* Go back to read mode */
  532. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = ((uint8_t)0x00);
  533. __DSB();
  534. }
  535. /* Get Data into Buffer */
  536. for(; index < size; index++)
  537. {
  538. *(uint8_t *)pBuffer++ = *(uint8_t *)deviceaddress;
  539. }
  540. /* Increment read pages number */
  541. numPagesRead++;
  542. /* Decrement pages to read */
  543. NumPageToRead--;
  544. /* Increment the NAND address */
  545. nandaddress = (uint32_t)(nandaddress + 1U);
  546. }
  547. /* Update the NAND controller state */
  548. hnand->State = HAL_NAND_STATE_READY;
  549. /* Process unlocked */
  550. __HAL_UNLOCK(hnand);
  551. return HAL_OK;
  552. }
  553. /**
  554. * @brief Read Page(s) from NAND memory block (16-bits addressing)
  555. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  556. * the configuration information for NAND module.
  557. * @param pAddress pointer to NAND address structure
  558. * @param pBuffer pointer to destination read buffer. pBuffer should be 16bits aligned
  559. * @param NumPageToRead number of pages to read from block
  560. * @retval HAL status
  561. */
  562. HAL_StatusTypeDef HAL_NAND_Read_Page_16b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint16_t *pBuffer, uint32_t NumPageToRead)
  563. {
  564. __IO uint32_t index = 0U;
  565. uint32_t tickstart = 0U;
  566. uint32_t deviceaddress = 0U, size = 0U, numPagesRead = 0U, nandaddress = 0U;
  567. /* Process Locked */
  568. __HAL_LOCK(hnand);
  569. /* Check the NAND controller state */
  570. if(hnand->State == HAL_NAND_STATE_BUSY)
  571. {
  572. return HAL_BUSY;
  573. }
  574. /* Identify the device address */
  575. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  576. {
  577. deviceaddress = NAND_DEVICE1;
  578. }
  579. else
  580. {
  581. deviceaddress = NAND_DEVICE2;
  582. }
  583. /* Update the NAND controller state */
  584. hnand->State = HAL_NAND_STATE_BUSY;
  585. /* NAND raw address calculation */
  586. nandaddress = ARRAY_ADDRESS(pAddress, hnand);
  587. /* Page(s) read loop */
  588. while((NumPageToRead != 0U) && (nandaddress < ((hnand->Config.BlockSize) * (hnand->Config.BlockNbr))))
  589. {
  590. /* update the buffer size */
  591. size = (hnand->Config.PageSize) + ((hnand->Config.PageSize) * numPagesRead);
  592. /* Send read page command sequence */
  593. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_A;
  594. __DSB();
  595. /* Cards with page size <= 512 bytes */
  596. if((hnand->Config.PageSize) <= 512U)
  597. {
  598. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  599. {
  600. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  601. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  602. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  603. }
  604. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  605. {
  606. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  607. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  608. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  609. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  610. }
  611. }
  612. else /* (hnand->Config.PageSize) > 512 */
  613. {
  614. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  615. {
  616. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  617. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  618. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  619. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  620. }
  621. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  622. {
  623. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  624. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  625. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  626. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  627. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  628. }
  629. }
  630. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_TRUE1;
  631. if(hnand->Config.ExtraCommandEnable == ENABLE)
  632. {
  633. /* Get tick */
  634. tickstart = HAL_GetTick();
  635. /* Read status until NAND is ready */
  636. while(HAL_NAND_Read_Status(hnand) != NAND_READY)
  637. {
  638. if((HAL_GetTick() - tickstart ) > NAND_WRITE_TIMEOUT)
  639. {
  640. return HAL_TIMEOUT;
  641. }
  642. }
  643. /* Go back to read mode */
  644. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = ((uint8_t)0x00);
  645. }
  646. /* Calculate PageSize */
  647. #ifdef FSMC_PCR2_PWID
  648. if (hnand->Init.MemoryDataWidth == FSMC_NAND_PCC_MEM_BUS_WIDTH_8)
  649. #else /* FMC_PCR2_PWID is defined */
  650. if (hnand->Init.MemoryDataWidth == FMC_NAND_PCC_MEM_BUS_WIDTH_8)
  651. #endif
  652. {
  653. size = size / 2U;
  654. }
  655. else
  656. {
  657. /* Do nothing */
  658. /* Keep the same PageSize for FMC_NAND_MEM_BUS_WIDTH_16*/
  659. }
  660. /* Get Data into Buffer */
  661. for(; index < size; index++)
  662. {
  663. *(uint16_t *)pBuffer++ = *(uint16_t *)deviceaddress;
  664. }
  665. /* Increment read pages number */
  666. numPagesRead++;
  667. /* Decrement pages to read */
  668. NumPageToRead--;
  669. /* Increment the NAND address */
  670. nandaddress = (uint32_t)(nandaddress + 1U);
  671. }
  672. /* Update the NAND controller state */
  673. hnand->State = HAL_NAND_STATE_READY;
  674. /* Process unlocked */
  675. __HAL_UNLOCK(hnand);
  676. return HAL_OK;
  677. }
  678. /**
  679. * @brief Write Page(s) to NAND memory block (8-bits addressing)
  680. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  681. * the configuration information for NAND module.
  682. * @param pAddress pointer to NAND address structure
  683. * @param pBuffer pointer to source buffer to write
  684. * @param NumPageToWrite number of pages to write to block
  685. * @retval HAL status
  686. */
  687. HAL_StatusTypeDef HAL_NAND_Write_Page_8b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint8_t *pBuffer, uint32_t NumPageToWrite)
  688. {
  689. __IO uint32_t index = 0U;
  690. uint32_t tickstart = 0U;
  691. uint32_t deviceaddress = 0U, size = 0U, numPagesWritten = 0U, nandaddress = 0U;
  692. /* Process Locked */
  693. __HAL_LOCK(hnand);
  694. /* Check the NAND controller state */
  695. if(hnand->State == HAL_NAND_STATE_BUSY)
  696. {
  697. return HAL_BUSY;
  698. }
  699. /* Identify the device address */
  700. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  701. {
  702. deviceaddress = NAND_DEVICE1;
  703. }
  704. else
  705. {
  706. deviceaddress = NAND_DEVICE2;
  707. }
  708. /* Update the NAND controller state */
  709. hnand->State = HAL_NAND_STATE_BUSY;
  710. /* NAND raw address calculation */
  711. nandaddress = ARRAY_ADDRESS(pAddress, hnand);
  712. /* Page(s) write loop */
  713. while((NumPageToWrite != 0U) && (nandaddress < ((hnand->Config.BlockSize) * (hnand->Config.BlockNbr))))
  714. {
  715. /* update the buffer size */
  716. size = hnand->Config.PageSize + ((hnand->Config.PageSize) * numPagesWritten);
  717. /* Send write page command sequence */
  718. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_A;
  719. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_WRITE0;
  720. /* Cards with page size <= 512 bytes */
  721. if((hnand->Config.PageSize) <= 512U)
  722. {
  723. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  724. {
  725. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  726. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  727. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  728. }
  729. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  730. {
  731. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  732. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  733. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  734. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  735. }
  736. }
  737. else /* (hnand->Config.PageSize) > 512 */
  738. {
  739. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  740. {
  741. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  742. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  743. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  744. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  745. }
  746. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  747. {
  748. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  749. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  750. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  751. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  752. __DSB();
  753. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  754. __DSB();
  755. }
  756. }
  757. /* Write data to memory */
  758. for(; index < size; index++)
  759. {
  760. *(__IO uint8_t *)deviceaddress = *(uint8_t *)pBuffer++;
  761. }
  762. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_WRITE_TRUE1;
  763. /* Get tick */
  764. tickstart = HAL_GetTick();
  765. /* Read status until NAND is ready */
  766. while(HAL_NAND_Read_Status(hnand) != NAND_READY)
  767. {
  768. if((HAL_GetTick() - tickstart ) > NAND_WRITE_TIMEOUT)
  769. {
  770. return HAL_TIMEOUT;
  771. }
  772. }
  773. /* Increment written pages number */
  774. numPagesWritten++;
  775. /* Decrement pages to write */
  776. NumPageToWrite--;
  777. /* Increment the NAND address */
  778. nandaddress = (uint32_t)(nandaddress + 1U);
  779. }
  780. /* Update the NAND controller state */
  781. hnand->State = HAL_NAND_STATE_READY;
  782. /* Process unlocked */
  783. __HAL_UNLOCK(hnand);
  784. return HAL_OK;
  785. }
  786. /**
  787. * @brief Write Page(s) to NAND memory block (16-bits addressing)
  788. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  789. * the configuration information for NAND module.
  790. * @param pAddress pointer to NAND address structure
  791. * @param pBuffer pointer to source buffer to write. pBuffer should be 16bits aligned
  792. * @param NumPageToWrite number of pages to write to block
  793. * @retval HAL status
  794. */
  795. HAL_StatusTypeDef HAL_NAND_Write_Page_16b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint16_t *pBuffer, uint32_t NumPageToWrite)
  796. {
  797. __IO uint32_t index = 0U;
  798. uint32_t tickstart = 0U;
  799. uint32_t deviceaddress = 0U, size = 0U, numPagesWritten = 0U, nandaddress = 0U;
  800. /* Process Locked */
  801. __HAL_LOCK(hnand);
  802. /* Check the NAND controller state */
  803. if(hnand->State == HAL_NAND_STATE_BUSY)
  804. {
  805. return HAL_BUSY;
  806. }
  807. /* Identify the device address */
  808. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  809. {
  810. deviceaddress = NAND_DEVICE1;
  811. }
  812. else
  813. {
  814. deviceaddress = NAND_DEVICE2;
  815. }
  816. /* Update the NAND controller state */
  817. hnand->State = HAL_NAND_STATE_BUSY;
  818. /* NAND raw address calculation */
  819. nandaddress = ARRAY_ADDRESS(pAddress, hnand);
  820. /* Page(s) write loop */
  821. while((NumPageToWrite != 0U) && (nandaddress < ((hnand->Config.BlockSize) * (hnand->Config.BlockNbr))))
  822. {
  823. /* update the buffer size */
  824. size = (hnand->Config.PageSize) + ((hnand->Config.PageSize) * numPagesWritten);
  825. /* Send write page command sequence */
  826. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_A;
  827. __DSB();
  828. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_WRITE0;
  829. __DSB();
  830. /* Cards with page size <= 512 bytes */
  831. if((hnand->Config.PageSize) <= 512U)
  832. {
  833. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  834. {
  835. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  836. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  837. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  838. }
  839. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  840. {
  841. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  842. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  843. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  844. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  845. }
  846. }
  847. else /* (hnand->Config.PageSize) > 512 */
  848. {
  849. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  850. {
  851. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  852. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  853. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  854. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  855. }
  856. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  857. {
  858. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  859. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  860. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  861. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  862. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  863. }
  864. }
  865. /* Calculate PageSize */
  866. #ifdef FSMC_PCR2_PWID
  867. if (hnand->Init.MemoryDataWidth == FSMC_NAND_PCC_MEM_BUS_WIDTH_8)
  868. #else /* FMC_PCR2_PWID is defined */
  869. if (hnand->Init.MemoryDataWidth == FMC_NAND_PCC_MEM_BUS_WIDTH_8)
  870. #endif
  871. {
  872. size = size / 2U;
  873. }
  874. else
  875. {
  876. /* Do nothing */
  877. /* Keep the same PageSize for FMC_NAND_MEM_BUS_WIDTH_16*/
  878. }
  879. /* Write data to memory */
  880. for(; index < size; index++)
  881. {
  882. *(__IO uint16_t *)deviceaddress = *(uint16_t *)pBuffer++;
  883. }
  884. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_WRITE_TRUE1;
  885. /* Get tick */
  886. tickstart = HAL_GetTick();
  887. /* Read status until NAND is ready */
  888. while(HAL_NAND_Read_Status(hnand) != NAND_READY)
  889. {
  890. if((HAL_GetTick() - tickstart ) > NAND_WRITE_TIMEOUT)
  891. {
  892. return HAL_TIMEOUT;
  893. }
  894. }
  895. /* Increment written pages number */
  896. numPagesWritten++;
  897. /* Decrement pages to write */
  898. NumPageToWrite--;
  899. /* Increment the NAND address */
  900. nandaddress = (uint32_t)(nandaddress + 1U);
  901. }
  902. /* Update the NAND controller state */
  903. hnand->State = HAL_NAND_STATE_READY;
  904. /* Process unlocked */
  905. __HAL_UNLOCK(hnand);
  906. return HAL_OK;
  907. }
  908. /**
  909. * @brief Read Spare area(s) from NAND memory
  910. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  911. * the configuration information for NAND module.
  912. * @param pAddress pointer to NAND address structure
  913. * @param pBuffer pointer to source buffer to write
  914. * @param NumSpareAreaToRead Number of spare area to read
  915. * @retval HAL status
  916. */
  917. HAL_StatusTypeDef HAL_NAND_Read_SpareArea_8b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint8_t *pBuffer, uint32_t NumSpareAreaToRead)
  918. {
  919. __IO uint32_t index = 0U;
  920. uint32_t tickstart = 0U;
  921. uint32_t deviceaddress = 0U, size = 0U, numSpareAreaRead = 0U, nandaddress = 0U, columnaddress = 0U;
  922. /* Process Locked */
  923. __HAL_LOCK(hnand);
  924. /* Check the NAND controller state */
  925. if(hnand->State == HAL_NAND_STATE_BUSY)
  926. {
  927. return HAL_BUSY;
  928. }
  929. /* Identify the device address */
  930. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  931. {
  932. deviceaddress = NAND_DEVICE1;
  933. }
  934. else
  935. {
  936. deviceaddress = NAND_DEVICE2;
  937. }
  938. /* Update the NAND controller state */
  939. hnand->State = HAL_NAND_STATE_BUSY;
  940. /* NAND raw address calculation */
  941. nandaddress = ARRAY_ADDRESS(pAddress, hnand);
  942. /* Column in page address */
  943. columnaddress = COLUMN_ADDRESS(hnand);
  944. /* Spare area(s) read loop */
  945. while((NumSpareAreaToRead != 0U) && (nandaddress < ((hnand->Config.BlockSize) * (hnand->Config.BlockNbr))))
  946. {
  947. /* update the buffer size */
  948. size = (hnand->Config.SpareAreaSize) + ((hnand->Config.SpareAreaSize) * numSpareAreaRead);
  949. /* Cards with page size <= 512 bytes */
  950. if((hnand->Config.PageSize) <= 512U)
  951. {
  952. /* Send read spare area command sequence */
  953. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_C;
  954. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  955. {
  956. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  957. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  958. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  959. }
  960. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  961. {
  962. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  963. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  964. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  965. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  966. }
  967. }
  968. else /* (hnand->Config.PageSize) > 512 */
  969. {
  970. /* Send read spare area command sequence */
  971. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_A;
  972. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  973. {
  974. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_1ST_CYCLE(columnaddress);
  975. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_2ND_CYCLE(columnaddress);
  976. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  977. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  978. }
  979. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  980. {
  981. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_1ST_CYCLE(columnaddress);
  982. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_2ND_CYCLE(columnaddress);
  983. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  984. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  985. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  986. }
  987. }
  988. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_TRUE1;
  989. if(hnand->Config.ExtraCommandEnable == ENABLE)
  990. {
  991. /* Get tick */
  992. tickstart = HAL_GetTick();
  993. /* Read status until NAND is ready */
  994. while(HAL_NAND_Read_Status(hnand) != NAND_READY)
  995. {
  996. if((HAL_GetTick() - tickstart ) > NAND_WRITE_TIMEOUT)
  997. {
  998. return HAL_TIMEOUT;
  999. }
  1000. }
  1001. /* Go back to read mode */
  1002. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = ((uint8_t)0x00);
  1003. }
  1004. /* Get Data into Buffer */
  1005. for(; index < size; index++)
  1006. {
  1007. *(uint8_t *)pBuffer++ = *(uint8_t *)deviceaddress;
  1008. }
  1009. /* Increment read spare areas number */
  1010. numSpareAreaRead++;
  1011. /* Decrement spare areas to read */
  1012. NumSpareAreaToRead--;
  1013. /* Increment the NAND address */
  1014. nandaddress = (uint32_t)(nandaddress + 1U);
  1015. }
  1016. /* Update the NAND controller state */
  1017. hnand->State = HAL_NAND_STATE_READY;
  1018. /* Process unlocked */
  1019. __HAL_UNLOCK(hnand);
  1020. return HAL_OK;
  1021. }
  1022. /**
  1023. * @brief Read Spare area(s) from NAND memory (16-bits addressing)
  1024. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  1025. * the configuration information for NAND module.
  1026. * @param pAddress pointer to NAND address structure
  1027. * @param pBuffer pointer to source buffer to write. pBuffer should be 16bits aligned.
  1028. * @param NumSpareAreaToRead Number of spare area to read
  1029. * @retval HAL status
  1030. */
  1031. HAL_StatusTypeDef HAL_NAND_Read_SpareArea_16b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint16_t *pBuffer, uint32_t NumSpareAreaToRead)
  1032. {
  1033. __IO uint32_t index = 0U;
  1034. uint32_t tickstart = 0U;
  1035. uint32_t deviceaddress = 0U, size = 0U, numSpareAreaRead = 0U, nandaddress = 0U, columnaddress = 0U;
  1036. /* Process Locked */
  1037. __HAL_LOCK(hnand);
  1038. /* Check the NAND controller state */
  1039. if(hnand->State == HAL_NAND_STATE_BUSY)
  1040. {
  1041. return HAL_BUSY;
  1042. }
  1043. /* Identify the device address */
  1044. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  1045. {
  1046. deviceaddress = NAND_DEVICE1;
  1047. }
  1048. else
  1049. {
  1050. deviceaddress = NAND_DEVICE2;
  1051. }
  1052. /* Update the NAND controller state */
  1053. hnand->State = HAL_NAND_STATE_BUSY;
  1054. /* NAND raw address calculation */
  1055. nandaddress = ARRAY_ADDRESS(pAddress, hnand);
  1056. /* Column in page address */
  1057. columnaddress = (uint32_t)(COLUMN_ADDRESS(hnand));
  1058. /* Spare area(s) read loop */
  1059. while((NumSpareAreaToRead != 0U) && (nandaddress < ((hnand->Config.BlockSize) * (hnand->Config.BlockNbr))))
  1060. {
  1061. /* update the buffer size */
  1062. size = (hnand->Config.SpareAreaSize) + ((hnand->Config.SpareAreaSize) * numSpareAreaRead);
  1063. /* Cards with page size <= 512 bytes */
  1064. if((hnand->Config.PageSize) <= 512U)
  1065. {
  1066. /* Send read spare area command sequence */
  1067. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_C;
  1068. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  1069. {
  1070. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  1071. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1072. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1073. }
  1074. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  1075. {
  1076. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  1077. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1078. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1079. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  1080. }
  1081. }
  1082. else /* (hnand->Config.PageSize) > 512 */
  1083. {
  1084. /* Send read spare area command sequence */
  1085. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_A;
  1086. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  1087. {
  1088. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_1ST_CYCLE(columnaddress);
  1089. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_2ND_CYCLE(columnaddress);
  1090. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1091. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1092. }
  1093. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  1094. {
  1095. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_1ST_CYCLE(columnaddress);
  1096. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_2ND_CYCLE(columnaddress);
  1097. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1098. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1099. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  1100. }
  1101. }
  1102. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_TRUE1;
  1103. if(hnand->Config.ExtraCommandEnable == ENABLE)
  1104. {
  1105. /* Get tick */
  1106. tickstart = HAL_GetTick();
  1107. /* Read status until NAND is ready */
  1108. while(HAL_NAND_Read_Status(hnand) != NAND_READY)
  1109. {
  1110. if((HAL_GetTick() - tickstart ) > NAND_WRITE_TIMEOUT)
  1111. {
  1112. return HAL_TIMEOUT;
  1113. }
  1114. }
  1115. /* Go back to read mode */
  1116. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = ((uint8_t)0x00);
  1117. }
  1118. /* Get Data into Buffer */
  1119. for(; index < size; index++)
  1120. {
  1121. *(uint16_t *)pBuffer++ = *(uint16_t *)deviceaddress;
  1122. }
  1123. /* Increment read spare areas number */
  1124. numSpareAreaRead++;
  1125. /* Decrement spare areas to read */
  1126. NumSpareAreaToRead--;
  1127. /* Increment the NAND address */
  1128. nandaddress = (uint32_t)(nandaddress + 1U);
  1129. }
  1130. /* Update the NAND controller state */
  1131. hnand->State = HAL_NAND_STATE_READY;
  1132. /* Process unlocked */
  1133. __HAL_UNLOCK(hnand);
  1134. return HAL_OK;
  1135. }
  1136. /**
  1137. * @brief Write Spare area(s) to NAND memory
  1138. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  1139. * the configuration information for NAND module.
  1140. * @param pAddress pointer to NAND address structure
  1141. * @param pBuffer pointer to source buffer to write
  1142. * @param NumSpareAreaTowrite number of spare areas to write to block
  1143. * @retval HAL status
  1144. */
  1145. HAL_StatusTypeDef HAL_NAND_Write_SpareArea_8b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint8_t *pBuffer, uint32_t NumSpareAreaTowrite)
  1146. {
  1147. __IO uint32_t index = 0U;
  1148. uint32_t tickstart = 0U;
  1149. uint32_t deviceaddress = 0U, size = 0U, numSpareAreaWritten = 0U, nandaddress = 0U, columnaddress = 0U;
  1150. /* Process Locked */
  1151. __HAL_LOCK(hnand);
  1152. /* Check the NAND controller state */
  1153. if(hnand->State == HAL_NAND_STATE_BUSY)
  1154. {
  1155. return HAL_BUSY;
  1156. }
  1157. /* Identify the device address */
  1158. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  1159. {
  1160. deviceaddress = NAND_DEVICE1;
  1161. }
  1162. else
  1163. {
  1164. deviceaddress = NAND_DEVICE2;
  1165. }
  1166. /* Update the FMC_NAND controller state */
  1167. hnand->State = HAL_NAND_STATE_BUSY;
  1168. /* Page address calculation */
  1169. nandaddress = ARRAY_ADDRESS(pAddress, hnand);
  1170. /* Column in page address */
  1171. columnaddress = COLUMN_ADDRESS(hnand);
  1172. /* Spare area(s) write loop */
  1173. while((NumSpareAreaTowrite != 0U) && (nandaddress < ((hnand->Config.BlockSize) * (hnand->Config.BlockNbr))))
  1174. {
  1175. /* update the buffer size */
  1176. size = (hnand->Config.SpareAreaSize) + ((hnand->Config.SpareAreaSize) * numSpareAreaWritten);
  1177. /* Cards with page size <= 512 bytes */
  1178. if((hnand->Config.PageSize) <= 512U)
  1179. {
  1180. /* Send write Spare area command sequence */
  1181. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_C;
  1182. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_WRITE0;
  1183. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  1184. {
  1185. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  1186. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1187. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1188. }
  1189. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  1190. {
  1191. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  1192. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1193. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1194. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  1195. }
  1196. }
  1197. else /* (hnand->Config.PageSize) > 512 */
  1198. {
  1199. /* Send write Spare area command sequence */
  1200. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_A;
  1201. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_WRITE0;
  1202. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  1203. {
  1204. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_1ST_CYCLE(columnaddress);
  1205. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_2ND_CYCLE(columnaddress);
  1206. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1207. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1208. }
  1209. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  1210. {
  1211. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_1ST_CYCLE(columnaddress);
  1212. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_2ND_CYCLE(columnaddress);
  1213. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1214. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1215. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  1216. }
  1217. }
  1218. /* Write data to memory */
  1219. for(; index < size; index++)
  1220. {
  1221. *(__IO uint8_t *)deviceaddress = *(uint8_t *)pBuffer++;
  1222. }
  1223. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_WRITE_TRUE1;
  1224. /* Get tick */
  1225. tickstart = HAL_GetTick();
  1226. /* Read status until NAND is ready */
  1227. while(HAL_NAND_Read_Status(hnand) != NAND_READY)
  1228. {
  1229. if((HAL_GetTick() - tickstart ) > NAND_WRITE_TIMEOUT)
  1230. {
  1231. return HAL_TIMEOUT;
  1232. }
  1233. }
  1234. /* Increment written spare areas number */
  1235. numSpareAreaWritten++;
  1236. /* Decrement spare areas to write */
  1237. NumSpareAreaTowrite--;
  1238. /* Increment the NAND address */
  1239. nandaddress = (uint32_t)(nandaddress + 1U);
  1240. }
  1241. /* Update the NAND controller state */
  1242. hnand->State = HAL_NAND_STATE_READY;
  1243. /* Process unlocked */
  1244. __HAL_UNLOCK(hnand);
  1245. return HAL_OK;
  1246. }
  1247. /**
  1248. * @brief Write Spare area(s) to NAND memory (16-bits addressing)
  1249. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  1250. * the configuration information for NAND module.
  1251. * @param pAddress pointer to NAND address structure
  1252. * @param pBuffer pointer to source buffer to write. pBuffer should be 16bits aligned.
  1253. * @param NumSpareAreaTowrite number of spare areas to write to block
  1254. * @retval HAL status
  1255. */
  1256. HAL_StatusTypeDef HAL_NAND_Write_SpareArea_16b(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress, uint16_t *pBuffer, uint32_t NumSpareAreaTowrite)
  1257. {
  1258. __IO uint32_t index = 0U;
  1259. uint32_t tickstart = 0U;
  1260. uint32_t deviceaddress = 0U, size = 0U, numSpareAreaWritten = 0U, nandaddress = 0U, columnaddress = 0U;
  1261. /* Process Locked */
  1262. __HAL_LOCK(hnand);
  1263. /* Check the NAND controller state */
  1264. if(hnand->State == HAL_NAND_STATE_BUSY)
  1265. {
  1266. return HAL_BUSY;
  1267. }
  1268. /* Identify the device address */
  1269. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  1270. {
  1271. deviceaddress = NAND_DEVICE1;
  1272. }
  1273. else
  1274. {
  1275. deviceaddress = NAND_DEVICE2;
  1276. }
  1277. /* Update the FMC_NAND controller state */
  1278. hnand->State = HAL_NAND_STATE_BUSY;
  1279. /* NAND raw address calculation */
  1280. nandaddress = ARRAY_ADDRESS(pAddress, hnand);
  1281. /* Column in page address */
  1282. columnaddress = (uint32_t)(COLUMN_ADDRESS(hnand));
  1283. /* Spare area(s) write loop */
  1284. while((NumSpareAreaTowrite != 0U) && (nandaddress < ((hnand->Config.BlockSize) * (hnand->Config.BlockNbr))))
  1285. {
  1286. /* update the buffer size */
  1287. size = (hnand->Config.SpareAreaSize) + ((hnand->Config.SpareAreaSize) * numSpareAreaWritten);
  1288. /* Cards with page size <= 512 bytes */
  1289. if((hnand->Config.PageSize) <= 512U)
  1290. {
  1291. /* Send write Spare area command sequence */
  1292. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_C;
  1293. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_WRITE0;
  1294. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  1295. {
  1296. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  1297. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1298. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1299. }
  1300. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  1301. {
  1302. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = 0x00;
  1303. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1304. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1305. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  1306. }
  1307. }
  1308. else /* (hnand->Config.PageSize) > 512 */
  1309. {
  1310. /* Send write Spare area command sequence */
  1311. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_AREA_A;
  1312. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_WRITE0;
  1313. if (((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) <= 65535U)
  1314. {
  1315. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_1ST_CYCLE(columnaddress);
  1316. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_2ND_CYCLE(columnaddress);
  1317. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1318. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1319. }
  1320. else /* ((hnand->Config.BlockSize)*(hnand->Config.BlockNbr)) > 65535 */
  1321. {
  1322. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_1ST_CYCLE(columnaddress);
  1323. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = COLUMN_2ND_CYCLE(columnaddress);
  1324. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(nandaddress);
  1325. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(nandaddress);
  1326. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(nandaddress);
  1327. }
  1328. }
  1329. /* Write data to memory */
  1330. for(; index < size; index++)
  1331. {
  1332. *(__IO uint16_t *)deviceaddress = *(uint16_t *)pBuffer++;
  1333. }
  1334. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_WRITE_TRUE1;
  1335. /* Get tick */
  1336. tickstart = HAL_GetTick();
  1337. /* Read status until NAND is ready */
  1338. while(HAL_NAND_Read_Status(hnand) != NAND_READY)
  1339. {
  1340. if((HAL_GetTick() - tickstart ) > NAND_WRITE_TIMEOUT)
  1341. {
  1342. return HAL_TIMEOUT;
  1343. }
  1344. }
  1345. /* Increment written spare areas number */
  1346. numSpareAreaWritten++;
  1347. /* Decrement spare areas to write */
  1348. NumSpareAreaTowrite--;
  1349. /* Increment the NAND address */
  1350. nandaddress = (uint32_t)(nandaddress + 1U);
  1351. }
  1352. /* Update the NAND controller state */
  1353. hnand->State = HAL_NAND_STATE_READY;
  1354. /* Process unlocked */
  1355. __HAL_UNLOCK(hnand);
  1356. return HAL_OK;
  1357. }
  1358. /**
  1359. * @brief NAND memory Block erase
  1360. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  1361. * the configuration information for NAND module.
  1362. * @param pAddress pointer to NAND address structure
  1363. * @retval HAL status
  1364. */
  1365. HAL_StatusTypeDef HAL_NAND_Erase_Block(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress)
  1366. {
  1367. uint32_t deviceaddress = 0U;
  1368. uint32_t tickstart = 0U;
  1369. /* Process Locked */
  1370. __HAL_LOCK(hnand);
  1371. /* Check the NAND controller state */
  1372. if(hnand->State == HAL_NAND_STATE_BUSY)
  1373. {
  1374. return HAL_BUSY;
  1375. }
  1376. /* Identify the device address */
  1377. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  1378. {
  1379. deviceaddress = NAND_DEVICE1;
  1380. }
  1381. else
  1382. {
  1383. deviceaddress = NAND_DEVICE2;
  1384. }
  1385. /* Update the NAND controller state */
  1386. hnand->State = HAL_NAND_STATE_BUSY;
  1387. /* Send Erase block command sequence */
  1388. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_ERASE0;
  1389. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_1ST_CYCLE(ARRAY_ADDRESS(pAddress, hnand));
  1390. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_2ND_CYCLE(ARRAY_ADDRESS(pAddress, hnand));
  1391. *(__IO uint8_t *)((uint32_t)(deviceaddress | ADDR_AREA)) = ADDR_3RD_CYCLE(ARRAY_ADDRESS(pAddress, hnand));
  1392. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_ERASE1;
  1393. /* Update the NAND controller state */
  1394. hnand->State = HAL_NAND_STATE_READY;
  1395. /* Get tick */
  1396. tickstart = HAL_GetTick();
  1397. /* Read status until NAND is ready */
  1398. while(HAL_NAND_Read_Status(hnand) != NAND_READY)
  1399. {
  1400. if((HAL_GetTick() - tickstart ) > NAND_WRITE_TIMEOUT)
  1401. {
  1402. /* Process unlocked */
  1403. __HAL_UNLOCK(hnand);
  1404. return HAL_TIMEOUT;
  1405. }
  1406. }
  1407. /* Process unlocked */
  1408. __HAL_UNLOCK(hnand);
  1409. return HAL_OK;
  1410. }
  1411. /**
  1412. * @brief NAND memory read status
  1413. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  1414. * the configuration information for NAND module.
  1415. * @retval NAND status
  1416. */
  1417. uint32_t HAL_NAND_Read_Status(NAND_HandleTypeDef *hnand)
  1418. {
  1419. uint32_t data = 0U;
  1420. uint32_t deviceaddress = 0U;
  1421. /* Identify the device address */
  1422. if(hnand->Init.NandBank == FMC_NAND_BANK2)
  1423. {
  1424. deviceaddress = NAND_DEVICE1;
  1425. }
  1426. else
  1427. {
  1428. deviceaddress = NAND_DEVICE2;
  1429. }
  1430. /* Send Read status operation command */
  1431. *(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = NAND_CMD_STATUS;
  1432. /* Read status register data */
  1433. data = *(__IO uint8_t *)deviceaddress;
  1434. /* Return the status */
  1435. if((data & NAND_ERROR) == NAND_ERROR)
  1436. {
  1437. return NAND_ERROR;
  1438. }
  1439. else if((data & NAND_READY) == NAND_READY)
  1440. {
  1441. return NAND_READY;
  1442. }
  1443. return NAND_BUSY;
  1444. }
  1445. /**
  1446. * @brief Increment the NAND memory address
  1447. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  1448. * the configuration information for NAND module.
  1449. * @param pAddress pointer to NAND address structure
  1450. * @retval The new status of the increment address operation. It can be:
  1451. * - NAND_VALID_ADDRESS: When the new address is valid address
  1452. * - NAND_INVALID_ADDRESS: When the new address is invalid address
  1453. */
  1454. uint32_t HAL_NAND_Address_Inc(NAND_HandleTypeDef *hnand, NAND_AddressTypeDef *pAddress)
  1455. {
  1456. uint32_t status = NAND_VALID_ADDRESS;
  1457. /* Increment page address */
  1458. pAddress->Page++;
  1459. /* Check NAND address is valid */
  1460. if(pAddress->Page == hnand->Config.BlockSize)
  1461. {
  1462. pAddress->Page = 0U;
  1463. pAddress->Block++;
  1464. if(pAddress->Block == hnand->Config.PlaneSize)
  1465. {
  1466. pAddress->Block = 0U;
  1467. pAddress->Plane++;
  1468. if(pAddress->Plane == (hnand->Config.PlaneNbr))
  1469. {
  1470. status = NAND_INVALID_ADDRESS;
  1471. }
  1472. }
  1473. }
  1474. return (status);
  1475. }
  1476. #if (USE_HAL_NAND_REGISTER_CALLBACKS == 1)
  1477. /**
  1478. * @brief Register a User NAND Callback
  1479. * To be used instead of the weak (surcharged) predefined callback
  1480. * @param hnand : NAND handle
  1481. * @param CallbackId : ID of the callback to be registered
  1482. * This parameter can be one of the following values:
  1483. * @arg @ref HAL_NAND_MSP_INIT_CB_ID NAND MspInit callback ID
  1484. * @arg @ref HAL_NAND_MSP_DEINIT_CB_ID NAND MspDeInit callback ID
  1485. * @arg @ref HAL_NAND_IT_CB_ID NAND IT callback ID
  1486. * @param pCallback : pointer to the Callback function
  1487. * @retval status
  1488. */
  1489. HAL_StatusTypeDef HAL_NAND_RegisterCallback (NAND_HandleTypeDef *hnand, HAL_NAND_CallbackIDTypeDef CallbackId, pNAND_CallbackTypeDef pCallback)
  1490. {
  1491. HAL_StatusTypeDef status = HAL_OK;
  1492. if(pCallback == NULL)
  1493. {
  1494. return HAL_ERROR;
  1495. }
  1496. /* Process locked */
  1497. __HAL_LOCK(hnand);
  1498. if(hnand->State == HAL_NAND_STATE_READY)
  1499. {
  1500. switch (CallbackId)
  1501. {
  1502. case HAL_NAND_MSP_INIT_CB_ID :
  1503. hnand->MspInitCallback = pCallback;
  1504. break;
  1505. case HAL_NAND_MSP_DEINIT_CB_ID :
  1506. hnand->MspDeInitCallback = pCallback;
  1507. break;
  1508. case HAL_NAND_IT_CB_ID :
  1509. hnand->ItCallback = pCallback;
  1510. break;
  1511. default :
  1512. /* update return status */
  1513. status = HAL_ERROR;
  1514. break;
  1515. }
  1516. }
  1517. else if(hnand->State == HAL_NAND_STATE_RESET)
  1518. {
  1519. switch (CallbackId)
  1520. {
  1521. case HAL_NAND_MSP_INIT_CB_ID :
  1522. hnand->MspInitCallback = pCallback;
  1523. break;
  1524. case HAL_NAND_MSP_DEINIT_CB_ID :
  1525. hnand->MspDeInitCallback = pCallback;
  1526. break;
  1527. default :
  1528. /* update return status */
  1529. status = HAL_ERROR;
  1530. break;
  1531. }
  1532. }
  1533. else
  1534. {
  1535. /* update return status */
  1536. status = HAL_ERROR;
  1537. }
  1538. /* Release Lock */
  1539. __HAL_UNLOCK(hnand);
  1540. return status;
  1541. }
  1542. /**
  1543. * @brief Unregister a User NAND Callback
  1544. * NAND Callback is redirected to the weak (surcharged) predefined callback
  1545. * @param hnand : NAND handle
  1546. * @param CallbackId : ID of the callback to be unregistered
  1547. * This parameter can be one of the following values:
  1548. * @arg @ref HAL_NAND_MSP_INIT_CB_ID NAND MspInit callback ID
  1549. * @arg @ref HAL_NAND_MSP_DEINIT_CB_ID NAND MspDeInit callback ID
  1550. * @arg @ref HAL_NAND_IT_CB_ID NAND IT callback ID
  1551. * @retval status
  1552. */
  1553. HAL_StatusTypeDef HAL_NAND_UnRegisterCallback (NAND_HandleTypeDef *hnand, HAL_NAND_CallbackIDTypeDef CallbackId)
  1554. {
  1555. HAL_StatusTypeDef status = HAL_OK;
  1556. /* Process locked */
  1557. __HAL_LOCK(hnand);
  1558. if(hnand->State == HAL_NAND_STATE_READY)
  1559. {
  1560. switch (CallbackId)
  1561. {
  1562. case HAL_NAND_MSP_INIT_CB_ID :
  1563. hnand->MspInitCallback = HAL_NAND_MspInit;
  1564. break;
  1565. case HAL_NAND_MSP_DEINIT_CB_ID :
  1566. hnand->MspDeInitCallback = HAL_NAND_MspDeInit;
  1567. break;
  1568. case HAL_NAND_IT_CB_ID :
  1569. hnand->ItCallback = HAL_NAND_ITCallback;
  1570. break;
  1571. default :
  1572. /* update return status */
  1573. status = HAL_ERROR;
  1574. break;
  1575. }
  1576. }
  1577. else if(hnand->State == HAL_NAND_STATE_RESET)
  1578. {
  1579. switch (CallbackId)
  1580. {
  1581. case HAL_NAND_MSP_INIT_CB_ID :
  1582. hnand->MspInitCallback = HAL_NAND_MspInit;
  1583. break;
  1584. case HAL_NAND_MSP_DEINIT_CB_ID :
  1585. hnand->MspDeInitCallback = HAL_NAND_MspDeInit;
  1586. break;
  1587. default :
  1588. /* update return status */
  1589. status = HAL_ERROR;
  1590. break;
  1591. }
  1592. }
  1593. else
  1594. {
  1595. /* update return status */
  1596. status = HAL_ERROR;
  1597. }
  1598. /* Release Lock */
  1599. __HAL_UNLOCK(hnand);
  1600. return status;
  1601. }
  1602. #endif
  1603. /**
  1604. * @}
  1605. */
  1606. /** @defgroup NAND_Exported_Functions_Group3 Peripheral Control functions
  1607. * @brief management functions
  1608. *
  1609. @verbatim
  1610. ==============================================================================
  1611. ##### NAND Control functions #####
  1612. ==============================================================================
  1613. [..]
  1614. This subsection provides a set of functions allowing to control dynamically
  1615. the NAND interface.
  1616. @endverbatim
  1617. * @{
  1618. */
  1619. /**
  1620. * @brief Enables dynamically NAND ECC feature.
  1621. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  1622. * the configuration information for NAND module.
  1623. * @retval HAL status
  1624. */
  1625. HAL_StatusTypeDef HAL_NAND_ECC_Enable(NAND_HandleTypeDef *hnand)
  1626. {
  1627. /* Check the NAND controller state */
  1628. if(hnand->State == HAL_NAND_STATE_BUSY)
  1629. {
  1630. return HAL_BUSY;
  1631. }
  1632. /* Update the NAND state */
  1633. hnand->State = HAL_NAND_STATE_BUSY;
  1634. /* Enable ECC feature */
  1635. FMC_NAND_ECC_Enable(hnand->Instance, hnand->Init.NandBank);
  1636. /* Update the NAND state */
  1637. hnand->State = HAL_NAND_STATE_READY;
  1638. return HAL_OK;
  1639. }
  1640. /**
  1641. * @brief Disables dynamically FMC_NAND ECC feature.
  1642. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  1643. * the configuration information for NAND module.
  1644. * @retval HAL status
  1645. */
  1646. HAL_StatusTypeDef HAL_NAND_ECC_Disable(NAND_HandleTypeDef *hnand)
  1647. {
  1648. /* Check the NAND controller state */
  1649. if(hnand->State == HAL_NAND_STATE_BUSY)
  1650. {
  1651. return HAL_BUSY;
  1652. }
  1653. /* Update the NAND state */
  1654. hnand->State = HAL_NAND_STATE_BUSY;
  1655. /* Disable ECC feature */
  1656. FMC_NAND_ECC_Disable(hnand->Instance, hnand->Init.NandBank);
  1657. /* Update the NAND state */
  1658. hnand->State = HAL_NAND_STATE_READY;
  1659. return HAL_OK;
  1660. }
  1661. /**
  1662. * @brief Disables dynamically NAND ECC feature.
  1663. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  1664. * the configuration information for NAND module.
  1665. * @param ECCval pointer to ECC value
  1666. * @param Timeout maximum timeout to wait
  1667. * @retval HAL status
  1668. */
  1669. HAL_StatusTypeDef HAL_NAND_GetECC(NAND_HandleTypeDef *hnand, uint32_t *ECCval, uint32_t Timeout)
  1670. {
  1671. HAL_StatusTypeDef status = HAL_OK;
  1672. /* Check the NAND controller state */
  1673. if(hnand->State == HAL_NAND_STATE_BUSY)
  1674. {
  1675. return HAL_BUSY;
  1676. }
  1677. /* Update the NAND state */
  1678. hnand->State = HAL_NAND_STATE_BUSY;
  1679. /* Get NAND ECC value */
  1680. status = FMC_NAND_GetECC(hnand->Instance, ECCval, hnand->Init.NandBank, Timeout);
  1681. /* Update the NAND state */
  1682. hnand->State = HAL_NAND_STATE_READY;
  1683. return status;
  1684. }
  1685. /**
  1686. * @}
  1687. */
  1688. /** @defgroup NAND_Exported_Functions_Group4 Peripheral State functions
  1689. * @brief Peripheral State functions
  1690. *
  1691. @verbatim
  1692. ==============================================================================
  1693. ##### NAND State functions #####
  1694. ==============================================================================
  1695. [..]
  1696. This subsection permits to get in run-time the status of the NAND controller
  1697. and the data flow.
  1698. @endverbatim
  1699. * @{
  1700. */
  1701. /**
  1702. * @brief return the NAND state
  1703. * @param hnand pointer to a NAND_HandleTypeDef structure that contains
  1704. * the configuration information for NAND module.
  1705. * @retval HAL state
  1706. */
  1707. HAL_NAND_StateTypeDef HAL_NAND_GetState(NAND_HandleTypeDef *hnand)
  1708. {
  1709. return hnand->State;
  1710. }
  1711. /**
  1712. * @}
  1713. */
  1714. /**
  1715. * @}
  1716. */
  1717. /**
  1718. * @}
  1719. */
  1720. #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx ||\
  1721. STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx ||\
  1722. STM32F446xx || STM32F469xx || STM32F479xx */
  1723. #endif /* HAL_NAND_MODULE_ENABLED */
  1724. /**
  1725. * @}
  1726. */
  1727. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/