mbed library with additional peripherals for ST F401 board
Fork of mbed-src by
This mbed LIB has additional peripherals for ST F401 board
- UART2 : PA_3 rx, PA_2 tx
- UART3 : PC_7 rx, PC_6 tx
- I2C2 : PB_3 SDA, PB_10 SCL
- I2C3 : PB_4 SDA, PA_8 SCL
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L152RE/stm32l1xx_flash.c@76:aeb1df146756, 2014-01-27 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Jan 27 14:30:07 2014 +0000
- Revision:
- 76:aeb1df146756
- Child:
- 80:66393a7b209d
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd
Full URL: https://github.com/mbedmicro/mbed/commit/a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd/
Add NUCLEO_L152RE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 76:aeb1df146756 | 1 | /** |
mbed_official | 76:aeb1df146756 | 2 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 3 | * @file stm32l1xx_flash.c |
mbed_official | 76:aeb1df146756 | 4 | * @author MCD Application Team |
mbed_official | 76:aeb1df146756 | 5 | * @version V1.2.0 |
mbed_official | 76:aeb1df146756 | 6 | * @date 22-February-2013 |
mbed_official | 76:aeb1df146756 | 7 | * @brief This file provides all the Flash firmware functions. These functions |
mbed_official | 76:aeb1df146756 | 8 | * can be executed from Internal FLASH or Internal SRAM memories. |
mbed_official | 76:aeb1df146756 | 9 | * The functions that should be called from SRAM are defined inside |
mbed_official | 76:aeb1df146756 | 10 | * the "stm32l1xx_flash_ramfunc.c" file. |
mbed_official | 76:aeb1df146756 | 11 | * This file provides firmware functions to manage the following |
mbed_official | 76:aeb1df146756 | 12 | * functionalities of the FLASH peripheral: |
mbed_official | 76:aeb1df146756 | 13 | * + FLASH Interface configuration |
mbed_official | 76:aeb1df146756 | 14 | * + FLASH Memory Programming |
mbed_official | 76:aeb1df146756 | 15 | * + DATA EEPROM Programming |
mbed_official | 76:aeb1df146756 | 16 | * + Option Bytes Programming |
mbed_official | 76:aeb1df146756 | 17 | * + Interrupts and flags management |
mbed_official | 76:aeb1df146756 | 18 | * |
mbed_official | 76:aeb1df146756 | 19 | * @verbatim |
mbed_official | 76:aeb1df146756 | 20 | |
mbed_official | 76:aeb1df146756 | 21 | ============================================================================== |
mbed_official | 76:aeb1df146756 | 22 | ##### How to use this driver ##### |
mbed_official | 76:aeb1df146756 | 23 | ============================================================================== |
mbed_official | 76:aeb1df146756 | 24 | [..] This driver provides functions to configure and program the Flash |
mbed_official | 76:aeb1df146756 | 25 | memory of all STM32L1xx devices. |
mbed_official | 76:aeb1df146756 | 26 | [..] These functions are split in 5 groups: |
mbed_official | 76:aeb1df146756 | 27 | (#) FLASH Interface configuration functions: this group includes |
mbed_official | 76:aeb1df146756 | 28 | the management of following features: |
mbed_official | 76:aeb1df146756 | 29 | (++) Set the latency. |
mbed_official | 76:aeb1df146756 | 30 | (++) Enable/Disable the prefetch buffer. |
mbed_official | 76:aeb1df146756 | 31 | (++) Enable/Disable the 64 bit Read Access. |
mbed_official | 76:aeb1df146756 | 32 | (++) Enable/Disable the RUN PowerDown mode. |
mbed_official | 76:aeb1df146756 | 33 | (++) Enable/Disable the SLEEP PowerDown mode. |
mbed_official | 76:aeb1df146756 | 34 | |
mbed_official | 76:aeb1df146756 | 35 | (#) FLASH Memory Programming functions: this group includes all |
mbed_official | 76:aeb1df146756 | 36 | needed functions to erase and program the main memory: |
mbed_official | 76:aeb1df146756 | 37 | (++) Lock and Unlock the Flash interface. |
mbed_official | 76:aeb1df146756 | 38 | (++) Erase function: Erase Page. |
mbed_official | 76:aeb1df146756 | 39 | (++) Program functions: Fast Word and Half Page(should be |
mbed_official | 76:aeb1df146756 | 40 | executed from internal SRAM). |
mbed_official | 76:aeb1df146756 | 41 | |
mbed_official | 76:aeb1df146756 | 42 | (#) DATA EEPROM Programming functions: this group includes all |
mbed_official | 76:aeb1df146756 | 43 | needed functions to erase and program the DATA EEPROM memory: |
mbed_official | 76:aeb1df146756 | 44 | (++) Lock and Unlock the DATA EEPROM interface. |
mbed_official | 76:aeb1df146756 | 45 | (++) Erase function: Erase Byte, erase HalfWord, erase Word, erase |
mbed_official | 76:aeb1df146756 | 46 | (++) Double Word (should be executed from internal SRAM). |
mbed_official | 76:aeb1df146756 | 47 | (++) Program functions: Fast Program Byte, Fast Program Half-Word, |
mbed_official | 76:aeb1df146756 | 48 | FastProgramWord, Program Byte, Program Half-Word, |
mbed_official | 76:aeb1df146756 | 49 | Program Word and Program Double-Word (should be executed |
mbed_official | 76:aeb1df146756 | 50 | from internal SRAM). |
mbed_official | 76:aeb1df146756 | 51 | |
mbed_official | 76:aeb1df146756 | 52 | (#) FLASH Option Bytes Programming functions: this group includes |
mbed_official | 76:aeb1df146756 | 53 | all needed functions to: |
mbed_official | 76:aeb1df146756 | 54 | (++) Lock and Unlock the Flash Option bytes. |
mbed_official | 76:aeb1df146756 | 55 | (++) Set/Reset the write protection. |
mbed_official | 76:aeb1df146756 | 56 | (++) Set the Read protection Level. |
mbed_official | 76:aeb1df146756 | 57 | (++) Set the BOR level. |
mbed_official | 76:aeb1df146756 | 58 | (++) rogram the user option Bytes. |
mbed_official | 76:aeb1df146756 | 59 | (++) Launch the Option Bytes loader. |
mbed_official | 76:aeb1df146756 | 60 | (++) Get the Write protection. |
mbed_official | 76:aeb1df146756 | 61 | (++) Get the read protection status. |
mbed_official | 76:aeb1df146756 | 62 | (++) Get the BOR level. |
mbed_official | 76:aeb1df146756 | 63 | (++) Get the user option bytes. |
mbed_official | 76:aeb1df146756 | 64 | |
mbed_official | 76:aeb1df146756 | 65 | (#) FLASH Interrupts and flag management functions: this group |
mbed_official | 76:aeb1df146756 | 66 | includes all needed functions to: |
mbed_official | 76:aeb1df146756 | 67 | (++) Enable/Disable the flash interrupt sources. |
mbed_official | 76:aeb1df146756 | 68 | (++) Get flags status. |
mbed_official | 76:aeb1df146756 | 69 | (++) Clear flags. |
mbed_official | 76:aeb1df146756 | 70 | (++) Get Flash operation status. |
mbed_official | 76:aeb1df146756 | 71 | (++) Wait for last flash operation. |
mbed_official | 76:aeb1df146756 | 72 | |
mbed_official | 76:aeb1df146756 | 73 | * @endverbatim |
mbed_official | 76:aeb1df146756 | 74 | * |
mbed_official | 76:aeb1df146756 | 75 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 76 | * @attention |
mbed_official | 76:aeb1df146756 | 77 | * |
mbed_official | 76:aeb1df146756 | 78 | * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> |
mbed_official | 76:aeb1df146756 | 79 | * |
mbed_official | 76:aeb1df146756 | 80 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
mbed_official | 76:aeb1df146756 | 81 | * You may not use this file except in compliance with the License. |
mbed_official | 76:aeb1df146756 | 82 | * You may obtain a copy of the License at: |
mbed_official | 76:aeb1df146756 | 83 | * |
mbed_official | 76:aeb1df146756 | 84 | * http://www.st.com/software_license_agreement_liberty_v2 |
mbed_official | 76:aeb1df146756 | 85 | * |
mbed_official | 76:aeb1df146756 | 86 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 76:aeb1df146756 | 87 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 76:aeb1df146756 | 88 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 76:aeb1df146756 | 89 | * See the License for the specific language governing permissions and |
mbed_official | 76:aeb1df146756 | 90 | * limitations under the License. |
mbed_official | 76:aeb1df146756 | 91 | * |
mbed_official | 76:aeb1df146756 | 92 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 93 | */ |
mbed_official | 76:aeb1df146756 | 94 | |
mbed_official | 76:aeb1df146756 | 95 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 96 | #include "stm32l1xx_flash.h" |
mbed_official | 76:aeb1df146756 | 97 | |
mbed_official | 76:aeb1df146756 | 98 | /** @addtogroup STM32L1xx_StdPeriph_Driver |
mbed_official | 76:aeb1df146756 | 99 | * @{ |
mbed_official | 76:aeb1df146756 | 100 | */ |
mbed_official | 76:aeb1df146756 | 101 | |
mbed_official | 76:aeb1df146756 | 102 | /** @defgroup FLASH |
mbed_official | 76:aeb1df146756 | 103 | * @brief FLASH driver modules |
mbed_official | 76:aeb1df146756 | 104 | * @{ |
mbed_official | 76:aeb1df146756 | 105 | */ |
mbed_official | 76:aeb1df146756 | 106 | |
mbed_official | 76:aeb1df146756 | 107 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 108 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 109 | |
mbed_official | 76:aeb1df146756 | 110 | /* FLASH Mask */ |
mbed_official | 76:aeb1df146756 | 111 | #define WRP01_MASK ((uint32_t)0x0000FFFF) |
mbed_official | 76:aeb1df146756 | 112 | #define WRP23_MASK ((uint32_t)0xFFFF0000) |
mbed_official | 76:aeb1df146756 | 113 | #define WRP45_MASK ((uint32_t)0x0000FFFF) |
mbed_official | 76:aeb1df146756 | 114 | #define WRP67_MASK ((uint32_t)0xFFFF0000) |
mbed_official | 76:aeb1df146756 | 115 | #define WRP89_MASK ((uint32_t)0x0000FFFF) |
mbed_official | 76:aeb1df146756 | 116 | #define WRP1011_MASK ((uint32_t)0xFFFF0000) |
mbed_official | 76:aeb1df146756 | 117 | |
mbed_official | 76:aeb1df146756 | 118 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 119 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 120 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 121 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 122 | |
mbed_official | 76:aeb1df146756 | 123 | /** @defgroup FLASH_Private_Functions |
mbed_official | 76:aeb1df146756 | 124 | * @{ |
mbed_official | 76:aeb1df146756 | 125 | */ |
mbed_official | 76:aeb1df146756 | 126 | |
mbed_official | 76:aeb1df146756 | 127 | /** @defgroup FLASH_Group1 FLASH Interface configuration functions |
mbed_official | 76:aeb1df146756 | 128 | * @brief FLASH Interface configuration functions |
mbed_official | 76:aeb1df146756 | 129 | * |
mbed_official | 76:aeb1df146756 | 130 | @verbatim |
mbed_official | 76:aeb1df146756 | 131 | ============================================================================== |
mbed_official | 76:aeb1df146756 | 132 | ##### FLASH Interface configuration functions ##### |
mbed_official | 76:aeb1df146756 | 133 | ============================================================================== |
mbed_official | 76:aeb1df146756 | 134 | |
mbed_official | 76:aeb1df146756 | 135 | [..] FLASH_Interface configuration_Functions, includes the following functions: |
mbed_official | 76:aeb1df146756 | 136 | (+) void FLASH_SetLatency(uint32_t FLASH_Latency): |
mbed_official | 76:aeb1df146756 | 137 | [..] To correctly read data from Flash memory, the number of wait states (LATENCY) |
mbed_official | 76:aeb1df146756 | 138 | must be correctly programmed according to the frequency of the CPU clock |
mbed_official | 76:aeb1df146756 | 139 | (HCLK) and the supply voltage of the device. |
mbed_official | 76:aeb1df146756 | 140 | [..] |
mbed_official | 76:aeb1df146756 | 141 | ---------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 142 | | Wait states | HCLK clock frequency (MHz) | |
mbed_official | 76:aeb1df146756 | 143 | | |------------------------------------------------| |
mbed_official | 76:aeb1df146756 | 144 | | (Latency) | voltage range | voltage range | |
mbed_official | 76:aeb1df146756 | 145 | | | 1.65 V - 3.6 V | 2.0 V - 3.6 V | |
mbed_official | 76:aeb1df146756 | 146 | | |----------------|---------------|---------------| |
mbed_official | 76:aeb1df146756 | 147 | | | VCORE = 1.2 V | VCORE = 1.5 V | VCORE = 1.8 V | |
mbed_official | 76:aeb1df146756 | 148 | |-------------- |----------------|---------------|---------------| |
mbed_official | 76:aeb1df146756 | 149 | |0WS(1CPU cycle)|0 < HCLK <= 2 |0 < HCLK <= 8 |0 < HCLK <= 16 | |
mbed_official | 76:aeb1df146756 | 150 | |---------------|----------------|---------------|---------------| |
mbed_official | 76:aeb1df146756 | 151 | |1WS(2CPU cycle)|2 < HCLK <= 4 |8 < HCLK <= 16 |16 < HCLK <= 32| |
mbed_official | 76:aeb1df146756 | 152 | ---------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 153 | [..] |
mbed_official | 76:aeb1df146756 | 154 | (+) void FLASH_PrefetchBufferCmd(FunctionalState NewState); |
mbed_official | 76:aeb1df146756 | 155 | (+) void FLASH_ReadAccess64Cmd(FunctionalState NewState); |
mbed_official | 76:aeb1df146756 | 156 | (+) void FLASH_RUNPowerDownCmd(FunctionalState NewState); |
mbed_official | 76:aeb1df146756 | 157 | (+) void FLASH_SLEEPPowerDownCmd(FunctionalState NewState); |
mbed_official | 76:aeb1df146756 | 158 | (+) void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState); |
mbed_official | 76:aeb1df146756 | 159 | [..] |
mbed_official | 76:aeb1df146756 | 160 | Here below the allowed configuration of Latency, 64Bit access and prefetch buffer |
mbed_official | 76:aeb1df146756 | 161 | [..] |
mbed_official | 76:aeb1df146756 | 162 | -------------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 163 | | | ACC64 = 0 | ACC64 = 1 | |
mbed_official | 76:aeb1df146756 | 164 | | Latency |----------------|---------------|---------------|---------------| |
mbed_official | 76:aeb1df146756 | 165 | | | PRFTEN = 0 | PRFTEN = 1 | PRFTEN = 0 | PRFTEN = 1 | |
mbed_official | 76:aeb1df146756 | 166 | |---------------|----------------|---------------|---------------|---------------| |
mbed_official | 76:aeb1df146756 | 167 | |0WS(1CPU cycle)| YES | NO | YES | YES | |
mbed_official | 76:aeb1df146756 | 168 | |---------------|----------------|---------------|---------------|---------------| |
mbed_official | 76:aeb1df146756 | 169 | |1WS(2CPU cycle)| NO | NO | YES | YES | |
mbed_official | 76:aeb1df146756 | 170 | -------------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 171 | [..] |
mbed_official | 76:aeb1df146756 | 172 | All these functions don't need the unlock sequence. |
mbed_official | 76:aeb1df146756 | 173 | |
mbed_official | 76:aeb1df146756 | 174 | @endverbatim |
mbed_official | 76:aeb1df146756 | 175 | * @{ |
mbed_official | 76:aeb1df146756 | 176 | */ |
mbed_official | 76:aeb1df146756 | 177 | |
mbed_official | 76:aeb1df146756 | 178 | /** |
mbed_official | 76:aeb1df146756 | 179 | * @brief Sets the code latency value. |
mbed_official | 76:aeb1df146756 | 180 | * @param FLASH_Latency: specifies the FLASH Latency value. |
mbed_official | 76:aeb1df146756 | 181 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 182 | * @arg FLASH_Latency_0: FLASH Zero Latency cycle. |
mbed_official | 76:aeb1df146756 | 183 | * @arg FLASH_Latency_1: FLASH One Latency cycle. |
mbed_official | 76:aeb1df146756 | 184 | * @retval None |
mbed_official | 76:aeb1df146756 | 185 | */ |
mbed_official | 76:aeb1df146756 | 186 | void FLASH_SetLatency(uint32_t FLASH_Latency) |
mbed_official | 76:aeb1df146756 | 187 | { |
mbed_official | 76:aeb1df146756 | 188 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 189 | |
mbed_official | 76:aeb1df146756 | 190 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 191 | assert_param(IS_FLASH_LATENCY(FLASH_Latency)); |
mbed_official | 76:aeb1df146756 | 192 | |
mbed_official | 76:aeb1df146756 | 193 | /* Read the ACR register */ |
mbed_official | 76:aeb1df146756 | 194 | tmpreg = FLASH->ACR; |
mbed_official | 76:aeb1df146756 | 195 | |
mbed_official | 76:aeb1df146756 | 196 | /* Sets the Latency value */ |
mbed_official | 76:aeb1df146756 | 197 | tmpreg &= (uint32_t) (~((uint32_t)FLASH_ACR_LATENCY)); |
mbed_official | 76:aeb1df146756 | 198 | tmpreg |= FLASH_Latency; |
mbed_official | 76:aeb1df146756 | 199 | |
mbed_official | 76:aeb1df146756 | 200 | /* Write the ACR register */ |
mbed_official | 76:aeb1df146756 | 201 | FLASH->ACR = tmpreg; |
mbed_official | 76:aeb1df146756 | 202 | } |
mbed_official | 76:aeb1df146756 | 203 | |
mbed_official | 76:aeb1df146756 | 204 | /** |
mbed_official | 76:aeb1df146756 | 205 | * @brief Enables or disables the Prefetch Buffer. |
mbed_official | 76:aeb1df146756 | 206 | * @param NewState: new state of the FLASH prefetch buffer. |
mbed_official | 76:aeb1df146756 | 207 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 208 | * @retval None |
mbed_official | 76:aeb1df146756 | 209 | */ |
mbed_official | 76:aeb1df146756 | 210 | void FLASH_PrefetchBufferCmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 211 | { |
mbed_official | 76:aeb1df146756 | 212 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 213 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 214 | |
mbed_official | 76:aeb1df146756 | 215 | if(NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 216 | { |
mbed_official | 76:aeb1df146756 | 217 | FLASH->ACR |= FLASH_ACR_PRFTEN; |
mbed_official | 76:aeb1df146756 | 218 | } |
mbed_official | 76:aeb1df146756 | 219 | else |
mbed_official | 76:aeb1df146756 | 220 | { |
mbed_official | 76:aeb1df146756 | 221 | FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_PRFTEN)); |
mbed_official | 76:aeb1df146756 | 222 | } |
mbed_official | 76:aeb1df146756 | 223 | } |
mbed_official | 76:aeb1df146756 | 224 | |
mbed_official | 76:aeb1df146756 | 225 | /** |
mbed_official | 76:aeb1df146756 | 226 | * @brief Enables or disables read access to flash by 64 bits. |
mbed_official | 76:aeb1df146756 | 227 | * @param NewState: new state of the FLASH read access mode. |
mbed_official | 76:aeb1df146756 | 228 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 229 | * @note If this bit is set, the Read access 64 bit is used. |
mbed_official | 76:aeb1df146756 | 230 | * If this bit is reset, the Read access 32 bit is used. |
mbed_official | 76:aeb1df146756 | 231 | * @note This bit cannot be written at the same time as the LATENCY and |
mbed_official | 76:aeb1df146756 | 232 | * PRFTEN bits. |
mbed_official | 76:aeb1df146756 | 233 | * To reset this bit, the LATENCY should be zero wait state and the |
mbed_official | 76:aeb1df146756 | 234 | * prefetch off. |
mbed_official | 76:aeb1df146756 | 235 | * @retval None |
mbed_official | 76:aeb1df146756 | 236 | */ |
mbed_official | 76:aeb1df146756 | 237 | void FLASH_ReadAccess64Cmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 238 | { |
mbed_official | 76:aeb1df146756 | 239 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 240 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 241 | |
mbed_official | 76:aeb1df146756 | 242 | if(NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 243 | { |
mbed_official | 76:aeb1df146756 | 244 | FLASH->ACR |= FLASH_ACR_ACC64; |
mbed_official | 76:aeb1df146756 | 245 | } |
mbed_official | 76:aeb1df146756 | 246 | else |
mbed_official | 76:aeb1df146756 | 247 | { |
mbed_official | 76:aeb1df146756 | 248 | FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_ACC64)); |
mbed_official | 76:aeb1df146756 | 249 | } |
mbed_official | 76:aeb1df146756 | 250 | } |
mbed_official | 76:aeb1df146756 | 251 | |
mbed_official | 76:aeb1df146756 | 252 | /** |
mbed_official | 76:aeb1df146756 | 253 | * @brief Enable or disable the power down mode during Sleep mode. |
mbed_official | 76:aeb1df146756 | 254 | * @note This function is used to power down the FLASH when the system is in SLEEP LP mode. |
mbed_official | 76:aeb1df146756 | 255 | * @param NewState: new state of the power down mode during sleep mode. |
mbed_official | 76:aeb1df146756 | 256 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 257 | * @retval None |
mbed_official | 76:aeb1df146756 | 258 | */ |
mbed_official | 76:aeb1df146756 | 259 | void FLASH_SLEEPPowerDownCmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 260 | { |
mbed_official | 76:aeb1df146756 | 261 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 262 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 263 | |
mbed_official | 76:aeb1df146756 | 264 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 265 | { |
mbed_official | 76:aeb1df146756 | 266 | /* Set the SLEEP_PD bit to put Flash in power down mode during sleep mode */ |
mbed_official | 76:aeb1df146756 | 267 | FLASH->ACR |= FLASH_ACR_SLEEP_PD; |
mbed_official | 76:aeb1df146756 | 268 | } |
mbed_official | 76:aeb1df146756 | 269 | else |
mbed_official | 76:aeb1df146756 | 270 | { |
mbed_official | 76:aeb1df146756 | 271 | /* Clear the SLEEP_PD bit in to put Flash in idle mode during sleep mode */ |
mbed_official | 76:aeb1df146756 | 272 | FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_SLEEP_PD)); |
mbed_official | 76:aeb1df146756 | 273 | } |
mbed_official | 76:aeb1df146756 | 274 | } |
mbed_official | 76:aeb1df146756 | 275 | |
mbed_official | 76:aeb1df146756 | 276 | /** |
mbed_official | 76:aeb1df146756 | 277 | * @} |
mbed_official | 76:aeb1df146756 | 278 | */ |
mbed_official | 76:aeb1df146756 | 279 | |
mbed_official | 76:aeb1df146756 | 280 | /** @defgroup FLASH_Group2 FLASH Memory Programming functions |
mbed_official | 76:aeb1df146756 | 281 | * @brief FLASH Memory Programming functions |
mbed_official | 76:aeb1df146756 | 282 | * |
mbed_official | 76:aeb1df146756 | 283 | @verbatim |
mbed_official | 76:aeb1df146756 | 284 | ============================================================================== |
mbed_official | 76:aeb1df146756 | 285 | ##### FLASH Memory Programming functions ##### |
mbed_official | 76:aeb1df146756 | 286 | ============================================================================== |
mbed_official | 76:aeb1df146756 | 287 | |
mbed_official | 76:aeb1df146756 | 288 | [..] The FLASH Memory Programming functions, includes the following functions: |
mbed_official | 76:aeb1df146756 | 289 | (+) void FLASH_Unlock(void); |
mbed_official | 76:aeb1df146756 | 290 | (+) void FLASH_Lock(void); |
mbed_official | 76:aeb1df146756 | 291 | (+) FLASH_Status FLASH_ErasePage(uint32_t Page_Address); |
mbed_official | 76:aeb1df146756 | 292 | (+) FLASH_Status FLASH_FastProgramWord(uint32_t Address, uint32_t Data); |
mbed_official | 76:aeb1df146756 | 293 | |
mbed_official | 76:aeb1df146756 | 294 | [..] Any operation of erase or program should follow these steps: |
mbed_official | 76:aeb1df146756 | 295 | (#) Call the FLASH_Unlock() function to enable the flash control register and |
mbed_official | 76:aeb1df146756 | 296 | program memory access. |
mbed_official | 76:aeb1df146756 | 297 | (#) Call the desired function to erase page or program data. |
mbed_official | 76:aeb1df146756 | 298 | (#) Call the FLASH_Lock() to disable the flash program memory access |
mbed_official | 76:aeb1df146756 | 299 | (recommended to protect the FLASH memory against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 300 | |
mbed_official | 76:aeb1df146756 | 301 | @endverbatim |
mbed_official | 76:aeb1df146756 | 302 | * @{ |
mbed_official | 76:aeb1df146756 | 303 | */ |
mbed_official | 76:aeb1df146756 | 304 | |
mbed_official | 76:aeb1df146756 | 305 | /** |
mbed_official | 76:aeb1df146756 | 306 | * @brief Unlocks the FLASH control register and program memory access. |
mbed_official | 76:aeb1df146756 | 307 | * @param None |
mbed_official | 76:aeb1df146756 | 308 | * @retval None |
mbed_official | 76:aeb1df146756 | 309 | */ |
mbed_official | 76:aeb1df146756 | 310 | void FLASH_Unlock(void) |
mbed_official | 76:aeb1df146756 | 311 | { |
mbed_official | 76:aeb1df146756 | 312 | if((FLASH->PECR & FLASH_PECR_PRGLOCK) != RESET) |
mbed_official | 76:aeb1df146756 | 313 | { |
mbed_official | 76:aeb1df146756 | 314 | /* Unlocking the data memory and FLASH_PECR register access */ |
mbed_official | 76:aeb1df146756 | 315 | DATA_EEPROM_Unlock(); |
mbed_official | 76:aeb1df146756 | 316 | |
mbed_official | 76:aeb1df146756 | 317 | /* Unlocking the program memory access */ |
mbed_official | 76:aeb1df146756 | 318 | FLASH->PRGKEYR = FLASH_PRGKEY1; |
mbed_official | 76:aeb1df146756 | 319 | FLASH->PRGKEYR = FLASH_PRGKEY2; |
mbed_official | 76:aeb1df146756 | 320 | } |
mbed_official | 76:aeb1df146756 | 321 | } |
mbed_official | 76:aeb1df146756 | 322 | |
mbed_official | 76:aeb1df146756 | 323 | /** |
mbed_official | 76:aeb1df146756 | 324 | * @brief Locks the Program memory access. |
mbed_official | 76:aeb1df146756 | 325 | * @param None |
mbed_official | 76:aeb1df146756 | 326 | * @retval None |
mbed_official | 76:aeb1df146756 | 327 | */ |
mbed_official | 76:aeb1df146756 | 328 | void FLASH_Lock(void) |
mbed_official | 76:aeb1df146756 | 329 | { |
mbed_official | 76:aeb1df146756 | 330 | /* Set the PRGLOCK Bit to lock the program memory access */ |
mbed_official | 76:aeb1df146756 | 331 | FLASH->PECR |= FLASH_PECR_PRGLOCK; |
mbed_official | 76:aeb1df146756 | 332 | } |
mbed_official | 76:aeb1df146756 | 333 | |
mbed_official | 76:aeb1df146756 | 334 | /** |
mbed_official | 76:aeb1df146756 | 335 | * @brief Erases a specified page in program memory. |
mbed_official | 76:aeb1df146756 | 336 | * @note To correctly run this function, the FLASH_Unlock() function |
mbed_official | 76:aeb1df146756 | 337 | * must be called before. |
mbed_official | 76:aeb1df146756 | 338 | * Call the FLASH_Lock() to disable the flash memory access |
mbed_official | 76:aeb1df146756 | 339 | * (recommended to protect the FLASH memory against possible unwanted operation) |
mbed_official | 76:aeb1df146756 | 340 | * @param Page_Address: The page address in program memory to be erased. |
mbed_official | 76:aeb1df146756 | 341 | * @note A Page is erased in the Program memory only if the address to load |
mbed_official | 76:aeb1df146756 | 342 | * is the start address of a page (multiple of 256 bytes). |
mbed_official | 76:aeb1df146756 | 343 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 344 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 345 | */ |
mbed_official | 76:aeb1df146756 | 346 | FLASH_Status FLASH_ErasePage(uint32_t Page_Address) |
mbed_official | 76:aeb1df146756 | 347 | { |
mbed_official | 76:aeb1df146756 | 348 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 349 | |
mbed_official | 76:aeb1df146756 | 350 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 351 | assert_param(IS_FLASH_PROGRAM_ADDRESS(Page_Address)); |
mbed_official | 76:aeb1df146756 | 352 | |
mbed_official | 76:aeb1df146756 | 353 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 354 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 355 | |
mbed_official | 76:aeb1df146756 | 356 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 357 | { |
mbed_official | 76:aeb1df146756 | 358 | /* If the previous operation is completed, proceed to erase the page */ |
mbed_official | 76:aeb1df146756 | 359 | |
mbed_official | 76:aeb1df146756 | 360 | /* Set the ERASE bit */ |
mbed_official | 76:aeb1df146756 | 361 | FLASH->PECR |= FLASH_PECR_ERASE; |
mbed_official | 76:aeb1df146756 | 362 | |
mbed_official | 76:aeb1df146756 | 363 | /* Set PROG bit */ |
mbed_official | 76:aeb1df146756 | 364 | FLASH->PECR |= FLASH_PECR_PROG; |
mbed_official | 76:aeb1df146756 | 365 | |
mbed_official | 76:aeb1df146756 | 366 | /* Write 00000000h to the first word of the program page to erase */ |
mbed_official | 76:aeb1df146756 | 367 | *(__IO uint32_t *)Page_Address = 0x00000000; |
mbed_official | 76:aeb1df146756 | 368 | |
mbed_official | 76:aeb1df146756 | 369 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 370 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 371 | |
mbed_official | 76:aeb1df146756 | 372 | /* If the erase operation is completed, disable the ERASE and PROG bits */ |
mbed_official | 76:aeb1df146756 | 373 | FLASH->PECR &= (uint32_t)(~FLASH_PECR_PROG); |
mbed_official | 76:aeb1df146756 | 374 | FLASH->PECR &= (uint32_t)(~FLASH_PECR_ERASE); |
mbed_official | 76:aeb1df146756 | 375 | } |
mbed_official | 76:aeb1df146756 | 376 | /* Return the Erase Status */ |
mbed_official | 76:aeb1df146756 | 377 | return status; |
mbed_official | 76:aeb1df146756 | 378 | } |
mbed_official | 76:aeb1df146756 | 379 | |
mbed_official | 76:aeb1df146756 | 380 | /** |
mbed_official | 76:aeb1df146756 | 381 | * @brief Programs a word at a specified address in program memory. |
mbed_official | 76:aeb1df146756 | 382 | * @note To correctly run this function, the FLASH_Unlock() function |
mbed_official | 76:aeb1df146756 | 383 | * must be called before. |
mbed_official | 76:aeb1df146756 | 384 | * Call the FLASH_Lock() to disable the flash memory access |
mbed_official | 76:aeb1df146756 | 385 | * (recommended to protect the FLASH memory against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 386 | * @param Address: specifies the address to be written. |
mbed_official | 76:aeb1df146756 | 387 | * @param Data: specifies the data to be written. |
mbed_official | 76:aeb1df146756 | 388 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 389 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 390 | */ |
mbed_official | 76:aeb1df146756 | 391 | FLASH_Status FLASH_FastProgramWord(uint32_t Address, uint32_t Data) |
mbed_official | 76:aeb1df146756 | 392 | { |
mbed_official | 76:aeb1df146756 | 393 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 394 | |
mbed_official | 76:aeb1df146756 | 395 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 396 | assert_param(IS_FLASH_PROGRAM_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 397 | |
mbed_official | 76:aeb1df146756 | 398 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 399 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 400 | |
mbed_official | 76:aeb1df146756 | 401 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 402 | { |
mbed_official | 76:aeb1df146756 | 403 | /* If the previous operation is completed, proceed to program the new word */ |
mbed_official | 76:aeb1df146756 | 404 | *(__IO uint32_t *)Address = Data; |
mbed_official | 76:aeb1df146756 | 405 | |
mbed_official | 76:aeb1df146756 | 406 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 407 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 408 | } |
mbed_official | 76:aeb1df146756 | 409 | /* Return the Write Status */ |
mbed_official | 76:aeb1df146756 | 410 | return status; |
mbed_official | 76:aeb1df146756 | 411 | } |
mbed_official | 76:aeb1df146756 | 412 | |
mbed_official | 76:aeb1df146756 | 413 | /** |
mbed_official | 76:aeb1df146756 | 414 | * @} |
mbed_official | 76:aeb1df146756 | 415 | */ |
mbed_official | 76:aeb1df146756 | 416 | |
mbed_official | 76:aeb1df146756 | 417 | /** @defgroup FLASH_Group3 DATA EEPROM Programming functions |
mbed_official | 76:aeb1df146756 | 418 | * @brief DATA EEPROM Programming functions |
mbed_official | 76:aeb1df146756 | 419 | * |
mbed_official | 76:aeb1df146756 | 420 | @verbatim |
mbed_official | 76:aeb1df146756 | 421 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 422 | ##### DATA EEPROM Programming functions ##### |
mbed_official | 76:aeb1df146756 | 423 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 424 | |
mbed_official | 76:aeb1df146756 | 425 | [..] The DATA_EEPROM Programming_Functions, includes the following functions: |
mbed_official | 76:aeb1df146756 | 426 | (+) void DATA_EEPROM_Unlock(void); |
mbed_official | 76:aeb1df146756 | 427 | (+) void DATA_EEPROM_Lock(void); |
mbed_official | 76:aeb1df146756 | 428 | (+) FLASH_Status DATA_EEPROM_EraseByte(uint32_t Address); |
mbed_official | 76:aeb1df146756 | 429 | (+) FLASH_Status DATA_EEPROM_EraseHalfWord(uint32_t Address); |
mbed_official | 76:aeb1df146756 | 430 | (+) FLASH_Status DATA_EEPROM_EraseWord(uint32_t Address); |
mbed_official | 76:aeb1df146756 | 431 | (+) FLASH_Status DATA_EEPROM_FastProgramByte(uint32_t Address, uint8_t Data); |
mbed_official | 76:aeb1df146756 | 432 | (+) FLASH_Status DATA_EEPROM_FastProgramHalfWord(uint32_t Address, uint16_t Data); |
mbed_official | 76:aeb1df146756 | 433 | (+) FLASH_Status DATA_EEPROM_FastProgramWord(uint32_t Address, uint32_t Data); |
mbed_official | 76:aeb1df146756 | 434 | (+) FLASH_Status DATA_EEPROM_ProgramByte(uint32_t Address, uint8_t Data); |
mbed_official | 76:aeb1df146756 | 435 | (+) FLASH_Status DATA_EEPROM_ProgramHalfWord(uint32_t Address, uint16_t Data); |
mbed_official | 76:aeb1df146756 | 436 | (+) FLASH_Status DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data); |
mbed_official | 76:aeb1df146756 | 437 | |
mbed_official | 76:aeb1df146756 | 438 | [..] Any operation of erase or program should follow these steps: |
mbed_official | 76:aeb1df146756 | 439 | (#) Call the DATA_EEPROM_Unlock() function to enable the data EEPROM access |
mbed_official | 76:aeb1df146756 | 440 | and Flash program erase control register access. |
mbed_official | 76:aeb1df146756 | 441 | (#) Call the desired function to erase or program data. |
mbed_official | 76:aeb1df146756 | 442 | (#) Call the DATA_EEPROM_Lock() to disable the data EEPROM access |
mbed_official | 76:aeb1df146756 | 443 | and Flash program erase control register access(recommended |
mbed_official | 76:aeb1df146756 | 444 | to protect the DATA_EEPROM against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 445 | |
mbed_official | 76:aeb1df146756 | 446 | @endverbatim |
mbed_official | 76:aeb1df146756 | 447 | * @{ |
mbed_official | 76:aeb1df146756 | 448 | */ |
mbed_official | 76:aeb1df146756 | 449 | |
mbed_official | 76:aeb1df146756 | 450 | /** |
mbed_official | 76:aeb1df146756 | 451 | * @brief Unlocks the data memory and FLASH_PECR register access. |
mbed_official | 76:aeb1df146756 | 452 | * @param None |
mbed_official | 76:aeb1df146756 | 453 | * @retval None |
mbed_official | 76:aeb1df146756 | 454 | */ |
mbed_official | 76:aeb1df146756 | 455 | void DATA_EEPROM_Unlock(void) |
mbed_official | 76:aeb1df146756 | 456 | { |
mbed_official | 76:aeb1df146756 | 457 | if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET) |
mbed_official | 76:aeb1df146756 | 458 | { |
mbed_official | 76:aeb1df146756 | 459 | /* Unlocking the Data memory and FLASH_PECR register access*/ |
mbed_official | 76:aeb1df146756 | 460 | FLASH->PEKEYR = FLASH_PEKEY1; |
mbed_official | 76:aeb1df146756 | 461 | FLASH->PEKEYR = FLASH_PEKEY2; |
mbed_official | 76:aeb1df146756 | 462 | } |
mbed_official | 76:aeb1df146756 | 463 | } |
mbed_official | 76:aeb1df146756 | 464 | |
mbed_official | 76:aeb1df146756 | 465 | /** |
mbed_official | 76:aeb1df146756 | 466 | * @brief Locks the Data memory and FLASH_PECR register access. |
mbed_official | 76:aeb1df146756 | 467 | * @param None |
mbed_official | 76:aeb1df146756 | 468 | * @retval None |
mbed_official | 76:aeb1df146756 | 469 | */ |
mbed_official | 76:aeb1df146756 | 470 | void DATA_EEPROM_Lock(void) |
mbed_official | 76:aeb1df146756 | 471 | { |
mbed_official | 76:aeb1df146756 | 472 | /* Set the PELOCK Bit to lock the data memory and FLASH_PECR register access */ |
mbed_official | 76:aeb1df146756 | 473 | FLASH->PECR |= FLASH_PECR_PELOCK; |
mbed_official | 76:aeb1df146756 | 474 | } |
mbed_official | 76:aeb1df146756 | 475 | |
mbed_official | 76:aeb1df146756 | 476 | /** |
mbed_official | 76:aeb1df146756 | 477 | * @brief Enables or disables DATA EEPROM fixed Time programming (2*Tprog). |
mbed_official | 76:aeb1df146756 | 478 | * @param NewState: new state of the DATA EEPROM fixed Time programming mode. |
mbed_official | 76:aeb1df146756 | 479 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 480 | * @retval None |
mbed_official | 76:aeb1df146756 | 481 | */ |
mbed_official | 76:aeb1df146756 | 482 | void DATA_EEPROM_FixedTimeProgramCmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 483 | { |
mbed_official | 76:aeb1df146756 | 484 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 485 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 486 | |
mbed_official | 76:aeb1df146756 | 487 | if(NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 488 | { |
mbed_official | 76:aeb1df146756 | 489 | FLASH->PECR |= (uint32_t)FLASH_PECR_FTDW; |
mbed_official | 76:aeb1df146756 | 490 | } |
mbed_official | 76:aeb1df146756 | 491 | else |
mbed_official | 76:aeb1df146756 | 492 | { |
mbed_official | 76:aeb1df146756 | 493 | FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW)); |
mbed_official | 76:aeb1df146756 | 494 | } |
mbed_official | 76:aeb1df146756 | 495 | } |
mbed_official | 76:aeb1df146756 | 496 | |
mbed_official | 76:aeb1df146756 | 497 | /** |
mbed_official | 76:aeb1df146756 | 498 | * @brief Erase a byte in data memory. |
mbed_official | 76:aeb1df146756 | 499 | * @param Address: specifies the address to be erased. |
mbed_official | 76:aeb1df146756 | 500 | * @note This function can be used only for STM32L1XX_HD and STM32L1XX_MDP |
mbed_official | 76:aeb1df146756 | 501 | * density devices. |
mbed_official | 76:aeb1df146756 | 502 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 76:aeb1df146756 | 503 | * must be called before. |
mbed_official | 76:aeb1df146756 | 504 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 76:aeb1df146756 | 505 | * and Flash program erase control register access(recommended to protect |
mbed_official | 76:aeb1df146756 | 506 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 507 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 508 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 509 | */ |
mbed_official | 76:aeb1df146756 | 510 | FLASH_Status DATA_EEPROM_EraseByte(uint32_t Address) |
mbed_official | 76:aeb1df146756 | 511 | { |
mbed_official | 76:aeb1df146756 | 512 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 513 | |
mbed_official | 76:aeb1df146756 | 514 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 515 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 516 | |
mbed_official | 76:aeb1df146756 | 517 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 518 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 519 | |
mbed_official | 76:aeb1df146756 | 520 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 521 | { |
mbed_official | 76:aeb1df146756 | 522 | /* Write "00h" to valid address in the data memory" */ |
mbed_official | 76:aeb1df146756 | 523 | *(__IO uint8_t *) Address = (uint8_t)0x00; |
mbed_official | 76:aeb1df146756 | 524 | } |
mbed_official | 76:aeb1df146756 | 525 | |
mbed_official | 76:aeb1df146756 | 526 | /* Return the erase status */ |
mbed_official | 76:aeb1df146756 | 527 | return status; |
mbed_official | 76:aeb1df146756 | 528 | } |
mbed_official | 76:aeb1df146756 | 529 | |
mbed_official | 76:aeb1df146756 | 530 | /** |
mbed_official | 76:aeb1df146756 | 531 | * @brief Erase a halfword in data memory. |
mbed_official | 76:aeb1df146756 | 532 | * @param Address: specifies the address to be erased. |
mbed_official | 76:aeb1df146756 | 533 | * @note This function can be used only for STM32L1XX_HD and STM32L1XX_MDP |
mbed_official | 76:aeb1df146756 | 534 | * density devices. |
mbed_official | 76:aeb1df146756 | 535 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 76:aeb1df146756 | 536 | * must be called before. |
mbed_official | 76:aeb1df146756 | 537 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 76:aeb1df146756 | 538 | * and Flash program erase control register access(recommended to protect |
mbed_official | 76:aeb1df146756 | 539 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 540 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 541 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 542 | */ |
mbed_official | 76:aeb1df146756 | 543 | FLASH_Status DATA_EEPROM_EraseHalfWord(uint32_t Address) |
mbed_official | 76:aeb1df146756 | 544 | { |
mbed_official | 76:aeb1df146756 | 545 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 546 | |
mbed_official | 76:aeb1df146756 | 547 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 548 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 549 | |
mbed_official | 76:aeb1df146756 | 550 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 551 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 552 | |
mbed_official | 76:aeb1df146756 | 553 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 554 | { |
mbed_official | 76:aeb1df146756 | 555 | /* Write "0000h" to valid address in the data memory" */ |
mbed_official | 76:aeb1df146756 | 556 | *(__IO uint16_t *) Address = (uint16_t)0x0000; |
mbed_official | 76:aeb1df146756 | 557 | } |
mbed_official | 76:aeb1df146756 | 558 | |
mbed_official | 76:aeb1df146756 | 559 | /* Return the erase status */ |
mbed_official | 76:aeb1df146756 | 560 | return status; |
mbed_official | 76:aeb1df146756 | 561 | } |
mbed_official | 76:aeb1df146756 | 562 | |
mbed_official | 76:aeb1df146756 | 563 | /** |
mbed_official | 76:aeb1df146756 | 564 | * @brief Erase a word in data memory. |
mbed_official | 76:aeb1df146756 | 565 | * @param Address: specifies the address to be erased. |
mbed_official | 76:aeb1df146756 | 566 | * @note For STM32L1XX_MD, A data memory word is erased in the data memory only |
mbed_official | 76:aeb1df146756 | 567 | * if the address to load is the start address of a word (multiple of a word). |
mbed_official | 76:aeb1df146756 | 568 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 76:aeb1df146756 | 569 | * must be called before. |
mbed_official | 76:aeb1df146756 | 570 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 76:aeb1df146756 | 571 | * and Flash program erase control register access(recommended to protect |
mbed_official | 76:aeb1df146756 | 572 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 573 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 574 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 575 | */ |
mbed_official | 76:aeb1df146756 | 576 | FLASH_Status DATA_EEPROM_EraseWord(uint32_t Address) |
mbed_official | 76:aeb1df146756 | 577 | { |
mbed_official | 76:aeb1df146756 | 578 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 579 | |
mbed_official | 76:aeb1df146756 | 580 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 581 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 582 | |
mbed_official | 76:aeb1df146756 | 583 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 584 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 585 | |
mbed_official | 76:aeb1df146756 | 586 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 587 | { |
mbed_official | 76:aeb1df146756 | 588 | /* Write "00000000h" to valid address in the data memory" */ |
mbed_official | 76:aeb1df146756 | 589 | *(__IO uint32_t *) Address = 0x00000000; |
mbed_official | 76:aeb1df146756 | 590 | } |
mbed_official | 76:aeb1df146756 | 591 | |
mbed_official | 76:aeb1df146756 | 592 | /* Return the erase status */ |
mbed_official | 76:aeb1df146756 | 593 | return status; |
mbed_official | 76:aeb1df146756 | 594 | } |
mbed_official | 76:aeb1df146756 | 595 | |
mbed_official | 76:aeb1df146756 | 596 | /** |
mbed_official | 76:aeb1df146756 | 597 | * @brief Write a Byte at a specified address in data memory. |
mbed_official | 76:aeb1df146756 | 598 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 76:aeb1df146756 | 599 | * must be called before. |
mbed_official | 76:aeb1df146756 | 600 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 76:aeb1df146756 | 601 | * and Flash program erase control register access(recommended to protect |
mbed_official | 76:aeb1df146756 | 602 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 603 | * @param Address: specifies the address to be written. |
mbed_official | 76:aeb1df146756 | 604 | * @param Data: specifies the data to be written. |
mbed_official | 76:aeb1df146756 | 605 | * @note This function assumes that the is data word is already erased. |
mbed_official | 76:aeb1df146756 | 606 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 607 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 608 | */ |
mbed_official | 76:aeb1df146756 | 609 | FLASH_Status DATA_EEPROM_FastProgramByte(uint32_t Address, uint8_t Data) |
mbed_official | 76:aeb1df146756 | 610 | { |
mbed_official | 76:aeb1df146756 | 611 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 612 | #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 613 | uint32_t tmp = 0, tmpaddr = 0; |
mbed_official | 76:aeb1df146756 | 614 | #endif |
mbed_official | 76:aeb1df146756 | 615 | |
mbed_official | 76:aeb1df146756 | 616 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 617 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 618 | |
mbed_official | 76:aeb1df146756 | 619 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 620 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 621 | |
mbed_official | 76:aeb1df146756 | 622 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 623 | { |
mbed_official | 76:aeb1df146756 | 624 | /* Clear the FTDW bit */ |
mbed_official | 76:aeb1df146756 | 625 | FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW)); |
mbed_official | 76:aeb1df146756 | 626 | |
mbed_official | 76:aeb1df146756 | 627 | #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 628 | if(Data != (uint8_t)0x00) |
mbed_official | 76:aeb1df146756 | 629 | { |
mbed_official | 76:aeb1df146756 | 630 | /* If the previous operation is completed, proceed to write the new Data */ |
mbed_official | 76:aeb1df146756 | 631 | *(__IO uint8_t *)Address = Data; |
mbed_official | 76:aeb1df146756 | 632 | |
mbed_official | 76:aeb1df146756 | 633 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 634 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 635 | } |
mbed_official | 76:aeb1df146756 | 636 | else |
mbed_official | 76:aeb1df146756 | 637 | { |
mbed_official | 76:aeb1df146756 | 638 | tmpaddr = Address & 0xFFFFFFFC; |
mbed_official | 76:aeb1df146756 | 639 | tmp = * (__IO uint32_t *) tmpaddr; |
mbed_official | 76:aeb1df146756 | 640 | tmpaddr = 0xFF << ((uint32_t) (0x8 * (Address & 0x3))); |
mbed_official | 76:aeb1df146756 | 641 | tmp &= ~tmpaddr; |
mbed_official | 76:aeb1df146756 | 642 | status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC); |
mbed_official | 76:aeb1df146756 | 643 | status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp); |
mbed_official | 76:aeb1df146756 | 644 | } |
mbed_official | 76:aeb1df146756 | 645 | #elif defined (STM32L1XX_HD) || defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 646 | /* If the previous operation is completed, proceed to write the new Data */ |
mbed_official | 76:aeb1df146756 | 647 | *(__IO uint8_t *)Address = Data; |
mbed_official | 76:aeb1df146756 | 648 | |
mbed_official | 76:aeb1df146756 | 649 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 650 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 651 | #endif |
mbed_official | 76:aeb1df146756 | 652 | } |
mbed_official | 76:aeb1df146756 | 653 | /* Return the Write Status */ |
mbed_official | 76:aeb1df146756 | 654 | return status; |
mbed_official | 76:aeb1df146756 | 655 | } |
mbed_official | 76:aeb1df146756 | 656 | |
mbed_official | 76:aeb1df146756 | 657 | /** |
mbed_official | 76:aeb1df146756 | 658 | * @brief Writes a half word at a specified address in data memory. |
mbed_official | 76:aeb1df146756 | 659 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 76:aeb1df146756 | 660 | * must be called before. |
mbed_official | 76:aeb1df146756 | 661 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 76:aeb1df146756 | 662 | * and Flash program erase control register access(recommended to protect |
mbed_official | 76:aeb1df146756 | 663 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 664 | * @param Address: specifies the address to be written. |
mbed_official | 76:aeb1df146756 | 665 | * @param Data: specifies the data to be written. |
mbed_official | 76:aeb1df146756 | 666 | * @note This function assumes that the is data word is already erased. |
mbed_official | 76:aeb1df146756 | 667 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 668 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 669 | */ |
mbed_official | 76:aeb1df146756 | 670 | FLASH_Status DATA_EEPROM_FastProgramHalfWord(uint32_t Address, uint16_t Data) |
mbed_official | 76:aeb1df146756 | 671 | { |
mbed_official | 76:aeb1df146756 | 672 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 673 | #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 674 | uint32_t tmp = 0, tmpaddr = 0; |
mbed_official | 76:aeb1df146756 | 675 | #endif |
mbed_official | 76:aeb1df146756 | 676 | |
mbed_official | 76:aeb1df146756 | 677 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 678 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 679 | |
mbed_official | 76:aeb1df146756 | 680 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 681 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 682 | |
mbed_official | 76:aeb1df146756 | 683 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 684 | { |
mbed_official | 76:aeb1df146756 | 685 | /* Clear the FTDW bit */ |
mbed_official | 76:aeb1df146756 | 686 | FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW)); |
mbed_official | 76:aeb1df146756 | 687 | |
mbed_official | 76:aeb1df146756 | 688 | #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 689 | if(Data != (uint16_t)0x0000) |
mbed_official | 76:aeb1df146756 | 690 | { |
mbed_official | 76:aeb1df146756 | 691 | /* If the previous operation is completed, proceed to write the new data */ |
mbed_official | 76:aeb1df146756 | 692 | *(__IO uint16_t *)Address = Data; |
mbed_official | 76:aeb1df146756 | 693 | |
mbed_official | 76:aeb1df146756 | 694 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 695 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 696 | } |
mbed_official | 76:aeb1df146756 | 697 | else |
mbed_official | 76:aeb1df146756 | 698 | { |
mbed_official | 76:aeb1df146756 | 699 | if((Address & 0x3) != 0x3) |
mbed_official | 76:aeb1df146756 | 700 | { |
mbed_official | 76:aeb1df146756 | 701 | tmpaddr = Address & 0xFFFFFFFC; |
mbed_official | 76:aeb1df146756 | 702 | tmp = * (__IO uint32_t *) tmpaddr; |
mbed_official | 76:aeb1df146756 | 703 | tmpaddr = 0xFFFF << ((uint32_t) (0x8 * (Address & 0x3))); |
mbed_official | 76:aeb1df146756 | 704 | tmp &= ~tmpaddr; |
mbed_official | 76:aeb1df146756 | 705 | status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC); |
mbed_official | 76:aeb1df146756 | 706 | status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp); |
mbed_official | 76:aeb1df146756 | 707 | } |
mbed_official | 76:aeb1df146756 | 708 | else |
mbed_official | 76:aeb1df146756 | 709 | { |
mbed_official | 76:aeb1df146756 | 710 | DATA_EEPROM_FastProgramByte(Address, 0x00); |
mbed_official | 76:aeb1df146756 | 711 | DATA_EEPROM_FastProgramByte(Address + 1, 0x00); |
mbed_official | 76:aeb1df146756 | 712 | } |
mbed_official | 76:aeb1df146756 | 713 | } |
mbed_official | 76:aeb1df146756 | 714 | #elif defined (STM32L1XX_HD) || defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 715 | /* If the previous operation is completed, proceed to write the new data */ |
mbed_official | 76:aeb1df146756 | 716 | *(__IO uint16_t *)Address = Data; |
mbed_official | 76:aeb1df146756 | 717 | |
mbed_official | 76:aeb1df146756 | 718 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 719 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 720 | #endif |
mbed_official | 76:aeb1df146756 | 721 | } |
mbed_official | 76:aeb1df146756 | 722 | /* Return the Write Status */ |
mbed_official | 76:aeb1df146756 | 723 | return status; |
mbed_official | 76:aeb1df146756 | 724 | } |
mbed_official | 76:aeb1df146756 | 725 | |
mbed_official | 76:aeb1df146756 | 726 | /** |
mbed_official | 76:aeb1df146756 | 727 | * @brief Programs a word at a specified address in data memory. |
mbed_official | 76:aeb1df146756 | 728 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 76:aeb1df146756 | 729 | * must be called before. |
mbed_official | 76:aeb1df146756 | 730 | * Call the DATA_EEPROM_Lock() to the data EEPROM access |
mbed_official | 76:aeb1df146756 | 731 | * and Flash program erase control register access(recommended to protect |
mbed_official | 76:aeb1df146756 | 732 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 733 | * @param Address: specifies the address to be written. |
mbed_official | 76:aeb1df146756 | 734 | * @param Data: specifies the data to be written. |
mbed_official | 76:aeb1df146756 | 735 | * @note This function assumes that the is data word is already erased. |
mbed_official | 76:aeb1df146756 | 736 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 737 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 738 | */ |
mbed_official | 76:aeb1df146756 | 739 | FLASH_Status DATA_EEPROM_FastProgramWord(uint32_t Address, uint32_t Data) |
mbed_official | 76:aeb1df146756 | 740 | { |
mbed_official | 76:aeb1df146756 | 741 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 742 | |
mbed_official | 76:aeb1df146756 | 743 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 744 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 745 | |
mbed_official | 76:aeb1df146756 | 746 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 747 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 748 | |
mbed_official | 76:aeb1df146756 | 749 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 750 | { |
mbed_official | 76:aeb1df146756 | 751 | /* Clear the FTDW bit */ |
mbed_official | 76:aeb1df146756 | 752 | FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW)); |
mbed_official | 76:aeb1df146756 | 753 | |
mbed_official | 76:aeb1df146756 | 754 | /* If the previous operation is completed, proceed to program the new data */ |
mbed_official | 76:aeb1df146756 | 755 | *(__IO uint32_t *)Address = Data; |
mbed_official | 76:aeb1df146756 | 756 | |
mbed_official | 76:aeb1df146756 | 757 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 758 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 759 | } |
mbed_official | 76:aeb1df146756 | 760 | /* Return the Write Status */ |
mbed_official | 76:aeb1df146756 | 761 | return status; |
mbed_official | 76:aeb1df146756 | 762 | } |
mbed_official | 76:aeb1df146756 | 763 | |
mbed_official | 76:aeb1df146756 | 764 | /** |
mbed_official | 76:aeb1df146756 | 765 | * @brief Write a Byte at a specified address in data memory without erase. |
mbed_official | 76:aeb1df146756 | 766 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 76:aeb1df146756 | 767 | * must be called before. |
mbed_official | 76:aeb1df146756 | 768 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 76:aeb1df146756 | 769 | * and Flash program erase control register access(recommended to protect |
mbed_official | 76:aeb1df146756 | 770 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 771 | * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before |
mbed_official | 76:aeb1df146756 | 772 | * this function to configure the Fixed Time Programming. |
mbed_official | 76:aeb1df146756 | 773 | * @param Address: specifies the address to be written. |
mbed_official | 76:aeb1df146756 | 774 | * @param Data: specifies the data to be written. |
mbed_official | 76:aeb1df146756 | 775 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 776 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 777 | */ |
mbed_official | 76:aeb1df146756 | 778 | FLASH_Status DATA_EEPROM_ProgramByte(uint32_t Address, uint8_t Data) |
mbed_official | 76:aeb1df146756 | 779 | { |
mbed_official | 76:aeb1df146756 | 780 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 781 | #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 782 | uint32_t tmp = 0, tmpaddr = 0; |
mbed_official | 76:aeb1df146756 | 783 | #endif |
mbed_official | 76:aeb1df146756 | 784 | |
mbed_official | 76:aeb1df146756 | 785 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 786 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 787 | |
mbed_official | 76:aeb1df146756 | 788 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 789 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 790 | |
mbed_official | 76:aeb1df146756 | 791 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 792 | { |
mbed_official | 76:aeb1df146756 | 793 | #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 794 | if(Data != (uint8_t) 0x00) |
mbed_official | 76:aeb1df146756 | 795 | { |
mbed_official | 76:aeb1df146756 | 796 | *(__IO uint8_t *)Address = Data; |
mbed_official | 76:aeb1df146756 | 797 | |
mbed_official | 76:aeb1df146756 | 798 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 799 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 800 | |
mbed_official | 76:aeb1df146756 | 801 | } |
mbed_official | 76:aeb1df146756 | 802 | else |
mbed_official | 76:aeb1df146756 | 803 | { |
mbed_official | 76:aeb1df146756 | 804 | tmpaddr = Address & 0xFFFFFFFC; |
mbed_official | 76:aeb1df146756 | 805 | tmp = * (__IO uint32_t *) tmpaddr; |
mbed_official | 76:aeb1df146756 | 806 | tmpaddr = 0xFF << ((uint32_t) (0x8 * (Address & 0x3))); |
mbed_official | 76:aeb1df146756 | 807 | tmp &= ~tmpaddr; |
mbed_official | 76:aeb1df146756 | 808 | status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC); |
mbed_official | 76:aeb1df146756 | 809 | status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp); |
mbed_official | 76:aeb1df146756 | 810 | } |
mbed_official | 76:aeb1df146756 | 811 | #elif defined (STM32L1XX_HD) || defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 812 | *(__IO uint8_t *)Address = Data; |
mbed_official | 76:aeb1df146756 | 813 | |
mbed_official | 76:aeb1df146756 | 814 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 815 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 816 | #endif |
mbed_official | 76:aeb1df146756 | 817 | } |
mbed_official | 76:aeb1df146756 | 818 | /* Return the Write Status */ |
mbed_official | 76:aeb1df146756 | 819 | return status; |
mbed_official | 76:aeb1df146756 | 820 | } |
mbed_official | 76:aeb1df146756 | 821 | |
mbed_official | 76:aeb1df146756 | 822 | /** |
mbed_official | 76:aeb1df146756 | 823 | * @brief Writes a half word at a specified address in data memory without erase. |
mbed_official | 76:aeb1df146756 | 824 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 76:aeb1df146756 | 825 | * must be called before. |
mbed_official | 76:aeb1df146756 | 826 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 76:aeb1df146756 | 827 | * and Flash program erase control register access(recommended to protect |
mbed_official | 76:aeb1df146756 | 828 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 829 | * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before |
mbed_official | 76:aeb1df146756 | 830 | * this function to configure the Fixed Time Programming |
mbed_official | 76:aeb1df146756 | 831 | * @param Address: specifies the address to be written. |
mbed_official | 76:aeb1df146756 | 832 | * @param Data: specifies the data to be written. |
mbed_official | 76:aeb1df146756 | 833 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 834 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 835 | */ |
mbed_official | 76:aeb1df146756 | 836 | FLASH_Status DATA_EEPROM_ProgramHalfWord(uint32_t Address, uint16_t Data) |
mbed_official | 76:aeb1df146756 | 837 | { |
mbed_official | 76:aeb1df146756 | 838 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 839 | #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 840 | uint32_t tmp = 0, tmpaddr = 0; |
mbed_official | 76:aeb1df146756 | 841 | #endif |
mbed_official | 76:aeb1df146756 | 842 | |
mbed_official | 76:aeb1df146756 | 843 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 844 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 845 | |
mbed_official | 76:aeb1df146756 | 846 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 847 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 848 | |
mbed_official | 76:aeb1df146756 | 849 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 850 | { |
mbed_official | 76:aeb1df146756 | 851 | #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 852 | if(Data != (uint16_t)0x0000) |
mbed_official | 76:aeb1df146756 | 853 | { |
mbed_official | 76:aeb1df146756 | 854 | *(__IO uint16_t *)Address = Data; |
mbed_official | 76:aeb1df146756 | 855 | |
mbed_official | 76:aeb1df146756 | 856 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 857 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 858 | } |
mbed_official | 76:aeb1df146756 | 859 | else |
mbed_official | 76:aeb1df146756 | 860 | { |
mbed_official | 76:aeb1df146756 | 861 | if((Address & 0x3) != 0x3) |
mbed_official | 76:aeb1df146756 | 862 | { |
mbed_official | 76:aeb1df146756 | 863 | tmpaddr = Address & 0xFFFFFFFC; |
mbed_official | 76:aeb1df146756 | 864 | tmp = * (__IO uint32_t *) tmpaddr; |
mbed_official | 76:aeb1df146756 | 865 | tmpaddr = 0xFFFF << ((uint32_t) (0x8 * (Address & 0x3))); |
mbed_official | 76:aeb1df146756 | 866 | tmp &= ~tmpaddr; |
mbed_official | 76:aeb1df146756 | 867 | status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC); |
mbed_official | 76:aeb1df146756 | 868 | status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp); |
mbed_official | 76:aeb1df146756 | 869 | } |
mbed_official | 76:aeb1df146756 | 870 | else |
mbed_official | 76:aeb1df146756 | 871 | { |
mbed_official | 76:aeb1df146756 | 872 | DATA_EEPROM_FastProgramByte(Address, 0x00); |
mbed_official | 76:aeb1df146756 | 873 | DATA_EEPROM_FastProgramByte(Address + 1, 0x00); |
mbed_official | 76:aeb1df146756 | 874 | } |
mbed_official | 76:aeb1df146756 | 875 | } |
mbed_official | 76:aeb1df146756 | 876 | #elif defined (STM32L1XX_HD) || defined (STM32L1XX_MDP) |
mbed_official | 76:aeb1df146756 | 877 | *(__IO uint16_t *)Address = Data; |
mbed_official | 76:aeb1df146756 | 878 | |
mbed_official | 76:aeb1df146756 | 879 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 880 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 881 | #endif |
mbed_official | 76:aeb1df146756 | 882 | } |
mbed_official | 76:aeb1df146756 | 883 | /* Return the Write Status */ |
mbed_official | 76:aeb1df146756 | 884 | return status; |
mbed_official | 76:aeb1df146756 | 885 | } |
mbed_official | 76:aeb1df146756 | 886 | |
mbed_official | 76:aeb1df146756 | 887 | /** |
mbed_official | 76:aeb1df146756 | 888 | * @brief Programs a word at a specified address in data memory without erase. |
mbed_official | 76:aeb1df146756 | 889 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 76:aeb1df146756 | 890 | * must be called before. |
mbed_official | 76:aeb1df146756 | 891 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 76:aeb1df146756 | 892 | * and Flash program erase control register access(recommended to protect |
mbed_official | 76:aeb1df146756 | 893 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 76:aeb1df146756 | 894 | * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before |
mbed_official | 76:aeb1df146756 | 895 | * this function to configure the Fixed Time Programming. |
mbed_official | 76:aeb1df146756 | 896 | * @param Address: specifies the address to be written. |
mbed_official | 76:aeb1df146756 | 897 | * @param Data: specifies the data to be written. |
mbed_official | 76:aeb1df146756 | 898 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 899 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 900 | */ |
mbed_official | 76:aeb1df146756 | 901 | FLASH_Status DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data) |
mbed_official | 76:aeb1df146756 | 902 | { |
mbed_official | 76:aeb1df146756 | 903 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 904 | |
mbed_official | 76:aeb1df146756 | 905 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 906 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 907 | |
mbed_official | 76:aeb1df146756 | 908 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 909 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 910 | |
mbed_official | 76:aeb1df146756 | 911 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 912 | { |
mbed_official | 76:aeb1df146756 | 913 | *(__IO uint32_t *)Address = Data; |
mbed_official | 76:aeb1df146756 | 914 | |
mbed_official | 76:aeb1df146756 | 915 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 916 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 917 | } |
mbed_official | 76:aeb1df146756 | 918 | /* Return the Write Status */ |
mbed_official | 76:aeb1df146756 | 919 | return status; |
mbed_official | 76:aeb1df146756 | 920 | } |
mbed_official | 76:aeb1df146756 | 921 | |
mbed_official | 76:aeb1df146756 | 922 | /** |
mbed_official | 76:aeb1df146756 | 923 | * @} |
mbed_official | 76:aeb1df146756 | 924 | */ |
mbed_official | 76:aeb1df146756 | 925 | |
mbed_official | 76:aeb1df146756 | 926 | /** @defgroup FLASH_Group4 Option Bytes Programming functions |
mbed_official | 76:aeb1df146756 | 927 | * @brief Option Bytes Programming functions |
mbed_official | 76:aeb1df146756 | 928 | * |
mbed_official | 76:aeb1df146756 | 929 | @verbatim |
mbed_official | 76:aeb1df146756 | 930 | ============================================================================== |
mbed_official | 76:aeb1df146756 | 931 | ##### Option Bytes Programming functions ##### |
mbed_official | 76:aeb1df146756 | 932 | ============================================================================== |
mbed_official | 76:aeb1df146756 | 933 | |
mbed_official | 76:aeb1df146756 | 934 | [..] The FLASH_Option Bytes Programming_functions, includes the following functions: |
mbed_official | 76:aeb1df146756 | 935 | (+) void FLASH_OB_Unlock(void); |
mbed_official | 76:aeb1df146756 | 936 | (+) void FLASH_OB_Lock(void); |
mbed_official | 76:aeb1df146756 | 937 | (+) void FLASH_OB_Launch(void); |
mbed_official | 76:aeb1df146756 | 938 | (+) FLASH_Status FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState); |
mbed_official | 76:aeb1df146756 | 939 | (+) FLASH_Status FLASH_OB_WRP1Config(uint32_t OB_WRP1, FunctionalState NewState); |
mbed_official | 76:aeb1df146756 | 940 | (+) FLASH_Status FLASH_OB_WRP2Config(uint32_t OB_WRP2, FunctionalState NewState); |
mbed_official | 76:aeb1df146756 | 941 | (+) FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP); |
mbed_official | 76:aeb1df146756 | 942 | (+) FLASH_Status FLASH_OB_PCROPConfig(uint32_t OB_WRP, FunctionalState NewState); |
mbed_official | 76:aeb1df146756 | 943 | (+) FLASH_Status FLASH_OB_PCROP1Config(uint32_t OB_WRP1, FunctionalState NewState); |
mbed_official | 76:aeb1df146756 | 944 | (+) FLASH_Status FLASH_OB_PCROPSelectionConfig(uint16_t OB_PcROP); |
mbed_official | 76:aeb1df146756 | 945 | (+) FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY); |
mbed_official | 76:aeb1df146756 | 946 | (+) FLASH_Status FLASH_OB_BORConfig(uint8_t OB_BOR); |
mbed_official | 76:aeb1df146756 | 947 | (+) uint8_t FLASH_OB_GetUser(void); |
mbed_official | 76:aeb1df146756 | 948 | (+) uint32_t FLASH_OB_GetWRP(void); |
mbed_official | 76:aeb1df146756 | 949 | (+) uint32_t FLASH_OB_GetWRP1(void); |
mbed_official | 76:aeb1df146756 | 950 | (+) uint32_t FLASH_OB_GetWRP2(void); |
mbed_official | 76:aeb1df146756 | 951 | (+) FlagStatus FLASH_OB_GetRDP(void); |
mbed_official | 76:aeb1df146756 | 952 | (+) FlagStatus FLASH_OB_GetSPRMOD(void); |
mbed_official | 76:aeb1df146756 | 953 | (+) uint8_t FLASH_OB_GetBOR(void); |
mbed_official | 76:aeb1df146756 | 954 | (+) FLASH_Status FLASH_OB_BootConfig(uint16_t OB_BOOT); |
mbed_official | 76:aeb1df146756 | 955 | |
mbed_official | 76:aeb1df146756 | 956 | [..] Any operation of erase or program should follow these steps: |
mbed_official | 76:aeb1df146756 | 957 | (#) Call the FLASH_OB_Unlock() function to enable the Flash option control |
mbed_official | 76:aeb1df146756 | 958 | register access. |
mbed_official | 76:aeb1df146756 | 959 | (#) Call one or several functions to program the desired option bytes. |
mbed_official | 76:aeb1df146756 | 960 | (++) void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState) => to Enable/Disable |
mbed_official | 76:aeb1df146756 | 961 | the desired sector write protection. |
mbed_official | 76:aeb1df146756 | 962 | (++) void FLASH_OB_RDPConfig(uint8_t OB_RDP) => to set the desired read Protection Level. |
mbed_official | 76:aeb1df146756 | 963 | (++) void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY) => to configure |
mbed_official | 76:aeb1df146756 | 964 | the user option Bytes: IWDG, STOP and the Standby. |
mbed_official | 76:aeb1df146756 | 965 | (++) void FLASH_OB_BORConfig(uint8_t OB_BOR) => to Set the BOR level. |
mbed_official | 76:aeb1df146756 | 966 | (#) Once all needed option bytes to be programmed are correctly written, call the |
mbed_official | 76:aeb1df146756 | 967 | FLASH_OB_Launch(void) function to launch the Option Bytes programming process. |
mbed_official | 76:aeb1df146756 | 968 | (#) Call the FLASH_OB_Lock() to disable the Flash option control register access (recommended |
mbed_official | 76:aeb1df146756 | 969 | to protect the option Bytes against possible unwanted operations). |
mbed_official | 76:aeb1df146756 | 970 | |
mbed_official | 76:aeb1df146756 | 971 | [..] Proprietary code Read Out Protection (PcROP): |
mbed_official | 76:aeb1df146756 | 972 | (#) The PcROP sector is selected by using the same option bytes as the Write |
mbed_official | 76:aeb1df146756 | 973 | protection (nWRPi bits). As a result, these 2 options are exclusive each other. |
mbed_official | 76:aeb1df146756 | 974 | (#) In order to activate the PcROP (change the function of the nWRPi option bits), |
mbed_official | 76:aeb1df146756 | 975 | the SPRMOD option bit must be activated. |
mbed_official | 76:aeb1df146756 | 976 | (#) The active value of nWRPi bits is inverted when PCROP mode is active, this |
mbed_official | 76:aeb1df146756 | 977 | means: if SPRMOD = 1 and nWRPi = 1 (default value), then the user sector "i" |
mbed_official | 76:aeb1df146756 | 978 | is read/write protected. |
mbed_official | 76:aeb1df146756 | 979 | (#) To activate PCROP mode for Flash sector(s), you need to follow the sequence below: |
mbed_official | 76:aeb1df146756 | 980 | (++) For sector(s) within the first 128KB of the Flash, use this function |
mbed_official | 76:aeb1df146756 | 981 | FLASH_OB_PCROPConfig(OB_WRP_Pagesxxx, ENABLE) |
mbed_official | 76:aeb1df146756 | 982 | (++) For sector(s) within the second 128KB of the Flash, use this function |
mbed_official | 76:aeb1df146756 | 983 | FLASH_OB_PCROP1Config(OB_WRP_Pagesxxx, ENABLE) |
mbed_official | 76:aeb1df146756 | 984 | (++) Activate the PCROP mode using FLASH_OB_PCROPSelectionConfig(OB_PcROP_Enable) function |
mbed_official | 76:aeb1df146756 | 985 | (#) PcROP is available only in STM32L1XX_MDP devices |
mbed_official | 76:aeb1df146756 | 986 | |
mbed_official | 76:aeb1df146756 | 987 | @endverbatim |
mbed_official | 76:aeb1df146756 | 988 | * @{ |
mbed_official | 76:aeb1df146756 | 989 | */ |
mbed_official | 76:aeb1df146756 | 990 | |
mbed_official | 76:aeb1df146756 | 991 | /** |
mbed_official | 76:aeb1df146756 | 992 | * @brief Unlocks the option bytes block access. |
mbed_official | 76:aeb1df146756 | 993 | * @param None |
mbed_official | 76:aeb1df146756 | 994 | * @retval None |
mbed_official | 76:aeb1df146756 | 995 | */ |
mbed_official | 76:aeb1df146756 | 996 | void FLASH_OB_Unlock(void) |
mbed_official | 76:aeb1df146756 | 997 | { |
mbed_official | 76:aeb1df146756 | 998 | if((FLASH->PECR & FLASH_PECR_OPTLOCK) != RESET) |
mbed_official | 76:aeb1df146756 | 999 | { |
mbed_official | 76:aeb1df146756 | 1000 | /* Unlocking the data memory and FLASH_PECR register access */ |
mbed_official | 76:aeb1df146756 | 1001 | DATA_EEPROM_Unlock(); |
mbed_official | 76:aeb1df146756 | 1002 | |
mbed_official | 76:aeb1df146756 | 1003 | /* Unlocking the option bytes block access */ |
mbed_official | 76:aeb1df146756 | 1004 | FLASH->OPTKEYR = FLASH_OPTKEY1; |
mbed_official | 76:aeb1df146756 | 1005 | FLASH->OPTKEYR = FLASH_OPTKEY2; |
mbed_official | 76:aeb1df146756 | 1006 | } |
mbed_official | 76:aeb1df146756 | 1007 | } |
mbed_official | 76:aeb1df146756 | 1008 | |
mbed_official | 76:aeb1df146756 | 1009 | /** |
mbed_official | 76:aeb1df146756 | 1010 | * @brief Locks the option bytes block access. |
mbed_official | 76:aeb1df146756 | 1011 | * @param None |
mbed_official | 76:aeb1df146756 | 1012 | * @retval None |
mbed_official | 76:aeb1df146756 | 1013 | */ |
mbed_official | 76:aeb1df146756 | 1014 | void FLASH_OB_Lock(void) |
mbed_official | 76:aeb1df146756 | 1015 | { |
mbed_official | 76:aeb1df146756 | 1016 | /* Set the OPTLOCK Bit to lock the option bytes block access */ |
mbed_official | 76:aeb1df146756 | 1017 | FLASH->PECR |= FLASH_PECR_OPTLOCK; |
mbed_official | 76:aeb1df146756 | 1018 | } |
mbed_official | 76:aeb1df146756 | 1019 | |
mbed_official | 76:aeb1df146756 | 1020 | /** |
mbed_official | 76:aeb1df146756 | 1021 | * @brief Launch the option byte loading. |
mbed_official | 76:aeb1df146756 | 1022 | * @param None |
mbed_official | 76:aeb1df146756 | 1023 | * @retval None |
mbed_official | 76:aeb1df146756 | 1024 | */ |
mbed_official | 76:aeb1df146756 | 1025 | void FLASH_OB_Launch(void) |
mbed_official | 76:aeb1df146756 | 1026 | { |
mbed_official | 76:aeb1df146756 | 1027 | /* Set the OBL_Launch bit to lauch the option byte loading */ |
mbed_official | 76:aeb1df146756 | 1028 | FLASH->PECR |= FLASH_PECR_OBL_LAUNCH; |
mbed_official | 76:aeb1df146756 | 1029 | } |
mbed_official | 76:aeb1df146756 | 1030 | |
mbed_official | 76:aeb1df146756 | 1031 | /** |
mbed_official | 76:aeb1df146756 | 1032 | * @brief Write protects the desired pages of the first 128KB of the Flash. |
mbed_official | 76:aeb1df146756 | 1033 | * @param OB_WRP: specifies the address of the pages to be write protected. |
mbed_official | 76:aeb1df146756 | 1034 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 1035 | * @arg value between OB_WRP_Pages0to15 and OB_WRP_Pages496to511 |
mbed_official | 76:aeb1df146756 | 1036 | * @arg OB_WRP_AllPages |
mbed_official | 76:aeb1df146756 | 1037 | * @param NewState: new state of the specified FLASH Pages Wtite protection. |
mbed_official | 76:aeb1df146756 | 1038 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 1039 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 1040 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 1041 | */ |
mbed_official | 76:aeb1df146756 | 1042 | FLASH_Status FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 1043 | { |
mbed_official | 76:aeb1df146756 | 1044 | uint32_t WRP01_Data = 0, WRP23_Data = 0; |
mbed_official | 76:aeb1df146756 | 1045 | |
mbed_official | 76:aeb1df146756 | 1046 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1047 | uint32_t tmp1 = 0, tmp2 = 0; |
mbed_official | 76:aeb1df146756 | 1048 | |
mbed_official | 76:aeb1df146756 | 1049 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1050 | assert_param(IS_OB_WRP(OB_WRP)); |
mbed_official | 76:aeb1df146756 | 1051 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 1052 | |
mbed_official | 76:aeb1df146756 | 1053 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1054 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1055 | |
mbed_official | 76:aeb1df146756 | 1056 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 1057 | { |
mbed_official | 76:aeb1df146756 | 1058 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 1059 | { |
mbed_official | 76:aeb1df146756 | 1060 | WRP01_Data = (uint16_t)(((OB_WRP & WRP01_MASK) | OB->WRP01)); |
mbed_official | 76:aeb1df146756 | 1061 | WRP23_Data = (uint16_t)((((OB_WRP & WRP23_MASK)>>16 | OB->WRP23))); |
mbed_official | 76:aeb1df146756 | 1062 | tmp1 = (uint32_t)(~(WRP01_Data) << 16)|(WRP01_Data); |
mbed_official | 76:aeb1df146756 | 1063 | OB->WRP01 = tmp1; |
mbed_official | 76:aeb1df146756 | 1064 | |
mbed_official | 76:aeb1df146756 | 1065 | tmp2 = (uint32_t)(~(WRP23_Data) << 16)|(WRP23_Data); |
mbed_official | 76:aeb1df146756 | 1066 | OB->WRP23 = tmp2; |
mbed_official | 76:aeb1df146756 | 1067 | } |
mbed_official | 76:aeb1df146756 | 1068 | |
mbed_official | 76:aeb1df146756 | 1069 | else |
mbed_official | 76:aeb1df146756 | 1070 | { |
mbed_official | 76:aeb1df146756 | 1071 | WRP01_Data = (uint16_t)(~OB_WRP & (WRP01_MASK & OB->WRP01)); |
mbed_official | 76:aeb1df146756 | 1072 | WRP23_Data = (uint16_t)((((~OB_WRP & WRP23_MASK)>>16 & OB->WRP23))); |
mbed_official | 76:aeb1df146756 | 1073 | |
mbed_official | 76:aeb1df146756 | 1074 | tmp1 = (uint32_t)((~WRP01_Data) << 16)|(WRP01_Data); |
mbed_official | 76:aeb1df146756 | 1075 | OB->WRP01 = tmp1; |
mbed_official | 76:aeb1df146756 | 1076 | |
mbed_official | 76:aeb1df146756 | 1077 | tmp2 = (uint32_t)((~WRP23_Data) << 16)|(WRP23_Data); |
mbed_official | 76:aeb1df146756 | 1078 | OB->WRP23 = tmp2; |
mbed_official | 76:aeb1df146756 | 1079 | } |
mbed_official | 76:aeb1df146756 | 1080 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1081 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1082 | } |
mbed_official | 76:aeb1df146756 | 1083 | |
mbed_official | 76:aeb1df146756 | 1084 | /* Return the write protection operation Status */ |
mbed_official | 76:aeb1df146756 | 1085 | return status; |
mbed_official | 76:aeb1df146756 | 1086 | } |
mbed_official | 76:aeb1df146756 | 1087 | |
mbed_official | 76:aeb1df146756 | 1088 | /** |
mbed_official | 76:aeb1df146756 | 1089 | * @brief Write protects the desired pages of the second 128KB of the Flash. |
mbed_official | 76:aeb1df146756 | 1090 | * @note This function can be used only for STM32L1XX_HD and STM32L1XX_MDP |
mbed_official | 76:aeb1df146756 | 1091 | * density devices. |
mbed_official | 76:aeb1df146756 | 1092 | * @param OB_WRP1: specifies the address of the pages to be write protected. |
mbed_official | 76:aeb1df146756 | 1093 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 1094 | * @arg value between OB_WRP_Pages512to527 and OB_WRP_Pages1008to1023 |
mbed_official | 76:aeb1df146756 | 1095 | * @arg OB_WRP_AllPages |
mbed_official | 76:aeb1df146756 | 1096 | * @param NewState: new state of the specified FLASH Pages Wtite protection. |
mbed_official | 76:aeb1df146756 | 1097 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 1098 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 1099 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 1100 | */ |
mbed_official | 76:aeb1df146756 | 1101 | FLASH_Status FLASH_OB_WRP1Config(uint32_t OB_WRP1, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 1102 | { |
mbed_official | 76:aeb1df146756 | 1103 | uint32_t WRP45_Data = 0, WRP67_Data = 0; |
mbed_official | 76:aeb1df146756 | 1104 | |
mbed_official | 76:aeb1df146756 | 1105 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1106 | uint32_t tmp1 = 0, tmp2 = 0; |
mbed_official | 76:aeb1df146756 | 1107 | |
mbed_official | 76:aeb1df146756 | 1108 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1109 | assert_param(IS_OB_WRP(OB_WRP1)); |
mbed_official | 76:aeb1df146756 | 1110 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 1111 | |
mbed_official | 76:aeb1df146756 | 1112 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1113 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1114 | |
mbed_official | 76:aeb1df146756 | 1115 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 1116 | { |
mbed_official | 76:aeb1df146756 | 1117 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 1118 | { |
mbed_official | 76:aeb1df146756 | 1119 | WRP45_Data = (uint16_t)(((OB_WRP1 & WRP45_MASK) | OB->WRP45)); |
mbed_official | 76:aeb1df146756 | 1120 | WRP67_Data = (uint16_t)((((OB_WRP1 & WRP67_MASK)>>16 | OB->WRP67))); |
mbed_official | 76:aeb1df146756 | 1121 | tmp1 = (uint32_t)(~(WRP45_Data) << 16)|(WRP45_Data); |
mbed_official | 76:aeb1df146756 | 1122 | OB->WRP45 = tmp1; |
mbed_official | 76:aeb1df146756 | 1123 | |
mbed_official | 76:aeb1df146756 | 1124 | tmp2 = (uint32_t)(~(WRP67_Data) << 16)|(WRP67_Data); |
mbed_official | 76:aeb1df146756 | 1125 | OB->WRP67 = tmp2; |
mbed_official | 76:aeb1df146756 | 1126 | } |
mbed_official | 76:aeb1df146756 | 1127 | |
mbed_official | 76:aeb1df146756 | 1128 | else |
mbed_official | 76:aeb1df146756 | 1129 | { |
mbed_official | 76:aeb1df146756 | 1130 | WRP45_Data = (uint16_t)(~OB_WRP1 & (WRP45_MASK & OB->WRP45)); |
mbed_official | 76:aeb1df146756 | 1131 | WRP67_Data = (uint16_t)((((~OB_WRP1 & WRP67_MASK)>>16 & OB->WRP67))); |
mbed_official | 76:aeb1df146756 | 1132 | |
mbed_official | 76:aeb1df146756 | 1133 | tmp1 = (uint32_t)((~WRP45_Data) << 16)|(WRP45_Data); |
mbed_official | 76:aeb1df146756 | 1134 | OB->WRP45 = tmp1; |
mbed_official | 76:aeb1df146756 | 1135 | |
mbed_official | 76:aeb1df146756 | 1136 | tmp2 = (uint32_t)((~WRP67_Data) << 16)|(WRP67_Data); |
mbed_official | 76:aeb1df146756 | 1137 | OB->WRP67 = tmp2; |
mbed_official | 76:aeb1df146756 | 1138 | } |
mbed_official | 76:aeb1df146756 | 1139 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1140 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1141 | } |
mbed_official | 76:aeb1df146756 | 1142 | |
mbed_official | 76:aeb1df146756 | 1143 | /* Return the write protection operation Status */ |
mbed_official | 76:aeb1df146756 | 1144 | return status; |
mbed_official | 76:aeb1df146756 | 1145 | } |
mbed_official | 76:aeb1df146756 | 1146 | |
mbed_official | 76:aeb1df146756 | 1147 | /** |
mbed_official | 76:aeb1df146756 | 1148 | * @brief Write protects the desired pages of the third 128KB of the Flash. |
mbed_official | 76:aeb1df146756 | 1149 | * @note This function can be used only for STM32L1XX_HD density devices. |
mbed_official | 76:aeb1df146756 | 1150 | * @param OB_WRP2: specifies the address of the pages to be write protected. |
mbed_official | 76:aeb1df146756 | 1151 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 1152 | * @arg value between OB_WRP_Pages1024to1039 and OB_WRP_Pages1520to1535 |
mbed_official | 76:aeb1df146756 | 1153 | * @arg OB_WRP_AllPages |
mbed_official | 76:aeb1df146756 | 1154 | * @param NewState: new state of the specified FLASH Pages Wtite protection. |
mbed_official | 76:aeb1df146756 | 1155 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 1156 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 1157 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 1158 | */ |
mbed_official | 76:aeb1df146756 | 1159 | FLASH_Status FLASH_OB_WRP2Config(uint32_t OB_WRP2, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 1160 | { |
mbed_official | 76:aeb1df146756 | 1161 | uint32_t WRP89_Data = 0, WRP1011_Data = 0; |
mbed_official | 76:aeb1df146756 | 1162 | |
mbed_official | 76:aeb1df146756 | 1163 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1164 | uint32_t tmp1 = 0, tmp2 = 0; |
mbed_official | 76:aeb1df146756 | 1165 | |
mbed_official | 76:aeb1df146756 | 1166 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1167 | assert_param(IS_OB_WRP(OB_WRP2)); |
mbed_official | 76:aeb1df146756 | 1168 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 1169 | |
mbed_official | 76:aeb1df146756 | 1170 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1171 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1172 | |
mbed_official | 76:aeb1df146756 | 1173 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 1174 | { |
mbed_official | 76:aeb1df146756 | 1175 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 1176 | { |
mbed_official | 76:aeb1df146756 | 1177 | WRP89_Data = (uint16_t)(((OB_WRP2 & WRP89_MASK) | OB->WRP89)); |
mbed_official | 76:aeb1df146756 | 1178 | WRP1011_Data = (uint16_t)((((OB_WRP2 & WRP1011_MASK)>>16 | OB->WRP1011))); |
mbed_official | 76:aeb1df146756 | 1179 | tmp1 = (uint32_t)(~(WRP89_Data) << 16)|(WRP89_Data); |
mbed_official | 76:aeb1df146756 | 1180 | OB->WRP89 = tmp1; |
mbed_official | 76:aeb1df146756 | 1181 | |
mbed_official | 76:aeb1df146756 | 1182 | tmp2 = (uint32_t)(~(WRP1011_Data) << 16)|(WRP1011_Data); |
mbed_official | 76:aeb1df146756 | 1183 | OB->WRP1011 = tmp2; |
mbed_official | 76:aeb1df146756 | 1184 | } |
mbed_official | 76:aeb1df146756 | 1185 | |
mbed_official | 76:aeb1df146756 | 1186 | else |
mbed_official | 76:aeb1df146756 | 1187 | { |
mbed_official | 76:aeb1df146756 | 1188 | WRP89_Data = (uint16_t)(~OB_WRP2 & (WRP89_MASK & OB->WRP89)); |
mbed_official | 76:aeb1df146756 | 1189 | WRP1011_Data = (uint16_t)((((~OB_WRP2 & WRP1011_MASK)>>16 & OB->WRP1011))); |
mbed_official | 76:aeb1df146756 | 1190 | |
mbed_official | 76:aeb1df146756 | 1191 | tmp1 = (uint32_t)((~WRP89_Data) << 16)|(WRP89_Data); |
mbed_official | 76:aeb1df146756 | 1192 | OB->WRP89 = tmp1; |
mbed_official | 76:aeb1df146756 | 1193 | |
mbed_official | 76:aeb1df146756 | 1194 | tmp2 = (uint32_t)((~WRP1011_Data) << 16)|(WRP1011_Data); |
mbed_official | 76:aeb1df146756 | 1195 | OB->WRP1011 = tmp2; |
mbed_official | 76:aeb1df146756 | 1196 | } |
mbed_official | 76:aeb1df146756 | 1197 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1198 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1199 | } |
mbed_official | 76:aeb1df146756 | 1200 | |
mbed_official | 76:aeb1df146756 | 1201 | /* Return the write protection operation Status */ |
mbed_official | 76:aeb1df146756 | 1202 | return status; |
mbed_official | 76:aeb1df146756 | 1203 | } |
mbed_official | 76:aeb1df146756 | 1204 | |
mbed_official | 76:aeb1df146756 | 1205 | /** |
mbed_official | 76:aeb1df146756 | 1206 | * @brief Enables or disables the read out protection. |
mbed_official | 76:aeb1df146756 | 1207 | * @note To correctly run this function, the FLASH_OB_Unlock() function |
mbed_official | 76:aeb1df146756 | 1208 | * must be called before. |
mbed_official | 76:aeb1df146756 | 1209 | * @param FLASH_ReadProtection_Level: specifies the read protection level. |
mbed_official | 76:aeb1df146756 | 1210 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 1211 | * @arg OB_RDP_Level_0: No protection |
mbed_official | 76:aeb1df146756 | 1212 | * @arg OB_RDP_Level_1: Read protection of the memory |
mbed_official | 76:aeb1df146756 | 1213 | * @arg OB_RDP_Level_2: Chip protection |
mbed_official | 76:aeb1df146756 | 1214 | * |
mbed_official | 76:aeb1df146756 | 1215 | * !!!Warning!!! When enabling OB_RDP_Level_2 it's no more possible to go back to level 1 or 0 |
mbed_official | 76:aeb1df146756 | 1216 | * |
mbed_official | 76:aeb1df146756 | 1217 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 1218 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 1219 | */ |
mbed_official | 76:aeb1df146756 | 1220 | FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP) |
mbed_official | 76:aeb1df146756 | 1221 | { |
mbed_official | 76:aeb1df146756 | 1222 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1223 | uint8_t tmp1 = 0; |
mbed_official | 76:aeb1df146756 | 1224 | uint32_t tmp2 = 0; |
mbed_official | 76:aeb1df146756 | 1225 | |
mbed_official | 76:aeb1df146756 | 1226 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1227 | assert_param(IS_OB_RDP(OB_RDP)); |
mbed_official | 76:aeb1df146756 | 1228 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1229 | |
mbed_official | 76:aeb1df146756 | 1230 | /* calculate the option byte to write */ |
mbed_official | 76:aeb1df146756 | 1231 | tmp1 = (uint8_t)(~(OB_RDP )); |
mbed_official | 76:aeb1df146756 | 1232 | tmp2 = (uint32_t)(((uint32_t)((uint32_t)(tmp1) << 16)) | ((uint32_t)OB_RDP)); |
mbed_official | 76:aeb1df146756 | 1233 | |
mbed_official | 76:aeb1df146756 | 1234 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 1235 | { |
mbed_official | 76:aeb1df146756 | 1236 | /* program read protection level */ |
mbed_official | 76:aeb1df146756 | 1237 | OB->RDP = tmp2; |
mbed_official | 76:aeb1df146756 | 1238 | } |
mbed_official | 76:aeb1df146756 | 1239 | |
mbed_official | 76:aeb1df146756 | 1240 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1241 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1242 | |
mbed_official | 76:aeb1df146756 | 1243 | /* Return the Read protection operation Status */ |
mbed_official | 76:aeb1df146756 | 1244 | return status; |
mbed_official | 76:aeb1df146756 | 1245 | } |
mbed_official | 76:aeb1df146756 | 1246 | |
mbed_official | 76:aeb1df146756 | 1247 | /** |
mbed_official | 76:aeb1df146756 | 1248 | * @brief Enables or disables the read/write protection (PCROP) of the desired |
mbed_official | 76:aeb1df146756 | 1249 | * sectors, for the first 128KB of the Flash. |
mbed_official | 76:aeb1df146756 | 1250 | * @note This function can be used only for STM32L1XX_MDP devices |
mbed_official | 76:aeb1df146756 | 1251 | * @param OB_WRP: specifies the address of the pages to be write protected. |
mbed_official | 76:aeb1df146756 | 1252 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 1253 | * @arg value between OB_WRP_Pages0to15 and OB_WRP_Pages496to511 |
mbed_official | 76:aeb1df146756 | 1254 | * @arg OB_WRP_AllPages |
mbed_official | 76:aeb1df146756 | 1255 | * @param NewState: new state of the specified FLASH Pages Write protection. |
mbed_official | 76:aeb1df146756 | 1256 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 1257 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 1258 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 1259 | */ |
mbed_official | 76:aeb1df146756 | 1260 | FLASH_Status FLASH_OB_PCROPConfig(uint32_t OB_WRP, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 1261 | { |
mbed_official | 76:aeb1df146756 | 1262 | uint32_t WRP01_Data = 0, WRP23_Data = 0; |
mbed_official | 76:aeb1df146756 | 1263 | |
mbed_official | 76:aeb1df146756 | 1264 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1265 | uint32_t tmp1 = 0, tmp2 = 0; |
mbed_official | 76:aeb1df146756 | 1266 | |
mbed_official | 76:aeb1df146756 | 1267 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1268 | assert_param(IS_OB_WRP(OB_WRP)); |
mbed_official | 76:aeb1df146756 | 1269 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 1270 | |
mbed_official | 76:aeb1df146756 | 1271 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1272 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1273 | |
mbed_official | 76:aeb1df146756 | 1274 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 1275 | { |
mbed_official | 76:aeb1df146756 | 1276 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 1277 | { |
mbed_official | 76:aeb1df146756 | 1278 | WRP01_Data = (uint16_t)(~OB_WRP & (WRP01_MASK & OB->WRP01)); |
mbed_official | 76:aeb1df146756 | 1279 | WRP23_Data = (uint16_t)((((~OB_WRP & WRP23_MASK)>>16 & OB->WRP23))); |
mbed_official | 76:aeb1df146756 | 1280 | |
mbed_official | 76:aeb1df146756 | 1281 | tmp1 = (uint32_t)((~WRP01_Data) << 16)|(WRP01_Data); |
mbed_official | 76:aeb1df146756 | 1282 | OB->WRP01 = tmp1; |
mbed_official | 76:aeb1df146756 | 1283 | |
mbed_official | 76:aeb1df146756 | 1284 | tmp2 = (uint32_t)((~WRP23_Data) << 16)|(WRP23_Data); |
mbed_official | 76:aeb1df146756 | 1285 | OB->WRP23 = tmp2; |
mbed_official | 76:aeb1df146756 | 1286 | |
mbed_official | 76:aeb1df146756 | 1287 | } |
mbed_official | 76:aeb1df146756 | 1288 | |
mbed_official | 76:aeb1df146756 | 1289 | else |
mbed_official | 76:aeb1df146756 | 1290 | { |
mbed_official | 76:aeb1df146756 | 1291 | WRP01_Data = (uint16_t)((OB_WRP & WRP01_MASK) | OB->WRP01); |
mbed_official | 76:aeb1df146756 | 1292 | WRP23_Data = (uint16_t)(((OB_WRP & WRP23_MASK) >> 16) | OB->WRP23); |
mbed_official | 76:aeb1df146756 | 1293 | |
mbed_official | 76:aeb1df146756 | 1294 | tmp1 = (uint32_t)(~(WRP01_Data) << 16)|(WRP01_Data); |
mbed_official | 76:aeb1df146756 | 1295 | OB->WRP01 = tmp1; |
mbed_official | 76:aeb1df146756 | 1296 | |
mbed_official | 76:aeb1df146756 | 1297 | tmp2 = (uint32_t)(~(WRP23_Data) << 16)|(WRP23_Data); |
mbed_official | 76:aeb1df146756 | 1298 | OB->WRP23 = tmp2; |
mbed_official | 76:aeb1df146756 | 1299 | |
mbed_official | 76:aeb1df146756 | 1300 | } |
mbed_official | 76:aeb1df146756 | 1301 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1302 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1303 | } |
mbed_official | 76:aeb1df146756 | 1304 | |
mbed_official | 76:aeb1df146756 | 1305 | /* Return the write protection operation Status */ |
mbed_official | 76:aeb1df146756 | 1306 | return status; |
mbed_official | 76:aeb1df146756 | 1307 | } |
mbed_official | 76:aeb1df146756 | 1308 | |
mbed_official | 76:aeb1df146756 | 1309 | /** |
mbed_official | 76:aeb1df146756 | 1310 | * @brief Enables or disables the read/write protection (PCROP) of the desired |
mbed_official | 76:aeb1df146756 | 1311 | * sectors, for the second 128KB of the Flash. |
mbed_official | 76:aeb1df146756 | 1312 | * @note This function can be used only for STM32L1XX_MDP devices |
mbed_official | 76:aeb1df146756 | 1313 | * @param OB_WRP1: specifies the address of the pages to be write protected. |
mbed_official | 76:aeb1df146756 | 1314 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 1315 | * @arg value between OB_WRP_Pages512to527 and OB_WRP_Pages1008to1023 |
mbed_official | 76:aeb1df146756 | 1316 | * @arg OB_WRP_AllPages |
mbed_official | 76:aeb1df146756 | 1317 | * @param NewState: new state of the specified FLASH Pages Write protection. |
mbed_official | 76:aeb1df146756 | 1318 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 1319 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 1320 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 1321 | */ |
mbed_official | 76:aeb1df146756 | 1322 | FLASH_Status FLASH_OB_PCROP1Config(uint32_t OB_WRP1, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 1323 | { |
mbed_official | 76:aeb1df146756 | 1324 | uint32_t WRP45_Data = 0, WRP67_Data = 0; |
mbed_official | 76:aeb1df146756 | 1325 | |
mbed_official | 76:aeb1df146756 | 1326 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1327 | uint32_t tmp1 = 0, tmp2 = 0; |
mbed_official | 76:aeb1df146756 | 1328 | |
mbed_official | 76:aeb1df146756 | 1329 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1330 | assert_param(IS_OB_WRP(OB_WRP1)); |
mbed_official | 76:aeb1df146756 | 1331 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 1332 | |
mbed_official | 76:aeb1df146756 | 1333 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1334 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1335 | |
mbed_official | 76:aeb1df146756 | 1336 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 1337 | { |
mbed_official | 76:aeb1df146756 | 1338 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 1339 | { |
mbed_official | 76:aeb1df146756 | 1340 | WRP45_Data = (uint16_t)(~OB_WRP1 & (WRP45_MASK & OB->WRP45)); |
mbed_official | 76:aeb1df146756 | 1341 | WRP67_Data = (uint16_t)((((~OB_WRP1 & WRP67_MASK)>>16 & OB->WRP67))); |
mbed_official | 76:aeb1df146756 | 1342 | |
mbed_official | 76:aeb1df146756 | 1343 | tmp1 = (uint32_t)((~WRP45_Data) << 16)|(WRP45_Data); |
mbed_official | 76:aeb1df146756 | 1344 | OB->WRP45 = tmp1; |
mbed_official | 76:aeb1df146756 | 1345 | |
mbed_official | 76:aeb1df146756 | 1346 | tmp2 = (uint32_t)((~WRP67_Data) << 16)|(WRP67_Data); |
mbed_official | 76:aeb1df146756 | 1347 | OB->WRP67 = tmp2; |
mbed_official | 76:aeb1df146756 | 1348 | } |
mbed_official | 76:aeb1df146756 | 1349 | else |
mbed_official | 76:aeb1df146756 | 1350 | { |
mbed_official | 76:aeb1df146756 | 1351 | WRP45_Data = (uint16_t)((OB_WRP1 & WRP45_MASK) | OB->WRP45); |
mbed_official | 76:aeb1df146756 | 1352 | WRP67_Data = (uint16_t)(((OB_WRP1 & WRP67_MASK)>>16) | OB->WRP67); |
mbed_official | 76:aeb1df146756 | 1353 | tmp1 = (uint32_t)(~(WRP45_Data) << 16)|(WRP45_Data); |
mbed_official | 76:aeb1df146756 | 1354 | OB->WRP45 = tmp1; |
mbed_official | 76:aeb1df146756 | 1355 | |
mbed_official | 76:aeb1df146756 | 1356 | tmp2 = (uint32_t)(~(WRP67_Data) << 16)|(WRP67_Data); |
mbed_official | 76:aeb1df146756 | 1357 | OB->WRP67 = tmp2; |
mbed_official | 76:aeb1df146756 | 1358 | } |
mbed_official | 76:aeb1df146756 | 1359 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1360 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1361 | } |
mbed_official | 76:aeb1df146756 | 1362 | |
mbed_official | 76:aeb1df146756 | 1363 | /* Return the write protection operation Status */ |
mbed_official | 76:aeb1df146756 | 1364 | return status; |
mbed_official | 76:aeb1df146756 | 1365 | } |
mbed_official | 76:aeb1df146756 | 1366 | |
mbed_official | 76:aeb1df146756 | 1367 | /** |
mbed_official | 76:aeb1df146756 | 1368 | * @brief Select the Protection Mode (SPRMOD). |
mbed_official | 76:aeb1df146756 | 1369 | * @note This function can be used only for STM32L1XX_MDP devices |
mbed_official | 76:aeb1df146756 | 1370 | * @note Once SPRMOD bit is active, unprotection of a protected sector is not possible |
mbed_official | 76:aeb1df146756 | 1371 | * @note Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag |
mbed_official | 76:aeb1df146756 | 1372 | * @param OB_PcROP: Select the Protection Mode of nWPRi bits. |
mbed_official | 76:aeb1df146756 | 1373 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 1374 | * @arg OB_PcROP_Enable: nWRPi control the read&write protection (PcROP) of respective user sectors. |
mbed_official | 76:aeb1df146756 | 1375 | * @arg OB_PcROP_Disable: nWRPi control the write protection of respective user sectors. |
mbed_official | 76:aeb1df146756 | 1376 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 1377 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 1378 | */ |
mbed_official | 76:aeb1df146756 | 1379 | FLASH_Status FLASH_OB_PCROPSelectionConfig(uint16_t OB_PcROP) |
mbed_official | 76:aeb1df146756 | 1380 | { |
mbed_official | 76:aeb1df146756 | 1381 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1382 | uint16_t tmp1 = 0; |
mbed_official | 76:aeb1df146756 | 1383 | uint32_t tmp2 = 0; |
mbed_official | 76:aeb1df146756 | 1384 | uint8_t optiontmp = 0; |
mbed_official | 76:aeb1df146756 | 1385 | uint16_t optiontmp2 = 0; |
mbed_official | 76:aeb1df146756 | 1386 | |
mbed_official | 76:aeb1df146756 | 1387 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1388 | assert_param(IS_OB_PCROP_SELECT(OB_PcROP)); |
mbed_official | 76:aeb1df146756 | 1389 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1390 | |
mbed_official | 76:aeb1df146756 | 1391 | /* Mask RDP Byte */ |
mbed_official | 76:aeb1df146756 | 1392 | optiontmp = (uint8_t)(*(__IO uint8_t *)(OB_BASE)); |
mbed_official | 76:aeb1df146756 | 1393 | |
mbed_official | 76:aeb1df146756 | 1394 | /* Update Option Byte */ |
mbed_official | 76:aeb1df146756 | 1395 | optiontmp2 = (uint16_t)(OB_PcROP | optiontmp); |
mbed_official | 76:aeb1df146756 | 1396 | |
mbed_official | 76:aeb1df146756 | 1397 | |
mbed_official | 76:aeb1df146756 | 1398 | /* calculate the option byte to write */ |
mbed_official | 76:aeb1df146756 | 1399 | tmp1 = (uint16_t)(~(optiontmp2 )); |
mbed_official | 76:aeb1df146756 | 1400 | tmp2 = (uint32_t)(((uint32_t)((uint32_t)(tmp1) << 16)) | ((uint32_t)optiontmp2)); |
mbed_official | 76:aeb1df146756 | 1401 | |
mbed_official | 76:aeb1df146756 | 1402 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 1403 | { |
mbed_official | 76:aeb1df146756 | 1404 | /* program PCRop */ |
mbed_official | 76:aeb1df146756 | 1405 | OB->RDP = tmp2; |
mbed_official | 76:aeb1df146756 | 1406 | } |
mbed_official | 76:aeb1df146756 | 1407 | |
mbed_official | 76:aeb1df146756 | 1408 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1409 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1410 | |
mbed_official | 76:aeb1df146756 | 1411 | /* Return the Read protection operation Status */ |
mbed_official | 76:aeb1df146756 | 1412 | return status; |
mbed_official | 76:aeb1df146756 | 1413 | } |
mbed_official | 76:aeb1df146756 | 1414 | |
mbed_official | 76:aeb1df146756 | 1415 | /** |
mbed_official | 76:aeb1df146756 | 1416 | * @brief Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY. |
mbed_official | 76:aeb1df146756 | 1417 | * @param OB_IWDG: Selects the WDG mode. |
mbed_official | 76:aeb1df146756 | 1418 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 1419 | * @arg OB_IWDG_SW: Software WDG selected |
mbed_official | 76:aeb1df146756 | 1420 | * @arg OB_IWDG_HW: Hardware WDG selected |
mbed_official | 76:aeb1df146756 | 1421 | * @param OB_STOP: Reset event when entering STOP mode. |
mbed_official | 76:aeb1df146756 | 1422 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 1423 | * @arg OB_STOP_NoRST: No reset generated when entering in STOP |
mbed_official | 76:aeb1df146756 | 1424 | * @arg OB_STOP_RST: Reset generated when entering in STOP |
mbed_official | 76:aeb1df146756 | 1425 | * @param OB_STDBY: Reset event when entering Standby mode. |
mbed_official | 76:aeb1df146756 | 1426 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 1427 | * @arg OB_STDBY_NoRST: No reset generated when entering in STANDBY |
mbed_official | 76:aeb1df146756 | 1428 | * @arg OB_STDBY_RST: Reset generated when entering in STANDBY |
mbed_official | 76:aeb1df146756 | 1429 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 1430 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 1431 | */ |
mbed_official | 76:aeb1df146756 | 1432 | FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY) |
mbed_official | 76:aeb1df146756 | 1433 | { |
mbed_official | 76:aeb1df146756 | 1434 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1435 | uint32_t tmp = 0, tmp1 = 0; |
mbed_official | 76:aeb1df146756 | 1436 | |
mbed_official | 76:aeb1df146756 | 1437 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1438 | assert_param(IS_OB_IWDG_SOURCE(OB_IWDG)); |
mbed_official | 76:aeb1df146756 | 1439 | assert_param(IS_OB_STOP_SOURCE(OB_STOP)); |
mbed_official | 76:aeb1df146756 | 1440 | assert_param(IS_OB_STDBY_SOURCE(OB_STDBY)); |
mbed_official | 76:aeb1df146756 | 1441 | |
mbed_official | 76:aeb1df146756 | 1442 | /* Get the User Option byte register */ |
mbed_official | 76:aeb1df146756 | 1443 | tmp1 = (FLASH->OBR & 0x000F0000) >> 16; |
mbed_official | 76:aeb1df146756 | 1444 | |
mbed_official | 76:aeb1df146756 | 1445 | /* Calculate the user option byte to write */ |
mbed_official | 76:aeb1df146756 | 1446 | tmp = (uint32_t)(((uint32_t)~((uint32_t)((uint32_t)(OB_IWDG) | (uint32_t)(OB_STOP) | (uint32_t)(OB_STDBY) | tmp1))) << ((uint32_t)0x10)); |
mbed_official | 76:aeb1df146756 | 1447 | tmp |= ((uint32_t)(OB_IWDG) | ((uint32_t)OB_STOP) | (uint32_t)(OB_STDBY) | tmp1); |
mbed_official | 76:aeb1df146756 | 1448 | |
mbed_official | 76:aeb1df146756 | 1449 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1450 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1451 | |
mbed_official | 76:aeb1df146756 | 1452 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 1453 | { |
mbed_official | 76:aeb1df146756 | 1454 | /* Write the User Option Byte */ |
mbed_official | 76:aeb1df146756 | 1455 | OB->USER = tmp; |
mbed_official | 76:aeb1df146756 | 1456 | } |
mbed_official | 76:aeb1df146756 | 1457 | |
mbed_official | 76:aeb1df146756 | 1458 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1459 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1460 | |
mbed_official | 76:aeb1df146756 | 1461 | /* Return the Option Byte program Status */ |
mbed_official | 76:aeb1df146756 | 1462 | return status; |
mbed_official | 76:aeb1df146756 | 1463 | } |
mbed_official | 76:aeb1df146756 | 1464 | |
mbed_official | 76:aeb1df146756 | 1465 | /** |
mbed_official | 76:aeb1df146756 | 1466 | * @brief Programs the FLASH brownout reset threshold level Option Byte. |
mbed_official | 76:aeb1df146756 | 1467 | * @param OB_BOR: Selects the brownout reset threshold level. |
mbed_official | 76:aeb1df146756 | 1468 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 1469 | * @arg OB_BOR_OFF: BOR is disabled at power down, the reset is asserted when the VDD |
mbed_official | 76:aeb1df146756 | 1470 | * power supply reaches the PDR(Power Down Reset) threshold (1.5V) |
mbed_official | 76:aeb1df146756 | 1471 | * @arg OB_BOR_LEVEL1: BOR Reset threshold levels for 1.7V - 1.8V VDD power supply |
mbed_official | 76:aeb1df146756 | 1472 | * @arg OB_BOR_LEVEL2: BOR Reset threshold levels for 1.9V - 2.0V VDD power supply |
mbed_official | 76:aeb1df146756 | 1473 | * @arg OB_BOR_LEVEL3: BOR Reset threshold levels for 2.3V - 2.4V VDD power supply |
mbed_official | 76:aeb1df146756 | 1474 | * @arg OB_BOR_LEVEL4: BOR Reset threshold levels for 2.55V - 2.65V VDD power supply |
mbed_official | 76:aeb1df146756 | 1475 | * @arg OB_BOR_LEVEL5: BOR Reset threshold levels for 2.8V - 2.9V VDD power supply |
mbed_official | 76:aeb1df146756 | 1476 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 1477 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 1478 | */ |
mbed_official | 76:aeb1df146756 | 1479 | FLASH_Status FLASH_OB_BORConfig(uint8_t OB_BOR) |
mbed_official | 76:aeb1df146756 | 1480 | { |
mbed_official | 76:aeb1df146756 | 1481 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1482 | uint32_t tmp = 0, tmp1 = 0; |
mbed_official | 76:aeb1df146756 | 1483 | |
mbed_official | 76:aeb1df146756 | 1484 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1485 | assert_param(IS_OB_BOR_LEVEL(OB_BOR)); |
mbed_official | 76:aeb1df146756 | 1486 | |
mbed_official | 76:aeb1df146756 | 1487 | /* Get the User Option byte register */ |
mbed_official | 76:aeb1df146756 | 1488 | tmp1 = (FLASH->OBR & 0x00F00000) >> 16; |
mbed_official | 76:aeb1df146756 | 1489 | |
mbed_official | 76:aeb1df146756 | 1490 | /* Calculate the option byte to write */ |
mbed_official | 76:aeb1df146756 | 1491 | tmp = (uint32_t)~(OB_BOR | tmp1)<<16; |
mbed_official | 76:aeb1df146756 | 1492 | tmp |= (OB_BOR | tmp1); |
mbed_official | 76:aeb1df146756 | 1493 | |
mbed_official | 76:aeb1df146756 | 1494 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1495 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1496 | |
mbed_official | 76:aeb1df146756 | 1497 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 1498 | { |
mbed_official | 76:aeb1df146756 | 1499 | /* Write the BOR Option Byte */ |
mbed_official | 76:aeb1df146756 | 1500 | OB->USER = tmp; |
mbed_official | 76:aeb1df146756 | 1501 | } |
mbed_official | 76:aeb1df146756 | 1502 | |
mbed_official | 76:aeb1df146756 | 1503 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1504 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1505 | |
mbed_official | 76:aeb1df146756 | 1506 | /* Return the Option Byte program Status */ |
mbed_official | 76:aeb1df146756 | 1507 | return status; |
mbed_official | 76:aeb1df146756 | 1508 | } |
mbed_official | 76:aeb1df146756 | 1509 | |
mbed_official | 76:aeb1df146756 | 1510 | /** |
mbed_official | 76:aeb1df146756 | 1511 | * @brief Configures to boot from Bank1 or Bank2. |
mbed_official | 76:aeb1df146756 | 1512 | * @note This function can be used only for STM32L1XX_HD density devices. |
mbed_official | 76:aeb1df146756 | 1513 | * @param OB_BOOT: select the FLASH Bank to boot from. |
mbed_official | 76:aeb1df146756 | 1514 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 1515 | * @arg OB_BOOT_BANK2: At startup, if boot pins are set in boot from user Flash |
mbed_official | 76:aeb1df146756 | 1516 | * position and this parameter is selected the device will boot from Bank2 or Bank1, |
mbed_official | 76:aeb1df146756 | 1517 | * depending on the activation of the bank. The active banks are checked in |
mbed_official | 76:aeb1df146756 | 1518 | * the following order: Bank2, followed by Bank1. |
mbed_official | 76:aeb1df146756 | 1519 | * The active bank is recognized by the value programmed at the base address |
mbed_official | 76:aeb1df146756 | 1520 | * of the respective bank (corresponding to the initial stack pointer value |
mbed_official | 76:aeb1df146756 | 1521 | * in the interrupt vector table). |
mbed_official | 76:aeb1df146756 | 1522 | * @arg OB_BOOT_BANK1: At startup, if boot pins are set in boot from user Flash |
mbed_official | 76:aeb1df146756 | 1523 | * position and this parameter is selected the device will boot from Bank1(Default). |
mbed_official | 76:aeb1df146756 | 1524 | * For more information, please refer to AN2606 from www.st.com. |
mbed_official | 76:aeb1df146756 | 1525 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 1526 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 1527 | */ |
mbed_official | 76:aeb1df146756 | 1528 | FLASH_Status FLASH_OB_BootConfig(uint8_t OB_BOOT) |
mbed_official | 76:aeb1df146756 | 1529 | { |
mbed_official | 76:aeb1df146756 | 1530 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1531 | uint32_t tmp = 0, tmp1 = 0; |
mbed_official | 76:aeb1df146756 | 1532 | |
mbed_official | 76:aeb1df146756 | 1533 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1534 | assert_param(IS_OB_BOOT_BANK(OB_BOOT)); |
mbed_official | 76:aeb1df146756 | 1535 | |
mbed_official | 76:aeb1df146756 | 1536 | /* Get the User Option byte register */ |
mbed_official | 76:aeb1df146756 | 1537 | tmp1 = (FLASH->OBR & 0x007F0000) >> 16; |
mbed_official | 76:aeb1df146756 | 1538 | |
mbed_official | 76:aeb1df146756 | 1539 | /* Calculate the option byte to write */ |
mbed_official | 76:aeb1df146756 | 1540 | tmp = (uint32_t)~(OB_BOOT | tmp1)<<16; |
mbed_official | 76:aeb1df146756 | 1541 | tmp |= (OB_BOOT | tmp1); |
mbed_official | 76:aeb1df146756 | 1542 | |
mbed_official | 76:aeb1df146756 | 1543 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1544 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1545 | |
mbed_official | 76:aeb1df146756 | 1546 | if(status == FLASH_COMPLETE) |
mbed_official | 76:aeb1df146756 | 1547 | { |
mbed_official | 76:aeb1df146756 | 1548 | /* Write the BOOT Option Byte */ |
mbed_official | 76:aeb1df146756 | 1549 | OB->USER = tmp; |
mbed_official | 76:aeb1df146756 | 1550 | } |
mbed_official | 76:aeb1df146756 | 1551 | |
mbed_official | 76:aeb1df146756 | 1552 | /* Wait for last operation to be completed */ |
mbed_official | 76:aeb1df146756 | 1553 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 76:aeb1df146756 | 1554 | |
mbed_official | 76:aeb1df146756 | 1555 | /* Return the Option Byte program Status */ |
mbed_official | 76:aeb1df146756 | 1556 | return status; |
mbed_official | 76:aeb1df146756 | 1557 | } |
mbed_official | 76:aeb1df146756 | 1558 | |
mbed_official | 76:aeb1df146756 | 1559 | /** |
mbed_official | 76:aeb1df146756 | 1560 | * @brief Returns the FLASH User Option Bytes values. |
mbed_official | 76:aeb1df146756 | 1561 | * @param None |
mbed_official | 76:aeb1df146756 | 1562 | * @retval The FLASH User Option Bytes. |
mbed_official | 76:aeb1df146756 | 1563 | */ |
mbed_official | 76:aeb1df146756 | 1564 | uint8_t FLASH_OB_GetUser(void) |
mbed_official | 76:aeb1df146756 | 1565 | { |
mbed_official | 76:aeb1df146756 | 1566 | /* Return the User Option Byte */ |
mbed_official | 76:aeb1df146756 | 1567 | return (uint8_t)(FLASH->OBR >> 20); |
mbed_official | 76:aeb1df146756 | 1568 | } |
mbed_official | 76:aeb1df146756 | 1569 | |
mbed_official | 76:aeb1df146756 | 1570 | /** |
mbed_official | 76:aeb1df146756 | 1571 | * @brief Returns the FLASH Write Protection Option Bytes value. |
mbed_official | 76:aeb1df146756 | 1572 | * @param None |
mbed_official | 76:aeb1df146756 | 1573 | * @retval The FLASH Write Protection Option Bytes value. |
mbed_official | 76:aeb1df146756 | 1574 | */ |
mbed_official | 76:aeb1df146756 | 1575 | uint32_t FLASH_OB_GetWRP(void) |
mbed_official | 76:aeb1df146756 | 1576 | { |
mbed_official | 76:aeb1df146756 | 1577 | /* Return the FLASH write protection Register value */ |
mbed_official | 76:aeb1df146756 | 1578 | return (uint32_t)(FLASH->WRPR); |
mbed_official | 76:aeb1df146756 | 1579 | } |
mbed_official | 76:aeb1df146756 | 1580 | |
mbed_official | 76:aeb1df146756 | 1581 | /** |
mbed_official | 76:aeb1df146756 | 1582 | * @brief Returns the FLASH Write Protection Option Bytes value. |
mbed_official | 76:aeb1df146756 | 1583 | * @note This function can be used only for STM32L1XX_HD and STM32L1XX_MDP |
mbed_official | 76:aeb1df146756 | 1584 | * density devices. |
mbed_official | 76:aeb1df146756 | 1585 | * @param None |
mbed_official | 76:aeb1df146756 | 1586 | * @retval The FLASH Write Protection Option Bytes value. |
mbed_official | 76:aeb1df146756 | 1587 | */ |
mbed_official | 76:aeb1df146756 | 1588 | uint32_t FLASH_OB_GetWRP1(void) |
mbed_official | 76:aeb1df146756 | 1589 | { |
mbed_official | 76:aeb1df146756 | 1590 | /* Return the FLASH write protection Register value */ |
mbed_official | 76:aeb1df146756 | 1591 | return (uint32_t)(FLASH->WRPR1); |
mbed_official | 76:aeb1df146756 | 1592 | } |
mbed_official | 76:aeb1df146756 | 1593 | |
mbed_official | 76:aeb1df146756 | 1594 | /** |
mbed_official | 76:aeb1df146756 | 1595 | * @brief Returns the FLASH Write Protection Option Bytes value. |
mbed_official | 76:aeb1df146756 | 1596 | * @note This function can be used only for STM32L1XX_HD density devices. |
mbed_official | 76:aeb1df146756 | 1597 | * @param None |
mbed_official | 76:aeb1df146756 | 1598 | * @retval The FLASH Write Protection Option Bytes value. |
mbed_official | 76:aeb1df146756 | 1599 | */ |
mbed_official | 76:aeb1df146756 | 1600 | uint32_t FLASH_OB_GetWRP2(void) |
mbed_official | 76:aeb1df146756 | 1601 | { |
mbed_official | 76:aeb1df146756 | 1602 | /* Return the FLASH write protection Register value */ |
mbed_official | 76:aeb1df146756 | 1603 | return (uint32_t)(FLASH->WRPR2); |
mbed_official | 76:aeb1df146756 | 1604 | } |
mbed_official | 76:aeb1df146756 | 1605 | |
mbed_official | 76:aeb1df146756 | 1606 | /** |
mbed_official | 76:aeb1df146756 | 1607 | * @brief Checks whether the FLASH Read out Protection Status is set or not. |
mbed_official | 76:aeb1df146756 | 1608 | * @param None |
mbed_official | 76:aeb1df146756 | 1609 | * @retval FLASH ReadOut Protection Status(SET or RESET). |
mbed_official | 76:aeb1df146756 | 1610 | */ |
mbed_official | 76:aeb1df146756 | 1611 | FlagStatus FLASH_OB_GetRDP(void) |
mbed_official | 76:aeb1df146756 | 1612 | { |
mbed_official | 76:aeb1df146756 | 1613 | FlagStatus readstatus = RESET; |
mbed_official | 76:aeb1df146756 | 1614 | |
mbed_official | 76:aeb1df146756 | 1615 | if ((uint8_t)(FLASH->OBR) != (uint8_t)OB_RDP_Level_0) |
mbed_official | 76:aeb1df146756 | 1616 | { |
mbed_official | 76:aeb1df146756 | 1617 | readstatus = SET; |
mbed_official | 76:aeb1df146756 | 1618 | } |
mbed_official | 76:aeb1df146756 | 1619 | else |
mbed_official | 76:aeb1df146756 | 1620 | { |
mbed_official | 76:aeb1df146756 | 1621 | readstatus = RESET; |
mbed_official | 76:aeb1df146756 | 1622 | } |
mbed_official | 76:aeb1df146756 | 1623 | return readstatus; |
mbed_official | 76:aeb1df146756 | 1624 | } |
mbed_official | 76:aeb1df146756 | 1625 | |
mbed_official | 76:aeb1df146756 | 1626 | /** |
mbed_official | 76:aeb1df146756 | 1627 | * @brief Returns the SPRMOD Status. |
mbed_official | 76:aeb1df146756 | 1628 | * @note This function can be used only for STM32L1XX_MDP devices |
mbed_official | 76:aeb1df146756 | 1629 | * @param None |
mbed_official | 76:aeb1df146756 | 1630 | * @retval The SPRMOD Status. |
mbed_official | 76:aeb1df146756 | 1631 | */ |
mbed_official | 76:aeb1df146756 | 1632 | FlagStatus FLASH_OB_GetSPRMOD(void) |
mbed_official | 76:aeb1df146756 | 1633 | { |
mbed_official | 76:aeb1df146756 | 1634 | FlagStatus readstatus = RESET; |
mbed_official | 76:aeb1df146756 | 1635 | uint16_t tmp = 0; |
mbed_official | 76:aeb1df146756 | 1636 | |
mbed_official | 76:aeb1df146756 | 1637 | /* Return the SPRMOD value */ |
mbed_official | 76:aeb1df146756 | 1638 | tmp = (uint16_t)(FLASH->OBR & (uint16_t)(0x0100)); |
mbed_official | 76:aeb1df146756 | 1639 | |
mbed_official | 76:aeb1df146756 | 1640 | if (tmp != (uint16_t)0x0000) |
mbed_official | 76:aeb1df146756 | 1641 | { |
mbed_official | 76:aeb1df146756 | 1642 | readstatus = SET; |
mbed_official | 76:aeb1df146756 | 1643 | } |
mbed_official | 76:aeb1df146756 | 1644 | else |
mbed_official | 76:aeb1df146756 | 1645 | { |
mbed_official | 76:aeb1df146756 | 1646 | readstatus = RESET; |
mbed_official | 76:aeb1df146756 | 1647 | } |
mbed_official | 76:aeb1df146756 | 1648 | return readstatus; |
mbed_official | 76:aeb1df146756 | 1649 | } |
mbed_official | 76:aeb1df146756 | 1650 | |
mbed_official | 76:aeb1df146756 | 1651 | /** |
mbed_official | 76:aeb1df146756 | 1652 | * @brief Returns the FLASH BOR level. |
mbed_official | 76:aeb1df146756 | 1653 | * @param None |
mbed_official | 76:aeb1df146756 | 1654 | * @retval The FLASH User Option Bytes. |
mbed_official | 76:aeb1df146756 | 1655 | */ |
mbed_official | 76:aeb1df146756 | 1656 | uint8_t FLASH_OB_GetBOR(void) |
mbed_official | 76:aeb1df146756 | 1657 | { |
mbed_official | 76:aeb1df146756 | 1658 | /* Return the BOR level */ |
mbed_official | 76:aeb1df146756 | 1659 | return (uint8_t)((FLASH->OBR & (uint32_t)0x000F0000) >> 16); |
mbed_official | 76:aeb1df146756 | 1660 | } |
mbed_official | 76:aeb1df146756 | 1661 | |
mbed_official | 76:aeb1df146756 | 1662 | /** |
mbed_official | 76:aeb1df146756 | 1663 | * @} |
mbed_official | 76:aeb1df146756 | 1664 | */ |
mbed_official | 76:aeb1df146756 | 1665 | |
mbed_official | 76:aeb1df146756 | 1666 | /** @defgroup FLASH_Group5 Interrupts and flags management functions |
mbed_official | 76:aeb1df146756 | 1667 | * @brief Interrupts and flags management functions |
mbed_official | 76:aeb1df146756 | 1668 | * |
mbed_official | 76:aeb1df146756 | 1669 | @verbatim |
mbed_official | 76:aeb1df146756 | 1670 | ============================================================================== |
mbed_official | 76:aeb1df146756 | 1671 | ##### Interrupts and flags management functions ##### |
mbed_official | 76:aeb1df146756 | 1672 | ============================================================================== |
mbed_official | 76:aeb1df146756 | 1673 | |
mbed_official | 76:aeb1df146756 | 1674 | @endverbatim |
mbed_official | 76:aeb1df146756 | 1675 | * @{ |
mbed_official | 76:aeb1df146756 | 1676 | */ |
mbed_official | 76:aeb1df146756 | 1677 | |
mbed_official | 76:aeb1df146756 | 1678 | /** |
mbed_official | 76:aeb1df146756 | 1679 | * @brief Enables or disables the specified FLASH interrupts. |
mbed_official | 76:aeb1df146756 | 1680 | * @param FLASH_IT: specifies the FLASH interrupt sources to be enabled or |
mbed_official | 76:aeb1df146756 | 1681 | * disabled. |
mbed_official | 76:aeb1df146756 | 1682 | * This parameter can be any combination of the following values: |
mbed_official | 76:aeb1df146756 | 1683 | * @arg FLASH_IT_EOP: FLASH end of programming Interrupt |
mbed_official | 76:aeb1df146756 | 1684 | * @arg FLASH_IT_ERR: FLASH Error Interrupt |
mbed_official | 76:aeb1df146756 | 1685 | * @retval None |
mbed_official | 76:aeb1df146756 | 1686 | */ |
mbed_official | 76:aeb1df146756 | 1687 | void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 1688 | { |
mbed_official | 76:aeb1df146756 | 1689 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1690 | assert_param(IS_FLASH_IT(FLASH_IT)); |
mbed_official | 76:aeb1df146756 | 1691 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 1692 | |
mbed_official | 76:aeb1df146756 | 1693 | if(NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 1694 | { |
mbed_official | 76:aeb1df146756 | 1695 | /* Enable the interrupt sources */ |
mbed_official | 76:aeb1df146756 | 1696 | FLASH->PECR |= FLASH_IT; |
mbed_official | 76:aeb1df146756 | 1697 | } |
mbed_official | 76:aeb1df146756 | 1698 | else |
mbed_official | 76:aeb1df146756 | 1699 | { |
mbed_official | 76:aeb1df146756 | 1700 | /* Disable the interrupt sources */ |
mbed_official | 76:aeb1df146756 | 1701 | FLASH->PECR &= ~(uint32_t)FLASH_IT; |
mbed_official | 76:aeb1df146756 | 1702 | } |
mbed_official | 76:aeb1df146756 | 1703 | } |
mbed_official | 76:aeb1df146756 | 1704 | |
mbed_official | 76:aeb1df146756 | 1705 | /** |
mbed_official | 76:aeb1df146756 | 1706 | * @brief Checks whether the specified FLASH flag is set or not. |
mbed_official | 76:aeb1df146756 | 1707 | * @param FLASH_FLAG: specifies the FLASH flag to check. |
mbed_official | 76:aeb1df146756 | 1708 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 1709 | * @arg FLASH_FLAG_BSY: FLASH write/erase operations in progress flag |
mbed_official | 76:aeb1df146756 | 1710 | * @arg FLASH_FLAG_EOP: FLASH End of Operation flag |
mbed_official | 76:aeb1df146756 | 1711 | * @arg FLASH_FLAG_READY: FLASH Ready flag after low power mode |
mbed_official | 76:aeb1df146756 | 1712 | * @arg FLASH_FLAG_ENDHV: FLASH End of high voltage flag |
mbed_official | 76:aeb1df146756 | 1713 | * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag |
mbed_official | 76:aeb1df146756 | 1714 | * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag |
mbed_official | 76:aeb1df146756 | 1715 | * @arg FLASH_FLAG_SIZERR: FLASH size error flag |
mbed_official | 76:aeb1df146756 | 1716 | * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag |
mbed_official | 76:aeb1df146756 | 1717 | * @arg FLASH_FLAG_OPTVERRUSR: FLASH Option User validity error flag |
mbed_official | 76:aeb1df146756 | 1718 | * @arg FLASH_FLAG_RDERR: FLASH Read protected error flag (available only in STM32L1XX_MDP devices) |
mbed_official | 76:aeb1df146756 | 1719 | * @retval The new state of FLASH_FLAG (SET or RESET). |
mbed_official | 76:aeb1df146756 | 1720 | */ |
mbed_official | 76:aeb1df146756 | 1721 | FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG) |
mbed_official | 76:aeb1df146756 | 1722 | { |
mbed_official | 76:aeb1df146756 | 1723 | FlagStatus bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 1724 | |
mbed_official | 76:aeb1df146756 | 1725 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1726 | assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG)); |
mbed_official | 76:aeb1df146756 | 1727 | |
mbed_official | 76:aeb1df146756 | 1728 | if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET) |
mbed_official | 76:aeb1df146756 | 1729 | { |
mbed_official | 76:aeb1df146756 | 1730 | bitstatus = SET; |
mbed_official | 76:aeb1df146756 | 1731 | } |
mbed_official | 76:aeb1df146756 | 1732 | else |
mbed_official | 76:aeb1df146756 | 1733 | { |
mbed_official | 76:aeb1df146756 | 1734 | bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 1735 | } |
mbed_official | 76:aeb1df146756 | 1736 | /* Return the new state of FLASH_FLAG (SET or RESET) */ |
mbed_official | 76:aeb1df146756 | 1737 | return bitstatus; |
mbed_official | 76:aeb1df146756 | 1738 | } |
mbed_official | 76:aeb1df146756 | 1739 | |
mbed_official | 76:aeb1df146756 | 1740 | /** |
mbed_official | 76:aeb1df146756 | 1741 | * @brief Clears the FLASH's pending flags. |
mbed_official | 76:aeb1df146756 | 1742 | * @param FLASH_FLAG: specifies the FLASH flags to clear. |
mbed_official | 76:aeb1df146756 | 1743 | * This parameter can be any combination of the following values: |
mbed_official | 76:aeb1df146756 | 1744 | * @arg FLASH_FLAG_EOP: FLASH End of Operation flag |
mbed_official | 76:aeb1df146756 | 1745 | * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag |
mbed_official | 76:aeb1df146756 | 1746 | * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag |
mbed_official | 76:aeb1df146756 | 1747 | * @arg FLASH_FLAG_SIZERR: FLASH size error flag |
mbed_official | 76:aeb1df146756 | 1748 | * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag |
mbed_official | 76:aeb1df146756 | 1749 | * @arg FLASH_FLAG_OPTVERRUSR: FLASH Option User validity error flag |
mbed_official | 76:aeb1df146756 | 1750 | * @arg FLASH_FLAG_RDERR: FLASH Read protected error flag (available only in STM32L1XX_MDP devices) |
mbed_official | 76:aeb1df146756 | 1751 | * @retval None |
mbed_official | 76:aeb1df146756 | 1752 | */ |
mbed_official | 76:aeb1df146756 | 1753 | void FLASH_ClearFlag(uint32_t FLASH_FLAG) |
mbed_official | 76:aeb1df146756 | 1754 | { |
mbed_official | 76:aeb1df146756 | 1755 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1756 | assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG)); |
mbed_official | 76:aeb1df146756 | 1757 | |
mbed_official | 76:aeb1df146756 | 1758 | /* Clear the flags */ |
mbed_official | 76:aeb1df146756 | 1759 | FLASH->SR = FLASH_FLAG; |
mbed_official | 76:aeb1df146756 | 1760 | } |
mbed_official | 76:aeb1df146756 | 1761 | |
mbed_official | 76:aeb1df146756 | 1762 | /** |
mbed_official | 76:aeb1df146756 | 1763 | * @brief Returns the FLASH Status. |
mbed_official | 76:aeb1df146756 | 1764 | * @param None |
mbed_official | 76:aeb1df146756 | 1765 | * @retval FLASH Status: The returned value can be: |
mbed_official | 76:aeb1df146756 | 1766 | * FLASH_BUSY, FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP or FLASH_COMPLETE. |
mbed_official | 76:aeb1df146756 | 1767 | */ |
mbed_official | 76:aeb1df146756 | 1768 | FLASH_Status FLASH_GetStatus(void) |
mbed_official | 76:aeb1df146756 | 1769 | { |
mbed_official | 76:aeb1df146756 | 1770 | FLASH_Status FLASHstatus = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1771 | |
mbed_official | 76:aeb1df146756 | 1772 | if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY) |
mbed_official | 76:aeb1df146756 | 1773 | { |
mbed_official | 76:aeb1df146756 | 1774 | FLASHstatus = FLASH_BUSY; |
mbed_official | 76:aeb1df146756 | 1775 | } |
mbed_official | 76:aeb1df146756 | 1776 | else |
mbed_official | 76:aeb1df146756 | 1777 | { |
mbed_official | 76:aeb1df146756 | 1778 | if((FLASH->SR & (uint32_t)FLASH_FLAG_WRPERR)!= (uint32_t)0x00) |
mbed_official | 76:aeb1df146756 | 1779 | { |
mbed_official | 76:aeb1df146756 | 1780 | FLASHstatus = FLASH_ERROR_WRP; |
mbed_official | 76:aeb1df146756 | 1781 | } |
mbed_official | 76:aeb1df146756 | 1782 | else |
mbed_official | 76:aeb1df146756 | 1783 | { |
mbed_official | 76:aeb1df146756 | 1784 | if((FLASH->SR & (uint32_t)0x1E00) != (uint32_t)0x00) |
mbed_official | 76:aeb1df146756 | 1785 | { |
mbed_official | 76:aeb1df146756 | 1786 | FLASHstatus = FLASH_ERROR_PROGRAM; |
mbed_official | 76:aeb1df146756 | 1787 | } |
mbed_official | 76:aeb1df146756 | 1788 | else |
mbed_official | 76:aeb1df146756 | 1789 | { |
mbed_official | 76:aeb1df146756 | 1790 | FLASHstatus = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1791 | } |
mbed_official | 76:aeb1df146756 | 1792 | } |
mbed_official | 76:aeb1df146756 | 1793 | } |
mbed_official | 76:aeb1df146756 | 1794 | /* Return the FLASH Status */ |
mbed_official | 76:aeb1df146756 | 1795 | return FLASHstatus; |
mbed_official | 76:aeb1df146756 | 1796 | } |
mbed_official | 76:aeb1df146756 | 1797 | |
mbed_official | 76:aeb1df146756 | 1798 | |
mbed_official | 76:aeb1df146756 | 1799 | /** |
mbed_official | 76:aeb1df146756 | 1800 | * @brief Waits for a FLASH operation to complete or a TIMEOUT to occur. |
mbed_official | 76:aeb1df146756 | 1801 | * @param Timeout: FLASH programming Timeout. |
mbed_official | 76:aeb1df146756 | 1802 | * @retval FLASH Status: The returned value can be: FLASH_BUSY, |
mbed_official | 76:aeb1df146756 | 1803 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 76:aeb1df146756 | 1804 | */ |
mbed_official | 76:aeb1df146756 | 1805 | FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) |
mbed_official | 76:aeb1df146756 | 1806 | { |
mbed_official | 76:aeb1df146756 | 1807 | __IO FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 76:aeb1df146756 | 1808 | |
mbed_official | 76:aeb1df146756 | 1809 | /* Check for the FLASH Status */ |
mbed_official | 76:aeb1df146756 | 1810 | status = FLASH_GetStatus(); |
mbed_official | 76:aeb1df146756 | 1811 | |
mbed_official | 76:aeb1df146756 | 1812 | /* Wait for a FLASH operation to complete or a TIMEOUT to occur */ |
mbed_official | 76:aeb1df146756 | 1813 | while((status == FLASH_BUSY) && (Timeout != 0x00)) |
mbed_official | 76:aeb1df146756 | 1814 | { |
mbed_official | 76:aeb1df146756 | 1815 | status = FLASH_GetStatus(); |
mbed_official | 76:aeb1df146756 | 1816 | Timeout--; |
mbed_official | 76:aeb1df146756 | 1817 | } |
mbed_official | 76:aeb1df146756 | 1818 | |
mbed_official | 76:aeb1df146756 | 1819 | if(Timeout == 0x00 ) |
mbed_official | 76:aeb1df146756 | 1820 | { |
mbed_official | 76:aeb1df146756 | 1821 | status = FLASH_TIMEOUT; |
mbed_official | 76:aeb1df146756 | 1822 | } |
mbed_official | 76:aeb1df146756 | 1823 | /* Return the operation status */ |
mbed_official | 76:aeb1df146756 | 1824 | return status; |
mbed_official | 76:aeb1df146756 | 1825 | } |
mbed_official | 76:aeb1df146756 | 1826 | |
mbed_official | 76:aeb1df146756 | 1827 | /** |
mbed_official | 76:aeb1df146756 | 1828 | * @} |
mbed_official | 76:aeb1df146756 | 1829 | */ |
mbed_official | 76:aeb1df146756 | 1830 | |
mbed_official | 76:aeb1df146756 | 1831 | /** |
mbed_official | 76:aeb1df146756 | 1832 | * @} |
mbed_official | 76:aeb1df146756 | 1833 | */ |
mbed_official | 76:aeb1df146756 | 1834 | |
mbed_official | 76:aeb1df146756 | 1835 | /** |
mbed_official | 76:aeb1df146756 | 1836 | * @} |
mbed_official | 76:aeb1df146756 | 1837 | */ |
mbed_official | 76:aeb1df146756 | 1838 | |
mbed_official | 76:aeb1df146756 | 1839 | /** |
mbed_official | 76:aeb1df146756 | 1840 | * @} |
mbed_official | 76:aeb1df146756 | 1841 | */ |
mbed_official | 76:aeb1df146756 | 1842 | |
mbed_official | 76:aeb1df146756 | 1843 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |