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