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:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

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