GameOpener / mbed-src

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Nov 03 10:30:07 2014 +0000
Revision:
381:5460fc57b6e4
Synchronized with git revision 02478cd1f27fc7b9643486472635eb515b2bca81

Full URL: https://github.com/mbedmicro/mbed/commit/02478cd1f27fc7b9643486472635eb515b2bca81/

Target: LPC1549 - Fix serial interrupt issues (issue report #616)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 381:5460fc57b6e4 1 /**
mbed_official 381:5460fc57b6e4 2 ******************************************************************************
mbed_official 381:5460fc57b6e4 3 * @file stm32f3xx_hal_flash_ex.c
mbed_official 381:5460fc57b6e4 4 * @author MCD Application Team
mbed_official 381:5460fc57b6e4 5 * @version V1.1.0
mbed_official 381:5460fc57b6e4 6 * @date 12-Sept-2014
mbed_official 381:5460fc57b6e4 7 * @brief Extended FLASH HAL module driver.
mbed_official 381:5460fc57b6e4 8 *
mbed_official 381:5460fc57b6e4 9 * This file provides firmware functions to manage the following
mbed_official 381:5460fc57b6e4 10 * functionalities of the FLASH peripheral:
mbed_official 381:5460fc57b6e4 11 * + Extended Initialization/de-initialization functions
mbed_official 381:5460fc57b6e4 12 * + Extended I/O operation functions
mbed_official 381:5460fc57b6e4 13 * + Extended Peripheral Control functions
mbed_official 381:5460fc57b6e4 14 * + Extended Peripheral State functions
mbed_official 381:5460fc57b6e4 15 *
mbed_official 381:5460fc57b6e4 16 @verbatim
mbed_official 381:5460fc57b6e4 17 ==============================================================================
mbed_official 381:5460fc57b6e4 18 ##### Flash peripheral extended features #####
mbed_official 381:5460fc57b6e4 19 ==============================================================================
mbed_official 381:5460fc57b6e4 20
mbed_official 381:5460fc57b6e4 21 ##### How to use this driver #####
mbed_official 381:5460fc57b6e4 22 ==============================================================================
mbed_official 381:5460fc57b6e4 23 [..] This driver provides functions to configure and program the FLASH memory
mbed_official 381:5460fc57b6e4 24 of all STM32F3xxx devices. It includes
mbed_official 381:5460fc57b6e4 25
mbed_official 381:5460fc57b6e4 26 (++) Set/Reset the write protection
mbed_official 381:5460fc57b6e4 27 (++) Program the user Option Bytes
mbed_official 381:5460fc57b6e4 28 (++) Get the Read protection Level
mbed_official 381:5460fc57b6e4 29
mbed_official 381:5460fc57b6e4 30 @endverbatim
mbed_official 381:5460fc57b6e4 31 ******************************************************************************
mbed_official 381:5460fc57b6e4 32 * @attention
mbed_official 381:5460fc57b6e4 33 *
mbed_official 381:5460fc57b6e4 34 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 381:5460fc57b6e4 35 *
mbed_official 381:5460fc57b6e4 36 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 381:5460fc57b6e4 37 * are permitted provided that the following conditions are met:
mbed_official 381:5460fc57b6e4 38 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 381:5460fc57b6e4 39 * this list of conditions and the following disclaimer.
mbed_official 381:5460fc57b6e4 40 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 381:5460fc57b6e4 41 * this list of conditions and the following disclaimer in the documentation
mbed_official 381:5460fc57b6e4 42 * and/or other materials provided with the distribution.
mbed_official 381:5460fc57b6e4 43 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 381:5460fc57b6e4 44 * may be used to endorse or promote products derived from this software
mbed_official 381:5460fc57b6e4 45 * without specific prior written permission.
mbed_official 381:5460fc57b6e4 46 *
mbed_official 381:5460fc57b6e4 47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 381:5460fc57b6e4 48 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 381:5460fc57b6e4 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 381:5460fc57b6e4 50 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 381:5460fc57b6e4 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 381:5460fc57b6e4 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 381:5460fc57b6e4 53 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 381:5460fc57b6e4 54 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 381:5460fc57b6e4 55 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 381:5460fc57b6e4 56 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 381:5460fc57b6e4 57 *
mbed_official 381:5460fc57b6e4 58 ******************************************************************************
mbed_official 381:5460fc57b6e4 59 */
mbed_official 381:5460fc57b6e4 60
mbed_official 381:5460fc57b6e4 61 /* Includes ------------------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 62 #include "stm32f3xx_hal.h"
mbed_official 381:5460fc57b6e4 63
mbed_official 381:5460fc57b6e4 64 /** @addtogroup STM32F3xx_HAL_Driver
mbed_official 381:5460fc57b6e4 65 * @{
mbed_official 381:5460fc57b6e4 66 */
mbed_official 381:5460fc57b6e4 67
mbed_official 381:5460fc57b6e4 68 /** @addtogroup FLASHEx FLASH Extended HAL module driver
mbed_official 381:5460fc57b6e4 69 * @brief FLASH Extended HAL module driver
mbed_official 381:5460fc57b6e4 70 * @{
mbed_official 381:5460fc57b6e4 71 */
mbed_official 381:5460fc57b6e4 72
mbed_official 381:5460fc57b6e4 73 #ifdef HAL_FLASH_MODULE_ENABLED
mbed_official 381:5460fc57b6e4 74
mbed_official 381:5460fc57b6e4 75 /* Private typedef -----------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 76 /* Private define ------------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 77 /** @defgroup FLASHEx_Private_Defines FLASH Extended Private Define
mbed_official 381:5460fc57b6e4 78 * @{
mbed_official 381:5460fc57b6e4 79 */
mbed_official 381:5460fc57b6e4 80 #define HAL_FLASH_TIMEOUT_VALUE ((uint32_t)50000)/* 50 s */
mbed_official 381:5460fc57b6e4 81 /**
mbed_official 381:5460fc57b6e4 82 * @}
mbed_official 381:5460fc57b6e4 83 */
mbed_official 381:5460fc57b6e4 84
mbed_official 381:5460fc57b6e4 85 /* Private macro -------------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 86 /* Private variables ---------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 87 /** @defgroup FLASHEx_Private_Variables FLASH Extended Private Variables
mbed_official 381:5460fc57b6e4 88 * @{
mbed_official 381:5460fc57b6e4 89 */
mbed_official 381:5460fc57b6e4 90 /* Variables used for Erase pages under interruption*/
mbed_official 381:5460fc57b6e4 91 extern FLASH_ProcessTypeDef pFlash;
mbed_official 381:5460fc57b6e4 92 /**
mbed_official 381:5460fc57b6e4 93 * @}
mbed_official 381:5460fc57b6e4 94 */
mbed_official 381:5460fc57b6e4 95
mbed_official 381:5460fc57b6e4 96 /* Private function prototypes -----------------------------------------------*/
mbed_official 381:5460fc57b6e4 97 /** @defgroup FLASHEx_Private_Functions FLASH Extended Private Functions
mbed_official 381:5460fc57b6e4 98 * @{
mbed_official 381:5460fc57b6e4 99 */
mbed_official 381:5460fc57b6e4 100 /* Erase operations */
mbed_official 381:5460fc57b6e4 101 static void FLASH_MassErase(void);
mbed_official 381:5460fc57b6e4 102
mbed_official 381:5460fc57b6e4 103 /* Option bytes control */
mbed_official 381:5460fc57b6e4 104 static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage);
mbed_official 381:5460fc57b6e4 105 static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage);
mbed_official 381:5460fc57b6e4 106 static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel);
mbed_official 381:5460fc57b6e4 107 static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig);
mbed_official 381:5460fc57b6e4 108 static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data);
mbed_official 381:5460fc57b6e4 109 static uint32_t FLASH_OB_GetWRP(void);
mbed_official 381:5460fc57b6e4 110 static FlagStatus FLASH_OB_GetRDP(void);
mbed_official 381:5460fc57b6e4 111 static uint8_t FLASH_OB_GetUser(void);
mbed_official 381:5460fc57b6e4 112 /**
mbed_official 381:5460fc57b6e4 113 * @}
mbed_official 381:5460fc57b6e4 114 */
mbed_official 381:5460fc57b6e4 115
mbed_official 381:5460fc57b6e4 116 /* Exported functions ---------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 117 /** @defgroup FLASHEx_Exported_Functions FLASH Extended Exported Functions
mbed_official 381:5460fc57b6e4 118 * @{
mbed_official 381:5460fc57b6e4 119 */
mbed_official 381:5460fc57b6e4 120
mbed_official 381:5460fc57b6e4 121 /** @defgroup FLASHEx_Exported_Functions_Group1 Extended Input and Output operation functions
mbed_official 381:5460fc57b6e4 122 * @brief I/O operation functions
mbed_official 381:5460fc57b6e4 123 *
mbed_official 381:5460fc57b6e4 124 @verbatim
mbed_official 381:5460fc57b6e4 125 ===============================================================================
mbed_official 381:5460fc57b6e4 126 ##### IO operation functions #####
mbed_official 381:5460fc57b6e4 127 ===============================================================================
mbed_official 381:5460fc57b6e4 128
mbed_official 381:5460fc57b6e4 129 @endverbatim
mbed_official 381:5460fc57b6e4 130 * @{
mbed_official 381:5460fc57b6e4 131 */
mbed_official 381:5460fc57b6e4 132 /**
mbed_official 381:5460fc57b6e4 133 * @brief Perform a mass erase or erase the specified FLASH memory pages
mbed_official 381:5460fc57b6e4 134 * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
mbed_official 381:5460fc57b6e4 135 * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
mbed_official 381:5460fc57b6e4 136 * @param[in] pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that
mbed_official 381:5460fc57b6e4 137 * contains the configuration information for the erasing.
mbed_official 381:5460fc57b6e4 138 *
mbed_official 381:5460fc57b6e4 139 * @param[out] PageError: pointer to variable that
mbed_official 381:5460fc57b6e4 140 * contains the configuration information on faulty page in case of error
mbed_official 381:5460fc57b6e4 141 * (0xFFFFFFFF means that all the pages have been correctly erased)
mbed_official 381:5460fc57b6e4 142 *
mbed_official 381:5460fc57b6e4 143 * @retval HAL_StatusTypeDef HAL Status
mbed_official 381:5460fc57b6e4 144 */
mbed_official 381:5460fc57b6e4 145 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)
mbed_official 381:5460fc57b6e4 146 {
mbed_official 381:5460fc57b6e4 147 HAL_StatusTypeDef status = HAL_ERROR;
mbed_official 381:5460fc57b6e4 148 uint32_t address = 0;
mbed_official 381:5460fc57b6e4 149
mbed_official 381:5460fc57b6e4 150 /* Process Locked */
mbed_official 381:5460fc57b6e4 151 __HAL_LOCK(&pFlash);
mbed_official 381:5460fc57b6e4 152
mbed_official 381:5460fc57b6e4 153 /* Check the parameters */
mbed_official 381:5460fc57b6e4 154 assert_param(IS_TYPEERASE(pEraseInit->TypeErase));
mbed_official 381:5460fc57b6e4 155
mbed_official 381:5460fc57b6e4 156 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 157 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 158
mbed_official 381:5460fc57b6e4 159 if (status == HAL_OK)
mbed_official 381:5460fc57b6e4 160 {
mbed_official 381:5460fc57b6e4 161 if (pEraseInit->TypeErase == TYPEERASE_MASSERASE)
mbed_official 381:5460fc57b6e4 162 {
mbed_official 381:5460fc57b6e4 163 /*Mass erase to be done*/
mbed_official 381:5460fc57b6e4 164 FLASH_MassErase();
mbed_official 381:5460fc57b6e4 165
mbed_official 381:5460fc57b6e4 166 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 167 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 168
mbed_official 381:5460fc57b6e4 169 /* Check FLASH End of Operation flag */
mbed_official 381:5460fc57b6e4 170 if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
mbed_official 381:5460fc57b6e4 171 {
mbed_official 381:5460fc57b6e4 172 /* Clear FLASH End of Operation pending bit */
mbed_official 381:5460fc57b6e4 173 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
mbed_official 381:5460fc57b6e4 174 }
mbed_official 381:5460fc57b6e4 175
mbed_official 381:5460fc57b6e4 176 /* If the erase operation is completed, disable the MER Bit */
mbed_official 381:5460fc57b6e4 177 CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
mbed_official 381:5460fc57b6e4 178 }
mbed_official 381:5460fc57b6e4 179 else
mbed_official 381:5460fc57b6e4 180 {
mbed_official 381:5460fc57b6e4 181 /* Check the parameters */
mbed_official 381:5460fc57b6e4 182 assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress));
mbed_official 381:5460fc57b6e4 183 assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages));
mbed_official 381:5460fc57b6e4 184
mbed_official 381:5460fc57b6e4 185 /*Initialization of PageError variable*/
mbed_official 381:5460fc57b6e4 186 *PageError = 0xFFFFFFFF;
mbed_official 381:5460fc57b6e4 187
mbed_official 381:5460fc57b6e4 188 /* Erase by page by page to be done*/
mbed_official 381:5460fc57b6e4 189 for(address = pEraseInit->PageAddress;
mbed_official 381:5460fc57b6e4 190 address < (pEraseInit->PageAddress + (pEraseInit->NbPages)*FLASH_PAGE_SIZE);
mbed_official 381:5460fc57b6e4 191 address += FLASH_PAGE_SIZE)
mbed_official 381:5460fc57b6e4 192 {
mbed_official 381:5460fc57b6e4 193 FLASH_PageErase(address);
mbed_official 381:5460fc57b6e4 194
mbed_official 381:5460fc57b6e4 195 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 196 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 197
mbed_official 381:5460fc57b6e4 198 /* Check FLASH End of Operation flag */
mbed_official 381:5460fc57b6e4 199 if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
mbed_official 381:5460fc57b6e4 200 {
mbed_official 381:5460fc57b6e4 201 /* Clear FLASH End of Operation pending bit */
mbed_official 381:5460fc57b6e4 202 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
mbed_official 381:5460fc57b6e4 203 }
mbed_official 381:5460fc57b6e4 204
mbed_official 381:5460fc57b6e4 205 /* If the erase operation is completed, disable the PER Bit */
mbed_official 381:5460fc57b6e4 206 CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
mbed_official 381:5460fc57b6e4 207
mbed_official 381:5460fc57b6e4 208 if (status != HAL_OK)
mbed_official 381:5460fc57b6e4 209 {
mbed_official 381:5460fc57b6e4 210 /* In case of error, stop erase procedure and return the faulty address */
mbed_official 381:5460fc57b6e4 211 *PageError = address;
mbed_official 381:5460fc57b6e4 212 break;
mbed_official 381:5460fc57b6e4 213 }
mbed_official 381:5460fc57b6e4 214 }
mbed_official 381:5460fc57b6e4 215 }
mbed_official 381:5460fc57b6e4 216 }
mbed_official 381:5460fc57b6e4 217
mbed_official 381:5460fc57b6e4 218 /* Process Unlocked */
mbed_official 381:5460fc57b6e4 219 __HAL_UNLOCK(&pFlash);
mbed_official 381:5460fc57b6e4 220
mbed_official 381:5460fc57b6e4 221 return status;
mbed_official 381:5460fc57b6e4 222 }
mbed_official 381:5460fc57b6e4 223
mbed_official 381:5460fc57b6e4 224 /**
mbed_official 381:5460fc57b6e4 225 * @brief Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled
mbed_official 381:5460fc57b6e4 226 * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
mbed_official 381:5460fc57b6e4 227 * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
mbed_official 381:5460fc57b6e4 228 * @param pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that
mbed_official 381:5460fc57b6e4 229 * contains the configuration information for the erasing.
mbed_official 381:5460fc57b6e4 230 *
mbed_official 381:5460fc57b6e4 231 * @retval HAL_StatusTypeDef HAL Status
mbed_official 381:5460fc57b6e4 232 */
mbed_official 381:5460fc57b6e4 233 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
mbed_official 381:5460fc57b6e4 234 {
mbed_official 381:5460fc57b6e4 235 HAL_StatusTypeDef status = HAL_OK;
mbed_official 381:5460fc57b6e4 236
mbed_official 381:5460fc57b6e4 237 /* Process Locked */
mbed_official 381:5460fc57b6e4 238 __HAL_LOCK(&pFlash);
mbed_official 381:5460fc57b6e4 239
mbed_official 381:5460fc57b6e4 240 /* Check the parameters */
mbed_official 381:5460fc57b6e4 241 assert_param(IS_TYPEERASE(pEraseInit->TypeErase));
mbed_official 381:5460fc57b6e4 242
mbed_official 381:5460fc57b6e4 243 /* Enable End of FLASH Operation and Error source interrupts */
mbed_official 381:5460fc57b6e4 244 __HAL_FLASH_ENABLE_IT((FLASH_IT_EOP | FLASH_IT_ERR));
mbed_official 381:5460fc57b6e4 245
mbed_official 381:5460fc57b6e4 246 if (pEraseInit->TypeErase == TYPEERASE_MASSERASE)
mbed_official 381:5460fc57b6e4 247 {
mbed_official 381:5460fc57b6e4 248 /*Mass erase to be done*/
mbed_official 381:5460fc57b6e4 249 pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE;
mbed_official 381:5460fc57b6e4 250 FLASH_MassErase();
mbed_official 381:5460fc57b6e4 251 }
mbed_official 381:5460fc57b6e4 252 else
mbed_official 381:5460fc57b6e4 253 {
mbed_official 381:5460fc57b6e4 254 /* Erase by page to be done*/
mbed_official 381:5460fc57b6e4 255
mbed_official 381:5460fc57b6e4 256 /* Check the parameters */
mbed_official 381:5460fc57b6e4 257 assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress));
mbed_official 381:5460fc57b6e4 258 assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages));
mbed_official 381:5460fc57b6e4 259
mbed_official 381:5460fc57b6e4 260 pFlash.ProcedureOnGoing = FLASH_PROC_PAGEERASE;
mbed_official 381:5460fc57b6e4 261 pFlash.DataRemaining = pEraseInit->NbPages;
mbed_official 381:5460fc57b6e4 262 pFlash.Address = pEraseInit->PageAddress;
mbed_official 381:5460fc57b6e4 263
mbed_official 381:5460fc57b6e4 264 /*Erase 1st page and wait for IT*/
mbed_official 381:5460fc57b6e4 265 FLASH_PageErase(pEraseInit->PageAddress);
mbed_official 381:5460fc57b6e4 266 }
mbed_official 381:5460fc57b6e4 267
mbed_official 381:5460fc57b6e4 268 return status;
mbed_official 381:5460fc57b6e4 269 }
mbed_official 381:5460fc57b6e4 270
mbed_official 381:5460fc57b6e4 271 /**
mbed_official 381:5460fc57b6e4 272 * @}
mbed_official 381:5460fc57b6e4 273 */
mbed_official 381:5460fc57b6e4 274
mbed_official 381:5460fc57b6e4 275 /** @defgroup FLASHEx_Exported_Functions_Group2 Extended Peripheral Control functions
mbed_official 381:5460fc57b6e4 276 * @brief Peripheral Control functions
mbed_official 381:5460fc57b6e4 277 *
mbed_official 381:5460fc57b6e4 278 @verbatim
mbed_official 381:5460fc57b6e4 279 ===============================================================================
mbed_official 381:5460fc57b6e4 280 ##### Peripheral Control functions #####
mbed_official 381:5460fc57b6e4 281 ===============================================================================
mbed_official 381:5460fc57b6e4 282 [..]
mbed_official 381:5460fc57b6e4 283 This subsection provides a set of functions allowing to control the FLASH
mbed_official 381:5460fc57b6e4 284 memory operations.
mbed_official 381:5460fc57b6e4 285
mbed_official 381:5460fc57b6e4 286 @endverbatim
mbed_official 381:5460fc57b6e4 287 * @{
mbed_official 381:5460fc57b6e4 288 */
mbed_official 381:5460fc57b6e4 289 /**
mbed_official 381:5460fc57b6e4 290 * @brief Erases the FLASH option bytes.
mbed_official 381:5460fc57b6e4 291 * @note This functions erases all option bytes except the Read protection (RDP).
mbed_official 381:5460fc57b6e4 292 * The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
mbed_official 381:5460fc57b6e4 293 * The function HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes
mbed_official 381:5460fc57b6e4 294 * The function HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes
mbed_official 381:5460fc57b6e4 295 * (system reset will occur)
mbed_official 381:5460fc57b6e4 296 * @retval HAL status
mbed_official 381:5460fc57b6e4 297 */
mbed_official 381:5460fc57b6e4 298
mbed_official 381:5460fc57b6e4 299 HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
mbed_official 381:5460fc57b6e4 300 {
mbed_official 381:5460fc57b6e4 301 uint8_t rdptmp = OB_RDP_LEVEL_0;
mbed_official 381:5460fc57b6e4 302 HAL_StatusTypeDef status = HAL_ERROR;
mbed_official 381:5460fc57b6e4 303 FLASH_OBProgramInitTypeDef optionsbytes;
mbed_official 381:5460fc57b6e4 304
mbed_official 381:5460fc57b6e4 305 /* Get the actual read protection Option Byte value */
mbed_official 381:5460fc57b6e4 306 HAL_FLASHEx_OBGetConfig(&optionsbytes);
mbed_official 381:5460fc57b6e4 307 if(optionsbytes.RDPLevel != RESET)
mbed_official 381:5460fc57b6e4 308 {
mbed_official 381:5460fc57b6e4 309 rdptmp = OB_RDP_LEVEL_1;
mbed_official 381:5460fc57b6e4 310 }
mbed_official 381:5460fc57b6e4 311
mbed_official 381:5460fc57b6e4 312 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 313 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 314
mbed_official 381:5460fc57b6e4 315 /* Clear pending flags (if any) */
mbed_official 381:5460fc57b6e4 316 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
mbed_official 381:5460fc57b6e4 317
mbed_official 381:5460fc57b6e4 318 if(status == HAL_OK)
mbed_official 381:5460fc57b6e4 319 {
mbed_official 381:5460fc57b6e4 320 /* If the previous operation is completed, proceed to erase the option bytes */
mbed_official 381:5460fc57b6e4 321 SET_BIT(FLASH->CR, FLASH_CR_OPTER);
mbed_official 381:5460fc57b6e4 322 SET_BIT(FLASH->CR, FLASH_CR_STRT);
mbed_official 381:5460fc57b6e4 323
mbed_official 381:5460fc57b6e4 324 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 325 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 326
mbed_official 381:5460fc57b6e4 327 /* If the erase operation is completed, disable the OPTER Bit */
mbed_official 381:5460fc57b6e4 328 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);
mbed_official 381:5460fc57b6e4 329
mbed_official 381:5460fc57b6e4 330 if(status == HAL_OK)
mbed_official 381:5460fc57b6e4 331 {
mbed_official 381:5460fc57b6e4 332 /* Restore the last read protection Option Byte value */
mbed_official 381:5460fc57b6e4 333 optionsbytes.OptionType = OPTIONBYTE_RDP;
mbed_official 381:5460fc57b6e4 334 optionsbytes.RDPLevel = rdptmp;
mbed_official 381:5460fc57b6e4 335 status = HAL_FLASHEx_OBProgram(&optionsbytes);
mbed_official 381:5460fc57b6e4 336 }
mbed_official 381:5460fc57b6e4 337 }
mbed_official 381:5460fc57b6e4 338
mbed_official 381:5460fc57b6e4 339 /* Return the erase status */
mbed_official 381:5460fc57b6e4 340 return status;
mbed_official 381:5460fc57b6e4 341 }
mbed_official 381:5460fc57b6e4 342
mbed_official 381:5460fc57b6e4 343 /**
mbed_official 381:5460fc57b6e4 344 * @brief Program option bytes
mbed_official 381:5460fc57b6e4 345 * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
mbed_official 381:5460fc57b6e4 346 * The function HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes
mbed_official 381:5460fc57b6e4 347 * The function HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes
mbed_official 381:5460fc57b6e4 348 * (system reset will occur)
mbed_official 381:5460fc57b6e4 349 *
mbed_official 381:5460fc57b6e4 350 * @param pOBInit: pointer to an FLASH_OBInitStruct structure that
mbed_official 381:5460fc57b6e4 351 * contains the configuration information for the programming.
mbed_official 381:5460fc57b6e4 352 *
mbed_official 381:5460fc57b6e4 353 * @retval HAL_StatusTypeDef HAL Status
mbed_official 381:5460fc57b6e4 354 */
mbed_official 381:5460fc57b6e4 355 HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
mbed_official 381:5460fc57b6e4 356 {
mbed_official 381:5460fc57b6e4 357 HAL_StatusTypeDef status = HAL_ERROR;
mbed_official 381:5460fc57b6e4 358
mbed_official 381:5460fc57b6e4 359 /* Check the parameters */
mbed_official 381:5460fc57b6e4 360 assert_param(IS_OPTIONBYTE(pOBInit->OptionType));
mbed_official 381:5460fc57b6e4 361
mbed_official 381:5460fc57b6e4 362 /* Write protection configuration */
mbed_official 381:5460fc57b6e4 363 if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP)
mbed_official 381:5460fc57b6e4 364 {
mbed_official 381:5460fc57b6e4 365 assert_param(IS_WRPSTATE(pOBInit->WRPState));
mbed_official 381:5460fc57b6e4 366 if (pOBInit->WRPState == WRPSTATE_ENABLE)
mbed_official 381:5460fc57b6e4 367 {
mbed_official 381:5460fc57b6e4 368 /* Enable of Write protection on the selected page */
mbed_official 381:5460fc57b6e4 369 status = FLASH_OB_EnableWRP(pOBInit->WRPPage);
mbed_official 381:5460fc57b6e4 370 }
mbed_official 381:5460fc57b6e4 371 else
mbed_official 381:5460fc57b6e4 372 {
mbed_official 381:5460fc57b6e4 373 /* Disable of Write protection on the selected page */
mbed_official 381:5460fc57b6e4 374 status = FLASH_OB_DisableWRP(pOBInit->WRPPage);
mbed_official 381:5460fc57b6e4 375 }
mbed_official 381:5460fc57b6e4 376 }
mbed_official 381:5460fc57b6e4 377
mbed_official 381:5460fc57b6e4 378 /* Read protection configuration */
mbed_official 381:5460fc57b6e4 379 if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP)
mbed_official 381:5460fc57b6e4 380 {
mbed_official 381:5460fc57b6e4 381 status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel);
mbed_official 381:5460fc57b6e4 382 }
mbed_official 381:5460fc57b6e4 383
mbed_official 381:5460fc57b6e4 384 /* USER configuration */
mbed_official 381:5460fc57b6e4 385 if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER)
mbed_official 381:5460fc57b6e4 386 {
mbed_official 381:5460fc57b6e4 387 status = FLASH_OB_UserConfig(pOBInit->USERConfig);
mbed_official 381:5460fc57b6e4 388 }
mbed_official 381:5460fc57b6e4 389
mbed_official 381:5460fc57b6e4 390 /* DATA configuration*/
mbed_official 381:5460fc57b6e4 391 if((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA)
mbed_official 381:5460fc57b6e4 392 {
mbed_official 381:5460fc57b6e4 393 status = FLASH_OB_ProgramData(pOBInit->DATAAddress, pOBInit->DATAData);
mbed_official 381:5460fc57b6e4 394 }
mbed_official 381:5460fc57b6e4 395
mbed_official 381:5460fc57b6e4 396 return status;
mbed_official 381:5460fc57b6e4 397 }
mbed_official 381:5460fc57b6e4 398
mbed_official 381:5460fc57b6e4 399 /**
mbed_official 381:5460fc57b6e4 400 * @brief Get the Option byte configuration
mbed_official 381:5460fc57b6e4 401 * @param pOBInit: pointer to an FLASH_OBInitStruct structure that
mbed_official 381:5460fc57b6e4 402 * contains the configuration information for the programming.
mbed_official 381:5460fc57b6e4 403 *
mbed_official 381:5460fc57b6e4 404 * @retval None
mbed_official 381:5460fc57b6e4 405 */
mbed_official 381:5460fc57b6e4 406 void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
mbed_official 381:5460fc57b6e4 407 {
mbed_official 381:5460fc57b6e4 408 pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER;
mbed_official 381:5460fc57b6e4 409
mbed_official 381:5460fc57b6e4 410 /*Get WRP*/
mbed_official 381:5460fc57b6e4 411 pOBInit->WRPPage = FLASH_OB_GetWRP();
mbed_official 381:5460fc57b6e4 412
mbed_official 381:5460fc57b6e4 413 /*Get RDP Level*/
mbed_official 381:5460fc57b6e4 414 pOBInit->RDPLevel = FLASH_OB_GetRDP();
mbed_official 381:5460fc57b6e4 415
mbed_official 381:5460fc57b6e4 416 /*Get USER*/
mbed_official 381:5460fc57b6e4 417 pOBInit->USERConfig = FLASH_OB_GetUser();
mbed_official 381:5460fc57b6e4 418 }
mbed_official 381:5460fc57b6e4 419
mbed_official 381:5460fc57b6e4 420 /**
mbed_official 381:5460fc57b6e4 421 * @}
mbed_official 381:5460fc57b6e4 422 */
mbed_official 381:5460fc57b6e4 423
mbed_official 381:5460fc57b6e4 424 /**
mbed_official 381:5460fc57b6e4 425 * @}
mbed_official 381:5460fc57b6e4 426 */
mbed_official 381:5460fc57b6e4 427
mbed_official 381:5460fc57b6e4 428 /** @addtogroup FLASHEx_Private_Functions FLASH Extended Private Functions
mbed_official 381:5460fc57b6e4 429 * @{
mbed_official 381:5460fc57b6e4 430 */
mbed_official 381:5460fc57b6e4 431
mbed_official 381:5460fc57b6e4 432 /**
mbed_official 381:5460fc57b6e4 433 * @brief Mass erase of FLASH memory
mbed_official 381:5460fc57b6e4 434 *
mbed_official 381:5460fc57b6e4 435 * @retval None
mbed_official 381:5460fc57b6e4 436 */
mbed_official 381:5460fc57b6e4 437 static void FLASH_MassErase(void)
mbed_official 381:5460fc57b6e4 438 {
mbed_official 381:5460fc57b6e4 439 /* Clear pending flags (if any) */
mbed_official 381:5460fc57b6e4 440 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
mbed_official 381:5460fc57b6e4 441
mbed_official 381:5460fc57b6e4 442 /* Proceed to erase all sectors */
mbed_official 381:5460fc57b6e4 443 SET_BIT(FLASH->CR, FLASH_CR_MER);
mbed_official 381:5460fc57b6e4 444 SET_BIT(FLASH->CR, FLASH_CR_STRT);
mbed_official 381:5460fc57b6e4 445 }
mbed_official 381:5460fc57b6e4 446
mbed_official 381:5460fc57b6e4 447 /**
mbed_official 381:5460fc57b6e4 448 * @}
mbed_official 381:5460fc57b6e4 449 */
mbed_official 381:5460fc57b6e4 450
mbed_official 381:5460fc57b6e4 451 /**
mbed_official 381:5460fc57b6e4 452 * @brief Enable the write protection of the desired pages
mbed_official 381:5460fc57b6e4 453 * @note When the memory read protection level is selected (RDP level = 1),
mbed_official 381:5460fc57b6e4 454 * it is not possible to program or erase the flash page i if CortexM4
mbed_official 381:5460fc57b6e4 455 * debug features are connected or boot code is executed in RAM, even if nWRPi = 1
mbed_official 381:5460fc57b6e4 456 *
mbed_official 381:5460fc57b6e4 457 * @param WriteProtectPage: specifies the page(s) to be write protected.
mbed_official 381:5460fc57b6e4 458 * The value of this parameter depend on device used within the same series
mbed_official 381:5460fc57b6e4 459 * @retval HAL status
mbed_official 381:5460fc57b6e4 460 */
mbed_official 381:5460fc57b6e4 461 static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
mbed_official 381:5460fc57b6e4 462 {
mbed_official 381:5460fc57b6e4 463 HAL_StatusTypeDef status = HAL_OK;
mbed_official 381:5460fc57b6e4 464 uint16_t WRP0_Data = 0xFFFF, WRP1_Data = 0xFFFF;
mbed_official 381:5460fc57b6e4 465 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
mbed_official 381:5460fc57b6e4 466 defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \
mbed_official 381:5460fc57b6e4 467 defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 381:5460fc57b6e4 468 uint16_t WRP2_Data = 0xFFFF, WRP3_Data = 0xFFFF;
mbed_official 381:5460fc57b6e4 469 #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
mbed_official 381:5460fc57b6e4 470 /* STM32F302xC || STM32F303xC || STM32F358xx || */
mbed_official 381:5460fc57b6e4 471 /* STM32F373xC || STM32F378xx */
mbed_official 381:5460fc57b6e4 472
mbed_official 381:5460fc57b6e4 473 /* Check the parameters */
mbed_official 381:5460fc57b6e4 474 assert_param(IS_OB_WRP(WriteProtectPage));
mbed_official 381:5460fc57b6e4 475
mbed_official 381:5460fc57b6e4 476 WriteProtectPage = (uint32_t)(~WriteProtectPage);
mbed_official 381:5460fc57b6e4 477 WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK);
mbed_official 381:5460fc57b6e4 478 WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8);
mbed_official 381:5460fc57b6e4 479 #if defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \
mbed_official 381:5460fc57b6e4 480 defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 381:5460fc57b6e4 481 WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16);
mbed_official 381:5460fc57b6e4 482 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24);
mbed_official 381:5460fc57b6e4 483 #endif /* STM32F302xC || STM32F303xC || STM32F358xx || */
mbed_official 381:5460fc57b6e4 484 /* STM32F373xC || STM32F378xx */
mbed_official 381:5460fc57b6e4 485
mbed_official 381:5460fc57b6e4 486 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx)
mbed_official 381:5460fc57b6e4 487 WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16);
mbed_official 381:5460fc57b6e4 488 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO255MASK) >> 24);
mbed_official 381:5460fc57b6e4 489 #endif /* STM32F302xE || STM32F303xE || STM32F398xx */
mbed_official 381:5460fc57b6e4 490
mbed_official 381:5460fc57b6e4 491 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 492 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 493
mbed_official 381:5460fc57b6e4 494 /* Clear pending flags (if any) */
mbed_official 381:5460fc57b6e4 495 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
mbed_official 381:5460fc57b6e4 496
mbed_official 381:5460fc57b6e4 497 if(status == HAL_OK)
mbed_official 381:5460fc57b6e4 498 {
mbed_official 381:5460fc57b6e4 499 SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
mbed_official 381:5460fc57b6e4 500
mbed_official 381:5460fc57b6e4 501 if(WRP0_Data != 0xFF)
mbed_official 381:5460fc57b6e4 502 {
mbed_official 381:5460fc57b6e4 503 OB->WRP0 &= WRP0_Data;
mbed_official 381:5460fc57b6e4 504
mbed_official 381:5460fc57b6e4 505 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 506 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 507 }
mbed_official 381:5460fc57b6e4 508
mbed_official 381:5460fc57b6e4 509 if((status == HAL_OK) && (WRP1_Data != 0xFF))
mbed_official 381:5460fc57b6e4 510 {
mbed_official 381:5460fc57b6e4 511 OB->WRP1 &= WRP1_Data;
mbed_official 381:5460fc57b6e4 512
mbed_official 381:5460fc57b6e4 513 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 514 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 515 }
mbed_official 381:5460fc57b6e4 516
mbed_official 381:5460fc57b6e4 517 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
mbed_official 381:5460fc57b6e4 518 defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \
mbed_official 381:5460fc57b6e4 519 defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 381:5460fc57b6e4 520 if((status == HAL_OK) && (WRP2_Data != 0xFF))
mbed_official 381:5460fc57b6e4 521 {
mbed_official 381:5460fc57b6e4 522 OB->WRP2 &= WRP2_Data;
mbed_official 381:5460fc57b6e4 523
mbed_official 381:5460fc57b6e4 524 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 525 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 526 }
mbed_official 381:5460fc57b6e4 527
mbed_official 381:5460fc57b6e4 528 if((status == HAL_OK) && (WRP3_Data != 0xFF))
mbed_official 381:5460fc57b6e4 529 {
mbed_official 381:5460fc57b6e4 530 OB->WRP3 &= WRP3_Data;
mbed_official 381:5460fc57b6e4 531
mbed_official 381:5460fc57b6e4 532 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 533 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 534 }
mbed_official 381:5460fc57b6e4 535 #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
mbed_official 381:5460fc57b6e4 536 /* STM32F302xC || STM32F303xC || STM32F358xx || */
mbed_official 381:5460fc57b6e4 537 /* STM32F373xC || STM32F378xx */
mbed_official 381:5460fc57b6e4 538
mbed_official 381:5460fc57b6e4 539 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 381:5460fc57b6e4 540 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
mbed_official 381:5460fc57b6e4 541 }
mbed_official 381:5460fc57b6e4 542
mbed_official 381:5460fc57b6e4 543 return status;
mbed_official 381:5460fc57b6e4 544
mbed_official 381:5460fc57b6e4 545 }
mbed_official 381:5460fc57b6e4 546
mbed_official 381:5460fc57b6e4 547 /**
mbed_official 381:5460fc57b6e4 548 * @brief Disable the write protection of the desired pages
mbed_official 381:5460fc57b6e4 549 * @note When the memory read protection level is selected (RDP level = 1),
mbed_official 381:5460fc57b6e4 550 * it is not possible to program or erase the flash page i if CortexM4
mbed_official 381:5460fc57b6e4 551 * debug features are connected or boot code is executed in RAM, even if nWRPi = 1
mbed_official 381:5460fc57b6e4 552 *
mbed_official 381:5460fc57b6e4 553 * @param WriteProtectPage: specifies the page(s) to be write unprotected.
mbed_official 381:5460fc57b6e4 554 * The value of this parameter depend on device used within the same series
mbed_official 381:5460fc57b6e4 555 * @retval HAL status
mbed_official 381:5460fc57b6e4 556 */
mbed_official 381:5460fc57b6e4 557 static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
mbed_official 381:5460fc57b6e4 558 {
mbed_official 381:5460fc57b6e4 559 HAL_StatusTypeDef status = HAL_OK;
mbed_official 381:5460fc57b6e4 560 uint16_t WRP0_Data = 0xFFFF, WRP1_Data = 0xFFFF;
mbed_official 381:5460fc57b6e4 561 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
mbed_official 381:5460fc57b6e4 562 defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \
mbed_official 381:5460fc57b6e4 563 defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 381:5460fc57b6e4 564 uint16_t WRP2_Data = 0xFFFF, WRP3_Data = 0xFFFF;
mbed_official 381:5460fc57b6e4 565 #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
mbed_official 381:5460fc57b6e4 566 /* STM32F302xC || STM32F303xC || STM32F358xx || */
mbed_official 381:5460fc57b6e4 567 /* STM32F373xC || STM32F378xx */
mbed_official 381:5460fc57b6e4 568
mbed_official 381:5460fc57b6e4 569 /* Check the parameters */
mbed_official 381:5460fc57b6e4 570 assert_param(IS_OB_WRP(WriteProtectPage));
mbed_official 381:5460fc57b6e4 571
mbed_official 381:5460fc57b6e4 572 WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK);
mbed_official 381:5460fc57b6e4 573 WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8);
mbed_official 381:5460fc57b6e4 574 #if defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \
mbed_official 381:5460fc57b6e4 575 defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 381:5460fc57b6e4 576 WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16);
mbed_official 381:5460fc57b6e4 577 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24);
mbed_official 381:5460fc57b6e4 578 #endif /* STM32F302xC || STM32F303xC || STM32F358xx || */
mbed_official 381:5460fc57b6e4 579 /* STM32F373xC || STM32F378xx */
mbed_official 381:5460fc57b6e4 580
mbed_official 381:5460fc57b6e4 581 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx)
mbed_official 381:5460fc57b6e4 582 WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16);
mbed_official 381:5460fc57b6e4 583 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO255MASK) >> 24);
mbed_official 381:5460fc57b6e4 584 #endif /* STM32F303xE || STM32F303xE || STM32F398xx */
mbed_official 381:5460fc57b6e4 585
mbed_official 381:5460fc57b6e4 586 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 587 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 588
mbed_official 381:5460fc57b6e4 589 /* Clear pending flags (if any) */
mbed_official 381:5460fc57b6e4 590 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
mbed_official 381:5460fc57b6e4 591
mbed_official 381:5460fc57b6e4 592 if(status == HAL_OK)
mbed_official 381:5460fc57b6e4 593 {
mbed_official 381:5460fc57b6e4 594 SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
mbed_official 381:5460fc57b6e4 595
mbed_official 381:5460fc57b6e4 596 if(WRP0_Data != 0xFF)
mbed_official 381:5460fc57b6e4 597 {
mbed_official 381:5460fc57b6e4 598 OB->WRP0 |= WRP0_Data;
mbed_official 381:5460fc57b6e4 599
mbed_official 381:5460fc57b6e4 600 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 601 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 602 }
mbed_official 381:5460fc57b6e4 603
mbed_official 381:5460fc57b6e4 604 if((status == HAL_OK) && (WRP1_Data != 0xFF))
mbed_official 381:5460fc57b6e4 605 {
mbed_official 381:5460fc57b6e4 606 OB->WRP1 |= WRP1_Data;
mbed_official 381:5460fc57b6e4 607
mbed_official 381:5460fc57b6e4 608 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 609 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 610 }
mbed_official 381:5460fc57b6e4 611
mbed_official 381:5460fc57b6e4 612 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
mbed_official 381:5460fc57b6e4 613 defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \
mbed_official 381:5460fc57b6e4 614 defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 381:5460fc57b6e4 615 if((status == HAL_OK) && (WRP2_Data != 0xFF))
mbed_official 381:5460fc57b6e4 616 {
mbed_official 381:5460fc57b6e4 617 OB->WRP2 |= WRP2_Data;
mbed_official 381:5460fc57b6e4 618
mbed_official 381:5460fc57b6e4 619 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 620 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 621 }
mbed_official 381:5460fc57b6e4 622
mbed_official 381:5460fc57b6e4 623 if((status == HAL_OK) && (WRP3_Data != 0xFF))
mbed_official 381:5460fc57b6e4 624 {
mbed_official 381:5460fc57b6e4 625 OB->WRP3 |= WRP3_Data;
mbed_official 381:5460fc57b6e4 626
mbed_official 381:5460fc57b6e4 627 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 628 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 629 }
mbed_official 381:5460fc57b6e4 630 #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
mbed_official 381:5460fc57b6e4 631 /* STM32F302xC || STM32F303xC || STM32F358xx || */
mbed_official 381:5460fc57b6e4 632 /* STM32F373xC || STM32F378xx */
mbed_official 381:5460fc57b6e4 633
mbed_official 381:5460fc57b6e4 634 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 381:5460fc57b6e4 635 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
mbed_official 381:5460fc57b6e4 636 }
mbed_official 381:5460fc57b6e4 637
mbed_official 381:5460fc57b6e4 638 return status;
mbed_official 381:5460fc57b6e4 639 }
mbed_official 381:5460fc57b6e4 640
mbed_official 381:5460fc57b6e4 641 /**
mbed_official 381:5460fc57b6e4 642 * @brief Set the read protection level.
mbed_official 381:5460fc57b6e4 643 * @param ReadProtectLevel: specifies the read protection level.
mbed_official 381:5460fc57b6e4 644 * This parameter can be one of the following values:
mbed_official 381:5460fc57b6e4 645 * @arg OB_RDP_LEVEL_0: No protection
mbed_official 381:5460fc57b6e4 646 * @arg OB_RDP_LEVEL_1: Read protection of the memory
mbed_official 381:5460fc57b6e4 647 * @arg OB_RDP_LEVEL_2: Full chip protection
mbed_official 381:5460fc57b6e4 648 *
mbed_official 381:5460fc57b6e4 649 * @note Warning: When enabling OB_RDP level 2 it's no more possible to go back to level 1 or 0
mbed_official 381:5460fc57b6e4 650 *
mbed_official 381:5460fc57b6e4 651 * @retval HAL status
mbed_official 381:5460fc57b6e4 652 */
mbed_official 381:5460fc57b6e4 653 static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
mbed_official 381:5460fc57b6e4 654 {
mbed_official 381:5460fc57b6e4 655 HAL_StatusTypeDef status = HAL_OK;
mbed_official 381:5460fc57b6e4 656
mbed_official 381:5460fc57b6e4 657 /* Check the parameters */
mbed_official 381:5460fc57b6e4 658 assert_param(IS_OB_RDP_LEVEL(ReadProtectLevel));
mbed_official 381:5460fc57b6e4 659
mbed_official 381:5460fc57b6e4 660 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 661 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 662
mbed_official 381:5460fc57b6e4 663 /* Clear pending flags (if any) */
mbed_official 381:5460fc57b6e4 664 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
mbed_official 381:5460fc57b6e4 665
mbed_official 381:5460fc57b6e4 666 if(status == HAL_OK)
mbed_official 381:5460fc57b6e4 667 {
mbed_official 381:5460fc57b6e4 668 /* Enable the Option Bytes Programming operation */
mbed_official 381:5460fc57b6e4 669 SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
mbed_official 381:5460fc57b6e4 670
mbed_official 381:5460fc57b6e4 671 WRITE_REG(OB->RDP, ReadProtectLevel);
mbed_official 381:5460fc57b6e4 672
mbed_official 381:5460fc57b6e4 673 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 674 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 675
mbed_official 381:5460fc57b6e4 676 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 381:5460fc57b6e4 677 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
mbed_official 381:5460fc57b6e4 678 }
mbed_official 381:5460fc57b6e4 679
mbed_official 381:5460fc57b6e4 680 return status;
mbed_official 381:5460fc57b6e4 681 }
mbed_official 381:5460fc57b6e4 682
mbed_official 381:5460fc57b6e4 683 /**
mbed_official 381:5460fc57b6e4 684 * @brief Program the FLASH User Option Byte.
mbed_official 381:5460fc57b6e4 685 * @note Programming of the OB should be performed only after an erase (otherwise PGERR occurs)
mbed_official 381:5460fc57b6e4 686 * @param UserConfig: The FLASH User Option Bytes values: IWDG_SW(Bit0), RST_STOP(Bit1), RST_STDBY(Bit2), BOOT1(Bit4),
mbed_official 381:5460fc57b6e4 687 * VDDA_Analog_Monitoring(Bit5) and SRAM_Parity_Enable(Bit6).
mbed_official 381:5460fc57b6e4 688 * And SDADC12_VDD_MONITOR(Bit7) for STM32F373 or STM32F378 .
mbed_official 381:5460fc57b6e4 689 * @retval HAL status
mbed_official 381:5460fc57b6e4 690 */
mbed_official 381:5460fc57b6e4 691 static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig)
mbed_official 381:5460fc57b6e4 692 {
mbed_official 381:5460fc57b6e4 693 HAL_StatusTypeDef status = HAL_OK;
mbed_official 381:5460fc57b6e4 694
mbed_official 381:5460fc57b6e4 695 /* Check the parameters */
mbed_official 381:5460fc57b6e4 696 assert_param(IS_OB_IWDG_SOURCE((UserConfig&OB_IWDG_SW)));
mbed_official 381:5460fc57b6e4 697 assert_param(IS_OB_STOP_SOURCE((UserConfig&OB_STOP_NO_RST)));
mbed_official 381:5460fc57b6e4 698 assert_param(IS_OB_STDBY_SOURCE((UserConfig&OB_STDBY_NO_RST)));
mbed_official 381:5460fc57b6e4 699 assert_param(IS_OB_BOOT1((UserConfig&OB_BOOT1_SET)));
mbed_official 381:5460fc57b6e4 700 assert_param(IS_OB_VDDA_ANALOG((UserConfig&OB_VDDA_ANALOG_ON)));
mbed_official 381:5460fc57b6e4 701 assert_param(IS_OB_SRAM_PARITY((UserConfig&OB_SRAM_PARITY_RESET)));
mbed_official 381:5460fc57b6e4 702 #if defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 381:5460fc57b6e4 703 assert_param(IS_OB_SDACD_VDD_MONITOR((UserConfig&OB_SDACD_VDD_MONITOR_SET)));
mbed_official 381:5460fc57b6e4 704 #endif /* STM32F373xC || STM32F378xx */
mbed_official 381:5460fc57b6e4 705
mbed_official 381:5460fc57b6e4 706 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 707 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 708
mbed_official 381:5460fc57b6e4 709 /* Clear pending flags (if any) */
mbed_official 381:5460fc57b6e4 710 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
mbed_official 381:5460fc57b6e4 711
mbed_official 381:5460fc57b6e4 712 if(status == HAL_OK)
mbed_official 381:5460fc57b6e4 713 {
mbed_official 381:5460fc57b6e4 714 /* Enable the Option Bytes Programming operation */
mbed_official 381:5460fc57b6e4 715 SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
mbed_official 381:5460fc57b6e4 716
mbed_official 381:5460fc57b6e4 717 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
mbed_official 381:5460fc57b6e4 718 defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \
mbed_official 381:5460fc57b6e4 719 defined(STM32F303x8) || defined(STM32F334x8) || \
mbed_official 381:5460fc57b6e4 720 defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
mbed_official 381:5460fc57b6e4 721 OB->USER = (UserConfig | 0x88);
mbed_official 381:5460fc57b6e4 722 #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
mbed_official 381:5460fc57b6e4 723 /* STM32F302xC || STM32F303xC || STM32F358xx || */
mbed_official 381:5460fc57b6e4 724 /* STM32F303x8 || STM32F334x8 || */
mbed_official 381:5460fc57b6e4 725 /* STM32F301x8 || STM32F302x8 || STM32F318xx */
mbed_official 381:5460fc57b6e4 726
mbed_official 381:5460fc57b6e4 727 #if defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 381:5460fc57b6e4 728 OB->USER = (UserConfig | 0x08);
mbed_official 381:5460fc57b6e4 729 #endif /* STM32F373xC || STM32F378xx */
mbed_official 381:5460fc57b6e4 730
mbed_official 381:5460fc57b6e4 731 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 732 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 733
mbed_official 381:5460fc57b6e4 734 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 381:5460fc57b6e4 735 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
mbed_official 381:5460fc57b6e4 736 }
mbed_official 381:5460fc57b6e4 737
mbed_official 381:5460fc57b6e4 738 return status;
mbed_official 381:5460fc57b6e4 739 }
mbed_official 381:5460fc57b6e4 740
mbed_official 381:5460fc57b6e4 741 /**
mbed_official 381:5460fc57b6e4 742 * @brief Programs a half word at a specified Option Byte Data address.
mbed_official 381:5460fc57b6e4 743 * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
mbed_official 381:5460fc57b6e4 744 * The function HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes
mbed_official 381:5460fc57b6e4 745 * The function HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes
mbed_official 381:5460fc57b6e4 746 * (system reset will occur)
mbed_official 381:5460fc57b6e4 747 * Programming of the OB should be performed only after an erase (otherwise PGERR occurs)
mbed_official 381:5460fc57b6e4 748 * @param Address: specifies the address to be programmed.
mbed_official 381:5460fc57b6e4 749 * This parameter can be 0x1FFFF804 or 0x1FFFF806.
mbed_official 381:5460fc57b6e4 750 * @param Data: specifies the data to be programmed.
mbed_official 381:5460fc57b6e4 751 * @retval HAL status
mbed_official 381:5460fc57b6e4 752 */
mbed_official 381:5460fc57b6e4 753 static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data)
mbed_official 381:5460fc57b6e4 754 {
mbed_official 381:5460fc57b6e4 755 HAL_StatusTypeDef status = HAL_ERROR;
mbed_official 381:5460fc57b6e4 756
mbed_official 381:5460fc57b6e4 757 /* Check the parameters */
mbed_official 381:5460fc57b6e4 758 assert_param(IS_OB_DATA_ADDRESS(Address));
mbed_official 381:5460fc57b6e4 759
mbed_official 381:5460fc57b6e4 760 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 761 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 762
mbed_official 381:5460fc57b6e4 763 /* Clear pending flags (if any) */
mbed_official 381:5460fc57b6e4 764 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
mbed_official 381:5460fc57b6e4 765
mbed_official 381:5460fc57b6e4 766 if(status == HAL_OK)
mbed_official 381:5460fc57b6e4 767 {
mbed_official 381:5460fc57b6e4 768 /* Enables the Option Bytes Programming operation */
mbed_official 381:5460fc57b6e4 769 SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
mbed_official 381:5460fc57b6e4 770 *(__IO uint16_t*)Address = Data;
mbed_official 381:5460fc57b6e4 771
mbed_official 381:5460fc57b6e4 772 /* Wait for last operation to be completed */
mbed_official 381:5460fc57b6e4 773 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 381:5460fc57b6e4 774
mbed_official 381:5460fc57b6e4 775 /* If the program operation is completed, disable the OPTPG Bit */
mbed_official 381:5460fc57b6e4 776 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
mbed_official 381:5460fc57b6e4 777 }
mbed_official 381:5460fc57b6e4 778 /* Return the Option Byte Data Program Status */
mbed_official 381:5460fc57b6e4 779 return status;
mbed_official 381:5460fc57b6e4 780 }
mbed_official 381:5460fc57b6e4 781
mbed_official 381:5460fc57b6e4 782 /**
mbed_official 381:5460fc57b6e4 783 * @brief Return the FLASH Write Protection Option Bytes value.
mbed_official 381:5460fc57b6e4 784 * @retval The FLASH Write Protection Option Bytes value
mbed_official 381:5460fc57b6e4 785 */
mbed_official 381:5460fc57b6e4 786 static uint32_t FLASH_OB_GetWRP(void)
mbed_official 381:5460fc57b6e4 787 {
mbed_official 381:5460fc57b6e4 788 /* Return the FLASH write protection Register value */
mbed_official 381:5460fc57b6e4 789 return (uint32_t)(READ_REG(FLASH->WRPR));
mbed_official 381:5460fc57b6e4 790 }
mbed_official 381:5460fc57b6e4 791
mbed_official 381:5460fc57b6e4 792 /**
mbed_official 381:5460fc57b6e4 793 * @brief Returns the FLASH Read Protection level.
mbed_official 381:5460fc57b6e4 794 * @retval FLASH ReadOut Protection Status:
mbed_official 381:5460fc57b6e4 795 * - SET, when OB_RDP_Level_1 or OB_RDP_Level_2 is set
mbed_official 381:5460fc57b6e4 796 * - RESET, when OB_RDP_Level_0 is set
mbed_official 381:5460fc57b6e4 797 */
mbed_official 381:5460fc57b6e4 798 static FlagStatus FLASH_OB_GetRDP(void)
mbed_official 381:5460fc57b6e4 799 {
mbed_official 381:5460fc57b6e4 800 FlagStatus readstatus = RESET;
mbed_official 381:5460fc57b6e4 801
mbed_official 381:5460fc57b6e4 802 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
mbed_official 381:5460fc57b6e4 803 defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \
mbed_official 381:5460fc57b6e4 804 defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
mbed_official 381:5460fc57b6e4 805 defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
mbed_official 381:5460fc57b6e4 806 if ((uint8_t)READ_BIT(FLASH->OBR, FLASH_OBR_RDPRT) != RESET)
mbed_official 381:5460fc57b6e4 807 #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
mbed_official 381:5460fc57b6e4 808 /* STM32F302xC || STM32F303xC || STM32F358xx || */
mbed_official 381:5460fc57b6e4 809 /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
mbed_official 381:5460fc57b6e4 810 /* STM32F301x8 || STM32F302x8 || STM32F318xx */
mbed_official 381:5460fc57b6e4 811
mbed_official 381:5460fc57b6e4 812 #if defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 381:5460fc57b6e4 813 if ((uint8_t)READ_BIT(FLASH->OBR, (FLASH_OBR_LEVEL1_PROT | FLASH_OBR_LEVEL2_PROT)) != RESET)
mbed_official 381:5460fc57b6e4 814 #endif /* STM32F373xC || STM32F378xx */
mbed_official 381:5460fc57b6e4 815 {
mbed_official 381:5460fc57b6e4 816 readstatus = SET;
mbed_official 381:5460fc57b6e4 817 }
mbed_official 381:5460fc57b6e4 818 else
mbed_official 381:5460fc57b6e4 819 {
mbed_official 381:5460fc57b6e4 820 readstatus = RESET;
mbed_official 381:5460fc57b6e4 821 }
mbed_official 381:5460fc57b6e4 822 return readstatus;
mbed_official 381:5460fc57b6e4 823 }
mbed_official 381:5460fc57b6e4 824
mbed_official 381:5460fc57b6e4 825 /**
mbed_official 381:5460fc57b6e4 826 * @brief Return the FLASH User Option Byte value.
mbed_official 381:5460fc57b6e4 827 * @retval The FLASH User Option Bytes values: IWDG_SW(Bit0), RST_STOP(Bit1), RST_STDBY(Bit2), BOOT1(Bit4),
mbed_official 381:5460fc57b6e4 828 * VDDA_Analog_Monitoring(Bit5) and SRAM_Parity_Enable(Bit6).
mbed_official 381:5460fc57b6e4 829 * And SDADC12_VDD_MONITOR(Bit7) for STM32F373 or STM32F378 .
mbed_official 381:5460fc57b6e4 830 */
mbed_official 381:5460fc57b6e4 831 static uint8_t FLASH_OB_GetUser(void)
mbed_official 381:5460fc57b6e4 832 {
mbed_official 381:5460fc57b6e4 833 /* Return the User Option Byte */
mbed_official 381:5460fc57b6e4 834 return (uint8_t)(READ_REG(FLASH->OBR) >> 8);
mbed_official 381:5460fc57b6e4 835 }
mbed_official 381:5460fc57b6e4 836
mbed_official 381:5460fc57b6e4 837 /**
mbed_official 381:5460fc57b6e4 838 * @}
mbed_official 381:5460fc57b6e4 839 */
mbed_official 381:5460fc57b6e4 840
mbed_official 381:5460fc57b6e4 841 #endif /* HAL_FLASH_MODULE_ENABLED */
mbed_official 381:5460fc57b6e4 842
mbed_official 381:5460fc57b6e4 843
mbed_official 381:5460fc57b6e4 844 /**
mbed_official 381:5460fc57b6e4 845 * @}
mbed_official 381:5460fc57b6e4 846 */
mbed_official 381:5460fc57b6e4 847
mbed_official 381:5460fc57b6e4 848 /**
mbed_official 381:5460fc57b6e4 849 * @}
mbed_official 381:5460fc57b6e4 850 */
mbed_official 381:5460fc57b6e4 851
mbed_official 381:5460fc57b6e4 852 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/