Modified version of the mbed library for use with the Nucleo boards.

Dependents:   EEPROMWrite Full-Project

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Sep 28 20:15:09 2015 +0100
Revision:
634:ac7d6880524d
Parent:
632:7687fb9c4f91
Synchronized with git revision 9b7d23d47153c298a6d24de9a415202705889d11

Full URL: https://github.com/mbedmicro/mbed/commit/9b7d23d47153c298a6d24de9a415202705889d11/

Revert "[NUCLEO_F303K8] add support of the STM32F303K8"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 375:3d36234a1087 1 /**
mbed_official 375:3d36234a1087 2 ******************************************************************************
mbed_official 375:3d36234a1087 3 * @file stm32f3xx_hal_nand.c
mbed_official 375:3d36234a1087 4 * @author MCD Application Team
mbed_official 634:ac7d6880524d 5 * @version V1.1.0
mbed_official 634:ac7d6880524d 6 * @date 12-Sept-2014
mbed_official 375:3d36234a1087 7 * @brief NAND HAL module driver.
mbed_official 375:3d36234a1087 8 * This file provides a generic firmware to drive NAND memories mounted
mbed_official 375:3d36234a1087 9 * as external device.
mbed_official 375:3d36234a1087 10 *
mbed_official 375:3d36234a1087 11 @verbatim
mbed_official 375:3d36234a1087 12 ==============================================================================
mbed_official 375:3d36234a1087 13 ##### How to use this driver #####
mbed_official 375:3d36234a1087 14 ==============================================================================
mbed_official 375:3d36234a1087 15 [..]
mbed_official 375:3d36234a1087 16 This driver is a generic layered driver which contains a set of APIs used to
mbed_official 375:3d36234a1087 17 control NAND flash memories. It uses the FMC/FSMC layer functions to interface
mbed_official 375:3d36234a1087 18 with NAND devices. This driver is used as follows:
mbed_official 375:3d36234a1087 19
mbed_official 375:3d36234a1087 20 (+) NAND flash memory configuration sequence using the function HAL_NAND_Init()
mbed_official 375:3d36234a1087 21 with control and timing parameters for both common and attribute spaces.
mbed_official 375:3d36234a1087 22
mbed_official 375:3d36234a1087 23 (+) Read NAND flash memory maker and device IDs using the function
mbed_official 375:3d36234a1087 24 HAL_NAND_Read_ID(). The read information is stored in the NAND_ID_TypeDef
mbed_official 375:3d36234a1087 25 structure declared by the function caller.
mbed_official 375:3d36234a1087 26
mbed_official 375:3d36234a1087 27 (+) Access NAND flash memory by read/write operations using the functions
mbed_official 375:3d36234a1087 28 HAL_NAND_Read_Page()/HAL_NAND_Read_SpareArea(), HAL_NAND_Write_Page()/HAL_NAND_Write_SpareArea()
mbed_official 375:3d36234a1087 29 to read/write page(s)/spare area(s). These functions use specific device
mbed_official 375:3d36234a1087 30 information (Block, page size..) predefined by the user in the HAL_NAND_Info_TypeDef
mbed_official 375:3d36234a1087 31 structure. The read/write address information is contained by the Nand_Address_Typedef
mbed_official 375:3d36234a1087 32 structure passed as parameter.
mbed_official 375:3d36234a1087 33
mbed_official 375:3d36234a1087 34 (+) Perform NAND flash Reset chip operation using the function HAL_NAND_Reset().
mbed_official 375:3d36234a1087 35
mbed_official 375:3d36234a1087 36 (+) Perform NAND flash erase block operation using the function HAL_NAND_Erase_Block().
mbed_official 375:3d36234a1087 37 The erase block address information is contained in the Nand_Address_Typedef
mbed_official 375:3d36234a1087 38 structure passed as parameter.
mbed_official 375:3d36234a1087 39
mbed_official 375:3d36234a1087 40 (+) Read the NAND flash status operation using the function HAL_NAND_Read_Status().
mbed_official 375:3d36234a1087 41
mbed_official 375:3d36234a1087 42 (+) You can also control the NAND device by calling the control APIs HAL_NAND_ECC_Enable()/
mbed_official 375:3d36234a1087 43 HAL_NAND_ECC_Disable() to respectively enable/disable the ECC code correction
mbed_official 375:3d36234a1087 44 feature or the function HAL_NAND_GetECC() to get the ECC correction code.
mbed_official 375:3d36234a1087 45
mbed_official 375:3d36234a1087 46 (+) You can monitor the NAND device HAL state by calling the function
mbed_official 375:3d36234a1087 47 HAL_NAND_GetState()
mbed_official 375:3d36234a1087 48
mbed_official 375:3d36234a1087 49 [..]
mbed_official 375:3d36234a1087 50 (@) This driver is a set of generic APIs which handle standard NAND flash operations.
mbed_official 375:3d36234a1087 51 If a NAND flash device contains different operations and/or implementations,
mbed_official 375:3d36234a1087 52 it should be implemented separately.
mbed_official 375:3d36234a1087 53
mbed_official 375:3d36234a1087 54 @endverbatim
mbed_official 375:3d36234a1087 55 ******************************************************************************
mbed_official 375:3d36234a1087 56 * @attention
mbed_official 375:3d36234a1087 57 *
mbed_official 634:ac7d6880524d 58 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 375:3d36234a1087 59 *
mbed_official 375:3d36234a1087 60 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 375:3d36234a1087 61 * are permitted provided that the following conditions are met:
mbed_official 375:3d36234a1087 62 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 375:3d36234a1087 63 * this list of conditions and the following disclaimer.
mbed_official 375:3d36234a1087 64 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 375:3d36234a1087 65 * this list of conditions and the following disclaimer in the documentation
mbed_official 375:3d36234a1087 66 * and/or other materials provided with the distribution.
mbed_official 375:3d36234a1087 67 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 375:3d36234a1087 68 * may be used to endorse or promote products derived from this software
mbed_official 375:3d36234a1087 69 * without specific prior written permission.
mbed_official 375:3d36234a1087 70 *
mbed_official 375:3d36234a1087 71 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 375:3d36234a1087 72 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 375:3d36234a1087 73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 375:3d36234a1087 74 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 375:3d36234a1087 75 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 375:3d36234a1087 76 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 375:3d36234a1087 77 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 375:3d36234a1087 78 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 375:3d36234a1087 79 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 375:3d36234a1087 80 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 375:3d36234a1087 81 *
mbed_official 375:3d36234a1087 82 ******************************************************************************
mbed_official 375:3d36234a1087 83 */
mbed_official 375:3d36234a1087 84
mbed_official 375:3d36234a1087 85 /* Includes ------------------------------------------------------------------*/
mbed_official 375:3d36234a1087 86 #include "stm32f3xx_hal.h"
mbed_official 375:3d36234a1087 87
mbed_official 375:3d36234a1087 88 /** @addtogroup STM32F3xx_HAL_Driver
mbed_official 375:3d36234a1087 89 * @{
mbed_official 375:3d36234a1087 90 */
mbed_official 375:3d36234a1087 91
mbed_official 375:3d36234a1087 92 /** @defgroup NAND NAND HAL module driver
mbed_official 375:3d36234a1087 93 * @brief NAND HAL module driver
mbed_official 375:3d36234a1087 94 * @{
mbed_official 375:3d36234a1087 95 */
mbed_official 375:3d36234a1087 96 #ifdef HAL_NAND_MODULE_ENABLED
mbed_official 375:3d36234a1087 97
mbed_official 375:3d36234a1087 98 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx)
mbed_official 375:3d36234a1087 99
mbed_official 375:3d36234a1087 100 /* Private typedef -----------------------------------------------------------*/
mbed_official 375:3d36234a1087 101 /* Private define ------------------------------------------------------------*/
mbed_official 375:3d36234a1087 102 /* Private macro -------------------------------------------------------------*/
mbed_official 375:3d36234a1087 103 /* Private variables ---------------------------------------------------------*/
mbed_official 375:3d36234a1087 104 /* Private function prototypes -----------------------------------------------*/
mbed_official 375:3d36234a1087 105 /* Exported functions ---------------------------------------------------------*/
mbed_official 375:3d36234a1087 106
mbed_official 375:3d36234a1087 107 /** @defgroup NAND_Exported_Functions NAND Exported Functions
mbed_official 375:3d36234a1087 108 * @{
mbed_official 375:3d36234a1087 109 */
mbed_official 375:3d36234a1087 110
mbed_official 375:3d36234a1087 111 /** @defgroup NAND_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 375:3d36234a1087 112 * @brief Initialization and Configuration functions
mbed_official 375:3d36234a1087 113 *
mbed_official 375:3d36234a1087 114 @verbatim
mbed_official 375:3d36234a1087 115 ==============================================================================
mbed_official 375:3d36234a1087 116 ##### NAND Initialization and de-initialization functions #####
mbed_official 375:3d36234a1087 117 ==============================================================================
mbed_official 375:3d36234a1087 118 [..]
mbed_official 375:3d36234a1087 119 This section provides functions allowing to initialize/de-initialize
mbed_official 375:3d36234a1087 120 the NAND memory
mbed_official 375:3d36234a1087 121
mbed_official 375:3d36234a1087 122 @endverbatim
mbed_official 375:3d36234a1087 123 * @{
mbed_official 375:3d36234a1087 124 */
mbed_official 375:3d36234a1087 125
mbed_official 375:3d36234a1087 126 /**
mbed_official 375:3d36234a1087 127 * @brief Perform NAND memory Initialization sequence
mbed_official 375:3d36234a1087 128 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 129 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 130 * @param ComSpace_Timing: pointer to Common space timing structure
mbed_official 375:3d36234a1087 131 * @param AttSpace_Timing: pointer to Attribute space timing structure
mbed_official 375:3d36234a1087 132 * @retval HAL status
mbed_official 375:3d36234a1087 133 */
mbed_official 375:3d36234a1087 134 HAL_StatusTypeDef HAL_NAND_Init(NAND_HandleTypeDef *hnand, FMC_NAND_PCC_TimingTypeDef *ComSpace_Timing, FMC_NAND_PCC_TimingTypeDef *AttSpace_Timing)
mbed_official 375:3d36234a1087 135 {
mbed_official 375:3d36234a1087 136 /* Check the NAND handle state */
mbed_official 634:ac7d6880524d 137 if(hnand == HAL_NULL)
mbed_official 375:3d36234a1087 138 {
mbed_official 375:3d36234a1087 139 return HAL_ERROR;
mbed_official 375:3d36234a1087 140 }
mbed_official 375:3d36234a1087 141
mbed_official 375:3d36234a1087 142 if(hnand->State == HAL_NAND_STATE_RESET)
mbed_official 375:3d36234a1087 143 {
mbed_official 375:3d36234a1087 144 /* Initialize the low level hardware (MSP) */
mbed_official 375:3d36234a1087 145 HAL_NAND_MspInit(hnand);
mbed_official 375:3d36234a1087 146 }
mbed_official 375:3d36234a1087 147
mbed_official 375:3d36234a1087 148 /* Initialize NAND control Interface */
mbed_official 375:3d36234a1087 149 FMC_NAND_Init(hnand->Instance, &(hnand->Init));
mbed_official 375:3d36234a1087 150
mbed_official 375:3d36234a1087 151 /* Initialize NAND common space timing Interface */
mbed_official 375:3d36234a1087 152 FMC_NAND_CommonSpace_Timing_Init(hnand->Instance, ComSpace_Timing, hnand->Init.NandBank);
mbed_official 375:3d36234a1087 153
mbed_official 375:3d36234a1087 154 /* Initialize NAND attribute space timing Interface */
mbed_official 375:3d36234a1087 155 FMC_NAND_AttributeSpace_Timing_Init(hnand->Instance, AttSpace_Timing, hnand->Init.NandBank);
mbed_official 375:3d36234a1087 156
mbed_official 375:3d36234a1087 157 /* Enable the NAND device */
mbed_official 375:3d36234a1087 158 __FMC_NAND_ENABLE(hnand->Instance, hnand->Init.NandBank);
mbed_official 375:3d36234a1087 159
mbed_official 375:3d36234a1087 160 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 161 hnand->State = HAL_NAND_STATE_READY;
mbed_official 375:3d36234a1087 162
mbed_official 375:3d36234a1087 163 return HAL_OK;
mbed_official 375:3d36234a1087 164 }
mbed_official 375:3d36234a1087 165
mbed_official 375:3d36234a1087 166 /**
mbed_official 375:3d36234a1087 167 * @brief Perform NAND memory De-Initialization sequence
mbed_official 375:3d36234a1087 168 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 169 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 170 * @retval HAL status
mbed_official 375:3d36234a1087 171 */
mbed_official 375:3d36234a1087 172 HAL_StatusTypeDef HAL_NAND_DeInit(NAND_HandleTypeDef *hnand)
mbed_official 375:3d36234a1087 173 {
mbed_official 375:3d36234a1087 174 /* Initialize the low level hardware (MSP) */
mbed_official 375:3d36234a1087 175 HAL_NAND_MspDeInit(hnand);
mbed_official 375:3d36234a1087 176
mbed_official 375:3d36234a1087 177 /* Configure the NAND registers with their reset values */
mbed_official 375:3d36234a1087 178 FMC_NAND_DeInit(hnand->Instance, hnand->Init.NandBank);
mbed_official 375:3d36234a1087 179
mbed_official 375:3d36234a1087 180 /* Reset the NAND controller state */
mbed_official 375:3d36234a1087 181 hnand->State = HAL_NAND_STATE_RESET;
mbed_official 375:3d36234a1087 182
mbed_official 375:3d36234a1087 183 /* Release Lock */
mbed_official 375:3d36234a1087 184 __HAL_UNLOCK(hnand);
mbed_official 375:3d36234a1087 185
mbed_official 375:3d36234a1087 186 return HAL_OK;
mbed_official 375:3d36234a1087 187 }
mbed_official 375:3d36234a1087 188
mbed_official 375:3d36234a1087 189 /**
mbed_official 375:3d36234a1087 190 * @brief NAND MSP Init
mbed_official 375:3d36234a1087 191 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 192 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 193 * @retval None
mbed_official 375:3d36234a1087 194 */
mbed_official 375:3d36234a1087 195 __weak void HAL_NAND_MspInit(NAND_HandleTypeDef *hnand)
mbed_official 375:3d36234a1087 196 {
mbed_official 375:3d36234a1087 197 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 375:3d36234a1087 198 the HAL_NAND_MspInit could be implemented in the user file
mbed_official 375:3d36234a1087 199 */
mbed_official 375:3d36234a1087 200 }
mbed_official 375:3d36234a1087 201
mbed_official 375:3d36234a1087 202 /**
mbed_official 375:3d36234a1087 203 * @brief NAND MSP DeInit
mbed_official 375:3d36234a1087 204 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 205 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 206 * @retval None
mbed_official 375:3d36234a1087 207 */
mbed_official 375:3d36234a1087 208 __weak void HAL_NAND_MspDeInit(NAND_HandleTypeDef *hnand)
mbed_official 375:3d36234a1087 209 {
mbed_official 375:3d36234a1087 210 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 375:3d36234a1087 211 the HAL_NAND_MspDeInit could be implemented in the user file
mbed_official 375:3d36234a1087 212 */
mbed_official 375:3d36234a1087 213 }
mbed_official 375:3d36234a1087 214
mbed_official 375:3d36234a1087 215
mbed_official 375:3d36234a1087 216 /**
mbed_official 375:3d36234a1087 217 * @brief This function handles NAND device interrupt request.
mbed_official 375:3d36234a1087 218 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 219 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 220 * @retval HAL status
mbed_official 375:3d36234a1087 221 */
mbed_official 375:3d36234a1087 222 void HAL_NAND_IRQHandler(NAND_HandleTypeDef *hnand)
mbed_official 375:3d36234a1087 223 {
mbed_official 375:3d36234a1087 224 /* Check NAND interrupt Rising edge flag */
mbed_official 375:3d36234a1087 225 if(__FMC_NAND_GET_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_RISING_EDGE))
mbed_official 375:3d36234a1087 226 {
mbed_official 375:3d36234a1087 227 /* NAND interrupt callback*/
mbed_official 375:3d36234a1087 228 HAL_NAND_ITCallback(hnand);
mbed_official 375:3d36234a1087 229
mbed_official 375:3d36234a1087 230 /* Clear NAND interrupt Rising edge pending bit */
mbed_official 375:3d36234a1087 231 __FMC_NAND_CLEAR_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_RISING_EDGE);
mbed_official 375:3d36234a1087 232 }
mbed_official 375:3d36234a1087 233
mbed_official 375:3d36234a1087 234 /* Check NAND interrupt Level flag */
mbed_official 375:3d36234a1087 235 if(__FMC_NAND_GET_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_LEVEL))
mbed_official 375:3d36234a1087 236 {
mbed_official 375:3d36234a1087 237 /* NAND interrupt callback*/
mbed_official 375:3d36234a1087 238 HAL_NAND_ITCallback(hnand);
mbed_official 375:3d36234a1087 239
mbed_official 375:3d36234a1087 240 /* Clear NAND interrupt Level pending bit */
mbed_official 375:3d36234a1087 241 __FMC_NAND_CLEAR_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_LEVEL);
mbed_official 375:3d36234a1087 242 }
mbed_official 375:3d36234a1087 243
mbed_official 375:3d36234a1087 244 /* Check NAND interrupt Falling edge flag */
mbed_official 375:3d36234a1087 245 if(__FMC_NAND_GET_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_FALLING_EDGE))
mbed_official 375:3d36234a1087 246 {
mbed_official 375:3d36234a1087 247 /* NAND interrupt callback*/
mbed_official 375:3d36234a1087 248 HAL_NAND_ITCallback(hnand);
mbed_official 375:3d36234a1087 249
mbed_official 375:3d36234a1087 250 /* Clear NAND interrupt Falling edge pending bit */
mbed_official 375:3d36234a1087 251 __FMC_NAND_CLEAR_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_FALLING_EDGE);
mbed_official 375:3d36234a1087 252 }
mbed_official 375:3d36234a1087 253
mbed_official 375:3d36234a1087 254 /* Check NAND interrupt FIFO empty flag */
mbed_official 375:3d36234a1087 255 if(__FMC_NAND_GET_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_FEMPT))
mbed_official 375:3d36234a1087 256 {
mbed_official 375:3d36234a1087 257 /* NAND interrupt callback*/
mbed_official 375:3d36234a1087 258 HAL_NAND_ITCallback(hnand);
mbed_official 375:3d36234a1087 259
mbed_official 375:3d36234a1087 260 /* Clear NAND interrupt FIFO empty pending bit */
mbed_official 375:3d36234a1087 261 __FMC_NAND_CLEAR_FLAG(hnand->Instance, hnand->Init.NandBank, FMC_FLAG_FEMPT);
mbed_official 375:3d36234a1087 262 }
mbed_official 375:3d36234a1087 263
mbed_official 375:3d36234a1087 264 }
mbed_official 375:3d36234a1087 265
mbed_official 375:3d36234a1087 266 /**
mbed_official 375:3d36234a1087 267 * @brief NAND interrupt feature callback
mbed_official 375:3d36234a1087 268 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 269 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 270 * @retval None
mbed_official 375:3d36234a1087 271 */
mbed_official 375:3d36234a1087 272 __weak void HAL_NAND_ITCallback(NAND_HandleTypeDef *hnand)
mbed_official 375:3d36234a1087 273 {
mbed_official 375:3d36234a1087 274 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 375:3d36234a1087 275 the HAL_NAND_ITCallback could be implemented in the user file
mbed_official 375:3d36234a1087 276 */
mbed_official 375:3d36234a1087 277 }
mbed_official 375:3d36234a1087 278
mbed_official 375:3d36234a1087 279 /**
mbed_official 375:3d36234a1087 280 * @}
mbed_official 375:3d36234a1087 281 */
mbed_official 375:3d36234a1087 282
mbed_official 375:3d36234a1087 283 /** @defgroup NAND_Exported_Functions_Group2 Input and Output functions
mbed_official 375:3d36234a1087 284 * @brief Input Output and memory control functions
mbed_official 375:3d36234a1087 285 *
mbed_official 375:3d36234a1087 286 @verbatim
mbed_official 375:3d36234a1087 287 ==============================================================================
mbed_official 375:3d36234a1087 288 ##### NAND Input and Output functions #####
mbed_official 375:3d36234a1087 289 ==============================================================================
mbed_official 375:3d36234a1087 290 [..]
mbed_official 375:3d36234a1087 291 This section provides functions allowing to use and control the NAND
mbed_official 375:3d36234a1087 292 memory
mbed_official 375:3d36234a1087 293
mbed_official 375:3d36234a1087 294 @endverbatim
mbed_official 375:3d36234a1087 295 * @{
mbed_official 375:3d36234a1087 296 */
mbed_official 375:3d36234a1087 297
mbed_official 375:3d36234a1087 298 /**
mbed_official 375:3d36234a1087 299 * @brief Read the NAND memory electronic signature
mbed_official 375:3d36234a1087 300 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 301 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 302 * @param pNAND_ID: NAND ID structure
mbed_official 375:3d36234a1087 303 * @retval HAL status
mbed_official 375:3d36234a1087 304 */
mbed_official 375:3d36234a1087 305 HAL_StatusTypeDef HAL_NAND_Read_ID(NAND_HandleTypeDef *hnand, NAND_IDTypeDef *pNAND_ID)
mbed_official 375:3d36234a1087 306 {
mbed_official 375:3d36234a1087 307 __IO uint32_t data = 0;
mbed_official 375:3d36234a1087 308 uint32_t deviceAddress = 0;
mbed_official 375:3d36234a1087 309
mbed_official 375:3d36234a1087 310 /* Process Locked */
mbed_official 375:3d36234a1087 311 __HAL_LOCK(hnand);
mbed_official 375:3d36234a1087 312
mbed_official 375:3d36234a1087 313 /* Check the NAND controller state */
mbed_official 375:3d36234a1087 314 if(hnand->State == HAL_NAND_STATE_BUSY)
mbed_official 375:3d36234a1087 315 {
mbed_official 375:3d36234a1087 316 return HAL_BUSY;
mbed_official 375:3d36234a1087 317 }
mbed_official 375:3d36234a1087 318
mbed_official 375:3d36234a1087 319 /* Identify the device address */
mbed_official 375:3d36234a1087 320 if(hnand->Init.NandBank == FMC_NAND_BANK2)
mbed_official 375:3d36234a1087 321 {
mbed_official 375:3d36234a1087 322 deviceAddress = NAND_DEVICE1;
mbed_official 375:3d36234a1087 323 }
mbed_official 375:3d36234a1087 324 else
mbed_official 375:3d36234a1087 325 {
mbed_official 375:3d36234a1087 326 deviceAddress = NAND_DEVICE2;
mbed_official 375:3d36234a1087 327 }
mbed_official 375:3d36234a1087 328
mbed_official 375:3d36234a1087 329 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 330 hnand->State = HAL_NAND_STATE_BUSY;
mbed_official 375:3d36234a1087 331
mbed_official 375:3d36234a1087 332 /* Send Read ID command sequence */
mbed_official 375:3d36234a1087 333 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = 0x90;
mbed_official 375:3d36234a1087 334 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = 0x00;
mbed_official 375:3d36234a1087 335
mbed_official 375:3d36234a1087 336 /* Read the electronic signature from NAND flash */
mbed_official 375:3d36234a1087 337 data = *(__IO uint32_t *)deviceAddress;
mbed_official 375:3d36234a1087 338
mbed_official 375:3d36234a1087 339 /* Return the data read */
mbed_official 375:3d36234a1087 340 pNAND_ID->Maker_Id = ADDR_1st_CYCLE(data);
mbed_official 375:3d36234a1087 341 pNAND_ID->Device_Id = ADDR_2nd_CYCLE(data);
mbed_official 375:3d36234a1087 342 pNAND_ID->Third_Id = ADDR_3rd_CYCLE(data);
mbed_official 375:3d36234a1087 343 pNAND_ID->Fourth_Id = ADDR_4th_CYCLE(data);
mbed_official 375:3d36234a1087 344
mbed_official 375:3d36234a1087 345 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 346 hnand->State = HAL_NAND_STATE_READY;
mbed_official 375:3d36234a1087 347
mbed_official 375:3d36234a1087 348 /* Process unlocked */
mbed_official 375:3d36234a1087 349 __HAL_UNLOCK(hnand);
mbed_official 375:3d36234a1087 350
mbed_official 375:3d36234a1087 351 return HAL_OK;
mbed_official 375:3d36234a1087 352 }
mbed_official 375:3d36234a1087 353
mbed_official 375:3d36234a1087 354 /**
mbed_official 375:3d36234a1087 355 * @brief NAND memory reset
mbed_official 375:3d36234a1087 356 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 357 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 358 * @retval HAL status
mbed_official 375:3d36234a1087 359 */
mbed_official 375:3d36234a1087 360 HAL_StatusTypeDef HAL_NAND_Reset(NAND_HandleTypeDef *hnand)
mbed_official 375:3d36234a1087 361 {
mbed_official 375:3d36234a1087 362 uint32_t deviceAddress = 0;
mbed_official 375:3d36234a1087 363
mbed_official 375:3d36234a1087 364 /* Process Locked */
mbed_official 375:3d36234a1087 365 __HAL_LOCK(hnand);
mbed_official 375:3d36234a1087 366
mbed_official 375:3d36234a1087 367 /* Check the NAND controller state */
mbed_official 375:3d36234a1087 368 if(hnand->State == HAL_NAND_STATE_BUSY)
mbed_official 375:3d36234a1087 369 {
mbed_official 375:3d36234a1087 370 return HAL_BUSY;
mbed_official 375:3d36234a1087 371 }
mbed_official 375:3d36234a1087 372
mbed_official 375:3d36234a1087 373 /* Identify the device address */
mbed_official 375:3d36234a1087 374 if(hnand->Init.NandBank == FMC_NAND_BANK2)
mbed_official 375:3d36234a1087 375 {
mbed_official 375:3d36234a1087 376 deviceAddress = NAND_DEVICE1;
mbed_official 375:3d36234a1087 377 }
mbed_official 375:3d36234a1087 378 else
mbed_official 375:3d36234a1087 379 {
mbed_official 375:3d36234a1087 380 deviceAddress = NAND_DEVICE2;
mbed_official 375:3d36234a1087 381 }
mbed_official 375:3d36234a1087 382
mbed_official 375:3d36234a1087 383 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 384 hnand->State = HAL_NAND_STATE_BUSY;
mbed_official 375:3d36234a1087 385
mbed_official 375:3d36234a1087 386 /* Send NAND reset command */
mbed_official 375:3d36234a1087 387 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = 0xFF;
mbed_official 375:3d36234a1087 388
mbed_official 375:3d36234a1087 389
mbed_official 375:3d36234a1087 390 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 391 hnand->State = HAL_NAND_STATE_READY;
mbed_official 375:3d36234a1087 392
mbed_official 375:3d36234a1087 393 /* Process unlocked */
mbed_official 375:3d36234a1087 394 __HAL_UNLOCK(hnand);
mbed_official 375:3d36234a1087 395
mbed_official 375:3d36234a1087 396 return HAL_OK;
mbed_official 375:3d36234a1087 397
mbed_official 375:3d36234a1087 398 }
mbed_official 375:3d36234a1087 399
mbed_official 375:3d36234a1087 400
mbed_official 375:3d36234a1087 401 /**
mbed_official 375:3d36234a1087 402 * @brief Read Page(s) from NAND memory block
mbed_official 375:3d36234a1087 403 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 404 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 405 * @param pAddress : pointer to NAND address structure
mbed_official 375:3d36234a1087 406 * @param pBuffer : pointer to destination read buffer
mbed_official 375:3d36234a1087 407 * @param NumPageToRead : number of pages to read from block
mbed_official 375:3d36234a1087 408 * @retval HAL status
mbed_official 375:3d36234a1087 409 */
mbed_official 375:3d36234a1087 410 HAL_StatusTypeDef HAL_NAND_Read_Page(NAND_HandleTypeDef *hnand, NAND_AddressTypedef *pAddress, uint8_t *pBuffer, uint32_t NumPageToRead)
mbed_official 375:3d36234a1087 411 {
mbed_official 375:3d36234a1087 412 __IO uint32_t index = 0;
mbed_official 375:3d36234a1087 413 uint32_t deviceAddress = 0, size = 0, numPagesRead = 0, nandAddress = 0;
mbed_official 375:3d36234a1087 414
mbed_official 375:3d36234a1087 415 /* Process Locked */
mbed_official 375:3d36234a1087 416 __HAL_LOCK(hnand);
mbed_official 375:3d36234a1087 417
mbed_official 375:3d36234a1087 418 /* Check the NAND controller state */
mbed_official 375:3d36234a1087 419 if(hnand->State == HAL_NAND_STATE_BUSY)
mbed_official 375:3d36234a1087 420 {
mbed_official 375:3d36234a1087 421 return HAL_BUSY;
mbed_official 375:3d36234a1087 422 }
mbed_official 375:3d36234a1087 423
mbed_official 375:3d36234a1087 424 /* Identify the device address */
mbed_official 375:3d36234a1087 425 if(hnand->Init.NandBank == FMC_NAND_BANK2)
mbed_official 375:3d36234a1087 426 {
mbed_official 375:3d36234a1087 427 deviceAddress = NAND_DEVICE1;
mbed_official 375:3d36234a1087 428 }
mbed_official 375:3d36234a1087 429 else
mbed_official 375:3d36234a1087 430 {
mbed_official 375:3d36234a1087 431 deviceAddress = NAND_DEVICE2;
mbed_official 375:3d36234a1087 432 }
mbed_official 375:3d36234a1087 433
mbed_official 375:3d36234a1087 434 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 435 hnand->State = HAL_NAND_STATE_BUSY;
mbed_official 375:3d36234a1087 436
mbed_official 375:3d36234a1087 437 /* NAND raw address calculation */
mbed_official 375:3d36234a1087 438 nandAddress = ARRAY_ADDRESS(pAddress, hnand);
mbed_official 375:3d36234a1087 439
mbed_official 375:3d36234a1087 440 /* Page(s) read loop */
mbed_official 375:3d36234a1087 441 while((NumPageToRead != 0) && (nandAddress < ((hnand->Info.BlockSize) * (hnand->Info.PageSize) * (hnand->Info.ZoneSize))))
mbed_official 375:3d36234a1087 442 {
mbed_official 375:3d36234a1087 443 /* update the buffer size */
mbed_official 375:3d36234a1087 444 size = (hnand->Info.PageSize) + ((hnand->Info.PageSize) * numPagesRead);
mbed_official 375:3d36234a1087 445
mbed_official 375:3d36234a1087 446 /* Send read page command sequence */
mbed_official 375:3d36234a1087 447 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = NAND_CMD_AREA_A;
mbed_official 375:3d36234a1087 448
mbed_official 375:3d36234a1087 449 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = 0x00;
mbed_official 375:3d36234a1087 450 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_1st_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 451 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_2nd_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 452 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_3rd_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 453
mbed_official 375:3d36234a1087 454 /* for 512 and 1 GB devices, 4th cycle is required */
mbed_official 375:3d36234a1087 455 if(hnand->Info.BlockNbr >= 1024)
mbed_official 375:3d36234a1087 456 {
mbed_official 375:3d36234a1087 457 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_4th_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 458 }
mbed_official 375:3d36234a1087 459
mbed_official 375:3d36234a1087 460 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = 0x30;
mbed_official 375:3d36234a1087 461
mbed_official 375:3d36234a1087 462 /* Get Data into Buffer */
mbed_official 375:3d36234a1087 463 for(; index < size; index++)
mbed_official 375:3d36234a1087 464 {
mbed_official 375:3d36234a1087 465 *(uint8_t *)pBuffer++ = *(uint8_t *)deviceAddress;
mbed_official 375:3d36234a1087 466 }
mbed_official 375:3d36234a1087 467
mbed_official 375:3d36234a1087 468 /* Increment read pages number */
mbed_official 375:3d36234a1087 469 numPagesRead++;
mbed_official 375:3d36234a1087 470
mbed_official 375:3d36234a1087 471 /* Decrement pages to read */
mbed_official 375:3d36234a1087 472 NumPageToRead--;
mbed_official 375:3d36234a1087 473
mbed_official 375:3d36234a1087 474 /* Increment the NAND address */
mbed_official 375:3d36234a1087 475 nandAddress = (uint32_t)(nandAddress + (hnand->Info.PageSize * 8));
mbed_official 375:3d36234a1087 476
mbed_official 375:3d36234a1087 477 }
mbed_official 375:3d36234a1087 478
mbed_official 375:3d36234a1087 479 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 480 hnand->State = HAL_NAND_STATE_READY;
mbed_official 375:3d36234a1087 481
mbed_official 375:3d36234a1087 482 /* Process unlocked */
mbed_official 375:3d36234a1087 483 __HAL_UNLOCK(hnand);
mbed_official 375:3d36234a1087 484
mbed_official 375:3d36234a1087 485 return HAL_OK;
mbed_official 375:3d36234a1087 486
mbed_official 375:3d36234a1087 487 }
mbed_official 375:3d36234a1087 488
mbed_official 375:3d36234a1087 489 /**
mbed_official 375:3d36234a1087 490 * @brief Write Page(s) to NAND memory block
mbed_official 375:3d36234a1087 491 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 492 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 493 * @param pAddress : pointer to NAND address structure
mbed_official 375:3d36234a1087 494 * @param pBuffer : pointer to source buffer to write
mbed_official 375:3d36234a1087 495 * @param NumPageToWrite : number of pages to write to block
mbed_official 375:3d36234a1087 496 * @retval HAL status
mbed_official 375:3d36234a1087 497 */
mbed_official 375:3d36234a1087 498 HAL_StatusTypeDef HAL_NAND_Write_Page(NAND_HandleTypeDef *hnand, NAND_AddressTypedef *pAddress, uint8_t *pBuffer, uint32_t NumPageToWrite)
mbed_official 375:3d36234a1087 499 {
mbed_official 375:3d36234a1087 500 __IO uint32_t index = 0;
mbed_official 375:3d36234a1087 501 uint32_t timeout = 0;
mbed_official 375:3d36234a1087 502 uint32_t deviceAddress = 0, size = 0 , numPagesWritten = 0, nandAddress = 0;
mbed_official 375:3d36234a1087 503
mbed_official 375:3d36234a1087 504 /* Process Locked */
mbed_official 375:3d36234a1087 505 __HAL_LOCK(hnand);
mbed_official 375:3d36234a1087 506
mbed_official 375:3d36234a1087 507 /* Check the NAND controller state */
mbed_official 375:3d36234a1087 508 if(hnand->State == HAL_NAND_STATE_BUSY)
mbed_official 375:3d36234a1087 509 {
mbed_official 375:3d36234a1087 510 return HAL_BUSY;
mbed_official 375:3d36234a1087 511 }
mbed_official 375:3d36234a1087 512
mbed_official 375:3d36234a1087 513 /* Identify the device address */
mbed_official 375:3d36234a1087 514 if(hnand->Init.NandBank == FMC_NAND_BANK2)
mbed_official 375:3d36234a1087 515 {
mbed_official 375:3d36234a1087 516 deviceAddress = NAND_DEVICE1;
mbed_official 375:3d36234a1087 517 }
mbed_official 375:3d36234a1087 518 else
mbed_official 375:3d36234a1087 519 {
mbed_official 375:3d36234a1087 520 deviceAddress = NAND_DEVICE2;
mbed_official 375:3d36234a1087 521 }
mbed_official 375:3d36234a1087 522
mbed_official 375:3d36234a1087 523 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 524 hnand->State = HAL_NAND_STATE_BUSY;
mbed_official 375:3d36234a1087 525
mbed_official 375:3d36234a1087 526 /* NAND raw address calculation */
mbed_official 375:3d36234a1087 527 nandAddress = ARRAY_ADDRESS(pAddress, hnand);
mbed_official 375:3d36234a1087 528
mbed_official 375:3d36234a1087 529 /* Page(s) write loop */
mbed_official 375:3d36234a1087 530 while((NumPageToWrite != 0) && (nandAddress < ((hnand->Info.BlockSize) * (hnand->Info.PageSize) * (hnand->Info.ZoneSize))))
mbed_official 375:3d36234a1087 531 {
mbed_official 375:3d36234a1087 532 /* update the buffer size */
mbed_official 375:3d36234a1087 533 size = (hnand->Info.PageSize) + ((hnand->Info.PageSize) * numPagesWritten);
mbed_official 375:3d36234a1087 534
mbed_official 375:3d36234a1087 535 /* Send write page command sequence */
mbed_official 375:3d36234a1087 536 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = NAND_CMD_AREA_A;
mbed_official 375:3d36234a1087 537 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = 0x80;
mbed_official 375:3d36234a1087 538
mbed_official 375:3d36234a1087 539 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = 0x00;
mbed_official 375:3d36234a1087 540 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_1st_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 541 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_2nd_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 542 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_3rd_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 543
mbed_official 375:3d36234a1087 544 /* for 512 and 1 GB devices, 4th cycle is required */
mbed_official 375:3d36234a1087 545 if(hnand->Info.BlockNbr >= 1024)
mbed_official 375:3d36234a1087 546 {
mbed_official 375:3d36234a1087 547 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_4th_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 548 }
mbed_official 375:3d36234a1087 549
mbed_official 375:3d36234a1087 550 /* Write data to memory */
mbed_official 375:3d36234a1087 551 for(; index < size; index++)
mbed_official 375:3d36234a1087 552 {
mbed_official 375:3d36234a1087 553 *(__IO uint8_t *)deviceAddress = *(uint8_t *)pBuffer++;
mbed_official 375:3d36234a1087 554 }
mbed_official 375:3d36234a1087 555
mbed_official 375:3d36234a1087 556 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = 0x10;
mbed_official 375:3d36234a1087 557
mbed_official 375:3d36234a1087 558 /* Read status until NAND is ready */
mbed_official 375:3d36234a1087 559 while(HAL_NAND_Read_Status(hnand) != NAND_READY)
mbed_official 375:3d36234a1087 560 {
mbed_official 375:3d36234a1087 561 /* Check for timeout value */
mbed_official 375:3d36234a1087 562 timeout = HAL_GetTick() + NAND_WRITE_TIMEOUT;
mbed_official 375:3d36234a1087 563
mbed_official 375:3d36234a1087 564 if(HAL_GetTick() >= timeout)
mbed_official 375:3d36234a1087 565 {
mbed_official 375:3d36234a1087 566 return HAL_TIMEOUT;
mbed_official 375:3d36234a1087 567 }
mbed_official 375:3d36234a1087 568 }
mbed_official 375:3d36234a1087 569
mbed_official 375:3d36234a1087 570 /* Increment written pages number */
mbed_official 375:3d36234a1087 571 numPagesWritten++;
mbed_official 375:3d36234a1087 572
mbed_official 375:3d36234a1087 573 /* Decrement pages to write */
mbed_official 375:3d36234a1087 574 NumPageToWrite--;
mbed_official 375:3d36234a1087 575
mbed_official 375:3d36234a1087 576 /* Increment the NAND address */
mbed_official 375:3d36234a1087 577 nandAddress = (uint32_t)(nandAddress + (hnand->Info.PageSize * 8));
mbed_official 375:3d36234a1087 578
mbed_official 375:3d36234a1087 579 }
mbed_official 375:3d36234a1087 580
mbed_official 375:3d36234a1087 581 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 582 hnand->State = HAL_NAND_STATE_READY;
mbed_official 375:3d36234a1087 583
mbed_official 375:3d36234a1087 584 /* Process unlocked */
mbed_official 375:3d36234a1087 585 __HAL_UNLOCK(hnand);
mbed_official 375:3d36234a1087 586
mbed_official 375:3d36234a1087 587 return HAL_OK;
mbed_official 375:3d36234a1087 588 }
mbed_official 375:3d36234a1087 589
mbed_official 375:3d36234a1087 590
mbed_official 375:3d36234a1087 591 /**
mbed_official 375:3d36234a1087 592 * @brief Read Spare area(s) from NAND memory
mbed_official 375:3d36234a1087 593 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 594 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 595 * @param pAddress : pointer to NAND address structure
mbed_official 375:3d36234a1087 596 * @param pBuffer: pointer to source buffer to write
mbed_official 375:3d36234a1087 597 * @param NumSpareAreaToRead: Number of spare area to read
mbed_official 375:3d36234a1087 598 * @retval HAL status
mbed_official 375:3d36234a1087 599 */
mbed_official 375:3d36234a1087 600 HAL_StatusTypeDef HAL_NAND_Read_SpareArea(NAND_HandleTypeDef *hnand, NAND_AddressTypedef *pAddress, uint8_t *pBuffer, uint32_t NumSpareAreaToRead)
mbed_official 375:3d36234a1087 601 {
mbed_official 375:3d36234a1087 602 __IO uint32_t index = 0;
mbed_official 375:3d36234a1087 603 uint32_t deviceAddress = 0, size = 0, numSpareAreaRead = 0, nandAddress = 0;
mbed_official 375:3d36234a1087 604
mbed_official 375:3d36234a1087 605 /* Process Locked */
mbed_official 375:3d36234a1087 606 __HAL_LOCK(hnand);
mbed_official 375:3d36234a1087 607
mbed_official 375:3d36234a1087 608 /* Check the NAND controller state */
mbed_official 375:3d36234a1087 609 if(hnand->State == HAL_NAND_STATE_BUSY)
mbed_official 375:3d36234a1087 610 {
mbed_official 375:3d36234a1087 611 return HAL_BUSY;
mbed_official 375:3d36234a1087 612 }
mbed_official 375:3d36234a1087 613
mbed_official 375:3d36234a1087 614 /* Identify the device address */
mbed_official 375:3d36234a1087 615 if(hnand->Init.NandBank == FMC_NAND_BANK2)
mbed_official 375:3d36234a1087 616 {
mbed_official 375:3d36234a1087 617 deviceAddress = NAND_DEVICE1;
mbed_official 375:3d36234a1087 618 }
mbed_official 375:3d36234a1087 619 else
mbed_official 375:3d36234a1087 620 {
mbed_official 375:3d36234a1087 621 deviceAddress = NAND_DEVICE2;
mbed_official 375:3d36234a1087 622 }
mbed_official 375:3d36234a1087 623
mbed_official 375:3d36234a1087 624 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 625 hnand->State = HAL_NAND_STATE_BUSY;
mbed_official 375:3d36234a1087 626
mbed_official 375:3d36234a1087 627 /* NAND raw address calculation */
mbed_official 375:3d36234a1087 628 nandAddress = ARRAY_ADDRESS(pAddress, hnand);
mbed_official 375:3d36234a1087 629
mbed_official 375:3d36234a1087 630 /* Spare area(s) read loop */
mbed_official 375:3d36234a1087 631 while((NumSpareAreaToRead != 0) && (nandAddress < ((hnand->Info.BlockSize) * (hnand->Info.SpareAreaSize) * (hnand->Info.ZoneSize))))
mbed_official 375:3d36234a1087 632 {
mbed_official 375:3d36234a1087 633
mbed_official 375:3d36234a1087 634 /* update the buffer size */
mbed_official 375:3d36234a1087 635 size = (hnand->Info.SpareAreaSize) + ((hnand->Info.SpareAreaSize) * numSpareAreaRead);
mbed_official 375:3d36234a1087 636
mbed_official 375:3d36234a1087 637 /* Send read spare area command sequence */
mbed_official 375:3d36234a1087 638 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = NAND_CMD_AREA_C;
mbed_official 375:3d36234a1087 639
mbed_official 375:3d36234a1087 640 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = 0x00;
mbed_official 375:3d36234a1087 641 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_1st_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 642 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_2nd_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 643 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_3rd_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 644
mbed_official 375:3d36234a1087 645 /* for 512 and 1 GB devices, 4th cycle is required */
mbed_official 375:3d36234a1087 646 if(hnand->Info.BlockNbr >= 1024)
mbed_official 375:3d36234a1087 647 {
mbed_official 375:3d36234a1087 648 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_4th_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 649 }
mbed_official 375:3d36234a1087 650
mbed_official 375:3d36234a1087 651 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = 0x30;
mbed_official 375:3d36234a1087 652
mbed_official 375:3d36234a1087 653 /* Get Data into Buffer */
mbed_official 375:3d36234a1087 654 for ( ;index < size; index++)
mbed_official 375:3d36234a1087 655 {
mbed_official 375:3d36234a1087 656 *(uint8_t *)pBuffer++ = *(uint8_t *)deviceAddress;
mbed_official 375:3d36234a1087 657 }
mbed_official 375:3d36234a1087 658
mbed_official 375:3d36234a1087 659 /* Increment read spare areas number */
mbed_official 375:3d36234a1087 660 numSpareAreaRead++;
mbed_official 375:3d36234a1087 661
mbed_official 375:3d36234a1087 662 /* Decrement spare areas to read */
mbed_official 375:3d36234a1087 663 NumSpareAreaToRead--;
mbed_official 375:3d36234a1087 664
mbed_official 375:3d36234a1087 665 /* Increment the NAND address */
mbed_official 375:3d36234a1087 666 nandAddress = (uint32_t)(nandAddress + (hnand->Info.SpareAreaSize));
mbed_official 375:3d36234a1087 667 }
mbed_official 375:3d36234a1087 668
mbed_official 375:3d36234a1087 669 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 670 hnand->State = HAL_NAND_STATE_READY;
mbed_official 375:3d36234a1087 671
mbed_official 375:3d36234a1087 672 /* Process unlocked */
mbed_official 375:3d36234a1087 673 __HAL_UNLOCK(hnand);
mbed_official 375:3d36234a1087 674
mbed_official 375:3d36234a1087 675 return HAL_OK;
mbed_official 375:3d36234a1087 676 }
mbed_official 375:3d36234a1087 677
mbed_official 375:3d36234a1087 678 /**
mbed_official 375:3d36234a1087 679 * @brief Write Spare area(s) to NAND memory
mbed_official 375:3d36234a1087 680 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 681 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 682 * @param pAddress : pointer to NAND address structure
mbed_official 375:3d36234a1087 683 * @param pBuffer : pointer to source buffer to write
mbed_official 375:3d36234a1087 684 * @param NumSpareAreaTowrite : number of spare areas to write to block
mbed_official 375:3d36234a1087 685 * @retval HAL status
mbed_official 375:3d36234a1087 686 */
mbed_official 375:3d36234a1087 687 HAL_StatusTypeDef HAL_NAND_Write_SpareArea(NAND_HandleTypeDef *hnand, NAND_AddressTypedef *pAddress, uint8_t *pBuffer, uint32_t NumSpareAreaTowrite)
mbed_official 375:3d36234a1087 688 {
mbed_official 375:3d36234a1087 689 __IO uint32_t index = 0;
mbed_official 375:3d36234a1087 690 uint32_t timeout = 0;
mbed_official 375:3d36234a1087 691 uint32_t deviceAddress = 0, size = 0, numSpareAreaWritten = 0, nandAddress = 0;
mbed_official 375:3d36234a1087 692
mbed_official 375:3d36234a1087 693 /* Process Locked */
mbed_official 375:3d36234a1087 694 __HAL_LOCK(hnand);
mbed_official 375:3d36234a1087 695
mbed_official 375:3d36234a1087 696 /* Check the NAND controller state */
mbed_official 375:3d36234a1087 697 if(hnand->State == HAL_NAND_STATE_BUSY)
mbed_official 375:3d36234a1087 698 {
mbed_official 375:3d36234a1087 699 return HAL_BUSY;
mbed_official 375:3d36234a1087 700 }
mbed_official 375:3d36234a1087 701
mbed_official 375:3d36234a1087 702 /* Identify the device address */
mbed_official 375:3d36234a1087 703 if(hnand->Init.NandBank == FMC_NAND_BANK2)
mbed_official 375:3d36234a1087 704 {
mbed_official 375:3d36234a1087 705 deviceAddress = NAND_DEVICE1;
mbed_official 375:3d36234a1087 706 }
mbed_official 375:3d36234a1087 707 else
mbed_official 375:3d36234a1087 708 {
mbed_official 375:3d36234a1087 709 deviceAddress = NAND_DEVICE2;
mbed_official 375:3d36234a1087 710 }
mbed_official 375:3d36234a1087 711
mbed_official 375:3d36234a1087 712 /* Update the FMC_NAND controller state */
mbed_official 375:3d36234a1087 713 hnand->State = HAL_NAND_STATE_BUSY;
mbed_official 375:3d36234a1087 714
mbed_official 375:3d36234a1087 715 /* NAND raw address calculation */
mbed_official 375:3d36234a1087 716 nandAddress = ARRAY_ADDRESS(pAddress, hnand);
mbed_official 375:3d36234a1087 717
mbed_official 375:3d36234a1087 718 /* Spare area(s) write loop */
mbed_official 375:3d36234a1087 719 while((NumSpareAreaTowrite != 0) && (nandAddress < ((hnand->Info.BlockSize) * (hnand->Info.SpareAreaSize) * (hnand->Info.ZoneSize))))
mbed_official 375:3d36234a1087 720 {
mbed_official 375:3d36234a1087 721 /* update the buffer size */
mbed_official 375:3d36234a1087 722 size = (hnand->Info.SpareAreaSize) + ((hnand->Info.SpareAreaSize) * numSpareAreaWritten);
mbed_official 375:3d36234a1087 723
mbed_official 375:3d36234a1087 724 /* Send write Spare area command sequence */
mbed_official 375:3d36234a1087 725 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = NAND_CMD_AREA_C;
mbed_official 375:3d36234a1087 726 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = 0x80;
mbed_official 375:3d36234a1087 727
mbed_official 375:3d36234a1087 728 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = 0x00;
mbed_official 375:3d36234a1087 729 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_1st_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 730 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_2nd_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 731 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_3rd_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 732
mbed_official 375:3d36234a1087 733 /* for 512 and 1 GB devices, 4th cycle is required */
mbed_official 375:3d36234a1087 734 if(hnand->Info.BlockNbr >= 1024)
mbed_official 375:3d36234a1087 735 {
mbed_official 375:3d36234a1087 736 *(__IO uint8_t *)((uint32_t)(deviceAddress | ADDR_AREA)) = ADDR_4th_CYCLE(nandAddress);
mbed_official 375:3d36234a1087 737 }
mbed_official 375:3d36234a1087 738
mbed_official 375:3d36234a1087 739 /* Write data to memory */
mbed_official 375:3d36234a1087 740 for(; index < size; index++)
mbed_official 375:3d36234a1087 741 {
mbed_official 375:3d36234a1087 742 *(__IO uint8_t *)deviceAddress = *(uint8_t *)pBuffer++;
mbed_official 375:3d36234a1087 743 }
mbed_official 375:3d36234a1087 744
mbed_official 375:3d36234a1087 745 *(__IO uint8_t *)((uint32_t)(deviceAddress | CMD_AREA)) = 0x10;
mbed_official 375:3d36234a1087 746
mbed_official 375:3d36234a1087 747
mbed_official 375:3d36234a1087 748 /* Read status until NAND is ready */
mbed_official 375:3d36234a1087 749 while(HAL_NAND_Read_Status(hnand) != NAND_READY)
mbed_official 375:3d36234a1087 750 {
mbed_official 375:3d36234a1087 751 /* Check for timeout value */
mbed_official 375:3d36234a1087 752 timeout = HAL_GetTick() + NAND_WRITE_TIMEOUT;
mbed_official 375:3d36234a1087 753
mbed_official 375:3d36234a1087 754 if(HAL_GetTick() >= timeout)
mbed_official 375:3d36234a1087 755 {
mbed_official 375:3d36234a1087 756 return HAL_TIMEOUT;
mbed_official 375:3d36234a1087 757 }
mbed_official 375:3d36234a1087 758 }
mbed_official 375:3d36234a1087 759
mbed_official 375:3d36234a1087 760 /* Increment written spare areas number */
mbed_official 375:3d36234a1087 761 numSpareAreaWritten++;
mbed_official 375:3d36234a1087 762
mbed_official 375:3d36234a1087 763 /* Decrement spare areas to write */
mbed_official 375:3d36234a1087 764 NumSpareAreaTowrite--;
mbed_official 375:3d36234a1087 765
mbed_official 375:3d36234a1087 766 /* Increment the NAND address */
mbed_official 375:3d36234a1087 767 nandAddress = (uint32_t)(nandAddress + (hnand->Info.PageSize));
mbed_official 375:3d36234a1087 768
mbed_official 375:3d36234a1087 769 }
mbed_official 375:3d36234a1087 770
mbed_official 375:3d36234a1087 771 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 772 hnand->State = HAL_NAND_STATE_READY;
mbed_official 375:3d36234a1087 773
mbed_official 375:3d36234a1087 774 /* Process unlocked */
mbed_official 375:3d36234a1087 775 __HAL_UNLOCK(hnand);
mbed_official 375:3d36234a1087 776
mbed_official 375:3d36234a1087 777 return HAL_OK;
mbed_official 375:3d36234a1087 778 }
mbed_official 375:3d36234a1087 779
mbed_official 375:3d36234a1087 780 /**
mbed_official 375:3d36234a1087 781 * @brief NAND memory Block erase
mbed_official 375:3d36234a1087 782 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 783 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 784 * @param pAddress : pointer to NAND address structure
mbed_official 375:3d36234a1087 785 * @retval HAL status
mbed_official 375:3d36234a1087 786 */
mbed_official 375:3d36234a1087 787 HAL_StatusTypeDef HAL_NAND_Erase_Block(NAND_HandleTypeDef *hnand, NAND_AddressTypedef *pAddress)
mbed_official 375:3d36234a1087 788 {
mbed_official 375:3d36234a1087 789 uint32_t DeviceAddress = 0;
mbed_official 375:3d36234a1087 790
mbed_official 375:3d36234a1087 791 /* Process Locked */
mbed_official 375:3d36234a1087 792 __HAL_LOCK(hnand);
mbed_official 375:3d36234a1087 793
mbed_official 375:3d36234a1087 794 /* Check the NAND controller state */
mbed_official 375:3d36234a1087 795 if(hnand->State == HAL_NAND_STATE_BUSY)
mbed_official 375:3d36234a1087 796 {
mbed_official 375:3d36234a1087 797 return HAL_BUSY;
mbed_official 375:3d36234a1087 798 }
mbed_official 375:3d36234a1087 799
mbed_official 375:3d36234a1087 800 /* Identify the device address */
mbed_official 375:3d36234a1087 801 if(hnand->Init.NandBank == FMC_NAND_BANK2)
mbed_official 375:3d36234a1087 802 {
mbed_official 375:3d36234a1087 803 DeviceAddress = NAND_DEVICE1;
mbed_official 375:3d36234a1087 804 }
mbed_official 375:3d36234a1087 805 else
mbed_official 375:3d36234a1087 806 {
mbed_official 375:3d36234a1087 807 DeviceAddress = NAND_DEVICE2;
mbed_official 375:3d36234a1087 808 }
mbed_official 375:3d36234a1087 809
mbed_official 375:3d36234a1087 810 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 811 hnand->State = HAL_NAND_STATE_BUSY;
mbed_official 375:3d36234a1087 812
mbed_official 375:3d36234a1087 813 /* Send Erase block command sequence */
mbed_official 375:3d36234a1087 814 *(__IO uint8_t *)((uint32_t)(DeviceAddress | CMD_AREA)) = 0x60;
mbed_official 375:3d36234a1087 815
mbed_official 375:3d36234a1087 816 *(__IO uint8_t *)((uint32_t)(DeviceAddress | ADDR_AREA)) = ADDR_1st_CYCLE(ARRAY_ADDRESS(pAddress, hnand));
mbed_official 375:3d36234a1087 817 *(__IO uint8_t *)((uint32_t)(DeviceAddress | ADDR_AREA)) = ADDR_2nd_CYCLE(ARRAY_ADDRESS(pAddress, hnand));
mbed_official 375:3d36234a1087 818 *(__IO uint8_t *)((uint32_t)(DeviceAddress | ADDR_AREA)) = ADDR_3rd_CYCLE(ARRAY_ADDRESS(pAddress, hnand));
mbed_official 375:3d36234a1087 819
mbed_official 375:3d36234a1087 820 /* for 512 and 1 GB devices, 4th cycle is required */
mbed_official 375:3d36234a1087 821 if(hnand->Info.BlockNbr >= 1024)
mbed_official 375:3d36234a1087 822 {
mbed_official 375:3d36234a1087 823 *(__IO uint8_t *)((uint32_t)(DeviceAddress | ADDR_AREA)) = ADDR_4th_CYCLE(ARRAY_ADDRESS(pAddress, hnand));
mbed_official 375:3d36234a1087 824 }
mbed_official 375:3d36234a1087 825
mbed_official 375:3d36234a1087 826 *(__IO uint8_t *)((uint32_t)(DeviceAddress | CMD_AREA)) = 0xD0;
mbed_official 375:3d36234a1087 827
mbed_official 375:3d36234a1087 828 /* Update the NAND controller state */
mbed_official 375:3d36234a1087 829 hnand->State = HAL_NAND_STATE_READY;
mbed_official 375:3d36234a1087 830
mbed_official 375:3d36234a1087 831 /* Process unlocked */
mbed_official 375:3d36234a1087 832 __HAL_UNLOCK(hnand);
mbed_official 375:3d36234a1087 833
mbed_official 375:3d36234a1087 834 return HAL_OK;
mbed_official 375:3d36234a1087 835 }
mbed_official 375:3d36234a1087 836
mbed_official 375:3d36234a1087 837
mbed_official 375:3d36234a1087 838 /**
mbed_official 375:3d36234a1087 839 * @brief NAND memory read status
mbed_official 375:3d36234a1087 840 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 841 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 842 * @retval NAND status
mbed_official 375:3d36234a1087 843 */
mbed_official 375:3d36234a1087 844 uint32_t HAL_NAND_Read_Status(NAND_HandleTypeDef *hnand)
mbed_official 375:3d36234a1087 845 {
mbed_official 375:3d36234a1087 846 uint32_t data = 0;
mbed_official 375:3d36234a1087 847 uint32_t DeviceAddress = 0;
mbed_official 375:3d36234a1087 848
mbed_official 375:3d36234a1087 849 /* Identify the device address */
mbed_official 375:3d36234a1087 850 if(hnand->Init.NandBank == FMC_NAND_BANK2)
mbed_official 375:3d36234a1087 851 {
mbed_official 375:3d36234a1087 852 DeviceAddress = NAND_DEVICE1;
mbed_official 375:3d36234a1087 853 }
mbed_official 375:3d36234a1087 854 else
mbed_official 375:3d36234a1087 855 {
mbed_official 375:3d36234a1087 856 DeviceAddress = NAND_DEVICE2;
mbed_official 375:3d36234a1087 857 }
mbed_official 375:3d36234a1087 858
mbed_official 375:3d36234a1087 859 /* Send Read status operation command */
mbed_official 375:3d36234a1087 860 *(__IO uint8_t *)((uint32_t)(DeviceAddress | CMD_AREA)) = 0x70;
mbed_official 375:3d36234a1087 861
mbed_official 375:3d36234a1087 862 /* Read status register data */
mbed_official 375:3d36234a1087 863 data = *(__IO uint8_t *)DeviceAddress;
mbed_official 375:3d36234a1087 864
mbed_official 375:3d36234a1087 865 /* Return the status */
mbed_official 375:3d36234a1087 866 if((data & NAND_ERROR) == NAND_ERROR)
mbed_official 375:3d36234a1087 867 {
mbed_official 375:3d36234a1087 868 return NAND_ERROR;
mbed_official 375:3d36234a1087 869 }
mbed_official 375:3d36234a1087 870 else if((data & NAND_READY) == NAND_READY)
mbed_official 375:3d36234a1087 871 {
mbed_official 375:3d36234a1087 872 return NAND_READY;
mbed_official 375:3d36234a1087 873 }
mbed_official 375:3d36234a1087 874
mbed_official 375:3d36234a1087 875 return NAND_BUSY;
mbed_official 375:3d36234a1087 876
mbed_official 375:3d36234a1087 877 }
mbed_official 375:3d36234a1087 878
mbed_official 375:3d36234a1087 879 /**
mbed_official 375:3d36234a1087 880 * @brief Increment the NAND memory address
mbed_official 375:3d36234a1087 881 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 882 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 883 * @param pAddress: pointer to NAND adress structure
mbed_official 375:3d36234a1087 884 * @retval The new status of the increment address operation. It can be:
mbed_official 375:3d36234a1087 885 * - NAND_VALID_ADDRESS: When the new address is valid address
mbed_official 375:3d36234a1087 886 * - NAND_INVALID_ADDRESS: When the new address is invalid address
mbed_official 375:3d36234a1087 887 */
mbed_official 375:3d36234a1087 888 uint32_t HAL_NAND_Address_Inc(NAND_HandleTypeDef *hnand, NAND_AddressTypedef *pAddress)
mbed_official 375:3d36234a1087 889 {
mbed_official 375:3d36234a1087 890 uint32_t status = NAND_VALID_ADDRESS;
mbed_official 375:3d36234a1087 891
mbed_official 375:3d36234a1087 892 /* Increment page address */
mbed_official 375:3d36234a1087 893 pAddress->Page++;
mbed_official 375:3d36234a1087 894
mbed_official 375:3d36234a1087 895 /* Check NAND address is valid */
mbed_official 375:3d36234a1087 896 if(pAddress->Page == hnand->Info.BlockSize)
mbed_official 375:3d36234a1087 897 {
mbed_official 375:3d36234a1087 898 pAddress->Page = 0;
mbed_official 375:3d36234a1087 899 pAddress->Block++;
mbed_official 375:3d36234a1087 900
mbed_official 375:3d36234a1087 901 if(pAddress->Block == hnand->Info.ZoneSize)
mbed_official 375:3d36234a1087 902 {
mbed_official 375:3d36234a1087 903 pAddress->Block = 0;
mbed_official 375:3d36234a1087 904 pAddress->Zone++;
mbed_official 375:3d36234a1087 905
mbed_official 375:3d36234a1087 906 if(pAddress->Zone == (hnand->Info.ZoneSize/ hnand->Info.BlockNbr))
mbed_official 375:3d36234a1087 907 {
mbed_official 375:3d36234a1087 908 status = NAND_INVALID_ADDRESS;
mbed_official 375:3d36234a1087 909 }
mbed_official 375:3d36234a1087 910 }
mbed_official 375:3d36234a1087 911 }
mbed_official 375:3d36234a1087 912
mbed_official 375:3d36234a1087 913 return (status);
mbed_official 375:3d36234a1087 914 }
mbed_official 375:3d36234a1087 915
mbed_official 375:3d36234a1087 916
mbed_official 375:3d36234a1087 917 /**
mbed_official 375:3d36234a1087 918 * @}
mbed_official 375:3d36234a1087 919 */
mbed_official 375:3d36234a1087 920
mbed_official 375:3d36234a1087 921 /** @defgroup NAND_Exported_Functions_Group3 Peripheral Control functions
mbed_official 375:3d36234a1087 922 * @brief management functions
mbed_official 375:3d36234a1087 923 *
mbed_official 375:3d36234a1087 924 @verbatim
mbed_official 375:3d36234a1087 925 ==============================================================================
mbed_official 375:3d36234a1087 926 ##### NAND Control functions #####
mbed_official 375:3d36234a1087 927 ==============================================================================
mbed_official 375:3d36234a1087 928 [..]
mbed_official 375:3d36234a1087 929 This subsection provides a set of functions allowing to control dynamically
mbed_official 375:3d36234a1087 930 the NAND interface.
mbed_official 375:3d36234a1087 931
mbed_official 375:3d36234a1087 932 @endverbatim
mbed_official 375:3d36234a1087 933 * @{
mbed_official 375:3d36234a1087 934 */
mbed_official 375:3d36234a1087 935
mbed_official 375:3d36234a1087 936
mbed_official 375:3d36234a1087 937 /**
mbed_official 375:3d36234a1087 938 * @brief Enables dynamically NAND ECC feature.
mbed_official 375:3d36234a1087 939 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 940 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 941 * @retval HAL status
mbed_official 375:3d36234a1087 942 */
mbed_official 375:3d36234a1087 943 HAL_StatusTypeDef HAL_NAND_ECC_Enable(NAND_HandleTypeDef *hnand)
mbed_official 375:3d36234a1087 944 {
mbed_official 375:3d36234a1087 945 /* Check the NAND controller state */
mbed_official 375:3d36234a1087 946 if(hnand->State == HAL_NAND_STATE_BUSY)
mbed_official 375:3d36234a1087 947 {
mbed_official 375:3d36234a1087 948 return HAL_BUSY;
mbed_official 375:3d36234a1087 949 }
mbed_official 375:3d36234a1087 950
mbed_official 375:3d36234a1087 951 /* Update the NAND state */
mbed_official 375:3d36234a1087 952 hnand->State = HAL_NAND_STATE_BUSY;
mbed_official 375:3d36234a1087 953
mbed_official 375:3d36234a1087 954 /* Enable ECC feature */
mbed_official 375:3d36234a1087 955 FMC_NAND_ECC_Enable(hnand->Instance, hnand->Init.NandBank);
mbed_official 375:3d36234a1087 956
mbed_official 375:3d36234a1087 957 /* Update the NAND state */
mbed_official 375:3d36234a1087 958 hnand->State = HAL_NAND_STATE_READY;
mbed_official 375:3d36234a1087 959
mbed_official 375:3d36234a1087 960 return HAL_OK;
mbed_official 375:3d36234a1087 961 }
mbed_official 375:3d36234a1087 962
mbed_official 375:3d36234a1087 963
mbed_official 375:3d36234a1087 964 /**
mbed_official 375:3d36234a1087 965 * @brief Disables dynamically FMC_NAND ECC feature.
mbed_official 375:3d36234a1087 966 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 967 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 968 * @retval HAL status
mbed_official 375:3d36234a1087 969 */
mbed_official 375:3d36234a1087 970 HAL_StatusTypeDef HAL_NAND_ECC_Disable(NAND_HandleTypeDef *hnand)
mbed_official 375:3d36234a1087 971 {
mbed_official 375:3d36234a1087 972 /* Check the NAND controller state */
mbed_official 375:3d36234a1087 973 if(hnand->State == HAL_NAND_STATE_BUSY)
mbed_official 375:3d36234a1087 974 {
mbed_official 375:3d36234a1087 975 return HAL_BUSY;
mbed_official 375:3d36234a1087 976 }
mbed_official 375:3d36234a1087 977
mbed_official 375:3d36234a1087 978 /* Update the NAND state */
mbed_official 375:3d36234a1087 979 hnand->State = HAL_NAND_STATE_BUSY;
mbed_official 375:3d36234a1087 980
mbed_official 375:3d36234a1087 981 /* Disable ECC feature */
mbed_official 375:3d36234a1087 982 FMC_NAND_ECC_Disable(hnand->Instance, hnand->Init.NandBank);
mbed_official 375:3d36234a1087 983
mbed_official 375:3d36234a1087 984 /* Update the NAND state */
mbed_official 375:3d36234a1087 985 hnand->State = HAL_NAND_STATE_READY;
mbed_official 375:3d36234a1087 986
mbed_official 375:3d36234a1087 987 return HAL_OK;
mbed_official 375:3d36234a1087 988 }
mbed_official 375:3d36234a1087 989
mbed_official 375:3d36234a1087 990 /**
mbed_official 375:3d36234a1087 991 * @brief Disables dynamically NAND ECC feature.
mbed_official 375:3d36234a1087 992 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 993 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 994 * @param ECCval: pointer to ECC value
mbed_official 375:3d36234a1087 995 * @param Timeout: maximum timeout to wait
mbed_official 375:3d36234a1087 996 * @retval HAL status
mbed_official 375:3d36234a1087 997 */
mbed_official 375:3d36234a1087 998 HAL_StatusTypeDef HAL_NAND_GetECC(NAND_HandleTypeDef *hnand, uint32_t *ECCval, uint32_t Timeout)
mbed_official 375:3d36234a1087 999 {
mbed_official 375:3d36234a1087 1000 HAL_StatusTypeDef status = HAL_OK;
mbed_official 375:3d36234a1087 1001
mbed_official 375:3d36234a1087 1002 /* Check the NAND controller state */
mbed_official 375:3d36234a1087 1003 if(hnand->State == HAL_NAND_STATE_BUSY)
mbed_official 375:3d36234a1087 1004 {
mbed_official 375:3d36234a1087 1005 return HAL_BUSY;
mbed_official 375:3d36234a1087 1006 }
mbed_official 375:3d36234a1087 1007
mbed_official 375:3d36234a1087 1008 /* Update the NAND state */
mbed_official 375:3d36234a1087 1009 hnand->State = HAL_NAND_STATE_BUSY;
mbed_official 375:3d36234a1087 1010
mbed_official 375:3d36234a1087 1011 /* Get NAND ECC value */
mbed_official 375:3d36234a1087 1012 status = FMC_NAND_GetECC(hnand->Instance, ECCval, hnand->Init.NandBank, Timeout);
mbed_official 375:3d36234a1087 1013
mbed_official 375:3d36234a1087 1014 /* Update the NAND state */
mbed_official 375:3d36234a1087 1015 hnand->State = HAL_NAND_STATE_READY;
mbed_official 375:3d36234a1087 1016
mbed_official 375:3d36234a1087 1017 return status;
mbed_official 375:3d36234a1087 1018 }
mbed_official 375:3d36234a1087 1019
mbed_official 375:3d36234a1087 1020 /**
mbed_official 375:3d36234a1087 1021 * @}
mbed_official 375:3d36234a1087 1022 */
mbed_official 375:3d36234a1087 1023
mbed_official 375:3d36234a1087 1024
mbed_official 375:3d36234a1087 1025 /** @defgroup NAND_Exported_Functions_Group4 Peripheral State functions
mbed_official 375:3d36234a1087 1026 * @brief Peripheral State functions
mbed_official 375:3d36234a1087 1027 *
mbed_official 375:3d36234a1087 1028 @verbatim
mbed_official 375:3d36234a1087 1029 ==============================================================================
mbed_official 375:3d36234a1087 1030 ##### NAND State functions #####
mbed_official 375:3d36234a1087 1031 ==============================================================================
mbed_official 375:3d36234a1087 1032 [..]
mbed_official 375:3d36234a1087 1033 This subsection permits to get in run-time the status of the NAND controller
mbed_official 375:3d36234a1087 1034 and the data flow.
mbed_official 375:3d36234a1087 1035
mbed_official 375:3d36234a1087 1036 @endverbatim
mbed_official 375:3d36234a1087 1037 * @{
mbed_official 375:3d36234a1087 1038 */
mbed_official 375:3d36234a1087 1039
mbed_official 375:3d36234a1087 1040 /**
mbed_official 375:3d36234a1087 1041 * @brief return the NAND state
mbed_official 375:3d36234a1087 1042 * @param hnand: pointer to a NAND_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 1043 * the configuration information for NAND module.
mbed_official 375:3d36234a1087 1044 * @retval HAL state
mbed_official 375:3d36234a1087 1045 */
mbed_official 375:3d36234a1087 1046 HAL_NAND_StateTypeDef HAL_NAND_GetState(NAND_HandleTypeDef *hnand)
mbed_official 375:3d36234a1087 1047 {
mbed_official 375:3d36234a1087 1048 return hnand->State;
mbed_official 375:3d36234a1087 1049 }
mbed_official 375:3d36234a1087 1050
mbed_official 375:3d36234a1087 1051 /**
mbed_official 375:3d36234a1087 1052 * @}
mbed_official 375:3d36234a1087 1053 */
mbed_official 375:3d36234a1087 1054
mbed_official 375:3d36234a1087 1055 /**
mbed_official 375:3d36234a1087 1056 * @}
mbed_official 375:3d36234a1087 1057 */
mbed_official 375:3d36234a1087 1058 #endif /* STM32F302xE || STM32F303xE || STM32F398xx */
mbed_official 375:3d36234a1087 1059 #endif /* HAL_NAND_MODULE_ENABLED */
mbed_official 375:3d36234a1087 1060
mbed_official 375:3d36234a1087 1061 /**
mbed_official 375:3d36234a1087 1062 * @}
mbed_official 375:3d36234a1087 1063 */
mbed_official 375:3d36234a1087 1064
mbed_official 375:3d36234a1087 1065 /**
mbed_official 375:3d36234a1087 1066 * @}
mbed_official 375:3d36234a1087 1067 */
mbed_official 375:3d36234a1087 1068
mbed_official 375:3d36234a1087 1069 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/