mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Jul 02 16:30:08 2015 +0100
Revision:
581:39197bcd20f2
Parent:
489:119543c9f674
Synchronized with git revision ae2d3cdffe70184eb8736d94f76c45c93f4b7724

Full URL: https://github.com/mbedmicro/mbed/commit/ae2d3cdffe70184eb8736d94f76c45c93f4b7724/

Make it possible to build the core mbed library with yotta

Who changed what in which revision?

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