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:
Thu Jul 02 16:30:08 2015 +0100
Revision:
581:39197bcd20f2
Parent:
489:119543c9f674
Synchronized with git revision ae2d3cdffe70184eb8736d94f76c45c93f4b7724

Full URL: https://github.com/mbedmicro/mbed/commit/ae2d3cdffe70184eb8736d94f76c45c93f4b7724/

Make it possible to build the core mbed library with yotta

Who changed what in which revision?

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