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