Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more
targets/cmsis/TARGET_STM/TARGET_STM32F1/stm32f1xx_hal_flash_ex.c@581:39197bcd20f2, 2015-07-02 (annotated)
- Committer:
- mbed_official
- Date:
- Thu Jul 02 16:30:08 2015 +0100
- Revision:
- 581:39197bcd20f2
- Parent:
- 489:119543c9f674
Synchronized with git revision ae2d3cdffe70184eb8736d94f76c45c93f4b7724
Full URL: https://github.com/mbedmicro/mbed/commit/ae2d3cdffe70184eb8736d94f76c45c93f4b7724/
Make it possible to build the core mbed library with yotta
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_official | 489:119543c9f674 | 1 | /** |
| mbed_official | 489:119543c9f674 | 2 | ****************************************************************************** |
| mbed_official | 489:119543c9f674 | 3 | * @file stm32f1xx_hal_flash_ex.c |
| mbed_official | 489:119543c9f674 | 4 | * @author MCD Application Team |
| mbed_official | 489:119543c9f674 | 5 | * @version V1.0.0 |
| mbed_official | 489:119543c9f674 | 6 | * @date 15-December-2014 |
| mbed_official | 489:119543c9f674 | 7 | * @brief Extended FLASH HAL module driver. |
| mbed_official | 489:119543c9f674 | 8 | * |
| mbed_official | 489:119543c9f674 | 9 | * This file provides firmware functions to manage the following |
| mbed_official | 489:119543c9f674 | 10 | * functionalities of the FLASH peripheral: |
| mbed_official | 489:119543c9f674 | 11 | * + Extended Initialization/de-initialization functions |
| mbed_official | 489:119543c9f674 | 12 | * + Extended I/O operation functions |
| mbed_official | 489:119543c9f674 | 13 | * + Extended Peripheral Control functions |
| mbed_official | 489:119543c9f674 | 14 | * |
| mbed_official | 489:119543c9f674 | 15 | @verbatim |
| mbed_official | 489:119543c9f674 | 16 | ============================================================================== |
| mbed_official | 489:119543c9f674 | 17 | ##### Flash peripheral extended features ##### |
| mbed_official | 489:119543c9f674 | 18 | ============================================================================== |
| mbed_official | 489:119543c9f674 | 19 | |
| mbed_official | 489:119543c9f674 | 20 | ##### How to use this driver ##### |
| mbed_official | 489:119543c9f674 | 21 | ============================================================================== |
| mbed_official | 489:119543c9f674 | 22 | [..] This driver provides functions to configure and program the FLASH memory |
| mbed_official | 489:119543c9f674 | 23 | of all STM32F1xxx devices. It includes |
| mbed_official | 489:119543c9f674 | 24 | |
| mbed_official | 489:119543c9f674 | 25 | (++) Set/Reset the write protection |
| mbed_official | 489:119543c9f674 | 26 | (++) Program the user Option Bytes |
| mbed_official | 489:119543c9f674 | 27 | (++) Get the Read protection Level |
| mbed_official | 489:119543c9f674 | 28 | |
| mbed_official | 489:119543c9f674 | 29 | @endverbatim |
| mbed_official | 489:119543c9f674 | 30 | ****************************************************************************** |
| mbed_official | 489:119543c9f674 | 31 | * @attention |
| mbed_official | 489:119543c9f674 | 32 | * |
| mbed_official | 489:119543c9f674 | 33 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
| mbed_official | 489:119543c9f674 | 34 | * |
| mbed_official | 489:119543c9f674 | 35 | * Redistribution and use in source and binary forms, with or without modification, |
| mbed_official | 489:119543c9f674 | 36 | * are permitted provided that the following conditions are met: |
| mbed_official | 489:119543c9f674 | 37 | * 1. Redistributions of source code must retain the above copyright notice, |
| mbed_official | 489:119543c9f674 | 38 | * this list of conditions and the following disclaimer. |
| mbed_official | 489:119543c9f674 | 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| mbed_official | 489:119543c9f674 | 40 | * this list of conditions and the following disclaimer in the documentation |
| mbed_official | 489:119543c9f674 | 41 | * and/or other materials provided with the distribution. |
| mbed_official | 489:119543c9f674 | 42 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| mbed_official | 489:119543c9f674 | 43 | * may be used to endorse or promote products derived from this software |
| mbed_official | 489:119543c9f674 | 44 | * without specific prior written permission. |
| mbed_official | 489:119543c9f674 | 45 | * |
| mbed_official | 489:119543c9f674 | 46 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| mbed_official | 489:119543c9f674 | 47 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| mbed_official | 489:119543c9f674 | 48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| mbed_official | 489:119543c9f674 | 49 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| mbed_official | 489:119543c9f674 | 50 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| mbed_official | 489:119543c9f674 | 51 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| mbed_official | 489:119543c9f674 | 52 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| mbed_official | 489:119543c9f674 | 53 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| mbed_official | 489:119543c9f674 | 54 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| mbed_official | 489:119543c9f674 | 55 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| mbed_official | 489:119543c9f674 | 56 | * |
| mbed_official | 489:119543c9f674 | 57 | ****************************************************************************** |
| mbed_official | 489:119543c9f674 | 58 | */ |
| mbed_official | 489:119543c9f674 | 59 | |
| mbed_official | 489:119543c9f674 | 60 | /* Includes ------------------------------------------------------------------*/ |
| mbed_official | 489:119543c9f674 | 61 | #include "stm32f1xx_hal.h" |
| mbed_official | 489:119543c9f674 | 62 | |
| mbed_official | 489:119543c9f674 | 63 | /** @addtogroup STM32F1xx_HAL_Driver |
| mbed_official | 489:119543c9f674 | 64 | * @{ |
| mbed_official | 489:119543c9f674 | 65 | */ |
| mbed_official | 489:119543c9f674 | 66 | #ifdef HAL_FLASH_MODULE_ENABLED |
| mbed_official | 489:119543c9f674 | 67 | |
| mbed_official | 489:119543c9f674 | 68 | /** @addtogroup FLASH |
| mbed_official | 489:119543c9f674 | 69 | * @{ |
| mbed_official | 489:119543c9f674 | 70 | */ |
| mbed_official | 489:119543c9f674 | 71 | /** @addtogroup FLASH_Private_Variables |
| mbed_official | 489:119543c9f674 | 72 | * @{ |
| mbed_official | 489:119543c9f674 | 73 | */ |
| mbed_official | 489:119543c9f674 | 74 | /* Variables used for Erase pages under interruption*/ |
| mbed_official | 489:119543c9f674 | 75 | extern FLASH_ProcessTypeDef pFlash; |
| mbed_official | 489:119543c9f674 | 76 | /** |
| mbed_official | 489:119543c9f674 | 77 | * @} |
| mbed_official | 489:119543c9f674 | 78 | */ |
| mbed_official | 489:119543c9f674 | 79 | |
| mbed_official | 489:119543c9f674 | 80 | /** |
| mbed_official | 489:119543c9f674 | 81 | * @} |
| mbed_official | 489:119543c9f674 | 82 | */ |
| mbed_official | 489:119543c9f674 | 83 | |
| mbed_official | 489:119543c9f674 | 84 | /** @defgroup FLASHEx FLASHEx |
| mbed_official | 489:119543c9f674 | 85 | * @brief FLASH Extended HAL module driver |
| mbed_official | 489:119543c9f674 | 86 | * @{ |
| mbed_official | 489:119543c9f674 | 87 | */ |
| mbed_official | 489:119543c9f674 | 88 | |
| mbed_official | 489:119543c9f674 | 89 | /* Private typedef -----------------------------------------------------------*/ |
| mbed_official | 489:119543c9f674 | 90 | /* Private define ------------------------------------------------------------*/ |
| mbed_official | 489:119543c9f674 | 91 | /** @defgroup FLASHEx_Private_Constants FLASHEx Private Constants |
| mbed_official | 489:119543c9f674 | 92 | * @{ |
| mbed_official | 489:119543c9f674 | 93 | */ |
| mbed_official | 489:119543c9f674 | 94 | /** |
| mbed_official | 489:119543c9f674 | 95 | * @} |
| mbed_official | 489:119543c9f674 | 96 | */ |
| mbed_official | 489:119543c9f674 | 97 | |
| mbed_official | 489:119543c9f674 | 98 | /* Private macro -------------------------------------------------------------*/ |
| mbed_official | 489:119543c9f674 | 99 | /** @defgroup FLASHEx_Private_Macros FLASHEx Private Macros |
| mbed_official | 489:119543c9f674 | 100 | * @{ |
| mbed_official | 489:119543c9f674 | 101 | */ |
| mbed_official | 489:119543c9f674 | 102 | /** |
| mbed_official | 489:119543c9f674 | 103 | * @} |
| mbed_official | 489:119543c9f674 | 104 | */ |
| mbed_official | 489:119543c9f674 | 105 | |
| mbed_official | 489:119543c9f674 | 106 | /* Private variables ---------------------------------------------------------*/ |
| mbed_official | 489:119543c9f674 | 107 | /* Private function prototypes -----------------------------------------------*/ |
| mbed_official | 489:119543c9f674 | 108 | /** @defgroup FLASHEx_Private_Functions FLASHEx Private Functions |
| mbed_official | 489:119543c9f674 | 109 | * @{ |
| mbed_official | 489:119543c9f674 | 110 | */ |
| mbed_official | 489:119543c9f674 | 111 | /* Erase operations */ |
| mbed_official | 489:119543c9f674 | 112 | static void FLASH_MassErase(uint32_t Banks); |
| mbed_official | 489:119543c9f674 | 113 | |
| mbed_official | 489:119543c9f674 | 114 | /* Option bytes control */ |
| mbed_official | 489:119543c9f674 | 115 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage); |
| mbed_official | 489:119543c9f674 | 116 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage); |
| mbed_official | 489:119543c9f674 | 117 | static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel); |
| mbed_official | 489:119543c9f674 | 118 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig); |
| mbed_official | 489:119543c9f674 | 119 | static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data); |
| mbed_official | 489:119543c9f674 | 120 | static uint32_t FLASH_OB_GetWRP(void); |
| mbed_official | 489:119543c9f674 | 121 | static FlagStatus FLASH_OB_GetRDP(void); |
| mbed_official | 489:119543c9f674 | 122 | static uint8_t FLASH_OB_GetUser(void); |
| mbed_official | 489:119543c9f674 | 123 | |
| mbed_official | 489:119543c9f674 | 124 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 125 | /* State operations */ |
| mbed_official | 489:119543c9f674 | 126 | static HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout); |
| mbed_official | 489:119543c9f674 | 127 | #endif |
| mbed_official | 489:119543c9f674 | 128 | /** |
| mbed_official | 489:119543c9f674 | 129 | * @} |
| mbed_official | 489:119543c9f674 | 130 | */ |
| mbed_official | 489:119543c9f674 | 131 | |
| mbed_official | 489:119543c9f674 | 132 | /* Exported functions ---------------------------------------------------------*/ |
| mbed_official | 489:119543c9f674 | 133 | /** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions |
| mbed_official | 489:119543c9f674 | 134 | * @{ |
| mbed_official | 489:119543c9f674 | 135 | */ |
| mbed_official | 489:119543c9f674 | 136 | |
| mbed_official | 489:119543c9f674 | 137 | /** @defgroup FLASHEx_Exported_Functions_Group1 Extended Input and Output operation functions |
| mbed_official | 489:119543c9f674 | 138 | * @brief I/O operation functions |
| mbed_official | 489:119543c9f674 | 139 | * |
| mbed_official | 489:119543c9f674 | 140 | @verbatim |
| mbed_official | 489:119543c9f674 | 141 | =============================================================================== |
| mbed_official | 489:119543c9f674 | 142 | ##### IO operation functions ##### |
| mbed_official | 489:119543c9f674 | 143 | =============================================================================== |
| mbed_official | 489:119543c9f674 | 144 | |
| mbed_official | 489:119543c9f674 | 145 | @endverbatim |
| mbed_official | 489:119543c9f674 | 146 | * @{ |
| mbed_official | 489:119543c9f674 | 147 | */ |
| mbed_official | 489:119543c9f674 | 148 | |
| mbed_official | 489:119543c9f674 | 149 | |
| mbed_official | 489:119543c9f674 | 150 | /** |
| mbed_official | 489:119543c9f674 | 151 | * @brief Perform a mass erase or erase the specified FLASH memory pages |
| mbed_official | 489:119543c9f674 | 152 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
| mbed_official | 489:119543c9f674 | 153 | * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface |
| mbed_official | 489:119543c9f674 | 154 | * @param[in] pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
| mbed_official | 489:119543c9f674 | 155 | * contains the configuration information for the erasing. |
| mbed_official | 489:119543c9f674 | 156 | * |
| mbed_official | 489:119543c9f674 | 157 | * @param[out] PageError: pointer to variable that |
| mbed_official | 489:119543c9f674 | 158 | * contains the configuration information on faulty page in case of error |
| mbed_official | 489:119543c9f674 | 159 | * (0xFFFFFFFF means that all the pages have been correctly erased) |
| mbed_official | 489:119543c9f674 | 160 | * |
| mbed_official | 489:119543c9f674 | 161 | * @retval HAL_StatusTypeDef HAL Status |
| mbed_official | 489:119543c9f674 | 162 | */ |
| mbed_official | 489:119543c9f674 | 163 | HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError) |
| mbed_official | 489:119543c9f674 | 164 | { |
| mbed_official | 489:119543c9f674 | 165 | HAL_StatusTypeDef status = HAL_ERROR; |
| mbed_official | 489:119543c9f674 | 166 | uint32_t address = 0; |
| mbed_official | 489:119543c9f674 | 167 | |
| mbed_official | 489:119543c9f674 | 168 | /* Process Locked */ |
| mbed_official | 489:119543c9f674 | 169 | __HAL_LOCK(&pFlash); |
| mbed_official | 489:119543c9f674 | 170 | |
| mbed_official | 489:119543c9f674 | 171 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 172 | assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
| mbed_official | 489:119543c9f674 | 173 | |
| mbed_official | 489:119543c9f674 | 174 | if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) |
| mbed_official | 489:119543c9f674 | 175 | { |
| mbed_official | 489:119543c9f674 | 176 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 177 | if (pEraseInit->Banks == FLASH_BANK_BOTH) |
| mbed_official | 489:119543c9f674 | 178 | { |
| mbed_official | 489:119543c9f674 | 179 | /* Mass Erase requested for Bank1 and Bank2 */ |
| mbed_official | 489:119543c9f674 | 180 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 181 | if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && \ |
| mbed_official | 489:119543c9f674 | 182 | (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)) |
| mbed_official | 489:119543c9f674 | 183 | { |
| mbed_official | 489:119543c9f674 | 184 | /*Mass erase to be done*/ |
| mbed_official | 489:119543c9f674 | 185 | FLASH_MassErase(FLASH_BANK_BOTH); |
| mbed_official | 489:119543c9f674 | 186 | |
| mbed_official | 489:119543c9f674 | 187 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 188 | if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && \ |
| mbed_official | 489:119543c9f674 | 189 | (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)) |
| mbed_official | 489:119543c9f674 | 190 | { |
| mbed_official | 489:119543c9f674 | 191 | status = HAL_OK; |
| mbed_official | 489:119543c9f674 | 192 | } |
| mbed_official | 489:119543c9f674 | 193 | |
| mbed_official | 489:119543c9f674 | 194 | /* If the erase operation is completed, disable the MER Bit */ |
| mbed_official | 489:119543c9f674 | 195 | CLEAR_BIT(FLASH->CR, FLASH_CR_MER); |
| mbed_official | 489:119543c9f674 | 196 | CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER); |
| mbed_official | 489:119543c9f674 | 197 | } |
| mbed_official | 489:119543c9f674 | 198 | } |
| mbed_official | 489:119543c9f674 | 199 | else if (pEraseInit->Banks == FLASH_BANK_2) |
| mbed_official | 489:119543c9f674 | 200 | { |
| mbed_official | 489:119543c9f674 | 201 | /* Mass Erase requested for Bank2 */ |
| mbed_official | 489:119543c9f674 | 202 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 203 | if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) |
| mbed_official | 489:119543c9f674 | 204 | { |
| mbed_official | 489:119543c9f674 | 205 | /*Mass erase to be done*/ |
| mbed_official | 489:119543c9f674 | 206 | FLASH_MassErase(FLASH_BANK_2); |
| mbed_official | 489:119543c9f674 | 207 | |
| mbed_official | 489:119543c9f674 | 208 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 209 | status = FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 210 | |
| mbed_official | 489:119543c9f674 | 211 | /* If the erase operation is completed, disable the MER Bit */ |
| mbed_official | 489:119543c9f674 | 212 | CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER); |
| mbed_official | 489:119543c9f674 | 213 | } |
| mbed_official | 489:119543c9f674 | 214 | } |
| mbed_official | 489:119543c9f674 | 215 | else |
| mbed_official | 489:119543c9f674 | 216 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 217 | { |
| mbed_official | 489:119543c9f674 | 218 | /* Mass Erase requested for Bank1 */ |
| mbed_official | 489:119543c9f674 | 219 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 220 | if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) |
| mbed_official | 489:119543c9f674 | 221 | { |
| mbed_official | 489:119543c9f674 | 222 | /*Mass erase to be done*/ |
| mbed_official | 489:119543c9f674 | 223 | FLASH_MassErase(FLASH_BANK_1); |
| mbed_official | 489:119543c9f674 | 224 | |
| mbed_official | 489:119543c9f674 | 225 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 226 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 227 | |
| mbed_official | 489:119543c9f674 | 228 | /* If the erase operation is completed, disable the MER Bit */ |
| mbed_official | 489:119543c9f674 | 229 | CLEAR_BIT(FLASH->CR, FLASH_CR_MER); |
| mbed_official | 489:119543c9f674 | 230 | } |
| mbed_official | 489:119543c9f674 | 231 | } |
| mbed_official | 489:119543c9f674 | 232 | } |
| mbed_official | 489:119543c9f674 | 233 | else |
| mbed_official | 489:119543c9f674 | 234 | { |
| mbed_official | 489:119543c9f674 | 235 | /* Page Erase is requested */ |
| mbed_official | 489:119543c9f674 | 236 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 237 | assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress)); |
| mbed_official | 489:119543c9f674 | 238 | assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages)); |
| mbed_official | 489:119543c9f674 | 239 | |
| mbed_official | 489:119543c9f674 | 240 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 241 | /* Page Erase requested on address located on bank2 */ |
| mbed_official | 489:119543c9f674 | 242 | if(pEraseInit->PageAddress > FLASH_BANK1_END) |
| mbed_official | 489:119543c9f674 | 243 | { |
| mbed_official | 489:119543c9f674 | 244 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 245 | if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) |
| mbed_official | 489:119543c9f674 | 246 | { |
| mbed_official | 489:119543c9f674 | 247 | /*Initialization of PageError variable*/ |
| mbed_official | 489:119543c9f674 | 248 | *PageError = 0xFFFFFFFF; |
| mbed_official | 489:119543c9f674 | 249 | |
| mbed_official | 489:119543c9f674 | 250 | /* Erase by page by page to be done*/ |
| mbed_official | 489:119543c9f674 | 251 | for(address = pEraseInit->PageAddress; |
| mbed_official | 489:119543c9f674 | 252 | address < (pEraseInit->PageAddress + (pEraseInit->NbPages)*FLASH_PAGE_SIZE); |
| mbed_official | 489:119543c9f674 | 253 | address += FLASH_PAGE_SIZE) |
| mbed_official | 489:119543c9f674 | 254 | { |
| mbed_official | 489:119543c9f674 | 255 | FLASH_PageErase(address); |
| mbed_official | 489:119543c9f674 | 256 | |
| mbed_official | 489:119543c9f674 | 257 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 258 | status = FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 259 | |
| mbed_official | 489:119543c9f674 | 260 | /* If the erase operation is completed, disable the PER Bit */ |
| mbed_official | 489:119543c9f674 | 261 | CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER); |
| mbed_official | 489:119543c9f674 | 262 | |
| mbed_official | 489:119543c9f674 | 263 | if (status != HAL_OK) |
| mbed_official | 489:119543c9f674 | 264 | { |
| mbed_official | 489:119543c9f674 | 265 | /* In case of error, stop erase procedure and return the faulty address */ |
| mbed_official | 489:119543c9f674 | 266 | *PageError = address; |
| mbed_official | 489:119543c9f674 | 267 | break; |
| mbed_official | 489:119543c9f674 | 268 | } |
| mbed_official | 489:119543c9f674 | 269 | } |
| mbed_official | 489:119543c9f674 | 270 | } |
| mbed_official | 489:119543c9f674 | 271 | } |
| mbed_official | 489:119543c9f674 | 272 | else |
| mbed_official | 489:119543c9f674 | 273 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 274 | { |
| mbed_official | 489:119543c9f674 | 275 | /* Page Erase requested on address located on bank1 */ |
| mbed_official | 489:119543c9f674 | 276 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 277 | if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) |
| mbed_official | 489:119543c9f674 | 278 | { |
| mbed_official | 489:119543c9f674 | 279 | if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) |
| mbed_official | 489:119543c9f674 | 280 | { |
| mbed_official | 489:119543c9f674 | 281 | /*Mass erase to be done*/ |
| mbed_official | 489:119543c9f674 | 282 | FLASH_MassErase(pEraseInit->Banks); |
| mbed_official | 489:119543c9f674 | 283 | |
| mbed_official | 489:119543c9f674 | 284 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 285 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 286 | |
| mbed_official | 489:119543c9f674 | 287 | /* If the erase operation is completed, disable the MER Bit */ |
| mbed_official | 489:119543c9f674 | 288 | CLEAR_BIT(FLASH->CR, FLASH_CR_MER); |
| mbed_official | 489:119543c9f674 | 289 | } |
| mbed_official | 489:119543c9f674 | 290 | else |
| mbed_official | 489:119543c9f674 | 291 | { |
| mbed_official | 489:119543c9f674 | 292 | /*Initialization of PageError variable*/ |
| mbed_official | 489:119543c9f674 | 293 | *PageError = 0xFFFFFFFF; |
| mbed_official | 489:119543c9f674 | 294 | |
| mbed_official | 489:119543c9f674 | 295 | /* Erase by page by page to be done*/ |
| mbed_official | 489:119543c9f674 | 296 | for(address = pEraseInit->PageAddress; |
| mbed_official | 489:119543c9f674 | 297 | address < (pEraseInit->PageAddress + (pEraseInit->NbPages)*FLASH_PAGE_SIZE); |
| mbed_official | 489:119543c9f674 | 298 | address += FLASH_PAGE_SIZE) |
| mbed_official | 489:119543c9f674 | 299 | { |
| mbed_official | 489:119543c9f674 | 300 | FLASH_PageErase(address); |
| mbed_official | 489:119543c9f674 | 301 | |
| mbed_official | 489:119543c9f674 | 302 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 303 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 304 | |
| mbed_official | 489:119543c9f674 | 305 | /* If the erase operation is completed, disable the PER Bit */ |
| mbed_official | 489:119543c9f674 | 306 | CLEAR_BIT(FLASH->CR, FLASH_CR_PER); |
| mbed_official | 489:119543c9f674 | 307 | |
| mbed_official | 489:119543c9f674 | 308 | if (status != HAL_OK) |
| mbed_official | 489:119543c9f674 | 309 | { |
| mbed_official | 489:119543c9f674 | 310 | /* In case of error, stop erase procedure and return the faulty address */ |
| mbed_official | 489:119543c9f674 | 311 | *PageError = address; |
| mbed_official | 489:119543c9f674 | 312 | break; |
| mbed_official | 489:119543c9f674 | 313 | } |
| mbed_official | 489:119543c9f674 | 314 | } |
| mbed_official | 489:119543c9f674 | 315 | } |
| mbed_official | 489:119543c9f674 | 316 | } |
| mbed_official | 489:119543c9f674 | 317 | } |
| mbed_official | 489:119543c9f674 | 318 | } |
| mbed_official | 489:119543c9f674 | 319 | |
| mbed_official | 489:119543c9f674 | 320 | /* Process Unlocked */ |
| mbed_official | 489:119543c9f674 | 321 | __HAL_UNLOCK(&pFlash); |
| mbed_official | 489:119543c9f674 | 322 | |
| mbed_official | 489:119543c9f674 | 323 | return status; |
| mbed_official | 489:119543c9f674 | 324 | } |
| mbed_official | 489:119543c9f674 | 325 | |
| mbed_official | 489:119543c9f674 | 326 | /** |
| mbed_official | 489:119543c9f674 | 327 | * @brief Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled |
| mbed_official | 489:119543c9f674 | 328 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
| mbed_official | 489:119543c9f674 | 329 | * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface |
| mbed_official | 489:119543c9f674 | 330 | * @param pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
| mbed_official | 489:119543c9f674 | 331 | * contains the configuration information for the erasing. |
| mbed_official | 489:119543c9f674 | 332 | * |
| mbed_official | 489:119543c9f674 | 333 | * @retval HAL_StatusTypeDef HAL Status |
| mbed_official | 489:119543c9f674 | 334 | */ |
| mbed_official | 489:119543c9f674 | 335 | HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) |
| mbed_official | 489:119543c9f674 | 336 | { |
| mbed_official | 489:119543c9f674 | 337 | HAL_StatusTypeDef status = HAL_OK; |
| mbed_official | 489:119543c9f674 | 338 | |
| mbed_official | 489:119543c9f674 | 339 | /* Process Locked */ |
| mbed_official | 489:119543c9f674 | 340 | __HAL_LOCK(&pFlash); |
| mbed_official | 489:119543c9f674 | 341 | |
| mbed_official | 489:119543c9f674 | 342 | /* If procedure already ongoing, reject the next one */ |
| mbed_official | 489:119543c9f674 | 343 | if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) |
| mbed_official | 489:119543c9f674 | 344 | { |
| mbed_official | 489:119543c9f674 | 345 | return HAL_ERROR; |
| mbed_official | 489:119543c9f674 | 346 | } |
| mbed_official | 489:119543c9f674 | 347 | |
| mbed_official | 489:119543c9f674 | 348 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 349 | assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
| mbed_official | 489:119543c9f674 | 350 | |
| mbed_official | 489:119543c9f674 | 351 | /* Enable End of FLASH Operation and Error source interrupts */ |
| mbed_official | 489:119543c9f674 | 352 | __HAL_FLASH_ENABLE_IT((FLASH_IT_EOP | FLASH_IT_ERR)); |
| mbed_official | 489:119543c9f674 | 353 | |
| mbed_official | 489:119543c9f674 | 354 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 355 | /* Enable End of FLASH Operation and Error source interrupts */ |
| mbed_official | 489:119543c9f674 | 356 | __HAL_FLASH_ENABLE_IT((FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2)); |
| mbed_official | 489:119543c9f674 | 357 | #endif |
| mbed_official | 489:119543c9f674 | 358 | |
| mbed_official | 489:119543c9f674 | 359 | if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) |
| mbed_official | 489:119543c9f674 | 360 | { |
| mbed_official | 489:119543c9f674 | 361 | /*Mass erase to be done*/ |
| mbed_official | 489:119543c9f674 | 362 | pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE; |
| mbed_official | 489:119543c9f674 | 363 | FLASH_MassErase(pEraseInit->Banks); |
| mbed_official | 489:119543c9f674 | 364 | } |
| mbed_official | 489:119543c9f674 | 365 | else |
| mbed_official | 489:119543c9f674 | 366 | { |
| mbed_official | 489:119543c9f674 | 367 | /* Erase by page to be done*/ |
| mbed_official | 489:119543c9f674 | 368 | |
| mbed_official | 489:119543c9f674 | 369 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 370 | assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress)); |
| mbed_official | 489:119543c9f674 | 371 | assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages)); |
| mbed_official | 489:119543c9f674 | 372 | |
| mbed_official | 489:119543c9f674 | 373 | pFlash.ProcedureOnGoing = FLASH_PROC_PAGEERASE; |
| mbed_official | 489:119543c9f674 | 374 | pFlash.DataRemaining = pEraseInit->NbPages; |
| mbed_official | 489:119543c9f674 | 375 | pFlash.Address = pEraseInit->PageAddress; |
| mbed_official | 489:119543c9f674 | 376 | |
| mbed_official | 489:119543c9f674 | 377 | /*Erase 1st page and wait for IT*/ |
| mbed_official | 489:119543c9f674 | 378 | FLASH_PageErase(pEraseInit->PageAddress); |
| mbed_official | 489:119543c9f674 | 379 | } |
| mbed_official | 489:119543c9f674 | 380 | |
| mbed_official | 489:119543c9f674 | 381 | return status; |
| mbed_official | 489:119543c9f674 | 382 | } |
| mbed_official | 489:119543c9f674 | 383 | |
| mbed_official | 489:119543c9f674 | 384 | /** |
| mbed_official | 489:119543c9f674 | 385 | * @} |
| mbed_official | 489:119543c9f674 | 386 | */ |
| mbed_official | 489:119543c9f674 | 387 | |
| mbed_official | 489:119543c9f674 | 388 | /** @defgroup FLASHEx_Exported_Functions_Group2 Extended Peripheral Control functions |
| mbed_official | 489:119543c9f674 | 389 | * @brief Peripheral Control functions |
| mbed_official | 489:119543c9f674 | 390 | * |
| mbed_official | 489:119543c9f674 | 391 | @verbatim |
| mbed_official | 489:119543c9f674 | 392 | =============================================================================== |
| mbed_official | 489:119543c9f674 | 393 | ##### Peripheral Control functions ##### |
| mbed_official | 489:119543c9f674 | 394 | =============================================================================== |
| mbed_official | 489:119543c9f674 | 395 | [..] |
| mbed_official | 489:119543c9f674 | 396 | This subsection provides a set of functions allowing to control the FLASH |
| mbed_official | 489:119543c9f674 | 397 | memory operations. |
| mbed_official | 489:119543c9f674 | 398 | |
| mbed_official | 489:119543c9f674 | 399 | @endverbatim |
| mbed_official | 489:119543c9f674 | 400 | * @{ |
| mbed_official | 489:119543c9f674 | 401 | */ |
| mbed_official | 489:119543c9f674 | 402 | |
| mbed_official | 489:119543c9f674 | 403 | /** |
| mbed_official | 489:119543c9f674 | 404 | * @brief Erases the FLASH option bytes. |
| mbed_official | 489:119543c9f674 | 405 | * @note This functions erases all option bytes except the Read protection (RDP). |
| mbed_official | 489:119543c9f674 | 406 | * The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
| mbed_official | 489:119543c9f674 | 407 | * The function HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
| mbed_official | 489:119543c9f674 | 408 | * The function HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
| mbed_official | 489:119543c9f674 | 409 | * (system reset will occur) |
| mbed_official | 489:119543c9f674 | 410 | * @retval HAL status |
| mbed_official | 489:119543c9f674 | 411 | */ |
| mbed_official | 489:119543c9f674 | 412 | |
| mbed_official | 489:119543c9f674 | 413 | HAL_StatusTypeDef HAL_FLASHEx_OBErase(void) |
| mbed_official | 489:119543c9f674 | 414 | { |
| mbed_official | 489:119543c9f674 | 415 | uint8_t rdptmp = OB_RDP_LEVEL_0; |
| mbed_official | 489:119543c9f674 | 416 | HAL_StatusTypeDef status = HAL_ERROR; |
| mbed_official | 489:119543c9f674 | 417 | |
| mbed_official | 489:119543c9f674 | 418 | /* Get the actual read protection Option Byte value */ |
| mbed_official | 489:119543c9f674 | 419 | if(FLASH_OB_GetRDP() != RESET) |
| mbed_official | 489:119543c9f674 | 420 | { |
| mbed_official | 489:119543c9f674 | 421 | rdptmp = OB_RDP_LEVEL_1; |
| mbed_official | 489:119543c9f674 | 422 | } |
| mbed_official | 489:119543c9f674 | 423 | |
| mbed_official | 489:119543c9f674 | 424 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 425 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 426 | |
| mbed_official | 489:119543c9f674 | 427 | if(status == HAL_OK) |
| mbed_official | 489:119543c9f674 | 428 | { |
| mbed_official | 489:119543c9f674 | 429 | /* Clean the error context */ |
| mbed_official | 489:119543c9f674 | 430 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
| mbed_official | 489:119543c9f674 | 431 | |
| mbed_official | 489:119543c9f674 | 432 | /* If the previous operation is completed, proceed to erase the option bytes */ |
| mbed_official | 489:119543c9f674 | 433 | SET_BIT(FLASH->CR, FLASH_CR_OPTER); |
| mbed_official | 489:119543c9f674 | 434 | SET_BIT(FLASH->CR, FLASH_CR_STRT); |
| mbed_official | 489:119543c9f674 | 435 | |
| mbed_official | 489:119543c9f674 | 436 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 437 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 438 | |
| mbed_official | 489:119543c9f674 | 439 | /* If the erase operation is completed, disable the OPTER Bit */ |
| mbed_official | 489:119543c9f674 | 440 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER); |
| mbed_official | 489:119543c9f674 | 441 | |
| mbed_official | 489:119543c9f674 | 442 | if(status == HAL_OK) |
| mbed_official | 489:119543c9f674 | 443 | { |
| mbed_official | 489:119543c9f674 | 444 | /* Restore the last read protection Option Byte value */ |
| mbed_official | 489:119543c9f674 | 445 | status = FLASH_OB_RDP_LevelConfig(rdptmp); |
| mbed_official | 489:119543c9f674 | 446 | } |
| mbed_official | 489:119543c9f674 | 447 | } |
| mbed_official | 489:119543c9f674 | 448 | |
| mbed_official | 489:119543c9f674 | 449 | /* Return the erase status */ |
| mbed_official | 489:119543c9f674 | 450 | return status; |
| mbed_official | 489:119543c9f674 | 451 | } |
| mbed_official | 489:119543c9f674 | 452 | |
| mbed_official | 489:119543c9f674 | 453 | /** |
| mbed_official | 489:119543c9f674 | 454 | * @brief Program option bytes |
| mbed_official | 489:119543c9f674 | 455 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
| mbed_official | 489:119543c9f674 | 456 | * The function HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
| mbed_official | 489:119543c9f674 | 457 | * The function HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
| mbed_official | 489:119543c9f674 | 458 | * (system reset will occur) |
| mbed_official | 489:119543c9f674 | 459 | * |
| mbed_official | 489:119543c9f674 | 460 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that |
| mbed_official | 489:119543c9f674 | 461 | * contains the configuration information for the programming. |
| mbed_official | 489:119543c9f674 | 462 | * |
| mbed_official | 489:119543c9f674 | 463 | * @retval HAL_StatusTypeDef HAL Status |
| mbed_official | 489:119543c9f674 | 464 | */ |
| mbed_official | 489:119543c9f674 | 465 | HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) |
| mbed_official | 489:119543c9f674 | 466 | { |
| mbed_official | 489:119543c9f674 | 467 | HAL_StatusTypeDef status = HAL_ERROR; |
| mbed_official | 489:119543c9f674 | 468 | |
| mbed_official | 489:119543c9f674 | 469 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 470 | assert_param(IS_OPTIONBYTE(pOBInit->OptionType)); |
| mbed_official | 489:119543c9f674 | 471 | |
| mbed_official | 489:119543c9f674 | 472 | /* Write protection configuration */ |
| mbed_official | 489:119543c9f674 | 473 | if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP) |
| mbed_official | 489:119543c9f674 | 474 | { |
| mbed_official | 489:119543c9f674 | 475 | assert_param(IS_WRPSTATE(pOBInit->WRPState)); |
| mbed_official | 489:119543c9f674 | 476 | if (pOBInit->WRPState == OB_WRPSTATE_ENABLE) |
| mbed_official | 489:119543c9f674 | 477 | { |
| mbed_official | 489:119543c9f674 | 478 | /* Enable of Write protection on the selected page */ |
| mbed_official | 489:119543c9f674 | 479 | status = FLASH_OB_EnableWRP(pOBInit->WRPPage); |
| mbed_official | 489:119543c9f674 | 480 | } |
| mbed_official | 489:119543c9f674 | 481 | else |
| mbed_official | 489:119543c9f674 | 482 | { |
| mbed_official | 489:119543c9f674 | 483 | /* Disable of Write protection on the selected page */ |
| mbed_official | 489:119543c9f674 | 484 | status = FLASH_OB_DisableWRP(pOBInit->WRPPage); |
| mbed_official | 489:119543c9f674 | 485 | } |
| mbed_official | 489:119543c9f674 | 486 | } |
| mbed_official | 489:119543c9f674 | 487 | |
| mbed_official | 489:119543c9f674 | 488 | /* Read protection configuration */ |
| mbed_official | 489:119543c9f674 | 489 | if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) |
| mbed_official | 489:119543c9f674 | 490 | { |
| mbed_official | 489:119543c9f674 | 491 | status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel); |
| mbed_official | 489:119543c9f674 | 492 | } |
| mbed_official | 489:119543c9f674 | 493 | |
| mbed_official | 489:119543c9f674 | 494 | /* USER configuration */ |
| mbed_official | 489:119543c9f674 | 495 | if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) |
| mbed_official | 489:119543c9f674 | 496 | { |
| mbed_official | 489:119543c9f674 | 497 | status = FLASH_OB_UserConfig(pOBInit->USERConfig); |
| mbed_official | 489:119543c9f674 | 498 | } |
| mbed_official | 489:119543c9f674 | 499 | |
| mbed_official | 489:119543c9f674 | 500 | /* DATA configuration*/ |
| mbed_official | 489:119543c9f674 | 501 | if((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA) |
| mbed_official | 489:119543c9f674 | 502 | { |
| mbed_official | 489:119543c9f674 | 503 | status = FLASH_OB_ProgramData(pOBInit->DATAAddress, pOBInit->DATAData); |
| mbed_official | 489:119543c9f674 | 504 | } |
| mbed_official | 489:119543c9f674 | 505 | |
| mbed_official | 489:119543c9f674 | 506 | return status; |
| mbed_official | 489:119543c9f674 | 507 | } |
| mbed_official | 489:119543c9f674 | 508 | |
| mbed_official | 489:119543c9f674 | 509 | /** |
| mbed_official | 489:119543c9f674 | 510 | * @brief Get the Option byte configuration |
| mbed_official | 489:119543c9f674 | 511 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that |
| mbed_official | 489:119543c9f674 | 512 | * contains the configuration information for the programming. |
| mbed_official | 489:119543c9f674 | 513 | * |
| mbed_official | 489:119543c9f674 | 514 | * @retval None |
| mbed_official | 489:119543c9f674 | 515 | */ |
| mbed_official | 489:119543c9f674 | 516 | void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) |
| mbed_official | 489:119543c9f674 | 517 | { |
| mbed_official | 489:119543c9f674 | 518 | pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER; |
| mbed_official | 489:119543c9f674 | 519 | |
| mbed_official | 489:119543c9f674 | 520 | /*Get WRP*/ |
| mbed_official | 489:119543c9f674 | 521 | pOBInit->WRPPage = FLASH_OB_GetWRP(); |
| mbed_official | 489:119543c9f674 | 522 | |
| mbed_official | 489:119543c9f674 | 523 | /*Get RDP Level*/ |
| mbed_official | 489:119543c9f674 | 524 | pOBInit->RDPLevel = FLASH_OB_GetRDP(); |
| mbed_official | 489:119543c9f674 | 525 | |
| mbed_official | 489:119543c9f674 | 526 | /*Get USER*/ |
| mbed_official | 489:119543c9f674 | 527 | pOBInit->USERConfig = FLASH_OB_GetUser(); |
| mbed_official | 489:119543c9f674 | 528 | } |
| mbed_official | 489:119543c9f674 | 529 | |
| mbed_official | 489:119543c9f674 | 530 | /** |
| mbed_official | 489:119543c9f674 | 531 | * @} |
| mbed_official | 489:119543c9f674 | 532 | */ |
| mbed_official | 489:119543c9f674 | 533 | |
| mbed_official | 489:119543c9f674 | 534 | /** |
| mbed_official | 489:119543c9f674 | 535 | * @} |
| mbed_official | 489:119543c9f674 | 536 | */ |
| mbed_official | 489:119543c9f674 | 537 | |
| mbed_official | 489:119543c9f674 | 538 | /** @addtogroup FLASHEx_Private_Functions |
| mbed_official | 489:119543c9f674 | 539 | * @{ |
| mbed_official | 489:119543c9f674 | 540 | */ |
| mbed_official | 489:119543c9f674 | 541 | |
| mbed_official | 489:119543c9f674 | 542 | /** |
| mbed_official | 489:119543c9f674 | 543 | * @brief Full erase of FLASH memory Bank |
| mbed_official | 489:119543c9f674 | 544 | * @param Banks: Banks to be erased |
| mbed_official | 489:119543c9f674 | 545 | * This parameter can be one of the following values: |
| mbed_official | 489:119543c9f674 | 546 | * @arg FLASH_BANK_1: Bank1 to be erased |
| mbed_official | 489:119543c9f674 | 547 | * @arg FLASH_BANK_2: Bank2 to be erased |
| mbed_official | 489:119543c9f674 | 548 | * @arg FLASH_BANK_BOTH: Bank1 and Bank2 to be erased |
| mbed_official | 489:119543c9f674 | 549 | * |
| mbed_official | 489:119543c9f674 | 550 | * @retval HAL Status |
| mbed_official | 489:119543c9f674 | 551 | */ |
| mbed_official | 489:119543c9f674 | 552 | static void FLASH_MassErase(uint32_t Banks) |
| mbed_official | 489:119543c9f674 | 553 | { |
| mbed_official | 489:119543c9f674 | 554 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 555 | assert_param(IS_FLASH_BANK(Banks)); |
| mbed_official | 489:119543c9f674 | 556 | |
| mbed_official | 489:119543c9f674 | 557 | /* Clean the error context */ |
| mbed_official | 489:119543c9f674 | 558 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
| mbed_official | 489:119543c9f674 | 559 | |
| mbed_official | 489:119543c9f674 | 560 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 561 | if(Banks == FLASH_BANK_BOTH) |
| mbed_official | 489:119543c9f674 | 562 | { |
| mbed_official | 489:119543c9f674 | 563 | /* bank1 & bank2 will be erased*/ |
| mbed_official | 489:119543c9f674 | 564 | SET_BIT(FLASH->CR, FLASH_CR_MER); |
| mbed_official | 489:119543c9f674 | 565 | SET_BIT(FLASH->CR2, FLASH_CR2_MER); |
| mbed_official | 489:119543c9f674 | 566 | SET_BIT(FLASH->CR, FLASH_CR_STRT); |
| mbed_official | 489:119543c9f674 | 567 | SET_BIT(FLASH->CR2, FLASH_CR2_STRT); |
| mbed_official | 489:119543c9f674 | 568 | } |
| mbed_official | 489:119543c9f674 | 569 | else if(Banks == FLASH_BANK_2) |
| mbed_official | 489:119543c9f674 | 570 | { |
| mbed_official | 489:119543c9f674 | 571 | /*Only bank2 will be erased*/ |
| mbed_official | 489:119543c9f674 | 572 | SET_BIT(FLASH->CR2, FLASH_CR2_MER); |
| mbed_official | 489:119543c9f674 | 573 | SET_BIT(FLASH->CR2, FLASH_CR2_STRT); |
| mbed_official | 489:119543c9f674 | 574 | } |
| mbed_official | 489:119543c9f674 | 575 | else |
| mbed_official | 489:119543c9f674 | 576 | { |
| mbed_official | 489:119543c9f674 | 577 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 578 | /*Only bank1 will be erased*/ |
| mbed_official | 489:119543c9f674 | 579 | SET_BIT(FLASH->CR, FLASH_CR_MER); |
| mbed_official | 489:119543c9f674 | 580 | SET_BIT(FLASH->CR, FLASH_CR_STRT); |
| mbed_official | 489:119543c9f674 | 581 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 582 | } |
| mbed_official | 489:119543c9f674 | 583 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 584 | } |
| mbed_official | 489:119543c9f674 | 585 | |
| mbed_official | 489:119543c9f674 | 586 | /** |
| mbed_official | 489:119543c9f674 | 587 | * @brief Enable the write protection of the desired pages |
| mbed_official | 489:119543c9f674 | 588 | * @note When the memory read protection level is selected (RDP level = 1), |
| mbed_official | 489:119543c9f674 | 589 | * it is not possible to program or erase the flash page i if CortexM4 |
| mbed_official | 489:119543c9f674 | 590 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
| mbed_official | 489:119543c9f674 | 591 | * |
| mbed_official | 489:119543c9f674 | 592 | * @param WriteProtectPage: specifies the page(s) to be write protected. |
| mbed_official | 489:119543c9f674 | 593 | * The value of this parameter depend on device used within the same series |
| mbed_official | 489:119543c9f674 | 594 | * @retval HAL status |
| mbed_official | 489:119543c9f674 | 595 | */ |
| mbed_official | 489:119543c9f674 | 596 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage) |
| mbed_official | 489:119543c9f674 | 597 | { |
| mbed_official | 489:119543c9f674 | 598 | HAL_StatusTypeDef status = HAL_OK; |
| mbed_official | 489:119543c9f674 | 599 | uint16_t WRP0_Data = 0xFFFF; |
| mbed_official | 489:119543c9f674 | 600 | #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB) || \ |
| mbed_official | 489:119543c9f674 | 601 | defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) || \ |
| mbed_official | 489:119543c9f674 | 602 | defined(STM32F101xG) || defined(STM32F103xG) || \ |
| mbed_official | 489:119543c9f674 | 603 | defined(STM32F105xC) || defined(STM32F107xC) |
| mbed_official | 489:119543c9f674 | 604 | uint16_t WRP1_Data = 0xFFFF, WRP2_Data = 0xFFFF, WRP3_Data = 0xFFFF; |
| mbed_official | 489:119543c9f674 | 605 | #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB || */ |
| mbed_official | 489:119543c9f674 | 606 | /* STM32F100xE || STM32F101xE || STM32F103xE || */ |
| mbed_official | 489:119543c9f674 | 607 | /* STM32F101xG || STM32F103xG || */ |
| mbed_official | 489:119543c9f674 | 608 | /* STM32F105xC || STM32F107xC */ |
| mbed_official | 489:119543c9f674 | 609 | |
| mbed_official | 489:119543c9f674 | 610 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 611 | assert_param(IS_OB_WRP(WriteProtectPage)); |
| mbed_official | 489:119543c9f674 | 612 | |
| mbed_official | 489:119543c9f674 | 613 | WriteProtectPage = (uint32_t)(~WriteProtectPage); |
| mbed_official | 489:119543c9f674 | 614 | |
| mbed_official | 489:119543c9f674 | 615 | /* Low Density and Medium Density */ |
| mbed_official | 489:119543c9f674 | 616 | #if defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) || \ |
| mbed_official | 489:119543c9f674 | 617 | defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB) |
| mbed_official | 489:119543c9f674 | 618 | WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO31MASK); |
| mbed_official | 489:119543c9f674 | 619 | #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 || */ |
| mbed_official | 489:119543c9f674 | 620 | /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */ |
| mbed_official | 489:119543c9f674 | 621 | |
| mbed_official | 489:119543c9f674 | 622 | /* Medium Density */ |
| mbed_official | 489:119543c9f674 | 623 | #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB) |
| mbed_official | 489:119543c9f674 | 624 | WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO63MASK) >> 8); |
| mbed_official | 489:119543c9f674 | 625 | WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES64TO95MASK) >> 16); |
| mbed_official | 489:119543c9f674 | 626 | WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES96TO127MASK) >> 24); |
| mbed_official | 489:119543c9f674 | 627 | #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */ |
| mbed_official | 489:119543c9f674 | 628 | |
| mbed_official | 489:119543c9f674 | 629 | /* High Density, XL Density and Connectivity line devices*/ |
| mbed_official | 489:119543c9f674 | 630 | #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) || \ |
| mbed_official | 489:119543c9f674 | 631 | defined(STM32F101xG) || defined(STM32F103xG) || \ |
| mbed_official | 489:119543c9f674 | 632 | defined(STM32F105xC) || defined(STM32F107xC) |
| mbed_official | 489:119543c9f674 | 633 | WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK); |
| mbed_official | 489:119543c9f674 | 634 | WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8); |
| mbed_official | 489:119543c9f674 | 635 | WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16); |
| mbed_official | 489:119543c9f674 | 636 | #endif /* STM32F100xE || STM32F101xE || STM32F103xE */ |
| mbed_official | 489:119543c9f674 | 637 | /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 638 | /* STM32F105xC || STM32F107xC */ |
| mbed_official | 489:119543c9f674 | 639 | |
| mbed_official | 489:119543c9f674 | 640 | /* High Density */ |
| mbed_official | 489:119543c9f674 | 641 | #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) |
| mbed_official | 489:119543c9f674 | 642 | WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO255MASK) >> 24); |
| mbed_official | 489:119543c9f674 | 643 | #endif /* STM32F100xE || STM32F101xE || STM32F103xE */ |
| mbed_official | 489:119543c9f674 | 644 | |
| mbed_official | 489:119543c9f674 | 645 | /* XL Density */ |
| mbed_official | 489:119543c9f674 | 646 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 647 | WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO511MASK) >> 24); |
| mbed_official | 489:119543c9f674 | 648 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 649 | |
| mbed_official | 489:119543c9f674 | 650 | /* Connectivity line devices */ |
| mbed_official | 489:119543c9f674 | 651 | #if defined(STM32F105xC) || defined(STM32F107xC) |
| mbed_official | 489:119543c9f674 | 652 | WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24); |
| mbed_official | 489:119543c9f674 | 653 | #endif /* STM32F105xC || STM32F107xC */ |
| mbed_official | 489:119543c9f674 | 654 | |
| mbed_official | 489:119543c9f674 | 655 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 656 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 657 | |
| mbed_official | 489:119543c9f674 | 658 | if(status == HAL_OK) |
| mbed_official | 489:119543c9f674 | 659 | { |
| mbed_official | 489:119543c9f674 | 660 | /* Clean the error context */ |
| mbed_official | 489:119543c9f674 | 661 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
| mbed_official | 489:119543c9f674 | 662 | |
| mbed_official | 489:119543c9f674 | 663 | SET_BIT(FLASH->CR, FLASH_CR_OPTPG); |
| mbed_official | 489:119543c9f674 | 664 | |
| mbed_official | 489:119543c9f674 | 665 | if(WRP0_Data != 0xFF) |
| mbed_official | 489:119543c9f674 | 666 | { |
| mbed_official | 489:119543c9f674 | 667 | OB->WRP0 &= WRP0_Data; |
| mbed_official | 489:119543c9f674 | 668 | |
| mbed_official | 489:119543c9f674 | 669 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 670 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 671 | } |
| mbed_official | 489:119543c9f674 | 672 | |
| mbed_official | 489:119543c9f674 | 673 | #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB) || \ |
| mbed_official | 489:119543c9f674 | 674 | defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) || \ |
| mbed_official | 489:119543c9f674 | 675 | defined(STM32F101xG) || defined(STM32F103xG) || \ |
| mbed_official | 489:119543c9f674 | 676 | defined(STM32F105xC) || defined(STM32F107xC) |
| mbed_official | 489:119543c9f674 | 677 | |
| mbed_official | 489:119543c9f674 | 678 | if((status == HAL_OK) && (WRP1_Data != 0xFF)) |
| mbed_official | 489:119543c9f674 | 679 | { |
| mbed_official | 489:119543c9f674 | 680 | OB->WRP1 &= WRP1_Data; |
| mbed_official | 489:119543c9f674 | 681 | |
| mbed_official | 489:119543c9f674 | 682 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 683 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 684 | } |
| mbed_official | 489:119543c9f674 | 685 | |
| mbed_official | 489:119543c9f674 | 686 | if((status == HAL_OK) && (WRP2_Data != 0xFF)) |
| mbed_official | 489:119543c9f674 | 687 | { |
| mbed_official | 489:119543c9f674 | 688 | OB->WRP2 &= WRP2_Data; |
| mbed_official | 489:119543c9f674 | 689 | |
| mbed_official | 489:119543c9f674 | 690 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 691 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 692 | } |
| mbed_official | 489:119543c9f674 | 693 | |
| mbed_official | 489:119543c9f674 | 694 | if((status == HAL_OK) && (WRP3_Data != 0xFF)) |
| mbed_official | 489:119543c9f674 | 695 | { |
| mbed_official | 489:119543c9f674 | 696 | OB->WRP3 &= WRP3_Data; |
| mbed_official | 489:119543c9f674 | 697 | |
| mbed_official | 489:119543c9f674 | 698 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 699 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 700 | } |
| mbed_official | 489:119543c9f674 | 701 | #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB || */ |
| mbed_official | 489:119543c9f674 | 702 | /* STM32F100xE || STM32F101xE || STM32F103xE || */ |
| mbed_official | 489:119543c9f674 | 703 | /* STM32F101xG || STM32F103xG || */ |
| mbed_official | 489:119543c9f674 | 704 | /* STM32F105xC || STM32F107xC */ |
| mbed_official | 489:119543c9f674 | 705 | |
| mbed_official | 489:119543c9f674 | 706 | /* if the program operation is completed, disable the OPTPG Bit */ |
| mbed_official | 489:119543c9f674 | 707 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); |
| mbed_official | 489:119543c9f674 | 708 | } |
| mbed_official | 489:119543c9f674 | 709 | |
| mbed_official | 489:119543c9f674 | 710 | return status; |
| mbed_official | 489:119543c9f674 | 711 | } |
| mbed_official | 489:119543c9f674 | 712 | |
| mbed_official | 489:119543c9f674 | 713 | /** |
| mbed_official | 489:119543c9f674 | 714 | * @brief Disable the write protection of the desired pages |
| mbed_official | 489:119543c9f674 | 715 | * @note When the memory read protection level is selected (RDP level = 1), |
| mbed_official | 489:119543c9f674 | 716 | * it is not possible to program or erase the flash page i if CortexM4 |
| mbed_official | 489:119543c9f674 | 717 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
| mbed_official | 489:119543c9f674 | 718 | * |
| mbed_official | 489:119543c9f674 | 719 | * @param WriteProtectPage: specifies the page(s) to be write unprotected. |
| mbed_official | 489:119543c9f674 | 720 | * The value of this parameter depend on device used within the same series |
| mbed_official | 489:119543c9f674 | 721 | * @retval HAL status |
| mbed_official | 489:119543c9f674 | 722 | */ |
| mbed_official | 489:119543c9f674 | 723 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage) |
| mbed_official | 489:119543c9f674 | 724 | { |
| mbed_official | 489:119543c9f674 | 725 | HAL_StatusTypeDef status = HAL_OK; |
| mbed_official | 489:119543c9f674 | 726 | uint16_t WRP0_Data = 0xFFFF; |
| mbed_official | 489:119543c9f674 | 727 | #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB) || \ |
| mbed_official | 489:119543c9f674 | 728 | defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) || \ |
| mbed_official | 489:119543c9f674 | 729 | defined(STM32F101xG) || defined(STM32F103xG) || \ |
| mbed_official | 489:119543c9f674 | 730 | defined(STM32F105xC) || defined(STM32F107xC) |
| mbed_official | 489:119543c9f674 | 731 | uint16_t WRP1_Data = 0xFFFF, WRP2_Data = 0xFFFF, WRP3_Data = 0xFFFF; |
| mbed_official | 489:119543c9f674 | 732 | #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB || */ |
| mbed_official | 489:119543c9f674 | 733 | /* STM32F100xE || STM32F101xE || STM32F103xE || */ |
| mbed_official | 489:119543c9f674 | 734 | /* STM32F101xG || STM32F103xG || */ |
| mbed_official | 489:119543c9f674 | 735 | /* STM32F105xC || STM32F107xC */ |
| mbed_official | 489:119543c9f674 | 736 | |
| mbed_official | 489:119543c9f674 | 737 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 738 | assert_param(IS_OB_WRP(WriteProtectPage)); |
| mbed_official | 489:119543c9f674 | 739 | |
| mbed_official | 489:119543c9f674 | 740 | /* Low Density and Medium Density */ |
| mbed_official | 489:119543c9f674 | 741 | #if defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) || \ |
| mbed_official | 489:119543c9f674 | 742 | defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB) |
| mbed_official | 489:119543c9f674 | 743 | WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO31MASK); |
| mbed_official | 489:119543c9f674 | 744 | #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 || */ |
| mbed_official | 489:119543c9f674 | 745 | /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */ |
| mbed_official | 489:119543c9f674 | 746 | |
| mbed_official | 489:119543c9f674 | 747 | /* Medium Density */ |
| mbed_official | 489:119543c9f674 | 748 | #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB) |
| mbed_official | 489:119543c9f674 | 749 | WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO63MASK) >> 8); |
| mbed_official | 489:119543c9f674 | 750 | WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES64TO95MASK) >> 16); |
| mbed_official | 489:119543c9f674 | 751 | WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES96TO127MASK) >> 24); |
| mbed_official | 489:119543c9f674 | 752 | #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */ |
| mbed_official | 489:119543c9f674 | 753 | |
| mbed_official | 489:119543c9f674 | 754 | /* High Density, XL Density and Connectivity line devices*/ |
| mbed_official | 489:119543c9f674 | 755 | #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) || \ |
| mbed_official | 489:119543c9f674 | 756 | defined(STM32F101xG) || defined(STM32F103xG) || \ |
| mbed_official | 489:119543c9f674 | 757 | defined(STM32F105xC) || defined(STM32F107xC) |
| mbed_official | 489:119543c9f674 | 758 | WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK); |
| mbed_official | 489:119543c9f674 | 759 | WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8); |
| mbed_official | 489:119543c9f674 | 760 | WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16); |
| mbed_official | 489:119543c9f674 | 761 | #endif /* STM32F100xE || STM32F101xE || STM32F103xE */ |
| mbed_official | 489:119543c9f674 | 762 | /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 763 | /* STM32F105xC || STM32F107xC */ |
| mbed_official | 489:119543c9f674 | 764 | |
| mbed_official | 489:119543c9f674 | 765 | /* High Density */ |
| mbed_official | 489:119543c9f674 | 766 | #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) |
| mbed_official | 489:119543c9f674 | 767 | WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO255MASK) >> 24); |
| mbed_official | 489:119543c9f674 | 768 | #endif /* STM32F100xE || STM32F101xE || STM32F103xE */ |
| mbed_official | 489:119543c9f674 | 769 | |
| mbed_official | 489:119543c9f674 | 770 | /* XL Density */ |
| mbed_official | 489:119543c9f674 | 771 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 772 | WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO511MASK) >> 24); |
| mbed_official | 489:119543c9f674 | 773 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 774 | |
| mbed_official | 489:119543c9f674 | 775 | /* Connectivity line devices */ |
| mbed_official | 489:119543c9f674 | 776 | #if defined(STM32F105xC) || defined(STM32F107xC) |
| mbed_official | 489:119543c9f674 | 777 | WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24); |
| mbed_official | 489:119543c9f674 | 778 | #endif /* STM32F105xC || STM32F107xC */ |
| mbed_official | 489:119543c9f674 | 779 | |
| mbed_official | 489:119543c9f674 | 780 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 781 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 782 | |
| mbed_official | 489:119543c9f674 | 783 | if(status == HAL_OK) |
| mbed_official | 489:119543c9f674 | 784 | { |
| mbed_official | 489:119543c9f674 | 785 | /* Clean the error context */ |
| mbed_official | 489:119543c9f674 | 786 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
| mbed_official | 489:119543c9f674 | 787 | |
| mbed_official | 489:119543c9f674 | 788 | SET_BIT(FLASH->CR, FLASH_CR_OPTPG); |
| mbed_official | 489:119543c9f674 | 789 | |
| mbed_official | 489:119543c9f674 | 790 | if(WRP0_Data != 0xFF) |
| mbed_official | 489:119543c9f674 | 791 | { |
| mbed_official | 489:119543c9f674 | 792 | OB->WRP0 |= WRP0_Data; |
| mbed_official | 489:119543c9f674 | 793 | |
| mbed_official | 489:119543c9f674 | 794 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 795 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 796 | } |
| mbed_official | 489:119543c9f674 | 797 | #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB) || \ |
| mbed_official | 489:119543c9f674 | 798 | defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) || \ |
| mbed_official | 489:119543c9f674 | 799 | defined(STM32F101xG) || defined(STM32F103xG) || \ |
| mbed_official | 489:119543c9f674 | 800 | defined(STM32F105xC) || defined(STM32F107xC) |
| mbed_official | 489:119543c9f674 | 801 | |
| mbed_official | 489:119543c9f674 | 802 | if((status == HAL_OK) && (WRP1_Data != 0xFF)) |
| mbed_official | 489:119543c9f674 | 803 | { |
| mbed_official | 489:119543c9f674 | 804 | OB->WRP1 |= WRP1_Data; |
| mbed_official | 489:119543c9f674 | 805 | |
| mbed_official | 489:119543c9f674 | 806 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 807 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 808 | } |
| mbed_official | 489:119543c9f674 | 809 | |
| mbed_official | 489:119543c9f674 | 810 | if((status == HAL_OK) && (WRP2_Data != 0xFF)) |
| mbed_official | 489:119543c9f674 | 811 | { |
| mbed_official | 489:119543c9f674 | 812 | OB->WRP2 |= WRP2_Data; |
| mbed_official | 489:119543c9f674 | 813 | |
| mbed_official | 489:119543c9f674 | 814 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 815 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 816 | } |
| mbed_official | 489:119543c9f674 | 817 | |
| mbed_official | 489:119543c9f674 | 818 | if((status == HAL_OK) && (WRP3_Data != 0xFF)) |
| mbed_official | 489:119543c9f674 | 819 | { |
| mbed_official | 489:119543c9f674 | 820 | OB->WRP3 |= WRP3_Data; |
| mbed_official | 489:119543c9f674 | 821 | |
| mbed_official | 489:119543c9f674 | 822 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 823 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 824 | } |
| mbed_official | 489:119543c9f674 | 825 | #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB ||*/ |
| mbed_official | 489:119543c9f674 | 826 | /* STM32F100xE || STM32F101xE || STM32F103xE ||*/ |
| mbed_official | 489:119543c9f674 | 827 | /* STM32F101xG || STM32F103xG ||*/ |
| mbed_official | 489:119543c9f674 | 828 | /* STM32F105xC || STM32F107xC */ |
| mbed_official | 489:119543c9f674 | 829 | |
| mbed_official | 489:119543c9f674 | 830 | /* if the program operation is completed, disable the OPTPG Bit */ |
| mbed_official | 489:119543c9f674 | 831 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); |
| mbed_official | 489:119543c9f674 | 832 | } |
| mbed_official | 489:119543c9f674 | 833 | return status; |
| mbed_official | 489:119543c9f674 | 834 | } |
| mbed_official | 489:119543c9f674 | 835 | |
| mbed_official | 489:119543c9f674 | 836 | /** |
| mbed_official | 489:119543c9f674 | 837 | * @brief Set the read protection level. |
| mbed_official | 489:119543c9f674 | 838 | * @param ReadProtectLevel: specifies the read protection level. |
| mbed_official | 489:119543c9f674 | 839 | * This parameter can be one of the following values: |
| mbed_official | 489:119543c9f674 | 840 | * @arg OB_RDP_LEVEL_0: No protection |
| mbed_official | 489:119543c9f674 | 841 | * @arg OB_RDP_LEVEL_1: Read protection of the memory |
| mbed_official | 489:119543c9f674 | 842 | * |
| mbed_official | 489:119543c9f674 | 843 | * @retval HAL status |
| mbed_official | 489:119543c9f674 | 844 | */ |
| mbed_official | 489:119543c9f674 | 845 | static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel) |
| mbed_official | 489:119543c9f674 | 846 | { |
| mbed_official | 489:119543c9f674 | 847 | HAL_StatusTypeDef status = HAL_OK; |
| mbed_official | 489:119543c9f674 | 848 | |
| mbed_official | 489:119543c9f674 | 849 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 850 | assert_param(IS_OB_RDP_LEVEL(ReadProtectLevel)); |
| mbed_official | 489:119543c9f674 | 851 | |
| mbed_official | 489:119543c9f674 | 852 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 853 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 854 | |
| mbed_official | 489:119543c9f674 | 855 | if(status == HAL_OK) |
| mbed_official | 489:119543c9f674 | 856 | { |
| mbed_official | 489:119543c9f674 | 857 | /* Clean the error context */ |
| mbed_official | 489:119543c9f674 | 858 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
| mbed_official | 489:119543c9f674 | 859 | |
| mbed_official | 489:119543c9f674 | 860 | /* Enable the Option Bytes Programming operation */ |
| mbed_official | 489:119543c9f674 | 861 | SET_BIT(FLASH->CR, FLASH_CR_OPTPG); |
| mbed_official | 489:119543c9f674 | 862 | |
| mbed_official | 489:119543c9f674 | 863 | WRITE_REG(OB->RDP, ReadProtectLevel); |
| mbed_official | 489:119543c9f674 | 864 | |
| mbed_official | 489:119543c9f674 | 865 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 866 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 867 | |
| mbed_official | 489:119543c9f674 | 868 | /* if the program operation is completed, disable the OPTPG Bit */ |
| mbed_official | 489:119543c9f674 | 869 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); |
| mbed_official | 489:119543c9f674 | 870 | } |
| mbed_official | 489:119543c9f674 | 871 | |
| mbed_official | 489:119543c9f674 | 872 | return status; |
| mbed_official | 489:119543c9f674 | 873 | } |
| mbed_official | 489:119543c9f674 | 874 | |
| mbed_official | 489:119543c9f674 | 875 | /** |
| mbed_official | 489:119543c9f674 | 876 | * @brief Program the FLASH User Option Byte. |
| mbed_official | 489:119543c9f674 | 877 | * @note Programming of the OB should be performed only after an erase (otherwise PGERR occurs) |
| mbed_official | 489:119543c9f674 | 878 | * @param UserConfig: The FLASH User Option Bytes values: FLASH_OBR_IWDG_SW(Bit2), |
| mbed_official | 489:119543c9f674 | 879 | * FLASH_OBR_nRST_STOP(Bit3),FLASH_OBR_nRST_STDBY(Bit4). |
| mbed_official | 489:119543c9f674 | 880 | * And BFBF2(Bit5) for STM32F101xG and STM32F103xG . |
| mbed_official | 489:119543c9f674 | 881 | * @retval HAL status |
| mbed_official | 489:119543c9f674 | 882 | */ |
| mbed_official | 489:119543c9f674 | 883 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig) |
| mbed_official | 489:119543c9f674 | 884 | { |
| mbed_official | 489:119543c9f674 | 885 | HAL_StatusTypeDef status = HAL_OK; |
| mbed_official | 489:119543c9f674 | 886 | |
| mbed_official | 489:119543c9f674 | 887 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 888 | assert_param(IS_OB_IWDG_SOURCE((UserConfig&OB_IWDG_SW))); |
| mbed_official | 489:119543c9f674 | 889 | assert_param(IS_OB_STOP_SOURCE((UserConfig&OB_STOP_NO_RST))); |
| mbed_official | 489:119543c9f674 | 890 | assert_param(IS_OB_STDBY_SOURCE((UserConfig&OB_STDBY_NO_RST))); |
| mbed_official | 489:119543c9f674 | 891 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 892 | assert_param(IS_OB_BOOT1((UserConfig&OB_BOOT1_SET))); |
| mbed_official | 489:119543c9f674 | 893 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 894 | |
| mbed_official | 489:119543c9f674 | 895 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 896 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 897 | |
| mbed_official | 489:119543c9f674 | 898 | if(status == HAL_OK) |
| mbed_official | 489:119543c9f674 | 899 | { |
| mbed_official | 489:119543c9f674 | 900 | /* Clean the error context */ |
| mbed_official | 489:119543c9f674 | 901 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
| mbed_official | 489:119543c9f674 | 902 | |
| mbed_official | 489:119543c9f674 | 903 | /* Enable the Option Bytes Programming operation */ |
| mbed_official | 489:119543c9f674 | 904 | SET_BIT(FLASH->CR, FLASH_CR_OPTPG); |
| mbed_official | 489:119543c9f674 | 905 | |
| mbed_official | 489:119543c9f674 | 906 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 907 | OB->USER = (UserConfig | 0xF0); |
| mbed_official | 489:119543c9f674 | 908 | #else |
| mbed_official | 489:119543c9f674 | 909 | OB->USER = (UserConfig | 0xF8); |
| mbed_official | 489:119543c9f674 | 910 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 911 | |
| mbed_official | 489:119543c9f674 | 912 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 913 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 914 | |
| mbed_official | 489:119543c9f674 | 915 | /* if the program operation is completed, disable the OPTPG Bit */ |
| mbed_official | 489:119543c9f674 | 916 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); |
| mbed_official | 489:119543c9f674 | 917 | } |
| mbed_official | 489:119543c9f674 | 918 | |
| mbed_official | 489:119543c9f674 | 919 | return status; |
| mbed_official | 489:119543c9f674 | 920 | } |
| mbed_official | 489:119543c9f674 | 921 | |
| mbed_official | 489:119543c9f674 | 922 | /** |
| mbed_official | 489:119543c9f674 | 923 | * @brief Programs a half word at a specified Option Byte Data address. |
| mbed_official | 489:119543c9f674 | 924 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
| mbed_official | 489:119543c9f674 | 925 | * The function HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
| mbed_official | 489:119543c9f674 | 926 | * The function HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
| mbed_official | 489:119543c9f674 | 927 | * (system reset will occur) |
| mbed_official | 489:119543c9f674 | 928 | * Programming of the OB should be performed only after an erase (otherwise PGERR occurs) |
| mbed_official | 489:119543c9f674 | 929 | * @param Address: specifies the address to be programmed. |
| mbed_official | 489:119543c9f674 | 930 | * This parameter can be 0x1FFFF804 or 0x1FFFF806. |
| mbed_official | 489:119543c9f674 | 931 | * @param Data: specifies the data to be programmed. |
| mbed_official | 489:119543c9f674 | 932 | * @retval HAL status |
| mbed_official | 489:119543c9f674 | 933 | */ |
| mbed_official | 489:119543c9f674 | 934 | static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data) |
| mbed_official | 489:119543c9f674 | 935 | { |
| mbed_official | 489:119543c9f674 | 936 | HAL_StatusTypeDef status = HAL_ERROR; |
| mbed_official | 489:119543c9f674 | 937 | |
| mbed_official | 489:119543c9f674 | 938 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 939 | assert_param(IS_OB_DATA_ADDRESS(Address)); |
| mbed_official | 489:119543c9f674 | 940 | |
| mbed_official | 489:119543c9f674 | 941 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 942 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 943 | |
| mbed_official | 489:119543c9f674 | 944 | if(status == HAL_OK) |
| mbed_official | 489:119543c9f674 | 945 | { |
| mbed_official | 489:119543c9f674 | 946 | /* Clean the error context */ |
| mbed_official | 489:119543c9f674 | 947 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
| mbed_official | 489:119543c9f674 | 948 | |
| mbed_official | 489:119543c9f674 | 949 | /* Enables the Option Bytes Programming operation */ |
| mbed_official | 489:119543c9f674 | 950 | SET_BIT(FLASH->CR, FLASH_CR_OPTPG); |
| mbed_official | 489:119543c9f674 | 951 | *(__IO uint16_t*)Address = Data; |
| mbed_official | 489:119543c9f674 | 952 | |
| mbed_official | 489:119543c9f674 | 953 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 954 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 955 | |
| mbed_official | 489:119543c9f674 | 956 | /* If the program operation is completed, disable the OPTPG Bit */ |
| mbed_official | 489:119543c9f674 | 957 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); |
| mbed_official | 489:119543c9f674 | 958 | } |
| mbed_official | 489:119543c9f674 | 959 | /* Return the Option Byte Data Program Status */ |
| mbed_official | 489:119543c9f674 | 960 | return status; |
| mbed_official | 489:119543c9f674 | 961 | } |
| mbed_official | 489:119543c9f674 | 962 | |
| mbed_official | 489:119543c9f674 | 963 | /** |
| mbed_official | 489:119543c9f674 | 964 | * @brief Return the FLASH Write Protection Option Bytes value. |
| mbed_official | 489:119543c9f674 | 965 | * @retval The FLASH Write Protection Option Bytes value |
| mbed_official | 489:119543c9f674 | 966 | */ |
| mbed_official | 489:119543c9f674 | 967 | static uint32_t FLASH_OB_GetWRP(void) |
| mbed_official | 489:119543c9f674 | 968 | { |
| mbed_official | 489:119543c9f674 | 969 | /* Return the FLASH write protection Register value */ |
| mbed_official | 489:119543c9f674 | 970 | return (uint32_t)(READ_REG(FLASH->WRPR)); |
| mbed_official | 489:119543c9f674 | 971 | } |
| mbed_official | 489:119543c9f674 | 972 | |
| mbed_official | 489:119543c9f674 | 973 | /** |
| mbed_official | 489:119543c9f674 | 974 | * @brief Returns the FLASH Read Protection level. |
| mbed_official | 489:119543c9f674 | 975 | * @retval FLASH ReadOut Protection Status: |
| mbed_official | 489:119543c9f674 | 976 | * - SET, when OB_RDP_LEVEL_1 is set |
| mbed_official | 489:119543c9f674 | 977 | * - RESET, when OB_RDP_LEVEL_0 is set |
| mbed_official | 489:119543c9f674 | 978 | */ |
| mbed_official | 489:119543c9f674 | 979 | static FlagStatus FLASH_OB_GetRDP(void) |
| mbed_official | 489:119543c9f674 | 980 | { |
| mbed_official | 489:119543c9f674 | 981 | FlagStatus readstatus = RESET; |
| mbed_official | 489:119543c9f674 | 982 | |
| mbed_official | 489:119543c9f674 | 983 | if (HAL_IS_BIT_SET(FLASH->OBR, FLASH_OBR_RDPRT)) |
| mbed_official | 489:119543c9f674 | 984 | { |
| mbed_official | 489:119543c9f674 | 985 | readstatus = SET; |
| mbed_official | 489:119543c9f674 | 986 | } |
| mbed_official | 489:119543c9f674 | 987 | else |
| mbed_official | 489:119543c9f674 | 988 | { |
| mbed_official | 489:119543c9f674 | 989 | readstatus = RESET; |
| mbed_official | 489:119543c9f674 | 990 | } |
| mbed_official | 489:119543c9f674 | 991 | return readstatus; |
| mbed_official | 489:119543c9f674 | 992 | } |
| mbed_official | 489:119543c9f674 | 993 | |
| mbed_official | 489:119543c9f674 | 994 | /** |
| mbed_official | 489:119543c9f674 | 995 | * @brief Return the FLASH User Option Byte value. |
| mbed_official | 489:119543c9f674 | 996 | * @retval The FLASH User Option Bytes values: FLASH_OBR_IWDG_SW(Bit2), |
| mbed_official | 489:119543c9f674 | 997 | * FLASH_OBR_nRST_STOP(Bit3),FLASH_OBR_nRST_STDBY(Bit4). |
| mbed_official | 489:119543c9f674 | 998 | * And FLASH_OBR_BFB2(Bit5) for STM32F101xG and STM32F103xG . |
| mbed_official | 489:119543c9f674 | 999 | */ |
| mbed_official | 489:119543c9f674 | 1000 | static uint8_t FLASH_OB_GetUser(void) |
| mbed_official | 489:119543c9f674 | 1001 | { |
| mbed_official | 489:119543c9f674 | 1002 | /* Return the User Option Byte */ |
| mbed_official | 489:119543c9f674 | 1003 | return (uint8_t)((READ_REG(FLASH->OBR) & FLASH_OBR_USER) >> 2); |
| mbed_official | 489:119543c9f674 | 1004 | } |
| mbed_official | 489:119543c9f674 | 1005 | |
| mbed_official | 489:119543c9f674 | 1006 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 1007 | /** |
| mbed_official | 489:119543c9f674 | 1008 | * @brief Wait for a FLASH BANK2 operation to complete. |
| mbed_official | 489:119543c9f674 | 1009 | * @param Timeout: maximum flash operationtimeout |
| mbed_official | 489:119543c9f674 | 1010 | * @retval HAL_StatusTypeDef HAL Status |
| mbed_official | 489:119543c9f674 | 1011 | */ |
| mbed_official | 489:119543c9f674 | 1012 | static HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout) |
| mbed_official | 489:119543c9f674 | 1013 | { |
| mbed_official | 489:119543c9f674 | 1014 | /* Wait for the FLASH BANK2 operation to complete by polling on BUSY flag to be reset. |
| mbed_official | 489:119543c9f674 | 1015 | Even if the FLASH BANK2 operation fails, the BUSY flag will be reset and an error |
| mbed_official | 489:119543c9f674 | 1016 | flag will be set */ |
| mbed_official | 489:119543c9f674 | 1017 | |
| mbed_official | 489:119543c9f674 | 1018 | uint32_t tickstart = HAL_GetTick(); |
| mbed_official | 489:119543c9f674 | 1019 | |
| mbed_official | 489:119543c9f674 | 1020 | while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY_BANK2)) |
| mbed_official | 489:119543c9f674 | 1021 | { |
| mbed_official | 489:119543c9f674 | 1022 | if (Timeout != HAL_MAX_DELAY) |
| mbed_official | 489:119543c9f674 | 1023 | { |
| mbed_official | 489:119543c9f674 | 1024 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
| mbed_official | 489:119543c9f674 | 1025 | { |
| mbed_official | 489:119543c9f674 | 1026 | return HAL_TIMEOUT; |
| mbed_official | 489:119543c9f674 | 1027 | } |
| mbed_official | 489:119543c9f674 | 1028 | } |
| mbed_official | 489:119543c9f674 | 1029 | } |
| mbed_official | 489:119543c9f674 | 1030 | |
| mbed_official | 489:119543c9f674 | 1031 | /* Check FLASH End of Operation flag */ |
| mbed_official | 489:119543c9f674 | 1032 | if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK2)) |
| mbed_official | 489:119543c9f674 | 1033 | { |
| mbed_official | 489:119543c9f674 | 1034 | /* Clear FLASH End of Operation pending bit */ |
| mbed_official | 489:119543c9f674 | 1035 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2); |
| mbed_official | 489:119543c9f674 | 1036 | } |
| mbed_official | 489:119543c9f674 | 1037 | |
| mbed_official | 489:119543c9f674 | 1038 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)) |
| mbed_official | 489:119543c9f674 | 1039 | { |
| mbed_official | 489:119543c9f674 | 1040 | /*Save the error code*/ |
| mbed_official | 489:119543c9f674 | 1041 | FLASH_SetErrorCode(); |
| mbed_official | 489:119543c9f674 | 1042 | return HAL_ERROR; |
| mbed_official | 489:119543c9f674 | 1043 | } |
| mbed_official | 489:119543c9f674 | 1044 | |
| mbed_official | 489:119543c9f674 | 1045 | /* If there is an error flag set */ |
| mbed_official | 489:119543c9f674 | 1046 | return HAL_OK; |
| mbed_official | 489:119543c9f674 | 1047 | |
| mbed_official | 489:119543c9f674 | 1048 | } |
| mbed_official | 489:119543c9f674 | 1049 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 1050 | |
| mbed_official | 489:119543c9f674 | 1051 | /** |
| mbed_official | 489:119543c9f674 | 1052 | * @} |
| mbed_official | 489:119543c9f674 | 1053 | */ |
| mbed_official | 489:119543c9f674 | 1054 | |
| mbed_official | 489:119543c9f674 | 1055 | /** |
| mbed_official | 489:119543c9f674 | 1056 | * @} |
| mbed_official | 489:119543c9f674 | 1057 | */ |
| mbed_official | 489:119543c9f674 | 1058 | |
| mbed_official | 489:119543c9f674 | 1059 | /** @addtogroup FLASH |
| mbed_official | 489:119543c9f674 | 1060 | * @{ |
| mbed_official | 489:119543c9f674 | 1061 | */ |
| mbed_official | 489:119543c9f674 | 1062 | |
| mbed_official | 489:119543c9f674 | 1063 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 1064 | /** @addtogroup FLASH_Exported_Functions |
| mbed_official | 489:119543c9f674 | 1065 | * @{ |
| mbed_official | 489:119543c9f674 | 1066 | */ |
| mbed_official | 489:119543c9f674 | 1067 | |
| mbed_official | 489:119543c9f674 | 1068 | /** @addtogroup FLASH_Exported_Functions_Group2 |
| mbed_official | 489:119543c9f674 | 1069 | * @{ |
| mbed_official | 489:119543c9f674 | 1070 | */ |
| mbed_official | 489:119543c9f674 | 1071 | |
| mbed_official | 489:119543c9f674 | 1072 | /** |
| mbed_official | 489:119543c9f674 | 1073 | * @brief Unlock the FLASH control register access |
| mbed_official | 489:119543c9f674 | 1074 | * @retval HAL Status |
| mbed_official | 489:119543c9f674 | 1075 | */ |
| mbed_official | 489:119543c9f674 | 1076 | HAL_StatusTypeDef HAL_FLASH_Unlock(void) |
| mbed_official | 489:119543c9f674 | 1077 | { |
| mbed_official | 489:119543c9f674 | 1078 | if (HAL_IS_BIT_SET(FLASH->CR, FLASH_CR_LOCK)) |
| mbed_official | 489:119543c9f674 | 1079 | { |
| mbed_official | 489:119543c9f674 | 1080 | /* Authorize the FLASH BANK1 Registers access */ |
| mbed_official | 489:119543c9f674 | 1081 | WRITE_REG(FLASH->KEYR, FLASH_KEY1); |
| mbed_official | 489:119543c9f674 | 1082 | WRITE_REG(FLASH->KEYR, FLASH_KEY2); |
| mbed_official | 489:119543c9f674 | 1083 | } |
| mbed_official | 489:119543c9f674 | 1084 | else |
| mbed_official | 489:119543c9f674 | 1085 | { |
| mbed_official | 489:119543c9f674 | 1086 | return HAL_ERROR; |
| mbed_official | 489:119543c9f674 | 1087 | } |
| mbed_official | 489:119543c9f674 | 1088 | |
| mbed_official | 489:119543c9f674 | 1089 | |
| mbed_official | 489:119543c9f674 | 1090 | if (HAL_IS_BIT_SET(FLASH->CR2, FLASH_CR2_LOCK)) |
| mbed_official | 489:119543c9f674 | 1091 | { |
| mbed_official | 489:119543c9f674 | 1092 | /* Authorize the FLASH BANK2 Registers access */ |
| mbed_official | 489:119543c9f674 | 1093 | WRITE_REG(FLASH->KEYR2, FLASH_KEY1); |
| mbed_official | 489:119543c9f674 | 1094 | WRITE_REG(FLASH->KEYR2, FLASH_KEY2); |
| mbed_official | 489:119543c9f674 | 1095 | } |
| mbed_official | 489:119543c9f674 | 1096 | else |
| mbed_official | 489:119543c9f674 | 1097 | { |
| mbed_official | 489:119543c9f674 | 1098 | return HAL_ERROR; |
| mbed_official | 489:119543c9f674 | 1099 | } |
| mbed_official | 489:119543c9f674 | 1100 | |
| mbed_official | 489:119543c9f674 | 1101 | return HAL_OK; |
| mbed_official | 489:119543c9f674 | 1102 | } |
| mbed_official | 489:119543c9f674 | 1103 | |
| mbed_official | 489:119543c9f674 | 1104 | /** |
| mbed_official | 489:119543c9f674 | 1105 | * @brief Locks the FLASH control register access |
| mbed_official | 489:119543c9f674 | 1106 | * @retval HAL Status |
| mbed_official | 489:119543c9f674 | 1107 | */ |
| mbed_official | 489:119543c9f674 | 1108 | HAL_StatusTypeDef HAL_FLASH_Lock(void) |
| mbed_official | 489:119543c9f674 | 1109 | { |
| mbed_official | 489:119543c9f674 | 1110 | /* Set the LOCK Bit to lock the FLASH BANK1 Registers access */ |
| mbed_official | 489:119543c9f674 | 1111 | SET_BIT(FLASH->CR, FLASH_CR_LOCK); |
| mbed_official | 489:119543c9f674 | 1112 | |
| mbed_official | 489:119543c9f674 | 1113 | /* Set the LOCK Bit to lock the FLASH BANK2 Registers access */ |
| mbed_official | 489:119543c9f674 | 1114 | SET_BIT(FLASH->CR2, FLASH_CR2_LOCK); |
| mbed_official | 489:119543c9f674 | 1115 | |
| mbed_official | 489:119543c9f674 | 1116 | return HAL_OK; |
| mbed_official | 489:119543c9f674 | 1117 | } |
| mbed_official | 489:119543c9f674 | 1118 | /** |
| mbed_official | 489:119543c9f674 | 1119 | * @} |
| mbed_official | 489:119543c9f674 | 1120 | */ |
| mbed_official | 489:119543c9f674 | 1121 | |
| mbed_official | 489:119543c9f674 | 1122 | /** @addtogroup FLASH_Exported_Functions_Group1 |
| mbed_official | 489:119543c9f674 | 1123 | * @{ |
| mbed_official | 489:119543c9f674 | 1124 | */ |
| mbed_official | 489:119543c9f674 | 1125 | |
| mbed_official | 489:119543c9f674 | 1126 | /** |
| mbed_official | 489:119543c9f674 | 1127 | * @brief Program halfword, word or double word at a specified address |
| mbed_official | 489:119543c9f674 | 1128 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
| mbed_official | 489:119543c9f674 | 1129 | * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface |
| mbed_official | 489:119543c9f674 | 1130 | * |
| mbed_official | 489:119543c9f674 | 1131 | * @note If an erase and a program operations are requested simultaneously, |
| mbed_official | 489:119543c9f674 | 1132 | * the erase operation is performed before the program one. |
| mbed_official | 489:119543c9f674 | 1133 | * |
| mbed_official | 489:119543c9f674 | 1134 | * @note FLASH should be previously erased before new programmation (only exception to this |
| mbed_official | 489:119543c9f674 | 1135 | * is when 0x0000 is programmed) |
| mbed_official | 489:119543c9f674 | 1136 | * |
| mbed_official | 489:119543c9f674 | 1137 | * @param TypeProgram: Indicate the way to program at a specified address. |
| mbed_official | 489:119543c9f674 | 1138 | * This parameter can be a value of @ref FLASH_Type_Program |
| mbed_official | 489:119543c9f674 | 1139 | * @param Address: Specifies the address to be programmed. |
| mbed_official | 489:119543c9f674 | 1140 | * @param Data: Specifies the data to be programmed |
| mbed_official | 489:119543c9f674 | 1141 | * |
| mbed_official | 489:119543c9f674 | 1142 | * @retval HAL_StatusTypeDef HAL Status |
| mbed_official | 489:119543c9f674 | 1143 | */ |
| mbed_official | 489:119543c9f674 | 1144 | HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data) |
| mbed_official | 489:119543c9f674 | 1145 | { |
| mbed_official | 489:119543c9f674 | 1146 | HAL_StatusTypeDef status = HAL_ERROR; |
| mbed_official | 489:119543c9f674 | 1147 | uint8_t index = 0; |
| mbed_official | 489:119543c9f674 | 1148 | uint8_t nbiterations = 0; |
| mbed_official | 489:119543c9f674 | 1149 | |
| mbed_official | 489:119543c9f674 | 1150 | /* Process Locked */ |
| mbed_official | 489:119543c9f674 | 1151 | __HAL_LOCK(&pFlash); |
| mbed_official | 489:119543c9f674 | 1152 | |
| mbed_official | 489:119543c9f674 | 1153 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 1154 | assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram)); |
| mbed_official | 489:119543c9f674 | 1155 | assert_param(IS_FLASH_PROGRAM_ADDRESS(Address)); |
| mbed_official | 489:119543c9f674 | 1156 | |
| mbed_official | 489:119543c9f674 | 1157 | if(Address <= FLASH_BANK1_END) |
| mbed_official | 489:119543c9f674 | 1158 | { |
| mbed_official | 489:119543c9f674 | 1159 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 1160 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 1161 | } |
| mbed_official | 489:119543c9f674 | 1162 | else |
| mbed_official | 489:119543c9f674 | 1163 | { |
| mbed_official | 489:119543c9f674 | 1164 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 1165 | status = FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 1166 | } |
| mbed_official | 489:119543c9f674 | 1167 | |
| mbed_official | 489:119543c9f674 | 1168 | if(status == HAL_OK) |
| mbed_official | 489:119543c9f674 | 1169 | { |
| mbed_official | 489:119543c9f674 | 1170 | if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD) |
| mbed_official | 489:119543c9f674 | 1171 | { |
| mbed_official | 489:119543c9f674 | 1172 | /* Program halfword (16-bit) at a specified address. */ |
| mbed_official | 489:119543c9f674 | 1173 | nbiterations = 1; |
| mbed_official | 489:119543c9f674 | 1174 | } |
| mbed_official | 489:119543c9f674 | 1175 | else if(TypeProgram == FLASH_TYPEPROGRAM_WORD) |
| mbed_official | 489:119543c9f674 | 1176 | { |
| mbed_official | 489:119543c9f674 | 1177 | /* Program word (32-bit = 2*16-bit) at a specified address. */ |
| mbed_official | 489:119543c9f674 | 1178 | nbiterations = 2; |
| mbed_official | 489:119543c9f674 | 1179 | } |
| mbed_official | 489:119543c9f674 | 1180 | else |
| mbed_official | 489:119543c9f674 | 1181 | { |
| mbed_official | 489:119543c9f674 | 1182 | /* Program double word (64-bit = 4*16-bit) at a specified address. */ |
| mbed_official | 489:119543c9f674 | 1183 | nbiterations = 4; |
| mbed_official | 489:119543c9f674 | 1184 | } |
| mbed_official | 489:119543c9f674 | 1185 | |
| mbed_official | 489:119543c9f674 | 1186 | for (index = 0; index < nbiterations; index++) |
| mbed_official | 489:119543c9f674 | 1187 | { |
| mbed_official | 489:119543c9f674 | 1188 | FLASH_Program_HalfWord((Address + (2*index)), (uint16_t)(Data >> (16*index))); |
| mbed_official | 489:119543c9f674 | 1189 | |
| mbed_official | 489:119543c9f674 | 1190 | if(Address <= FLASH_BANK1_END) |
| mbed_official | 489:119543c9f674 | 1191 | { |
| mbed_official | 489:119543c9f674 | 1192 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 1193 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 1194 | |
| mbed_official | 489:119543c9f674 | 1195 | /* If the program operation is completed, disable the PG Bit */ |
| mbed_official | 489:119543c9f674 | 1196 | CLEAR_BIT(FLASH->CR, FLASH_CR_PG); |
| mbed_official | 489:119543c9f674 | 1197 | } |
| mbed_official | 489:119543c9f674 | 1198 | else |
| mbed_official | 489:119543c9f674 | 1199 | { |
| mbed_official | 489:119543c9f674 | 1200 | /* Wait for last operation to be completed */ |
| mbed_official | 489:119543c9f674 | 1201 | status = FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE); |
| mbed_official | 489:119543c9f674 | 1202 | |
| mbed_official | 489:119543c9f674 | 1203 | /* If the program operation is completed, disable the PG Bit */ |
| mbed_official | 489:119543c9f674 | 1204 | CLEAR_BIT(FLASH->CR2, FLASH_CR2_PG); |
| mbed_official | 489:119543c9f674 | 1205 | } |
| mbed_official | 489:119543c9f674 | 1206 | /* In case of error, stop programation procedure */ |
| mbed_official | 489:119543c9f674 | 1207 | if (status != HAL_OK) |
| mbed_official | 489:119543c9f674 | 1208 | { |
| mbed_official | 489:119543c9f674 | 1209 | break; |
| mbed_official | 489:119543c9f674 | 1210 | } |
| mbed_official | 489:119543c9f674 | 1211 | } |
| mbed_official | 489:119543c9f674 | 1212 | } |
| mbed_official | 489:119543c9f674 | 1213 | |
| mbed_official | 489:119543c9f674 | 1214 | /* Process Unlocked */ |
| mbed_official | 489:119543c9f674 | 1215 | __HAL_UNLOCK(&pFlash); |
| mbed_official | 489:119543c9f674 | 1216 | |
| mbed_official | 489:119543c9f674 | 1217 | return status; |
| mbed_official | 489:119543c9f674 | 1218 | } |
| mbed_official | 489:119543c9f674 | 1219 | |
| mbed_official | 489:119543c9f674 | 1220 | /** |
| mbed_official | 489:119543c9f674 | 1221 | * @brief Program halfword, word or double word at a specified address with interrupt enabled. |
| mbed_official | 489:119543c9f674 | 1222 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
| mbed_official | 489:119543c9f674 | 1223 | * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface |
| mbed_official | 489:119543c9f674 | 1224 | * |
| mbed_official | 489:119543c9f674 | 1225 | * @note If an erase and a program operations are requested simultaneously, |
| mbed_official | 489:119543c9f674 | 1226 | * the erase operation is performed before the program one. |
| mbed_official | 489:119543c9f674 | 1227 | * |
| mbed_official | 489:119543c9f674 | 1228 | * @param TypeProgram: Indicate the way to program at a specified address. |
| mbed_official | 489:119543c9f674 | 1229 | * This parameter can be a value of @ref FLASH_Type_Program |
| mbed_official | 489:119543c9f674 | 1230 | * @param Address: Specifies the address to be programmed. |
| mbed_official | 489:119543c9f674 | 1231 | * @param Data: Specifies the data to be programmed |
| mbed_official | 489:119543c9f674 | 1232 | * |
| mbed_official | 489:119543c9f674 | 1233 | * @retval HAL_StatusTypeDef HAL Status |
| mbed_official | 489:119543c9f674 | 1234 | */ |
| mbed_official | 489:119543c9f674 | 1235 | HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data) |
| mbed_official | 489:119543c9f674 | 1236 | { |
| mbed_official | 489:119543c9f674 | 1237 | HAL_StatusTypeDef status = HAL_OK; |
| mbed_official | 489:119543c9f674 | 1238 | |
| mbed_official | 489:119543c9f674 | 1239 | /* Process Locked */ |
| mbed_official | 489:119543c9f674 | 1240 | __HAL_LOCK(&pFlash); |
| mbed_official | 489:119543c9f674 | 1241 | |
| mbed_official | 489:119543c9f674 | 1242 | /* If procedure already ongoing, reject the next one */ |
| mbed_official | 489:119543c9f674 | 1243 | if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) |
| mbed_official | 489:119543c9f674 | 1244 | { |
| mbed_official | 489:119543c9f674 | 1245 | return HAL_ERROR; |
| mbed_official | 489:119543c9f674 | 1246 | } |
| mbed_official | 489:119543c9f674 | 1247 | |
| mbed_official | 489:119543c9f674 | 1248 | /* Check the parameters */ |
| mbed_official | 489:119543c9f674 | 1249 | assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram)); |
| mbed_official | 489:119543c9f674 | 1250 | assert_param(IS_FLASH_PROGRAM_ADDRESS(Address)); |
| mbed_official | 489:119543c9f674 | 1251 | |
| mbed_official | 489:119543c9f674 | 1252 | if(Address <= FLASH_BANK1_END) |
| mbed_official | 489:119543c9f674 | 1253 | { |
| mbed_official | 489:119543c9f674 | 1254 | /* Enable End of FLASH Operation and Error source interrupts */ |
| mbed_official | 489:119543c9f674 | 1255 | __HAL_FLASH_ENABLE_IT((FLASH_IT_EOP_BANK1 | FLASH_IT_ERR_BANK1)); |
| mbed_official | 489:119543c9f674 | 1256 | }else |
| mbed_official | 489:119543c9f674 | 1257 | { |
| mbed_official | 489:119543c9f674 | 1258 | /* Enable End of FLASH Operation and Error source interrupts */ |
| mbed_official | 489:119543c9f674 | 1259 | __HAL_FLASH_ENABLE_IT((FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2)); |
| mbed_official | 489:119543c9f674 | 1260 | } |
| mbed_official | 489:119543c9f674 | 1261 | |
| mbed_official | 489:119543c9f674 | 1262 | pFlash.Address = Address; |
| mbed_official | 489:119543c9f674 | 1263 | pFlash.Data = Data; |
| mbed_official | 489:119543c9f674 | 1264 | |
| mbed_official | 489:119543c9f674 | 1265 | if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD) |
| mbed_official | 489:119543c9f674 | 1266 | { |
| mbed_official | 489:119543c9f674 | 1267 | pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMHALFWORD; |
| mbed_official | 489:119543c9f674 | 1268 | /*Program halfword (16-bit) at a specified address.*/ |
| mbed_official | 489:119543c9f674 | 1269 | pFlash.DataRemaining = 1; |
| mbed_official | 489:119543c9f674 | 1270 | } |
| mbed_official | 489:119543c9f674 | 1271 | else if(TypeProgram == FLASH_TYPEPROGRAM_WORD) |
| mbed_official | 489:119543c9f674 | 1272 | { |
| mbed_official | 489:119543c9f674 | 1273 | pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMWORD; |
| mbed_official | 489:119543c9f674 | 1274 | /*Program word (32-bit : 2*16-bit) at a specified address.*/ |
| mbed_official | 489:119543c9f674 | 1275 | pFlash.DataRemaining = 2; |
| mbed_official | 489:119543c9f674 | 1276 | } |
| mbed_official | 489:119543c9f674 | 1277 | else |
| mbed_official | 489:119543c9f674 | 1278 | { |
| mbed_official | 489:119543c9f674 | 1279 | pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMDOUBLEWORD; |
| mbed_official | 489:119543c9f674 | 1280 | /*Program double word (64-bit : 4*16-bit) at a specified address.*/ |
| mbed_official | 489:119543c9f674 | 1281 | pFlash.DataRemaining = 4; |
| mbed_official | 489:119543c9f674 | 1282 | } |
| mbed_official | 489:119543c9f674 | 1283 | |
| mbed_official | 489:119543c9f674 | 1284 | /*Program halfword (16-bit) at a specified address.*/ |
| mbed_official | 489:119543c9f674 | 1285 | FLASH_Program_HalfWord(Address, (uint16_t)Data); |
| mbed_official | 489:119543c9f674 | 1286 | |
| mbed_official | 489:119543c9f674 | 1287 | return status; |
| mbed_official | 489:119543c9f674 | 1288 | } |
| mbed_official | 489:119543c9f674 | 1289 | |
| mbed_official | 489:119543c9f674 | 1290 | /** |
| mbed_official | 489:119543c9f674 | 1291 | * @brief This function handles FLASH interrupt request. |
| mbed_official | 489:119543c9f674 | 1292 | * @retval None |
| mbed_official | 489:119543c9f674 | 1293 | */ |
| mbed_official | 489:119543c9f674 | 1294 | void HAL_FLASH_IRQHandler(void) |
| mbed_official | 489:119543c9f674 | 1295 | { |
| mbed_official | 489:119543c9f674 | 1296 | uint32_t addresstmp = 0; |
| mbed_official | 489:119543c9f674 | 1297 | |
| mbed_official | 489:119543c9f674 | 1298 | /* Check FLASH operation error flags */ |
| mbed_official | 489:119543c9f674 | 1299 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK1) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK1) || \ |
| mbed_official | 489:119543c9f674 | 1300 | (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2))) |
| mbed_official | 489:119543c9f674 | 1301 | { |
| mbed_official | 489:119543c9f674 | 1302 | /*Save the Error code*/ |
| mbed_official | 489:119543c9f674 | 1303 | FLASH_SetErrorCode(); |
| mbed_official | 489:119543c9f674 | 1304 | |
| mbed_official | 489:119543c9f674 | 1305 | /* FLASH error interrupt user callback */ |
| mbed_official | 489:119543c9f674 | 1306 | HAL_FLASH_OperationErrorCallback(pFlash.Address); |
| mbed_official | 489:119543c9f674 | 1307 | |
| mbed_official | 489:119543c9f674 | 1308 | /* Reset address and stop the procedure ongoing*/ |
| mbed_official | 489:119543c9f674 | 1309 | pFlash.Address = 0xFFFFFFFF; |
| mbed_official | 489:119543c9f674 | 1310 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
| mbed_official | 489:119543c9f674 | 1311 | } |
| mbed_official | 489:119543c9f674 | 1312 | |
| mbed_official | 489:119543c9f674 | 1313 | /* Check FLASH End of Operation flag */ |
| mbed_official | 489:119543c9f674 | 1314 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK1)) |
| mbed_official | 489:119543c9f674 | 1315 | { |
| mbed_official | 489:119543c9f674 | 1316 | /* Clear FLASH End of Operation pending bit */ |
| mbed_official | 489:119543c9f674 | 1317 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK1); |
| mbed_official | 489:119543c9f674 | 1318 | |
| mbed_official | 489:119543c9f674 | 1319 | /* Process can continue only if no error detected */ |
| mbed_official | 489:119543c9f674 | 1320 | if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE) |
| mbed_official | 489:119543c9f674 | 1321 | { |
| mbed_official | 489:119543c9f674 | 1322 | if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE) |
| mbed_official | 489:119543c9f674 | 1323 | { |
| mbed_official | 489:119543c9f674 | 1324 | /* Nb of pages to erased can be decreased */ |
| mbed_official | 489:119543c9f674 | 1325 | pFlash.DataRemaining--; |
| mbed_official | 489:119543c9f674 | 1326 | |
| mbed_official | 489:119543c9f674 | 1327 | /* Indicate user which page address has been erased*/ |
| mbed_official | 489:119543c9f674 | 1328 | HAL_FLASH_EndOfOperationCallback(pFlash.Address); |
| mbed_official | 489:119543c9f674 | 1329 | |
| mbed_official | 489:119543c9f674 | 1330 | /* Check if there are still pages to erase*/ |
| mbed_official | 489:119543c9f674 | 1331 | if(pFlash.DataRemaining != 0) |
| mbed_official | 489:119543c9f674 | 1332 | { |
| mbed_official | 489:119543c9f674 | 1333 | /* Increment page address to next page */ |
| mbed_official | 489:119543c9f674 | 1334 | pFlash.Address += FLASH_PAGE_SIZE; |
| mbed_official | 489:119543c9f674 | 1335 | addresstmp = pFlash.Address; |
| mbed_official | 489:119543c9f674 | 1336 | |
| mbed_official | 489:119543c9f674 | 1337 | /* Operation is completed, disable the PER Bit */ |
| mbed_official | 489:119543c9f674 | 1338 | CLEAR_BIT(FLASH->CR, FLASH_CR_PER); |
| mbed_official | 489:119543c9f674 | 1339 | |
| mbed_official | 489:119543c9f674 | 1340 | FLASH_PageErase(addresstmp); |
| mbed_official | 489:119543c9f674 | 1341 | } |
| mbed_official | 489:119543c9f674 | 1342 | else |
| mbed_official | 489:119543c9f674 | 1343 | { |
| mbed_official | 489:119543c9f674 | 1344 | /*No more pages to Erase*/ |
| mbed_official | 489:119543c9f674 | 1345 | |
| mbed_official | 489:119543c9f674 | 1346 | /*Reset Address and stop Erase pages procedure*/ |
| mbed_official | 489:119543c9f674 | 1347 | pFlash.Address = 0xFFFFFFFF; |
| mbed_official | 489:119543c9f674 | 1348 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
| mbed_official | 489:119543c9f674 | 1349 | } |
| mbed_official | 489:119543c9f674 | 1350 | } |
| mbed_official | 489:119543c9f674 | 1351 | else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE) |
| mbed_official | 489:119543c9f674 | 1352 | { |
| mbed_official | 489:119543c9f674 | 1353 | /* Operation is completed, disable the MER Bit */ |
| mbed_official | 489:119543c9f674 | 1354 | CLEAR_BIT(FLASH->CR, FLASH_CR_MER); |
| mbed_official | 489:119543c9f674 | 1355 | |
| mbed_official | 489:119543c9f674 | 1356 | /* Stop Mass Erase procedure if no pending mass erase on other bank */ |
| mbed_official | 489:119543c9f674 | 1357 | if (HAL_IS_BIT_CLR(FLASH->CR2, FLASH_CR2_MER)) |
| mbed_official | 489:119543c9f674 | 1358 | { |
| mbed_official | 489:119543c9f674 | 1359 | /* MassErase ended. Return the selected bank*/ |
| mbed_official | 489:119543c9f674 | 1360 | /* FLASH EOP interrupt user callback */ |
| mbed_official | 489:119543c9f674 | 1361 | HAL_FLASH_EndOfOperationCallback(0); |
| mbed_official | 489:119543c9f674 | 1362 | |
| mbed_official | 489:119543c9f674 | 1363 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
| mbed_official | 489:119543c9f674 | 1364 | } |
| mbed_official | 489:119543c9f674 | 1365 | } |
| mbed_official | 489:119543c9f674 | 1366 | else |
| mbed_official | 489:119543c9f674 | 1367 | { |
| mbed_official | 489:119543c9f674 | 1368 | /* Nb of 16-bit data to program can be decreased */ |
| mbed_official | 489:119543c9f674 | 1369 | pFlash.DataRemaining--; |
| mbed_official | 489:119543c9f674 | 1370 | |
| mbed_official | 489:119543c9f674 | 1371 | /* Check if there are still 16-bit data to program */ |
| mbed_official | 489:119543c9f674 | 1372 | if(pFlash.DataRemaining != 0) |
| mbed_official | 489:119543c9f674 | 1373 | { |
| mbed_official | 489:119543c9f674 | 1374 | /* Increment address to 16-bit */ |
| mbed_official | 489:119543c9f674 | 1375 | pFlash.Address += 2; |
| mbed_official | 489:119543c9f674 | 1376 | addresstmp = pFlash.Address; |
| mbed_official | 489:119543c9f674 | 1377 | |
| mbed_official | 489:119543c9f674 | 1378 | /* Shift to have next 16-bit data */ |
| mbed_official | 489:119543c9f674 | 1379 | pFlash.Data = (pFlash.Data >> 16); |
| mbed_official | 489:119543c9f674 | 1380 | |
| mbed_official | 489:119543c9f674 | 1381 | /* Operation is completed, disable the PG Bit */ |
| mbed_official | 489:119543c9f674 | 1382 | CLEAR_BIT(FLASH->CR, FLASH_CR_PG); |
| mbed_official | 489:119543c9f674 | 1383 | |
| mbed_official | 489:119543c9f674 | 1384 | /*Program halfword (16-bit) at a specified address.*/ |
| mbed_official | 489:119543c9f674 | 1385 | FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data); |
| mbed_official | 489:119543c9f674 | 1386 | } |
| mbed_official | 489:119543c9f674 | 1387 | else |
| mbed_official | 489:119543c9f674 | 1388 | { |
| mbed_official | 489:119543c9f674 | 1389 | /*Program ended. Return the selected address*/ |
| mbed_official | 489:119543c9f674 | 1390 | /* FLASH EOP interrupt user callback */ |
| mbed_official | 489:119543c9f674 | 1391 | if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD) |
| mbed_official | 489:119543c9f674 | 1392 | { |
| mbed_official | 489:119543c9f674 | 1393 | HAL_FLASH_EndOfOperationCallback(pFlash.Address); |
| mbed_official | 489:119543c9f674 | 1394 | } |
| mbed_official | 489:119543c9f674 | 1395 | else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD) |
| mbed_official | 489:119543c9f674 | 1396 | { |
| mbed_official | 489:119543c9f674 | 1397 | HAL_FLASH_EndOfOperationCallback(pFlash.Address - 2); |
| mbed_official | 489:119543c9f674 | 1398 | } |
| mbed_official | 489:119543c9f674 | 1399 | else |
| mbed_official | 489:119543c9f674 | 1400 | { |
| mbed_official | 489:119543c9f674 | 1401 | HAL_FLASH_EndOfOperationCallback(pFlash.Address - 6); |
| mbed_official | 489:119543c9f674 | 1402 | } |
| mbed_official | 489:119543c9f674 | 1403 | |
| mbed_official | 489:119543c9f674 | 1404 | /* Reset Address and stop Program procedure*/ |
| mbed_official | 489:119543c9f674 | 1405 | pFlash.Address = 0xFFFFFFFF; |
| mbed_official | 489:119543c9f674 | 1406 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
| mbed_official | 489:119543c9f674 | 1407 | } |
| mbed_official | 489:119543c9f674 | 1408 | } |
| mbed_official | 489:119543c9f674 | 1409 | } |
| mbed_official | 489:119543c9f674 | 1410 | } |
| mbed_official | 489:119543c9f674 | 1411 | |
| mbed_official | 489:119543c9f674 | 1412 | /* Check FLASH End of Operation flag */ |
| mbed_official | 489:119543c9f674 | 1413 | if(__HAL_FLASH_GET_FLAG( FLASH_FLAG_EOP_BANK2)) |
| mbed_official | 489:119543c9f674 | 1414 | { |
| mbed_official | 489:119543c9f674 | 1415 | /* Clear FLASH End of Operation pending bit */ |
| mbed_official | 489:119543c9f674 | 1416 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2); |
| mbed_official | 489:119543c9f674 | 1417 | |
| mbed_official | 489:119543c9f674 | 1418 | /* Process can continue only if no error detected */ |
| mbed_official | 489:119543c9f674 | 1419 | if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE) |
| mbed_official | 489:119543c9f674 | 1420 | { |
| mbed_official | 489:119543c9f674 | 1421 | if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE) |
| mbed_official | 489:119543c9f674 | 1422 | { |
| mbed_official | 489:119543c9f674 | 1423 | /* Nb of pages to erased can be decreased */ |
| mbed_official | 489:119543c9f674 | 1424 | pFlash.DataRemaining--; |
| mbed_official | 489:119543c9f674 | 1425 | |
| mbed_official | 489:119543c9f674 | 1426 | /* Indicate user which page address has been erased*/ |
| mbed_official | 489:119543c9f674 | 1427 | HAL_FLASH_EndOfOperationCallback(pFlash.Address); |
| mbed_official | 489:119543c9f674 | 1428 | |
| mbed_official | 489:119543c9f674 | 1429 | /* Check if there are still pages to erase*/ |
| mbed_official | 489:119543c9f674 | 1430 | if(pFlash.DataRemaining != 0) |
| mbed_official | 489:119543c9f674 | 1431 | { |
| mbed_official | 489:119543c9f674 | 1432 | /* Increment page address to next page */ |
| mbed_official | 489:119543c9f674 | 1433 | pFlash.Address += FLASH_PAGE_SIZE; |
| mbed_official | 489:119543c9f674 | 1434 | addresstmp = pFlash.Address; |
| mbed_official | 489:119543c9f674 | 1435 | |
| mbed_official | 489:119543c9f674 | 1436 | /* Operation is completed, disable the PER Bit */ |
| mbed_official | 489:119543c9f674 | 1437 | CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER); |
| mbed_official | 489:119543c9f674 | 1438 | |
| mbed_official | 489:119543c9f674 | 1439 | FLASH_PageErase(addresstmp); |
| mbed_official | 489:119543c9f674 | 1440 | } |
| mbed_official | 489:119543c9f674 | 1441 | else |
| mbed_official | 489:119543c9f674 | 1442 | { |
| mbed_official | 489:119543c9f674 | 1443 | /*No more pages to Erase*/ |
| mbed_official | 489:119543c9f674 | 1444 | |
| mbed_official | 489:119543c9f674 | 1445 | /*Reset Address and stop Erase pages procedure*/ |
| mbed_official | 489:119543c9f674 | 1446 | pFlash.Address = 0xFFFFFFFF; |
| mbed_official | 489:119543c9f674 | 1447 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
| mbed_official | 489:119543c9f674 | 1448 | } |
| mbed_official | 489:119543c9f674 | 1449 | } |
| mbed_official | 489:119543c9f674 | 1450 | else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE) |
| mbed_official | 489:119543c9f674 | 1451 | { |
| mbed_official | 489:119543c9f674 | 1452 | /* Operation is completed, disable the MER Bit */ |
| mbed_official | 489:119543c9f674 | 1453 | CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER); |
| mbed_official | 489:119543c9f674 | 1454 | |
| mbed_official | 489:119543c9f674 | 1455 | if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_MER)) |
| mbed_official | 489:119543c9f674 | 1456 | { |
| mbed_official | 489:119543c9f674 | 1457 | /* MassErase ended. Return the selected bank*/ |
| mbed_official | 489:119543c9f674 | 1458 | /* FLASH EOP interrupt user callback */ |
| mbed_official | 489:119543c9f674 | 1459 | HAL_FLASH_EndOfOperationCallback(0); |
| mbed_official | 489:119543c9f674 | 1460 | |
| mbed_official | 489:119543c9f674 | 1461 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
| mbed_official | 489:119543c9f674 | 1462 | } |
| mbed_official | 489:119543c9f674 | 1463 | } |
| mbed_official | 489:119543c9f674 | 1464 | else |
| mbed_official | 489:119543c9f674 | 1465 | { |
| mbed_official | 489:119543c9f674 | 1466 | /* Nb of 16-bit data to program can be decreased */ |
| mbed_official | 489:119543c9f674 | 1467 | pFlash.DataRemaining--; |
| mbed_official | 489:119543c9f674 | 1468 | |
| mbed_official | 489:119543c9f674 | 1469 | /* Check if there are still 16-bit data to program */ |
| mbed_official | 489:119543c9f674 | 1470 | if(pFlash.DataRemaining != 0) |
| mbed_official | 489:119543c9f674 | 1471 | { |
| mbed_official | 489:119543c9f674 | 1472 | /* Increment address to 16-bit */ |
| mbed_official | 489:119543c9f674 | 1473 | pFlash.Address += 2; |
| mbed_official | 489:119543c9f674 | 1474 | addresstmp = pFlash.Address; |
| mbed_official | 489:119543c9f674 | 1475 | |
| mbed_official | 489:119543c9f674 | 1476 | /* Shift to have next 16-bit data */ |
| mbed_official | 489:119543c9f674 | 1477 | pFlash.Data = (pFlash.Data >> 16); |
| mbed_official | 489:119543c9f674 | 1478 | |
| mbed_official | 489:119543c9f674 | 1479 | /* Operation is completed, disable the PG Bit */ |
| mbed_official | 489:119543c9f674 | 1480 | CLEAR_BIT(FLASH->CR2, FLASH_CR2_PG); |
| mbed_official | 489:119543c9f674 | 1481 | |
| mbed_official | 489:119543c9f674 | 1482 | /*Program halfword (16-bit) at a specified address.*/ |
| mbed_official | 489:119543c9f674 | 1483 | FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data); |
| mbed_official | 489:119543c9f674 | 1484 | } |
| mbed_official | 489:119543c9f674 | 1485 | else |
| mbed_official | 489:119543c9f674 | 1486 | { |
| mbed_official | 489:119543c9f674 | 1487 | /*Program ended. Return the selected address*/ |
| mbed_official | 489:119543c9f674 | 1488 | /* FLASH EOP interrupt user callback */ |
| mbed_official | 489:119543c9f674 | 1489 | if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD) |
| mbed_official | 489:119543c9f674 | 1490 | { |
| mbed_official | 489:119543c9f674 | 1491 | HAL_FLASH_EndOfOperationCallback(pFlash.Address); |
| mbed_official | 489:119543c9f674 | 1492 | } |
| mbed_official | 489:119543c9f674 | 1493 | else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD) |
| mbed_official | 489:119543c9f674 | 1494 | { |
| mbed_official | 489:119543c9f674 | 1495 | HAL_FLASH_EndOfOperationCallback(pFlash.Address-2); |
| mbed_official | 489:119543c9f674 | 1496 | } |
| mbed_official | 489:119543c9f674 | 1497 | else |
| mbed_official | 489:119543c9f674 | 1498 | { |
| mbed_official | 489:119543c9f674 | 1499 | HAL_FLASH_EndOfOperationCallback(pFlash.Address-6); |
| mbed_official | 489:119543c9f674 | 1500 | } |
| mbed_official | 489:119543c9f674 | 1501 | |
| mbed_official | 489:119543c9f674 | 1502 | /* Reset Address and stop Program procedure*/ |
| mbed_official | 489:119543c9f674 | 1503 | pFlash.Address = 0xFFFFFFFF; |
| mbed_official | 489:119543c9f674 | 1504 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
| mbed_official | 489:119543c9f674 | 1505 | } |
| mbed_official | 489:119543c9f674 | 1506 | } |
| mbed_official | 489:119543c9f674 | 1507 | } |
| mbed_official | 489:119543c9f674 | 1508 | } |
| mbed_official | 489:119543c9f674 | 1509 | |
| mbed_official | 489:119543c9f674 | 1510 | if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE) |
| mbed_official | 489:119543c9f674 | 1511 | { |
| mbed_official | 489:119543c9f674 | 1512 | /* Operation is completed, disable the PG, PER and MER Bits for both bank */ |
| mbed_official | 489:119543c9f674 | 1513 | CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER)); |
| mbed_official | 489:119543c9f674 | 1514 | CLEAR_BIT(FLASH->CR2, (FLASH_CR2_PG | FLASH_CR2_PER | FLASH_CR2_MER)); |
| mbed_official | 489:119543c9f674 | 1515 | |
| mbed_official | 489:119543c9f674 | 1516 | /* Disable End of FLASH Operation and Error source interrupts for both banks */ |
| mbed_official | 489:119543c9f674 | 1517 | __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP_BANK1 | FLASH_IT_ERR_BANK1 | FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2); |
| mbed_official | 489:119543c9f674 | 1518 | |
| mbed_official | 489:119543c9f674 | 1519 | /* Process Unlocked */ |
| mbed_official | 489:119543c9f674 | 1520 | __HAL_UNLOCK(&pFlash); |
| mbed_official | 489:119543c9f674 | 1521 | } |
| mbed_official | 489:119543c9f674 | 1522 | } |
| mbed_official | 489:119543c9f674 | 1523 | /** |
| mbed_official | 489:119543c9f674 | 1524 | * @} |
| mbed_official | 489:119543c9f674 | 1525 | */ |
| mbed_official | 489:119543c9f674 | 1526 | |
| mbed_official | 489:119543c9f674 | 1527 | /** |
| mbed_official | 489:119543c9f674 | 1528 | * @} |
| mbed_official | 489:119543c9f674 | 1529 | */ |
| mbed_official | 489:119543c9f674 | 1530 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 1531 | |
| mbed_official | 489:119543c9f674 | 1532 | /** @addtogroup FLASH_Private_Functions |
| mbed_official | 489:119543c9f674 | 1533 | * @{ |
| mbed_official | 489:119543c9f674 | 1534 | */ |
| mbed_official | 489:119543c9f674 | 1535 | |
| mbed_official | 489:119543c9f674 | 1536 | /** |
| mbed_official | 489:119543c9f674 | 1537 | * @brief Program a half-word (16-bit) at a specified address. |
| mbed_official | 489:119543c9f674 | 1538 | * @param Address: specifies the address to be programmed. |
| mbed_official | 489:119543c9f674 | 1539 | * @param Data: specifies the data to be programmed. |
| mbed_official | 489:119543c9f674 | 1540 | * @retval None |
| mbed_official | 489:119543c9f674 | 1541 | */ |
| mbed_official | 489:119543c9f674 | 1542 | void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data) |
| mbed_official | 489:119543c9f674 | 1543 | { |
| mbed_official | 489:119543c9f674 | 1544 | /* Clean the error context */ |
| mbed_official | 489:119543c9f674 | 1545 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
| mbed_official | 489:119543c9f674 | 1546 | |
| mbed_official | 489:119543c9f674 | 1547 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 1548 | if(Address <= FLASH_BANK1_END) |
| mbed_official | 489:119543c9f674 | 1549 | { |
| mbed_official | 489:119543c9f674 | 1550 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 1551 | /* Proceed to program the new data */ |
| mbed_official | 489:119543c9f674 | 1552 | SET_BIT(FLASH->CR, FLASH_CR_PG); |
| mbed_official | 489:119543c9f674 | 1553 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 1554 | } |
| mbed_official | 489:119543c9f674 | 1555 | else |
| mbed_official | 489:119543c9f674 | 1556 | { |
| mbed_official | 489:119543c9f674 | 1557 | /* Proceed to program the new data */ |
| mbed_official | 489:119543c9f674 | 1558 | SET_BIT(FLASH->CR2, FLASH_CR2_PG); |
| mbed_official | 489:119543c9f674 | 1559 | } |
| mbed_official | 489:119543c9f674 | 1560 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 1561 | |
| mbed_official | 489:119543c9f674 | 1562 | /* Write data in the address */ |
| mbed_official | 489:119543c9f674 | 1563 | *(__IO uint16_t*)Address = Data; |
| mbed_official | 489:119543c9f674 | 1564 | } |
| mbed_official | 489:119543c9f674 | 1565 | |
| mbed_official | 489:119543c9f674 | 1566 | /** |
| mbed_official | 489:119543c9f674 | 1567 | * @brief Set the specific FLASH error flag. |
| mbed_official | 489:119543c9f674 | 1568 | * @retval None |
| mbed_official | 489:119543c9f674 | 1569 | */ |
| mbed_official | 489:119543c9f674 | 1570 | void FLASH_SetErrorCode(void) |
| mbed_official | 489:119543c9f674 | 1571 | { |
| mbed_official | 489:119543c9f674 | 1572 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 1573 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2)) |
| mbed_official | 489:119543c9f674 | 1574 | #else |
| mbed_official | 489:119543c9f674 | 1575 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR)) |
| mbed_official | 489:119543c9f674 | 1576 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 1577 | { |
| mbed_official | 489:119543c9f674 | 1578 | pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP; |
| mbed_official | 489:119543c9f674 | 1579 | } |
| mbed_official | 489:119543c9f674 | 1580 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 1581 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)) |
| mbed_official | 489:119543c9f674 | 1582 | #else |
| mbed_official | 489:119543c9f674 | 1583 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR)) |
| mbed_official | 489:119543c9f674 | 1584 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 1585 | { |
| mbed_official | 489:119543c9f674 | 1586 | pFlash.ErrorCode |= HAL_FLASH_ERROR_PROG; |
| mbed_official | 489:119543c9f674 | 1587 | } |
| mbed_official | 489:119543c9f674 | 1588 | |
| mbed_official | 489:119543c9f674 | 1589 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR)) |
| mbed_official | 489:119543c9f674 | 1590 | { |
| mbed_official | 489:119543c9f674 | 1591 | pFlash.ErrorCode |= HAL_FLASH_ERROR_OPTV; |
| mbed_official | 489:119543c9f674 | 1592 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR); |
| mbed_official | 489:119543c9f674 | 1593 | } |
| mbed_official | 489:119543c9f674 | 1594 | |
| mbed_official | 489:119543c9f674 | 1595 | /* Clear FLASH error pending bits */ |
| mbed_official | 489:119543c9f674 | 1596 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 1597 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR | FLASH_FLAG_WRPERR_BANK2 | FLASH_FLAG_PGERR | FLASH_FLAG_PGERR_BANK2); |
| mbed_official | 489:119543c9f674 | 1598 | #else |
| mbed_official | 489:119543c9f674 | 1599 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR); |
| mbed_official | 489:119543c9f674 | 1600 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 1601 | } |
| mbed_official | 489:119543c9f674 | 1602 | |
| mbed_official | 489:119543c9f674 | 1603 | /** |
| mbed_official | 489:119543c9f674 | 1604 | * @brief Erase the specified FLASH memory page |
| mbed_official | 489:119543c9f674 | 1605 | * @param PageAddress: FLASH page to erase |
| mbed_official | 489:119543c9f674 | 1606 | * The value of this parameter depend on device used within the same series |
| mbed_official | 489:119543c9f674 | 1607 | * |
| mbed_official | 489:119543c9f674 | 1608 | * @retval None |
| mbed_official | 489:119543c9f674 | 1609 | */ |
| mbed_official | 489:119543c9f674 | 1610 | void FLASH_PageErase(uint32_t PageAddress) |
| mbed_official | 489:119543c9f674 | 1611 | { |
| mbed_official | 489:119543c9f674 | 1612 | /* Clean the error context */ |
| mbed_official | 489:119543c9f674 | 1613 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
| mbed_official | 489:119543c9f674 | 1614 | |
| mbed_official | 489:119543c9f674 | 1615 | #if defined(STM32F101xG) || defined(STM32F103xG) |
| mbed_official | 489:119543c9f674 | 1616 | if(PageAddress > FLASH_BANK1_END) |
| mbed_official | 489:119543c9f674 | 1617 | { |
| mbed_official | 489:119543c9f674 | 1618 | /* Proceed to erase the page */ |
| mbed_official | 489:119543c9f674 | 1619 | SET_BIT(FLASH->CR2, FLASH_CR2_PER); |
| mbed_official | 489:119543c9f674 | 1620 | WRITE_REG(FLASH->AR2, PageAddress); |
| mbed_official | 489:119543c9f674 | 1621 | SET_BIT(FLASH->CR2, FLASH_CR2_STRT); |
| mbed_official | 489:119543c9f674 | 1622 | } |
| mbed_official | 489:119543c9f674 | 1623 | else |
| mbed_official | 489:119543c9f674 | 1624 | #endif /* STM32F101xG || STM32F103xG */ |
| mbed_official | 489:119543c9f674 | 1625 | { |
| mbed_official | 489:119543c9f674 | 1626 | /* Proceed to erase the page */ |
| mbed_official | 489:119543c9f674 | 1627 | SET_BIT(FLASH->CR, FLASH_CR_PER); |
| mbed_official | 489:119543c9f674 | 1628 | WRITE_REG(FLASH->AR, PageAddress); |
| mbed_official | 489:119543c9f674 | 1629 | SET_BIT(FLASH->CR, FLASH_CR_STRT); |
| mbed_official | 489:119543c9f674 | 1630 | } |
| mbed_official | 489:119543c9f674 | 1631 | } |
| mbed_official | 489:119543c9f674 | 1632 | |
| mbed_official | 489:119543c9f674 | 1633 | /** |
| mbed_official | 489:119543c9f674 | 1634 | * @} |
| mbed_official | 489:119543c9f674 | 1635 | */ |
| mbed_official | 489:119543c9f674 | 1636 | |
| mbed_official | 489:119543c9f674 | 1637 | /** |
| mbed_official | 489:119543c9f674 | 1638 | * @} |
| mbed_official | 489:119543c9f674 | 1639 | */ |
| mbed_official | 489:119543c9f674 | 1640 | |
| mbed_official | 489:119543c9f674 | 1641 | /** |
| mbed_official | 489:119543c9f674 | 1642 | * @} |
| mbed_official | 489:119543c9f674 | 1643 | */ |
| mbed_official | 489:119543c9f674 | 1644 | |
| mbed_official | 489:119543c9f674 | 1645 | #endif /* HAL_FLASH_MODULE_ENABLED */ |
| mbed_official | 489:119543c9f674 | 1646 | /** |
| mbed_official | 489:119543c9f674 | 1647 | * @} |
| mbed_official | 489:119543c9f674 | 1648 | */ |
| mbed_official | 489:119543c9f674 | 1649 | |
| mbed_official | 489:119543c9f674 | 1650 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |

