mbed library sources

Dependents:   bare

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Jan 27 14:30:07 2014 +0000
Revision:
76:aeb1df146756
Child:
106:ced8cbb51063
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd

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

Add NUCLEO_L152RE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 76:aeb1df146756 1 /**
mbed_official 76:aeb1df146756 2 ******************************************************************************
mbed_official 76:aeb1df146756 3 * @file stm32f0xx_flash.c
mbed_official 76:aeb1df146756 4 * @author MCD Application Team
mbed_official 76:aeb1df146756 5 * @version V1.3.0
mbed_official 76:aeb1df146756 6 * @date 16-January-2014
mbed_official 76:aeb1df146756 7 * @brief This file provides firmware functions to manage the following
mbed_official 76:aeb1df146756 8 * functionalities of the FLASH peripheral:
mbed_official 76:aeb1df146756 9 * - FLASH Interface configuration
mbed_official 76:aeb1df146756 10 * - FLASH Memory Programming
mbed_official 76:aeb1df146756 11 * - Option Bytes Programming
mbed_official 76:aeb1df146756 12 * - Interrupts and flags management
mbed_official 76:aeb1df146756 13 *
mbed_official 76:aeb1df146756 14 * @verbatim
mbed_official 76:aeb1df146756 15 ===============================================================================
mbed_official 76:aeb1df146756 16 ##### How to use this driver #####
mbed_official 76:aeb1df146756 17 ===============================================================================
mbed_official 76:aeb1df146756 18 [..] This driver provides functions to configure and program the Flash
mbed_official 76:aeb1df146756 19 memory of all STM32F0xx devices. These functions are split in 4 groups
mbed_official 76:aeb1df146756 20 (#) FLASH Interface configuration functions: this group includes the
mbed_official 76:aeb1df146756 21 management of following features:
mbed_official 76:aeb1df146756 22 (++) Set the latency
mbed_official 76:aeb1df146756 23 (++) Enable/Disable the prefetch buffer
mbed_official 76:aeb1df146756 24
mbed_official 76:aeb1df146756 25 (#) FLASH Memory Programming functions: this group includes all needed
mbed_official 76:aeb1df146756 26 functions to erase and program the main memory:
mbed_official 76:aeb1df146756 27 (++) Lock and Unlock the Flash interface.
mbed_official 76:aeb1df146756 28 (++) Erase function: Erase Page, erase all pages.
mbed_official 76:aeb1df146756 29 (++) Program functions: Half Word and Word write.
mbed_official 76:aeb1df146756 30
mbed_official 76:aeb1df146756 31 (#) FLASH Option Bytes Programming functions: this group includes all
mbed_official 76:aeb1df146756 32 needed functions to:
mbed_official 76:aeb1df146756 33 (++) Lock and Unlock the Flash Option bytes.
mbed_official 76:aeb1df146756 34 (++) Launch the Option Bytes loader
mbed_official 76:aeb1df146756 35 (++) Erase the Option Bytes
mbed_official 76:aeb1df146756 36 (++)Set/Reset the write protection
mbed_official 76:aeb1df146756 37 (++) Set the Read protection Level
mbed_official 76:aeb1df146756 38 (++) Program the user option Bytes
mbed_official 76:aeb1df146756 39 (++) Set/Reset the BOOT1 bit
mbed_official 76:aeb1df146756 40 (++) Enable/Disable the VDDA Analog Monitoring
mbed_official 76:aeb1df146756 41 (++) Get the user option bytes
mbed_official 76:aeb1df146756 42 (++) Get the Write protection
mbed_official 76:aeb1df146756 43 (++) Get the read protection status
mbed_official 76:aeb1df146756 44
mbed_official 76:aeb1df146756 45 (#) FLASH Interrupts and flag management functions: this group includes
mbed_official 76:aeb1df146756 46 all needed functions to:
mbed_official 76:aeb1df146756 47 (++) Enable/Disable the flash interrupt sources
mbed_official 76:aeb1df146756 48 (++) Get flags status
mbed_official 76:aeb1df146756 49 (++) Clear flags
mbed_official 76:aeb1df146756 50 (++) Get Flash operation status
mbed_official 76:aeb1df146756 51 (++) Wait for last flash operation
mbed_official 76:aeb1df146756 52
mbed_official 76:aeb1df146756 53 @endverbatim
mbed_official 76:aeb1df146756 54
mbed_official 76:aeb1df146756 55 ******************************************************************************
mbed_official 76:aeb1df146756 56 * @attention
mbed_official 76:aeb1df146756 57 *
mbed_official 76:aeb1df146756 58 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 59 *
mbed_official 76:aeb1df146756 60 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
mbed_official 76:aeb1df146756 61 * You may not use this file except in compliance with the License.
mbed_official 76:aeb1df146756 62 * You may obtain a copy of the License at:
mbed_official 76:aeb1df146756 63 *
mbed_official 76:aeb1df146756 64 * http://www.st.com/software_license_agreement_liberty_v2
mbed_official 76:aeb1df146756 65 *
mbed_official 76:aeb1df146756 66 * Unless required by applicable law or agreed to in writing, software
mbed_official 76:aeb1df146756 67 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 76:aeb1df146756 68 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 76:aeb1df146756 69 * See the License for the specific language governing permissions and
mbed_official 76:aeb1df146756 70 * limitations under the License.
mbed_official 76:aeb1df146756 71 *
mbed_official 76:aeb1df146756 72 ******************************************************************************
mbed_official 76:aeb1df146756 73 */
mbed_official 76:aeb1df146756 74
mbed_official 76:aeb1df146756 75 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 76 #include "stm32f0xx_flash.h"
mbed_official 76:aeb1df146756 77
mbed_official 76:aeb1df146756 78 /** @addtogroup STM32F0xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 79 * @{
mbed_official 76:aeb1df146756 80 */
mbed_official 76:aeb1df146756 81
mbed_official 76:aeb1df146756 82 /** @defgroup FLASH
mbed_official 76:aeb1df146756 83 * @brief FLASH driver modules
mbed_official 76:aeb1df146756 84 * @{
mbed_official 76:aeb1df146756 85 */
mbed_official 76:aeb1df146756 86
mbed_official 76:aeb1df146756 87 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 88 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 89 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 90 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 91 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 92 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 93
mbed_official 76:aeb1df146756 94 /** @defgroup FLASH_Private_Functions
mbed_official 76:aeb1df146756 95 * @{
mbed_official 76:aeb1df146756 96 */
mbed_official 76:aeb1df146756 97
mbed_official 76:aeb1df146756 98 /** @defgroup FLASH_Group1 FLASH Interface configuration functions
mbed_official 76:aeb1df146756 99 * @brief FLASH Interface configuration functions
mbed_official 76:aeb1df146756 100 *
mbed_official 76:aeb1df146756 101 @verbatim
mbed_official 76:aeb1df146756 102 ===============================================================================
mbed_official 76:aeb1df146756 103 ##### FLASH Interface configuration functions #####
mbed_official 76:aeb1df146756 104 ===============================================================================
mbed_official 76:aeb1df146756 105
mbed_official 76:aeb1df146756 106 [..] FLASH_Interface configuration_Functions, includes the following functions:
mbed_official 76:aeb1df146756 107 (+) void FLASH_SetLatency(uint32_t FLASH_Latency):
mbed_official 76:aeb1df146756 108 [..] To correctly read data from Flash memory, the number of wait states (LATENCY)
mbed_official 76:aeb1df146756 109 must be correctly programmed according to the frequency of the CPU clock (HCLK)
mbed_official 76:aeb1df146756 110 [..]
mbed_official 76:aeb1df146756 111 +--------------------------------------------- +
mbed_official 76:aeb1df146756 112 | Wait states | HCLK clock frequency (MHz) |
mbed_official 76:aeb1df146756 113 |---------------|------------------------------|
mbed_official 76:aeb1df146756 114 |0WS(1CPU cycle)| 0 < HCLK <= 24 |
mbed_official 76:aeb1df146756 115 |---------------|------------------------------|
mbed_official 76:aeb1df146756 116 |1WS(2CPU cycle)| 24 < HCLK <= 48 |
mbed_official 76:aeb1df146756 117 +----------------------------------------------+
mbed_official 76:aeb1df146756 118 [..]
mbed_official 76:aeb1df146756 119 (+) void FLASH_PrefetchBufferCmd(FunctionalState NewState);
mbed_official 76:aeb1df146756 120 [..]
mbed_official 76:aeb1df146756 121 All these functions don't need the unlock sequence.
mbed_official 76:aeb1df146756 122
mbed_official 76:aeb1df146756 123 @endverbatim
mbed_official 76:aeb1df146756 124 * @{
mbed_official 76:aeb1df146756 125 */
mbed_official 76:aeb1df146756 126
mbed_official 76:aeb1df146756 127 /**
mbed_official 76:aeb1df146756 128 * @brief Sets the code latency value.
mbed_official 76:aeb1df146756 129 * @param FLASH_Latency: specifies the FLASH Latency value.
mbed_official 76:aeb1df146756 130 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 131 * @arg FLASH_Latency_0: FLASH Zero Latency cycle
mbed_official 76:aeb1df146756 132 * @arg FLASH_Latency_1: FLASH One Latency cycle
mbed_official 76:aeb1df146756 133 * @retval None
mbed_official 76:aeb1df146756 134 */
mbed_official 76:aeb1df146756 135 void FLASH_SetLatency(uint32_t FLASH_Latency)
mbed_official 76:aeb1df146756 136 {
mbed_official 76:aeb1df146756 137 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 138
mbed_official 76:aeb1df146756 139 /* Check the parameters */
mbed_official 76:aeb1df146756 140 assert_param(IS_FLASH_LATENCY(FLASH_Latency));
mbed_official 76:aeb1df146756 141
mbed_official 76:aeb1df146756 142 /* Read the ACR register */
mbed_official 76:aeb1df146756 143 tmpreg = FLASH->ACR;
mbed_official 76:aeb1df146756 144
mbed_official 76:aeb1df146756 145 /* Sets the Latency value */
mbed_official 76:aeb1df146756 146 tmpreg &= (uint32_t) (~((uint32_t)FLASH_ACR_LATENCY));
mbed_official 76:aeb1df146756 147 tmpreg |= FLASH_Latency;
mbed_official 76:aeb1df146756 148
mbed_official 76:aeb1df146756 149 /* Write the ACR register */
mbed_official 76:aeb1df146756 150 FLASH->ACR = tmpreg;
mbed_official 76:aeb1df146756 151 }
mbed_official 76:aeb1df146756 152
mbed_official 76:aeb1df146756 153 /**
mbed_official 76:aeb1df146756 154 * @brief Enables or disables the Prefetch Buffer.
mbed_official 76:aeb1df146756 155 * @param NewState: new state of the FLASH prefetch buffer.
mbed_official 76:aeb1df146756 156 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 157 * @retval None
mbed_official 76:aeb1df146756 158 */
mbed_official 76:aeb1df146756 159 void FLASH_PrefetchBufferCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 160 {
mbed_official 76:aeb1df146756 161 /* Check the parameters */
mbed_official 76:aeb1df146756 162 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 163
mbed_official 76:aeb1df146756 164 if(NewState != DISABLE)
mbed_official 76:aeb1df146756 165 {
mbed_official 76:aeb1df146756 166 FLASH->ACR |= FLASH_ACR_PRFTBE;
mbed_official 76:aeb1df146756 167 }
mbed_official 76:aeb1df146756 168 else
mbed_official 76:aeb1df146756 169 {
mbed_official 76:aeb1df146756 170 FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_PRFTBE));
mbed_official 76:aeb1df146756 171 }
mbed_official 76:aeb1df146756 172 }
mbed_official 76:aeb1df146756 173
mbed_official 76:aeb1df146756 174 /**
mbed_official 76:aeb1df146756 175 * @brief Checks whether the FLASH Prefetch Buffer status is set or not.
mbed_official 76:aeb1df146756 176 * @param None
mbed_official 76:aeb1df146756 177 * @retval FLASH Prefetch Buffer Status (SET or RESET).
mbed_official 76:aeb1df146756 178 */
mbed_official 76:aeb1df146756 179 FlagStatus FLASH_GetPrefetchBufferStatus(void)
mbed_official 76:aeb1df146756 180 {
mbed_official 76:aeb1df146756 181 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 182
mbed_official 76:aeb1df146756 183 if ((FLASH->ACR & FLASH_ACR_PRFTBS) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 184 {
mbed_official 76:aeb1df146756 185 bitstatus = SET;
mbed_official 76:aeb1df146756 186 }
mbed_official 76:aeb1df146756 187 else
mbed_official 76:aeb1df146756 188 {
mbed_official 76:aeb1df146756 189 bitstatus = RESET;
mbed_official 76:aeb1df146756 190 }
mbed_official 76:aeb1df146756 191 /* Return the new state of FLASH Prefetch Buffer Status (SET or RESET) */
mbed_official 76:aeb1df146756 192 return bitstatus;
mbed_official 76:aeb1df146756 193 }
mbed_official 76:aeb1df146756 194
mbed_official 76:aeb1df146756 195 /**
mbed_official 76:aeb1df146756 196 * @}
mbed_official 76:aeb1df146756 197 */
mbed_official 76:aeb1df146756 198
mbed_official 76:aeb1df146756 199 /** @defgroup FLASH_Group2 FLASH Memory Programming functions
mbed_official 76:aeb1df146756 200 * @brief FLASH Memory Programming functions
mbed_official 76:aeb1df146756 201 *
mbed_official 76:aeb1df146756 202 @verbatim
mbed_official 76:aeb1df146756 203 ===============================================================================
mbed_official 76:aeb1df146756 204 ##### FLASH Memory Programming functions #####
mbed_official 76:aeb1df146756 205 ===============================================================================
mbed_official 76:aeb1df146756 206
mbed_official 76:aeb1df146756 207 [..] The FLASH Memory Programming functions, includes the following functions:
mbed_official 76:aeb1df146756 208 (+) void FLASH_Unlock(void);
mbed_official 76:aeb1df146756 209 (+) void FLASH_Lock(void);
mbed_official 76:aeb1df146756 210 (+) FLASH_Status FLASH_ErasePage(uint32_t Page_Address);
mbed_official 76:aeb1df146756 211 (+) FLASH_Status FLASH_EraseAllPages(void);
mbed_official 76:aeb1df146756 212 (+) FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
mbed_official 76:aeb1df146756 213 (+) FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
mbed_official 76:aeb1df146756 214
mbed_official 76:aeb1df146756 215 [..] Any operation of erase or program should follow these steps:
mbed_official 76:aeb1df146756 216
mbed_official 76:aeb1df146756 217 (#) Call the FLASH_Unlock() function to enable the flash control register and
mbed_official 76:aeb1df146756 218 program memory access
mbed_official 76:aeb1df146756 219 (#) Call the desired function to erase page or program data
mbed_official 76:aeb1df146756 220 (#) Call the FLASH_Lock() to disable the flash program memory access
mbed_official 76:aeb1df146756 221 (recommended to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 222
mbed_official 76:aeb1df146756 223 @endverbatim
mbed_official 76:aeb1df146756 224 * @{
mbed_official 76:aeb1df146756 225 */
mbed_official 76:aeb1df146756 226
mbed_official 76:aeb1df146756 227 /**
mbed_official 76:aeb1df146756 228 * @brief Unlocks the FLASH control register and program memory access.
mbed_official 76:aeb1df146756 229 * @param None
mbed_official 76:aeb1df146756 230 * @retval None
mbed_official 76:aeb1df146756 231 */
mbed_official 76:aeb1df146756 232 void FLASH_Unlock(void)
mbed_official 76:aeb1df146756 233 {
mbed_official 76:aeb1df146756 234 if((FLASH->CR & FLASH_CR_LOCK) != RESET)
mbed_official 76:aeb1df146756 235 {
mbed_official 76:aeb1df146756 236 /* Unlocking the program memory access */
mbed_official 76:aeb1df146756 237 FLASH->KEYR = FLASH_FKEY1;
mbed_official 76:aeb1df146756 238 FLASH->KEYR = FLASH_FKEY2;
mbed_official 76:aeb1df146756 239 }
mbed_official 76:aeb1df146756 240 }
mbed_official 76:aeb1df146756 241
mbed_official 76:aeb1df146756 242 /**
mbed_official 76:aeb1df146756 243 * @brief Locks the Program memory access.
mbed_official 76:aeb1df146756 244 * @param None
mbed_official 76:aeb1df146756 245 * @retval None
mbed_official 76:aeb1df146756 246 */
mbed_official 76:aeb1df146756 247 void FLASH_Lock(void)
mbed_official 76:aeb1df146756 248 {
mbed_official 76:aeb1df146756 249 /* Set the LOCK Bit to lock the FLASH control register and program memory access */
mbed_official 76:aeb1df146756 250 FLASH->CR |= FLASH_CR_LOCK;
mbed_official 76:aeb1df146756 251 }
mbed_official 76:aeb1df146756 252
mbed_official 76:aeb1df146756 253 /**
mbed_official 76:aeb1df146756 254 * @brief Erases a specified page in program memory.
mbed_official 76:aeb1df146756 255 * @note To correctly run this function, the FLASH_Unlock() function must be called before.
mbed_official 76:aeb1df146756 256 * @note Call the FLASH_Lock() to disable the flash memory access (recommended
mbed_official 76:aeb1df146756 257 * to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 258 * @param Page_Address: The page address in program memory to be erased.
mbed_official 76:aeb1df146756 259 * @note A Page is erased in the Program memory only if the address to load
mbed_official 76:aeb1df146756 260 * is the start address of a page (multiple of 1024 bytes).
mbed_official 76:aeb1df146756 261 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 262 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 263 */
mbed_official 76:aeb1df146756 264 FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
mbed_official 76:aeb1df146756 265 {
mbed_official 76:aeb1df146756 266 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 267
mbed_official 76:aeb1df146756 268 /* Check the parameters */
mbed_official 76:aeb1df146756 269 assert_param(IS_FLASH_PROGRAM_ADDRESS(Page_Address));
mbed_official 76:aeb1df146756 270
mbed_official 76:aeb1df146756 271 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 272 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 273
mbed_official 76:aeb1df146756 274 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 275 {
mbed_official 76:aeb1df146756 276 /* If the previous operation is completed, proceed to erase the page */
mbed_official 76:aeb1df146756 277 FLASH->CR |= FLASH_CR_PER;
mbed_official 76:aeb1df146756 278 FLASH->AR = Page_Address;
mbed_official 76:aeb1df146756 279 FLASH->CR |= FLASH_CR_STRT;
mbed_official 76:aeb1df146756 280
mbed_official 76:aeb1df146756 281 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 282 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 283
mbed_official 76:aeb1df146756 284 /* Disable the PER Bit */
mbed_official 76:aeb1df146756 285 FLASH->CR &= ~FLASH_CR_PER;
mbed_official 76:aeb1df146756 286 }
mbed_official 76:aeb1df146756 287
mbed_official 76:aeb1df146756 288 /* Return the Erase Status */
mbed_official 76:aeb1df146756 289 return status;
mbed_official 76:aeb1df146756 290 }
mbed_official 76:aeb1df146756 291
mbed_official 76:aeb1df146756 292 /**
mbed_official 76:aeb1df146756 293 * @brief Erases all FLASH pages.
mbed_official 76:aeb1df146756 294 * @note To correctly run this function, the FLASH_Unlock() function must be called before.
mbed_official 76:aeb1df146756 295 * @note Call the FLASH_Lock() to disable the flash memory access (recommended
mbed_official 76:aeb1df146756 296 * to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 297 * @param None
mbed_official 76:aeb1df146756 298 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 76:aeb1df146756 299 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 300 */
mbed_official 76:aeb1df146756 301 FLASH_Status FLASH_EraseAllPages(void)
mbed_official 76:aeb1df146756 302 {
mbed_official 76:aeb1df146756 303 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 304
mbed_official 76:aeb1df146756 305 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 306 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 307
mbed_official 76:aeb1df146756 308 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 309 {
mbed_official 76:aeb1df146756 310 /* if the previous operation is completed, proceed to erase all pages */
mbed_official 76:aeb1df146756 311 FLASH->CR |= FLASH_CR_MER;
mbed_official 76:aeb1df146756 312 FLASH->CR |= FLASH_CR_STRT;
mbed_official 76:aeb1df146756 313
mbed_official 76:aeb1df146756 314 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 315 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 316
mbed_official 76:aeb1df146756 317 /* Disable the MER Bit */
mbed_official 76:aeb1df146756 318 FLASH->CR &= ~FLASH_CR_MER;
mbed_official 76:aeb1df146756 319 }
mbed_official 76:aeb1df146756 320
mbed_official 76:aeb1df146756 321 /* Return the Erase Status */
mbed_official 76:aeb1df146756 322 return status;
mbed_official 76:aeb1df146756 323 }
mbed_official 76:aeb1df146756 324
mbed_official 76:aeb1df146756 325 /**
mbed_official 76:aeb1df146756 326 * @brief Programs a word at a specified address.
mbed_official 76:aeb1df146756 327 * @note To correctly run this function, the FLASH_Unlock() function must be called before.
mbed_official 76:aeb1df146756 328 * @note Call the FLASH_Lock() to disable the flash memory access (recommended
mbed_official 76:aeb1df146756 329 * to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 330 * @param Address: specifies the address to be programmed.
mbed_official 76:aeb1df146756 331 * @param Data: specifies the data to be programmed.
mbed_official 76:aeb1df146756 332 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 76:aeb1df146756 333 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 334 */
mbed_official 76:aeb1df146756 335 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
mbed_official 76:aeb1df146756 336 {
mbed_official 76:aeb1df146756 337 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 338 __IO uint32_t tmp = 0;
mbed_official 76:aeb1df146756 339
mbed_official 76:aeb1df146756 340 /* Check the parameters */
mbed_official 76:aeb1df146756 341 assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
mbed_official 76:aeb1df146756 342
mbed_official 76:aeb1df146756 343 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 344 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 345
mbed_official 76:aeb1df146756 346 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 347 {
mbed_official 76:aeb1df146756 348 /* If the previous operation is completed, proceed to program the new first
mbed_official 76:aeb1df146756 349 half word */
mbed_official 76:aeb1df146756 350 FLASH->CR |= FLASH_CR_PG;
mbed_official 76:aeb1df146756 351
mbed_official 76:aeb1df146756 352 *(__IO uint16_t*)Address = (uint16_t)Data;
mbed_official 76:aeb1df146756 353
mbed_official 76:aeb1df146756 354 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 355 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 356
mbed_official 76:aeb1df146756 357 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 358 {
mbed_official 76:aeb1df146756 359 /* If the previous operation is completed, proceed to program the new second
mbed_official 76:aeb1df146756 360 half word */
mbed_official 76:aeb1df146756 361 tmp = Address + 2;
mbed_official 76:aeb1df146756 362
mbed_official 76:aeb1df146756 363 *(__IO uint16_t*) tmp = Data >> 16;
mbed_official 76:aeb1df146756 364
mbed_official 76:aeb1df146756 365 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 366 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 367
mbed_official 76:aeb1df146756 368 /* Disable the PG Bit */
mbed_official 76:aeb1df146756 369 FLASH->CR &= ~FLASH_CR_PG;
mbed_official 76:aeb1df146756 370 }
mbed_official 76:aeb1df146756 371 else
mbed_official 76:aeb1df146756 372 {
mbed_official 76:aeb1df146756 373 /* Disable the PG Bit */
mbed_official 76:aeb1df146756 374 FLASH->CR &= ~FLASH_CR_PG;
mbed_official 76:aeb1df146756 375 }
mbed_official 76:aeb1df146756 376 }
mbed_official 76:aeb1df146756 377
mbed_official 76:aeb1df146756 378 /* Return the Program Status */
mbed_official 76:aeb1df146756 379 return status;
mbed_official 76:aeb1df146756 380 }
mbed_official 76:aeb1df146756 381
mbed_official 76:aeb1df146756 382 /**
mbed_official 76:aeb1df146756 383 * @brief Programs a half word at a specified address.
mbed_official 76:aeb1df146756 384 * @note To correctly run this function, the FLASH_Unlock() function must be called before.
mbed_official 76:aeb1df146756 385 * @note Call the FLASH_Lock() to disable the flash memory access (recommended
mbed_official 76:aeb1df146756 386 * to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 387 * @param Address: specifies the address to be programmed.
mbed_official 76:aeb1df146756 388 * @param Data: specifies the data to be programmed.
mbed_official 76:aeb1df146756 389 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 76:aeb1df146756 390 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 391 */
mbed_official 76:aeb1df146756 392 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
mbed_official 76:aeb1df146756 393 {
mbed_official 76:aeb1df146756 394 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 395
mbed_official 76:aeb1df146756 396 /* Check the parameters */
mbed_official 76:aeb1df146756 397 assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
mbed_official 76:aeb1df146756 398
mbed_official 76:aeb1df146756 399 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 400 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 401
mbed_official 76:aeb1df146756 402 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 403 {
mbed_official 76:aeb1df146756 404 /* If the previous operation is completed, proceed to program the new data */
mbed_official 76:aeb1df146756 405 FLASH->CR |= FLASH_CR_PG;
mbed_official 76:aeb1df146756 406
mbed_official 76:aeb1df146756 407 *(__IO uint16_t*)Address = Data;
mbed_official 76:aeb1df146756 408
mbed_official 76:aeb1df146756 409 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 410 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 411
mbed_official 76:aeb1df146756 412 /* Disable the PG Bit */
mbed_official 76:aeb1df146756 413 FLASH->CR &= ~FLASH_CR_PG;
mbed_official 76:aeb1df146756 414 }
mbed_official 76:aeb1df146756 415
mbed_official 76:aeb1df146756 416 /* Return the Program Status */
mbed_official 76:aeb1df146756 417 return status;
mbed_official 76:aeb1df146756 418 }
mbed_official 76:aeb1df146756 419
mbed_official 76:aeb1df146756 420 /**
mbed_official 76:aeb1df146756 421 * @}
mbed_official 76:aeb1df146756 422 */
mbed_official 76:aeb1df146756 423
mbed_official 76:aeb1df146756 424 /** @defgroup FLASH_Group3 Option Bytes Programming functions
mbed_official 76:aeb1df146756 425 * @brief Option Bytes Programming functions
mbed_official 76:aeb1df146756 426 *
mbed_official 76:aeb1df146756 427 @verbatim
mbed_official 76:aeb1df146756 428 ===============================================================================
mbed_official 76:aeb1df146756 429 ##### Option Bytes Programming functions #####
mbed_official 76:aeb1df146756 430 ===============================================================================
mbed_official 76:aeb1df146756 431
mbed_official 76:aeb1df146756 432 [..] The FLASH_Option Bytes Programming_functions, includes the following functions:
mbed_official 76:aeb1df146756 433 (+) void FLASH_OB_Unlock(void);
mbed_official 76:aeb1df146756 434 (+) void FLASH_OB_Lock(void);
mbed_official 76:aeb1df146756 435 (+) void FLASH_OB_Launch(void);
mbed_official 76:aeb1df146756 436 (+) FLASH_Status FLASH_OB_Erase(void);
mbed_official 76:aeb1df146756 437 (+) FLASH_Status FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState);
mbed_official 76:aeb1df146756 438 (+) FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP);
mbed_official 76:aeb1df146756 439 (+) FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);
mbed_official 76:aeb1df146756 440 (+) FLASH_Status FLASH_OB_BOOTConfig(uint8_t OB_BOOT1);
mbed_official 76:aeb1df146756 441 (+) FLASH_Status FLASH_OB_VDDAConfig(uint8_t OB_VDDA_ANALOG);
mbed_official 76:aeb1df146756 442 (+) FLASH_Status FLASH_OB_WriteUser(uint8_t OB_USER);
mbed_official 76:aeb1df146756 443 (+) FLASH_OB_ProgramData(uint32_t Address, uint8_t Data);
mbed_official 76:aeb1df146756 444 (+) uint8_t FLASH_OB_GetUser(void);
mbed_official 76:aeb1df146756 445 (+) uint32_t FLASH_OB_GetWRP(void);
mbed_official 76:aeb1df146756 446 (+) FlagStatus FLASH_OB_GetRDP(void);
mbed_official 76:aeb1df146756 447
mbed_official 76:aeb1df146756 448 [..] Any operation of erase or program should follow these steps:
mbed_official 76:aeb1df146756 449
mbed_official 76:aeb1df146756 450 (#) Call the FLASH_OB_Unlock() function to enable the Option Bytes registers access
mbed_official 76:aeb1df146756 451
mbed_official 76:aeb1df146756 452 (#) Call one or several functions to program the desired option bytes
mbed_official 76:aeb1df146756 453 (++) FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP) => to set the desired read Protection Level
mbed_official 76:aeb1df146756 454 (++) FLASH_Status FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState)
mbed_official 76:aeb1df146756 455 => to Enable/Disable the desired sector write protection
mbed_official 76:aeb1df146756 456 (++) FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY)
mbed_official 76:aeb1df146756 457 => to configure the user option Bytes: IWDG, STOP and the Standby.
mbed_official 76:aeb1df146756 458 (++) FLASH_Status FLASH_OB_BOOTConfig(uint8_t OB_BOOT1)
mbed_official 76:aeb1df146756 459 => to set or reset BOOT1
mbed_official 76:aeb1df146756 460 (++) FLASH_Status FLASH_OB_VDDAConfig(uint8_t OB_VDDA_ANALOG)
mbed_official 76:aeb1df146756 461 => to enable or disable the VDDA Analog Monitoring
mbed_official 76:aeb1df146756 462 (++) You can write all User Options bytes at once using a single function
mbed_official 76:aeb1df146756 463 by calling FLASH_Status FLASH_OB_WriteUser(uint8_t OB_USER)
mbed_official 76:aeb1df146756 464 (++) FLASH_OB_ProgramData(uint32_t Address, uint8_t Data) to program the
mbed_official 76:aeb1df146756 465 two half word in the option bytes
mbed_official 76:aeb1df146756 466
mbed_official 76:aeb1df146756 467 (#) Once all needed option bytes to be programmed are correctly written, call the
mbed_official 76:aeb1df146756 468 FLASH_OB_Launch(void) function to launch the Option Bytes programming process.
mbed_official 76:aeb1df146756 469
mbed_official 76:aeb1df146756 470 (#) Call the FLASH_OB_Lock() to disable the Option Bytes registers access (recommended
mbed_official 76:aeb1df146756 471 to protect the option Bytes against possible unwanted operations)
mbed_official 76:aeb1df146756 472
mbed_official 76:aeb1df146756 473 @endverbatim
mbed_official 76:aeb1df146756 474 * @{
mbed_official 76:aeb1df146756 475 */
mbed_official 76:aeb1df146756 476
mbed_official 76:aeb1df146756 477 /**
mbed_official 76:aeb1df146756 478 * @brief Unlocks the option bytes block access.
mbed_official 76:aeb1df146756 479 * @param None
mbed_official 76:aeb1df146756 480 * @retval None
mbed_official 76:aeb1df146756 481 */
mbed_official 76:aeb1df146756 482 void FLASH_OB_Unlock(void)
mbed_official 76:aeb1df146756 483 {
mbed_official 76:aeb1df146756 484 if((FLASH->CR & FLASH_CR_OPTWRE) == RESET)
mbed_official 76:aeb1df146756 485 {
mbed_official 76:aeb1df146756 486 /* Unlocking the option bytes block access */
mbed_official 76:aeb1df146756 487 FLASH->OPTKEYR = FLASH_OPTKEY1;
mbed_official 76:aeb1df146756 488 FLASH->OPTKEYR = FLASH_OPTKEY2;
mbed_official 76:aeb1df146756 489 }
mbed_official 76:aeb1df146756 490 }
mbed_official 76:aeb1df146756 491
mbed_official 76:aeb1df146756 492 /**
mbed_official 76:aeb1df146756 493 * @brief Locks the option bytes block access.
mbed_official 76:aeb1df146756 494 * @param None
mbed_official 76:aeb1df146756 495 * @retval None
mbed_official 76:aeb1df146756 496 */
mbed_official 76:aeb1df146756 497 void FLASH_OB_Lock(void)
mbed_official 76:aeb1df146756 498 {
mbed_official 76:aeb1df146756 499 /* Set the OPTWREN Bit to lock the option bytes block access */
mbed_official 76:aeb1df146756 500 FLASH->CR &= ~FLASH_CR_OPTWRE;
mbed_official 76:aeb1df146756 501 }
mbed_official 76:aeb1df146756 502
mbed_official 76:aeb1df146756 503 /**
mbed_official 76:aeb1df146756 504 * @brief Launch the option byte loading.
mbed_official 76:aeb1df146756 505 * @param None
mbed_official 76:aeb1df146756 506 * @retval None
mbed_official 76:aeb1df146756 507 */
mbed_official 76:aeb1df146756 508 void FLASH_OB_Launch(void)
mbed_official 76:aeb1df146756 509 {
mbed_official 76:aeb1df146756 510 /* Set the OBL_Launch bit to launch the option byte loading */
mbed_official 76:aeb1df146756 511 FLASH->CR |= FLASH_CR_OBL_LAUNCH;
mbed_official 76:aeb1df146756 512 }
mbed_official 76:aeb1df146756 513
mbed_official 76:aeb1df146756 514 /**
mbed_official 76:aeb1df146756 515 * @brief Erases the FLASH option bytes.
mbed_official 76:aeb1df146756 516 * @note To correctly run this function, the FLASH_OB_Unlock() function must be called before.
mbed_official 76:aeb1df146756 517 * @note Call the FLASH_OB_Lock() to disable the flash control register access and the option
mbed_official 76:aeb1df146756 518 * bytes (recommended to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 519 * @note This functions erases all option bytes except the Read protection (RDP).
mbed_official 76:aeb1df146756 520 * @param None
mbed_official 76:aeb1df146756 521 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 76:aeb1df146756 522 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 523 */
mbed_official 76:aeb1df146756 524 FLASH_Status FLASH_OB_Erase(void)
mbed_official 76:aeb1df146756 525 {
mbed_official 76:aeb1df146756 526 uint16_t rdptmp = OB_RDP_Level_0;
mbed_official 76:aeb1df146756 527
mbed_official 76:aeb1df146756 528 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 529
mbed_official 76:aeb1df146756 530 /* Get the actual read protection Option Byte value */
mbed_official 76:aeb1df146756 531 if(FLASH_OB_GetRDP() != RESET)
mbed_official 76:aeb1df146756 532 {
mbed_official 76:aeb1df146756 533 rdptmp = 0x00;
mbed_official 76:aeb1df146756 534 }
mbed_official 76:aeb1df146756 535
mbed_official 76:aeb1df146756 536 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 537 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 538
mbed_official 76:aeb1df146756 539 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 540 {
mbed_official 76:aeb1df146756 541 /* If the previous operation is completed, proceed to erase the option bytes */
mbed_official 76:aeb1df146756 542 FLASH->CR |= FLASH_CR_OPTER;
mbed_official 76:aeb1df146756 543 FLASH->CR |= FLASH_CR_STRT;
mbed_official 76:aeb1df146756 544
mbed_official 76:aeb1df146756 545 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 546 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 547
mbed_official 76:aeb1df146756 548 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 549 {
mbed_official 76:aeb1df146756 550 /* If the erase operation is completed, disable the OPTER Bit */
mbed_official 76:aeb1df146756 551 FLASH->CR &= ~FLASH_CR_OPTER;
mbed_official 76:aeb1df146756 552
mbed_official 76:aeb1df146756 553 /* Enable the Option Bytes Programming operation */
mbed_official 76:aeb1df146756 554 FLASH->CR |= FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 555
mbed_official 76:aeb1df146756 556 /* Restore the last read protection Option Byte value */
mbed_official 76:aeb1df146756 557 OB->RDP = (uint16_t)rdptmp;
mbed_official 76:aeb1df146756 558
mbed_official 76:aeb1df146756 559 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 560 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 561
mbed_official 76:aeb1df146756 562 if(status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 563 {
mbed_official 76:aeb1df146756 564 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 76:aeb1df146756 565 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 566 }
mbed_official 76:aeb1df146756 567 }
mbed_official 76:aeb1df146756 568 else
mbed_official 76:aeb1df146756 569 {
mbed_official 76:aeb1df146756 570 if (status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 571 {
mbed_official 76:aeb1df146756 572 /* Disable the OPTPG Bit */
mbed_official 76:aeb1df146756 573 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 574 }
mbed_official 76:aeb1df146756 575 }
mbed_official 76:aeb1df146756 576 }
mbed_official 76:aeb1df146756 577 /* Return the erase status */
mbed_official 76:aeb1df146756 578 return status;
mbed_official 76:aeb1df146756 579 }
mbed_official 76:aeb1df146756 580
mbed_official 76:aeb1df146756 581 /**
mbed_official 76:aeb1df146756 582 * @brief Write protects the desired pages
mbed_official 76:aeb1df146756 583 * @note To correctly run this function, the FLASH_OB_Unlock() function must be called before.
mbed_official 76:aeb1df146756 584 * @note Call the FLASH_OB_Lock() to disable the flash control register access and the option
mbed_official 76:aeb1df146756 585 * bytes (recommended to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 586 * @param OB_WRP: specifies the address of the pages to be write protected.
mbed_official 76:aeb1df146756 587 * This parameter can be:
mbed_official 76:aeb1df146756 588 * @arg OB_WRP_Pages0to3..OB_WRP_Pages60to63
mbed_official 76:aeb1df146756 589 * @arg OB_WRP_AllPages
mbed_official 76:aeb1df146756 590 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 591 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 592 */
mbed_official 76:aeb1df146756 593 FLASH_Status FLASH_OB_EnableWRP(uint32_t OB_WRP)
mbed_official 76:aeb1df146756 594 {
mbed_official 76:aeb1df146756 595 uint16_t WRP0_Data = 0xFFFF, WRP1_Data = 0xFFFF, WRP2_Data = 0xFFFF, WRP3_Data = 0xFFFF;
mbed_official 76:aeb1df146756 596
mbed_official 76:aeb1df146756 597 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 598
mbed_official 76:aeb1df146756 599 /* Check the parameters */
mbed_official 76:aeb1df146756 600 assert_param(IS_OB_WRP(OB_WRP));
mbed_official 76:aeb1df146756 601
mbed_official 76:aeb1df146756 602 OB_WRP = (uint32_t)(~OB_WRP);
mbed_official 76:aeb1df146756 603 WRP0_Data = (uint16_t)(OB_WRP & OB_WRP0_WRP0);
mbed_official 76:aeb1df146756 604 WRP1_Data = (uint16_t)((OB_WRP >> 8) & OB_WRP0_WRP0);
mbed_official 76:aeb1df146756 605 WRP2_Data = (uint16_t)((OB_WRP >> 16) & OB_WRP0_WRP0) ;
mbed_official 76:aeb1df146756 606 WRP3_Data = (uint16_t)((OB_WRP >> 24) & OB_WRP0_WRP0) ;
mbed_official 76:aeb1df146756 607
mbed_official 76:aeb1df146756 608 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 609 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 610
mbed_official 76:aeb1df146756 611 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 612 {
mbed_official 76:aeb1df146756 613 FLASH->CR |= FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 614
mbed_official 76:aeb1df146756 615 if(WRP0_Data != 0xFF)
mbed_official 76:aeb1df146756 616 {
mbed_official 76:aeb1df146756 617 OB->WRP0 = WRP0_Data;
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) && (WRP1_Data != 0xFF))
mbed_official 76:aeb1df146756 623 {
mbed_official 76:aeb1df146756 624 OB->WRP1 = WRP1_Data;
mbed_official 76:aeb1df146756 625
mbed_official 76:aeb1df146756 626 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 627 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 628 }
mbed_official 76:aeb1df146756 629 if((status == FLASH_COMPLETE) && (WRP2_Data != 0xFF))
mbed_official 76:aeb1df146756 630 {
mbed_official 76:aeb1df146756 631 OB->WRP2 = WRP2_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 if((status == FLASH_COMPLETE) && (WRP3_Data != 0xFF))
mbed_official 76:aeb1df146756 637 {
mbed_official 76:aeb1df146756 638 OB->WRP3 = WRP3_Data;
mbed_official 76:aeb1df146756 639
mbed_official 76:aeb1df146756 640 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 641 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 642 }
mbed_official 76:aeb1df146756 643 if(status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 644 {
mbed_official 76:aeb1df146756 645 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 76:aeb1df146756 646 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 647 }
mbed_official 76:aeb1df146756 648 }
mbed_official 76:aeb1df146756 649 /* Return the write protection operation Status */
mbed_official 76:aeb1df146756 650 return status;
mbed_official 76:aeb1df146756 651 }
mbed_official 76:aeb1df146756 652
mbed_official 76:aeb1df146756 653 /**
mbed_official 76:aeb1df146756 654 * @brief Enables or disables the read out protection.
mbed_official 76:aeb1df146756 655 * @note To correctly run this function, the FLASH_OB_Unlock() function must be called before.
mbed_official 76:aeb1df146756 656 * @note Call the FLASH_OB_Lock() to disable the flash control register access and the option
mbed_official 76:aeb1df146756 657 * bytes (recommended to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 658 * @param FLASH_ReadProtection_Level: specifies the read protection level.
mbed_official 76:aeb1df146756 659 * This parameter can be:
mbed_official 76:aeb1df146756 660 * @arg OB_RDP_Level_0: No protection
mbed_official 76:aeb1df146756 661 * @arg OB_RDP_Level_1: Read protection of the memory
mbed_official 76:aeb1df146756 662 * @arg OB_RDP_Level_2: Chip protection
mbed_official 76:aeb1df146756 663 * @note When enabling OB_RDP level 2 it's no more possible to go back to level 1 or 0
mbed_official 76:aeb1df146756 664 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 665 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 666 */
mbed_official 76:aeb1df146756 667 FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP)
mbed_official 76:aeb1df146756 668 {
mbed_official 76:aeb1df146756 669 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 670
mbed_official 76:aeb1df146756 671 /* Check the parameters */
mbed_official 76:aeb1df146756 672 assert_param(IS_OB_RDP(OB_RDP));
mbed_official 76:aeb1df146756 673 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 674
mbed_official 76:aeb1df146756 675 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 676 {
mbed_official 76:aeb1df146756 677 FLASH->CR |= FLASH_CR_OPTER;
mbed_official 76:aeb1df146756 678 FLASH->CR |= FLASH_CR_STRT;
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 /* If the erase operation is completed, disable the OPTER Bit */
mbed_official 76:aeb1df146756 686 FLASH->CR &= ~FLASH_CR_OPTER;
mbed_official 76:aeb1df146756 687
mbed_official 76:aeb1df146756 688 /* Enable the Option Bytes Programming operation */
mbed_official 76:aeb1df146756 689 FLASH->CR |= FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 690
mbed_official 76:aeb1df146756 691 OB->RDP = OB_RDP;
mbed_official 76:aeb1df146756 692
mbed_official 76:aeb1df146756 693 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 694 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 695
mbed_official 76:aeb1df146756 696 if(status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 697 {
mbed_official 76:aeb1df146756 698 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 76:aeb1df146756 699 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 700 }
mbed_official 76:aeb1df146756 701 }
mbed_official 76:aeb1df146756 702 else
mbed_official 76:aeb1df146756 703 {
mbed_official 76:aeb1df146756 704 if(status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 705 {
mbed_official 76:aeb1df146756 706 /* Disable the OPTER Bit */
mbed_official 76:aeb1df146756 707 FLASH->CR &= ~FLASH_CR_OPTER;
mbed_official 76:aeb1df146756 708 }
mbed_official 76:aeb1df146756 709 }
mbed_official 76:aeb1df146756 710 }
mbed_official 76:aeb1df146756 711 /* Return the protection operation Status */
mbed_official 76:aeb1df146756 712 return status;
mbed_official 76:aeb1df146756 713 }
mbed_official 76:aeb1df146756 714
mbed_official 76:aeb1df146756 715 /**
mbed_official 76:aeb1df146756 716 * @brief Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
mbed_official 76:aeb1df146756 717 * @note To correctly run this function, the FLASH_OB_Unlock() function must be called before.
mbed_official 76:aeb1df146756 718 * @note Call the FLASH_OB_Lock() to disable the flash control register access and the option
mbed_official 76:aeb1df146756 719 * bytes (recommended to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 720 * @param OB_IWDG: Selects the WDG mode
mbed_official 76:aeb1df146756 721 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 722 * @arg OB_IWDG_SW: Software WDG selected
mbed_official 76:aeb1df146756 723 * @arg OB_IWDG_HW: Hardware WDG selected
mbed_official 76:aeb1df146756 724 * @param OB_STOP: Reset event when entering STOP mode.
mbed_official 76:aeb1df146756 725 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 726 * @arg OB_STOP_NoRST: No reset generated when entering in STOP
mbed_official 76:aeb1df146756 727 * @arg OB_STOP_RST: Reset generated when entering in STOP
mbed_official 76:aeb1df146756 728 * @param OB_STDBY: Reset event when entering Standby mode.
mbed_official 76:aeb1df146756 729 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 730 * @arg OB_STDBY_NoRST: No reset generated when entering in STANDBY
mbed_official 76:aeb1df146756 731 * @arg OB_STDBY_RST: Reset generated when entering in STANDBY
mbed_official 76:aeb1df146756 732 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 733 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 734 */
mbed_official 76:aeb1df146756 735 FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY)
mbed_official 76:aeb1df146756 736 {
mbed_official 76:aeb1df146756 737 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 738
mbed_official 76:aeb1df146756 739 /* Check the parameters */
mbed_official 76:aeb1df146756 740 assert_param(IS_OB_IWDG_SOURCE(OB_IWDG));
mbed_official 76:aeb1df146756 741 assert_param(IS_OB_STOP_SOURCE(OB_STOP));
mbed_official 76:aeb1df146756 742 assert_param(IS_OB_STDBY_SOURCE(OB_STDBY));
mbed_official 76:aeb1df146756 743
mbed_official 76:aeb1df146756 744 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 745 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 746
mbed_official 76:aeb1df146756 747 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 748 {
mbed_official 76:aeb1df146756 749 /* Enable the Option Bytes Programming operation */
mbed_official 76:aeb1df146756 750 FLASH->CR |= FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 751
mbed_official 76:aeb1df146756 752 OB->USER = (uint16_t)((uint16_t)(OB_IWDG | OB_STOP) | (uint16_t)(OB_STDBY | 0xF8));
mbed_official 76:aeb1df146756 753
mbed_official 76:aeb1df146756 754 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 755 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 756
mbed_official 76:aeb1df146756 757 if(status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 758 {
mbed_official 76:aeb1df146756 759 /* If the program operation is completed, disable the OPTPG Bit */
mbed_official 76:aeb1df146756 760 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 761 }
mbed_official 76:aeb1df146756 762 }
mbed_official 76:aeb1df146756 763 /* Return the Option Byte program Status */
mbed_official 76:aeb1df146756 764 return status;
mbed_official 76:aeb1df146756 765 }
mbed_official 76:aeb1df146756 766
mbed_official 76:aeb1df146756 767 /**
mbed_official 76:aeb1df146756 768 * @brief Sets or resets the BOOT1 option bit.
mbed_official 76:aeb1df146756 769 * @param OB_BOOT1: Set or Reset the BOOT1 option bit.
mbed_official 76:aeb1df146756 770 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 771 * @arg OB_BOOT1_RESET: BOOT1 option bit reset
mbed_official 76:aeb1df146756 772 * @arg OB_BOOT1_SET: BOOT1 option bit set
mbed_official 76:aeb1df146756 773 * @retval None
mbed_official 76:aeb1df146756 774 */
mbed_official 76:aeb1df146756 775 FLASH_Status FLASH_OB_BOOTConfig(uint8_t OB_BOOT1)
mbed_official 76:aeb1df146756 776 {
mbed_official 76:aeb1df146756 777 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 778
mbed_official 76:aeb1df146756 779 /* Check the parameters */
mbed_official 76:aeb1df146756 780 assert_param(IS_OB_BOOT1(OB_BOOT1));
mbed_official 76:aeb1df146756 781
mbed_official 76:aeb1df146756 782 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 783 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 784
mbed_official 76:aeb1df146756 785 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 786 {
mbed_official 76:aeb1df146756 787 /* Enable the Option Bytes Programming operation */
mbed_official 76:aeb1df146756 788 FLASH->CR |= FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 789
mbed_official 76:aeb1df146756 790 OB->USER = OB_BOOT1 | 0xEF;
mbed_official 76:aeb1df146756 791
mbed_official 76:aeb1df146756 792 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 793 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 794
mbed_official 76:aeb1df146756 795 if(status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 796 {
mbed_official 76:aeb1df146756 797 /* If the program operation is completed, disable the OPTPG Bit */
mbed_official 76:aeb1df146756 798 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 799 }
mbed_official 76:aeb1df146756 800 }
mbed_official 76:aeb1df146756 801 /* Return the Option Byte program Status */
mbed_official 76:aeb1df146756 802 return status;
mbed_official 76:aeb1df146756 803 }
mbed_official 76:aeb1df146756 804
mbed_official 76:aeb1df146756 805 /**
mbed_official 76:aeb1df146756 806 * @brief Sets or resets the BOOT0 option bit.
mbed_official 76:aeb1df146756 807 * @note This function is applicable only for the STM32F042 devices.
mbed_official 76:aeb1df146756 808 * @param OB_BOOT0: Set or Reset the BOOT0 option bit.
mbed_official 76:aeb1df146756 809 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 810 * @arg OB_BOOT0_RESET: BOOT0 option bit reset
mbed_official 76:aeb1df146756 811 * @arg OB_BOOT0_SET: BOOT0 option bit set
mbed_official 76:aeb1df146756 812 * @retval None
mbed_official 76:aeb1df146756 813 */
mbed_official 76:aeb1df146756 814 FLASH_Status FLASH_OB_BOOT0Config(uint8_t OB_BOOT0)
mbed_official 76:aeb1df146756 815 {
mbed_official 76:aeb1df146756 816 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 817
mbed_official 76:aeb1df146756 818 /* Check the parameters */
mbed_official 76:aeb1df146756 819 assert_param(IS_OB_BOOT0(OB_BOOT0));
mbed_official 76:aeb1df146756 820
mbed_official 76:aeb1df146756 821 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 822 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 823
mbed_official 76:aeb1df146756 824 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 825 {
mbed_official 76:aeb1df146756 826 /* Enable the Option Bytes Programming operation */
mbed_official 76:aeb1df146756 827 FLASH->CR |= FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 828
mbed_official 76:aeb1df146756 829 OB->USER = OB_BOOT0 | 0xF7;
mbed_official 76:aeb1df146756 830
mbed_official 76:aeb1df146756 831 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 832 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 833
mbed_official 76:aeb1df146756 834 if(status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 835 {
mbed_official 76:aeb1df146756 836 /* If the program operation is completed, disable the OPTPG Bit */
mbed_official 76:aeb1df146756 837 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 838 }
mbed_official 76:aeb1df146756 839 }
mbed_official 76:aeb1df146756 840 /* Return the Option Byte program Status */
mbed_official 76:aeb1df146756 841 return status;
mbed_official 76:aeb1df146756 842 }
mbed_official 76:aeb1df146756 843
mbed_official 76:aeb1df146756 844 /**
mbed_official 76:aeb1df146756 845 * @brief Sets or resets the BOOT0SW option bit.
mbed_official 76:aeb1df146756 846 * @note This function is applicable only for the STM32F042 devices.
mbed_official 76:aeb1df146756 847 * @param OB_BOOT0SW: Set or Reset the BOOT0_SW option bit.
mbed_official 76:aeb1df146756 848 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 849 * @arg OB_BOOT0_SW: BOOT0_SW option bit reset
mbed_official 76:aeb1df146756 850 * @arg OB_BOOT0_HW: BOOT0_SW option bit set
mbed_official 76:aeb1df146756 851 * @retval None
mbed_official 76:aeb1df146756 852 */
mbed_official 76:aeb1df146756 853 FLASH_Status FLASH_OB_BOOT0SWConfig(uint8_t OB_BOOT0SW)
mbed_official 76:aeb1df146756 854 {
mbed_official 76:aeb1df146756 855 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 856
mbed_official 76:aeb1df146756 857 /* Check the parameters */
mbed_official 76:aeb1df146756 858 assert_param(IS_OB_BOOT0SW(OB_BOOT0SW));
mbed_official 76:aeb1df146756 859
mbed_official 76:aeb1df146756 860 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 861 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 862
mbed_official 76:aeb1df146756 863 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 864 {
mbed_official 76:aeb1df146756 865 /* Enable the Option Bytes Programming operation */
mbed_official 76:aeb1df146756 866 FLASH->CR |= FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 867
mbed_official 76:aeb1df146756 868 OB->USER = OB_BOOT0SW | 0x7F;
mbed_official 76:aeb1df146756 869
mbed_official 76:aeb1df146756 870 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 871 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 872
mbed_official 76:aeb1df146756 873 if(status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 874 {
mbed_official 76:aeb1df146756 875 /* If the program operation is completed, disable the OPTPG Bit */
mbed_official 76:aeb1df146756 876 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 877 }
mbed_official 76:aeb1df146756 878 }
mbed_official 76:aeb1df146756 879 /* Return the Option Byte program Status */
mbed_official 76:aeb1df146756 880 return status;
mbed_official 76:aeb1df146756 881 }
mbed_official 76:aeb1df146756 882
mbed_official 76:aeb1df146756 883 /**
mbed_official 76:aeb1df146756 884 * @brief Sets or resets the analogue monitoring on VDDA Power source.
mbed_official 76:aeb1df146756 885 * @param OB_VDDA_ANALOG: Selects the analog monitoring on VDDA Power source.
mbed_official 76:aeb1df146756 886 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 887 * @arg OB_VDDA_ANALOG_ON: Analog monitoring on VDDA Power source ON
mbed_official 76:aeb1df146756 888 * @arg OB_VDDA_ANALOG_OFF: Analog monitoring on VDDA Power source OFF
mbed_official 76:aeb1df146756 889 * @retval None
mbed_official 76:aeb1df146756 890 */
mbed_official 76:aeb1df146756 891 FLASH_Status FLASH_OB_VDDAConfig(uint8_t OB_VDDA_ANALOG)
mbed_official 76:aeb1df146756 892 {
mbed_official 76:aeb1df146756 893 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 894
mbed_official 76:aeb1df146756 895 /* Check the parameters */
mbed_official 76:aeb1df146756 896 assert_param(IS_OB_VDDA_ANALOG(OB_VDDA_ANALOG));
mbed_official 76:aeb1df146756 897
mbed_official 76:aeb1df146756 898 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 899 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 900
mbed_official 76:aeb1df146756 901 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 902 {
mbed_official 76:aeb1df146756 903 /* Enable the Option Bytes Programming operation */
mbed_official 76:aeb1df146756 904 FLASH->CR |= FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 905
mbed_official 76:aeb1df146756 906 OB->USER = OB_VDDA_ANALOG | 0xDF;
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_TIMEOUT)
mbed_official 76:aeb1df146756 912 {
mbed_official 76:aeb1df146756 913 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 76:aeb1df146756 914 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 915 }
mbed_official 76:aeb1df146756 916 }
mbed_official 76:aeb1df146756 917 /* Return the Option Byte program Status */
mbed_official 76:aeb1df146756 918 return status;
mbed_official 76:aeb1df146756 919 }
mbed_official 76:aeb1df146756 920
mbed_official 76:aeb1df146756 921 /**
mbed_official 76:aeb1df146756 922 * @brief Sets or resets the SRAM parity.
mbed_official 76:aeb1df146756 923 * @param OB_SRAM_Parity: Set or Reset the SRAM parity enable bit.
mbed_official 76:aeb1df146756 924 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 925 * @arg OB_SRAM_PARITY_SET: Set SRAM parity.
mbed_official 76:aeb1df146756 926 * @arg OB_SRAM_PARITY_RESET: Reset SRAM parity.
mbed_official 76:aeb1df146756 927 * @retval None
mbed_official 76:aeb1df146756 928 */
mbed_official 76:aeb1df146756 929 FLASH_Status FLASH_OB_SRAMParityConfig(uint8_t OB_SRAM_Parity)
mbed_official 76:aeb1df146756 930 {
mbed_official 76:aeb1df146756 931 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 932
mbed_official 76:aeb1df146756 933 /* Check the parameters */
mbed_official 76:aeb1df146756 934 assert_param(IS_OB_SRAM_PARITY(OB_SRAM_Parity));
mbed_official 76:aeb1df146756 935
mbed_official 76:aeb1df146756 936 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 937 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 938
mbed_official 76:aeb1df146756 939 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 940 {
mbed_official 76:aeb1df146756 941 /* Enable the Option Bytes Programming operation */
mbed_official 76:aeb1df146756 942 FLASH->CR |= FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 943
mbed_official 76:aeb1df146756 944 OB->USER = OB_SRAM_Parity | 0xBF;
mbed_official 76:aeb1df146756 945
mbed_official 76:aeb1df146756 946 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 947 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 948
mbed_official 76:aeb1df146756 949 if(status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 950 {
mbed_official 76:aeb1df146756 951 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 76:aeb1df146756 952 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 953 }
mbed_official 76:aeb1df146756 954 }
mbed_official 76:aeb1df146756 955 /* Return the Option Byte program Status */
mbed_official 76:aeb1df146756 956 return status;
mbed_official 76:aeb1df146756 957 }
mbed_official 76:aeb1df146756 958
mbed_official 76:aeb1df146756 959 /**
mbed_official 76:aeb1df146756 960 * @brief Programs the FLASH User Option Byte: IWDG_SW, RST_STOP, RST_STDBY,
mbed_official 76:aeb1df146756 961 * BOOT1 and VDDA ANALOG monitoring.
mbed_official 76:aeb1df146756 962 * @note To correctly run this function, the FLASH_OB_Unlock() function must be called before.
mbed_official 76:aeb1df146756 963 * @note Call the FLASH_OB_Lock() to disable the flash control register access and the option
mbed_official 76:aeb1df146756 964 * bytes (recommended to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 965 * @param OB_USER: Selects all user option bytes
mbed_official 76:aeb1df146756 966 * This parameter is a combination of the following values:
mbed_official 76:aeb1df146756 967 * @arg OB_IWDG_SW / OB_IWDG_HW: Software / Hardware WDG selected
mbed_official 76:aeb1df146756 968 * @arg OB_STOP_NoRST / OB_STOP_RST: No reset / Reset generated when entering in STOP
mbed_official 76:aeb1df146756 969 * @arg OB_STDBY_NoRST / OB_STDBY_RST: No reset / Reset generated when entering in STANDBY
mbed_official 76:aeb1df146756 970 * @arg OB_BOOT1_RESET / OB_BOOT1_SET: BOOT1 Reset / Set
mbed_official 76:aeb1df146756 971 * @arg OB_VDDA_ANALOG_ON / OB_VDDA_ANALOG_OFF: Analog monitoring on VDDA Power source ON / OFF
mbed_official 76:aeb1df146756 972 * @arg OB_SRAM_PARITY_SET / OB_SRAM_PARITY_RESET: SRAM Parity SET / RESET
mbed_official 76:aeb1df146756 973 * @arg OB_BOOT0_RESET / OB_BOOT0_SET: BOOT0 Reset / Set
mbed_official 76:aeb1df146756 974 * @arg OB_BOOT0_SW / OB_BOOT0_SW: BOOT0 pin disabled / BOOT0 pin bonded with GPIO
mbed_official 76:aeb1df146756 975 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 976 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 977 */
mbed_official 76:aeb1df146756 978 FLASH_Status FLASH_OB_WriteUser(uint8_t OB_USER)
mbed_official 76:aeb1df146756 979 {
mbed_official 76:aeb1df146756 980 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 981
mbed_official 76:aeb1df146756 982 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 983 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 984
mbed_official 76:aeb1df146756 985 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 986 {
mbed_official 76:aeb1df146756 987 /* Enable the Option Bytes Programming operation */
mbed_official 76:aeb1df146756 988 FLASH->CR |= FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 989
mbed_official 76:aeb1df146756 990 OB->USER = OB_USER;
mbed_official 76:aeb1df146756 991
mbed_official 76:aeb1df146756 992 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 993 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 994
mbed_official 76:aeb1df146756 995 if(status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 996 {
mbed_official 76:aeb1df146756 997 /* If the program operation is completed, disable the OPTPG Bit */
mbed_official 76:aeb1df146756 998 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 999 }
mbed_official 76:aeb1df146756 1000 }
mbed_official 76:aeb1df146756 1001 /* Return the Option Byte program Status */
mbed_official 76:aeb1df146756 1002 return status;
mbed_official 76:aeb1df146756 1003
mbed_official 76:aeb1df146756 1004 }
mbed_official 76:aeb1df146756 1005
mbed_official 76:aeb1df146756 1006 /**
mbed_official 76:aeb1df146756 1007 * @brief Programs a half word at a specified Option Byte Data address.
mbed_official 76:aeb1df146756 1008 * @note To correctly run this function, the FLASH_OB_Unlock() function must be called before.
mbed_official 76:aeb1df146756 1009 * @note Call the FLASH_OB_Lock() to disable the flash control register access and the option
mbed_official 76:aeb1df146756 1010 * bytes (recommended to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 1011 * @param Address: specifies the address to be programmed.
mbed_official 76:aeb1df146756 1012 * This parameter can be 0x1FFFF804 or 0x1FFFF806.
mbed_official 76:aeb1df146756 1013 * @param Data: specifies the data to be programmed.
mbed_official 76:aeb1df146756 1014 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 76:aeb1df146756 1015 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1016 */
mbed_official 76:aeb1df146756 1017 FLASH_Status FLASH_OB_ProgramData(uint32_t Address, uint8_t Data)
mbed_official 76:aeb1df146756 1018 {
mbed_official 76:aeb1df146756 1019 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1020 /* Check the parameters */
mbed_official 76:aeb1df146756 1021 assert_param(IS_OB_DATA_ADDRESS(Address));
mbed_official 76:aeb1df146756 1022 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1023
mbed_official 76:aeb1df146756 1024 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 1025 {
mbed_official 76:aeb1df146756 1026 /* Enables the Option Bytes Programming operation */
mbed_official 76:aeb1df146756 1027 FLASH->CR |= FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 1028 *(__IO uint16_t*)Address = Data;
mbed_official 76:aeb1df146756 1029
mbed_official 76:aeb1df146756 1030 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1031 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1032
mbed_official 76:aeb1df146756 1033 if(status != FLASH_TIMEOUT)
mbed_official 76:aeb1df146756 1034 {
mbed_official 76:aeb1df146756 1035 /* If the program operation is completed, disable the OPTPG Bit */
mbed_official 76:aeb1df146756 1036 FLASH->CR &= ~FLASH_CR_OPTPG;
mbed_official 76:aeb1df146756 1037 }
mbed_official 76:aeb1df146756 1038 }
mbed_official 76:aeb1df146756 1039 /* Return the Option Byte Data Program Status */
mbed_official 76:aeb1df146756 1040 return status;
mbed_official 76:aeb1df146756 1041 }
mbed_official 76:aeb1df146756 1042
mbed_official 76:aeb1df146756 1043 /**
mbed_official 76:aeb1df146756 1044 * @brief Returns the FLASH User Option Bytes values.
mbed_official 76:aeb1df146756 1045 * @param None
mbed_official 76:aeb1df146756 1046 * @retval The FLASH User Option Bytes .
mbed_official 76:aeb1df146756 1047 */
mbed_official 76:aeb1df146756 1048 uint8_t FLASH_OB_GetUser(void)
mbed_official 76:aeb1df146756 1049 {
mbed_official 76:aeb1df146756 1050 /* Return the User Option Byte */
mbed_official 76:aeb1df146756 1051 return (uint8_t)(FLASH->OBR >> 8);
mbed_official 76:aeb1df146756 1052 }
mbed_official 76:aeb1df146756 1053
mbed_official 76:aeb1df146756 1054 /**
mbed_official 76:aeb1df146756 1055 * @brief Returns the FLASH Write Protection Option Bytes value.
mbed_official 76:aeb1df146756 1056 * @param None
mbed_official 76:aeb1df146756 1057 * @retval The FLASH Write Protection Option Bytes value
mbed_official 76:aeb1df146756 1058 */
mbed_official 76:aeb1df146756 1059 uint32_t FLASH_OB_GetWRP(void)
mbed_official 76:aeb1df146756 1060 {
mbed_official 76:aeb1df146756 1061 /* Return the FLASH write protection Register value */
mbed_official 76:aeb1df146756 1062 return (uint32_t)(FLASH->WRPR);
mbed_official 76:aeb1df146756 1063 }
mbed_official 76:aeb1df146756 1064
mbed_official 76:aeb1df146756 1065 /**
mbed_official 76:aeb1df146756 1066 * @brief Checks whether the FLASH Read out Protection Status is set or not.
mbed_official 76:aeb1df146756 1067 * @param None
mbed_official 76:aeb1df146756 1068 * @retval FLASH ReadOut Protection Status(SET or RESET)
mbed_official 76:aeb1df146756 1069 */
mbed_official 76:aeb1df146756 1070 FlagStatus FLASH_OB_GetRDP(void)
mbed_official 76:aeb1df146756 1071 {
mbed_official 76:aeb1df146756 1072 FlagStatus readstatus = RESET;
mbed_official 76:aeb1df146756 1073
mbed_official 76:aeb1df146756 1074 if ((uint8_t)(FLASH->OBR & (FLASH_OBR_RDPRT1 | FLASH_OBR_RDPRT2)) != RESET)
mbed_official 76:aeb1df146756 1075 {
mbed_official 76:aeb1df146756 1076 readstatus = SET;
mbed_official 76:aeb1df146756 1077 }
mbed_official 76:aeb1df146756 1078 else
mbed_official 76:aeb1df146756 1079 {
mbed_official 76:aeb1df146756 1080 readstatus = RESET;
mbed_official 76:aeb1df146756 1081 }
mbed_official 76:aeb1df146756 1082 return readstatus;
mbed_official 76:aeb1df146756 1083 }
mbed_official 76:aeb1df146756 1084
mbed_official 76:aeb1df146756 1085 /**
mbed_official 76:aeb1df146756 1086 * @}
mbed_official 76:aeb1df146756 1087 */
mbed_official 76:aeb1df146756 1088
mbed_official 76:aeb1df146756 1089 /** @defgroup FLASH_Group4 Interrupts and flags management functions
mbed_official 76:aeb1df146756 1090 * @brief Interrupts and flags management functions
mbed_official 76:aeb1df146756 1091 *
mbed_official 76:aeb1df146756 1092 @verbatim
mbed_official 76:aeb1df146756 1093 ===============================================================================
mbed_official 76:aeb1df146756 1094 ##### Interrupts and flags management functions #####
mbed_official 76:aeb1df146756 1095 ===============================================================================
mbed_official 76:aeb1df146756 1096
mbed_official 76:aeb1df146756 1097 @endverbatim
mbed_official 76:aeb1df146756 1098 * @{
mbed_official 76:aeb1df146756 1099 */
mbed_official 76:aeb1df146756 1100
mbed_official 76:aeb1df146756 1101 /**
mbed_official 76:aeb1df146756 1102 * @brief Enables or disables the specified FLASH interrupts.
mbed_official 76:aeb1df146756 1103 * @param FLASH_IT: specifies the FLASH interrupt sources to be enabled or
mbed_official 76:aeb1df146756 1104 * disabled.
mbed_official 76:aeb1df146756 1105 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1106 * @arg FLASH_IT_EOP: FLASH end of programming Interrupt
mbed_official 76:aeb1df146756 1107 * @arg FLASH_IT_ERR: FLASH Error Interrupt
mbed_official 76:aeb1df146756 1108 * @retval None
mbed_official 76:aeb1df146756 1109 */
mbed_official 76:aeb1df146756 1110 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)
mbed_official 76:aeb1df146756 1111 {
mbed_official 76:aeb1df146756 1112 /* Check the parameters */
mbed_official 76:aeb1df146756 1113 assert_param(IS_FLASH_IT(FLASH_IT));
mbed_official 76:aeb1df146756 1114 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1115
mbed_official 76:aeb1df146756 1116 if(NewState != DISABLE)
mbed_official 76:aeb1df146756 1117 {
mbed_official 76:aeb1df146756 1118 /* Enable the interrupt sources */
mbed_official 76:aeb1df146756 1119 FLASH->CR |= FLASH_IT;
mbed_official 76:aeb1df146756 1120 }
mbed_official 76:aeb1df146756 1121 else
mbed_official 76:aeb1df146756 1122 {
mbed_official 76:aeb1df146756 1123 /* Disable the interrupt sources */
mbed_official 76:aeb1df146756 1124 FLASH->CR &= ~(uint32_t)FLASH_IT;
mbed_official 76:aeb1df146756 1125 }
mbed_official 76:aeb1df146756 1126 }
mbed_official 76:aeb1df146756 1127
mbed_official 76:aeb1df146756 1128 /**
mbed_official 76:aeb1df146756 1129 * @brief Checks whether the specified FLASH flag is set or not.
mbed_official 76:aeb1df146756 1130 * @param FLASH_FLAG: specifies the FLASH flag to check.
mbed_official 76:aeb1df146756 1131 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1132 * @arg FLASH_FLAG_BSY: FLASH write/erase operations in progress flag
mbed_official 76:aeb1df146756 1133 * @arg FLASH_FLAG_PGERR: FLASH Programming error flag flag
mbed_official 76:aeb1df146756 1134 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
mbed_official 76:aeb1df146756 1135 * @arg FLASH_FLAG_EOP: FLASH End of Programming flag
mbed_official 76:aeb1df146756 1136 * @retval The new state of FLASH_FLAG (SET or RESET).
mbed_official 76:aeb1df146756 1137 */
mbed_official 76:aeb1df146756 1138 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)
mbed_official 76:aeb1df146756 1139 {
mbed_official 76:aeb1df146756 1140 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 1141
mbed_official 76:aeb1df146756 1142 /* Check the parameters */
mbed_official 76:aeb1df146756 1143 assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG));
mbed_official 76:aeb1df146756 1144
mbed_official 76:aeb1df146756 1145 if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 1146 {
mbed_official 76:aeb1df146756 1147 bitstatus = SET;
mbed_official 76:aeb1df146756 1148 }
mbed_official 76:aeb1df146756 1149 else
mbed_official 76:aeb1df146756 1150 {
mbed_official 76:aeb1df146756 1151 bitstatus = RESET;
mbed_official 76:aeb1df146756 1152 }
mbed_official 76:aeb1df146756 1153 /* Return the new state of FLASH_FLAG (SET or RESET) */
mbed_official 76:aeb1df146756 1154 return bitstatus;
mbed_official 76:aeb1df146756 1155 }
mbed_official 76:aeb1df146756 1156
mbed_official 76:aeb1df146756 1157 /**
mbed_official 76:aeb1df146756 1158 * @brief Clears the FLASH's pending flags.
mbed_official 76:aeb1df146756 1159 * @param FLASH_FLAG: specifies the FLASH flags to clear.
mbed_official 76:aeb1df146756 1160 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1161 * @arg FLASH_FLAG_PGERR: FLASH Programming error flag flag
mbed_official 76:aeb1df146756 1162 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
mbed_official 76:aeb1df146756 1163 * @arg FLASH_FLAG_EOP: FLASH End of Programming flag
mbed_official 76:aeb1df146756 1164 * @retval None
mbed_official 76:aeb1df146756 1165 */
mbed_official 76:aeb1df146756 1166 void FLASH_ClearFlag(uint32_t FLASH_FLAG)
mbed_official 76:aeb1df146756 1167 {
mbed_official 76:aeb1df146756 1168 /* Check the parameters */
mbed_official 76:aeb1df146756 1169 assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG));
mbed_official 76:aeb1df146756 1170
mbed_official 76:aeb1df146756 1171 /* Clear the flags */
mbed_official 76:aeb1df146756 1172 FLASH->SR = FLASH_FLAG;
mbed_official 76:aeb1df146756 1173 }
mbed_official 76:aeb1df146756 1174
mbed_official 76:aeb1df146756 1175 /**
mbed_official 76:aeb1df146756 1176 * @brief Returns the FLASH Status.
mbed_official 76:aeb1df146756 1177 * @param None
mbed_official 76:aeb1df146756 1178 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1179 * FLASH_BUSY, FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP or FLASH_COMPLETE.
mbed_official 76:aeb1df146756 1180 */
mbed_official 76:aeb1df146756 1181 FLASH_Status FLASH_GetStatus(void)
mbed_official 76:aeb1df146756 1182 {
mbed_official 76:aeb1df146756 1183 FLASH_Status FLASHstatus = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1184
mbed_official 76:aeb1df146756 1185 if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY)
mbed_official 76:aeb1df146756 1186 {
mbed_official 76:aeb1df146756 1187 FLASHstatus = FLASH_BUSY;
mbed_official 76:aeb1df146756 1188 }
mbed_official 76:aeb1df146756 1189 else
mbed_official 76:aeb1df146756 1190 {
mbed_official 76:aeb1df146756 1191 if((FLASH->SR & (uint32_t)FLASH_FLAG_WRPERR)!= (uint32_t)0x00)
mbed_official 76:aeb1df146756 1192 {
mbed_official 76:aeb1df146756 1193 FLASHstatus = FLASH_ERROR_WRP;
mbed_official 76:aeb1df146756 1194 }
mbed_official 76:aeb1df146756 1195 else
mbed_official 76:aeb1df146756 1196 {
mbed_official 76:aeb1df146756 1197 if((FLASH->SR & (uint32_t)(FLASH_SR_PGERR)) != (uint32_t)0x00)
mbed_official 76:aeb1df146756 1198 {
mbed_official 76:aeb1df146756 1199 FLASHstatus = FLASH_ERROR_PROGRAM;
mbed_official 76:aeb1df146756 1200 }
mbed_official 76:aeb1df146756 1201 else
mbed_official 76:aeb1df146756 1202 {
mbed_official 76:aeb1df146756 1203 FLASHstatus = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1204 }
mbed_official 76:aeb1df146756 1205 }
mbed_official 76:aeb1df146756 1206 }
mbed_official 76:aeb1df146756 1207 /* Return the FLASH Status */
mbed_official 76:aeb1df146756 1208 return FLASHstatus;
mbed_official 76:aeb1df146756 1209 }
mbed_official 76:aeb1df146756 1210
mbed_official 76:aeb1df146756 1211
mbed_official 76:aeb1df146756 1212 /**
mbed_official 76:aeb1df146756 1213 * @brief Waits for a FLASH operation to complete or a TIMEOUT to occur.
mbed_official 76:aeb1df146756 1214 * @param Timeout: FLASH programming Timeout
mbed_official 76:aeb1df146756 1215 * @retval FLASH Status: The returned value can be: FLASH_BUSY,
mbed_official 76:aeb1df146756 1216 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1217 */
mbed_official 76:aeb1df146756 1218 FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout)
mbed_official 76:aeb1df146756 1219 {
mbed_official 76:aeb1df146756 1220 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1221
mbed_official 76:aeb1df146756 1222 /* Check for the FLASH Status */
mbed_official 76:aeb1df146756 1223 status = FLASH_GetStatus();
mbed_official 76:aeb1df146756 1224
mbed_official 76:aeb1df146756 1225 /* Wait for a FLASH operation to complete or a TIMEOUT to occur */
mbed_official 76:aeb1df146756 1226 while((status == FLASH_BUSY) && (Timeout != 0x00))
mbed_official 76:aeb1df146756 1227 {
mbed_official 76:aeb1df146756 1228 status = FLASH_GetStatus();
mbed_official 76:aeb1df146756 1229 Timeout--;
mbed_official 76:aeb1df146756 1230 }
mbed_official 76:aeb1df146756 1231
mbed_official 76:aeb1df146756 1232 if(Timeout == 0x00 )
mbed_official 76:aeb1df146756 1233 {
mbed_official 76:aeb1df146756 1234 status = FLASH_TIMEOUT;
mbed_official 76:aeb1df146756 1235 }
mbed_official 76:aeb1df146756 1236 /* Return the operation status */
mbed_official 76:aeb1df146756 1237 return status;
mbed_official 76:aeb1df146756 1238 }
mbed_official 76:aeb1df146756 1239
mbed_official 76:aeb1df146756 1240 /**
mbed_official 76:aeb1df146756 1241 * @}
mbed_official 76:aeb1df146756 1242 */
mbed_official 76:aeb1df146756 1243
mbed_official 76:aeb1df146756 1244 /**
mbed_official 76:aeb1df146756 1245 * @}
mbed_official 76:aeb1df146756 1246 */
mbed_official 76:aeb1df146756 1247
mbed_official 76:aeb1df146756 1248 /**
mbed_official 76:aeb1df146756 1249 * @}
mbed_official 76:aeb1df146756 1250 */
mbed_official 76:aeb1df146756 1251
mbed_official 76:aeb1df146756 1252 /**
mbed_official 76:aeb1df146756 1253 * @}
mbed_official 76:aeb1df146756 1254 */
mbed_official 76:aeb1df146756 1255
mbed_official 76:aeb1df146756 1256 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/