Lancaster University's (short term!) clone of mbed-src for micro:bit. This is a copy of the github branch https://github.com/lancaster-university/mbed-classic

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

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