mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F411RE/stm32f4xx_hal_nor.c@310:6188e0254baa, 2014-09-16 (annotated)
- Committer:
- janekm
- Date:
- Tue Sep 16 22:42:01 2014 +0000
- Revision:
- 310:6188e0254baa
- Parent:
- 235:685d5f11838f
N/A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 235:685d5f11838f | 1 | /** |
mbed_official | 235:685d5f11838f | 2 | ****************************************************************************** |
mbed_official | 235:685d5f11838f | 3 | * @file stm32f4xx_hal_nor.c |
mbed_official | 235:685d5f11838f | 4 | * @author MCD Application Team |
mbed_official | 235:685d5f11838f | 5 | * @version V1.1.0 |
mbed_official | 235:685d5f11838f | 6 | * @date 19-June-2014 |
mbed_official | 235:685d5f11838f | 7 | * @brief NOR HAL module driver. |
mbed_official | 235:685d5f11838f | 8 | * This file provides a generic firmware to drive NOR memories mounted |
mbed_official | 235:685d5f11838f | 9 | * as external device. |
mbed_official | 235:685d5f11838f | 10 | * |
mbed_official | 235:685d5f11838f | 11 | @verbatim |
mbed_official | 235:685d5f11838f | 12 | ============================================================================== |
mbed_official | 235:685d5f11838f | 13 | ##### How to use this driver ##### |
mbed_official | 235:685d5f11838f | 14 | ============================================================================== |
mbed_official | 235:685d5f11838f | 15 | [..] |
mbed_official | 235:685d5f11838f | 16 | This driver is a generic layered driver which contains a set of APIs used to |
mbed_official | 235:685d5f11838f | 17 | control NOR flash memories. It uses the FMC/FSMC layer functions to interface |
mbed_official | 235:685d5f11838f | 18 | with NOR devices. This driver is used as follows: |
mbed_official | 235:685d5f11838f | 19 | |
mbed_official | 235:685d5f11838f | 20 | (+) NOR flash memory configuration sequence using the function HAL_NOR_Init() |
mbed_official | 235:685d5f11838f | 21 | with control and timing parameters for both normal and extended mode. |
mbed_official | 235:685d5f11838f | 22 | |
mbed_official | 235:685d5f11838f | 23 | (+) Read NOR flash memory manufacturer code and device IDs using the function |
mbed_official | 235:685d5f11838f | 24 | HAL_NOR_Read_ID(). The read information is stored in the NOR_ID_TypeDef |
mbed_official | 235:685d5f11838f | 25 | structure declared by the function caller. |
mbed_official | 235:685d5f11838f | 26 | |
mbed_official | 235:685d5f11838f | 27 | (+) Access NOR flash memory by read/write data unit operations using the functions |
mbed_official | 235:685d5f11838f | 28 | HAL_NOR_Read(), HAL_NOR_Program(). |
mbed_official | 235:685d5f11838f | 29 | |
mbed_official | 235:685d5f11838f | 30 | (+) Perform NOR flash erase block/chip operations using the functions |
mbed_official | 235:685d5f11838f | 31 | HAL_NOR_Erase_Block() and HAL_NOR_Erase_Chip(). |
mbed_official | 235:685d5f11838f | 32 | |
mbed_official | 235:685d5f11838f | 33 | (+) Read the NOR flash CFI (common flash interface) IDs using the function |
mbed_official | 235:685d5f11838f | 34 | HAL_NOR_Read_CFI(). The read information is stored in the NOR_CFI_TypeDef |
mbed_official | 235:685d5f11838f | 35 | structure declared by the function caller. |
mbed_official | 235:685d5f11838f | 36 | |
mbed_official | 235:685d5f11838f | 37 | (+) You can also control the NOR device by calling the control APIs HAL_NOR_WriteOperation_Enable()/ |
mbed_official | 235:685d5f11838f | 38 | HAL_NOR_WriteOperation_Disable() to respectively enable/disable the NOR write operation |
mbed_official | 235:685d5f11838f | 39 | |
mbed_official | 235:685d5f11838f | 40 | (+) You can monitor the NOR device HAL state by calling the function |
mbed_official | 235:685d5f11838f | 41 | HAL_NOR_GetState() |
mbed_official | 235:685d5f11838f | 42 | [..] |
mbed_official | 235:685d5f11838f | 43 | (@) This driver is a set of generic APIs which handle standard NOR flash operations. |
mbed_official | 235:685d5f11838f | 44 | If a NOR flash device contains different operations and/or implementations, |
mbed_official | 235:685d5f11838f | 45 | it should be implemented separately. |
mbed_official | 235:685d5f11838f | 46 | |
mbed_official | 235:685d5f11838f | 47 | *** NOR HAL driver macros list *** |
mbed_official | 235:685d5f11838f | 48 | ============================================= |
mbed_official | 235:685d5f11838f | 49 | [..] |
mbed_official | 235:685d5f11838f | 50 | Below the list of most used macros in NOR HAL driver. |
mbed_official | 235:685d5f11838f | 51 | |
mbed_official | 235:685d5f11838f | 52 | (+) __NOR_WRITE : NOR memory write data to specified address |
mbed_official | 235:685d5f11838f | 53 | |
mbed_official | 235:685d5f11838f | 54 | @endverbatim |
mbed_official | 235:685d5f11838f | 55 | ****************************************************************************** |
mbed_official | 235:685d5f11838f | 56 | * @attention |
mbed_official | 235:685d5f11838f | 57 | * |
mbed_official | 235:685d5f11838f | 58 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 235:685d5f11838f | 59 | * |
mbed_official | 235:685d5f11838f | 60 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 235:685d5f11838f | 61 | * are permitted provided that the following conditions are met: |
mbed_official | 235:685d5f11838f | 62 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 235:685d5f11838f | 63 | * this list of conditions and the following disclaimer. |
mbed_official | 235:685d5f11838f | 64 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 235:685d5f11838f | 65 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 235:685d5f11838f | 66 | * and/or other materials provided with the distribution. |
mbed_official | 235:685d5f11838f | 67 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 235:685d5f11838f | 68 | * may be used to endorse or promote products derived from this software |
mbed_official | 235:685d5f11838f | 69 | * without specific prior written permission. |
mbed_official | 235:685d5f11838f | 70 | * |
mbed_official | 235:685d5f11838f | 71 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 235:685d5f11838f | 72 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 235:685d5f11838f | 73 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 235:685d5f11838f | 74 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 235:685d5f11838f | 75 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 235:685d5f11838f | 76 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 235:685d5f11838f | 77 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 235:685d5f11838f | 78 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 235:685d5f11838f | 79 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 235:685d5f11838f | 80 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 235:685d5f11838f | 81 | * |
mbed_official | 235:685d5f11838f | 82 | ****************************************************************************** |
mbed_official | 235:685d5f11838f | 83 | */ |
mbed_official | 235:685d5f11838f | 84 | |
mbed_official | 235:685d5f11838f | 85 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 86 | #include "stm32f4xx_hal.h" |
mbed_official | 235:685d5f11838f | 87 | |
mbed_official | 235:685d5f11838f | 88 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 235:685d5f11838f | 89 | * @{ |
mbed_official | 235:685d5f11838f | 90 | */ |
mbed_official | 235:685d5f11838f | 91 | |
mbed_official | 235:685d5f11838f | 92 | /** @defgroup NOR |
mbed_official | 235:685d5f11838f | 93 | * @brief NOR driver modules |
mbed_official | 235:685d5f11838f | 94 | * @{ |
mbed_official | 235:685d5f11838f | 95 | */ |
mbed_official | 235:685d5f11838f | 96 | #ifdef HAL_NOR_MODULE_ENABLED |
mbed_official | 235:685d5f11838f | 97 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) |
mbed_official | 235:685d5f11838f | 98 | |
mbed_official | 235:685d5f11838f | 99 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 100 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 101 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 102 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 103 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 104 | |
mbed_official | 235:685d5f11838f | 105 | |
mbed_official | 235:685d5f11838f | 106 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 107 | |
mbed_official | 235:685d5f11838f | 108 | /** @defgroup NOR_Private_Functions |
mbed_official | 235:685d5f11838f | 109 | * @{ |
mbed_official | 235:685d5f11838f | 110 | */ |
mbed_official | 235:685d5f11838f | 111 | |
mbed_official | 235:685d5f11838f | 112 | /** @defgroup NOR_Group1 Initialization and de-initialization functions |
mbed_official | 235:685d5f11838f | 113 | * @brief Initialization and Configuration functions |
mbed_official | 235:685d5f11838f | 114 | * |
mbed_official | 235:685d5f11838f | 115 | @verbatim |
mbed_official | 235:685d5f11838f | 116 | ============================================================================== |
mbed_official | 235:685d5f11838f | 117 | ##### NOR Initialization and de_initialization functions ##### |
mbed_official | 235:685d5f11838f | 118 | ============================================================================== |
mbed_official | 235:685d5f11838f | 119 | [..] |
mbed_official | 235:685d5f11838f | 120 | This section provides functions allowing to initialize/de-initialize |
mbed_official | 235:685d5f11838f | 121 | the NOR memory |
mbed_official | 235:685d5f11838f | 122 | |
mbed_official | 235:685d5f11838f | 123 | @endverbatim |
mbed_official | 235:685d5f11838f | 124 | * @{ |
mbed_official | 235:685d5f11838f | 125 | */ |
mbed_official | 235:685d5f11838f | 126 | |
mbed_official | 235:685d5f11838f | 127 | /** |
mbed_official | 235:685d5f11838f | 128 | * @brief Perform the NOR memory Initialization sequence |
mbed_official | 235:685d5f11838f | 129 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 130 | * @param Timing: pointer to NOR control timing structure |
mbed_official | 235:685d5f11838f | 131 | * @param ExtTiming: pointer to NOR extended mode timing structure |
mbed_official | 235:685d5f11838f | 132 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 133 | */ |
mbed_official | 235:685d5f11838f | 134 | HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming) |
mbed_official | 235:685d5f11838f | 135 | { |
mbed_official | 235:685d5f11838f | 136 | /* Check the NOR handle parameter */ |
mbed_official | 235:685d5f11838f | 137 | if(hnor == NULL) |
mbed_official | 235:685d5f11838f | 138 | { |
mbed_official | 235:685d5f11838f | 139 | return HAL_ERROR; |
mbed_official | 235:685d5f11838f | 140 | } |
mbed_official | 235:685d5f11838f | 141 | |
mbed_official | 235:685d5f11838f | 142 | if(hnor->State == HAL_NOR_STATE_RESET) |
mbed_official | 235:685d5f11838f | 143 | { |
mbed_official | 235:685d5f11838f | 144 | /* Initialize the low level hardware (MSP) */ |
mbed_official | 235:685d5f11838f | 145 | HAL_NOR_MspInit(hnor); |
mbed_official | 235:685d5f11838f | 146 | } |
mbed_official | 235:685d5f11838f | 147 | |
mbed_official | 235:685d5f11838f | 148 | /* Initialize NOR control Interface */ |
mbed_official | 235:685d5f11838f | 149 | FMC_NORSRAM_Init(hnor->Instance, &(hnor->Init)); |
mbed_official | 235:685d5f11838f | 150 | |
mbed_official | 235:685d5f11838f | 151 | /* Initialize NOR timing Interface */ |
mbed_official | 235:685d5f11838f | 152 | FMC_NORSRAM_Timing_Init(hnor->Instance, Timing, hnor->Init.NSBank); |
mbed_official | 235:685d5f11838f | 153 | |
mbed_official | 235:685d5f11838f | 154 | /* Initialize NOR extended mode timing Interface */ |
mbed_official | 235:685d5f11838f | 155 | FMC_NORSRAM_Extended_Timing_Init(hnor->Extended, ExtTiming, hnor->Init.NSBank, hnor->Init.ExtendedMode); |
mbed_official | 235:685d5f11838f | 156 | |
mbed_official | 235:685d5f11838f | 157 | /* Enable the NORSRAM device */ |
mbed_official | 235:685d5f11838f | 158 | __FMC_NORSRAM_ENABLE(hnor->Instance, hnor->Init.NSBank); |
mbed_official | 235:685d5f11838f | 159 | |
mbed_official | 235:685d5f11838f | 160 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 161 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 235:685d5f11838f | 162 | |
mbed_official | 235:685d5f11838f | 163 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 164 | } |
mbed_official | 235:685d5f11838f | 165 | |
mbed_official | 235:685d5f11838f | 166 | /** |
mbed_official | 235:685d5f11838f | 167 | * @brief Perform NOR memory De-Initialization sequence |
mbed_official | 235:685d5f11838f | 168 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 169 | * the configuration information for NOR module. |
mbed_official | 235:685d5f11838f | 170 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 171 | */ |
mbed_official | 235:685d5f11838f | 172 | HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor) |
mbed_official | 235:685d5f11838f | 173 | { |
mbed_official | 235:685d5f11838f | 174 | /* De-Initialize the low level hardware (MSP) */ |
mbed_official | 235:685d5f11838f | 175 | HAL_NOR_MspDeInit(hnor); |
mbed_official | 235:685d5f11838f | 176 | |
mbed_official | 235:685d5f11838f | 177 | /* Configure the NOR registers with their reset values */ |
mbed_official | 235:685d5f11838f | 178 | FMC_NORSRAM_DeInit(hnor->Instance, hnor->Extended, hnor->Init.NSBank); |
mbed_official | 235:685d5f11838f | 179 | |
mbed_official | 235:685d5f11838f | 180 | /* Update the NOR controller state */ |
mbed_official | 235:685d5f11838f | 181 | hnor->State = HAL_NOR_STATE_RESET; |
mbed_official | 235:685d5f11838f | 182 | |
mbed_official | 235:685d5f11838f | 183 | /* Release Lock */ |
mbed_official | 235:685d5f11838f | 184 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 185 | |
mbed_official | 235:685d5f11838f | 186 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 187 | } |
mbed_official | 235:685d5f11838f | 188 | |
mbed_official | 235:685d5f11838f | 189 | /** |
mbed_official | 235:685d5f11838f | 190 | * @brief NOR MSP Init |
mbed_official | 235:685d5f11838f | 191 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 192 | * the configuration information for NOR module. |
mbed_official | 235:685d5f11838f | 193 | * @retval None |
mbed_official | 235:685d5f11838f | 194 | */ |
mbed_official | 235:685d5f11838f | 195 | __weak void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor) |
mbed_official | 235:685d5f11838f | 196 | { |
mbed_official | 235:685d5f11838f | 197 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 235:685d5f11838f | 198 | the HAL_NOR_MspInit could be implemented in the user file |
mbed_official | 235:685d5f11838f | 199 | */ |
mbed_official | 235:685d5f11838f | 200 | } |
mbed_official | 235:685d5f11838f | 201 | |
mbed_official | 235:685d5f11838f | 202 | /** |
mbed_official | 235:685d5f11838f | 203 | * @brief NOR MSP DeInit |
mbed_official | 235:685d5f11838f | 204 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 205 | * the configuration information for NOR module. |
mbed_official | 235:685d5f11838f | 206 | * @retval None |
mbed_official | 235:685d5f11838f | 207 | */ |
mbed_official | 235:685d5f11838f | 208 | __weak void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor) |
mbed_official | 235:685d5f11838f | 209 | { |
mbed_official | 235:685d5f11838f | 210 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 235:685d5f11838f | 211 | the HAL_NOR_MspDeInit could be implemented in the user file |
mbed_official | 235:685d5f11838f | 212 | */ |
mbed_official | 235:685d5f11838f | 213 | } |
mbed_official | 235:685d5f11838f | 214 | |
mbed_official | 235:685d5f11838f | 215 | /** |
mbed_official | 235:685d5f11838f | 216 | * @brief NOR BSP Wait fro Ready/Busy signal |
mbed_official | 235:685d5f11838f | 217 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 218 | * the configuration information for NOR module. |
mbed_official | 235:685d5f11838f | 219 | * @param Timeout: Maximum timeout value |
mbed_official | 235:685d5f11838f | 220 | * @retval None |
mbed_official | 235:685d5f11838f | 221 | */ |
mbed_official | 235:685d5f11838f | 222 | __weak void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout) |
mbed_official | 235:685d5f11838f | 223 | { |
mbed_official | 235:685d5f11838f | 224 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 235:685d5f11838f | 225 | the HAL_NOR_BspWait could be implemented in the user file |
mbed_official | 235:685d5f11838f | 226 | */ |
mbed_official | 235:685d5f11838f | 227 | } |
mbed_official | 235:685d5f11838f | 228 | |
mbed_official | 235:685d5f11838f | 229 | /** |
mbed_official | 235:685d5f11838f | 230 | * @} |
mbed_official | 235:685d5f11838f | 231 | */ |
mbed_official | 235:685d5f11838f | 232 | |
mbed_official | 235:685d5f11838f | 233 | /** @defgroup NOR_Group2 Input and Output functions |
mbed_official | 235:685d5f11838f | 234 | * @brief Input Output and memory control functions |
mbed_official | 235:685d5f11838f | 235 | * |
mbed_official | 235:685d5f11838f | 236 | @verbatim |
mbed_official | 235:685d5f11838f | 237 | ============================================================================== |
mbed_official | 235:685d5f11838f | 238 | ##### NOR Input and Output functions ##### |
mbed_official | 235:685d5f11838f | 239 | ============================================================================== |
mbed_official | 235:685d5f11838f | 240 | [..] |
mbed_official | 235:685d5f11838f | 241 | This section provides functions allowing to use and control the NOR memory |
mbed_official | 235:685d5f11838f | 242 | |
mbed_official | 235:685d5f11838f | 243 | @endverbatim |
mbed_official | 235:685d5f11838f | 244 | * @{ |
mbed_official | 235:685d5f11838f | 245 | */ |
mbed_official | 235:685d5f11838f | 246 | |
mbed_official | 235:685d5f11838f | 247 | /** |
mbed_official | 235:685d5f11838f | 248 | * @brief Read NOR flash IDs |
mbed_official | 235:685d5f11838f | 249 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 250 | * @param pNOR_ID : pointer to NOR ID structure |
mbed_official | 235:685d5f11838f | 251 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 252 | */ |
mbed_official | 235:685d5f11838f | 253 | HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID) |
mbed_official | 235:685d5f11838f | 254 | { |
mbed_official | 235:685d5f11838f | 255 | uint32_t deviceAddress = 0; |
mbed_official | 235:685d5f11838f | 256 | |
mbed_official | 235:685d5f11838f | 257 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 258 | __HAL_LOCK(hnor); |
mbed_official | 235:685d5f11838f | 259 | |
mbed_official | 235:685d5f11838f | 260 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 261 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 235:685d5f11838f | 262 | { |
mbed_official | 235:685d5f11838f | 263 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 264 | } |
mbed_official | 235:685d5f11838f | 265 | |
mbed_official | 235:685d5f11838f | 266 | /* Select the NOR device address */ |
mbed_official | 235:685d5f11838f | 267 | if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) |
mbed_official | 235:685d5f11838f | 268 | { |
mbed_official | 235:685d5f11838f | 269 | deviceAddress = NOR_MEMORY_ADRESS1; |
mbed_official | 235:685d5f11838f | 270 | } |
mbed_official | 235:685d5f11838f | 271 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) |
mbed_official | 235:685d5f11838f | 272 | { |
mbed_official | 235:685d5f11838f | 273 | deviceAddress = NOR_MEMORY_ADRESS2; |
mbed_official | 235:685d5f11838f | 274 | } |
mbed_official | 235:685d5f11838f | 275 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) |
mbed_official | 235:685d5f11838f | 276 | { |
mbed_official | 235:685d5f11838f | 277 | deviceAddress = NOR_MEMORY_ADRESS3; |
mbed_official | 235:685d5f11838f | 278 | } |
mbed_official | 235:685d5f11838f | 279 | else /* FMC_NORSRAM_BANK4 */ |
mbed_official | 235:685d5f11838f | 280 | { |
mbed_official | 235:685d5f11838f | 281 | deviceAddress = NOR_MEMORY_ADRESS4; |
mbed_official | 235:685d5f11838f | 282 | } |
mbed_official | 235:685d5f11838f | 283 | |
mbed_official | 235:685d5f11838f | 284 | /* Update the NOR controller state */ |
mbed_official | 235:685d5f11838f | 285 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 286 | |
mbed_official | 235:685d5f11838f | 287 | /* Send read ID command */ |
mbed_official | 235:685d5f11838f | 288 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x00AA); |
mbed_official | 235:685d5f11838f | 289 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x02AA), 0x0055); |
mbed_official | 235:685d5f11838f | 290 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x0090); |
mbed_official | 235:685d5f11838f | 291 | |
mbed_official | 235:685d5f11838f | 292 | /* Read the NOR IDs */ |
mbed_official | 235:685d5f11838f | 293 | pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) __NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, MC_ADDRESS); |
mbed_official | 235:685d5f11838f | 294 | pNOR_ID->Device_Code1 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, DEVICE_CODE1_ADDR); |
mbed_official | 235:685d5f11838f | 295 | pNOR_ID->Device_Code2 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, DEVICE_CODE2_ADDR); |
mbed_official | 235:685d5f11838f | 296 | pNOR_ID->Device_Code3 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, DEVICE_CODE3_ADDR); |
mbed_official | 235:685d5f11838f | 297 | |
mbed_official | 235:685d5f11838f | 298 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 299 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 235:685d5f11838f | 300 | |
mbed_official | 235:685d5f11838f | 301 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 302 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 303 | |
mbed_official | 235:685d5f11838f | 304 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 305 | } |
mbed_official | 235:685d5f11838f | 306 | |
mbed_official | 235:685d5f11838f | 307 | /** |
mbed_official | 235:685d5f11838f | 308 | * @brief Returns the NOR memory to Read mode. |
mbed_official | 235:685d5f11838f | 309 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 310 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 311 | */ |
mbed_official | 235:685d5f11838f | 312 | HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor) |
mbed_official | 235:685d5f11838f | 313 | { |
mbed_official | 235:685d5f11838f | 314 | uint32_t deviceAddress = 0; |
mbed_official | 235:685d5f11838f | 315 | |
mbed_official | 235:685d5f11838f | 316 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 317 | __HAL_LOCK(hnor); |
mbed_official | 235:685d5f11838f | 318 | |
mbed_official | 235:685d5f11838f | 319 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 320 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 235:685d5f11838f | 321 | { |
mbed_official | 235:685d5f11838f | 322 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 323 | } |
mbed_official | 235:685d5f11838f | 324 | |
mbed_official | 235:685d5f11838f | 325 | /* Select the NOR device address */ |
mbed_official | 235:685d5f11838f | 326 | if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) |
mbed_official | 235:685d5f11838f | 327 | { |
mbed_official | 235:685d5f11838f | 328 | deviceAddress = NOR_MEMORY_ADRESS1; |
mbed_official | 235:685d5f11838f | 329 | } |
mbed_official | 235:685d5f11838f | 330 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) |
mbed_official | 235:685d5f11838f | 331 | { |
mbed_official | 235:685d5f11838f | 332 | deviceAddress = NOR_MEMORY_ADRESS2; |
mbed_official | 235:685d5f11838f | 333 | } |
mbed_official | 235:685d5f11838f | 334 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) |
mbed_official | 235:685d5f11838f | 335 | { |
mbed_official | 235:685d5f11838f | 336 | deviceAddress = NOR_MEMORY_ADRESS3; |
mbed_official | 235:685d5f11838f | 337 | } |
mbed_official | 235:685d5f11838f | 338 | else /* FMC_NORSRAM_BANK4 */ |
mbed_official | 235:685d5f11838f | 339 | { |
mbed_official | 235:685d5f11838f | 340 | deviceAddress = NOR_MEMORY_ADRESS4; |
mbed_official | 235:685d5f11838f | 341 | } |
mbed_official | 235:685d5f11838f | 342 | |
mbed_official | 235:685d5f11838f | 343 | __NOR_WRITE(deviceAddress, 0x00F0); |
mbed_official | 235:685d5f11838f | 344 | |
mbed_official | 235:685d5f11838f | 345 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 346 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 235:685d5f11838f | 347 | |
mbed_official | 235:685d5f11838f | 348 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 349 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 350 | |
mbed_official | 235:685d5f11838f | 351 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 352 | } |
mbed_official | 235:685d5f11838f | 353 | |
mbed_official | 235:685d5f11838f | 354 | /** |
mbed_official | 235:685d5f11838f | 355 | * @brief Read data from NOR memory |
mbed_official | 235:685d5f11838f | 356 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 357 | * @param pAddress: pointer to Device address |
mbed_official | 235:685d5f11838f | 358 | * @param pData : pointer to read data |
mbed_official | 235:685d5f11838f | 359 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 360 | */ |
mbed_official | 235:685d5f11838f | 361 | HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData) |
mbed_official | 235:685d5f11838f | 362 | { |
mbed_official | 235:685d5f11838f | 363 | uint32_t deviceAddress = 0; |
mbed_official | 235:685d5f11838f | 364 | |
mbed_official | 235:685d5f11838f | 365 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 366 | __HAL_LOCK(hnor); |
mbed_official | 235:685d5f11838f | 367 | |
mbed_official | 235:685d5f11838f | 368 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 369 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 235:685d5f11838f | 370 | { |
mbed_official | 235:685d5f11838f | 371 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 372 | } |
mbed_official | 235:685d5f11838f | 373 | |
mbed_official | 235:685d5f11838f | 374 | /* Select the NOR device address */ |
mbed_official | 235:685d5f11838f | 375 | if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) |
mbed_official | 235:685d5f11838f | 376 | { |
mbed_official | 235:685d5f11838f | 377 | deviceAddress = NOR_MEMORY_ADRESS1; |
mbed_official | 235:685d5f11838f | 378 | } |
mbed_official | 235:685d5f11838f | 379 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) |
mbed_official | 235:685d5f11838f | 380 | { |
mbed_official | 235:685d5f11838f | 381 | deviceAddress = NOR_MEMORY_ADRESS2; |
mbed_official | 235:685d5f11838f | 382 | } |
mbed_official | 235:685d5f11838f | 383 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) |
mbed_official | 235:685d5f11838f | 384 | { |
mbed_official | 235:685d5f11838f | 385 | deviceAddress = NOR_MEMORY_ADRESS3; |
mbed_official | 235:685d5f11838f | 386 | } |
mbed_official | 235:685d5f11838f | 387 | else /* FMC_NORSRAM_BANK4 */ |
mbed_official | 235:685d5f11838f | 388 | { |
mbed_official | 235:685d5f11838f | 389 | deviceAddress = NOR_MEMORY_ADRESS4; |
mbed_official | 235:685d5f11838f | 390 | } |
mbed_official | 235:685d5f11838f | 391 | |
mbed_official | 235:685d5f11838f | 392 | /* Update the NOR controller state */ |
mbed_official | 235:685d5f11838f | 393 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 394 | |
mbed_official | 235:685d5f11838f | 395 | /* Send read data command */ |
mbed_official | 235:685d5f11838f | 396 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x00555), 0x00AA); |
mbed_official | 235:685d5f11838f | 397 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x002AA), 0x0055); |
mbed_official | 235:685d5f11838f | 398 | __NOR_WRITE(pAddress, 0x00F0); |
mbed_official | 235:685d5f11838f | 399 | |
mbed_official | 235:685d5f11838f | 400 | /* Read the data */ |
mbed_official | 235:685d5f11838f | 401 | *pData = *(__IO uint32_t *)pAddress; |
mbed_official | 235:685d5f11838f | 402 | |
mbed_official | 235:685d5f11838f | 403 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 404 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 235:685d5f11838f | 405 | |
mbed_official | 235:685d5f11838f | 406 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 407 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 408 | |
mbed_official | 235:685d5f11838f | 409 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 410 | } |
mbed_official | 235:685d5f11838f | 411 | |
mbed_official | 235:685d5f11838f | 412 | /** |
mbed_official | 235:685d5f11838f | 413 | * @brief Program data to NOR memory |
mbed_official | 235:685d5f11838f | 414 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 415 | * @param pAddress: Device address |
mbed_official | 235:685d5f11838f | 416 | * @param pData : pointer to the data to write |
mbed_official | 235:685d5f11838f | 417 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 418 | */ |
mbed_official | 235:685d5f11838f | 419 | HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData) |
mbed_official | 235:685d5f11838f | 420 | { |
mbed_official | 235:685d5f11838f | 421 | uint32_t deviceAddress = 0; |
mbed_official | 235:685d5f11838f | 422 | |
mbed_official | 235:685d5f11838f | 423 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 424 | __HAL_LOCK(hnor); |
mbed_official | 235:685d5f11838f | 425 | |
mbed_official | 235:685d5f11838f | 426 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 427 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 235:685d5f11838f | 428 | { |
mbed_official | 235:685d5f11838f | 429 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 430 | } |
mbed_official | 235:685d5f11838f | 431 | |
mbed_official | 235:685d5f11838f | 432 | /* Select the NOR device address */ |
mbed_official | 235:685d5f11838f | 433 | if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) |
mbed_official | 235:685d5f11838f | 434 | { |
mbed_official | 235:685d5f11838f | 435 | deviceAddress = NOR_MEMORY_ADRESS1; |
mbed_official | 235:685d5f11838f | 436 | } |
mbed_official | 235:685d5f11838f | 437 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) |
mbed_official | 235:685d5f11838f | 438 | { |
mbed_official | 235:685d5f11838f | 439 | deviceAddress = NOR_MEMORY_ADRESS2; |
mbed_official | 235:685d5f11838f | 440 | } |
mbed_official | 235:685d5f11838f | 441 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) |
mbed_official | 235:685d5f11838f | 442 | { |
mbed_official | 235:685d5f11838f | 443 | deviceAddress = NOR_MEMORY_ADRESS3; |
mbed_official | 235:685d5f11838f | 444 | } |
mbed_official | 235:685d5f11838f | 445 | else /* FMC_NORSRAM_BANK4 */ |
mbed_official | 235:685d5f11838f | 446 | { |
mbed_official | 235:685d5f11838f | 447 | deviceAddress = NOR_MEMORY_ADRESS4; |
mbed_official | 235:685d5f11838f | 448 | } |
mbed_official | 235:685d5f11838f | 449 | |
mbed_official | 235:685d5f11838f | 450 | /* Update the NOR controller state */ |
mbed_official | 235:685d5f11838f | 451 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 452 | |
mbed_official | 235:685d5f11838f | 453 | /* Send program data command */ |
mbed_official | 235:685d5f11838f | 454 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x00AA); |
mbed_official | 235:685d5f11838f | 455 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x02AA), 0x0055); |
mbed_official | 235:685d5f11838f | 456 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x00A0); |
mbed_official | 235:685d5f11838f | 457 | |
mbed_official | 235:685d5f11838f | 458 | /* Write the data */ |
mbed_official | 235:685d5f11838f | 459 | __NOR_WRITE(pAddress, *pData); |
mbed_official | 235:685d5f11838f | 460 | |
mbed_official | 235:685d5f11838f | 461 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 462 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 235:685d5f11838f | 463 | |
mbed_official | 235:685d5f11838f | 464 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 465 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 466 | |
mbed_official | 235:685d5f11838f | 467 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 468 | } |
mbed_official | 235:685d5f11838f | 469 | |
mbed_official | 235:685d5f11838f | 470 | /** |
mbed_official | 235:685d5f11838f | 471 | * @brief Reads a half-word buffer from the NOR memory. |
mbed_official | 235:685d5f11838f | 472 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 473 | * @param uwAddress: NOR memory internal address to read from. |
mbed_official | 235:685d5f11838f | 474 | * @param pData: pointer to the buffer that receives the data read from the |
mbed_official | 235:685d5f11838f | 475 | * NOR memory. |
mbed_official | 235:685d5f11838f | 476 | * @param uwBufferSize : number of Half word to read. |
mbed_official | 235:685d5f11838f | 477 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 478 | */ |
mbed_official | 235:685d5f11838f | 479 | HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize) |
mbed_official | 235:685d5f11838f | 480 | { |
mbed_official | 235:685d5f11838f | 481 | uint32_t deviceAddress = 0; |
mbed_official | 235:685d5f11838f | 482 | |
mbed_official | 235:685d5f11838f | 483 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 484 | __HAL_LOCK(hnor); |
mbed_official | 235:685d5f11838f | 485 | |
mbed_official | 235:685d5f11838f | 486 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 487 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 235:685d5f11838f | 488 | { |
mbed_official | 235:685d5f11838f | 489 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 490 | } |
mbed_official | 235:685d5f11838f | 491 | |
mbed_official | 235:685d5f11838f | 492 | /* Select the NOR device address */ |
mbed_official | 235:685d5f11838f | 493 | if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) |
mbed_official | 235:685d5f11838f | 494 | { |
mbed_official | 235:685d5f11838f | 495 | deviceAddress = NOR_MEMORY_ADRESS1; |
mbed_official | 235:685d5f11838f | 496 | } |
mbed_official | 235:685d5f11838f | 497 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) |
mbed_official | 235:685d5f11838f | 498 | { |
mbed_official | 235:685d5f11838f | 499 | deviceAddress = NOR_MEMORY_ADRESS2; |
mbed_official | 235:685d5f11838f | 500 | } |
mbed_official | 235:685d5f11838f | 501 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) |
mbed_official | 235:685d5f11838f | 502 | { |
mbed_official | 235:685d5f11838f | 503 | deviceAddress = NOR_MEMORY_ADRESS3; |
mbed_official | 235:685d5f11838f | 504 | } |
mbed_official | 235:685d5f11838f | 505 | else /* FMC_NORSRAM_BANK4 */ |
mbed_official | 235:685d5f11838f | 506 | { |
mbed_official | 235:685d5f11838f | 507 | deviceAddress = NOR_MEMORY_ADRESS4; |
mbed_official | 235:685d5f11838f | 508 | } |
mbed_official | 235:685d5f11838f | 509 | |
mbed_official | 235:685d5f11838f | 510 | /* Update the NOR controller state */ |
mbed_official | 235:685d5f11838f | 511 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 512 | |
mbed_official | 235:685d5f11838f | 513 | /* Send read data command */ |
mbed_official | 235:685d5f11838f | 514 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x00555), 0x00AA); |
mbed_official | 235:685d5f11838f | 515 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x002AA), 0x0055); |
mbed_official | 235:685d5f11838f | 516 | __NOR_WRITE(uwAddress, 0x00F0); |
mbed_official | 235:685d5f11838f | 517 | |
mbed_official | 235:685d5f11838f | 518 | /* Read buffer */ |
mbed_official | 235:685d5f11838f | 519 | while( uwBufferSize > 0) |
mbed_official | 235:685d5f11838f | 520 | { |
mbed_official | 235:685d5f11838f | 521 | *pData++ = *(__IO uint16_t *)uwAddress; |
mbed_official | 235:685d5f11838f | 522 | uwAddress += 2; |
mbed_official | 235:685d5f11838f | 523 | uwBufferSize--; |
mbed_official | 235:685d5f11838f | 524 | } |
mbed_official | 235:685d5f11838f | 525 | |
mbed_official | 235:685d5f11838f | 526 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 527 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 235:685d5f11838f | 528 | |
mbed_official | 235:685d5f11838f | 529 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 530 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 531 | |
mbed_official | 235:685d5f11838f | 532 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 533 | } |
mbed_official | 235:685d5f11838f | 534 | |
mbed_official | 235:685d5f11838f | 535 | /** |
mbed_official | 235:685d5f11838f | 536 | * @brief Writes a half-word buffer to the NOR memory. This function must be used |
mbed_official | 235:685d5f11838f | 537 | only with S29GL128P NOR memory. |
mbed_official | 235:685d5f11838f | 538 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 539 | * @param uwAddress: NOR memory internal start write address |
mbed_official | 235:685d5f11838f | 540 | * @param pData: pointer to source data buffer. |
mbed_official | 235:685d5f11838f | 541 | * @param uwBufferSize: Size of the buffer to write |
mbed_official | 235:685d5f11838f | 542 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 543 | */ |
mbed_official | 235:685d5f11838f | 544 | HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize) |
mbed_official | 235:685d5f11838f | 545 | { |
mbed_official | 235:685d5f11838f | 546 | uint32_t lastloadedaddress = 0; |
mbed_official | 235:685d5f11838f | 547 | uint32_t currentaddress = 0; |
mbed_official | 235:685d5f11838f | 548 | uint32_t endaddress = 0; |
mbed_official | 235:685d5f11838f | 549 | uint32_t deviceAddress = 0; |
mbed_official | 235:685d5f11838f | 550 | |
mbed_official | 235:685d5f11838f | 551 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 552 | __HAL_LOCK(hnor); |
mbed_official | 235:685d5f11838f | 553 | |
mbed_official | 235:685d5f11838f | 554 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 555 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 235:685d5f11838f | 556 | { |
mbed_official | 235:685d5f11838f | 557 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 558 | } |
mbed_official | 235:685d5f11838f | 559 | |
mbed_official | 235:685d5f11838f | 560 | /* Select the NOR device address */ |
mbed_official | 235:685d5f11838f | 561 | if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) |
mbed_official | 235:685d5f11838f | 562 | { |
mbed_official | 235:685d5f11838f | 563 | deviceAddress = NOR_MEMORY_ADRESS1; |
mbed_official | 235:685d5f11838f | 564 | } |
mbed_official | 235:685d5f11838f | 565 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) |
mbed_official | 235:685d5f11838f | 566 | { |
mbed_official | 235:685d5f11838f | 567 | deviceAddress = NOR_MEMORY_ADRESS2; |
mbed_official | 235:685d5f11838f | 568 | } |
mbed_official | 235:685d5f11838f | 569 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) |
mbed_official | 235:685d5f11838f | 570 | { |
mbed_official | 235:685d5f11838f | 571 | deviceAddress = NOR_MEMORY_ADRESS3; |
mbed_official | 235:685d5f11838f | 572 | } |
mbed_official | 235:685d5f11838f | 573 | else /* FMC_NORSRAM_BANK4 */ |
mbed_official | 235:685d5f11838f | 574 | { |
mbed_official | 235:685d5f11838f | 575 | deviceAddress = NOR_MEMORY_ADRESS4; |
mbed_official | 235:685d5f11838f | 576 | } |
mbed_official | 235:685d5f11838f | 577 | |
mbed_official | 235:685d5f11838f | 578 | /* Update the NOR controller state */ |
mbed_official | 235:685d5f11838f | 579 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 580 | |
mbed_official | 235:685d5f11838f | 581 | /* Initialize variables */ |
mbed_official | 235:685d5f11838f | 582 | currentaddress = uwAddress; |
mbed_official | 235:685d5f11838f | 583 | endaddress = uwAddress + uwBufferSize - 1; |
mbed_official | 235:685d5f11838f | 584 | lastloadedaddress = uwAddress; |
mbed_official | 235:685d5f11838f | 585 | |
mbed_official | 235:685d5f11838f | 586 | /* Issue unlock command sequence */ |
mbed_official | 235:685d5f11838f | 587 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x00AA); |
mbed_official | 235:685d5f11838f | 588 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x02AA), 0x0055); |
mbed_official | 235:685d5f11838f | 589 | |
mbed_official | 235:685d5f11838f | 590 | /* Write Buffer Load Command */ |
mbed_official | 235:685d5f11838f | 591 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, uwAddress), 0x25); |
mbed_official | 235:685d5f11838f | 592 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, uwAddress), (uwBufferSize - 1)); |
mbed_official | 235:685d5f11838f | 593 | |
mbed_official | 235:685d5f11838f | 594 | /* Load Data into NOR Buffer */ |
mbed_official | 235:685d5f11838f | 595 | while(currentaddress <= endaddress) |
mbed_official | 235:685d5f11838f | 596 | { |
mbed_official | 235:685d5f11838f | 597 | /* Store last loaded address & data value (for polling) */ |
mbed_official | 235:685d5f11838f | 598 | lastloadedaddress = currentaddress; |
mbed_official | 235:685d5f11838f | 599 | |
mbed_official | 235:685d5f11838f | 600 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, currentaddress), *pData++); |
mbed_official | 235:685d5f11838f | 601 | |
mbed_official | 235:685d5f11838f | 602 | currentaddress += 1; |
mbed_official | 235:685d5f11838f | 603 | } |
mbed_official | 235:685d5f11838f | 604 | |
mbed_official | 235:685d5f11838f | 605 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, lastloadedaddress), 0x29); |
mbed_official | 235:685d5f11838f | 606 | |
mbed_official | 235:685d5f11838f | 607 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 608 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 235:685d5f11838f | 609 | |
mbed_official | 235:685d5f11838f | 610 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 611 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 612 | |
mbed_official | 235:685d5f11838f | 613 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 614 | |
mbed_official | 235:685d5f11838f | 615 | } |
mbed_official | 235:685d5f11838f | 616 | |
mbed_official | 235:685d5f11838f | 617 | /** |
mbed_official | 235:685d5f11838f | 618 | * @brief Erase the specified block of the NOR memory |
mbed_official | 235:685d5f11838f | 619 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 620 | * @param BlockAddress : Block to erase address |
mbed_official | 235:685d5f11838f | 621 | * @param Address: Device address |
mbed_official | 235:685d5f11838f | 622 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 623 | */ |
mbed_official | 235:685d5f11838f | 624 | HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address) |
mbed_official | 235:685d5f11838f | 625 | { |
mbed_official | 235:685d5f11838f | 626 | uint32_t deviceAddress = 0; |
mbed_official | 235:685d5f11838f | 627 | |
mbed_official | 235:685d5f11838f | 628 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 629 | __HAL_LOCK(hnor); |
mbed_official | 235:685d5f11838f | 630 | |
mbed_official | 235:685d5f11838f | 631 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 632 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 235:685d5f11838f | 633 | { |
mbed_official | 235:685d5f11838f | 634 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 635 | } |
mbed_official | 235:685d5f11838f | 636 | |
mbed_official | 235:685d5f11838f | 637 | /* Select the NOR device address */ |
mbed_official | 235:685d5f11838f | 638 | if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) |
mbed_official | 235:685d5f11838f | 639 | { |
mbed_official | 235:685d5f11838f | 640 | deviceAddress = NOR_MEMORY_ADRESS1; |
mbed_official | 235:685d5f11838f | 641 | } |
mbed_official | 235:685d5f11838f | 642 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) |
mbed_official | 235:685d5f11838f | 643 | { |
mbed_official | 235:685d5f11838f | 644 | deviceAddress = NOR_MEMORY_ADRESS2; |
mbed_official | 235:685d5f11838f | 645 | } |
mbed_official | 235:685d5f11838f | 646 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) |
mbed_official | 235:685d5f11838f | 647 | { |
mbed_official | 235:685d5f11838f | 648 | deviceAddress = NOR_MEMORY_ADRESS3; |
mbed_official | 235:685d5f11838f | 649 | } |
mbed_official | 235:685d5f11838f | 650 | else /* FMC_NORSRAM_BANK4 */ |
mbed_official | 235:685d5f11838f | 651 | { |
mbed_official | 235:685d5f11838f | 652 | deviceAddress = NOR_MEMORY_ADRESS4; |
mbed_official | 235:685d5f11838f | 653 | } |
mbed_official | 235:685d5f11838f | 654 | |
mbed_official | 235:685d5f11838f | 655 | /* Update the NOR controller state */ |
mbed_official | 235:685d5f11838f | 656 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 657 | |
mbed_official | 235:685d5f11838f | 658 | /* Send block erase command sequence */ |
mbed_official | 235:685d5f11838f | 659 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x00AA); |
mbed_official | 235:685d5f11838f | 660 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x02AA), 0x0055); |
mbed_official | 235:685d5f11838f | 661 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x0080); |
mbed_official | 235:685d5f11838f | 662 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x00AA); |
mbed_official | 235:685d5f11838f | 663 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x02AA), 0x0055); |
mbed_official | 235:685d5f11838f | 664 | __NOR_WRITE((uint32_t)(BlockAddress + Address), 0x30); |
mbed_official | 235:685d5f11838f | 665 | |
mbed_official | 235:685d5f11838f | 666 | /* Check the NOR memory status and update the controller state */ |
mbed_official | 235:685d5f11838f | 667 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 235:685d5f11838f | 668 | |
mbed_official | 235:685d5f11838f | 669 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 670 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 671 | |
mbed_official | 235:685d5f11838f | 672 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 673 | |
mbed_official | 235:685d5f11838f | 674 | } |
mbed_official | 235:685d5f11838f | 675 | |
mbed_official | 235:685d5f11838f | 676 | /** |
mbed_official | 235:685d5f11838f | 677 | * @brief Erase the entire NOR chip. |
mbed_official | 235:685d5f11838f | 678 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 679 | * @param Address : Device address |
mbed_official | 235:685d5f11838f | 680 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 681 | */ |
mbed_official | 235:685d5f11838f | 682 | HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address) |
mbed_official | 235:685d5f11838f | 683 | { |
mbed_official | 235:685d5f11838f | 684 | uint32_t deviceAddress = 0; |
mbed_official | 235:685d5f11838f | 685 | |
mbed_official | 235:685d5f11838f | 686 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 687 | __HAL_LOCK(hnor); |
mbed_official | 235:685d5f11838f | 688 | |
mbed_official | 235:685d5f11838f | 689 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 690 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 235:685d5f11838f | 691 | { |
mbed_official | 235:685d5f11838f | 692 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 693 | } |
mbed_official | 235:685d5f11838f | 694 | |
mbed_official | 235:685d5f11838f | 695 | /* Select the NOR device address */ |
mbed_official | 235:685d5f11838f | 696 | if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) |
mbed_official | 235:685d5f11838f | 697 | { |
mbed_official | 235:685d5f11838f | 698 | deviceAddress = NOR_MEMORY_ADRESS1; |
mbed_official | 235:685d5f11838f | 699 | } |
mbed_official | 235:685d5f11838f | 700 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) |
mbed_official | 235:685d5f11838f | 701 | { |
mbed_official | 235:685d5f11838f | 702 | deviceAddress = NOR_MEMORY_ADRESS2; |
mbed_official | 235:685d5f11838f | 703 | } |
mbed_official | 235:685d5f11838f | 704 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) |
mbed_official | 235:685d5f11838f | 705 | { |
mbed_official | 235:685d5f11838f | 706 | deviceAddress = NOR_MEMORY_ADRESS3; |
mbed_official | 235:685d5f11838f | 707 | } |
mbed_official | 235:685d5f11838f | 708 | else /* FMC_NORSRAM_BANK4 */ |
mbed_official | 235:685d5f11838f | 709 | { |
mbed_official | 235:685d5f11838f | 710 | deviceAddress = NOR_MEMORY_ADRESS4; |
mbed_official | 235:685d5f11838f | 711 | } |
mbed_official | 235:685d5f11838f | 712 | |
mbed_official | 235:685d5f11838f | 713 | /* Update the NOR controller state */ |
mbed_official | 235:685d5f11838f | 714 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 715 | |
mbed_official | 235:685d5f11838f | 716 | /* Send NOR chip erase command sequence */ |
mbed_official | 235:685d5f11838f | 717 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x00AA); |
mbed_official | 235:685d5f11838f | 718 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x02AA), 0x0055); |
mbed_official | 235:685d5f11838f | 719 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x0080); |
mbed_official | 235:685d5f11838f | 720 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x00AA); |
mbed_official | 235:685d5f11838f | 721 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x02AA), 0x0055); |
mbed_official | 235:685d5f11838f | 722 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0555), 0x0010); |
mbed_official | 235:685d5f11838f | 723 | |
mbed_official | 235:685d5f11838f | 724 | /* Check the NOR memory status and update the controller state */ |
mbed_official | 235:685d5f11838f | 725 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 235:685d5f11838f | 726 | |
mbed_official | 235:685d5f11838f | 727 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 728 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 729 | |
mbed_official | 235:685d5f11838f | 730 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 731 | } |
mbed_official | 235:685d5f11838f | 732 | |
mbed_official | 235:685d5f11838f | 733 | /** |
mbed_official | 235:685d5f11838f | 734 | * @brief Read NOR flash CFI IDs |
mbed_official | 235:685d5f11838f | 735 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 736 | * @param pNOR_CFI : pointer to NOR CFI IDs structure |
mbed_official | 235:685d5f11838f | 737 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 738 | */ |
mbed_official | 235:685d5f11838f | 739 | HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI) |
mbed_official | 235:685d5f11838f | 740 | { |
mbed_official | 235:685d5f11838f | 741 | uint32_t deviceAddress = 0; |
mbed_official | 235:685d5f11838f | 742 | |
mbed_official | 235:685d5f11838f | 743 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 744 | __HAL_LOCK(hnor); |
mbed_official | 235:685d5f11838f | 745 | |
mbed_official | 235:685d5f11838f | 746 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 747 | if(hnor->State == HAL_NOR_STATE_BUSY) |
mbed_official | 235:685d5f11838f | 748 | { |
mbed_official | 235:685d5f11838f | 749 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 750 | } |
mbed_official | 235:685d5f11838f | 751 | |
mbed_official | 235:685d5f11838f | 752 | /* Select the NOR device address */ |
mbed_official | 235:685d5f11838f | 753 | if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) |
mbed_official | 235:685d5f11838f | 754 | { |
mbed_official | 235:685d5f11838f | 755 | deviceAddress = NOR_MEMORY_ADRESS1; |
mbed_official | 235:685d5f11838f | 756 | } |
mbed_official | 235:685d5f11838f | 757 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) |
mbed_official | 235:685d5f11838f | 758 | { |
mbed_official | 235:685d5f11838f | 759 | deviceAddress = NOR_MEMORY_ADRESS2; |
mbed_official | 235:685d5f11838f | 760 | } |
mbed_official | 235:685d5f11838f | 761 | else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) |
mbed_official | 235:685d5f11838f | 762 | { |
mbed_official | 235:685d5f11838f | 763 | deviceAddress = NOR_MEMORY_ADRESS3; |
mbed_official | 235:685d5f11838f | 764 | } |
mbed_official | 235:685d5f11838f | 765 | else /* FMC_NORSRAM_BANK4 */ |
mbed_official | 235:685d5f11838f | 766 | { |
mbed_official | 235:685d5f11838f | 767 | deviceAddress = NOR_MEMORY_ADRESS4; |
mbed_official | 235:685d5f11838f | 768 | } |
mbed_official | 235:685d5f11838f | 769 | |
mbed_official | 235:685d5f11838f | 770 | /* Update the NOR controller state */ |
mbed_official | 235:685d5f11838f | 771 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 772 | |
mbed_official | 235:685d5f11838f | 773 | /* Send read CFI query command */ |
mbed_official | 235:685d5f11838f | 774 | __NOR_WRITE(__NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, 0x0055), 0x0098); |
mbed_official | 235:685d5f11838f | 775 | |
mbed_official | 235:685d5f11838f | 776 | /* read the NOR CFI information */ |
mbed_official | 235:685d5f11838f | 777 | pNOR_CFI->CFI_1 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, CFI1_ADDRESS); |
mbed_official | 235:685d5f11838f | 778 | pNOR_CFI->CFI_2 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, CFI2_ADDRESS); |
mbed_official | 235:685d5f11838f | 779 | pNOR_CFI->CFI_3 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, CFI3_ADDRESS); |
mbed_official | 235:685d5f11838f | 780 | pNOR_CFI->CFI_4 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(deviceAddress, NOR_MEMORY_8B, CFI4_ADDRESS); |
mbed_official | 235:685d5f11838f | 781 | |
mbed_official | 235:685d5f11838f | 782 | /* Check the NOR controller state */ |
mbed_official | 235:685d5f11838f | 783 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 235:685d5f11838f | 784 | |
mbed_official | 235:685d5f11838f | 785 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 786 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 787 | |
mbed_official | 235:685d5f11838f | 788 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 789 | } |
mbed_official | 235:685d5f11838f | 790 | |
mbed_official | 235:685d5f11838f | 791 | /** |
mbed_official | 235:685d5f11838f | 792 | * @} |
mbed_official | 235:685d5f11838f | 793 | */ |
mbed_official | 235:685d5f11838f | 794 | |
mbed_official | 235:685d5f11838f | 795 | /** @defgroup NOR_Group3 Control functions |
mbed_official | 235:685d5f11838f | 796 | * @brief management functions |
mbed_official | 235:685d5f11838f | 797 | * |
mbed_official | 235:685d5f11838f | 798 | @verbatim |
mbed_official | 235:685d5f11838f | 799 | ============================================================================== |
mbed_official | 235:685d5f11838f | 800 | ##### NOR Control functions ##### |
mbed_official | 235:685d5f11838f | 801 | ============================================================================== |
mbed_official | 235:685d5f11838f | 802 | [..] |
mbed_official | 235:685d5f11838f | 803 | This subsection provides a set of functions allowing to control dynamically |
mbed_official | 235:685d5f11838f | 804 | the NOR interface. |
mbed_official | 235:685d5f11838f | 805 | |
mbed_official | 235:685d5f11838f | 806 | @endverbatim |
mbed_official | 235:685d5f11838f | 807 | * @{ |
mbed_official | 235:685d5f11838f | 808 | */ |
mbed_official | 235:685d5f11838f | 809 | |
mbed_official | 235:685d5f11838f | 810 | /** |
mbed_official | 235:685d5f11838f | 811 | * @brief Enables dynamically NOR write operation. |
mbed_official | 235:685d5f11838f | 812 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 813 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 814 | */ |
mbed_official | 235:685d5f11838f | 815 | HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor) |
mbed_official | 235:685d5f11838f | 816 | { |
mbed_official | 235:685d5f11838f | 817 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 818 | __HAL_LOCK(hnor); |
mbed_official | 235:685d5f11838f | 819 | |
mbed_official | 235:685d5f11838f | 820 | /* Enable write operation */ |
mbed_official | 235:685d5f11838f | 821 | FMC_NORSRAM_WriteOperation_Enable(hnor->Instance, hnor->Init.NSBank); |
mbed_official | 235:685d5f11838f | 822 | |
mbed_official | 235:685d5f11838f | 823 | /* Update the NOR controller state */ |
mbed_official | 235:685d5f11838f | 824 | hnor->State = HAL_NOR_STATE_READY; |
mbed_official | 235:685d5f11838f | 825 | |
mbed_official | 235:685d5f11838f | 826 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 827 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 828 | |
mbed_official | 235:685d5f11838f | 829 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 830 | } |
mbed_official | 235:685d5f11838f | 831 | |
mbed_official | 235:685d5f11838f | 832 | /** |
mbed_official | 235:685d5f11838f | 833 | * @brief Disables dynamically NOR write operation. |
mbed_official | 235:685d5f11838f | 834 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 835 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 836 | */ |
mbed_official | 235:685d5f11838f | 837 | HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor) |
mbed_official | 235:685d5f11838f | 838 | { |
mbed_official | 235:685d5f11838f | 839 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 840 | __HAL_LOCK(hnor); |
mbed_official | 235:685d5f11838f | 841 | |
mbed_official | 235:685d5f11838f | 842 | /* Update the SRAM controller state */ |
mbed_official | 235:685d5f11838f | 843 | hnor->State = HAL_NOR_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 844 | |
mbed_official | 235:685d5f11838f | 845 | /* Disable write operation */ |
mbed_official | 235:685d5f11838f | 846 | FMC_NORSRAM_WriteOperation_Disable(hnor->Instance, hnor->Init.NSBank); |
mbed_official | 235:685d5f11838f | 847 | |
mbed_official | 235:685d5f11838f | 848 | /* Update the NOR controller state */ |
mbed_official | 235:685d5f11838f | 849 | hnor->State = HAL_NOR_STATE_PROTECTED; |
mbed_official | 235:685d5f11838f | 850 | |
mbed_official | 235:685d5f11838f | 851 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 852 | __HAL_UNLOCK(hnor); |
mbed_official | 235:685d5f11838f | 853 | |
mbed_official | 235:685d5f11838f | 854 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 855 | } |
mbed_official | 235:685d5f11838f | 856 | |
mbed_official | 235:685d5f11838f | 857 | /** |
mbed_official | 235:685d5f11838f | 858 | * @} |
mbed_official | 235:685d5f11838f | 859 | */ |
mbed_official | 235:685d5f11838f | 860 | |
mbed_official | 235:685d5f11838f | 861 | /** @defgroup NOR_Group4 State functions |
mbed_official | 235:685d5f11838f | 862 | * @brief Peripheral State functions |
mbed_official | 235:685d5f11838f | 863 | * |
mbed_official | 235:685d5f11838f | 864 | @verbatim |
mbed_official | 235:685d5f11838f | 865 | ============================================================================== |
mbed_official | 235:685d5f11838f | 866 | ##### NOR State functions ##### |
mbed_official | 235:685d5f11838f | 867 | ============================================================================== |
mbed_official | 235:685d5f11838f | 868 | [..] |
mbed_official | 235:685d5f11838f | 869 | This subsection permits to get in run-time the status of the NOR controller |
mbed_official | 235:685d5f11838f | 870 | and the data flow. |
mbed_official | 235:685d5f11838f | 871 | |
mbed_official | 235:685d5f11838f | 872 | @endverbatim |
mbed_official | 235:685d5f11838f | 873 | * @{ |
mbed_official | 235:685d5f11838f | 874 | */ |
mbed_official | 235:685d5f11838f | 875 | |
mbed_official | 235:685d5f11838f | 876 | /** |
mbed_official | 235:685d5f11838f | 877 | * @brief return the NOR controller state |
mbed_official | 235:685d5f11838f | 878 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 879 | * @retval NOR controller state |
mbed_official | 235:685d5f11838f | 880 | */ |
mbed_official | 235:685d5f11838f | 881 | HAL_NOR_StateTypeDef HAL_NOR_GetState(NOR_HandleTypeDef *hnor) |
mbed_official | 235:685d5f11838f | 882 | { |
mbed_official | 235:685d5f11838f | 883 | return hnor->State; |
mbed_official | 235:685d5f11838f | 884 | } |
mbed_official | 235:685d5f11838f | 885 | |
mbed_official | 235:685d5f11838f | 886 | /** |
mbed_official | 235:685d5f11838f | 887 | * @brief Returns the NOR operation status. |
mbed_official | 235:685d5f11838f | 888 | * @param hnor: pointer to the NOR handle |
mbed_official | 235:685d5f11838f | 889 | * @param Address: Device address |
mbed_official | 235:685d5f11838f | 890 | * @param Timeout: NOR progamming Timeout |
mbed_official | 235:685d5f11838f | 891 | * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR |
mbed_official | 235:685d5f11838f | 892 | * or NOR_TIMEOUT |
mbed_official | 235:685d5f11838f | 893 | */ |
mbed_official | 235:685d5f11838f | 894 | NOR_StatusTypedef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout) |
mbed_official | 235:685d5f11838f | 895 | { |
mbed_official | 235:685d5f11838f | 896 | NOR_StatusTypedef status = NOR_ONGOING; |
mbed_official | 235:685d5f11838f | 897 | uint16_t tmpSR1 = 0, tmpSR2 = 0; |
mbed_official | 235:685d5f11838f | 898 | uint32_t tickstart = 0; |
mbed_official | 235:685d5f11838f | 899 | |
mbed_official | 235:685d5f11838f | 900 | /* Poll on NOR memory Ready/Busy signal ------------------------------------*/ |
mbed_official | 235:685d5f11838f | 901 | HAL_NOR_MspWait(hnor, Timeout); |
mbed_official | 235:685d5f11838f | 902 | |
mbed_official | 235:685d5f11838f | 903 | /* Get the NOR memory operation status -------------------------------------*/ |
mbed_official | 235:685d5f11838f | 904 | while(status != NOR_SUCCESS) |
mbed_official | 235:685d5f11838f | 905 | { |
mbed_official | 235:685d5f11838f | 906 | /* Get tick */ |
mbed_official | 235:685d5f11838f | 907 | tickstart = HAL_GetTick(); |
mbed_official | 235:685d5f11838f | 908 | /* Check for the Timeout */ |
mbed_official | 235:685d5f11838f | 909 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 235:685d5f11838f | 910 | { |
mbed_official | 235:685d5f11838f | 911 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 235:685d5f11838f | 912 | { |
mbed_official | 235:685d5f11838f | 913 | status = NOR_TIMEOUT; |
mbed_official | 235:685d5f11838f | 914 | } |
mbed_official | 235:685d5f11838f | 915 | } |
mbed_official | 235:685d5f11838f | 916 | |
mbed_official | 235:685d5f11838f | 917 | /* Read NOR status register (DQ6 and DQ5) */ |
mbed_official | 235:685d5f11838f | 918 | tmpSR1 = *(__IO uint16_t *)Address; |
mbed_official | 235:685d5f11838f | 919 | tmpSR2 = *(__IO uint16_t *)Address; |
mbed_official | 235:685d5f11838f | 920 | |
mbed_official | 235:685d5f11838f | 921 | /* If DQ6 did not toggle between the two reads then return NOR_Success */ |
mbed_official | 235:685d5f11838f | 922 | if((tmpSR1 & 0x0040) == (tmpSR2 & 0x0040)) |
mbed_official | 235:685d5f11838f | 923 | { |
mbed_official | 235:685d5f11838f | 924 | return NOR_SUCCESS; |
mbed_official | 235:685d5f11838f | 925 | } |
mbed_official | 235:685d5f11838f | 926 | |
mbed_official | 235:685d5f11838f | 927 | if((tmpSR1 & 0x0020) == 0x0020) |
mbed_official | 235:685d5f11838f | 928 | { |
mbed_official | 235:685d5f11838f | 929 | return NOR_ONGOING; |
mbed_official | 235:685d5f11838f | 930 | } |
mbed_official | 235:685d5f11838f | 931 | |
mbed_official | 235:685d5f11838f | 932 | tmpSR1 = *(__IO uint16_t *)Address; |
mbed_official | 235:685d5f11838f | 933 | tmpSR2 = *(__IO uint16_t *)Address; |
mbed_official | 235:685d5f11838f | 934 | |
mbed_official | 235:685d5f11838f | 935 | /* If DQ6 did not toggle between the two reads then return NOR_Success */ |
mbed_official | 235:685d5f11838f | 936 | if((tmpSR1 & 0x0040) == (tmpSR2 & 0x0040)) |
mbed_official | 235:685d5f11838f | 937 | { |
mbed_official | 235:685d5f11838f | 938 | return NOR_SUCCESS; |
mbed_official | 235:685d5f11838f | 939 | } |
mbed_official | 235:685d5f11838f | 940 | |
mbed_official | 235:685d5f11838f | 941 | if((tmpSR1 & 0x0020) == 0x0020) |
mbed_official | 235:685d5f11838f | 942 | { |
mbed_official | 235:685d5f11838f | 943 | return NOR_ERROR; |
mbed_official | 235:685d5f11838f | 944 | } |
mbed_official | 235:685d5f11838f | 945 | } |
mbed_official | 235:685d5f11838f | 946 | |
mbed_official | 235:685d5f11838f | 947 | /* Return the operation status */ |
mbed_official | 235:685d5f11838f | 948 | return status; |
mbed_official | 235:685d5f11838f | 949 | } |
mbed_official | 235:685d5f11838f | 950 | |
mbed_official | 235:685d5f11838f | 951 | /** |
mbed_official | 235:685d5f11838f | 952 | * @} |
mbed_official | 235:685d5f11838f | 953 | */ |
mbed_official | 235:685d5f11838f | 954 | |
mbed_official | 235:685d5f11838f | 955 | /** |
mbed_official | 235:685d5f11838f | 956 | * @} |
mbed_official | 235:685d5f11838f | 957 | */ |
mbed_official | 235:685d5f11838f | 958 | #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */ |
mbed_official | 235:685d5f11838f | 959 | #endif /* HAL_NOR_MODULE_ENABLED */ |
mbed_official | 235:685d5f11838f | 960 | /** |
mbed_official | 235:685d5f11838f | 961 | * @} |
mbed_official | 235:685d5f11838f | 962 | */ |
mbed_official | 235:685d5f11838f | 963 | |
mbed_official | 235:685d5f11838f | 964 | /** |
mbed_official | 235:685d5f11838f | 965 | * @} |
mbed_official | 235:685d5f11838f | 966 | */ |
mbed_official | 235:685d5f11838f | 967 | |
mbed_official | 235:685d5f11838f | 968 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |