mbed w/ spi bug fig

Dependents:   display-puck

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu May 22 20:00:09 2014 +0100
Revision:
205:c41fc65bcfb4
Child:
218:44081b78fdc2
Synchronized with git revision ea4b6f76efab17a3f7d7777b0cc1ef05fec6d1cb

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

[NUCLEO_F072RB] cmsis files

Who changed what in which revision?

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