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