mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Wed Jun 11 09:45:09 2014 +0100
Revision:
226:b062af740e40
Parent:
106:ced8cbb51063
Child:
369:2e96f1b71984
Synchronized with git revision 42deb9ac55f9bdf9835e9c41dc757117d344ffda

Full URL: https://github.com/mbedmicro/mbed/commit/42deb9ac55f9bdf9835e9c41dc757117d344ffda/

[NUCLEO_F401RE] Remove call to Systick + bug fixes

Who changed what in which revision?

UserRevisionLine numberNew 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 226:b062af740e40 5 * @version V1.1.0RC2
mbed_official 226:b062af740e40 6 * @date 14-May-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>&copy; 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 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
mbed_official 87:085cde657901 98
mbed_official 87:085cde657901 99 /* Private typedef -----------------------------------------------------------*/
mbed_official 87:085cde657901 100 /* Private define ------------------------------------------------------------*/
mbed_official 106:ced8cbb51063 101 /* Private macro -------------------------------------------------------------*/
mbed_official 87:085cde657901 102 /* Private variables ---------------------------------------------------------*/
mbed_official 87:085cde657901 103 /* Private function prototypes -----------------------------------------------*/
mbed_official 87:085cde657901 104
mbed_official 87:085cde657901 105
mbed_official 87:085cde657901 106 /* Private functions ---------------------------------------------------------*/
mbed_official 87:085cde657901 107
mbed_official 87:085cde657901 108 /** @defgroup NOR_Private_Functions
mbed_official 87:085cde657901 109 * @{
mbed_official 87:085cde657901 110 */
mbed_official 87:085cde657901 111
mbed_official 87:085cde657901 112 /** @defgroup NOR_Group1 Initialization and de-initialization functions
mbed_official 87:085cde657901 113 * @brief Initialization and Configuration functions
mbed_official 87:085cde657901 114 *
mbed_official 87:085cde657901 115 @verbatim
mbed_official 87:085cde657901 116 ==============================================================================
mbed_official 87:085cde657901 117 ##### NOR Initialization and de_initialization functions #####
mbed_official 87:085cde657901 118 ==============================================================================
mbed_official 87:085cde657901 119 [..]
mbed_official 87:085cde657901 120 This section provides functions allowing to initialize/de-initialize
mbed_official 87:085cde657901 121 the NOR memory
mbed_official 87:085cde657901 122
mbed_official 87:085cde657901 123 @endverbatim
mbed_official 87:085cde657901 124 * @{
mbed_official 87:085cde657901 125 */
mbed_official 87:085cde657901 126
mbed_official 87:085cde657901 127 /**
mbed_official 87:085cde657901 128 * @brief Perform the NOR memory Initialization sequence
mbed_official 226:b062af740e40 129 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 130 * the configuration information for NOR module.
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 106:ced8cbb51063 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 106:ced8cbb51063 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 106:ced8cbb51063 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 * @brief Perform NOR memory De-Initialization sequence
mbed_official 226:b062af740e40 169 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 170 * the configuration information for NOR module.
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 /* De-Initialize the low level hardware (MSP) */
mbed_official 87:085cde657901 176 HAL_NOR_MspDeInit(hnor);
mbed_official 87:085cde657901 177
mbed_official 87:085cde657901 178 /* Configure the NOR registers with their reset values */
mbed_official 87:085cde657901 179 FMC_NORSRAM_DeInit(hnor->Instance, hnor->Extended, hnor->Init.NSBank);
mbed_official 87:085cde657901 180
mbed_official 87:085cde657901 181 /* Update the NOR controller state */
mbed_official 106:ced8cbb51063 182 hnor->State = HAL_NOR_STATE_RESET;
mbed_official 106:ced8cbb51063 183
mbed_official 106:ced8cbb51063 184 /* Release Lock */
mbed_official 106:ced8cbb51063 185 __HAL_UNLOCK(hnor);
mbed_official 106:ced8cbb51063 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 226:b062af740e40 192 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 193 * the configuration information for NOR module.
mbed_official 87:085cde657901 194 * @retval None
mbed_official 87:085cde657901 195 */
mbed_official 87:085cde657901 196 __weak void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor)
mbed_official 87:085cde657901 197 {
mbed_official 87:085cde657901 198 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 87:085cde657901 199 the HAL_NOR_MspInit could be implemented in the user file
mbed_official 87:085cde657901 200 */
mbed_official 87:085cde657901 201 }
mbed_official 87:085cde657901 202
mbed_official 87:085cde657901 203 /**
mbed_official 87:085cde657901 204 * @brief NOR MSP DeInit
mbed_official 226:b062af740e40 205 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 206 * the configuration information for NOR module.
mbed_official 87:085cde657901 207 * @retval None
mbed_official 87:085cde657901 208 */
mbed_official 87:085cde657901 209 __weak void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor)
mbed_official 87:085cde657901 210 {
mbed_official 87:085cde657901 211 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 87:085cde657901 212 the HAL_NOR_MspDeInit could be implemented in the user file
mbed_official 87:085cde657901 213 */
mbed_official 87:085cde657901 214 }
mbed_official 87:085cde657901 215
mbed_official 87:085cde657901 216 /**
mbed_official 87:085cde657901 217 * @brief NOR BSP Wait fro Ready/Busy signal
mbed_official 226:b062af740e40 218 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 219 * the configuration information for NOR module.
mbed_official 87:085cde657901 220 * @param Timeout: Maximum timeout value
mbed_official 87:085cde657901 221 * @retval None
mbed_official 87:085cde657901 222 */
mbed_official 87:085cde657901 223 __weak void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout)
mbed_official 87:085cde657901 224 {
mbed_official 87:085cde657901 225 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 87:085cde657901 226 the HAL_NOR_BspWait could be implemented in the user file
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 * @}
mbed_official 87:085cde657901 232 */
mbed_official 87:085cde657901 233
mbed_official 87:085cde657901 234 /** @defgroup NOR_Group2 Input and Output functions
mbed_official 87:085cde657901 235 * @brief Input Output and memory control functions
mbed_official 87:085cde657901 236 *
mbed_official 87:085cde657901 237 @verbatim
mbed_official 87:085cde657901 238 ==============================================================================
mbed_official 87:085cde657901 239 ##### NOR Input and Output functions #####
mbed_official 87:085cde657901 240 ==============================================================================
mbed_official 87:085cde657901 241 [..]
mbed_official 87:085cde657901 242 This section provides functions allowing to use and control the NOR memory
mbed_official 87:085cde657901 243
mbed_official 87:085cde657901 244 @endverbatim
mbed_official 87:085cde657901 245 * @{
mbed_official 87:085cde657901 246 */
mbed_official 87:085cde657901 247
mbed_official 87:085cde657901 248 /**
mbed_official 87:085cde657901 249 * @brief Read NOR flash IDs
mbed_official 226:b062af740e40 250 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 251 * the configuration information for NOR module.
mbed_official 87:085cde657901 252 * @param pNOR_ID : pointer to NOR ID structure
mbed_official 87:085cde657901 253 * @retval HAL status
mbed_official 87:085cde657901 254 */
mbed_official 87:085cde657901 255 HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID)
mbed_official 87:085cde657901 256 {
mbed_official 87:085cde657901 257 /* Process Locked */
mbed_official 87:085cde657901 258 __HAL_LOCK(hnor);
mbed_official 87:085cde657901 259
mbed_official 87:085cde657901 260 /* Check the NOR controller state */
mbed_official 87:085cde657901 261 if(hnor->State == HAL_NOR_STATE_BUSY)
mbed_official 87:085cde657901 262 {
mbed_official 87:085cde657901 263 return HAL_BUSY;
mbed_official 87:085cde657901 264 }
mbed_official 87:085cde657901 265
mbed_official 87:085cde657901 266 /* Update the NOR controller state */
mbed_official 87:085cde657901 267 hnor->State = HAL_NOR_STATE_BUSY;
mbed_official 87:085cde657901 268
mbed_official 87:085cde657901 269 /* Send read ID command */
mbed_official 87:085cde657901 270 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA);
mbed_official 87:085cde657901 271 __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055);
mbed_official 87:085cde657901 272 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x0090);
mbed_official 87:085cde657901 273
mbed_official 87:085cde657901 274 /* Read the NOR IDs */
mbed_official 87:085cde657901 275 pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) __NOR_ADDR_SHIFT(MC_ADDRESS);
mbed_official 87:085cde657901 276 pNOR_ID->Device_Code1 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(DEVICE_CODE1_ADDR);
mbed_official 87:085cde657901 277 pNOR_ID->Device_Code2 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(DEVICE_CODE2_ADDR);
mbed_official 87:085cde657901 278 pNOR_ID->Device_Code3 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(DEVICE_CODE3_ADDR);
mbed_official 87:085cde657901 279
mbed_official 87:085cde657901 280 /* Check the NOR controller state */
mbed_official 87:085cde657901 281 hnor->State = HAL_NOR_STATE_READY;
mbed_official 87:085cde657901 282
mbed_official 87:085cde657901 283 /* Process unlocked */
mbed_official 87:085cde657901 284 __HAL_UNLOCK(hnor);
mbed_official 87:085cde657901 285
mbed_official 87:085cde657901 286 return HAL_OK;
mbed_official 87:085cde657901 287 }
mbed_official 87:085cde657901 288
mbed_official 87:085cde657901 289 /**
mbed_official 87:085cde657901 290 * @brief Returns the NOR memory to Read mode.
mbed_official 226:b062af740e40 291 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 292 * the configuration information for NOR module.
mbed_official 87:085cde657901 293 * @retval HAL status
mbed_official 87:085cde657901 294 */
mbed_official 87:085cde657901 295 HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor)
mbed_official 87:085cde657901 296 {
mbed_official 87:085cde657901 297 /* Process Locked */
mbed_official 87:085cde657901 298 __HAL_LOCK(hnor);
mbed_official 87:085cde657901 299
mbed_official 87:085cde657901 300 /* Check the NOR controller state */
mbed_official 87:085cde657901 301 if(hnor->State == HAL_NOR_STATE_BUSY)
mbed_official 87:085cde657901 302 {
mbed_official 87:085cde657901 303 return HAL_BUSY;
mbed_official 87:085cde657901 304 }
mbed_official 87:085cde657901 305
mbed_official 87:085cde657901 306 __NOR_WRITE(NOR_MEMORY_ADRESS, 0x00F0);
mbed_official 87:085cde657901 307
mbed_official 87:085cde657901 308 /* Check the NOR controller state */
mbed_official 87:085cde657901 309 hnor->State = HAL_NOR_STATE_READY;
mbed_official 87:085cde657901 310
mbed_official 87:085cde657901 311 /* Process unlocked */
mbed_official 87:085cde657901 312 __HAL_UNLOCK(hnor);
mbed_official 87:085cde657901 313
mbed_official 87:085cde657901 314 return HAL_OK;
mbed_official 87:085cde657901 315 }
mbed_official 87:085cde657901 316
mbed_official 87:085cde657901 317 /**
mbed_official 87:085cde657901 318 * @brief Read data from NOR memory
mbed_official 226:b062af740e40 319 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 320 * the configuration information for NOR module.
mbed_official 87:085cde657901 321 * @param pAddress: pointer to Device address
mbed_official 87:085cde657901 322 * @param pData : pointer to read data
mbed_official 87:085cde657901 323 * @retval HAL status
mbed_official 87:085cde657901 324 */
mbed_official 87:085cde657901 325 HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
mbed_official 87:085cde657901 326 {
mbed_official 87:085cde657901 327 /* Process Locked */
mbed_official 87:085cde657901 328 __HAL_LOCK(hnor);
mbed_official 87:085cde657901 329
mbed_official 87:085cde657901 330 /* Check the NOR controller state */
mbed_official 87:085cde657901 331 if(hnor->State == HAL_NOR_STATE_BUSY)
mbed_official 87:085cde657901 332 {
mbed_official 87:085cde657901 333 return HAL_BUSY;
mbed_official 87:085cde657901 334 }
mbed_official 87:085cde657901 335
mbed_official 87:085cde657901 336 /* Update the NOR controller state */
mbed_official 87:085cde657901 337 hnor->State = HAL_NOR_STATE_BUSY;
mbed_official 87:085cde657901 338
mbed_official 87:085cde657901 339 /* Send read data command */
mbed_official 87:085cde657901 340 __NOR_WRITE(__NOR_ADDR_SHIFT(0x00555), 0x00AA);
mbed_official 87:085cde657901 341 __NOR_WRITE(__NOR_ADDR_SHIFT(0x002AA), 0x0055);
mbed_official 87:085cde657901 342 __NOR_WRITE(*pAddress, 0x00F0);
mbed_official 87:085cde657901 343
mbed_official 87:085cde657901 344 /* Read the data */
mbed_official 87:085cde657901 345 *pData = *(__IO uint32_t *)pAddress;
mbed_official 87:085cde657901 346
mbed_official 87:085cde657901 347 /* Check the NOR controller state */
mbed_official 87:085cde657901 348 hnor->State = HAL_NOR_STATE_READY;
mbed_official 87:085cde657901 349
mbed_official 87:085cde657901 350 /* Process unlocked */
mbed_official 87:085cde657901 351 __HAL_UNLOCK(hnor);
mbed_official 87:085cde657901 352
mbed_official 87:085cde657901 353 return HAL_OK;
mbed_official 87:085cde657901 354 }
mbed_official 87:085cde657901 355
mbed_official 87:085cde657901 356 /**
mbed_official 87:085cde657901 357 * @brief Program data to NOR memory
mbed_official 226:b062af740e40 358 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 359 * the configuration information for NOR module.
mbed_official 87:085cde657901 360 * @param pAddress: Device address
mbed_official 87:085cde657901 361 * @param pData : pointer to the data to write
mbed_official 87:085cde657901 362 * @retval HAL status
mbed_official 87:085cde657901 363 */
mbed_official 87:085cde657901 364 HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
mbed_official 87:085cde657901 365 {
mbed_official 87:085cde657901 366 /* Process Locked */
mbed_official 87:085cde657901 367 __HAL_LOCK(hnor);
mbed_official 87:085cde657901 368
mbed_official 87:085cde657901 369 /* Check the NOR controller state */
mbed_official 87:085cde657901 370 if(hnor->State == HAL_NOR_STATE_BUSY)
mbed_official 87:085cde657901 371 {
mbed_official 87:085cde657901 372 return HAL_BUSY;
mbed_official 87:085cde657901 373 }
mbed_official 87:085cde657901 374
mbed_official 87:085cde657901 375 /* Update the NOR controller state */
mbed_official 87:085cde657901 376 hnor->State = HAL_NOR_STATE_BUSY;
mbed_official 87:085cde657901 377
mbed_official 87:085cde657901 378 /* Send program data command */
mbed_official 87:085cde657901 379 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA);
mbed_official 87:085cde657901 380 __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055);
mbed_official 87:085cde657901 381 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00A0);
mbed_official 87:085cde657901 382
mbed_official 87:085cde657901 383 /* Write the data */
mbed_official 87:085cde657901 384 __NOR_WRITE(pAddress, *pData);
mbed_official 87:085cde657901 385
mbed_official 87:085cde657901 386 /* Check the NOR controller state */
mbed_official 87:085cde657901 387 hnor->State = HAL_NOR_STATE_READY;
mbed_official 87:085cde657901 388
mbed_official 87:085cde657901 389 /* Process unlocked */
mbed_official 87:085cde657901 390 __HAL_UNLOCK(hnor);
mbed_official 87:085cde657901 391
mbed_official 87:085cde657901 392 return HAL_OK;
mbed_official 87:085cde657901 393 }
mbed_official 87:085cde657901 394
mbed_official 87:085cde657901 395 /**
mbed_official 87:085cde657901 396 * @brief Reads a block of data from the FMC NOR memory.
mbed_official 226:b062af740e40 397 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 398 * the configuration information for NOR module.
mbed_official 87:085cde657901 399 * @param uwAddress: NOR memory internal address to read from.
mbed_official 87:085cde657901 400 * @param pData: pointer to the buffer that receives the data read from the
mbed_official 87:085cde657901 401 * NOR memory.
mbed_official 87:085cde657901 402 * @param uwBufferSize : number of Half word to read.
mbed_official 87:085cde657901 403 * @retval HAL status
mbed_official 87:085cde657901 404 */
mbed_official 87:085cde657901 405 HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
mbed_official 87:085cde657901 406 {
mbed_official 87:085cde657901 407 /* Process Locked */
mbed_official 87:085cde657901 408 __HAL_LOCK(hnor);
mbed_official 87:085cde657901 409
mbed_official 87:085cde657901 410 /* Check the NOR controller state */
mbed_official 87:085cde657901 411 if(hnor->State == HAL_NOR_STATE_BUSY)
mbed_official 87:085cde657901 412 {
mbed_official 87:085cde657901 413 return HAL_BUSY;
mbed_official 87:085cde657901 414 }
mbed_official 87:085cde657901 415
mbed_official 87:085cde657901 416 /* Update the NOR controller state */
mbed_official 87:085cde657901 417 hnor->State = HAL_NOR_STATE_BUSY;
mbed_official 87:085cde657901 418
mbed_official 87:085cde657901 419 /* Send read data command */
mbed_official 87:085cde657901 420 __NOR_WRITE(__NOR_ADDR_SHIFT(0x00555), 0x00AA);
mbed_official 87:085cde657901 421 __NOR_WRITE(__NOR_ADDR_SHIFT(0x002AA), 0x0055);
mbed_official 87:085cde657901 422 __NOR_WRITE(uwAddress, 0x00F0);
mbed_official 87:085cde657901 423
mbed_official 87:085cde657901 424 /* Read buffer */
mbed_official 87:085cde657901 425 while( uwBufferSize > 0)
mbed_official 87:085cde657901 426 {
mbed_official 87:085cde657901 427 *pData++ = *(__IO uint16_t *)uwAddress;
mbed_official 87:085cde657901 428 uwAddress += 2;
mbed_official 87:085cde657901 429 uwBufferSize--;
mbed_official 87:085cde657901 430 }
mbed_official 87:085cde657901 431
mbed_official 87:085cde657901 432 /* Check the NOR controller state */
mbed_official 87:085cde657901 433 hnor->State = HAL_NOR_STATE_READY;
mbed_official 87:085cde657901 434
mbed_official 87:085cde657901 435 /* Process unlocked */
mbed_official 87:085cde657901 436 __HAL_UNLOCK(hnor);
mbed_official 87:085cde657901 437
mbed_official 87:085cde657901 438 return HAL_OK;
mbed_official 87:085cde657901 439 }
mbed_official 87:085cde657901 440
mbed_official 87:085cde657901 441 /**
mbed_official 87:085cde657901 442 * @brief Writes a half-word buffer to the FMC NOR memory. This function
mbed_official 87:085cde657901 443 * must be used only with S29GL128P NOR memory.
mbed_official 226:b062af740e40 444 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 445 * the configuration information for NOR module.
mbed_official 87:085cde657901 446 * @param uwAddress: NOR memory internal address from which the data
mbed_official 87:085cde657901 447 * @param pData: pointer to source data buffer.
mbed_official 87:085cde657901 448 * @param uwBufferSize: number of Half words to write. The maximum allowed
mbed_official 87:085cde657901 449 * @retval HAL status
mbed_official 87:085cde657901 450 */
mbed_official 87:085cde657901 451 HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
mbed_official 87:085cde657901 452 {
mbed_official 87:085cde657901 453 uint32_t lastloadedaddress = 0;
mbed_official 87:085cde657901 454 uint32_t currentaddress = 0;
mbed_official 87:085cde657901 455 uint32_t endaddress = 0;
mbed_official 87:085cde657901 456
mbed_official 87:085cde657901 457 /* Process Locked */
mbed_official 87:085cde657901 458 __HAL_LOCK(hnor);
mbed_official 87:085cde657901 459
mbed_official 87:085cde657901 460 /* Check the NOR controller state */
mbed_official 87:085cde657901 461 if(hnor->State == HAL_NOR_STATE_BUSY)
mbed_official 87:085cde657901 462 {
mbed_official 87:085cde657901 463 return HAL_BUSY;
mbed_official 87:085cde657901 464 }
mbed_official 87:085cde657901 465
mbed_official 87:085cde657901 466 /* Update the NOR controller state */
mbed_official 87:085cde657901 467 hnor->State = HAL_NOR_STATE_BUSY;
mbed_official 87:085cde657901 468
mbed_official 87:085cde657901 469 /* Initialize variables */
mbed_official 87:085cde657901 470 currentaddress = uwAddress;
mbed_official 87:085cde657901 471 endaddress = uwAddress + uwBufferSize - 1;
mbed_official 87:085cde657901 472 lastloadedaddress = uwAddress;
mbed_official 87:085cde657901 473
mbed_official 87:085cde657901 474 /* Issue unlock command sequence */
mbed_official 87:085cde657901 475 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA);
mbed_official 87:085cde657901 476 __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055);
mbed_official 87:085cde657901 477
mbed_official 87:085cde657901 478 /* Write Buffer Load Command */
mbed_official 87:085cde657901 479 __NOR_WRITE(__NOR_ADDR_SHIFT(uwAddress), 0x25);
mbed_official 87:085cde657901 480 __NOR_WRITE(__NOR_ADDR_SHIFT(uwAddress), (uwBufferSize - 1));
mbed_official 87:085cde657901 481
mbed_official 87:085cde657901 482 /* Load Data into NOR Buffer */
mbed_official 87:085cde657901 483 while(currentaddress <= endaddress)
mbed_official 87:085cde657901 484 {
mbed_official 87:085cde657901 485 /* Store last loaded address & data value (for polling) */
mbed_official 87:085cde657901 486 lastloadedaddress = currentaddress;
mbed_official 87:085cde657901 487
mbed_official 87:085cde657901 488 __NOR_WRITE(__NOR_ADDR_SHIFT(currentaddress), *pData++);
mbed_official 87:085cde657901 489
mbed_official 87:085cde657901 490 currentaddress += 1;
mbed_official 87:085cde657901 491 }
mbed_official 87:085cde657901 492
mbed_official 87:085cde657901 493 __NOR_WRITE(__NOR_ADDR_SHIFT(lastloadedaddress), 0x29);
mbed_official 87:085cde657901 494
mbed_official 87:085cde657901 495 /* Check the NOR controller state */
mbed_official 87:085cde657901 496 hnor->State = HAL_NOR_STATE_READY;
mbed_official 87:085cde657901 497
mbed_official 87:085cde657901 498 /* Process unlocked */
mbed_official 87:085cde657901 499 __HAL_UNLOCK(hnor);
mbed_official 87:085cde657901 500
mbed_official 87:085cde657901 501 return HAL_OK;
mbed_official 87:085cde657901 502
mbed_official 87:085cde657901 503 }
mbed_official 87:085cde657901 504
mbed_official 87:085cde657901 505 /**
mbed_official 87:085cde657901 506 * @brief Erase the specified block of the NOR memory
mbed_official 226:b062af740e40 507 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 508 * the configuration information for NOR module.
mbed_official 87:085cde657901 509 * @param BlockAddress : Block to erase address
mbed_official 87:085cde657901 510 * @param Address: Device address
mbed_official 87:085cde657901 511 * @retval HAL status
mbed_official 87:085cde657901 512 */
mbed_official 87:085cde657901 513 HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address)
mbed_official 87:085cde657901 514 {
mbed_official 87:085cde657901 515 /* Process Locked */
mbed_official 87:085cde657901 516 __HAL_LOCK(hnor);
mbed_official 87:085cde657901 517
mbed_official 87:085cde657901 518 /* Check the NOR controller state */
mbed_official 87:085cde657901 519 if(hnor->State == HAL_NOR_STATE_BUSY)
mbed_official 87:085cde657901 520 {
mbed_official 87:085cde657901 521 return HAL_BUSY;
mbed_official 87:085cde657901 522 }
mbed_official 87:085cde657901 523
mbed_official 87:085cde657901 524 /* Update the NOR controller state */
mbed_official 87:085cde657901 525 hnor->State = HAL_NOR_STATE_BUSY;
mbed_official 87:085cde657901 526
mbed_official 87:085cde657901 527 /* Send block erase command sequence */
mbed_official 87:085cde657901 528 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA);
mbed_official 87:085cde657901 529 __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055);
mbed_official 87:085cde657901 530 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x0080);
mbed_official 87:085cde657901 531 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA);
mbed_official 87:085cde657901 532 __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055);
mbed_official 87:085cde657901 533 __NOR_WRITE((uint32_t)(BlockAddress + Address), 0x30);
mbed_official 87:085cde657901 534
mbed_official 87:085cde657901 535 /* Check the NOR memory status and update the controller state */
mbed_official 87:085cde657901 536 hnor->State = HAL_NOR_STATE_READY;
mbed_official 87:085cde657901 537
mbed_official 87:085cde657901 538 /* Process unlocked */
mbed_official 87:085cde657901 539 __HAL_UNLOCK(hnor);
mbed_official 87:085cde657901 540
mbed_official 87:085cde657901 541 return HAL_OK;
mbed_official 87:085cde657901 542
mbed_official 87:085cde657901 543 }
mbed_official 87:085cde657901 544
mbed_official 87:085cde657901 545 /**
mbed_official 87:085cde657901 546 * @brief Erase the entire NOR chip.
mbed_official 226:b062af740e40 547 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 548 * the configuration information for NOR module.
mbed_official 87:085cde657901 549 * @param Address : Device address
mbed_official 87:085cde657901 550 * @retval HAL status
mbed_official 87:085cde657901 551 */
mbed_official 87:085cde657901 552 HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address)
mbed_official 87:085cde657901 553 {
mbed_official 87:085cde657901 554 /* Process Locked */
mbed_official 87:085cde657901 555 __HAL_LOCK(hnor);
mbed_official 87:085cde657901 556
mbed_official 87:085cde657901 557 /* Check the NOR controller state */
mbed_official 87:085cde657901 558 if(hnor->State == HAL_NOR_STATE_BUSY)
mbed_official 87:085cde657901 559 {
mbed_official 87:085cde657901 560 return HAL_BUSY;
mbed_official 87:085cde657901 561 }
mbed_official 87:085cde657901 562
mbed_official 87:085cde657901 563 /* Update the NOR controller state */
mbed_official 87:085cde657901 564 hnor->State = HAL_NOR_STATE_BUSY;
mbed_official 87:085cde657901 565
mbed_official 87:085cde657901 566 /* Send NOR chip erase command sequence */
mbed_official 87:085cde657901 567 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA);
mbed_official 87:085cde657901 568 __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055);
mbed_official 87:085cde657901 569 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x0080);
mbed_official 87:085cde657901 570 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x00AA);
mbed_official 87:085cde657901 571 __NOR_WRITE(__NOR_ADDR_SHIFT(0x02AA), 0x0055);
mbed_official 87:085cde657901 572 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0555), 0x0010);
mbed_official 87:085cde657901 573
mbed_official 87:085cde657901 574 /* Check the NOR memory status and update the controller state */
mbed_official 87:085cde657901 575 hnor->State = HAL_NOR_STATE_READY;
mbed_official 87:085cde657901 576
mbed_official 87:085cde657901 577 /* Process unlocked */
mbed_official 87:085cde657901 578 __HAL_UNLOCK(hnor);
mbed_official 87:085cde657901 579
mbed_official 87:085cde657901 580 return HAL_OK;
mbed_official 87:085cde657901 581 }
mbed_official 87:085cde657901 582
mbed_official 87:085cde657901 583 /**
mbed_official 87:085cde657901 584 * @brief Read NOR flash CFI IDs
mbed_official 226:b062af740e40 585 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 586 * the configuration information for NOR module.
mbed_official 87:085cde657901 587 * @param pNOR_CFI : pointer to NOR CFI IDs structure
mbed_official 87:085cde657901 588 * @retval HAL status
mbed_official 87:085cde657901 589 */
mbed_official 87:085cde657901 590 HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI)
mbed_official 87:085cde657901 591 {
mbed_official 87:085cde657901 592 /* Process Locked */
mbed_official 87:085cde657901 593 __HAL_LOCK(hnor);
mbed_official 87:085cde657901 594
mbed_official 87:085cde657901 595 /* Check the NOR controller state */
mbed_official 87:085cde657901 596 if(hnor->State == HAL_NOR_STATE_BUSY)
mbed_official 87:085cde657901 597 {
mbed_official 87:085cde657901 598 return HAL_BUSY;
mbed_official 87:085cde657901 599 }
mbed_official 87:085cde657901 600
mbed_official 87:085cde657901 601 /* Update the NOR controller state */
mbed_official 87:085cde657901 602 hnor->State = HAL_NOR_STATE_BUSY;
mbed_official 87:085cde657901 603
mbed_official 87:085cde657901 604 /* Send read CFI query command */
mbed_official 87:085cde657901 605 __NOR_WRITE(__NOR_ADDR_SHIFT(0x0055), 0x0098);
mbed_official 87:085cde657901 606
mbed_official 87:085cde657901 607 /* read the NOR CFI information */
mbed_official 87:085cde657901 608 pNOR_CFI->CFI_1 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(CFI1_ADDRESS);
mbed_official 87:085cde657901 609 pNOR_CFI->CFI_2 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(CFI2_ADDRESS);
mbed_official 87:085cde657901 610 pNOR_CFI->CFI_3 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(CFI3_ADDRESS);
mbed_official 87:085cde657901 611 pNOR_CFI->CFI_4 = *(__IO uint16_t *) __NOR_ADDR_SHIFT(CFI4_ADDRESS);
mbed_official 87:085cde657901 612
mbed_official 87:085cde657901 613 /* Check the NOR controller state */
mbed_official 87:085cde657901 614 hnor->State = HAL_NOR_STATE_READY;
mbed_official 87:085cde657901 615
mbed_official 87:085cde657901 616 /* Process unlocked */
mbed_official 87:085cde657901 617 __HAL_UNLOCK(hnor);
mbed_official 87:085cde657901 618
mbed_official 87:085cde657901 619 return HAL_OK;
mbed_official 87:085cde657901 620 }
mbed_official 87:085cde657901 621
mbed_official 87:085cde657901 622 /**
mbed_official 87:085cde657901 623 * @}
mbed_official 87:085cde657901 624 */
mbed_official 87:085cde657901 625
mbed_official 87:085cde657901 626 /** @defgroup NOR_Group3 Control functions
mbed_official 87:085cde657901 627 * @brief management functions
mbed_official 87:085cde657901 628 *
mbed_official 87:085cde657901 629 @verbatim
mbed_official 87:085cde657901 630 ==============================================================================
mbed_official 87:085cde657901 631 ##### NOR Control functions #####
mbed_official 106:ced8cbb51063 632 ==============================================================================
mbed_official 87:085cde657901 633 [..]
mbed_official 87:085cde657901 634 This subsection provides a set of functions allowing to control dynamically
mbed_official 87:085cde657901 635 the NOR interface.
mbed_official 87:085cde657901 636
mbed_official 87:085cde657901 637 @endverbatim
mbed_official 87:085cde657901 638 * @{
mbed_official 87:085cde657901 639 */
mbed_official 87:085cde657901 640
mbed_official 87:085cde657901 641 /**
mbed_official 87:085cde657901 642 * @brief Enables dynamically NOR write operation.
mbed_official 226:b062af740e40 643 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 644 * the configuration information for NOR module.
mbed_official 87:085cde657901 645 * @retval HAL status
mbed_official 87:085cde657901 646 */
mbed_official 87:085cde657901 647 HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor)
mbed_official 87:085cde657901 648 {
mbed_official 87:085cde657901 649 /* Process Locked */
mbed_official 87:085cde657901 650 __HAL_LOCK(hnor);
mbed_official 87:085cde657901 651
mbed_official 87:085cde657901 652 /* Enable write operation */
mbed_official 87:085cde657901 653 FMC_NORSRAM_WriteOperation_Enable(hnor->Instance, hnor->Init.NSBank);
mbed_official 87:085cde657901 654
mbed_official 87:085cde657901 655 /* Update the NOR controller state */
mbed_official 87:085cde657901 656 hnor->State = HAL_NOR_STATE_READY;
mbed_official 87:085cde657901 657
mbed_official 87:085cde657901 658 /* Process unlocked */
mbed_official 87:085cde657901 659 __HAL_UNLOCK(hnor);
mbed_official 87:085cde657901 660
mbed_official 87:085cde657901 661 return HAL_OK;
mbed_official 87:085cde657901 662 }
mbed_official 87:085cde657901 663
mbed_official 87:085cde657901 664 /**
mbed_official 87:085cde657901 665 * @brief Disables dynamically NOR write operation.
mbed_official 226:b062af740e40 666 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 667 * the configuration information for NOR module.
mbed_official 87:085cde657901 668 * @retval HAL status
mbed_official 87:085cde657901 669 */
mbed_official 87:085cde657901 670 HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor)
mbed_official 87:085cde657901 671 {
mbed_official 87:085cde657901 672 /* Process Locked */
mbed_official 87:085cde657901 673 __HAL_LOCK(hnor);
mbed_official 87:085cde657901 674
mbed_official 87:085cde657901 675 /* Update the SRAM controller state */
mbed_official 87:085cde657901 676 hnor->State = HAL_NOR_STATE_BUSY;
mbed_official 87:085cde657901 677
mbed_official 87:085cde657901 678 /* Disable write operation */
mbed_official 87:085cde657901 679 FMC_NORSRAM_WriteOperation_Disable(hnor->Instance, hnor->Init.NSBank);
mbed_official 87:085cde657901 680
mbed_official 87:085cde657901 681 /* Update the NOR controller state */
mbed_official 87:085cde657901 682 hnor->State = HAL_NOR_STATE_PROTECTED;
mbed_official 87:085cde657901 683
mbed_official 87:085cde657901 684 /* Process unlocked */
mbed_official 87:085cde657901 685 __HAL_UNLOCK(hnor);
mbed_official 87:085cde657901 686
mbed_official 87:085cde657901 687 return HAL_OK;
mbed_official 87:085cde657901 688 }
mbed_official 87:085cde657901 689
mbed_official 87:085cde657901 690 /**
mbed_official 87:085cde657901 691 * @}
mbed_official 87:085cde657901 692 */
mbed_official 87:085cde657901 693
mbed_official 87:085cde657901 694 /** @defgroup NOR_Group4 State functions
mbed_official 87:085cde657901 695 * @brief Peripheral State functions
mbed_official 87:085cde657901 696 *
mbed_official 87:085cde657901 697 @verbatim
mbed_official 87:085cde657901 698 ==============================================================================
mbed_official 87:085cde657901 699 ##### NOR State functions #####
mbed_official 87:085cde657901 700 ==============================================================================
mbed_official 87:085cde657901 701 [..]
mbed_official 226:b062af740e40 702 This subsection permits to get in run-time the status of the NOR controller
mbed_official 87:085cde657901 703 and the data flow.
mbed_official 87:085cde657901 704
mbed_official 87:085cde657901 705 @endverbatim
mbed_official 87:085cde657901 706 * @{
mbed_official 87:085cde657901 707 */
mbed_official 87:085cde657901 708
mbed_official 87:085cde657901 709 /**
mbed_official 87:085cde657901 710 * @brief return the NOR controller state
mbed_official 226:b062af740e40 711 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 712 * the configuration information for NOR module.
mbed_official 87:085cde657901 713 * @retval NOR controller state
mbed_official 87:085cde657901 714 */
mbed_official 87:085cde657901 715 HAL_NOR_StateTypeDef HAL_NOR_GetState(NOR_HandleTypeDef *hnor)
mbed_official 87:085cde657901 716 {
mbed_official 87:085cde657901 717 return hnor->State;
mbed_official 87:085cde657901 718 }
mbed_official 87:085cde657901 719
mbed_official 87:085cde657901 720 /**
mbed_official 87:085cde657901 721 * @brief Returns the NOR operation status.
mbed_official 226:b062af740e40 722 * @param hnor: pointer to a NOR_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 723 * the configuration information for NOR module.
mbed_official 87:085cde657901 724 * @param Address: Device address
mbed_official 87:085cde657901 725 * @param Timeout: NOR progamming Timeout
mbed_official 87:085cde657901 726 * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
mbed_official 87:085cde657901 727 * or NOR_TIMEOUT
mbed_official 87:085cde657901 728 */
mbed_official 87:085cde657901 729 NOR_StatusTypedef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout)
mbed_official 87:085cde657901 730 {
mbed_official 87:085cde657901 731 NOR_StatusTypedef status = NOR_ONGOING;
mbed_official 87:085cde657901 732 uint16_t tmpSR1 = 0, tmpSR2 = 0;
mbed_official 87:085cde657901 733 uint32_t timeout = 0;
mbed_official 87:085cde657901 734
mbed_official 87:085cde657901 735 /* Poll on NOR memory Ready/Busy signal ------------------------------------*/
mbed_official 87:085cde657901 736 HAL_NOR_MspWait(hnor, timeout);
mbed_official 87:085cde657901 737
mbed_official 87:085cde657901 738 /* Get the NOR memory operation status -------------------------------------*/
mbed_official 87:085cde657901 739 while(status != NOR_SUCCESS)
mbed_official 87:085cde657901 740 {
mbed_official 87:085cde657901 741 /* Check for timeout value */
mbed_official 87:085cde657901 742 timeout = HAL_GetTick() + Timeout;
mbed_official 87:085cde657901 743
mbed_official 87:085cde657901 744 if(HAL_GetTick() >= timeout)
mbed_official 87:085cde657901 745 {
mbed_official 87:085cde657901 746 status = NOR_TIMEOUT;
mbed_official 87:085cde657901 747 }
mbed_official 87:085cde657901 748
mbed_official 87:085cde657901 749 /* Read NOR status register (DQ6 and DQ5) */
mbed_official 87:085cde657901 750 tmpSR1 = *(__IO uint16_t *)Address;
mbed_official 87:085cde657901 751 tmpSR2 = *(__IO uint16_t *)Address;
mbed_official 87:085cde657901 752
mbed_official 87:085cde657901 753 /* If DQ6 did not toggle between the two reads then return NOR_Success */
mbed_official 87:085cde657901 754 if((tmpSR1 & 0x0040) == (tmpSR2 & 0x0040))
mbed_official 87:085cde657901 755 {
mbed_official 87:085cde657901 756 return NOR_SUCCESS;
mbed_official 87:085cde657901 757 }
mbed_official 87:085cde657901 758
mbed_official 87:085cde657901 759 if((tmpSR1 & 0x0020) == 0x0020)
mbed_official 87:085cde657901 760 {
mbed_official 87:085cde657901 761 return NOR_ONGOING;
mbed_official 87:085cde657901 762 }
mbed_official 87:085cde657901 763
mbed_official 87:085cde657901 764 tmpSR1 = *(__IO uint16_t *)Address;
mbed_official 87:085cde657901 765 tmpSR2 = *(__IO uint16_t *)Address;
mbed_official 87:085cde657901 766
mbed_official 87:085cde657901 767 /* If DQ6 did not toggle between the two reads then return NOR_Success */
mbed_official 87:085cde657901 768 if((tmpSR1 & 0x0040) == (tmpSR2 & 0x0040))
mbed_official 87:085cde657901 769 {
mbed_official 87:085cde657901 770 return NOR_SUCCESS;
mbed_official 87:085cde657901 771 }
mbed_official 87:085cde657901 772
mbed_official 87:085cde657901 773 if((tmpSR1 & 0x0020) == 0x0020)
mbed_official 87:085cde657901 774 {
mbed_official 87:085cde657901 775 return NOR_ERROR;
mbed_official 87:085cde657901 776 }
mbed_official 87:085cde657901 777 }
mbed_official 87:085cde657901 778
mbed_official 87:085cde657901 779 /* Return the operation status */
mbed_official 87:085cde657901 780 return status;
mbed_official 87:085cde657901 781 }
mbed_official 87:085cde657901 782
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 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
mbed_official 87:085cde657901 791 #endif /* HAL_NOR_MODULE_ENABLED */
mbed_official 87:085cde657901 792 /**
mbed_official 87:085cde657901 793 * @}
mbed_official 87:085cde657901 794 */
mbed_official 87:085cde657901 795
mbed_official 87:085cde657901 796 /**
mbed_official 87:085cde657901 797 * @}
mbed_official 87:085cde657901 798 */
mbed_official 87:085cde657901 799
mbed_official 87:085cde657901 800 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/