mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_flash_ex.c@489:119543c9f674, 2015-03-12 (annotated)
- Committer:
- mbed_official
- Date:
- Thu Mar 12 14:30:49 2015 +0000
- Revision:
- 489:119543c9f674
- Parent:
- 382:ee426a420dbb
Synchronized with git revision 051854181516992fb498d51f9ee6e70cbad9e083
Full URL: https://github.com/mbedmicro/mbed/commit/051854181516992fb498d51f9ee6e70cbad9e083/
Fix ksdk mcu HAL - stopbit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 376:cb4d9db17537 | 1 | /** |
mbed_official | 376:cb4d9db17537 | 2 | ****************************************************************************** |
mbed_official | 376:cb4d9db17537 | 3 | * @file stm32l0xx_hal_flash_ex.c |
mbed_official | 376:cb4d9db17537 | 4 | * @author MCD Application Team |
mbed_official | 489:119543c9f674 | 5 | * @version V1.2.0 |
mbed_official | 489:119543c9f674 | 6 | * @date 06-February-2015 |
mbed_official | 376:cb4d9db17537 | 7 | * @brief FLASH HAL module driver. |
mbed_official | 376:cb4d9db17537 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 376:cb4d9db17537 | 9 | * functionalities of the internal FLASH memory: |
mbed_official | 376:cb4d9db17537 | 10 | * + FLASH Interface configuration |
mbed_official | 489:119543c9f674 | 11 | * + FLASH Memory Erasing |
mbed_official | 489:119543c9f674 | 12 | * + DATA EEPROM Programming/Erasing |
mbed_official | 376:cb4d9db17537 | 13 | * + Option Bytes Programming |
mbed_official | 489:119543c9f674 | 14 | * + Interrupts management |
mbed_official | 376:cb4d9db17537 | 15 | * |
mbed_official | 376:cb4d9db17537 | 16 | * @verbatim |
mbed_official | 376:cb4d9db17537 | 17 | ============================================================================== |
mbed_official | 376:cb4d9db17537 | 18 | ##### Flash peripheral Extended features ##### |
mbed_official | 376:cb4d9db17537 | 19 | ============================================================================== |
mbed_official | 376:cb4d9db17537 | 20 | |
mbed_official | 376:cb4d9db17537 | 21 | [..] Comparing to other products, the FLASH interface for STM32L0xx |
mbed_official | 376:cb4d9db17537 | 22 | devices contains the following additional features |
mbed_official | 489:119543c9f674 | 23 | (+) Erase functions |
mbed_official | 376:cb4d9db17537 | 24 | (+) DATA_EEPROM memory management |
mbed_official | 376:cb4d9db17537 | 25 | (+) BOOT option bit configuration |
mbed_official | 376:cb4d9db17537 | 26 | (+) PCROP protection for all sectors |
mbed_official | 376:cb4d9db17537 | 27 | |
mbed_official | 376:cb4d9db17537 | 28 | ##### How to use this driver ##### |
mbed_official | 376:cb4d9db17537 | 29 | ============================================================================== |
mbed_official | 376:cb4d9db17537 | 30 | [..] This driver provides functions to configure and program the FLASH memory |
mbed_official | 376:cb4d9db17537 | 31 | of all STM32L0xx. It includes: |
mbed_official | 376:cb4d9db17537 | 32 | (+) Full DATA_EEPROM erase and program management |
mbed_official | 376:cb4d9db17537 | 33 | (+) Boot activation |
mbed_official | 489:119543c9f674 | 34 | (+) PCROP protection configuration and control for all sectors |
mbed_official | 376:cb4d9db17537 | 35 | |
mbed_official | 376:cb4d9db17537 | 36 | @endverbatim |
mbed_official | 376:cb4d9db17537 | 37 | ****************************************************************************** |
mbed_official | 376:cb4d9db17537 | 38 | * @attention |
mbed_official | 376:cb4d9db17537 | 39 | * |
mbed_official | 489:119543c9f674 | 40 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
mbed_official | 376:cb4d9db17537 | 41 | * |
mbed_official | 376:cb4d9db17537 | 42 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 376:cb4d9db17537 | 43 | * are permitted provided that the following conditions are met: |
mbed_official | 376:cb4d9db17537 | 44 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 376:cb4d9db17537 | 45 | * this list of conditions and the following disclaimer. |
mbed_official | 376:cb4d9db17537 | 46 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 376:cb4d9db17537 | 47 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 376:cb4d9db17537 | 48 | * and/or other materials provided with the distribution. |
mbed_official | 376:cb4d9db17537 | 49 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 376:cb4d9db17537 | 50 | * may be used to endorse or promote products derived from this software |
mbed_official | 376:cb4d9db17537 | 51 | * without specific prior written permission. |
mbed_official | 376:cb4d9db17537 | 52 | * |
mbed_official | 376:cb4d9db17537 | 53 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 376:cb4d9db17537 | 54 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 376:cb4d9db17537 | 55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 376:cb4d9db17537 | 56 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 376:cb4d9db17537 | 57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 376:cb4d9db17537 | 58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 376:cb4d9db17537 | 59 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 376:cb4d9db17537 | 60 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 376:cb4d9db17537 | 61 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 376:cb4d9db17537 | 62 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 376:cb4d9db17537 | 63 | * |
mbed_official | 376:cb4d9db17537 | 64 | ****************************************************************************** |
mbed_official | 376:cb4d9db17537 | 65 | */ |
mbed_official | 376:cb4d9db17537 | 66 | |
mbed_official | 376:cb4d9db17537 | 67 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 68 | #include "stm32l0xx_hal.h" |
mbed_official | 489:119543c9f674 | 69 | |
mbed_official | 489:119543c9f674 | 70 | /** @addtogroup STM32L0xx_HAL_Driver |
mbed_official | 376:cb4d9db17537 | 71 | * @{ |
mbed_official | 376:cb4d9db17537 | 72 | */ |
mbed_official | 376:cb4d9db17537 | 73 | |
mbed_official | 489:119543c9f674 | 74 | /** @addtogroup FLASHEx |
mbed_official | 376:cb4d9db17537 | 75 | * @brief FLASH HAL Extension module driver |
mbed_official | 376:cb4d9db17537 | 76 | * @{ |
mbed_official | 376:cb4d9db17537 | 77 | */ |
mbed_official | 376:cb4d9db17537 | 78 | |
mbed_official | 376:cb4d9db17537 | 79 | #ifdef HAL_FLASH_MODULE_ENABLED |
mbed_official | 376:cb4d9db17537 | 80 | |
mbed_official | 376:cb4d9db17537 | 81 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 82 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 83 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 84 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 85 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 489:119543c9f674 | 86 | static HAL_StatusTypeDef FLASH_OB_RDPConfig(uint8_t OB_RDP); |
mbed_official | 489:119543c9f674 | 87 | static HAL_StatusTypeDef FLASH_OB_BORConfig(uint8_t OB_BOR); |
mbed_official | 489:119543c9f674 | 88 | static uint8_t FLASH_OB_GetUser(void); |
mbed_official | 489:119543c9f674 | 89 | static uint8_t FLASH_OB_GetRDP(void); |
mbed_official | 489:119543c9f674 | 90 | static uint8_t FLASH_OB_GetBOR(void); |
mbed_official | 489:119543c9f674 | 91 | static uint8_t FLASH_OB_GetBOOTBit1(void); |
mbed_official | 489:119543c9f674 | 92 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 489:119543c9f674 | 93 | static HAL_StatusTypeDef FLASH_OB_ProtectedSectorsConfig(uint32_t Sector, uint32_t Sector2, uint32_t NewState); |
mbed_official | 489:119543c9f674 | 94 | #else |
mbed_official | 489:119543c9f674 | 95 | static HAL_StatusTypeDef FLASH_OB_ProtectedSectorsConfig(uint32_t Sector, uint32_t NewState); |
mbed_official | 489:119543c9f674 | 96 | #endif |
mbed_official | 489:119543c9f674 | 97 | static HAL_StatusTypeDef FLASH_OB_PCROPSelectionConfig(uint32_t WPRMOD); |
mbed_official | 489:119543c9f674 | 98 | static uint32_t FLASH_OB_GetWRP(void); |
mbed_official | 489:119543c9f674 | 99 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 489:119543c9f674 | 100 | static uint32_t FLASH_OB_GetWRP2(void); |
mbed_official | 489:119543c9f674 | 101 | #endif |
mbed_official | 376:cb4d9db17537 | 102 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY); |
mbed_official | 489:119543c9f674 | 103 | static HAL_StatusTypeDef FLASH_OB_BOOTBit1Config(uint8_t OB_BOOT_Bit1); |
mbed_official | 489:119543c9f674 | 104 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 489:119543c9f674 | 105 | static HAL_StatusTypeDef FLASH_OB_BFB2Config(uint8_t OB_BFB2); |
mbed_official | 489:119543c9f674 | 106 | #endif |
mbed_official | 489:119543c9f674 | 107 | |
mbed_official | 489:119543c9f674 | 108 | /* Exported functions ---------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 109 | |
mbed_official | 489:119543c9f674 | 110 | /** @addtogroup FLASHEx_Exported_Functions |
mbed_official | 376:cb4d9db17537 | 111 | * @{ |
mbed_official | 376:cb4d9db17537 | 112 | */ |
mbed_official | 376:cb4d9db17537 | 113 | |
mbed_official | 489:119543c9f674 | 114 | /** @addtogroup FLASHEx_Exported_Functions_Group1 |
mbed_official | 489:119543c9f674 | 115 | * @brief FLASH Memory Erasing functions |
mbed_official | 376:cb4d9db17537 | 116 | * |
mbed_official | 376:cb4d9db17537 | 117 | @verbatim |
mbed_official | 489:119543c9f674 | 118 | ============================================================================== |
mbed_official | 489:119543c9f674 | 119 | ##### FLASH Erasing Programming functions ##### |
mbed_official | 489:119543c9f674 | 120 | ============================================================================== |
mbed_official | 489:119543c9f674 | 121 | |
mbed_official | 489:119543c9f674 | 122 | [..] The FLASH Memory Erasing functions, includes the following functions: |
mbed_official | 489:119543c9f674 | 123 | (+) HAL_FLASHEx_Erase: return only when erase has been done |
mbed_official | 489:119543c9f674 | 124 | (+) HAL_FLASHEx_Erase_IT: end of erase is done when HAL_FLASH_EndOfOperationCallback is called with parameter |
mbed_official | 489:119543c9f674 | 125 | 0xFFFFFFFF |
mbed_official | 489:119543c9f674 | 126 | |
mbed_official | 489:119543c9f674 | 127 | [..] Any operation of erase should follow these steps: |
mbed_official | 489:119543c9f674 | 128 | (#) Call the HAL_FLASH_Unlock() function to enable the flash control register and |
mbed_official | 489:119543c9f674 | 129 | program memory access. |
mbed_official | 489:119543c9f674 | 130 | (#) Call the desired function to erase page. |
mbed_official | 489:119543c9f674 | 131 | (#) Call the HAL_FLASH_Lock() to disable the flash program memory access |
mbed_official | 489:119543c9f674 | 132 | (recommended to protect the FLASH memory against possible unwanted operation). |
mbed_official | 376:cb4d9db17537 | 133 | |
mbed_official | 376:cb4d9db17537 | 134 | @endverbatim |
mbed_official | 376:cb4d9db17537 | 135 | * @{ |
mbed_official | 376:cb4d9db17537 | 136 | */ |
mbed_official | 376:cb4d9db17537 | 137 | |
mbed_official | 376:cb4d9db17537 | 138 | /** |
mbed_official | 489:119543c9f674 | 139 | * @brief Erase the specified FLASH memory Pages |
mbed_official | 489:119543c9f674 | 140 | * @note To correctly run this function, the HAL_FLASH_Unlock() function |
mbed_official | 489:119543c9f674 | 141 | * must be called before. |
mbed_official | 489:119543c9f674 | 142 | * Call the HAL_FLASH_Lock() to disable the flash memory access |
mbed_official | 489:119543c9f674 | 143 | * (recommended to protect the FLASH memory against possible unwanted operation) |
mbed_official | 489:119543c9f674 | 144 | * @param[in] pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
mbed_official | 489:119543c9f674 | 145 | * contains the configuration information for the erasing. |
mbed_official | 489:119543c9f674 | 146 | * |
mbed_official | 489:119543c9f674 | 147 | * @param[out] PageError: pointer to variable that |
mbed_official | 489:119543c9f674 | 148 | * contains the configuration information on faulty sector in case of error |
mbed_official | 489:119543c9f674 | 149 | * (0xFFFFFFFF means that all the sectors have been correctly erased) |
mbed_official | 489:119543c9f674 | 150 | * |
mbed_official | 489:119543c9f674 | 151 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 489:119543c9f674 | 152 | */ |
mbed_official | 489:119543c9f674 | 153 | HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError) |
mbed_official | 489:119543c9f674 | 154 | { |
mbed_official | 489:119543c9f674 | 155 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 489:119543c9f674 | 156 | uint32_t index = 0; |
mbed_official | 489:119543c9f674 | 157 | |
mbed_official | 489:119543c9f674 | 158 | /* Process Locked */ |
mbed_official | 489:119543c9f674 | 159 | __HAL_LOCK(&ProcFlash); |
mbed_official | 489:119543c9f674 | 160 | |
mbed_official | 489:119543c9f674 | 161 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 162 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 489:119543c9f674 | 163 | |
mbed_official | 489:119543c9f674 | 164 | if (status == HAL_OK) |
mbed_official | 489:119543c9f674 | 165 | { |
mbed_official | 489:119543c9f674 | 166 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 167 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 489:119543c9f674 | 168 | |
mbed_official | 489:119543c9f674 | 169 | /*Initialization of PageError variable*/ |
mbed_official | 489:119543c9f674 | 170 | *PageError = 0xFFFFFFFF; |
mbed_official | 489:119543c9f674 | 171 | |
mbed_official | 489:119543c9f674 | 172 | /* Check the parameters */ |
mbed_official | 489:119543c9f674 | 173 | assert_param(IS_NBPAGES(pEraseInit->NbPages)); |
mbed_official | 489:119543c9f674 | 174 | assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
mbed_official | 489:119543c9f674 | 175 | assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress)); |
mbed_official | 489:119543c9f674 | 176 | assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress + pEraseInit->NbPages * FLASH_PAGE_SIZE - 1)); |
mbed_official | 489:119543c9f674 | 177 | |
mbed_official | 489:119543c9f674 | 178 | /* Erase by sector by sector to be done*/ |
mbed_official | 489:119543c9f674 | 179 | for(index = pEraseInit->PageAddress; index < ((pEraseInit->NbPages * FLASH_PAGE_SIZE)+ pEraseInit->PageAddress); index += FLASH_PAGE_SIZE) |
mbed_official | 489:119543c9f674 | 180 | { |
mbed_official | 489:119543c9f674 | 181 | FLASH_ErasePage(index); |
mbed_official | 489:119543c9f674 | 182 | |
mbed_official | 489:119543c9f674 | 183 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 184 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 489:119543c9f674 | 185 | |
mbed_official | 489:119543c9f674 | 186 | /* If the erase operation is completed, disable the ERASE Bit */ |
mbed_official | 489:119543c9f674 | 187 | CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG); |
mbed_official | 489:119543c9f674 | 188 | CLEAR_BIT(FLASH->PECR, FLASH_PECR_ERASE); |
mbed_official | 489:119543c9f674 | 189 | |
mbed_official | 489:119543c9f674 | 190 | if (status != HAL_OK) |
mbed_official | 489:119543c9f674 | 191 | { |
mbed_official | 489:119543c9f674 | 192 | /* In case of error, stop erase procedure and return the faulty sector*/ |
mbed_official | 489:119543c9f674 | 193 | *PageError = index; |
mbed_official | 489:119543c9f674 | 194 | break; |
mbed_official | 489:119543c9f674 | 195 | } |
mbed_official | 489:119543c9f674 | 196 | } |
mbed_official | 489:119543c9f674 | 197 | } |
mbed_official | 489:119543c9f674 | 198 | |
mbed_official | 489:119543c9f674 | 199 | /* Process Unlocked */ |
mbed_official | 489:119543c9f674 | 200 | __HAL_UNLOCK(&ProcFlash); |
mbed_official | 489:119543c9f674 | 201 | |
mbed_official | 489:119543c9f674 | 202 | return status; |
mbed_official | 489:119543c9f674 | 203 | } |
mbed_official | 489:119543c9f674 | 204 | |
mbed_official | 489:119543c9f674 | 205 | /** |
mbed_official | 489:119543c9f674 | 206 | * @brief Perform a page erase of the specified FLASH memory pages with interrupt enabled |
mbed_official | 489:119543c9f674 | 207 | * @note To correctly run this function, the HAL_FLASH_Unlock() function |
mbed_official | 489:119543c9f674 | 208 | * must be called before. |
mbed_official | 489:119543c9f674 | 209 | * Call the HAL_FLASH_Lock() to disable the flash memory access |
mbed_official | 489:119543c9f674 | 210 | * (recommended to protect the FLASH memory against possible unwanted operation). |
mbed_official | 489:119543c9f674 | 211 | End of erase is done when HAL_FLASH_EndOfOperationCallback is called with parameter |
mbed_official | 489:119543c9f674 | 212 | 0xFFFFFFFF |
mbed_official | 489:119543c9f674 | 213 | * @param pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
mbed_official | 489:119543c9f674 | 214 | * contains the configuration information for the erasing. |
mbed_official | 489:119543c9f674 | 215 | * |
mbed_official | 489:119543c9f674 | 216 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 489:119543c9f674 | 217 | */ |
mbed_official | 489:119543c9f674 | 218 | HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) |
mbed_official | 489:119543c9f674 | 219 | { |
mbed_official | 489:119543c9f674 | 220 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 489:119543c9f674 | 221 | |
mbed_official | 489:119543c9f674 | 222 | /* Process Locked */ |
mbed_official | 489:119543c9f674 | 223 | __HAL_LOCK(&ProcFlash); |
mbed_official | 489:119543c9f674 | 224 | |
mbed_official | 489:119543c9f674 | 225 | /* Enable End of FLASH Operation interrupt */ |
mbed_official | 489:119543c9f674 | 226 | __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP); |
mbed_official | 489:119543c9f674 | 227 | |
mbed_official | 489:119543c9f674 | 228 | /* Enable Error source interrupt */ |
mbed_official | 489:119543c9f674 | 229 | __HAL_FLASH_ENABLE_IT(FLASH_IT_ERR); |
mbed_official | 489:119543c9f674 | 230 | |
mbed_official | 489:119543c9f674 | 231 | /* Check the parameters */ |
mbed_official | 489:119543c9f674 | 232 | assert_param(IS_NBPAGES(pEraseInit->NbPages)); |
mbed_official | 489:119543c9f674 | 233 | assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
mbed_official | 489:119543c9f674 | 234 | assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress)); |
mbed_official | 489:119543c9f674 | 235 | assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress + pEraseInit->NbPages * FLASH_PAGE_SIZE - 1)); |
mbed_official | 489:119543c9f674 | 236 | |
mbed_official | 489:119543c9f674 | 237 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 238 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 489:119543c9f674 | 239 | ProcFlash.ProcedureOnGoing = FLASH_PROC_PAGEERASE; |
mbed_official | 489:119543c9f674 | 240 | ProcFlash.NbPagesToErase = pEraseInit->NbPages; |
mbed_official | 489:119543c9f674 | 241 | ProcFlash.Page = pEraseInit->PageAddress; |
mbed_official | 489:119543c9f674 | 242 | |
mbed_official | 489:119543c9f674 | 243 | /* Erase 1st page and wait for IT */ |
mbed_official | 489:119543c9f674 | 244 | FLASH_ErasePage(pEraseInit->PageAddress); |
mbed_official | 489:119543c9f674 | 245 | return status; |
mbed_official | 489:119543c9f674 | 246 | } |
mbed_official | 489:119543c9f674 | 247 | |
mbed_official | 489:119543c9f674 | 248 | /** |
mbed_official | 489:119543c9f674 | 249 | * @} |
mbed_official | 489:119543c9f674 | 250 | */ |
mbed_official | 489:119543c9f674 | 251 | |
mbed_official | 489:119543c9f674 | 252 | |
mbed_official | 489:119543c9f674 | 253 | /** @addtogroup FLASHEx_Exported_Functions_Group2 |
mbed_official | 489:119543c9f674 | 254 | * @brief Option Bytes Programming functions |
mbed_official | 489:119543c9f674 | 255 | * |
mbed_official | 489:119543c9f674 | 256 | @verbatim |
mbed_official | 489:119543c9f674 | 257 | ============================================================================== |
mbed_official | 489:119543c9f674 | 258 | ##### Option Bytes Programming functions ##### |
mbed_official | 489:119543c9f674 | 259 | ============================================================================== |
mbed_official | 489:119543c9f674 | 260 | |
mbed_official | 489:119543c9f674 | 261 | [..] Any operation of erase or program should follow these steps: |
mbed_official | 489:119543c9f674 | 262 | (#) Call the HAL_FLASH_OB_Unlock() function to enable the Flash option control |
mbed_official | 489:119543c9f674 | 263 | register access. |
mbed_official | 489:119543c9f674 | 264 | (#) Call following function to program the desired option bytes. |
mbed_official | 489:119543c9f674 | 265 | (++) HAL_FLASHEx_OBProgram: |
mbed_official | 489:119543c9f674 | 266 | - To Enable/Disable the desired sector write protection. |
mbed_official | 489:119543c9f674 | 267 | - To set the desired read Protection Level. |
mbed_official | 489:119543c9f674 | 268 | - To configure the user option Bytes: IWDG, STOP and the Standby. |
mbed_official | 489:119543c9f674 | 269 | - To Set the BOR level. |
mbed_official | 489:119543c9f674 | 270 | (#) Once all needed option bytes to be programmed are correctly written, call the |
mbed_official | 489:119543c9f674 | 271 | HAL_FLASH_OB_Launch(void) function to launch the Option Bytes programming process. |
mbed_official | 489:119543c9f674 | 272 | (#) Call the HAL_FLASH_OB_Lock() to disable the Flash option control register access (recommended |
mbed_official | 489:119543c9f674 | 273 | to protect the option Bytes against possible unwanted operations). |
mbed_official | 489:119543c9f674 | 274 | |
mbed_official | 489:119543c9f674 | 275 | [..] Proprietary code Read Out Protection (PcROP): |
mbed_official | 489:119543c9f674 | 276 | (#) The PcROP sector is selected by using the same option bytes as the Write |
mbed_official | 489:119543c9f674 | 277 | protection (nWRPi bits). As a result, these 2 options are exclusive each other. |
mbed_official | 489:119543c9f674 | 278 | (#) In order to activate the PcROP (change the function of the nWRPi option bits), |
mbed_official | 489:119543c9f674 | 279 | the WPRMOD option bit must be activated. |
mbed_official | 489:119543c9f674 | 280 | (#) The active value of nWRPi bits is inverted when PCROP mode is active, this |
mbed_official | 489:119543c9f674 | 281 | means: if WPRMOD = 1 and nWRPi = 1 (default value), then the user sector "i" |
mbed_official | 489:119543c9f674 | 282 | is read/write protected. |
mbed_official | 489:119543c9f674 | 283 | (#) To activate PCROP mode for Flash sector(s), you need to call the following function: |
mbed_official | 489:119543c9f674 | 284 | (++) HAL_FLASHEx_AdvOBProgram in selecting sectors to be read/write protected |
mbed_official | 489:119543c9f674 | 285 | (++) HAL_FLASHEx_OB_SelectPCROP to enable the read/write protection |
mbed_official | 489:119543c9f674 | 286 | @endverbatim |
mbed_official | 489:119543c9f674 | 287 | * @{ |
mbed_official | 489:119543c9f674 | 288 | */ |
mbed_official | 489:119543c9f674 | 289 | |
mbed_official | 489:119543c9f674 | 290 | /** |
mbed_official | 489:119543c9f674 | 291 | * @brief Program option bytes |
mbed_official | 489:119543c9f674 | 292 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that |
mbed_official | 489:119543c9f674 | 293 | * contains the configuration information for the programming. |
mbed_official | 489:119543c9f674 | 294 | * |
mbed_official | 489:119543c9f674 | 295 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 489:119543c9f674 | 296 | */ |
mbed_official | 489:119543c9f674 | 297 | HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) |
mbed_official | 489:119543c9f674 | 298 | { |
mbed_official | 489:119543c9f674 | 299 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 489:119543c9f674 | 300 | |
mbed_official | 489:119543c9f674 | 301 | /* Process Locked */ |
mbed_official | 489:119543c9f674 | 302 | __HAL_LOCK(&ProcFlash); |
mbed_official | 489:119543c9f674 | 303 | |
mbed_official | 489:119543c9f674 | 304 | /* Check the parameters */ |
mbed_official | 489:119543c9f674 | 305 | assert_param(IS_OPTIONBYTE(pOBInit->OptionType)); |
mbed_official | 489:119543c9f674 | 306 | |
mbed_official | 489:119543c9f674 | 307 | /* Write protection configuration */ |
mbed_official | 489:119543c9f674 | 308 | if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP) |
mbed_official | 489:119543c9f674 | 309 | { |
mbed_official | 489:119543c9f674 | 310 | assert_param(IS_WRPSTATE(pOBInit->WRPState)); |
mbed_official | 489:119543c9f674 | 311 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 489:119543c9f674 | 312 | status = FLASH_OB_ProtectedSectorsConfig(pOBInit->WRPSector, pOBInit->WRPSector2, pOBInit->WRPState); |
mbed_official | 489:119543c9f674 | 313 | #else |
mbed_official | 489:119543c9f674 | 314 | status = FLASH_OB_ProtectedSectorsConfig(pOBInit->WRPSector, pOBInit->WRPState); |
mbed_official | 489:119543c9f674 | 315 | #endif |
mbed_official | 489:119543c9f674 | 316 | if (status != HAL_OK) |
mbed_official | 489:119543c9f674 | 317 | { |
mbed_official | 489:119543c9f674 | 318 | /* Process Unlocked */ |
mbed_official | 489:119543c9f674 | 319 | __HAL_UNLOCK(&ProcFlash); |
mbed_official | 489:119543c9f674 | 320 | return status; |
mbed_official | 489:119543c9f674 | 321 | } |
mbed_official | 489:119543c9f674 | 322 | } |
mbed_official | 489:119543c9f674 | 323 | |
mbed_official | 489:119543c9f674 | 324 | /* Read protection configuration */ |
mbed_official | 489:119543c9f674 | 325 | if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) |
mbed_official | 489:119543c9f674 | 326 | { |
mbed_official | 489:119543c9f674 | 327 | status = FLASH_OB_RDPConfig(pOBInit->RDPLevel); |
mbed_official | 489:119543c9f674 | 328 | if (status != HAL_OK) |
mbed_official | 489:119543c9f674 | 329 | { |
mbed_official | 489:119543c9f674 | 330 | /* Process Unlocked */ |
mbed_official | 489:119543c9f674 | 331 | __HAL_UNLOCK(&ProcFlash); |
mbed_official | 489:119543c9f674 | 332 | return status; |
mbed_official | 489:119543c9f674 | 333 | } |
mbed_official | 489:119543c9f674 | 334 | } |
mbed_official | 489:119543c9f674 | 335 | |
mbed_official | 489:119543c9f674 | 336 | /* USER configuration */ |
mbed_official | 489:119543c9f674 | 337 | if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) |
mbed_official | 489:119543c9f674 | 338 | { |
mbed_official | 489:119543c9f674 | 339 | status = FLASH_OB_UserConfig(pOBInit->USERConfig & OB_IWDG_SW, |
mbed_official | 489:119543c9f674 | 340 | pOBInit->USERConfig & OB_STOP_NORST, |
mbed_official | 489:119543c9f674 | 341 | pOBInit->USERConfig & OB_STDBY_NORST); |
mbed_official | 489:119543c9f674 | 342 | if (status != HAL_OK) |
mbed_official | 489:119543c9f674 | 343 | { |
mbed_official | 489:119543c9f674 | 344 | /* Process Unlocked */ |
mbed_official | 489:119543c9f674 | 345 | __HAL_UNLOCK(&ProcFlash); |
mbed_official | 489:119543c9f674 | 346 | return status; |
mbed_official | 489:119543c9f674 | 347 | } |
mbed_official | 489:119543c9f674 | 348 | } |
mbed_official | 489:119543c9f674 | 349 | |
mbed_official | 489:119543c9f674 | 350 | /* BOR Level configuration */ |
mbed_official | 489:119543c9f674 | 351 | if((pOBInit->OptionType & OPTIONBYTE_BOR) == OPTIONBYTE_BOR) |
mbed_official | 489:119543c9f674 | 352 | { |
mbed_official | 489:119543c9f674 | 353 | status = FLASH_OB_BORConfig(pOBInit->BORLevel); |
mbed_official | 489:119543c9f674 | 354 | } |
mbed_official | 489:119543c9f674 | 355 | |
mbed_official | 489:119543c9f674 | 356 | /* Program BOOT Bit1 config option byte */ |
mbed_official | 489:119543c9f674 | 357 | if ((pOBInit->OptionType & OPTIONBYTE_BOOT_BIT1) == OPTIONBYTE_BOOT_BIT1) |
mbed_official | 489:119543c9f674 | 358 | { |
mbed_official | 489:119543c9f674 | 359 | status = FLASH_OB_BOOTBit1Config(pOBInit->BOOTBit1Config); |
mbed_official | 489:119543c9f674 | 360 | } |
mbed_official | 489:119543c9f674 | 361 | |
mbed_official | 489:119543c9f674 | 362 | /* Process Unlocked */ |
mbed_official | 489:119543c9f674 | 363 | __HAL_UNLOCK(&ProcFlash); |
mbed_official | 489:119543c9f674 | 364 | return status; |
mbed_official | 489:119543c9f674 | 365 | } |
mbed_official | 489:119543c9f674 | 366 | |
mbed_official | 489:119543c9f674 | 367 | /** |
mbed_official | 489:119543c9f674 | 368 | * @brief Get the Option byte configuration |
mbed_official | 489:119543c9f674 | 369 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that |
mbed_official | 489:119543c9f674 | 370 | * contains the configuration information for the programming. |
mbed_official | 489:119543c9f674 | 371 | * |
mbed_official | 489:119543c9f674 | 372 | * @retval None |
mbed_official | 489:119543c9f674 | 373 | */ |
mbed_official | 489:119543c9f674 | 374 | void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) |
mbed_official | 489:119543c9f674 | 375 | { |
mbed_official | 489:119543c9f674 | 376 | pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_BOR; |
mbed_official | 489:119543c9f674 | 377 | |
mbed_official | 489:119543c9f674 | 378 | /* Get WRP sector */ |
mbed_official | 489:119543c9f674 | 379 | pOBInit->WRPSector = FLASH_OB_GetWRP(); |
mbed_official | 489:119543c9f674 | 380 | |
mbed_official | 489:119543c9f674 | 381 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 489:119543c9f674 | 382 | pOBInit->WRPSector2 = FLASH_OB_GetWRP2(); |
mbed_official | 489:119543c9f674 | 383 | #endif |
mbed_official | 489:119543c9f674 | 384 | |
mbed_official | 489:119543c9f674 | 385 | /* Get RDP Level */ |
mbed_official | 489:119543c9f674 | 386 | pOBInit->RDPLevel = FLASH_OB_GetRDP(); |
mbed_official | 489:119543c9f674 | 387 | |
mbed_official | 489:119543c9f674 | 388 | /* Get USER */ |
mbed_official | 489:119543c9f674 | 389 | pOBInit->USERConfig = FLASH_OB_GetUser(); |
mbed_official | 489:119543c9f674 | 390 | |
mbed_official | 489:119543c9f674 | 391 | /* Get BOR Level */ |
mbed_official | 489:119543c9f674 | 392 | pOBInit->BORLevel = FLASH_OB_GetBOR(); |
mbed_official | 489:119543c9f674 | 393 | |
mbed_official | 489:119543c9f674 | 394 | /* Get BOOT bit 1 config OB */ |
mbed_official | 489:119543c9f674 | 395 | pOBInit->BOOTBit1Config = FLASH_OB_GetBOOTBit1(); |
mbed_official | 489:119543c9f674 | 396 | |
mbed_official | 489:119543c9f674 | 397 | } |
mbed_official | 489:119543c9f674 | 398 | |
mbed_official | 489:119543c9f674 | 399 | /** |
mbed_official | 376:cb4d9db17537 | 400 | * @brief Program option bytes |
mbed_official | 376:cb4d9db17537 | 401 | * @param pAdvOBInit: pointer to an FLASH_AdvOBProgramInitTypeDef structure that |
mbed_official | 376:cb4d9db17537 | 402 | * contains the configuration information for the programming. |
mbed_official | 376:cb4d9db17537 | 403 | * |
mbed_official | 376:cb4d9db17537 | 404 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 376:cb4d9db17537 | 405 | */ |
mbed_official | 376:cb4d9db17537 | 406 | HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram (FLASH_AdvOBProgramInitTypeDef *pAdvOBInit) |
mbed_official | 376:cb4d9db17537 | 407 | { |
mbed_official | 376:cb4d9db17537 | 408 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 376:cb4d9db17537 | 409 | |
mbed_official | 376:cb4d9db17537 | 410 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 411 | assert_param(IS_OBEX(pAdvOBInit->OptionType)); |
mbed_official | 376:cb4d9db17537 | 412 | |
mbed_official | 489:119543c9f674 | 413 | /* Program PCROP option byte */ |
mbed_official | 489:119543c9f674 | 414 | if ((pAdvOBInit->OptionType & OPTIONBYTE_PCROP) == OPTIONBYTE_PCROP) |
mbed_official | 376:cb4d9db17537 | 415 | { |
mbed_official | 376:cb4d9db17537 | 416 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 417 | assert_param(IS_PCROPSTATE(pAdvOBInit->PCROPState)); |
mbed_official | 489:119543c9f674 | 418 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 489:119543c9f674 | 419 | status = FLASH_OB_ProtectedSectorsConfig(pAdvOBInit->PCROPSector, pAdvOBInit->PCROPSector2, pAdvOBInit->PCROPState); |
mbed_official | 489:119543c9f674 | 420 | #else |
mbed_official | 489:119543c9f674 | 421 | status = FLASH_OB_ProtectedSectorsConfig(pAdvOBInit->PCROPSector, pAdvOBInit->PCROPState); |
mbed_official | 489:119543c9f674 | 422 | #endif |
mbed_official | 489:119543c9f674 | 423 | } |
mbed_official | 489:119543c9f674 | 424 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 489:119543c9f674 | 425 | if ((pAdvOBInit->OptionType & OPTIONBYTE_BOOTCONFIG) == OPTIONBYTE_BOOTCONFIG) |
mbed_official | 376:cb4d9db17537 | 426 | { |
mbed_official | 489:119543c9f674 | 427 | status = FLASH_OB_BFB2Config(pAdvOBInit->BootConfig); |
mbed_official | 376:cb4d9db17537 | 428 | } |
mbed_official | 489:119543c9f674 | 429 | #endif |
mbed_official | 376:cb4d9db17537 | 430 | |
mbed_official | 376:cb4d9db17537 | 431 | return status; |
mbed_official | 376:cb4d9db17537 | 432 | } |
mbed_official | 376:cb4d9db17537 | 433 | |
mbed_official | 376:cb4d9db17537 | 434 | /** |
mbed_official | 376:cb4d9db17537 | 435 | * @brief Get the OBEX byte configuration |
mbed_official | 376:cb4d9db17537 | 436 | * @param pAdvOBInit: pointer to an FLASH_AdvOBProgramInitTypeDef structure that |
mbed_official | 376:cb4d9db17537 | 437 | * contains the configuration information for the programming. |
mbed_official | 376:cb4d9db17537 | 438 | * |
mbed_official | 376:cb4d9db17537 | 439 | * @retval None |
mbed_official | 376:cb4d9db17537 | 440 | */ |
mbed_official | 376:cb4d9db17537 | 441 | void HAL_FLASHEx_AdvOBGetConfig(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit) |
mbed_official | 376:cb4d9db17537 | 442 | { |
mbed_official | 489:119543c9f674 | 443 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 489:119543c9f674 | 444 | pAdvOBInit->OptionType = OPTIONBYTE_PCROP| OPTIONBYTE_BOOTCONFIG; |
mbed_official | 489:119543c9f674 | 445 | #else |
mbed_official | 489:119543c9f674 | 446 | pAdvOBInit->OptionType = OPTIONBYTE_PCROP; |
mbed_official | 489:119543c9f674 | 447 | #endif |
mbed_official | 489:119543c9f674 | 448 | /* Get PCROP state */ |
mbed_official | 489:119543c9f674 | 449 | pAdvOBInit->PCROPState = (FLASH->OPTR & FLASH_OPTR_WPRMOD) >> 8; |
mbed_official | 489:119543c9f674 | 450 | /* Get PCROP protected sector */ |
mbed_official | 489:119543c9f674 | 451 | pAdvOBInit->PCROPSector = FLASH->WRPR; |
mbed_official | 489:119543c9f674 | 452 | |
mbed_official | 489:119543c9f674 | 453 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 489:119543c9f674 | 454 | /* Get PCROP protected sector */ |
mbed_official | 489:119543c9f674 | 455 | pAdvOBInit->PCROPSector2 = FLASH->WRPR2; |
mbed_official | 489:119543c9f674 | 456 | |
mbed_official | 489:119543c9f674 | 457 | /* Get boot bank config */ |
mbed_official | 489:119543c9f674 | 458 | pAdvOBInit->BootConfig = (FLASH->OPTR & FLASH_OPTR_BFB2) >> 23; |
mbed_official | 489:119543c9f674 | 459 | #endif |
mbed_official | 489:119543c9f674 | 460 | } |
mbed_official | 489:119543c9f674 | 461 | |
mbed_official | 489:119543c9f674 | 462 | /** |
mbed_official | 489:119543c9f674 | 463 | * @brief Select the Protection Mode (WPRMOD). |
mbed_official | 489:119543c9f674 | 464 | * @note Once WPRMOD bit is active, unprotection of a protected sector is not possible |
mbed_official | 489:119543c9f674 | 465 | * @note Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag |
mbed_official | 489:119543c9f674 | 466 | * @param None |
mbed_official | 489:119543c9f674 | 467 | * @retval HAL status |
mbed_official | 489:119543c9f674 | 468 | */ |
mbed_official | 489:119543c9f674 | 469 | HAL_StatusTypeDef HAL_FLASHEx_OB_SelectPCROP(void) |
mbed_official | 489:119543c9f674 | 470 | { |
mbed_official | 489:119543c9f674 | 471 | return (FLASH_OB_PCROPSelectionConfig(1)); |
mbed_official | 489:119543c9f674 | 472 | } |
mbed_official | 489:119543c9f674 | 473 | |
mbed_official | 489:119543c9f674 | 474 | /** |
mbed_official | 489:119543c9f674 | 475 | * @brief Deselect the Protection Mode (WPRMOD). |
mbed_official | 489:119543c9f674 | 476 | * @note Once WPRMOD bit is active, unprotection of a protected sector is not possible |
mbed_official | 489:119543c9f674 | 477 | * @note Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag |
mbed_official | 489:119543c9f674 | 478 | * @param None |
mbed_official | 489:119543c9f674 | 479 | * @retval HAL status |
mbed_official | 489:119543c9f674 | 480 | */ |
mbed_official | 489:119543c9f674 | 481 | HAL_StatusTypeDef HAL_FLASHEx_OB_DeSelectPCROP(void) |
mbed_official | 489:119543c9f674 | 482 | { |
mbed_official | 489:119543c9f674 | 483 | return (FLASH_OB_PCROPSelectionConfig(0)); |
mbed_official | 376:cb4d9db17537 | 484 | } |
mbed_official | 376:cb4d9db17537 | 485 | |
mbed_official | 376:cb4d9db17537 | 486 | /** |
mbed_official | 376:cb4d9db17537 | 487 | * @} |
mbed_official | 376:cb4d9db17537 | 488 | */ |
mbed_official | 376:cb4d9db17537 | 489 | |
mbed_official | 489:119543c9f674 | 490 | /** @addtogroup FLASHEx_Exported_Functions_Group3 |
mbed_official | 376:cb4d9db17537 | 491 | * @brief DATA EEPROM Programming functions |
mbed_official | 376:cb4d9db17537 | 492 | * |
mbed_official | 376:cb4d9db17537 | 493 | @verbatim |
mbed_official | 376:cb4d9db17537 | 494 | =============================================================================== |
mbed_official | 376:cb4d9db17537 | 495 | ##### DATA EEPROM Programming functions ##### |
mbed_official | 376:cb4d9db17537 | 496 | =============================================================================== |
mbed_official | 376:cb4d9db17537 | 497 | |
mbed_official | 376:cb4d9db17537 | 498 | [..] The FLASH_DATAEEPROM Programming_Functions, includes the following functions: |
mbed_official | 376:cb4d9db17537 | 499 | (+) HAL_FLASHEx_DATAEEPROM_Unlock(void); |
mbed_official | 376:cb4d9db17537 | 500 | (+) HAL_FLASHEx_DATAEEPROM_Lock(void); |
mbed_official | 376:cb4d9db17537 | 501 | (+) HAL_FLASHEx_DATAEEPROM_Erase(uint32_t Address) |
mbed_official | 376:cb4d9db17537 | 502 | (+) HAL_FLASHEx_DATAEEPROM_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data) |
mbed_official | 376:cb4d9db17537 | 503 | |
mbed_official | 376:cb4d9db17537 | 504 | [..] Any operation of erase or program should follow these steps: |
mbed_official | 376:cb4d9db17537 | 505 | (#) Call the HAL_FLASHEx_DATAEEPROM_Unlock() function to enable the data EEPROM access |
mbed_official | 376:cb4d9db17537 | 506 | and Flash program erase control register access. |
mbed_official | 376:cb4d9db17537 | 507 | (#) Call the desired function to erase or program data. |
mbed_official | 376:cb4d9db17537 | 508 | (#) Call the HAL_FLASHEx_DATAEEPROM_Lock() to disable the data EEPROM access |
mbed_official | 376:cb4d9db17537 | 509 | and Flash program erase control register access(recommended |
mbed_official | 376:cb4d9db17537 | 510 | to protect the DATA_EEPROM against possible unwanted operation). |
mbed_official | 376:cb4d9db17537 | 511 | |
mbed_official | 376:cb4d9db17537 | 512 | @endverbatim |
mbed_official | 376:cb4d9db17537 | 513 | * @{ |
mbed_official | 376:cb4d9db17537 | 514 | */ |
mbed_official | 376:cb4d9db17537 | 515 | /** |
mbed_official | 376:cb4d9db17537 | 516 | * @brief Unlocks the data memory and FLASH_PECR register access. |
mbed_official | 376:cb4d9db17537 | 517 | * @param None |
mbed_official | 376:cb4d9db17537 | 518 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 376:cb4d9db17537 | 519 | */ |
mbed_official | 376:cb4d9db17537 | 520 | HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Unlock(void) |
mbed_official | 376:cb4d9db17537 | 521 | { |
mbed_official | 376:cb4d9db17537 | 522 | if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET) |
mbed_official | 376:cb4d9db17537 | 523 | { |
mbed_official | 489:119543c9f674 | 524 | /* Unlocking the Data memory and FLASH_PECR register access */ |
mbed_official | 376:cb4d9db17537 | 525 | FLASH->PEKEYR = FLASH_PEKEY1; |
mbed_official | 376:cb4d9db17537 | 526 | FLASH->PEKEYR = FLASH_PEKEY2; |
mbed_official | 489:119543c9f674 | 527 | return HAL_OK; |
mbed_official | 376:cb4d9db17537 | 528 | } |
mbed_official | 376:cb4d9db17537 | 529 | else |
mbed_official | 376:cb4d9db17537 | 530 | { |
mbed_official | 376:cb4d9db17537 | 531 | return HAL_ERROR; |
mbed_official | 376:cb4d9db17537 | 532 | } |
mbed_official | 376:cb4d9db17537 | 533 | } |
mbed_official | 376:cb4d9db17537 | 534 | |
mbed_official | 376:cb4d9db17537 | 535 | /** |
mbed_official | 376:cb4d9db17537 | 536 | * @brief Locks the Data memory and FLASH_PECR register access. |
mbed_official | 376:cb4d9db17537 | 537 | * @param None |
mbed_official | 376:cb4d9db17537 | 538 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 376:cb4d9db17537 | 539 | */ |
mbed_official | 376:cb4d9db17537 | 540 | HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Lock(void) |
mbed_official | 376:cb4d9db17537 | 541 | { |
mbed_official | 376:cb4d9db17537 | 542 | /* Set the PELOCK Bit to lock the data memory and FLASH_PECR register access */ |
mbed_official | 489:119543c9f674 | 543 | SET_BIT(FLASH->PECR, FLASH_PECR_PELOCK); |
mbed_official | 376:cb4d9db17537 | 544 | return HAL_OK; |
mbed_official | 376:cb4d9db17537 | 545 | } |
mbed_official | 376:cb4d9db17537 | 546 | |
mbed_official | 376:cb4d9db17537 | 547 | /** |
mbed_official | 376:cb4d9db17537 | 548 | * @brief Erase a word in data memory. |
mbed_official | 376:cb4d9db17537 | 549 | * @param Address: specifies the address to be erased. |
mbed_official | 376:cb4d9db17537 | 550 | * @note To correctly run this function, the HAL_FLASHEx_DATAEEPROM_Unlock() function |
mbed_official | 376:cb4d9db17537 | 551 | * must be called before. |
mbed_official | 376:cb4d9db17537 | 552 | * Call the HAL_FLASHEx_DATAEEPROM_Lock() to the data EEPROM access |
mbed_official | 376:cb4d9db17537 | 553 | * and Flash program erase control register access(recommended to protect |
mbed_official | 376:cb4d9db17537 | 554 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 489:119543c9f674 | 555 | * @retval HAL status |
mbed_official | 376:cb4d9db17537 | 556 | */ |
mbed_official | 376:cb4d9db17537 | 557 | HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Erase(uint32_t Address) |
mbed_official | 376:cb4d9db17537 | 558 | { |
mbed_official | 376:cb4d9db17537 | 559 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 376:cb4d9db17537 | 560 | |
mbed_official | 376:cb4d9db17537 | 561 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 562 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 376:cb4d9db17537 | 563 | |
mbed_official | 376:cb4d9db17537 | 564 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 565 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 566 | |
mbed_official | 376:cb4d9db17537 | 567 | if(status == HAL_OK) |
mbed_official | 376:cb4d9db17537 | 568 | { |
mbed_official | 489:119543c9f674 | 569 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 570 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 489:119543c9f674 | 571 | |
mbed_official | 376:cb4d9db17537 | 572 | /* Write "00000000h" to valid address in the data memory" */ |
mbed_official | 489:119543c9f674 | 573 | *(__IO uint32_t *) Address = 0x00000000; |
mbed_official | 489:119543c9f674 | 574 | } |
mbed_official | 376:cb4d9db17537 | 575 | return status; |
mbed_official | 376:cb4d9db17537 | 576 | } |
mbed_official | 376:cb4d9db17537 | 577 | |
mbed_official | 376:cb4d9db17537 | 578 | /** |
mbed_official | 376:cb4d9db17537 | 579 | * @brief Program word at a specified address |
mbed_official | 376:cb4d9db17537 | 580 | * @param TypeProgram: Indicate the way to program at a specified address. |
mbed_official | 489:119543c9f674 | 581 | * This parameter can be a value of @ref FLASHEx_Type_Program_Data |
mbed_official | 376:cb4d9db17537 | 582 | * @param Address: specifies the address to be programmed. |
mbed_official | 376:cb4d9db17537 | 583 | * @param Data: specifies the data to be programmed |
mbed_official | 376:cb4d9db17537 | 584 | * |
mbed_official | 376:cb4d9db17537 | 585 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 376:cb4d9db17537 | 586 | */ |
mbed_official | 376:cb4d9db17537 | 587 | |
mbed_official | 489:119543c9f674 | 588 | HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data) |
mbed_official | 376:cb4d9db17537 | 589 | { |
mbed_official | 376:cb4d9db17537 | 590 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 376:cb4d9db17537 | 591 | |
mbed_official | 376:cb4d9db17537 | 592 | /* Process Locked */ |
mbed_official | 489:119543c9f674 | 593 | __HAL_LOCK(&ProcFlash); |
mbed_official | 376:cb4d9db17537 | 594 | |
mbed_official | 376:cb4d9db17537 | 595 | /* Check the parameters */ |
mbed_official | 489:119543c9f674 | 596 | assert_param(IS_TYPEPROGRAMDATA(TypeProgram)); |
mbed_official | 489:119543c9f674 | 597 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 489:119543c9f674 | 598 | |
mbed_official | 376:cb4d9db17537 | 599 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 600 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 601 | |
mbed_official | 376:cb4d9db17537 | 602 | if(status == HAL_OK) |
mbed_official | 376:cb4d9db17537 | 603 | { |
mbed_official | 489:119543c9f674 | 604 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 605 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 489:119543c9f674 | 606 | |
mbed_official | 489:119543c9f674 | 607 | if(TypeProgram == FLASH_TYPEPROGRAMDATA_WORD) |
mbed_official | 376:cb4d9db17537 | 608 | { |
mbed_official | 489:119543c9f674 | 609 | /* Program word (32-bit) at a specified address */ |
mbed_official | 489:119543c9f674 | 610 | *(__IO uint32_t *)Address = Data; |
mbed_official | 376:cb4d9db17537 | 611 | } |
mbed_official | 489:119543c9f674 | 612 | else if(TypeProgram == FLASH_TYPEPROGRAMDATA_HALFWORD) |
mbed_official | 376:cb4d9db17537 | 613 | { |
mbed_official | 489:119543c9f674 | 614 | /* Program word (16-bit) at a specified address */ |
mbed_official | 489:119543c9f674 | 615 | *(__IO uint16_t *)Address = (uint16_t) Data; |
mbed_official | 376:cb4d9db17537 | 616 | } |
mbed_official | 489:119543c9f674 | 617 | else if(TypeProgram == FLASH_TYPEPROGRAMDATA_BYTE) |
mbed_official | 376:cb4d9db17537 | 618 | { |
mbed_official | 489:119543c9f674 | 619 | /*Program word (8-bit) at a specified address */ |
mbed_official | 489:119543c9f674 | 620 | *(__IO uint8_t *)Address = (uint8_t) Data; |
mbed_official | 376:cb4d9db17537 | 621 | } |
mbed_official | 489:119543c9f674 | 622 | else |
mbed_official | 376:cb4d9db17537 | 623 | { |
mbed_official | 489:119543c9f674 | 624 | status = HAL_ERROR; |
mbed_official | 376:cb4d9db17537 | 625 | } |
mbed_official | 489:119543c9f674 | 626 | |
mbed_official | 489:119543c9f674 | 627 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 628 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 489:119543c9f674 | 629 | } |
mbed_official | 376:cb4d9db17537 | 630 | /* Process Unlocked */ |
mbed_official | 489:119543c9f674 | 631 | __HAL_UNLOCK(&ProcFlash); |
mbed_official | 376:cb4d9db17537 | 632 | return status; |
mbed_official | 376:cb4d9db17537 | 633 | } |
mbed_official | 376:cb4d9db17537 | 634 | |
mbed_official | 376:cb4d9db17537 | 635 | /** |
mbed_official | 489:119543c9f674 | 636 | * @brief Enable DATA EEPROM fixed Time programming (2*Tprog). |
mbed_official | 489:119543c9f674 | 637 | * @retval None |
mbed_official | 376:cb4d9db17537 | 638 | */ |
mbed_official | 489:119543c9f674 | 639 | void HAL_FLASHEx_DATAEEPROM_EnableFixedTimeProgram(void) |
mbed_official | 376:cb4d9db17537 | 640 | { |
mbed_official | 489:119543c9f674 | 641 | SET_BIT(FLASH->PECR, FLASH_PECR_FIX); |
mbed_official | 376:cb4d9db17537 | 642 | } |
mbed_official | 376:cb4d9db17537 | 643 | |
mbed_official | 376:cb4d9db17537 | 644 | /** |
mbed_official | 489:119543c9f674 | 645 | * @brief Disables DATA EEPROM fixed Time programming (2*Tprog). |
mbed_official | 376:cb4d9db17537 | 646 | * @retval None |
mbed_official | 376:cb4d9db17537 | 647 | */ |
mbed_official | 489:119543c9f674 | 648 | void HAL_FLASHEx_DATAEEPROM_DisableFixedTimeProgram(void) |
mbed_official | 376:cb4d9db17537 | 649 | { |
mbed_official | 489:119543c9f674 | 650 | CLEAR_BIT(FLASH->PECR, FLASH_PECR_FIX); |
mbed_official | 376:cb4d9db17537 | 651 | } |
mbed_official | 376:cb4d9db17537 | 652 | |
mbed_official | 376:cb4d9db17537 | 653 | /** |
mbed_official | 376:cb4d9db17537 | 654 | * @} |
mbed_official | 376:cb4d9db17537 | 655 | */ |
mbed_official | 489:119543c9f674 | 656 | |
mbed_official | 376:cb4d9db17537 | 657 | /** |
mbed_official | 376:cb4d9db17537 | 658 | * @brief Returns the FLASH User Option Bytes values. |
mbed_official | 376:cb4d9db17537 | 659 | * @param None |
mbed_official | 376:cb4d9db17537 | 660 | * @retval The FLASH User Option Bytes. |
mbed_official | 376:cb4d9db17537 | 661 | */ |
mbed_official | 376:cb4d9db17537 | 662 | static uint8_t FLASH_OB_GetUser(void) |
mbed_official | 376:cb4d9db17537 | 663 | { |
mbed_official | 376:cb4d9db17537 | 664 | /* Return the User Option Byte */ |
mbed_official | 489:119543c9f674 | 665 | return (uint8_t)((FLASH->OPTR & FLASH_OPTR_USER) >> 16); |
mbed_official | 489:119543c9f674 | 666 | } |
mbed_official | 489:119543c9f674 | 667 | |
mbed_official | 489:119543c9f674 | 668 | /** |
mbed_official | 489:119543c9f674 | 669 | * @brief Returns the FLASH Read out Protection Level. |
mbed_official | 489:119543c9f674 | 670 | * @param None |
mbed_official | 489:119543c9f674 | 671 | * @retval FLASH RDP level. |
mbed_official | 489:119543c9f674 | 672 | */ |
mbed_official | 489:119543c9f674 | 673 | static uint8_t FLASH_OB_GetRDP(void) |
mbed_official | 489:119543c9f674 | 674 | { |
mbed_official | 489:119543c9f674 | 675 | return (uint8_t)(FLASH->OPTR & FLASH_OPTR_RDPROT); |
mbed_official | 489:119543c9f674 | 676 | } |
mbed_official | 489:119543c9f674 | 677 | |
mbed_official | 489:119543c9f674 | 678 | /** |
mbed_official | 489:119543c9f674 | 679 | * @brief Returns the FLASH BOR level. |
mbed_official | 489:119543c9f674 | 680 | * @param None |
mbed_official | 489:119543c9f674 | 681 | * @retval The BOR level Option Bytes. |
mbed_official | 489:119543c9f674 | 682 | */ |
mbed_official | 489:119543c9f674 | 683 | static uint8_t FLASH_OB_GetBOR(void) |
mbed_official | 489:119543c9f674 | 684 | { |
mbed_official | 489:119543c9f674 | 685 | /* Return the BOR level */ |
mbed_official | 489:119543c9f674 | 686 | return (uint8_t)((FLASH->OPTR & (uint32_t)FLASH_OPTR_BOR_LEV) >> 16); |
mbed_official | 489:119543c9f674 | 687 | } |
mbed_official | 489:119543c9f674 | 688 | |
mbed_official | 489:119543c9f674 | 689 | /** |
mbed_official | 489:119543c9f674 | 690 | * @brief Returns the FLASH BOOT bit1 value. |
mbed_official | 489:119543c9f674 | 691 | * @param None |
mbed_official | 489:119543c9f674 | 692 | * @retval The BOOT bit 1 value Option Bytes. |
mbed_official | 489:119543c9f674 | 693 | */ |
mbed_official | 489:119543c9f674 | 694 | static uint8_t FLASH_OB_GetBOOTBit1(void) |
mbed_official | 489:119543c9f674 | 695 | { |
mbed_official | 489:119543c9f674 | 696 | /* Return the BOR level */ |
mbed_official | 489:119543c9f674 | 697 | return (FLASH->OPTR & FLASH_OPTR_BOOT1) >> 31; |
mbed_official | 489:119543c9f674 | 698 | |
mbed_official | 376:cb4d9db17537 | 699 | } |
mbed_official | 376:cb4d9db17537 | 700 | |
mbed_official | 376:cb4d9db17537 | 701 | /** |
mbed_official | 376:cb4d9db17537 | 702 | * @brief Returns the FLASH Write Protection Option Bytes value. |
mbed_official | 376:cb4d9db17537 | 703 | * @param None |
mbed_official | 376:cb4d9db17537 | 704 | * @retval The FLASH Write Protection Option Bytes value. |
mbed_official | 376:cb4d9db17537 | 705 | */ |
mbed_official | 376:cb4d9db17537 | 706 | static uint32_t FLASH_OB_GetWRP(void) |
mbed_official | 376:cb4d9db17537 | 707 | { |
mbed_official | 376:cb4d9db17537 | 708 | /* Return the FLASH write protection Register value */ |
mbed_official | 376:cb4d9db17537 | 709 | return (uint32_t)(FLASH->WRPR); |
mbed_official | 376:cb4d9db17537 | 710 | } |
mbed_official | 376:cb4d9db17537 | 711 | |
mbed_official | 489:119543c9f674 | 712 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 376:cb4d9db17537 | 713 | /** |
mbed_official | 489:119543c9f674 | 714 | * @brief Returns the FLASH Write Protection Option Bytes value. |
mbed_official | 376:cb4d9db17537 | 715 | * @param None |
mbed_official | 489:119543c9f674 | 716 | * @retval The FLASH Write Protection Option Bytes value. |
mbed_official | 376:cb4d9db17537 | 717 | */ |
mbed_official | 489:119543c9f674 | 718 | static uint32_t FLASH_OB_GetWRP2(void) |
mbed_official | 376:cb4d9db17537 | 719 | { |
mbed_official | 489:119543c9f674 | 720 | /* Return the FLASH write protection Register value */ |
mbed_official | 489:119543c9f674 | 721 | return (uint32_t)(FLASH->WRPR2); |
mbed_official | 376:cb4d9db17537 | 722 | } |
mbed_official | 489:119543c9f674 | 723 | #endif /* STM32L071xx || STM32L072xx || STM32L073xx || STM32L081xx || STM32L082xx || STM32L083xx */ |
mbed_official | 376:cb4d9db17537 | 724 | |
mbed_official | 376:cb4d9db17537 | 725 | /** |
mbed_official | 376:cb4d9db17537 | 726 | * @brief Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY. |
mbed_official | 376:cb4d9db17537 | 727 | * @param OB_IWDG: Selects the WDG mode. |
mbed_official | 376:cb4d9db17537 | 728 | * This parameter can be one of the following values: |
mbed_official | 376:cb4d9db17537 | 729 | * @arg OB_IWDG_SW: Software WDG selected |
mbed_official | 376:cb4d9db17537 | 730 | * @arg OB_IWDG_HW: Hardware WDG selected |
mbed_official | 376:cb4d9db17537 | 731 | * @param OB_STOP: Reset event when entering STOP mode. |
mbed_official | 376:cb4d9db17537 | 732 | * This parameter can be one of the following values: |
mbed_official | 376:cb4d9db17537 | 733 | * @arg OB_STOP_NoRST: No reset generated when entering in STOP |
mbed_official | 376:cb4d9db17537 | 734 | * @arg OB_STOP_RST: Reset generated when entering in STOP |
mbed_official | 376:cb4d9db17537 | 735 | * @param OB_STDBY: Reset event when entering Standby mode. |
mbed_official | 376:cb4d9db17537 | 736 | * This parameter can be one of the following values: |
mbed_official | 489:119543c9f674 | 737 | * @arg OB_STDBY_NORST: No reset generated when entering in STANDBY |
mbed_official | 376:cb4d9db17537 | 738 | * @arg OB_STDBY_RST: Reset generated when entering in STANDBY |
mbed_official | 489:119543c9f674 | 739 | * @retval HAL status |
mbed_official | 376:cb4d9db17537 | 740 | */ |
mbed_official | 376:cb4d9db17537 | 741 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY) |
mbed_official | 376:cb4d9db17537 | 742 | { |
mbed_official | 376:cb4d9db17537 | 743 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 489:119543c9f674 | 744 | uint32_t tmp = 0, tmp1 = 0, OB_Bits = (uint32_t) (OB_IWDG | OB_STOP | OB_STDBY); |
mbed_official | 376:cb4d9db17537 | 745 | |
mbed_official | 376:cb4d9db17537 | 746 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 747 | assert_param(IS_OB_IWDG_SOURCE(OB_IWDG)); |
mbed_official | 376:cb4d9db17537 | 748 | assert_param(IS_OB_STOP_SOURCE(OB_STOP)); |
mbed_official | 376:cb4d9db17537 | 749 | assert_param(IS_OB_STDBY_SOURCE(OB_STDBY)); |
mbed_official | 376:cb4d9db17537 | 750 | |
mbed_official | 489:119543c9f674 | 751 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 752 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 489:119543c9f674 | 753 | |
mbed_official | 376:cb4d9db17537 | 754 | /* Get the User Option byte register */ |
mbed_official | 489:119543c9f674 | 755 | tmp1 = OB->USER & ((~FLASH_OPTR_USER) >> 16); |
mbed_official | 489:119543c9f674 | 756 | |
mbed_official | 376:cb4d9db17537 | 757 | /* Calculate the user option byte to write */ |
mbed_official | 489:119543c9f674 | 758 | tmp = (~(OB_Bits | tmp1)) << 16; |
mbed_official | 489:119543c9f674 | 759 | tmp |= OB_Bits | tmp1; |
mbed_official | 376:cb4d9db17537 | 760 | |
mbed_official | 376:cb4d9db17537 | 761 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 762 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 763 | |
mbed_official | 376:cb4d9db17537 | 764 | if(status == HAL_OK) |
mbed_official | 376:cb4d9db17537 | 765 | { |
mbed_official | 489:119543c9f674 | 766 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 767 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 489:119543c9f674 | 768 | /* Program OB */ |
mbed_official | 376:cb4d9db17537 | 769 | OB->USER = tmp; |
mbed_official | 489:119543c9f674 | 770 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 771 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 772 | } |
mbed_official | 489:119543c9f674 | 773 | return status; |
mbed_official | 489:119543c9f674 | 774 | } |
mbed_official | 489:119543c9f674 | 775 | |
mbed_official | 489:119543c9f674 | 776 | /** |
mbed_official | 489:119543c9f674 | 777 | * @brief Enables or disables the read out protection. |
mbed_official | 489:119543c9f674 | 778 | * @note To correctly run this function, the FLASH_OB_Unlock() function |
mbed_official | 489:119543c9f674 | 779 | * must be called before. |
mbed_official | 489:119543c9f674 | 780 | * @param OB_RDP: specifies the read protection level. |
mbed_official | 489:119543c9f674 | 781 | * This parameter can be: |
mbed_official | 489:119543c9f674 | 782 | * @arg OB_RDP_LEVEL0: No protection |
mbed_official | 489:119543c9f674 | 783 | * @arg OB_RDP_LEVEL1: Read protection of the memory |
mbed_official | 489:119543c9f674 | 784 | * @arg OB_RDP_LEVEL2: Chip protection |
mbed_official | 489:119543c9f674 | 785 | * |
mbed_official | 489:119543c9f674 | 786 | * !!!Warning!!! When enabling OB_RDP_LEVEL2 it's no more possible to go back to level 1 or 0 |
mbed_official | 489:119543c9f674 | 787 | * |
mbed_official | 489:119543c9f674 | 788 | * @retval HAL status |
mbed_official | 489:119543c9f674 | 789 | */ |
mbed_official | 489:119543c9f674 | 790 | static HAL_StatusTypeDef FLASH_OB_RDPConfig(uint8_t OB_RDP) |
mbed_official | 489:119543c9f674 | 791 | { |
mbed_official | 489:119543c9f674 | 792 | HAL_StatusTypeDef status; |
mbed_official | 489:119543c9f674 | 793 | uint32_t tmp = 0, tmp1 = 0, OB_Bits = (uint32_t) OB_RDP; |
mbed_official | 489:119543c9f674 | 794 | |
mbed_official | 489:119543c9f674 | 795 | /* Check the parameters */ |
mbed_official | 489:119543c9f674 | 796 | assert_param(IS_OB_RDP(OB_RDP)); |
mbed_official | 489:119543c9f674 | 797 | |
mbed_official | 489:119543c9f674 | 798 | /* Calculate the option byte to write */ |
mbed_official | 489:119543c9f674 | 799 | tmp = (OB->RDP & ((~FLASH_OPTR_RDPROT) & 0x0000FFFF)) | OB_Bits; |
mbed_official | 489:119543c9f674 | 800 | tmp1 = (~tmp << 16) | tmp; |
mbed_official | 376:cb4d9db17537 | 801 | |
mbed_official | 376:cb4d9db17537 | 802 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 803 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 489:119543c9f674 | 804 | |
mbed_official | 489:119543c9f674 | 805 | if(status == HAL_OK) |
mbed_official | 489:119543c9f674 | 806 | { |
mbed_official | 489:119543c9f674 | 807 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 808 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 489:119543c9f674 | 809 | /* Program OB */ |
mbed_official | 489:119543c9f674 | 810 | OB->RDP = tmp1; |
mbed_official | 489:119543c9f674 | 811 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 812 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 489:119543c9f674 | 813 | } |
mbed_official | 489:119543c9f674 | 814 | return status; |
mbed_official | 376:cb4d9db17537 | 815 | } |
mbed_official | 376:cb4d9db17537 | 816 | |
mbed_official | 376:cb4d9db17537 | 817 | /** |
mbed_official | 376:cb4d9db17537 | 818 | * @brief Programs the FLASH brownout reset threshold level Option Byte. |
mbed_official | 376:cb4d9db17537 | 819 | * @param OB_BOR: Selects the brownout reset threshold level. |
mbed_official | 376:cb4d9db17537 | 820 | * This parameter can be one of the following values: |
mbed_official | 376:cb4d9db17537 | 821 | * @arg OB_BOR_OFF: BOR is disabled at power down, the reset is asserted when the VDD |
mbed_official | 376:cb4d9db17537 | 822 | * power supply reaches the PDR(Power Down Reset) threshold (1.5V) |
mbed_official | 376:cb4d9db17537 | 823 | * @arg OB_BOR_LEVEL1: BOR Reset threshold levels for 1.7V - 1.8V VDD power supply |
mbed_official | 376:cb4d9db17537 | 824 | * @arg OB_BOR_LEVEL2: BOR Reset threshold levels for 1.9V - 2.0V VDD power supply |
mbed_official | 376:cb4d9db17537 | 825 | * @arg OB_BOR_LEVEL3: BOR Reset threshold levels for 2.3V - 2.4V VDD power supply |
mbed_official | 376:cb4d9db17537 | 826 | * @arg OB_BOR_LEVEL4: BOR Reset threshold levels for 2.55V - 2.65V VDD power supply |
mbed_official | 376:cb4d9db17537 | 827 | * @arg OB_BOR_LEVEL5: BOR Reset threshold levels for 2.8V - 2.9V VDD power supply |
mbed_official | 489:119543c9f674 | 828 | * @retval HAL status |
mbed_official | 376:cb4d9db17537 | 829 | */ |
mbed_official | 489:119543c9f674 | 830 | static HAL_StatusTypeDef FLASH_OB_BORConfig(uint8_t OB_BOR) |
mbed_official | 376:cb4d9db17537 | 831 | { |
mbed_official | 376:cb4d9db17537 | 832 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 489:119543c9f674 | 833 | uint32_t tmp = 0, tmp1 = 0, OB_Bits = (uint32_t) OB_BOR; |
mbed_official | 376:cb4d9db17537 | 834 | |
mbed_official | 376:cb4d9db17537 | 835 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 836 | assert_param(IS_OB_BOR_LEVEL(OB_BOR)); |
mbed_official | 376:cb4d9db17537 | 837 | |
mbed_official | 376:cb4d9db17537 | 838 | /* Get the User Option byte register */ |
mbed_official | 489:119543c9f674 | 839 | tmp1 = OB->USER & ((~FLASH_OPTR_BOR_LEV) >> 16); |
mbed_official | 489:119543c9f674 | 840 | |
mbed_official | 489:119543c9f674 | 841 | /* Calculate the user option byte to write */ |
mbed_official | 489:119543c9f674 | 842 | tmp = (~(OB_Bits | tmp1)) << 16; |
mbed_official | 489:119543c9f674 | 843 | tmp |= OB_Bits | tmp1; |
mbed_official | 376:cb4d9db17537 | 844 | |
mbed_official | 376:cb4d9db17537 | 845 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 846 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 847 | |
mbed_official | 376:cb4d9db17537 | 848 | if(status == HAL_OK) |
mbed_official | 376:cb4d9db17537 | 849 | { |
mbed_official | 489:119543c9f674 | 850 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 851 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 489:119543c9f674 | 852 | /* Program OB */ |
mbed_official | 376:cb4d9db17537 | 853 | OB->USER = tmp; |
mbed_official | 489:119543c9f674 | 854 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 855 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 856 | } |
mbed_official | 376:cb4d9db17537 | 857 | |
mbed_official | 376:cb4d9db17537 | 858 | return status; |
mbed_official | 376:cb4d9db17537 | 859 | } |
mbed_official | 376:cb4d9db17537 | 860 | |
mbed_official | 489:119543c9f674 | 861 | /** |
mbed_official | 489:119543c9f674 | 862 | * @brief Sets or resets the BOOT bit1 option bit. |
mbed_official | 489:119543c9f674 | 863 | * @param OB_BOOT_BIT1: Set or Reset the BOOT bit1 option bit. |
mbed_official | 489:119543c9f674 | 864 | * This parameter can be one of the following values: |
mbed_official | 489:119543c9f674 | 865 | * @arg OB_BOOT_BIT1_RESET: BOOT1 option bit reset |
mbed_official | 489:119543c9f674 | 866 | * @arg OB_BOOT_BIT1_SET: BOOT1 option bit set |
mbed_official | 489:119543c9f674 | 867 | * @retval HAL status |
mbed_official | 489:119543c9f674 | 868 | */ |
mbed_official | 489:119543c9f674 | 869 | static HAL_StatusTypeDef FLASH_OB_BOOTBit1Config(uint8_t OB_BOOT_BIT1) |
mbed_official | 489:119543c9f674 | 870 | { |
mbed_official | 489:119543c9f674 | 871 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 489:119543c9f674 | 872 | uint32_t tmp = 0, tmp1 = 0, OB_Bits = ((uint32_t) OB_BOOT_BIT1) << 15; |
mbed_official | 376:cb4d9db17537 | 873 | |
mbed_official | 376:cb4d9db17537 | 874 | /* Check the parameters */ |
mbed_official | 489:119543c9f674 | 875 | assert_param(IS_OB_BOOT1(OB_BOOT_BIT1)); |
mbed_official | 489:119543c9f674 | 876 | |
mbed_official | 489:119543c9f674 | 877 | /* Get the User Option byte register */ |
mbed_official | 489:119543c9f674 | 878 | tmp1 = OB->USER & ((~FLASH_OPTR_BOOT1) >> 16); |
mbed_official | 376:cb4d9db17537 | 879 | |
mbed_official | 489:119543c9f674 | 880 | /* Calculate the user option byte to write */ |
mbed_official | 489:119543c9f674 | 881 | tmp = (~(OB_Bits | tmp1)) << 16; |
mbed_official | 489:119543c9f674 | 882 | tmp |= OB_Bits | tmp1; |
mbed_official | 376:cb4d9db17537 | 883 | |
mbed_official | 489:119543c9f674 | 884 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 885 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 489:119543c9f674 | 886 | |
mbed_official | 489:119543c9f674 | 887 | if(status == HAL_OK) |
mbed_official | 489:119543c9f674 | 888 | { |
mbed_official | 489:119543c9f674 | 889 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 890 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 489:119543c9f674 | 891 | /* Program OB */ |
mbed_official | 489:119543c9f674 | 892 | OB->USER = tmp; |
mbed_official | 376:cb4d9db17537 | 893 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 894 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 895 | } |
mbed_official | 376:cb4d9db17537 | 896 | |
mbed_official | 489:119543c9f674 | 897 | return status; |
mbed_official | 376:cb4d9db17537 | 898 | } |
mbed_official | 376:cb4d9db17537 | 899 | |
mbed_official | 376:cb4d9db17537 | 900 | /** |
mbed_official | 489:119543c9f674 | 901 | * @brief Select the Protection Mode (WPRMOD). |
mbed_official | 489:119543c9f674 | 902 | * @note Once WPRMOD bit is active, unprotection of a protected sector is not possible |
mbed_official | 376:cb4d9db17537 | 903 | * @note Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag |
mbed_official | 376:cb4d9db17537 | 904 | * @param OB_PcROP: Select the Protection Mode of WPR bits. |
mbed_official | 376:cb4d9db17537 | 905 | * This parameter can be: |
mbed_official | 376:cb4d9db17537 | 906 | * @arg OB_PCROP_SELECTED: nWRP control the read&write protection (PcROP) of respective user sectors. |
mbed_official | 376:cb4d9db17537 | 907 | * @arg OB_PCROP_DESELECTED: nWRP control the write protection of respective user sectors. |
mbed_official | 489:119543c9f674 | 908 | * @retval HAL status |
mbed_official | 376:cb4d9db17537 | 909 | */ |
mbed_official | 489:119543c9f674 | 910 | static HAL_StatusTypeDef FLASH_OB_PCROPSelectionConfig(uint32_t WPRMOD) |
mbed_official | 376:cb4d9db17537 | 911 | { |
mbed_official | 489:119543c9f674 | 912 | HAL_StatusTypeDef status; |
mbed_official | 489:119543c9f674 | 913 | uint32_t tmp = 0, tmp1 = 0, OB_Bits = ((uint32_t) WPRMOD) << 8; |
mbed_official | 489:119543c9f674 | 914 | |
mbed_official | 489:119543c9f674 | 915 | /* Get the User Option byte register */ |
mbed_official | 489:119543c9f674 | 916 | tmp1 = OB->USER & ((~FLASH_OPTR_WPRMOD) >> 16); |
mbed_official | 489:119543c9f674 | 917 | |
mbed_official | 489:119543c9f674 | 918 | /* Calculate the user option byte to write */ |
mbed_official | 489:119543c9f674 | 919 | tmp = (~(OB_Bits | tmp1)) << 16; |
mbed_official | 489:119543c9f674 | 920 | tmp |= OB_Bits | tmp1; |
mbed_official | 376:cb4d9db17537 | 921 | |
mbed_official | 489:119543c9f674 | 922 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 923 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 924 | |
mbed_official | 376:cb4d9db17537 | 925 | if(status == HAL_OK) |
mbed_official | 376:cb4d9db17537 | 926 | { |
mbed_official | 489:119543c9f674 | 927 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 928 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 489:119543c9f674 | 929 | /* Program OB */ |
mbed_official | 489:119543c9f674 | 930 | OB->RDP = tmp; |
mbed_official | 489:119543c9f674 | 931 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 932 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 933 | } |
mbed_official | 376:cb4d9db17537 | 934 | |
mbed_official | 376:cb4d9db17537 | 935 | return status; |
mbed_official | 376:cb4d9db17537 | 936 | } |
mbed_official | 376:cb4d9db17537 | 937 | |
mbed_official | 489:119543c9f674 | 938 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 376:cb4d9db17537 | 939 | /** |
mbed_official | 489:119543c9f674 | 940 | * @brief Sets or resets the BFB2 option bit. |
mbed_official | 489:119543c9f674 | 941 | * @param BFB2: Set or Reset the BFB2 option bit. |
mbed_official | 489:119543c9f674 | 942 | * This parameter can be one of the following values: |
mbed_official | 489:119543c9f674 | 943 | * @arg OB_BOOT_BANK1: BFB2 option bit reset |
mbed_official | 489:119543c9f674 | 944 | * @arg OB_BOOT_BANK2: BFB2 option bit set |
mbed_official | 489:119543c9f674 | 945 | * @retval None |
mbed_official | 376:cb4d9db17537 | 946 | */ |
mbed_official | 489:119543c9f674 | 947 | static HAL_StatusTypeDef FLASH_OB_BFB2Config(uint8_t OB_BFB2) |
mbed_official | 376:cb4d9db17537 | 948 | { |
mbed_official | 489:119543c9f674 | 949 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 489:119543c9f674 | 950 | uint32_t tmp = 0, tmp1 = 0, OB_Bits = ((uint32_t) OB_BFB2) << 7; |
mbed_official | 489:119543c9f674 | 951 | |
mbed_official | 376:cb4d9db17537 | 952 | /* Check the parameters */ |
mbed_official | 489:119543c9f674 | 953 | assert_param(IS_OB_BOOT_BANK(OB_BFB2)); |
mbed_official | 489:119543c9f674 | 954 | |
mbed_official | 489:119543c9f674 | 955 | /* Get the User Option byte register */ |
mbed_official | 489:119543c9f674 | 956 | tmp1 = OB->USER & ((~FLASH_OPTR_BFB2) >> 16); |
mbed_official | 376:cb4d9db17537 | 957 | |
mbed_official | 489:119543c9f674 | 958 | /* Calculate the user option byte to write */ |
mbed_official | 489:119543c9f674 | 959 | tmp = (~(OB_Bits | tmp1)) << 16; |
mbed_official | 489:119543c9f674 | 960 | tmp |= OB_Bits | tmp1; |
mbed_official | 489:119543c9f674 | 961 | |
mbed_official | 376:cb4d9db17537 | 962 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 963 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 489:119543c9f674 | 964 | |
mbed_official | 376:cb4d9db17537 | 965 | if(status == HAL_OK) |
mbed_official | 489:119543c9f674 | 966 | { |
mbed_official | 489:119543c9f674 | 967 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 968 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 376:cb4d9db17537 | 969 | |
mbed_official | 489:119543c9f674 | 970 | /* Program OB */ |
mbed_official | 489:119543c9f674 | 971 | OB->USER = tmp; |
mbed_official | 489:119543c9f674 | 972 | |
mbed_official | 376:cb4d9db17537 | 973 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 974 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 975 | } |
mbed_official | 376:cb4d9db17537 | 976 | return status; |
mbed_official | 376:cb4d9db17537 | 977 | } |
mbed_official | 489:119543c9f674 | 978 | #endif |
mbed_official | 376:cb4d9db17537 | 979 | |
mbed_official | 376:cb4d9db17537 | 980 | /** |
mbed_official | 489:119543c9f674 | 981 | * @brief Write Option Byte of the desired pages of the Flash. |
mbed_official | 489:119543c9f674 | 982 | * @param Sector: specifies the sectors to be write protected. |
mbed_official | 489:119543c9f674 | 983 | * @param Sector2: specifies the sectors to be write protected only stm32l07xxx and stm32l08xxx devices |
mbed_official | 489:119543c9f674 | 984 | * @param NewState: new state of the specified FLASH Pages Wite protection. |
mbed_official | 489:119543c9f674 | 985 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 489:119543c9f674 | 986 | * @retval HAL_StatusTypeDef |
mbed_official | 376:cb4d9db17537 | 987 | */ |
mbed_official | 489:119543c9f674 | 988 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 489:119543c9f674 | 989 | static HAL_StatusTypeDef FLASH_OB_ProtectedSectorsConfig(uint32_t Sector, uint32_t Sector2, uint32_t NewState) |
mbed_official | 489:119543c9f674 | 990 | #else |
mbed_official | 489:119543c9f674 | 991 | static HAL_StatusTypeDef FLASH_OB_ProtectedSectorsConfig(uint32_t Sector, uint32_t NewState) |
mbed_official | 489:119543c9f674 | 992 | #endif |
mbed_official | 376:cb4d9db17537 | 993 | { |
mbed_official | 489:119543c9f674 | 994 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 489:119543c9f674 | 995 | uint32_t WRP_Data = 0; |
mbed_official | 489:119543c9f674 | 996 | uint32_t OB_WRP = Sector; |
mbed_official | 376:cb4d9db17537 | 997 | |
mbed_official | 376:cb4d9db17537 | 998 | /* Check the parameters */ |
mbed_official | 489:119543c9f674 | 999 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 376:cb4d9db17537 | 1000 | |
mbed_official | 376:cb4d9db17537 | 1001 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 1002 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 1003 | |
mbed_official | 376:cb4d9db17537 | 1004 | if(status == HAL_OK) |
mbed_official | 376:cb4d9db17537 | 1005 | { |
mbed_official | 489:119543c9f674 | 1006 | /* Clean the error context */ |
mbed_official | 489:119543c9f674 | 1007 | ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 376:cb4d9db17537 | 1008 | |
mbed_official | 489:119543c9f674 | 1009 | if (OB_WRP & 0x0000FFFF) |
mbed_official | 489:119543c9f674 | 1010 | { |
mbed_official | 489:119543c9f674 | 1011 | if (NewState != OB_WRPSTATE_DISABLE) |
mbed_official | 489:119543c9f674 | 1012 | { |
mbed_official | 489:119543c9f674 | 1013 | WRP_Data = (uint16_t)(((OB_WRP & WRP_MASK_LOW) | OB->WRP01)); |
mbed_official | 489:119543c9f674 | 1014 | OB->WRP01 = (uint32_t)(~(WRP_Data) << 16) | (WRP_Data); |
mbed_official | 489:119543c9f674 | 1015 | } |
mbed_official | 489:119543c9f674 | 1016 | else |
mbed_official | 489:119543c9f674 | 1017 | { |
mbed_official | 489:119543c9f674 | 1018 | WRP_Data = (uint16_t)(~OB_WRP & (WRP_MASK_LOW & OB->WRP01)); |
mbed_official | 489:119543c9f674 | 1019 | OB->WRP01 = (uint32_t)((~WRP_Data) << 16) | (WRP_Data); |
mbed_official | 489:119543c9f674 | 1020 | } |
mbed_official | 489:119543c9f674 | 1021 | } |
mbed_official | 489:119543c9f674 | 1022 | #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx) |
mbed_official | 489:119543c9f674 | 1023 | if (OB_WRP & 0xFFFF0000) |
mbed_official | 489:119543c9f674 | 1024 | { |
mbed_official | 489:119543c9f674 | 1025 | if (NewState != OB_WRPSTATE_DISABLE) |
mbed_official | 489:119543c9f674 | 1026 | { |
mbed_official | 489:119543c9f674 | 1027 | WRP_Data = (uint16_t)((((OB_WRP & WRP_MASK_HIGH) >> 16 | OB->WRP23))); |
mbed_official | 489:119543c9f674 | 1028 | OB->WRP23 = (uint32_t)(~(WRP_Data) << 16) | (WRP_Data); |
mbed_official | 489:119543c9f674 | 1029 | } |
mbed_official | 489:119543c9f674 | 1030 | else |
mbed_official | 489:119543c9f674 | 1031 | { |
mbed_official | 489:119543c9f674 | 1032 | WRP_Data = (uint16_t)((((~OB_WRP & WRP_MASK_HIGH) >> 16 & OB->WRP23))); |
mbed_official | 489:119543c9f674 | 1033 | OB->WRP23 = (uint32_t)((~WRP_Data) << 16) | (WRP_Data); |
mbed_official | 489:119543c9f674 | 1034 | } |
mbed_official | 489:119543c9f674 | 1035 | } |
mbed_official | 376:cb4d9db17537 | 1036 | |
mbed_official | 489:119543c9f674 | 1037 | OB_WRP = Sector2; |
mbed_official | 489:119543c9f674 | 1038 | if (OB_WRP & 0x0000FFFF) |
mbed_official | 489:119543c9f674 | 1039 | { |
mbed_official | 489:119543c9f674 | 1040 | if (NewState != OB_WRPSTATE_DISABLE) |
mbed_official | 489:119543c9f674 | 1041 | { |
mbed_official | 489:119543c9f674 | 1042 | WRP_Data = (uint16_t)(((OB_WRP & WRP_MASK_LOW) | OB->WRP45)); |
mbed_official | 489:119543c9f674 | 1043 | OB->WRP45 =(uint32_t)(~(WRP_Data) << 16) | (WRP_Data); |
mbed_official | 489:119543c9f674 | 1044 | } |
mbed_official | 489:119543c9f674 | 1045 | else |
mbed_official | 489:119543c9f674 | 1046 | { |
mbed_official | 489:119543c9f674 | 1047 | WRP_Data = (uint16_t)(~OB_WRP & (WRP_MASK_LOW & OB->WRP45)); |
mbed_official | 489:119543c9f674 | 1048 | OB->WRP45 = (uint32_t)((~WRP_Data) << 16) | (WRP_Data); |
mbed_official | 489:119543c9f674 | 1049 | } |
mbed_official | 489:119543c9f674 | 1050 | } |
mbed_official | 489:119543c9f674 | 1051 | #endif /* STM32L071xx || STM32L072xx || STM32L073xx || STM32L081xx || STM32L082xx || STM32L083xx */ |
mbed_official | 489:119543c9f674 | 1052 | } |
mbed_official | 376:cb4d9db17537 | 1053 | /* Wait for last operation to be completed */ |
mbed_official | 489:119543c9f674 | 1054 | status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); |
mbed_official | 376:cb4d9db17537 | 1055 | |
mbed_official | 489:119543c9f674 | 1056 | /* Return the write protection operation Status */ |
mbed_official | 489:119543c9f674 | 1057 | return status; |
mbed_official | 376:cb4d9db17537 | 1058 | } |
mbed_official | 376:cb4d9db17537 | 1059 | |
mbed_official | 376:cb4d9db17537 | 1060 | /** |
mbed_official | 376:cb4d9db17537 | 1061 | * @} |
mbed_official | 376:cb4d9db17537 | 1062 | */ |
mbed_official | 489:119543c9f674 | 1063 | #endif /* HAL_FLASH_MODULE_ENABLED */ |
mbed_official | 376:cb4d9db17537 | 1064 | |
mbed_official | 376:cb4d9db17537 | 1065 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |