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