Fawwaz Nadzmy / mbed-dev

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Thu Nov 24 17:03:03 2016 +0000
Revision:
151:5eaa88a5bcc7
Parent:
149:156823d33999
This updates the lib to the mbed lib v130

Who changed what in which revision?

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