2 ******************************************************************************
3 * @file stm32f7xx_hal_nand.c
4 * @author MCD Application Team
7 * @brief NAND HAL module driver.
8 * This file provides a generic firmware to drive NAND memories mounted
12 ==============================================================================
13 ##### How to use this driver #####
14 ==============================================================================
16 This driver is a generic layered driver which contains a set of APIs used to
17 control NAND flash memories. It uses the FMC/FSMC layer functions to interface
18 with NAND devices. This driver is used as follows:
20 (+) NAND flash memory configuration sequence using the function HAL_NAND_Init()
21 with control and timing parameters for both common and attribute spaces.
23 (+) Read NAND flash memory maker and device IDs using the function
24 HAL_NAND_Read_ID(). The read information is stored in the NAND_ID_TypeDef
25 structure declared by the function caller.
27 (+) Access NAND flash memory by read/write operations using the functions
28 HAL_NAND_Read_Page()/HAL_NAND_Read_SpareArea(), HAL_NAND_Write_Page()/HAL_NAND_Write_SpareArea()
29 to read/write page(s)/spare area(s). These functions use specific device
30 information (Block, page size..) predefined by the user in the HAL_NAND_Info_TypeDef
31 structure. The read/write address information is contained by the Nand_Address_Typedef
32 structure passed as parameter.
34 (+) Perform NAND flash Reset chip operation using the function HAL_NAND_Reset().
36 (+) Perform NAND flash erase block operation using the function HAL_NAND_Erase_Block().
37 The erase block address information is contained in the Nand_Address_Typedef
38 structure passed as parameter.
40 (+) Read the NAND flash status operation using the function HAL_NAND_Read_Status().
42 (+) You can also control the NAND device by calling the control APIs HAL_NAND_ECC_Enable()/
43 HAL_NAND_ECC_Disable() to respectively enable/disable the ECC code correction
44 feature or the function HAL_NAND_GetECC() to get the ECC correction code.
46 (+) You can monitor the NAND device HAL state by calling the function
50 (@) This driver is a set of generic APIs which handle standard NAND flash operations.
51 If a NAND flash device contains different operations and/or implementations,
52 it should be implemented separately.
55 ******************************************************************************
58 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
60 * Redistribution and use in source and binary forms, with or without modification,
61 * are permitted provided that the following conditions are met:
62 * 1. Redistributions of source code must retain the above copyright notice,
63 * this list of conditions and the following disclaimer.
64 * 2. Redistributions in binary form must reproduce the above copyright notice,
65 * this list of conditions and the following disclaimer in the documentation
66 * and/or other materials provided with the distribution.
67 * 3. Neither the name of STMicroelectronics nor the names of its contributors
68 * may be used to endorse or promote products derived from this software
69 * without specific prior written permission.
71 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
72 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
74 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
75 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
76 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
77 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
78 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
79 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
80 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
82 ******************************************************************************
85 /* Includes ------------------------------------------------------------------*/
86 #include "stm32f7xx_hal.h"
88 /** @addtogroup STM32F7xx_HAL_Driver
93 #ifdef HAL_NAND_MODULE_ENABLED
95 /** @defgroup NAND NAND
96 * @brief NAND HAL module driver
100 /* Private typedef -----------------------------------------------------------*/
101 /* Private Constants ------------------------------------------------------------*/
102 /* Private macro -------------------------------------------------------------*/
103 /* Private variables ---------------------------------------------------------*/
104 /* Private function prototypes -----------------------------------------------*/
105 /* Exported functions ---------------------------------------------------------*/
107 /** @defgroup NAND_Exported_Functions NAND Exported Functions
111 /** @defgroup NAND_Exported_Functions_Group1 Initialization and de-initialization functions
112 * @brief Initialization and Configuration functions
115 ==============================================================================
116 ##### NAND Initialization and de-initialization functions #####
117 ==============================================================================
119 This section provides functions allowing to initialize/de-initialize
127 * @brief Perform NAND memory Initialization sequence
128 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
129 * the configuration information for NAND module.
130 * @param ComSpace_Timing: pointer to Common space timing structure
131 * @param AttSpace_Timing: pointer to Attribute space timing structure
134 HAL_StatusTypeDef
HAL_NAND_Init(NAND_HandleTypeDef
*hnand
, FMC_NAND_PCC_TimingTypeDef
*ComSpace_Timing
, FMC_NAND_PCC_TimingTypeDef
*AttSpace_Timing
)
136 /* Check the NAND handle state */
142 if(hnand
->State
== HAL_NAND_STATE_RESET
)
144 /* Allocate lock resource and initialize it */
145 hnand
->Lock
= HAL_UNLOCKED
;
146 /* Initialize the low level hardware (MSP) */
147 HAL_NAND_MspInit(hnand
);
150 /* Initialize NAND control Interface */
151 FMC_NAND_Init(hnand
->Instance
, &(hnand
->Init
));
153 /* Initialize NAND common space timing Interface */
154 FMC_NAND_CommonSpace_Timing_Init(hnand
->Instance
, ComSpace_Timing
, hnand
->Init
.NandBank
);
156 /* Initialize NAND attribute space timing Interface */
157 FMC_NAND_AttributeSpace_Timing_Init(hnand
->Instance
, AttSpace_Timing
, hnand
->Init
.NandBank
);
159 /* Enable the NAND device */
160 __FMC_NAND_ENABLE(hnand
->Instance
);
162 /* Update the NAND controller state */
163 hnand
->State
= HAL_NAND_STATE_READY
;
169 * @brief Perform NAND memory De-Initialization sequence
170 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
171 * the configuration information for NAND module.
174 HAL_StatusTypeDef
HAL_NAND_DeInit(NAND_HandleTypeDef
*hnand
)
176 /* Initialize the low level hardware (MSP) */
177 HAL_NAND_MspDeInit(hnand
);
179 /* Configure the NAND registers with their reset values */
180 FMC_NAND_DeInit(hnand
->Instance
, hnand
->Init
.NandBank
);
182 /* Reset the NAND controller state */
183 hnand
->State
= HAL_NAND_STATE_RESET
;
192 * @brief NAND MSP Init
193 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
194 * the configuration information for NAND module.
197 __weak
void HAL_NAND_MspInit(NAND_HandleTypeDef
*hnand
)
199 /* Prevent unused argument(s) compilation warning */
202 /* NOTE : This function Should not be modified, when the callback is needed,
203 the HAL_NAND_MspInit could be implemented in the user file
208 * @brief NAND MSP DeInit
209 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
210 * the configuration information for NAND module.
213 __weak
void HAL_NAND_MspDeInit(NAND_HandleTypeDef
*hnand
)
215 /* Prevent unused argument(s) compilation warning */
218 /* NOTE : This function Should not be modified, when the callback is needed,
219 the HAL_NAND_MspDeInit could be implemented in the user file
225 * @brief This function handles NAND device interrupt request.
226 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
227 * the configuration information for NAND module.
230 void HAL_NAND_IRQHandler(NAND_HandleTypeDef
*hnand
)
232 /* Check NAND interrupt Rising edge flag */
233 if(__FMC_NAND_GET_FLAG(hnand
->Instance
, hnand
->Init
.NandBank
, FMC_FLAG_RISING_EDGE
))
235 /* NAND interrupt callback*/
236 HAL_NAND_ITCallback(hnand
);
238 /* Clear NAND interrupt Rising edge pending bit */
239 __FMC_NAND_CLEAR_FLAG(hnand
->Instance
, FMC_FLAG_RISING_EDGE
);
242 /* Check NAND interrupt Level flag */
243 if(__FMC_NAND_GET_FLAG(hnand
->Instance
, hnand
->Init
.NandBank
, FMC_FLAG_LEVEL
))
245 /* NAND interrupt callback*/
246 HAL_NAND_ITCallback(hnand
);
248 /* Clear NAND interrupt Level pending bit */
249 __FMC_NAND_CLEAR_FLAG(hnand
->Instance
, FMC_FLAG_LEVEL
);
252 /* Check NAND interrupt Falling edge flag */
253 if(__FMC_NAND_GET_FLAG(hnand
->Instance
, hnand
->Init
.NandBank
, FMC_FLAG_FALLING_EDGE
))
255 /* NAND interrupt callback*/
256 HAL_NAND_ITCallback(hnand
);
258 /* Clear NAND interrupt Falling edge pending bit */
259 __FMC_NAND_CLEAR_FLAG(hnand
->Instance
, FMC_FLAG_FALLING_EDGE
);
262 /* Check NAND interrupt FIFO empty flag */
263 if(__FMC_NAND_GET_FLAG(hnand
->Instance
, hnand
->Init
.NandBank
, FMC_FLAG_FEMPT
))
265 /* NAND interrupt callback*/
266 HAL_NAND_ITCallback(hnand
);
268 /* Clear NAND interrupt FIFO empty pending bit */
269 __FMC_NAND_CLEAR_FLAG(hnand
->Instance
, FMC_FLAG_FEMPT
);
275 * @brief NAND interrupt feature callback
276 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
277 * the configuration information for NAND module.
280 __weak
void HAL_NAND_ITCallback(NAND_HandleTypeDef
*hnand
)
282 /* Prevent unused argument(s) compilation warning */
285 /* NOTE : This function Should not be modified, when the callback is needed,
286 the HAL_NAND_ITCallback could be implemented in the user file
294 /** @defgroup NAND_Exported_Functions_Group2 Input and Output functions
295 * @brief Input Output and memory control functions
298 ==============================================================================
299 ##### NAND Input and Output functions #####
300 ==============================================================================
302 This section provides functions allowing to use and control the NAND
310 * @brief Read the NAND memory electronic signature
311 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
312 * the configuration information for NAND module.
313 * @param pNAND_ID: NAND ID structure
316 HAL_StatusTypeDef
HAL_NAND_Read_ID(NAND_HandleTypeDef
*hnand
, NAND_IDTypeDef
*pNAND_ID
)
318 __IO
uint32_t data
= 0;
319 __IO
uint32_t data1
= 0;
320 uint32_t deviceAddress
= 0;
325 /* Check the NAND controller state */
326 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
331 /* Identify the device address */
332 deviceAddress
= NAND_DEVICE
;
334 /* Update the NAND controller state */
335 hnand
->State
= HAL_NAND_STATE_BUSY
;
337 /* Send Read ID command sequence */
338 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_READID
;
340 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = 0x00;
343 /* Read the electronic signature from NAND flash */
344 if (hnand
->Init
.MemoryDataWidth
== FMC_NAND_PCC_MEM_BUS_WIDTH_8
)
346 data
= *(__IO
uint32_t *)deviceAddress
;
348 /* Return the data read */
349 pNAND_ID
->Maker_Id
= ADDR_1ST_CYCLE(data
);
350 pNAND_ID
->Device_Id
= ADDR_2ND_CYCLE(data
);
351 pNAND_ID
->Third_Id
= ADDR_3RD_CYCLE(data
);
352 pNAND_ID
->Fourth_Id
= ADDR_4TH_CYCLE(data
);
356 data
= *(__IO
uint32_t *)deviceAddress
;
357 data1
= *((__IO
uint32_t *)deviceAddress
+ 4);
359 /* Return the data read */
360 pNAND_ID
->Maker_Id
= ADDR_1ST_CYCLE(data
);
361 pNAND_ID
->Device_Id
= ADDR_3RD_CYCLE(data
);
362 pNAND_ID
->Third_Id
= ADDR_1ST_CYCLE(data1
);
363 pNAND_ID
->Fourth_Id
= ADDR_3RD_CYCLE(data1
);
367 /* Update the NAND controller state */
368 hnand
->State
= HAL_NAND_STATE_READY
;
370 /* Process unlocked */
377 * @brief NAND memory reset
378 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
379 * the configuration information for NAND module.
382 HAL_StatusTypeDef
HAL_NAND_Reset(NAND_HandleTypeDef
*hnand
)
384 uint32_t deviceAddress
= 0;
389 /* Check the NAND controller state */
390 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
395 /* Identify the device address */
396 deviceAddress
= NAND_DEVICE
;
398 /* Update the NAND controller state */
399 hnand
->State
= HAL_NAND_STATE_BUSY
;
401 /* Send NAND reset command */
402 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = 0xFF;
405 /* Update the NAND controller state */
406 hnand
->State
= HAL_NAND_STATE_READY
;
408 /* Process unlocked */
416 * @brief Read Page(s) from NAND memory block (8-bits addressing)
417 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
418 * the configuration information for NAND module.
419 * @param pAddress : pointer to NAND address structure
420 * @param pBuffer : pointer to destination read buffer
421 * @param NumPageToRead : number of pages to read from block
424 HAL_StatusTypeDef
HAL_NAND_Read_Page_8b(NAND_HandleTypeDef
*hnand
, NAND_AddressTypeDef
*pAddress
, uint8_t *pBuffer
, uint32_t NumPageToRead
)
426 __IO
uint32_t index
= 0;
427 uint32_t deviceAddress
= 0, size
= 0, numPagesRead
= 0, nandAddress
= 0;
432 /* Check the NAND controller state */
433 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
438 /* Identify the device address */
439 deviceAddress
= NAND_DEVICE
;
441 /* Update the NAND controller state */
442 hnand
->State
= HAL_NAND_STATE_BUSY
;
444 /* NAND raw address calculation */
445 nandAddress
= ARRAY_ADDRESS(pAddress
, hnand
);
447 /* Page(s) read loop */
448 while((NumPageToRead
!= 0) && (nandAddress
< ((hnand
->Info
.BlockSize
) * (hnand
->Info
.PageSize
) * (hnand
->Info
.ZoneSize
))))
450 /* update the buffer size */
451 size
= (hnand
->Info
.PageSize
) + ((hnand
->Info
.PageSize
) * numPagesRead
);
453 /* Send read page command sequence */
454 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_A
;
456 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = 0x00;
458 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_1ST_CYCLE(nandAddress
);
460 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_2ND_CYCLE(nandAddress
);
462 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_3RD_CYCLE(nandAddress
);
465 /* for 512 and 1 GB devices, 4th cycle is required */
466 if(hnand
->Info
.BlockNbr
>= 1024)
468 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_4TH_CYCLE(nandAddress
);
472 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_TRUE1
;
475 if (hnand
->Init
.MemoryDataWidth
== FMC_NAND_MEM_BUS_WIDTH_8
)
477 /* Get Data into Buffer */
478 for(; index
< size
; index
++)
480 *(uint8_t *)pBuffer
++ = *(uint8_t *)deviceAddress
;
485 /* Get Data into Buffer */
486 for(; index
< size
; index
++)
488 *(uint16_t *)pBuffer
++ = *(uint16_t *)deviceAddress
;
492 /* Increment read pages number */
495 /* Decrement pages to read */
498 /* Increment the NAND address */
499 nandAddress
= (uint32_t)(nandAddress
+ (hnand
->Info
.PageSize
* 8));
502 /* Update the NAND controller state */
503 hnand
->State
= HAL_NAND_STATE_READY
;
505 /* Process unlocked */
513 * @brief Read Page(s) from NAND memory block (16-bits addressing)
514 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
515 * the configuration information for NAND module.
516 * @param pAddress : pointer to NAND address structure
517 * @param pBuffer : pointer to destination read buffer
518 * @param NumPageToRead : number of pages to read from block
521 HAL_StatusTypeDef
HAL_NAND_Read_Page_16b(NAND_HandleTypeDef
*hnand
, NAND_AddressTypeDef
*pAddress
, uint16_t *pBuffer
, uint32_t NumPageToRead
)
523 __IO
uint32_t index
= 0;
524 uint32_t deviceAddress
= 0, size
= 0, numPagesRead
= 0, nandAddress
= 0;
529 /* Check the NAND controller state */
530 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
535 /* Identify the device address */
536 deviceAddress
= NAND_DEVICE
;
538 /* Update the NAND controller state */
539 hnand
->State
= HAL_NAND_STATE_BUSY
;
541 /* NAND raw address calculation */
542 nandAddress
= ARRAY_ADDRESS(pAddress
, hnand
);
544 /* Page(s) read loop */
545 while((NumPageToRead
!= 0) && (nandAddress
< ((hnand
->Info
.BlockSize
) * (hnand
->Info
.PageSize
) * (hnand
->Info
.ZoneSize
))))
547 /* update the buffer size */
548 size
= (hnand
->Info
.PageSize
) + ((hnand
->Info
.PageSize
) * numPagesRead
);
550 /* Send read page command sequence */
551 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_A
;
553 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = 0x00;
555 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_1ST_CYCLE(nandAddress
);
557 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_2ND_CYCLE(nandAddress
);
559 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_3RD_CYCLE(nandAddress
);
562 /* for 512 and 1 GB devices, 4th cycle is required */
563 if(hnand
->Info
.BlockNbr
>= 1024)
565 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_4TH_CYCLE(nandAddress
);
569 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_TRUE1
;
572 /* Get Data into Buffer */
573 for(; index
< size
; index
++)
575 *(uint16_t *)pBuffer
++ = *(uint16_t *)deviceAddress
;
578 /* Increment read pages number */
581 /* Decrement pages to read */
584 /* Increment the NAND address */
585 nandAddress
= (uint32_t)(nandAddress
+ (hnand
->Info
.PageSize
* 8));
588 /* Update the NAND controller state */
589 hnand
->State
= HAL_NAND_STATE_READY
;
591 /* Process unlocked */
598 * @brief Write Page(s) to NAND memory block (8-bits addressing)
599 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
600 * the configuration information for NAND module.
601 * @param pAddress : pointer to NAND address structure
602 * @param pBuffer : pointer to source buffer to write
603 * @param NumPageToWrite : number of pages to write to block
606 HAL_StatusTypeDef
HAL_NAND_Write_Page_8b(NAND_HandleTypeDef
*hnand
, NAND_AddressTypeDef
*pAddress
, uint8_t *pBuffer
, uint32_t NumPageToWrite
)
608 __IO
uint32_t index
= 0;
609 uint32_t tickstart
= 0;
610 uint32_t deviceAddress
= 0, size
= 0, numPagesWritten
= 0, nandAddress
= 0;
615 /* Check the NAND controller state */
616 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
621 /* Identify the device address */
622 deviceAddress
= NAND_DEVICE
;
624 /* Update the NAND controller state */
625 hnand
->State
= HAL_NAND_STATE_BUSY
;
627 /* NAND raw address calculation */
628 nandAddress
= ARRAY_ADDRESS(pAddress
, hnand
);
630 /* Page(s) write loop */
631 while((NumPageToWrite
!= 0) && (nandAddress
< ((hnand
->Info
.BlockSize
) * (hnand
->Info
.PageSize
) * (hnand
->Info
.ZoneSize
))))
633 /* update the buffer size */
634 size
= (hnand
->Info
.PageSize
) + ((hnand
->Info
.PageSize
) * numPagesWritten
);
636 /* Send write page command sequence */
637 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_A
;
639 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_WRITE0
;
642 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = 0x00;
644 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_1ST_CYCLE(nandAddress
);
646 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_2ND_CYCLE(nandAddress
);
648 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_3RD_CYCLE(nandAddress
);
651 /* for 512 and 1 GB devices, 4th cycle is required */
652 if(hnand
->Info
.BlockNbr
>= 1024)
654 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_4TH_CYCLE(nandAddress
);
658 if (hnand
->Init
.MemoryDataWidth
== FMC_NAND_MEM_BUS_WIDTH_8
)
660 /* Write data to memory */
661 for(; index
< size
; index
++)
663 *(__IO
uint8_t *)deviceAddress
= *(uint8_t *)pBuffer
++;
669 /* Write data to memory */
670 for(; index
< size
; index
++)
672 *(__IO
uint16_t *)deviceAddress
= *(uint16_t *)pBuffer
++;
677 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_WRITE_TRUE1
;
680 /* Read status until NAND is ready */
681 while(HAL_NAND_Read_Status(hnand
) != NAND_READY
)
684 tickstart
= HAL_GetTick();
686 if((HAL_GetTick() - tickstart
) > NAND_WRITE_TIMEOUT
)
692 /* Increment written pages number */
695 /* Decrement pages to write */
698 /* Increment the NAND address */
699 nandAddress
= (uint32_t)(nandAddress
+ (hnand
->Info
.PageSize
* 8));
702 /* Update the NAND controller state */
703 hnand
->State
= HAL_NAND_STATE_READY
;
705 /* Process unlocked */
712 * @brief Write Page(s) to NAND memory block (16-bits addressing)
713 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
714 * the configuration information for NAND module.
715 * @param pAddress : pointer to NAND address structure
716 * @param pBuffer : pointer to source buffer to write
717 * @param NumPageToWrite : number of pages to write to block
720 HAL_StatusTypeDef
HAL_NAND_Write_Page_16b(NAND_HandleTypeDef
*hnand
, NAND_AddressTypeDef
*pAddress
, uint16_t *pBuffer
, uint32_t NumPageToWrite
)
722 __IO
uint32_t index
= 0;
723 uint32_t tickstart
= 0;
724 uint32_t deviceAddress
= 0, size
= 0, numPagesWritten
= 0, nandAddress
= 0;
729 /* Check the NAND controller state */
730 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
735 /* Identify the device address */
736 deviceAddress
= NAND_DEVICE
;
738 /* Update the NAND controller state */
739 hnand
->State
= HAL_NAND_STATE_BUSY
;
741 /* NAND raw address calculation */
742 nandAddress
= ARRAY_ADDRESS(pAddress
, hnand
);
744 /* Page(s) write loop */
745 while((NumPageToWrite
!= 0) && (nandAddress
< ((hnand
->Info
.BlockSize
) * (hnand
->Info
.PageSize
) * (hnand
->Info
.ZoneSize
))))
747 /* update the buffer size */
748 size
= (hnand
->Info
.PageSize
) + ((hnand
->Info
.PageSize
) * numPagesWritten
);
750 /* Send write page command sequence */
751 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_A
;
753 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_WRITE0
;
756 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = 0x00;
758 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_1ST_CYCLE(nandAddress
);
760 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_2ND_CYCLE(nandAddress
);
762 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_3RD_CYCLE(nandAddress
);
765 /* for 512 and 1 GB devices, 4th cycle is required */
766 if(hnand
->Info
.BlockNbr
>= 1024)
768 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_4TH_CYCLE(nandAddress
);
772 /* Write data to memory */
773 for(; index
< size
; index
++)
775 *(__IO
uint16_t *)deviceAddress
= *(uint16_t *)pBuffer
++;
779 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_WRITE_TRUE1
;
782 /* Read status until NAND is ready */
783 while(HAL_NAND_Read_Status(hnand
) != NAND_READY
)
786 tickstart
= HAL_GetTick();
788 if((HAL_GetTick() - tickstart
) > NAND_WRITE_TIMEOUT
)
794 /* Increment written pages number */
797 /* Decrement pages to write */
800 /* Increment the NAND address */
801 nandAddress
= (uint32_t)(nandAddress
+ (hnand
->Info
.PageSize
* 8));
804 /* Update the NAND controller state */
805 hnand
->State
= HAL_NAND_STATE_READY
;
807 /* Process unlocked */
814 * @brief Read Spare area(s) from NAND memory (8-bits addressing)
815 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
816 * the configuration information for NAND module.
817 * @param pAddress : pointer to NAND address structure
818 * @param pBuffer: pointer to source buffer to write
819 * @param NumSpareAreaToRead: Number of spare area to read
822 HAL_StatusTypeDef
HAL_NAND_Read_SpareArea_8b(NAND_HandleTypeDef
*hnand
, NAND_AddressTypeDef
*pAddress
, uint8_t *pBuffer
, uint32_t NumSpareAreaToRead
)
824 __IO
uint32_t index
= 0;
825 uint32_t deviceAddress
= 0, size
= 0, numSpareAreaRead
= 0, nandAddress
= 0;
830 /* Check the NAND controller state */
831 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
836 /* Identify the device address */
837 deviceAddress
= NAND_DEVICE
;
839 /* Update the NAND controller state */
840 hnand
->State
= HAL_NAND_STATE_BUSY
;
842 /* NAND raw address calculation */
843 nandAddress
= ARRAY_ADDRESS(pAddress
, hnand
);
845 /* Spare area(s) read loop */
846 while((NumSpareAreaToRead
!= 0) && (nandAddress
< ((hnand
->Info
.BlockSize
) * (hnand
->Info
.SpareAreaSize
) * (hnand
->Info
.ZoneSize
))))
848 /* update the buffer size */
849 size
= (hnand
->Info
.SpareAreaSize
) + ((hnand
->Info
.SpareAreaSize
) * numSpareAreaRead
);
851 /* Send read spare area command sequence */
852 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_C
;
854 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = 0x00;
856 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_1ST_CYCLE(nandAddress
);
858 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_2ND_CYCLE(nandAddress
);
860 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_3RD_CYCLE(nandAddress
);
863 /* for 512 and 1 GB devices, 4th cycle is required */
864 if(hnand
->Info
.BlockNbr
>= 1024)
866 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_4TH_CYCLE(nandAddress
);
870 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_TRUE1
;
873 /* Get Data into Buffer */
874 for(; index
< size
; index
++)
876 *(uint8_t *)pBuffer
++ = *(uint8_t *)deviceAddress
;
879 /* Increment read spare areas number */
882 /* Decrement spare areas to read */
883 NumSpareAreaToRead
--;
885 /* Increment the NAND address */
886 nandAddress
= (uint32_t)(nandAddress
+ (hnand
->Info
.SpareAreaSize
));
889 /* Update the NAND controller state */
890 hnand
->State
= HAL_NAND_STATE_READY
;
892 /* Process unlocked */
899 * @brief Read Spare area(s) from NAND memory (16-bits addressing)
900 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
901 * the configuration information for NAND module.
902 * @param pAddress : pointer to NAND address structure
903 * @param pBuffer: pointer to source buffer to write
904 * @param NumSpareAreaToRead: Number of spare area to read
907 HAL_StatusTypeDef
HAL_NAND_Read_SpareArea_16b(NAND_HandleTypeDef
*hnand
, NAND_AddressTypeDef
*pAddress
, uint16_t *pBuffer
, uint32_t NumSpareAreaToRead
)
909 __IO
uint32_t index
= 0;
910 uint32_t deviceAddress
= 0, size
= 0, numSpareAreaRead
= 0, nandAddress
= 0;
915 /* Check the NAND controller state */
916 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
921 /* Identify the device address */
922 deviceAddress
= NAND_DEVICE
;
924 /* Update the NAND controller state */
925 hnand
->State
= HAL_NAND_STATE_BUSY
;
927 /* NAND raw address calculation */
928 nandAddress
= ARRAY_ADDRESS(pAddress
, hnand
);
930 /* Spare area(s) read loop */
931 while((NumSpareAreaToRead
!= 0) && (nandAddress
< ((hnand
->Info
.BlockSize
) * (hnand
->Info
.SpareAreaSize
) * (hnand
->Info
.ZoneSize
))))
933 /* update the buffer size */
934 size
= (hnand
->Info
.SpareAreaSize
) + ((hnand
->Info
.SpareAreaSize
) * numSpareAreaRead
);
936 /* Send read spare area command sequence */
937 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_C
;
939 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = 0x00;
941 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_1ST_CYCLE(nandAddress
);
943 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_2ND_CYCLE(nandAddress
);
945 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_3RD_CYCLE(nandAddress
);
948 /* for 512 and 1 GB devices, 4th cycle is required */
949 if(hnand
->Info
.BlockNbr
>= 1024)
951 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_4TH_CYCLE(nandAddress
);
955 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_TRUE1
;
958 /* Get Data into Buffer */
959 for(; index
< size
; index
++)
961 *(uint16_t *)pBuffer
++ = *(uint16_t *)deviceAddress
;
964 /* Increment read spare areas number */
967 /* Decrement spare areas to read */
968 NumSpareAreaToRead
--;
970 /* Increment the NAND address */
971 nandAddress
= (uint32_t)(nandAddress
+ (hnand
->Info
.SpareAreaSize
));
974 /* Update the NAND controller state */
975 hnand
->State
= HAL_NAND_STATE_READY
;
977 /* Process unlocked */
984 * @brief Write Spare area(s) to NAND memory (8-bits addressing)
985 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
986 * the configuration information for NAND module.
987 * @param pAddress : pointer to NAND address structure
988 * @param pBuffer : pointer to source buffer to write
989 * @param NumSpareAreaTowrite : number of spare areas to write to block
992 HAL_StatusTypeDef
HAL_NAND_Write_SpareArea_8b(NAND_HandleTypeDef
*hnand
, NAND_AddressTypeDef
*pAddress
, uint8_t *pBuffer
, uint32_t NumSpareAreaTowrite
)
994 __IO
uint32_t index
= 0;
995 uint32_t tickstart
= 0;
996 uint32_t deviceAddress
= 0, size
= 0, numSpareAreaWritten
= 0, nandAddress
= 0;
1001 /* Check the NAND controller state */
1002 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
1007 /* Identify the device address */
1008 deviceAddress
= NAND_DEVICE
;
1010 /* Update the FMC_NAND controller state */
1011 hnand
->State
= HAL_NAND_STATE_BUSY
;
1013 /* NAND raw address calculation */
1014 nandAddress
= ARRAY_ADDRESS(pAddress
, hnand
);
1016 /* Spare area(s) write loop */
1017 while((NumSpareAreaTowrite
!= 0) && (nandAddress
< ((hnand
->Info
.BlockSize
) * (hnand
->Info
.SpareAreaSize
) * (hnand
->Info
.ZoneSize
))))
1019 /* update the buffer size */
1020 size
= (hnand
->Info
.SpareAreaSize
) + ((hnand
->Info
.SpareAreaSize
) * numSpareAreaWritten
);
1022 /* Send write Spare area command sequence */
1023 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_C
;
1025 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_WRITE0
;
1027 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = 0x00;
1029 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_1ST_CYCLE(nandAddress
);
1031 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_2ND_CYCLE(nandAddress
);
1033 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_3RD_CYCLE(nandAddress
);
1035 /* for 512 and 1 GB devices, 4th cycle is required */
1036 if(hnand
->Info
.BlockNbr
>= 1024)
1038 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_4TH_CYCLE(nandAddress
);
1042 /* Write data to memory */
1043 for(; index
< size
; index
++)
1045 *(__IO
uint8_t *)deviceAddress
= *(uint8_t *)pBuffer
++;
1049 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_WRITE_TRUE1
;
1052 /* Read status until NAND is ready */
1053 while(HAL_NAND_Read_Status(hnand
) != NAND_READY
)
1056 tickstart
= HAL_GetTick();
1058 if((HAL_GetTick() - tickstart
) > NAND_WRITE_TIMEOUT
)
1064 /* Increment written spare areas number */
1065 numSpareAreaWritten
++;
1067 /* Decrement spare areas to write */
1068 NumSpareAreaTowrite
--;
1070 /* Increment the NAND address */
1071 nandAddress
= (uint32_t)(nandAddress
+ (hnand
->Info
.PageSize
));
1074 /* Update the NAND controller state */
1075 hnand
->State
= HAL_NAND_STATE_READY
;
1077 /* Process unlocked */
1078 __HAL_UNLOCK(hnand
);
1084 * @brief Write Spare area(s) to NAND memory (16-bits addressing)
1085 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
1086 * the configuration information for NAND module.
1087 * @param pAddress : pointer to NAND address structure
1088 * @param pBuffer : pointer to source buffer to write
1089 * @param NumSpareAreaTowrite : number of spare areas to write to block
1090 * @retval HAL status
1092 HAL_StatusTypeDef
HAL_NAND_Write_SpareArea_16b(NAND_HandleTypeDef
*hnand
, NAND_AddressTypeDef
*pAddress
, uint16_t *pBuffer
, uint32_t NumSpareAreaTowrite
)
1094 __IO
uint32_t index
= 0;
1095 uint32_t tickstart
= 0;
1096 uint32_t deviceAddress
= 0, size
= 0, numSpareAreaWritten
= 0, nandAddress
= 0;
1098 /* Process Locked */
1101 /* Check the NAND controller state */
1102 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
1107 /* Identify the device address */
1108 deviceAddress
= NAND_DEVICE
;
1110 /* Update the FMC_NAND controller state */
1111 hnand
->State
= HAL_NAND_STATE_BUSY
;
1113 /* NAND raw address calculation */
1114 nandAddress
= ARRAY_ADDRESS(pAddress
, hnand
);
1116 /* Spare area(s) write loop */
1117 while((NumSpareAreaTowrite
!= 0) && (nandAddress
< ((hnand
->Info
.BlockSize
) * (hnand
->Info
.SpareAreaSize
) * (hnand
->Info
.ZoneSize
))))
1119 /* update the buffer size */
1120 size
= (hnand
->Info
.SpareAreaSize
) + ((hnand
->Info
.SpareAreaSize
) * numSpareAreaWritten
);
1122 /* Send write Spare area command sequence */
1123 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_AREA_C
;
1125 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_WRITE0
;
1127 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = 0x00;
1129 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_1ST_CYCLE(nandAddress
);
1131 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_2ND_CYCLE(nandAddress
);
1133 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_3RD_CYCLE(nandAddress
);
1135 /* for 512 and 1 GB devices, 4th cycle is required */
1136 if(hnand
->Info
.BlockNbr
>= 1024)
1138 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| ADDR_AREA
)) = ADDR_4TH_CYCLE(nandAddress
);
1142 /* Write data to memory */
1143 for(; index
< size
; index
++)
1145 *(__IO
uint16_t *)deviceAddress
= *(uint16_t *)pBuffer
++;
1149 *(__IO
uint8_t *)((uint32_t)(deviceAddress
| CMD_AREA
)) = NAND_CMD_WRITE_TRUE1
;
1152 /* Read status until NAND is ready */
1153 while(HAL_NAND_Read_Status(hnand
) != NAND_READY
)
1156 tickstart
= HAL_GetTick();
1158 if((HAL_GetTick() - tickstart
) > NAND_WRITE_TIMEOUT
)
1164 /* Increment written spare areas number */
1165 numSpareAreaWritten
++;
1167 /* Decrement spare areas to write */
1168 NumSpareAreaTowrite
--;
1170 /* Increment the NAND address */
1171 nandAddress
= (uint32_t)(nandAddress
+ (hnand
->Info
.PageSize
));
1174 /* Update the NAND controller state */
1175 hnand
->State
= HAL_NAND_STATE_READY
;
1177 /* Process unlocked */
1178 __HAL_UNLOCK(hnand
);
1184 * @brief NAND memory Block erase
1185 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
1186 * the configuration information for NAND module.
1187 * @param pAddress : pointer to NAND address structure
1188 * @retval HAL status
1190 HAL_StatusTypeDef
HAL_NAND_Erase_Block(NAND_HandleTypeDef
*hnand
, NAND_AddressTypeDef
*pAddress
)
1192 uint32_t DeviceAddress
= 0;
1194 /* Process Locked */
1197 /* Check the NAND controller state */
1198 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
1203 /* Identify the device address */
1204 DeviceAddress
= NAND_DEVICE
;
1206 /* Update the NAND controller state */
1207 hnand
->State
= HAL_NAND_STATE_BUSY
;
1209 /* Send Erase block command sequence */
1210 *(__IO
uint8_t *)((uint32_t)(DeviceAddress
| CMD_AREA
)) = NAND_CMD_ERASE0
;
1212 *(__IO
uint8_t *)((uint32_t)(DeviceAddress
| ADDR_AREA
)) = ADDR_1ST_CYCLE(ARRAY_ADDRESS(pAddress
, hnand
));
1214 *(__IO
uint8_t *)((uint32_t)(DeviceAddress
| ADDR_AREA
)) = ADDR_2ND_CYCLE(ARRAY_ADDRESS(pAddress
, hnand
));
1216 *(__IO
uint8_t *)((uint32_t)(DeviceAddress
| ADDR_AREA
)) = ADDR_3RD_CYCLE(ARRAY_ADDRESS(pAddress
, hnand
));
1219 /* for 512 and 1 GB devices, 4th cycle is required */
1220 if(hnand
->Info
.BlockNbr
>= 1024)
1222 *(__IO
uint8_t *)((uint32_t)(DeviceAddress
| ADDR_AREA
)) = ADDR_4TH_CYCLE(ARRAY_ADDRESS(pAddress
, hnand
));
1226 *(__IO
uint8_t *)((uint32_t)(DeviceAddress
| CMD_AREA
)) = NAND_CMD_ERASE1
;
1229 /* Update the NAND controller state */
1230 hnand
->State
= HAL_NAND_STATE_READY
;
1232 /* Process unlocked */
1233 __HAL_UNLOCK(hnand
);
1239 * @brief NAND memory read status
1240 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
1241 * the configuration information for NAND module.
1242 * @retval NAND status
1244 uint32_t HAL_NAND_Read_Status(NAND_HandleTypeDef
*hnand
)
1247 uint32_t DeviceAddress
= 0;
1249 /* Identify the device address */
1250 DeviceAddress
= NAND_DEVICE
;
1252 /* Send Read status operation command */
1253 *(__IO
uint8_t *)((uint32_t)(DeviceAddress
| CMD_AREA
)) = NAND_CMD_STATUS
;
1255 /* Read status register data */
1256 data
= *(__IO
uint8_t *)DeviceAddress
;
1258 /* Return the status */
1259 if((data
& NAND_ERROR
) == NAND_ERROR
)
1263 else if((data
& NAND_READY
) == NAND_READY
)
1272 * @brief Increment the NAND memory address
1273 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
1274 * the configuration information for NAND module.
1275 * @param pAddress: pointer to NAND address structure
1276 * @retval The new status of the increment address operation. It can be:
1277 * - NAND_VALID_ADDRESS: When the new address is valid address
1278 * - NAND_INVALID_ADDRESS: When the new address is invalid address
1280 uint32_t HAL_NAND_Address_Inc(NAND_HandleTypeDef
*hnand
, NAND_AddressTypeDef
*pAddress
)
1282 uint32_t status
= NAND_VALID_ADDRESS
;
1284 /* Increment page address */
1287 /* Check NAND address is valid */
1288 if(pAddress
->Page
== hnand
->Info
.BlockSize
)
1293 if(pAddress
->Block
== hnand
->Info
.ZoneSize
)
1295 pAddress
->Block
= 0;
1298 if(pAddress
->Zone
== (hnand
->Info
.ZoneSize
/ hnand
->Info
.BlockNbr
))
1300 status
= NAND_INVALID_ADDRESS
;
1311 /** @defgroup NAND_Exported_Functions_Group3 Peripheral Control functions
1312 * @brief management functions
1315 ==============================================================================
1316 ##### NAND Control functions #####
1317 ==============================================================================
1319 This subsection provides a set of functions allowing to control dynamically
1328 * @brief Enables dynamically NAND ECC feature.
1329 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
1330 * the configuration information for NAND module.
1331 * @retval HAL status
1333 HAL_StatusTypeDef
HAL_NAND_ECC_Enable(NAND_HandleTypeDef
*hnand
)
1335 /* Check the NAND controller state */
1336 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
1341 /* Update the NAND state */
1342 hnand
->State
= HAL_NAND_STATE_BUSY
;
1344 /* Enable ECC feature */
1345 FMC_NAND_ECC_Enable(hnand
->Instance
, hnand
->Init
.NandBank
);
1347 /* Update the NAND state */
1348 hnand
->State
= HAL_NAND_STATE_READY
;
1354 * @brief Disables dynamically FMC_NAND ECC feature.
1355 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
1356 * the configuration information for NAND module.
1357 * @retval HAL status
1359 HAL_StatusTypeDef
HAL_NAND_ECC_Disable(NAND_HandleTypeDef
*hnand
)
1361 /* Check the NAND controller state */
1362 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
1367 /* Update the NAND state */
1368 hnand
->State
= HAL_NAND_STATE_BUSY
;
1370 /* Disable ECC feature */
1371 FMC_NAND_ECC_Disable(hnand
->Instance
, hnand
->Init
.NandBank
);
1373 /* Update the NAND state */
1374 hnand
->State
= HAL_NAND_STATE_READY
;
1380 * @brief Disables dynamically NAND ECC feature.
1381 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
1382 * the configuration information for NAND module.
1383 * @param ECCval: pointer to ECC value
1384 * @param Timeout: maximum timeout to wait
1385 * @retval HAL status
1387 HAL_StatusTypeDef
HAL_NAND_GetECC(NAND_HandleTypeDef
*hnand
, uint32_t *ECCval
, uint32_t Timeout
)
1389 HAL_StatusTypeDef status
= HAL_OK
;
1391 /* Check the NAND controller state */
1392 if(hnand
->State
== HAL_NAND_STATE_BUSY
)
1397 /* Update the NAND state */
1398 hnand
->State
= HAL_NAND_STATE_BUSY
;
1400 /* Get NAND ECC value */
1401 status
= FMC_NAND_GetECC(hnand
->Instance
, ECCval
, hnand
->Init
.NandBank
, Timeout
);
1403 /* Update the NAND state */
1404 hnand
->State
= HAL_NAND_STATE_READY
;
1414 /** @defgroup NAND_Exported_Functions_Group4 Peripheral State functions
1415 * @brief Peripheral State functions
1418 ==============================================================================
1419 ##### NAND State functions #####
1420 ==============================================================================
1422 This subsection permits to get in run-time the status of the NAND controller
1430 * @brief return the NAND state
1431 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
1432 * the configuration information for NAND module.
1435 HAL_NAND_StateTypeDef
HAL_NAND_GetState(NAND_HandleTypeDef
*hnand
)
1437 return hnand
->State
;
1448 #endif /* HAL_NAND_MODULE_ENABLED */
1458 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/