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