mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_nor.c@87:085cde657901, 2014-02-08 (annotated)
- Committer:
- mbed_official
- Date:
- Sat Feb 08 19:45:06 2014 +0000
- Revision:
- 87:085cde657901
- Child:
- 106:ced8cbb51063
Synchronized with git revision 9272cdeb45ec7e6077641536509413da8fd2ebc2
Full URL: https://github.com/mbedmicro/mbed/commit/9272cdeb45ec7e6077641536509413da8fd2ebc2/
Add NUCLEO_F401RE, improvements
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_nor.c |
mbed_official | 87:085cde657901 | 4 | * @author MCD Application Team |
mbed_official | 87:085cde657901 | 5 | * @version V1.0.0RC2 |
mbed_official | 87:085cde657901 | 6 | * @date 04-February-2014 |
mbed_official | 87:085cde657901 | 7 | * @brief NOR HAL module driver. |
mbed_official | 87:085cde657901 | 8 | * This file provides a generic firmware to drive NOR 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 NOR flash memories. It uses the FMC/FSMC layer functions to interface |
mbed_official | 87:085cde657901 | 18 | with NOR devices. This driver is used as follows: |
mbed_official | 87:085cde657901 | 19 | |
mbed_official | 87:085cde657901 | 20 | (+) NOR flash memory configuration sequence using the function HAL_NOR_Init() |
mbed_official | 87:085cde657901 | 21 | with control and timing parameters for both normal and extended mode. |
mbed_official | 87:085cde657901 | 22 | |
mbed_official | 87:085cde657901 | 23 | (+) Read NOR flash memory manufacturer code and device IDs using the function |
mbed_official | 87:085cde657901 | 24 | HAL_NOR_Read_ID(). The read information is stored in the NOR_ID_TypeDef |
mbed_official | 87:085cde657901 | 25 | structure declared by the function caller. |
mbed_official | 87:085cde657901 | 26 | |
mbed_official | 87:085cde657901 | 27 | (+) Access NOR flash memory by read/write data unit operations using the functions |
mbed_official | 87:085cde657901 | 28 | HAL_NOR_Read(), HAL_NOR_Program(). |
mbed_official | 87:085cde657901 | 29 | |
mbed_official | 87:085cde657901 | 30 | (+) Perform NOR flash erase block/chip operations using the functions |
mbed_official | 87:085cde657901 | 31 | HAL_NOR_Erase_Block() and HAL_NOR_Erase_Chip(). |
mbed_official | 87:085cde657901 | 32 | |
mbed_official | 87:085cde657901 | 33 | (+) Read the NOR flash CFI (common flash interface) IDs using the function |
mbed_official | 87:085cde657901 | 34 | HAL_NOR_Read_CFI(). The read information is stored in the NOR_CFI_TypeDef |
mbed_official | 87:085cde657901 | 35 | structure declared by the function caller. |
mbed_official | 87:085cde657901 | 36 | |
mbed_official | 87:085cde657901 | 37 | (+) You can also control the NOR device by calling the control APIs HAL_NOR_WriteOperation_Enable()/ |
mbed_official | 87:085cde657901 | 38 | HAL_NOR_WriteOperation_Disable() to respectively enable/disable the NOR write operation |
mbed_official | 87:085cde657901 | 39 | |
mbed_official | 87:085cde657901 | 40 | (+) You can monitor the NOR device HAL state by calling the function |
mbed_official | 87:085cde657901 | 41 | HAL_NOR_GetState() |
mbed_official | 87:085cde657901 | 42 | [..] |
mbed_official | 87:085cde657901 | 43 | (@) This driver is a set of generic APIs which handle standard NOR flash operations. |
mbed_official | 87:085cde657901 | 44 | If a NOR flash device contains different operations and/or implementations, |
mbed_official | 87:085cde657901 | 45 | it should be implemented separately. |
mbed_official | 87:085cde657901 | 46 | |
mbed_official | 87:085cde657901 | 47 | *** NOR HAL driver macros list *** |
mbed_official | 87:085cde657901 | 48 | ============================================= |
mbed_official | 87:085cde657901 | 49 | [..] |
mbed_official | 87:085cde657901 | 50 | Below the list of most used macros in NOR HAL driver. |
mbed_official | 87:085cde657901 | 51 | |
mbed_official | 87:085cde657901 | 52 | (+) __NOR_WRITE : NOR memory write data to specified address |
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 NOR |
mbed_official | 87:085cde657901 | 93 | * @brief NOR driver modules |
mbed_official | 87:085cde657901 | 94 | * @{ |
mbed_official | 87:085cde657901 | 95 | */ |
mbed_official | 87:085cde657901 | 96 | #ifdef HAL_NOR_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 | |
mbed_official | 87:085cde657901 | 106 | |
mbed_official | 87:085cde657901 | 107 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 108 | |
mbed_official | 87:085cde657901 | 109 | /** @defgroup NOR_Private_Functions |
mbed_official | 87:085cde657901 | 110 | * @{ |
mbed_official | 87:085cde657901 | 111 | */ |
mbed_official | 87:085cde657901 | 112 | |
mbed_official | 87:085cde657901 | 113 | /** @defgroup NOR_Group1 Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 114 | * @brief Initialization and Configuration functions |
mbed_official | 87:085cde657901 | 115 | * |
mbed_official | 87:085cde657901 | 116 | @verbatim |
mbed_official | 87:085cde657901 | 117 | ============================================================================== |
mbed_official | 87:085cde657901 | 118 | ##### NOR Initialization and de_initialization functions ##### |
mbed_official | 87:085cde657901 | 119 | ============================================================================== |
mbed_official | 87:085cde657901 | 120 | [..] |
mbed_official | 87:085cde657901 | 121 | This section provides functions allowing to initialize/de-initialize |
mbed_official | 87:085cde657901 | 122 | the NOR memory |
mbed_official | 87:085cde657901 | 123 | |
mbed_official | 87:085cde657901 | 124 | @endverbatim |
mbed_official | 87:085cde657901 | 125 | * @{ |
mbed_official | 87:085cde657901 | 126 | */ |
mbed_official | 87:085cde657901 | 127 | |
mbed_official | 87:085cde657901 | 128 | /** |
mbed_official | 87:085cde657901 | 129 | * @brief Perform the NOR memory Initialization sequence |
mbed_official | 87:085cde657901 | 130 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 131 | * @param Timing: pointer to NOR control timing structure |
mbed_official | 87:085cde657901 | 132 | * @param ExtTiming: pointer to NOR extended mode timing structure |
mbed_official | 87:085cde657901 | 133 | * @retval HAL status |
mbed_official | 87:085cde657901 | 134 | */ |
mbed_official | 87:085cde657901 | 135 | HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming) |
mbed_official | 87:085cde657901 | 136 | { |
mbed_official | 87:085cde657901 | 137 | /* Check the NOR handle parameter */ |
mbed_official | 87:085cde657901 | 138 | if(hnor == NULL) |
mbed_official | 87:085cde657901 | 139 | { |
mbed_official | 87:085cde657901 | 140 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 141 | } |
mbed_official | 87:085cde657901 | 142 | |
mbed_official | 87:085cde657901 | 143 | if(hnor->State == HAL_NOR_STATE_RESET) |
mbed_official | 87:085cde657901 | 144 | { |
mbed_official | 87:085cde657901 | 145 | /* Initialize the low level hardware (MSP) */ |
mbed_official | 87:085cde657901 | 146 | HAL_NOR_MspInit(hnor); |
mbed_official | 87:085cde657901 | 147 | } |
mbed_official | 87:085cde657901 | 148 | |
mbed_official | 87:085cde657901 | 149 | /* Initialize NOR control Interface */ |
mbed_official | 87:085cde657901 | 150 | FMC_NORSRAM_Init(hnor->Instance, &(hnor->Init)); |
mbed_official | 87:085cde657901 | 151 | |
mbed_official | 87:085cde657901 | 152 | /* Initialize NOR timing Interface */ |
mbed_official | 87:085cde657901 | 153 | FMC_NORSRAM_Timing_Init(hnor->Instance, Timing, hnor->Init.NSBank); |
mbed_official | 87:085cde657901 | 154 | |
mbed_official | 87:085cde657901 | 155 | /* Initialize NOR extended mode timing Interface */ |
mbed_official | 87:085cde657901 | 156 | FMC_NORSRAM_Extended_Timing_Init(hnor->Extended, ExtTiming, hnor->Init.NSBank, hnor->Init.ExtendedMode); |
mbed_official | 87:085cde657901 | 157 | |
mbed_official | 87:085cde657901 | 158 | /* Enable the NORSRAM device */ |
mbed_official | 87:085cde657901 | 159 | __FMC_NORSRAM_ENABLE(hnor->Instance, hnor->Init.NSBank); |
mbed_official | 87:085cde657901 | 160 | |
mbed_official | 87:085cde657901 | 161 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 162 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 163 | |
mbed_official | 87:085cde657901 | 164 | return HAL_OK; |
mbed_official | 87:085cde657901 | 165 | |
mbed_official | 87:085cde657901 | 166 | } |
mbed_official | 87:085cde657901 | 167 | |
mbed_official | 87:085cde657901 | 168 | /** |
mbed_official | 87:085cde657901 | 169 | * @brief Perform NOR memory De-Initialization sequence |
mbed_official | 87:085cde657901 | 170 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 171 | * @retval HAL status |
mbed_official | 87:085cde657901 | 172 | */ |
mbed_official | 87:085cde657901 | 173 | HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor) |
mbed_official | 87:085cde657901 | 174 | { |
mbed_official | 87:085cde657901 | 175 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 176 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 87:085cde657901 | 177 | |
mbed_official | 87:085cde657901 | 178 | /* De-Initialize the low level hardware (MSP) */ |
mbed_official | 87:085cde657901 | 179 | HAL_NOR_MspDeInit(hnor); |
mbed_official | 87:085cde657901 | 180 | |
mbed_official | 87:085cde657901 | 181 | /* Configure the NOR registers with their reset values */ |
mbed_official | 87:085cde657901 | 182 | FMC_NORSRAM_DeInit(hnor->Instance, hnor->Extended, hnor->Init.NSBank); |
mbed_official | 87:085cde657901 | 183 | |
mbed_official | 87:085cde657901 | 184 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 185 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 186 | |
mbed_official | 87:085cde657901 | 187 | return HAL_OK; |
mbed_official | 87:085cde657901 | 188 | } |
mbed_official | 87:085cde657901 | 189 | |
mbed_official | 87:085cde657901 | 190 | /** |
mbed_official | 87:085cde657901 | 191 | * @brief NOR MSP Init |
mbed_official | 87:085cde657901 | 192 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 193 | * @retval None |
mbed_official | 87:085cde657901 | 194 | */ |
mbed_official | 87:085cde657901 | 195 | __weak void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor) |
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_NOR_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 NOR MSP DeInit |
mbed_official | 87:085cde657901 | 204 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 205 | * @retval None |
mbed_official | 87:085cde657901 | 206 | */ |
mbed_official | 87:085cde657901 | 207 | __weak void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor) |
mbed_official | 87:085cde657901 | 208 | { |
mbed_official | 87:085cde657901 | 209 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 210 | the HAL_NOR_MspDeInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 211 | */ |
mbed_official | 87:085cde657901 | 212 | } |
mbed_official | 87:085cde657901 | 213 | |
mbed_official | 87:085cde657901 | 214 | /** |
mbed_official | 87:085cde657901 | 215 | * @brief NOR BSP Wait fro Ready/Busy signal |
mbed_official | 87:085cde657901 | 216 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 217 | * @param Timeout: Maximum timeout value |
mbed_official | 87:085cde657901 | 218 | * @retval None |
mbed_official | 87:085cde657901 | 219 | */ |
mbed_official | 87:085cde657901 | 220 | __weak void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 221 | { |
mbed_official | 87:085cde657901 | 222 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 223 | the HAL_NOR_BspWait could be implemented in the user file |
mbed_official | 87:085cde657901 | 224 | */ |
mbed_official | 87:085cde657901 | 225 | } |
mbed_official | 87:085cde657901 | 226 | |
mbed_official | 87:085cde657901 | 227 | /** |
mbed_official | 87:085cde657901 | 228 | * @} |
mbed_official | 87:085cde657901 | 229 | */ |
mbed_official | 87:085cde657901 | 230 | |
mbed_official | 87:085cde657901 | 231 | /** @defgroup NOR_Group2 Input and Output functions |
mbed_official | 87:085cde657901 | 232 | * @brief Input Output and memory control functions |
mbed_official | 87:085cde657901 | 233 | * |
mbed_official | 87:085cde657901 | 234 | @verbatim |
mbed_official | 87:085cde657901 | 235 | ============================================================================== |
mbed_official | 87:085cde657901 | 236 | ##### NOR Input and Output functions ##### |
mbed_official | 87:085cde657901 | 237 | ============================================================================== |
mbed_official | 87:085cde657901 | 238 | [..] |
mbed_official | 87:085cde657901 | 239 | This section provides functions allowing to use and control the NOR memory |
mbed_official | 87:085cde657901 | 240 | |
mbed_official | 87:085cde657901 | 241 | @endverbatim |
mbed_official | 87:085cde657901 | 242 | * @{ |
mbed_official | 87:085cde657901 | 243 | */ |
mbed_official | 87:085cde657901 | 244 | |
mbed_official | 87:085cde657901 | 245 | /** |
mbed_official | 87:085cde657901 | 246 | * @brief Read NOR flash IDs |
mbed_official | 87:085cde657901 | 247 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 248 | * @param pNOR_ID : pointer to NOR ID structure |
mbed_official | 87:085cde657901 | 249 | * @retval HAL status |
mbed_official | 87:085cde657901 | 250 | */ |
mbed_official | 87:085cde657901 | 251 | HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID) |
mbed_official | 87:085cde657901 | 252 | { |
mbed_official | 87:085cde657901 | 253 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 254 | __HAL_LOCK(hnor); |
mbed_official | 87:085cde657901 | 255 | |
mbed_official | 87:085cde657901 | 256 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 257 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 87:085cde657901 | 258 | { |
mbed_official | 87:085cde657901 | 259 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 260 | } |
mbed_official | 87:085cde657901 | 261 | |
mbed_official | 87:085cde657901 | 262 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 263 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 87:085cde657901 | 264 | |
mbed_official | 87:085cde657901 | 265 | /* Send read ID command */ |
mbed_official | 87:085cde657901 | 266 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA); |
mbed_official | 87:085cde657901 | 267 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055); |
mbed_official | 87:085cde657901 | 268 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x0090); |
mbed_official | 87:085cde657901 | 269 | |
mbed_official | 87:085cde657901 | 270 | /* Read the NOR IDs */ |
mbed_official | 87:085cde657901 | 271 | pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) __NOR_ADDR_SHIFT(MC_ADDRESS); |
mbed_official | 87:085cde657901 | 272 | pNOR_ID->Device_Code1 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(DEVICE_CODE1_ADDR); |
mbed_official | 87:085cde657901 | 273 | pNOR_ID->Device_Code2 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(DEVICE_CODE2_ADDR); |
mbed_official | 87:085cde657901 | 274 | pNOR_ID->Device_Code3 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(DEVICE_CODE3_ADDR); |
mbed_official | 87:085cde657901 | 275 | |
mbed_official | 87:085cde657901 | 276 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 277 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 278 | |
mbed_official | 87:085cde657901 | 279 | /* Process unlocked */ |
mbed_official | 87:085cde657901 | 280 | __HAL_UNLOCK(hnor); |
mbed_official | 87:085cde657901 | 281 | |
mbed_official | 87:085cde657901 | 282 | return HAL_OK; |
mbed_official | 87:085cde657901 | 283 | } |
mbed_official | 87:085cde657901 | 284 | |
mbed_official | 87:085cde657901 | 285 | /** |
mbed_official | 87:085cde657901 | 286 | * @brief Returns the NOR memory to Read mode. |
mbed_official | 87:085cde657901 | 287 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 288 | * @retval HAL status |
mbed_official | 87:085cde657901 | 289 | */ |
mbed_official | 87:085cde657901 | 290 | HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor) |
mbed_official | 87:085cde657901 | 291 | { |
mbed_official | 87:085cde657901 | 292 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 293 | __HAL_LOCK(hnor); |
mbed_official | 87:085cde657901 | 294 | |
mbed_official | 87:085cde657901 | 295 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 296 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 87:085cde657901 | 297 | { |
mbed_official | 87:085cde657901 | 298 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 299 | } |
mbed_official | 87:085cde657901 | 300 | |
mbed_official | 87:085cde657901 | 301 | __NOR_WRITE(NOR_MEMORY_ADRESS, 0x00F0); |
mbed_official | 87:085cde657901 | 302 | |
mbed_official | 87:085cde657901 | 303 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 304 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 305 | |
mbed_official | 87:085cde657901 | 306 | /* Process unlocked */ |
mbed_official | 87:085cde657901 | 307 | __HAL_UNLOCK(hnor); |
mbed_official | 87:085cde657901 | 308 | |
mbed_official | 87:085cde657901 | 309 | return HAL_OK; |
mbed_official | 87:085cde657901 | 310 | } |
mbed_official | 87:085cde657901 | 311 | |
mbed_official | 87:085cde657901 | 312 | |
mbed_official | 87:085cde657901 | 313 | /** |
mbed_official | 87:085cde657901 | 314 | * @brief Read data from NOR memory |
mbed_official | 87:085cde657901 | 315 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 316 | * @param pAddress: pointer to Device address |
mbed_official | 87:085cde657901 | 317 | * @param pData : pointer to read data |
mbed_official | 87:085cde657901 | 318 | * @retval HAL status |
mbed_official | 87:085cde657901 | 319 | */ |
mbed_official | 87:085cde657901 | 320 | HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData) |
mbed_official | 87:085cde657901 | 321 | { |
mbed_official | 87:085cde657901 | 322 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 323 | __HAL_LOCK(hnor); |
mbed_official | 87:085cde657901 | 324 | |
mbed_official | 87:085cde657901 | 325 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 326 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 87:085cde657901 | 327 | { |
mbed_official | 87:085cde657901 | 328 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 329 | } |
mbed_official | 87:085cde657901 | 330 | |
mbed_official | 87:085cde657901 | 331 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 332 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 87:085cde657901 | 333 | |
mbed_official | 87:085cde657901 | 334 | /* Send read data command */ |
mbed_official | 87:085cde657901 | 335 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x00555), 0x00AA); |
mbed_official | 87:085cde657901 | 336 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x002AA), 0x0055); |
mbed_official | 87:085cde657901 | 337 | __NOR_WRITE(*pAddress, 0x00F0); |
mbed_official | 87:085cde657901 | 338 | |
mbed_official | 87:085cde657901 | 339 | /* Read the data */ |
mbed_official | 87:085cde657901 | 340 | *pData = *(__IO uint32_t *)pAddress; |
mbed_official | 87:085cde657901 | 341 | |
mbed_official | 87:085cde657901 | 342 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 343 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 344 | |
mbed_official | 87:085cde657901 | 345 | /* Process unlocked */ |
mbed_official | 87:085cde657901 | 346 | __HAL_UNLOCK(hnor); |
mbed_official | 87:085cde657901 | 347 | |
mbed_official | 87:085cde657901 | 348 | return HAL_OK; |
mbed_official | 87:085cde657901 | 349 | } |
mbed_official | 87:085cde657901 | 350 | |
mbed_official | 87:085cde657901 | 351 | |
mbed_official | 87:085cde657901 | 352 | /** |
mbed_official | 87:085cde657901 | 353 | * @brief Program data to NOR memory |
mbed_official | 87:085cde657901 | 354 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 355 | * @param pAddress: Device address |
mbed_official | 87:085cde657901 | 356 | * @param pData : pointer to the data to write |
mbed_official | 87:085cde657901 | 357 | * @retval HAL status |
mbed_official | 87:085cde657901 | 358 | */ |
mbed_official | 87:085cde657901 | 359 | HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData) |
mbed_official | 87:085cde657901 | 360 | { |
mbed_official | 87:085cde657901 | 361 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 362 | __HAL_LOCK(hnor); |
mbed_official | 87:085cde657901 | 363 | |
mbed_official | 87:085cde657901 | 364 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 365 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 87:085cde657901 | 366 | { |
mbed_official | 87:085cde657901 | 367 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 368 | } |
mbed_official | 87:085cde657901 | 369 | |
mbed_official | 87:085cde657901 | 370 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 371 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 87:085cde657901 | 372 | |
mbed_official | 87:085cde657901 | 373 | /* Send program data command */ |
mbed_official | 87:085cde657901 | 374 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA); |
mbed_official | 87:085cde657901 | 375 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055); |
mbed_official | 87:085cde657901 | 376 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00A0); |
mbed_official | 87:085cde657901 | 377 | |
mbed_official | 87:085cde657901 | 378 | /* Write the data */ |
mbed_official | 87:085cde657901 | 379 | __NOR_WRITE(pAddress, *pData); |
mbed_official | 87:085cde657901 | 380 | |
mbed_official | 87:085cde657901 | 381 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 382 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 383 | |
mbed_official | 87:085cde657901 | 384 | /* Process unlocked */ |
mbed_official | 87:085cde657901 | 385 | __HAL_UNLOCK(hnor); |
mbed_official | 87:085cde657901 | 386 | |
mbed_official | 87:085cde657901 | 387 | return HAL_OK; |
mbed_official | 87:085cde657901 | 388 | } |
mbed_official | 87:085cde657901 | 389 | |
mbed_official | 87:085cde657901 | 390 | |
mbed_official | 87:085cde657901 | 391 | /** |
mbed_official | 87:085cde657901 | 392 | * @brief Reads a block of data from the FMC NOR memory. |
mbed_official | 87:085cde657901 | 393 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 394 | * @param uwAddress: NOR memory internal address to read from. |
mbed_official | 87:085cde657901 | 395 | * @param pData: pointer to the buffer that receives the data read from the |
mbed_official | 87:085cde657901 | 396 | * NOR memory. |
mbed_official | 87:085cde657901 | 397 | * @param uwBufferSize : number of Half word to read. |
mbed_official | 87:085cde657901 | 398 | * @retval HAL status |
mbed_official | 87:085cde657901 | 399 | */ |
mbed_official | 87:085cde657901 | 400 | HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize) |
mbed_official | 87:085cde657901 | 401 | { |
mbed_official | 87:085cde657901 | 402 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 403 | __HAL_LOCK(hnor); |
mbed_official | 87:085cde657901 | 404 | |
mbed_official | 87:085cde657901 | 405 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 406 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 87:085cde657901 | 407 | { |
mbed_official | 87:085cde657901 | 408 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 409 | } |
mbed_official | 87:085cde657901 | 410 | |
mbed_official | 87:085cde657901 | 411 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 412 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 87:085cde657901 | 413 | |
mbed_official | 87:085cde657901 | 414 | /* Send read data command */ |
mbed_official | 87:085cde657901 | 415 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x00555), 0x00AA); |
mbed_official | 87:085cde657901 | 416 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x002AA), 0x0055); |
mbed_official | 87:085cde657901 | 417 | __NOR_WRITE(uwAddress, 0x00F0); |
mbed_official | 87:085cde657901 | 418 | |
mbed_official | 87:085cde657901 | 419 | /* Read buffer */ |
mbed_official | 87:085cde657901 | 420 | while( uwBufferSize > 0) |
mbed_official | 87:085cde657901 | 421 | { |
mbed_official | 87:085cde657901 | 422 | *pData++ = *(__IO uint16_t *)uwAddress; |
mbed_official | 87:085cde657901 | 423 | uwAddress += 2; |
mbed_official | 87:085cde657901 | 424 | uwBufferSize--; |
mbed_official | 87:085cde657901 | 425 | } |
mbed_official | 87:085cde657901 | 426 | |
mbed_official | 87:085cde657901 | 427 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 428 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 429 | |
mbed_official | 87:085cde657901 | 430 | /* Process unlocked */ |
mbed_official | 87:085cde657901 | 431 | __HAL_UNLOCK(hnor); |
mbed_official | 87:085cde657901 | 432 | |
mbed_official | 87:085cde657901 | 433 | return HAL_OK; |
mbed_official | 87:085cde657901 | 434 | } |
mbed_official | 87:085cde657901 | 435 | |
mbed_official | 87:085cde657901 | 436 | |
mbed_official | 87:085cde657901 | 437 | /** |
mbed_official | 87:085cde657901 | 438 | * @brief Writes a half-word buffer to the FMC NOR memory. This function |
mbed_official | 87:085cde657901 | 439 | * must be used only with S29GL128P NOR memory. |
mbed_official | 87:085cde657901 | 440 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 441 | * @param uwAddress: NOR memory internal address from which the data |
mbed_official | 87:085cde657901 | 442 | * @param pData: pointer to source data buffer. |
mbed_official | 87:085cde657901 | 443 | * @param uwBufferSize: number of Half words to write. The maximum allowed |
mbed_official | 87:085cde657901 | 444 | * @retval HAL status |
mbed_official | 87:085cde657901 | 445 | */ |
mbed_official | 87:085cde657901 | 446 | HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize) |
mbed_official | 87:085cde657901 | 447 | { |
mbed_official | 87:085cde657901 | 448 | uint32_t lastloadedaddress = 0; |
mbed_official | 87:085cde657901 | 449 | uint32_t currentaddress = 0; |
mbed_official | 87:085cde657901 | 450 | uint32_t endaddress = 0; |
mbed_official | 87:085cde657901 | 451 | |
mbed_official | 87:085cde657901 | 452 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 453 | __HAL_LOCK(hnor); |
mbed_official | 87:085cde657901 | 454 | |
mbed_official | 87:085cde657901 | 455 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 456 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 87:085cde657901 | 457 | { |
mbed_official | 87:085cde657901 | 458 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 459 | } |
mbed_official | 87:085cde657901 | 460 | |
mbed_official | 87:085cde657901 | 461 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 462 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 87:085cde657901 | 463 | |
mbed_official | 87:085cde657901 | 464 | /* Initialize variables */ |
mbed_official | 87:085cde657901 | 465 | currentaddress = uwAddress; |
mbed_official | 87:085cde657901 | 466 | endaddress = uwAddress + uwBufferSize - 1; |
mbed_official | 87:085cde657901 | 467 | lastloadedaddress = uwAddress; |
mbed_official | 87:085cde657901 | 468 | |
mbed_official | 87:085cde657901 | 469 | /* Issue unlock command sequence */ |
mbed_official | 87:085cde657901 | 470 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA); |
mbed_official | 87:085cde657901 | 471 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055); |
mbed_official | 87:085cde657901 | 472 | |
mbed_official | 87:085cde657901 | 473 | /* Write Buffer Load Command */ |
mbed_official | 87:085cde657901 | 474 | __NOR_WRITE(__NOR_ADDR_SHIFT(uwAddress), 0x25); |
mbed_official | 87:085cde657901 | 475 | __NOR_WRITE(__NOR_ADDR_SHIFT(uwAddress), (uwBufferSize - 1)); |
mbed_official | 87:085cde657901 | 476 | |
mbed_official | 87:085cde657901 | 477 | /* Load Data into NOR Buffer */ |
mbed_official | 87:085cde657901 | 478 | while(currentaddress <= endaddress) |
mbed_official | 87:085cde657901 | 479 | { |
mbed_official | 87:085cde657901 | 480 | /* Store last loaded address & data value (for polling) */ |
mbed_official | 87:085cde657901 | 481 | lastloadedaddress = currentaddress; |
mbed_official | 87:085cde657901 | 482 | |
mbed_official | 87:085cde657901 | 483 | __NOR_WRITE(__NOR_ADDR_SHIFT(currentaddress), *pData++); |
mbed_official | 87:085cde657901 | 484 | |
mbed_official | 87:085cde657901 | 485 | currentaddress += 1; |
mbed_official | 87:085cde657901 | 486 | } |
mbed_official | 87:085cde657901 | 487 | |
mbed_official | 87:085cde657901 | 488 | __NOR_WRITE(__NOR_ADDR_SHIFT(lastloadedaddress), 0x29); |
mbed_official | 87:085cde657901 | 489 | |
mbed_official | 87:085cde657901 | 490 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 491 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 492 | |
mbed_official | 87:085cde657901 | 493 | /* Process unlocked */ |
mbed_official | 87:085cde657901 | 494 | __HAL_UNLOCK(hnor); |
mbed_official | 87:085cde657901 | 495 | |
mbed_official | 87:085cde657901 | 496 | return HAL_OK; |
mbed_official | 87:085cde657901 | 497 | |
mbed_official | 87:085cde657901 | 498 | } |
mbed_official | 87:085cde657901 | 499 | |
mbed_official | 87:085cde657901 | 500 | /** |
mbed_official | 87:085cde657901 | 501 | * @brief Erase the specified block of the NOR memory |
mbed_official | 87:085cde657901 | 502 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 503 | * @param BlockAddress : Block to erase address |
mbed_official | 87:085cde657901 | 504 | * @param Address: Device address |
mbed_official | 87:085cde657901 | 505 | * @retval HAL status |
mbed_official | 87:085cde657901 | 506 | */ |
mbed_official | 87:085cde657901 | 507 | HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address) |
mbed_official | 87:085cde657901 | 508 | { |
mbed_official | 87:085cde657901 | 509 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 510 | __HAL_LOCK(hnor); |
mbed_official | 87:085cde657901 | 511 | |
mbed_official | 87:085cde657901 | 512 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 513 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 87:085cde657901 | 514 | { |
mbed_official | 87:085cde657901 | 515 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 516 | } |
mbed_official | 87:085cde657901 | 517 | |
mbed_official | 87:085cde657901 | 518 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 519 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 87:085cde657901 | 520 | |
mbed_official | 87:085cde657901 | 521 | /* Send block erase command sequence */ |
mbed_official | 87:085cde657901 | 522 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA); |
mbed_official | 87:085cde657901 | 523 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055); |
mbed_official | 87:085cde657901 | 524 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x0080); |
mbed_official | 87:085cde657901 | 525 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA); |
mbed_official | 87:085cde657901 | 526 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055); |
mbed_official | 87:085cde657901 | 527 | __NOR_WRITE((uint32_t)(BlockAddress + Address), 0x30); |
mbed_official | 87:085cde657901 | 528 | |
mbed_official | 87:085cde657901 | 529 | /* Check the NOR memory status and update the controller state */ |
mbed_official | 87:085cde657901 | 530 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 531 | |
mbed_official | 87:085cde657901 | 532 | /* Process unlocked */ |
mbed_official | 87:085cde657901 | 533 | __HAL_UNLOCK(hnor); |
mbed_official | 87:085cde657901 | 534 | |
mbed_official | 87:085cde657901 | 535 | return HAL_OK; |
mbed_official | 87:085cde657901 | 536 | |
mbed_official | 87:085cde657901 | 537 | } |
mbed_official | 87:085cde657901 | 538 | |
mbed_official | 87:085cde657901 | 539 | |
mbed_official | 87:085cde657901 | 540 | /** |
mbed_official | 87:085cde657901 | 541 | * @brief Erase the entire NOR chip. |
mbed_official | 87:085cde657901 | 542 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 543 | * @param Address : Device address |
mbed_official | 87:085cde657901 | 544 | * @retval HAL status |
mbed_official | 87:085cde657901 | 545 | */ |
mbed_official | 87:085cde657901 | 546 | HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address) |
mbed_official | 87:085cde657901 | 547 | { |
mbed_official | 87:085cde657901 | 548 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 549 | __HAL_LOCK(hnor); |
mbed_official | 87:085cde657901 | 550 | |
mbed_official | 87:085cde657901 | 551 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 552 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 87:085cde657901 | 553 | { |
mbed_official | 87:085cde657901 | 554 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 555 | } |
mbed_official | 87:085cde657901 | 556 | |
mbed_official | 87:085cde657901 | 557 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 558 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 87:085cde657901 | 559 | |
mbed_official | 87:085cde657901 | 560 | /* Send NOR chip erase command sequence */ |
mbed_official | 87:085cde657901 | 561 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA); |
mbed_official | 87:085cde657901 | 562 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055); |
mbed_official | 87:085cde657901 | 563 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x0080); |
mbed_official | 87:085cde657901 | 564 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA); |
mbed_official | 87:085cde657901 | 565 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055); |
mbed_official | 87:085cde657901 | 566 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x0010); |
mbed_official | 87:085cde657901 | 567 | |
mbed_official | 87:085cde657901 | 568 | /* Check the NOR memory status and update the controller state */ |
mbed_official | 87:085cde657901 | 569 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 570 | |
mbed_official | 87:085cde657901 | 571 | /* Process unlocked */ |
mbed_official | 87:085cde657901 | 572 | __HAL_UNLOCK(hnor); |
mbed_official | 87:085cde657901 | 573 | |
mbed_official | 87:085cde657901 | 574 | return HAL_OK; |
mbed_official | 87:085cde657901 | 575 | } |
mbed_official | 87:085cde657901 | 576 | |
mbed_official | 87:085cde657901 | 577 | |
mbed_official | 87:085cde657901 | 578 | /** |
mbed_official | 87:085cde657901 | 579 | * @brief Read NOR flash CFI IDs |
mbed_official | 87:085cde657901 | 580 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 581 | * @param pNOR_CFI : pointer to NOR CFI IDs structure |
mbed_official | 87:085cde657901 | 582 | * @retval HAL status |
mbed_official | 87:085cde657901 | 583 | */ |
mbed_official | 87:085cde657901 | 584 | HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI) |
mbed_official | 87:085cde657901 | 585 | { |
mbed_official | 87:085cde657901 | 586 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 587 | __HAL_LOCK(hnor); |
mbed_official | 87:085cde657901 | 588 | |
mbed_official | 87:085cde657901 | 589 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 590 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 87:085cde657901 | 591 | { |
mbed_official | 87:085cde657901 | 592 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 593 | } |
mbed_official | 87:085cde657901 | 594 | |
mbed_official | 87:085cde657901 | 595 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 596 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 87:085cde657901 | 597 | |
mbed_official | 87:085cde657901 | 598 | /* Send read CFI query command */ |
mbed_official | 87:085cde657901 | 599 | __NOR_WRITE(__NOR_ADDR_SHIFT(0x0055), 0x0098); |
mbed_official | 87:085cde657901 | 600 | |
mbed_official | 87:085cde657901 | 601 | /* read the NOR CFI information */ |
mbed_official | 87:085cde657901 | 602 | pNOR_CFI->CFI_1 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(CFI1_ADDRESS); |
mbed_official | 87:085cde657901 | 603 | pNOR_CFI->CFI_2 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(CFI2_ADDRESS); |
mbed_official | 87:085cde657901 | 604 | pNOR_CFI->CFI_3 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(CFI3_ADDRESS); |
mbed_official | 87:085cde657901 | 605 | pNOR_CFI->CFI_4 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(CFI4_ADDRESS); |
mbed_official | 87:085cde657901 | 606 | |
mbed_official | 87:085cde657901 | 607 | /* Check the NOR controller state */ |
mbed_official | 87:085cde657901 | 608 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 609 | |
mbed_official | 87:085cde657901 | 610 | /* Process unlocked */ |
mbed_official | 87:085cde657901 | 611 | __HAL_UNLOCK(hnor); |
mbed_official | 87:085cde657901 | 612 | |
mbed_official | 87:085cde657901 | 613 | return HAL_OK; |
mbed_official | 87:085cde657901 | 614 | } |
mbed_official | 87:085cde657901 | 615 | |
mbed_official | 87:085cde657901 | 616 | |
mbed_official | 87:085cde657901 | 617 | /** |
mbed_official | 87:085cde657901 | 618 | * @} |
mbed_official | 87:085cde657901 | 619 | */ |
mbed_official | 87:085cde657901 | 620 | |
mbed_official | 87:085cde657901 | 621 | /** @defgroup NOR_Group3 Control functions |
mbed_official | 87:085cde657901 | 622 | * @brief management functions |
mbed_official | 87:085cde657901 | 623 | * |
mbed_official | 87:085cde657901 | 624 | @verbatim |
mbed_official | 87:085cde657901 | 625 | ============================================================================== |
mbed_official | 87:085cde657901 | 626 | ##### NOR Control functions ##### |
mbed_official | 87:085cde657901 | 627 | ============================================================================== |
mbed_official | 87:085cde657901 | 628 | [..] |
mbed_official | 87:085cde657901 | 629 | This subsection provides a set of functions allowing to control dynamically |
mbed_official | 87:085cde657901 | 630 | the NOR interface. |
mbed_official | 87:085cde657901 | 631 | |
mbed_official | 87:085cde657901 | 632 | @endverbatim |
mbed_official | 87:085cde657901 | 633 | * @{ |
mbed_official | 87:085cde657901 | 634 | */ |
mbed_official | 87:085cde657901 | 635 | |
mbed_official | 87:085cde657901 | 636 | /** |
mbed_official | 87:085cde657901 | 637 | * @brief Enables dynamically NOR write operation. |
mbed_official | 87:085cde657901 | 638 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 639 | * @retval HAL status |
mbed_official | 87:085cde657901 | 640 | */ |
mbed_official | 87:085cde657901 | 641 | HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor) |
mbed_official | 87:085cde657901 | 642 | { |
mbed_official | 87:085cde657901 | 643 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 644 | __HAL_LOCK(hnor); |
mbed_official | 87:085cde657901 | 645 | |
mbed_official | 87:085cde657901 | 646 | /* Enable write operation */ |
mbed_official | 87:085cde657901 | 647 | FMC_NORSRAM_WriteOperation_Enable(hnor->Instance, hnor->Init.NSBank); |
mbed_official | 87:085cde657901 | 648 | |
mbed_official | 87:085cde657901 | 649 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 650 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 87:085cde657901 | 651 | |
mbed_official | 87:085cde657901 | 652 | /* Process unlocked */ |
mbed_official | 87:085cde657901 | 653 | __HAL_UNLOCK(hnor); |
mbed_official | 87:085cde657901 | 654 | |
mbed_official | 87:085cde657901 | 655 | return HAL_OK; |
mbed_official | 87:085cde657901 | 656 | } |
mbed_official | 87:085cde657901 | 657 | |
mbed_official | 87:085cde657901 | 658 | /** |
mbed_official | 87:085cde657901 | 659 | * @brief Disables dynamically NOR write operation. |
mbed_official | 87:085cde657901 | 660 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 661 | * @retval HAL status |
mbed_official | 87:085cde657901 | 662 | */ |
mbed_official | 87:085cde657901 | 663 | HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor) |
mbed_official | 87:085cde657901 | 664 | { |
mbed_official | 87:085cde657901 | 665 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 666 | __HAL_LOCK(hnor); |
mbed_official | 87:085cde657901 | 667 | |
mbed_official | 87:085cde657901 | 668 | /* Update the SRAM controller state */ |
mbed_official | 87:085cde657901 | 669 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 87:085cde657901 | 670 | |
mbed_official | 87:085cde657901 | 671 | /* Disable write operation */ |
mbed_official | 87:085cde657901 | 672 | FMC_NORSRAM_WriteOperation_Disable(hnor->Instance, hnor->Init.NSBank); |
mbed_official | 87:085cde657901 | 673 | |
mbed_official | 87:085cde657901 | 674 | /* Update the NOR controller state */ |
mbed_official | 87:085cde657901 | 675 | hnor->State = HAL_NOR_STATE_PROTECTED; |
mbed_official | 87:085cde657901 | 676 | |
mbed_official | 87:085cde657901 | 677 | /* Process unlocked */ |
mbed_official | 87:085cde657901 | 678 | __HAL_UNLOCK(hnor); |
mbed_official | 87:085cde657901 | 679 | |
mbed_official | 87:085cde657901 | 680 | return HAL_OK; |
mbed_official | 87:085cde657901 | 681 | } |
mbed_official | 87:085cde657901 | 682 | |
mbed_official | 87:085cde657901 | 683 | /** |
mbed_official | 87:085cde657901 | 684 | * @} |
mbed_official | 87:085cde657901 | 685 | */ |
mbed_official | 87:085cde657901 | 686 | |
mbed_official | 87:085cde657901 | 687 | /** @defgroup NOR_Group4 State functions |
mbed_official | 87:085cde657901 | 688 | * @brief Peripheral State functions |
mbed_official | 87:085cde657901 | 689 | * |
mbed_official | 87:085cde657901 | 690 | @verbatim |
mbed_official | 87:085cde657901 | 691 | ============================================================================== |
mbed_official | 87:085cde657901 | 692 | ##### NOR State functions ##### |
mbed_official | 87:085cde657901 | 693 | ============================================================================== |
mbed_official | 87:085cde657901 | 694 | [..] |
mbed_official | 87:085cde657901 | 695 | This subsection permit to get in run-time the status of the NOR controller |
mbed_official | 87:085cde657901 | 696 | and the data flow. |
mbed_official | 87:085cde657901 | 697 | |
mbed_official | 87:085cde657901 | 698 | @endverbatim |
mbed_official | 87:085cde657901 | 699 | * @{ |
mbed_official | 87:085cde657901 | 700 | */ |
mbed_official | 87:085cde657901 | 701 | |
mbed_official | 87:085cde657901 | 702 | /** |
mbed_official | 87:085cde657901 | 703 | * @brief return the NOR controller state |
mbed_official | 87:085cde657901 | 704 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 705 | * @retval NOR controller state |
mbed_official | 87:085cde657901 | 706 | */ |
mbed_official | 87:085cde657901 | 707 | HAL_NOR_StateTypeDef HAL_NOR_GetState(NOR_HandleTypeDef *hnor) |
mbed_official | 87:085cde657901 | 708 | { |
mbed_official | 87:085cde657901 | 709 | return hnor->State; |
mbed_official | 87:085cde657901 | 710 | } |
mbed_official | 87:085cde657901 | 711 | |
mbed_official | 87:085cde657901 | 712 | /** |
mbed_official | 87:085cde657901 | 713 | * @brief Returns the NOR operation status. |
mbed_official | 87:085cde657901 | 714 | * @param hnor: pointer to NOR handle |
mbed_official | 87:085cde657901 | 715 | * @param Address: Device address |
mbed_official | 87:085cde657901 | 716 | * @param Timeout: NOR progamming Timeout |
mbed_official | 87:085cde657901 | 717 | * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR |
mbed_official | 87:085cde657901 | 718 | * or NOR_TIMEOUT |
mbed_official | 87:085cde657901 | 719 | */ |
mbed_official | 87:085cde657901 | 720 | NOR_StatusTypedef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 721 | { |
mbed_official | 87:085cde657901 | 722 | NOR_StatusTypedef status = NOR_ONGOING; |
mbed_official | 87:085cde657901 | 723 | uint16_t tmpSR1 = 0, tmpSR2 = 0; |
mbed_official | 87:085cde657901 | 724 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 725 | |
mbed_official | 87:085cde657901 | 726 | /* Poll on NOR memory Ready/Busy signal ------------------------------------*/ |
mbed_official | 87:085cde657901 | 727 | HAL_NOR_MspWait(hnor, timeout); |
mbed_official | 87:085cde657901 | 728 | |
mbed_official | 87:085cde657901 | 729 | /* Get the NOR memory operation status -------------------------------------*/ |
mbed_official | 87:085cde657901 | 730 | while(status != NOR_SUCCESS) |
mbed_official | 87:085cde657901 | 731 | { |
mbed_official | 87:085cde657901 | 732 | /* Check for timeout value */ |
mbed_official | 87:085cde657901 | 733 | timeout = HAL_GetTick() + Timeout; |
mbed_official | 87:085cde657901 | 734 | |
mbed_official | 87:085cde657901 | 735 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 736 | { |
mbed_official | 87:085cde657901 | 737 | status = NOR_TIMEOUT; |
mbed_official | 87:085cde657901 | 738 | } |
mbed_official | 87:085cde657901 | 739 | |
mbed_official | 87:085cde657901 | 740 | /* Read NOR status register (DQ6 and DQ5) */ |
mbed_official | 87:085cde657901 | 741 | tmpSR1 = *(__IO uint16_t *)Address; |
mbed_official | 87:085cde657901 | 742 | tmpSR2 = *(__IO uint16_t *)Address; |
mbed_official | 87:085cde657901 | 743 | |
mbed_official | 87:085cde657901 | 744 | /* If DQ6 did not toggle between the two reads then return NOR_Success */ |
mbed_official | 87:085cde657901 | 745 | if((tmpSR1 & 0x0040) == (tmpSR2 & 0x0040)) |
mbed_official | 87:085cde657901 | 746 | { |
mbed_official | 87:085cde657901 | 747 | return NOR_SUCCESS; |
mbed_official | 87:085cde657901 | 748 | } |
mbed_official | 87:085cde657901 | 749 | |
mbed_official | 87:085cde657901 | 750 | if((tmpSR1 & 0x0020) == 0x0020) |
mbed_official | 87:085cde657901 | 751 | { |
mbed_official | 87:085cde657901 | 752 | return NOR_ONGOING; |
mbed_official | 87:085cde657901 | 753 | } |
mbed_official | 87:085cde657901 | 754 | |
mbed_official | 87:085cde657901 | 755 | tmpSR1 = *(__IO uint16_t *)Address; |
mbed_official | 87:085cde657901 | 756 | tmpSR2 = *(__IO uint16_t *)Address; |
mbed_official | 87:085cde657901 | 757 | |
mbed_official | 87:085cde657901 | 758 | /* If DQ6 did not toggle between the two reads then return NOR_Success */ |
mbed_official | 87:085cde657901 | 759 | if((tmpSR1 & 0x0040) == (tmpSR2 & 0x0040)) |
mbed_official | 87:085cde657901 | 760 | { |
mbed_official | 87:085cde657901 | 761 | return NOR_SUCCESS; |
mbed_official | 87:085cde657901 | 762 | } |
mbed_official | 87:085cde657901 | 763 | |
mbed_official | 87:085cde657901 | 764 | if((tmpSR1 & 0x0020) == 0x0020) |
mbed_official | 87:085cde657901 | 765 | { |
mbed_official | 87:085cde657901 | 766 | return NOR_ERROR; |
mbed_official | 87:085cde657901 | 767 | } |
mbed_official | 87:085cde657901 | 768 | } |
mbed_official | 87:085cde657901 | 769 | |
mbed_official | 87:085cde657901 | 770 | /* Return the operation status */ |
mbed_official | 87:085cde657901 | 771 | return status; |
mbed_official | 87:085cde657901 | 772 | } |
mbed_official | 87:085cde657901 | 773 | |
mbed_official | 87:085cde657901 | 774 | /** |
mbed_official | 87:085cde657901 | 775 | * @} |
mbed_official | 87:085cde657901 | 776 | */ |
mbed_official | 87:085cde657901 | 777 | |
mbed_official | 87:085cde657901 | 778 | /** |
mbed_official | 87:085cde657901 | 779 | * @} |
mbed_official | 87:085cde657901 | 780 | */ |
mbed_official | 87:085cde657901 | 781 | #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */ |
mbed_official | 87:085cde657901 | 782 | #endif /* HAL_NOR_MODULE_ENABLED */ |
mbed_official | 87:085cde657901 | 783 | /** |
mbed_official | 87:085cde657901 | 784 | * @} |
mbed_official | 87:085cde657901 | 785 | */ |
mbed_official | 87:085cde657901 | 786 | |
mbed_official | 87:085cde657901 | 787 | /** |
mbed_official | 87:085cde657901 | 788 | * @} |
mbed_official | 87:085cde657901 | 789 | */ |
mbed_official | 87:085cde657901 | 790 | |
mbed_official | 87:085cde657901 | 791 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |