mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32F7/stm32f7xx_hal_flash_ex.c@637:ed69428d4850, 2015-12-22 (annotated)
- Committer:
- jaerts
- Date:
- Tue Dec 22 13:22:16 2015 +0000
- Revision:
- 637:ed69428d4850
- Parent:
- 610:813dcc80987e
Add very shady LPC1768 CAN Filter implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 573:ad23fe03a082 | 1 | /** |
mbed_official | 573:ad23fe03a082 | 2 | ****************************************************************************** |
mbed_official | 573:ad23fe03a082 | 3 | * @file stm32f7xx_hal_flash_ex.c |
mbed_official | 573:ad23fe03a082 | 4 | * @author MCD Application Team |
mbed_official | 610:813dcc80987e | 5 | * @version V1.0.1 |
mbed_official | 610:813dcc80987e | 6 | * @date 25-June-2015 |
mbed_official | 573:ad23fe03a082 | 7 | * @brief Extended FLASH HAL module driver. |
mbed_official | 573:ad23fe03a082 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 573:ad23fe03a082 | 9 | * functionalities of the FLASH extension peripheral: |
mbed_official | 573:ad23fe03a082 | 10 | * + Extended programming operations functions |
mbed_official | 573:ad23fe03a082 | 11 | * |
mbed_official | 573:ad23fe03a082 | 12 | @verbatim |
mbed_official | 573:ad23fe03a082 | 13 | ============================================================================== |
mbed_official | 573:ad23fe03a082 | 14 | ##### Flash Extension features ##### |
mbed_official | 573:ad23fe03a082 | 15 | ============================================================================== |
mbed_official | 573:ad23fe03a082 | 16 | |
mbed_official | 573:ad23fe03a082 | 17 | [..] Comparing to other previous devices, the FLASH interface for STM32F727xx/437xx and |
mbed_official | 573:ad23fe03a082 | 18 | devices contains the following additional features |
mbed_official | 573:ad23fe03a082 | 19 | |
mbed_official | 573:ad23fe03a082 | 20 | (+) Capacity up to 2 Mbyte with dual bank architecture supporting read-while-write |
mbed_official | 573:ad23fe03a082 | 21 | capability (RWW) |
mbed_official | 573:ad23fe03a082 | 22 | (+) Dual bank memory organization |
mbed_official | 573:ad23fe03a082 | 23 | (+) PCROP protection for all banks |
mbed_official | 573:ad23fe03a082 | 24 | |
mbed_official | 573:ad23fe03a082 | 25 | ##### How to use this driver ##### |
mbed_official | 573:ad23fe03a082 | 26 | ============================================================================== |
mbed_official | 573:ad23fe03a082 | 27 | [..] This driver provides functions to configure and program the FLASH memory |
mbed_official | 573:ad23fe03a082 | 28 | of all STM32F7xx devices. It includes |
mbed_official | 573:ad23fe03a082 | 29 | (#) FLASH Memory Erase functions: |
mbed_official | 573:ad23fe03a082 | 30 | (++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and |
mbed_official | 573:ad23fe03a082 | 31 | HAL_FLASH_Lock() functions |
mbed_official | 573:ad23fe03a082 | 32 | (++) Erase function: Erase sector, erase all sectors |
mbed_official | 573:ad23fe03a082 | 33 | (++) There are two modes of erase : |
mbed_official | 573:ad23fe03a082 | 34 | (+++) Polling Mode using HAL_FLASHEx_Erase() |
mbed_official | 573:ad23fe03a082 | 35 | (+++) Interrupt Mode using HAL_FLASHEx_Erase_IT() |
mbed_official | 573:ad23fe03a082 | 36 | |
mbed_official | 573:ad23fe03a082 | 37 | (#) Option Bytes Programming functions: Use HAL_FLASHEx_OBProgram() to : |
mbed_official | 573:ad23fe03a082 | 38 | (++) Set/Reset the write protection |
mbed_official | 573:ad23fe03a082 | 39 | (++) Set the Read protection Level |
mbed_official | 573:ad23fe03a082 | 40 | (++) Set the BOR level |
mbed_official | 573:ad23fe03a082 | 41 | (++) Program the user Option Bytes |
mbed_official | 573:ad23fe03a082 | 42 | (#) Advanced Option Bytes Programming functions: Use HAL_FLASHEx_AdvOBProgram() to : |
mbed_official | 573:ad23fe03a082 | 43 | (++) Extended space (bank 2) erase function |
mbed_official | 573:ad23fe03a082 | 44 | (++) Full FLASH space (2 Mo) erase (bank 1 and bank 2) |
mbed_official | 573:ad23fe03a082 | 45 | (++) Dual Boot activation |
mbed_official | 573:ad23fe03a082 | 46 | (++) Write protection configuration for bank 2 |
mbed_official | 573:ad23fe03a082 | 47 | (++) PCROP protection configuration and control for both banks |
mbed_official | 573:ad23fe03a082 | 48 | |
mbed_official | 573:ad23fe03a082 | 49 | @endverbatim |
mbed_official | 573:ad23fe03a082 | 50 | ****************************************************************************** |
mbed_official | 573:ad23fe03a082 | 51 | * @attention |
mbed_official | 573:ad23fe03a082 | 52 | * |
mbed_official | 573:ad23fe03a082 | 53 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
mbed_official | 573:ad23fe03a082 | 54 | * |
mbed_official | 573:ad23fe03a082 | 55 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 573:ad23fe03a082 | 56 | * are permitted provided that the following conditions are met: |
mbed_official | 573:ad23fe03a082 | 57 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 573:ad23fe03a082 | 58 | * this list of conditions and the following disclaimer. |
mbed_official | 573:ad23fe03a082 | 59 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 573:ad23fe03a082 | 60 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 573:ad23fe03a082 | 61 | * and/or other materials provided with the distribution. |
mbed_official | 573:ad23fe03a082 | 62 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 573:ad23fe03a082 | 63 | * may be used to endorse or promote products derived from this software |
mbed_official | 573:ad23fe03a082 | 64 | * without specific prior written permission. |
mbed_official | 573:ad23fe03a082 | 65 | * |
mbed_official | 573:ad23fe03a082 | 66 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 573:ad23fe03a082 | 67 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 573:ad23fe03a082 | 68 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 573:ad23fe03a082 | 69 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 573:ad23fe03a082 | 70 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 573:ad23fe03a082 | 71 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 573:ad23fe03a082 | 72 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 573:ad23fe03a082 | 73 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 573:ad23fe03a082 | 74 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 573:ad23fe03a082 | 75 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 573:ad23fe03a082 | 76 | * |
mbed_official | 573:ad23fe03a082 | 77 | ****************************************************************************** |
mbed_official | 573:ad23fe03a082 | 78 | */ |
mbed_official | 573:ad23fe03a082 | 79 | |
mbed_official | 573:ad23fe03a082 | 80 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 81 | #include "stm32f7xx_hal.h" |
mbed_official | 573:ad23fe03a082 | 82 | |
mbed_official | 573:ad23fe03a082 | 83 | /** @addtogroup STM32F7xx_HAL_Driver |
mbed_official | 573:ad23fe03a082 | 84 | * @{ |
mbed_official | 573:ad23fe03a082 | 85 | */ |
mbed_official | 573:ad23fe03a082 | 86 | |
mbed_official | 573:ad23fe03a082 | 87 | /** @defgroup FLASHEx FLASHEx |
mbed_official | 573:ad23fe03a082 | 88 | * @brief FLASH HAL Extension module driver |
mbed_official | 573:ad23fe03a082 | 89 | * @{ |
mbed_official | 573:ad23fe03a082 | 90 | */ |
mbed_official | 573:ad23fe03a082 | 91 | |
mbed_official | 573:ad23fe03a082 | 92 | #ifdef HAL_FLASH_MODULE_ENABLED |
mbed_official | 573:ad23fe03a082 | 93 | |
mbed_official | 573:ad23fe03a082 | 94 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 95 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 96 | /** @addtogroup FLASHEx_Private_Constants |
mbed_official | 573:ad23fe03a082 | 97 | * @{ |
mbed_official | 573:ad23fe03a082 | 98 | */ |
mbed_official | 573:ad23fe03a082 | 99 | #define SECTOR_MASK ((uint32_t)0xFFFFFF07) |
mbed_official | 573:ad23fe03a082 | 100 | #define FLASH_TIMEOUT_VALUE ((uint32_t)50000)/* 50 s */ |
mbed_official | 573:ad23fe03a082 | 101 | /** |
mbed_official | 573:ad23fe03a082 | 102 | * @} |
mbed_official | 573:ad23fe03a082 | 103 | */ |
mbed_official | 573:ad23fe03a082 | 104 | |
mbed_official | 573:ad23fe03a082 | 105 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 106 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 107 | /** @addtogroup FLASHEx_Private_Variables |
mbed_official | 573:ad23fe03a082 | 108 | * @{ |
mbed_official | 573:ad23fe03a082 | 109 | */ |
mbed_official | 573:ad23fe03a082 | 110 | extern FLASH_ProcessTypeDef pFlash; |
mbed_official | 573:ad23fe03a082 | 111 | /** |
mbed_official | 573:ad23fe03a082 | 112 | * @} |
mbed_official | 573:ad23fe03a082 | 113 | */ |
mbed_official | 573:ad23fe03a082 | 114 | |
mbed_official | 573:ad23fe03a082 | 115 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 116 | /** @addtogroup FLASHEx_Private_Functions |
mbed_official | 573:ad23fe03a082 | 117 | * @{ |
mbed_official | 573:ad23fe03a082 | 118 | */ |
mbed_official | 573:ad23fe03a082 | 119 | /* Option bytes control */ |
mbed_official | 573:ad23fe03a082 | 120 | static void FLASH_MassErase(uint8_t VoltageRange); |
mbed_official | 573:ad23fe03a082 | 121 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector); |
mbed_official | 573:ad23fe03a082 | 122 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector); |
mbed_official | 573:ad23fe03a082 | 123 | static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint32_t Level); |
mbed_official | 573:ad23fe03a082 | 124 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint32_t Wwdg, uint32_t Iwdg, uint32_t Stop, uint32_t Stdby, uint32_t Iwdgstop, uint32_t Iwdgstdby); |
mbed_official | 573:ad23fe03a082 | 125 | static HAL_StatusTypeDef FLASH_OB_BOR_LevelConfig(uint8_t Level); |
mbed_official | 573:ad23fe03a082 | 126 | static HAL_StatusTypeDef FLASH_OB_BootAddressConfig(uint32_t BootOption, uint32_t Address); |
mbed_official | 573:ad23fe03a082 | 127 | static uint32_t FLASH_OB_GetUser(void); |
mbed_official | 573:ad23fe03a082 | 128 | static uint32_t FLASH_OB_GetWRP(void); |
mbed_official | 610:813dcc80987e | 129 | static uint8_t FLASH_OB_GetRDP(void); |
mbed_official | 573:ad23fe03a082 | 130 | static uint32_t FLASH_OB_GetBOR(void); |
mbed_official | 573:ad23fe03a082 | 131 | static uint32_t FLASH_OB_GetBootAddress(uint32_t BootOption); |
mbed_official | 573:ad23fe03a082 | 132 | |
mbed_official | 573:ad23fe03a082 | 133 | extern HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); |
mbed_official | 573:ad23fe03a082 | 134 | /** |
mbed_official | 573:ad23fe03a082 | 135 | * @} |
mbed_official | 573:ad23fe03a082 | 136 | */ |
mbed_official | 573:ad23fe03a082 | 137 | |
mbed_official | 573:ad23fe03a082 | 138 | /* Exported functions --------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 139 | /** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions |
mbed_official | 573:ad23fe03a082 | 140 | * @{ |
mbed_official | 573:ad23fe03a082 | 141 | */ |
mbed_official | 573:ad23fe03a082 | 142 | |
mbed_official | 573:ad23fe03a082 | 143 | /** @defgroup FLASHEx_Exported_Functions_Group1 Extended IO operation functions |
mbed_official | 573:ad23fe03a082 | 144 | * @brief Extended IO operation functions |
mbed_official | 573:ad23fe03a082 | 145 | * |
mbed_official | 573:ad23fe03a082 | 146 | @verbatim |
mbed_official | 573:ad23fe03a082 | 147 | =============================================================================== |
mbed_official | 573:ad23fe03a082 | 148 | ##### Extended programming operation functions ##### |
mbed_official | 573:ad23fe03a082 | 149 | =============================================================================== |
mbed_official | 573:ad23fe03a082 | 150 | [..] |
mbed_official | 573:ad23fe03a082 | 151 | This subsection provides a set of functions allowing to manage the Extension FLASH |
mbed_official | 573:ad23fe03a082 | 152 | programming operations Operations. |
mbed_official | 573:ad23fe03a082 | 153 | |
mbed_official | 573:ad23fe03a082 | 154 | @endverbatim |
mbed_official | 573:ad23fe03a082 | 155 | * @{ |
mbed_official | 573:ad23fe03a082 | 156 | */ |
mbed_official | 573:ad23fe03a082 | 157 | /** |
mbed_official | 573:ad23fe03a082 | 158 | * @brief Perform a mass erase or erase the specified FLASH memory sectors |
mbed_official | 573:ad23fe03a082 | 159 | * @param[in] pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
mbed_official | 573:ad23fe03a082 | 160 | * contains the configuration information for the erasing. |
mbed_official | 573:ad23fe03a082 | 161 | * |
mbed_official | 573:ad23fe03a082 | 162 | * @param[out] SectorError: pointer to variable that |
mbed_official | 573:ad23fe03a082 | 163 | * contains the configuration information on faulty sector in case of error |
mbed_official | 573:ad23fe03a082 | 164 | * (0xFFFFFFFF means that all the sectors have been correctly erased) |
mbed_official | 573:ad23fe03a082 | 165 | * |
mbed_official | 573:ad23fe03a082 | 166 | * @retval HAL Status |
mbed_official | 573:ad23fe03a082 | 167 | */ |
mbed_official | 573:ad23fe03a082 | 168 | HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError) |
mbed_official | 573:ad23fe03a082 | 169 | { |
mbed_official | 573:ad23fe03a082 | 170 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 171 | uint32_t index = 0; |
mbed_official | 573:ad23fe03a082 | 172 | |
mbed_official | 573:ad23fe03a082 | 173 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 174 | __HAL_LOCK(&pFlash); |
mbed_official | 573:ad23fe03a082 | 175 | |
mbed_official | 573:ad23fe03a082 | 176 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 177 | assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
mbed_official | 573:ad23fe03a082 | 178 | |
mbed_official | 573:ad23fe03a082 | 179 | /* Wait for last operation to be completed */ |
mbed_official | 573:ad23fe03a082 | 180 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 573:ad23fe03a082 | 181 | |
mbed_official | 573:ad23fe03a082 | 182 | if(status == HAL_OK) |
mbed_official | 573:ad23fe03a082 | 183 | { |
mbed_official | 573:ad23fe03a082 | 184 | /*Initialization of SectorError variable*/ |
mbed_official | 573:ad23fe03a082 | 185 | *SectorError = 0xFFFFFFFF; |
mbed_official | 573:ad23fe03a082 | 186 | |
mbed_official | 573:ad23fe03a082 | 187 | if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) |
mbed_official | 573:ad23fe03a082 | 188 | { |
mbed_official | 573:ad23fe03a082 | 189 | /*Mass erase to be done*/ |
mbed_official | 573:ad23fe03a082 | 190 | FLASH_MassErase((uint8_t) pEraseInit->VoltageRange); |
mbed_official | 573:ad23fe03a082 | 191 | |
mbed_official | 573:ad23fe03a082 | 192 | /* Wait for last operation to be completed */ |
mbed_official | 573:ad23fe03a082 | 193 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 573:ad23fe03a082 | 194 | |
mbed_official | 573:ad23fe03a082 | 195 | /* if the erase operation is completed, disable the MER Bit */ |
mbed_official | 573:ad23fe03a082 | 196 | FLASH->CR &= (~FLASH_MER_BIT); |
mbed_official | 573:ad23fe03a082 | 197 | } |
mbed_official | 573:ad23fe03a082 | 198 | else |
mbed_official | 573:ad23fe03a082 | 199 | { |
mbed_official | 573:ad23fe03a082 | 200 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 201 | assert_param(IS_FLASH_NBSECTORS(pEraseInit->NbSectors + pEraseInit->Sector)); |
mbed_official | 573:ad23fe03a082 | 202 | |
mbed_official | 573:ad23fe03a082 | 203 | /* Erase by sector by sector to be done*/ |
mbed_official | 573:ad23fe03a082 | 204 | for(index = pEraseInit->Sector; index < (pEraseInit->NbSectors + pEraseInit->Sector); index++) |
mbed_official | 573:ad23fe03a082 | 205 | { |
mbed_official | 573:ad23fe03a082 | 206 | FLASH_Erase_Sector(index, (uint8_t) pEraseInit->VoltageRange); |
mbed_official | 573:ad23fe03a082 | 207 | |
mbed_official | 573:ad23fe03a082 | 208 | /* Wait for last operation to be completed */ |
mbed_official | 573:ad23fe03a082 | 209 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 573:ad23fe03a082 | 210 | |
mbed_official | 573:ad23fe03a082 | 211 | /* If the erase operation is completed, disable the SER Bit */ |
mbed_official | 573:ad23fe03a082 | 212 | FLASH->CR &= (~FLASH_CR_SER); |
mbed_official | 573:ad23fe03a082 | 213 | FLASH->CR &= SECTOR_MASK; |
mbed_official | 573:ad23fe03a082 | 214 | |
mbed_official | 573:ad23fe03a082 | 215 | if(status != HAL_OK) |
mbed_official | 573:ad23fe03a082 | 216 | { |
mbed_official | 573:ad23fe03a082 | 217 | /* In case of error, stop erase procedure and return the faulty sector*/ |
mbed_official | 573:ad23fe03a082 | 218 | *SectorError = index; |
mbed_official | 573:ad23fe03a082 | 219 | break; |
mbed_official | 573:ad23fe03a082 | 220 | } |
mbed_official | 573:ad23fe03a082 | 221 | } |
mbed_official | 573:ad23fe03a082 | 222 | } |
mbed_official | 573:ad23fe03a082 | 223 | } |
mbed_official | 573:ad23fe03a082 | 224 | |
mbed_official | 573:ad23fe03a082 | 225 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 226 | __HAL_UNLOCK(&pFlash); |
mbed_official | 573:ad23fe03a082 | 227 | |
mbed_official | 573:ad23fe03a082 | 228 | return status; |
mbed_official | 573:ad23fe03a082 | 229 | } |
mbed_official | 573:ad23fe03a082 | 230 | |
mbed_official | 573:ad23fe03a082 | 231 | /** |
mbed_official | 573:ad23fe03a082 | 232 | * @brief Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled |
mbed_official | 573:ad23fe03a082 | 233 | * @param pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
mbed_official | 573:ad23fe03a082 | 234 | * contains the configuration information for the erasing. |
mbed_official | 573:ad23fe03a082 | 235 | * |
mbed_official | 573:ad23fe03a082 | 236 | * @retval HAL Status |
mbed_official | 573:ad23fe03a082 | 237 | */ |
mbed_official | 573:ad23fe03a082 | 238 | HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) |
mbed_official | 573:ad23fe03a082 | 239 | { |
mbed_official | 573:ad23fe03a082 | 240 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 573:ad23fe03a082 | 241 | |
mbed_official | 573:ad23fe03a082 | 242 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 243 | __HAL_LOCK(&pFlash); |
mbed_official | 573:ad23fe03a082 | 244 | |
mbed_official | 573:ad23fe03a082 | 245 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 246 | assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
mbed_official | 573:ad23fe03a082 | 247 | |
mbed_official | 573:ad23fe03a082 | 248 | /* Enable End of FLASH Operation interrupt */ |
mbed_official | 573:ad23fe03a082 | 249 | __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP); |
mbed_official | 573:ad23fe03a082 | 250 | |
mbed_official | 573:ad23fe03a082 | 251 | /* Enable Error source interrupt */ |
mbed_official | 573:ad23fe03a082 | 252 | __HAL_FLASH_ENABLE_IT(FLASH_IT_ERR); |
mbed_official | 573:ad23fe03a082 | 253 | |
mbed_official | 573:ad23fe03a082 | 254 | /* Clear pending flags (if any) */ |
mbed_official | 573:ad23fe03a082 | 255 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |\ |
mbed_official | 573:ad23fe03a082 | 256 | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_ERSERR); |
mbed_official | 573:ad23fe03a082 | 257 | |
mbed_official | 573:ad23fe03a082 | 258 | if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) |
mbed_official | 573:ad23fe03a082 | 259 | { |
mbed_official | 573:ad23fe03a082 | 260 | /*Mass erase to be done*/ |
mbed_official | 573:ad23fe03a082 | 261 | pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE; |
mbed_official | 573:ad23fe03a082 | 262 | FLASH_MassErase((uint8_t) pEraseInit->VoltageRange); |
mbed_official | 573:ad23fe03a082 | 263 | } |
mbed_official | 573:ad23fe03a082 | 264 | else |
mbed_official | 573:ad23fe03a082 | 265 | { |
mbed_official | 573:ad23fe03a082 | 266 | /* Erase by sector to be done*/ |
mbed_official | 573:ad23fe03a082 | 267 | |
mbed_official | 573:ad23fe03a082 | 268 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 269 | assert_param(IS_FLASH_NBSECTORS(pEraseInit->NbSectors + pEraseInit->Sector)); |
mbed_official | 573:ad23fe03a082 | 270 | |
mbed_official | 573:ad23fe03a082 | 271 | pFlash.ProcedureOnGoing = FLASH_PROC_SECTERASE; |
mbed_official | 573:ad23fe03a082 | 272 | pFlash.NbSectorsToErase = pEraseInit->NbSectors; |
mbed_official | 573:ad23fe03a082 | 273 | pFlash.Sector = pEraseInit->Sector; |
mbed_official | 573:ad23fe03a082 | 274 | pFlash.VoltageForErase = (uint8_t)pEraseInit->VoltageRange; |
mbed_official | 573:ad23fe03a082 | 275 | |
mbed_official | 573:ad23fe03a082 | 276 | /*Erase 1st sector and wait for IT*/ |
mbed_official | 573:ad23fe03a082 | 277 | FLASH_Erase_Sector(pEraseInit->Sector, pEraseInit->VoltageRange); |
mbed_official | 573:ad23fe03a082 | 278 | } |
mbed_official | 573:ad23fe03a082 | 279 | |
mbed_official | 573:ad23fe03a082 | 280 | return status; |
mbed_official | 573:ad23fe03a082 | 281 | } |
mbed_official | 573:ad23fe03a082 | 282 | |
mbed_official | 573:ad23fe03a082 | 283 | /** |
mbed_official | 573:ad23fe03a082 | 284 | * @brief Program option bytes |
mbed_official | 573:ad23fe03a082 | 285 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that |
mbed_official | 573:ad23fe03a082 | 286 | * contains the configuration information for the programming. |
mbed_official | 573:ad23fe03a082 | 287 | * |
mbed_official | 573:ad23fe03a082 | 288 | * @retval HAL Status |
mbed_official | 573:ad23fe03a082 | 289 | */ |
mbed_official | 573:ad23fe03a082 | 290 | HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) |
mbed_official | 573:ad23fe03a082 | 291 | { |
mbed_official | 573:ad23fe03a082 | 292 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 293 | |
mbed_official | 573:ad23fe03a082 | 294 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 295 | __HAL_LOCK(&pFlash); |
mbed_official | 573:ad23fe03a082 | 296 | |
mbed_official | 573:ad23fe03a082 | 297 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 298 | assert_param(IS_OPTIONBYTE(pOBInit->OptionType)); |
mbed_official | 573:ad23fe03a082 | 299 | |
mbed_official | 573:ad23fe03a082 | 300 | /* Write protection configuration */ |
mbed_official | 573:ad23fe03a082 | 301 | if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP) |
mbed_official | 573:ad23fe03a082 | 302 | { |
mbed_official | 573:ad23fe03a082 | 303 | assert_param(IS_WRPSTATE(pOBInit->WRPState)); |
mbed_official | 573:ad23fe03a082 | 304 | if(pOBInit->WRPState == OB_WRPSTATE_ENABLE) |
mbed_official | 573:ad23fe03a082 | 305 | { |
mbed_official | 573:ad23fe03a082 | 306 | /*Enable of Write protection on the selected Sector*/ |
mbed_official | 573:ad23fe03a082 | 307 | status = FLASH_OB_EnableWRP(pOBInit->WRPSector); |
mbed_official | 573:ad23fe03a082 | 308 | } |
mbed_official | 573:ad23fe03a082 | 309 | else |
mbed_official | 573:ad23fe03a082 | 310 | { |
mbed_official | 573:ad23fe03a082 | 311 | /*Disable of Write protection on the selected Sector*/ |
mbed_official | 573:ad23fe03a082 | 312 | status = FLASH_OB_DisableWRP(pOBInit->WRPSector); |
mbed_official | 573:ad23fe03a082 | 313 | } |
mbed_official | 573:ad23fe03a082 | 314 | } |
mbed_official | 573:ad23fe03a082 | 315 | |
mbed_official | 573:ad23fe03a082 | 316 | /* Read protection configuration */ |
mbed_official | 573:ad23fe03a082 | 317 | if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) |
mbed_official | 573:ad23fe03a082 | 318 | { |
mbed_official | 573:ad23fe03a082 | 319 | status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel); |
mbed_official | 573:ad23fe03a082 | 320 | } |
mbed_official | 573:ad23fe03a082 | 321 | |
mbed_official | 573:ad23fe03a082 | 322 | /* USER configuration */ |
mbed_official | 573:ad23fe03a082 | 323 | if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) |
mbed_official | 573:ad23fe03a082 | 324 | { |
mbed_official | 573:ad23fe03a082 | 325 | status = FLASH_OB_UserConfig(pOBInit->USERConfig & OB_WWDG_SW, |
mbed_official | 573:ad23fe03a082 | 326 | pOBInit->USERConfig & OB_IWDG_SW, |
mbed_official | 573:ad23fe03a082 | 327 | pOBInit->USERConfig & OB_STOP_NO_RST, |
mbed_official | 573:ad23fe03a082 | 328 | pOBInit->USERConfig & OB_STDBY_NO_RST, |
mbed_official | 573:ad23fe03a082 | 329 | pOBInit->USERConfig & OB_IWDG_STOP_ACTIVE, |
mbed_official | 573:ad23fe03a082 | 330 | pOBInit->USERConfig & OB_IWDG_STDBY_ACTIVE); |
mbed_official | 573:ad23fe03a082 | 331 | } |
mbed_official | 573:ad23fe03a082 | 332 | |
mbed_official | 573:ad23fe03a082 | 333 | /* BOR Level configuration */ |
mbed_official | 573:ad23fe03a082 | 334 | if((pOBInit->OptionType & OPTIONBYTE_BOR) == OPTIONBYTE_BOR) |
mbed_official | 573:ad23fe03a082 | 335 | { |
mbed_official | 573:ad23fe03a082 | 336 | status = FLASH_OB_BOR_LevelConfig(pOBInit->BORLevel); |
mbed_official | 573:ad23fe03a082 | 337 | } |
mbed_official | 573:ad23fe03a082 | 338 | |
mbed_official | 573:ad23fe03a082 | 339 | /* Boot 0 Address configuration */ |
mbed_official | 573:ad23fe03a082 | 340 | if((pOBInit->OptionType & OPTIONBYTE_BOOTADDR_0) == OPTIONBYTE_BOOTADDR_0) |
mbed_official | 573:ad23fe03a082 | 341 | { |
mbed_official | 573:ad23fe03a082 | 342 | status = FLASH_OB_BootAddressConfig(OPTIONBYTE_BOOTADDR_0, pOBInit->BootAddr0); |
mbed_official | 573:ad23fe03a082 | 343 | } |
mbed_official | 573:ad23fe03a082 | 344 | |
mbed_official | 573:ad23fe03a082 | 345 | /* Boot 1 Address configuration */ |
mbed_official | 573:ad23fe03a082 | 346 | if((pOBInit->OptionType & OPTIONBYTE_BOOTADDR_1) == OPTIONBYTE_BOOTADDR_1) |
mbed_official | 573:ad23fe03a082 | 347 | { |
mbed_official | 573:ad23fe03a082 | 348 | status = FLASH_OB_BootAddressConfig(OPTIONBYTE_BOOTADDR_1, pOBInit->BootAddr1); |
mbed_official | 573:ad23fe03a082 | 349 | } |
mbed_official | 573:ad23fe03a082 | 350 | |
mbed_official | 573:ad23fe03a082 | 351 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 352 | __HAL_UNLOCK(&pFlash); |
mbed_official | 573:ad23fe03a082 | 353 | |
mbed_official | 573:ad23fe03a082 | 354 | return status; |
mbed_official | 573:ad23fe03a082 | 355 | } |
mbed_official | 573:ad23fe03a082 | 356 | |
mbed_official | 573:ad23fe03a082 | 357 | /** |
mbed_official | 573:ad23fe03a082 | 358 | * @brief Get the Option byte configuration |
mbed_official | 573:ad23fe03a082 | 359 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that |
mbed_official | 573:ad23fe03a082 | 360 | * contains the configuration information for the programming. |
mbed_official | 573:ad23fe03a082 | 361 | * |
mbed_official | 573:ad23fe03a082 | 362 | * @retval None |
mbed_official | 573:ad23fe03a082 | 363 | */ |
mbed_official | 573:ad23fe03a082 | 364 | void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) |
mbed_official | 573:ad23fe03a082 | 365 | { |
mbed_official | 573:ad23fe03a082 | 366 | pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER |\ |
mbed_official | 573:ad23fe03a082 | 367 | OPTIONBYTE_BOR | OPTIONBYTE_BOOTADDR_0 | OPTIONBYTE_BOOTADDR_1; |
mbed_official | 573:ad23fe03a082 | 368 | |
mbed_official | 573:ad23fe03a082 | 369 | /*Get WRP*/ |
mbed_official | 573:ad23fe03a082 | 370 | pOBInit->WRPSector = FLASH_OB_GetWRP(); |
mbed_official | 573:ad23fe03a082 | 371 | |
mbed_official | 573:ad23fe03a082 | 372 | /*Get RDP Level*/ |
mbed_official | 573:ad23fe03a082 | 373 | pOBInit->RDPLevel = FLASH_OB_GetRDP(); |
mbed_official | 573:ad23fe03a082 | 374 | |
mbed_official | 573:ad23fe03a082 | 375 | /*Get USER*/ |
mbed_official | 573:ad23fe03a082 | 376 | pOBInit->USERConfig = FLASH_OB_GetUser(); |
mbed_official | 573:ad23fe03a082 | 377 | |
mbed_official | 573:ad23fe03a082 | 378 | /*Get BOR Level*/ |
mbed_official | 573:ad23fe03a082 | 379 | pOBInit->BORLevel = FLASH_OB_GetBOR(); |
mbed_official | 573:ad23fe03a082 | 380 | |
mbed_official | 573:ad23fe03a082 | 381 | /*Get Boot Address when Boot pin = 0 */ |
mbed_official | 573:ad23fe03a082 | 382 | pOBInit->BootAddr0 = FLASH_OB_GetBootAddress(OPTIONBYTE_BOOTADDR_0); |
mbed_official | 573:ad23fe03a082 | 383 | |
mbed_official | 573:ad23fe03a082 | 384 | /*Get Boot Address when Boot pin = 1 */ |
mbed_official | 573:ad23fe03a082 | 385 | pOBInit->BootAddr1 = FLASH_OB_GetBootAddress(OPTIONBYTE_BOOTADDR_1); |
mbed_official | 573:ad23fe03a082 | 386 | } |
mbed_official | 573:ad23fe03a082 | 387 | |
mbed_official | 573:ad23fe03a082 | 388 | /** |
mbed_official | 573:ad23fe03a082 | 389 | * @} |
mbed_official | 573:ad23fe03a082 | 390 | */ |
mbed_official | 573:ad23fe03a082 | 391 | |
mbed_official | 573:ad23fe03a082 | 392 | /** |
mbed_official | 573:ad23fe03a082 | 393 | * @brief Full erase of FLASH memory sectors |
mbed_official | 573:ad23fe03a082 | 394 | * @param VoltageRange: The device voltage range which defines the erase parallelism. |
mbed_official | 573:ad23fe03a082 | 395 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 396 | * @arg VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V, |
mbed_official | 573:ad23fe03a082 | 397 | * the operation will be done by byte (8-bit) |
mbed_official | 573:ad23fe03a082 | 398 | * @arg VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V, |
mbed_official | 573:ad23fe03a082 | 399 | * the operation will be done by half word (16-bit) |
mbed_official | 573:ad23fe03a082 | 400 | * @arg VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V, |
mbed_official | 573:ad23fe03a082 | 401 | * the operation will be done by word (32-bit) |
mbed_official | 573:ad23fe03a082 | 402 | * @arg VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp, |
mbed_official | 573:ad23fe03a082 | 403 | * the operation will be done by double word (64-bit) |
mbed_official | 573:ad23fe03a082 | 404 | * |
mbed_official | 573:ad23fe03a082 | 405 | * @retval HAL Status |
mbed_official | 573:ad23fe03a082 | 406 | */ |
mbed_official | 573:ad23fe03a082 | 407 | static void FLASH_MassErase(uint8_t VoltageRange) |
mbed_official | 573:ad23fe03a082 | 408 | { |
mbed_official | 573:ad23fe03a082 | 409 | uint32_t tmp_psize = 0; |
mbed_official | 573:ad23fe03a082 | 410 | |
mbed_official | 573:ad23fe03a082 | 411 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 412 | assert_param(IS_VOLTAGERANGE(VoltageRange)); |
mbed_official | 573:ad23fe03a082 | 413 | |
mbed_official | 573:ad23fe03a082 | 414 | /* if the previous operation is completed, proceed to erase all sectors */ |
mbed_official | 573:ad23fe03a082 | 415 | FLASH->CR &= CR_PSIZE_MASK; |
mbed_official | 573:ad23fe03a082 | 416 | FLASH->CR |= tmp_psize; |
mbed_official | 573:ad23fe03a082 | 417 | FLASH->CR |= FLASH_CR_MER; |
mbed_official | 573:ad23fe03a082 | 418 | FLASH->CR |= FLASH_CR_STRT; |
mbed_official | 573:ad23fe03a082 | 419 | /* Data synchronous Barrier (DSB) Just after the write operation |
mbed_official | 573:ad23fe03a082 | 420 | This will force the CPU to respect the sequence of instruction (no optimization).*/ |
mbed_official | 573:ad23fe03a082 | 421 | __DSB(); |
mbed_official | 573:ad23fe03a082 | 422 | } |
mbed_official | 573:ad23fe03a082 | 423 | |
mbed_official | 573:ad23fe03a082 | 424 | /** |
mbed_official | 573:ad23fe03a082 | 425 | * @brief Erase the specified FLASH memory sector |
mbed_official | 573:ad23fe03a082 | 426 | * @param Sector: FLASH sector to erase |
mbed_official | 573:ad23fe03a082 | 427 | * The value of this parameter depend on device used within the same series |
mbed_official | 573:ad23fe03a082 | 428 | * @param VoltageRange: The device voltage range which defines the erase parallelism. |
mbed_official | 573:ad23fe03a082 | 429 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 430 | * @arg FLASH_VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V, |
mbed_official | 573:ad23fe03a082 | 431 | * the operation will be done by byte (8-bit) |
mbed_official | 573:ad23fe03a082 | 432 | * @arg FLASH_VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V, |
mbed_official | 573:ad23fe03a082 | 433 | * the operation will be done by half word (16-bit) |
mbed_official | 573:ad23fe03a082 | 434 | * @arg FLASH_VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V, |
mbed_official | 573:ad23fe03a082 | 435 | * the operation will be done by word (32-bit) |
mbed_official | 573:ad23fe03a082 | 436 | * @arg FLASH_VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp, |
mbed_official | 573:ad23fe03a082 | 437 | * the operation will be done by double word (64-bit) |
mbed_official | 573:ad23fe03a082 | 438 | * |
mbed_official | 573:ad23fe03a082 | 439 | * @retval None |
mbed_official | 573:ad23fe03a082 | 440 | */ |
mbed_official | 573:ad23fe03a082 | 441 | void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange) |
mbed_official | 573:ad23fe03a082 | 442 | { |
mbed_official | 573:ad23fe03a082 | 443 | uint32_t tmp_psize = 0; |
mbed_official | 573:ad23fe03a082 | 444 | |
mbed_official | 573:ad23fe03a082 | 445 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 446 | assert_param(IS_FLASH_SECTOR(Sector)); |
mbed_official | 573:ad23fe03a082 | 447 | assert_param(IS_VOLTAGERANGE(VoltageRange)); |
mbed_official | 573:ad23fe03a082 | 448 | |
mbed_official | 573:ad23fe03a082 | 449 | if(VoltageRange == FLASH_VOLTAGE_RANGE_1) |
mbed_official | 573:ad23fe03a082 | 450 | { |
mbed_official | 573:ad23fe03a082 | 451 | tmp_psize = FLASH_PSIZE_BYTE; |
mbed_official | 573:ad23fe03a082 | 452 | } |
mbed_official | 573:ad23fe03a082 | 453 | else if(VoltageRange == FLASH_VOLTAGE_RANGE_2) |
mbed_official | 573:ad23fe03a082 | 454 | { |
mbed_official | 573:ad23fe03a082 | 455 | tmp_psize = FLASH_PSIZE_HALF_WORD; |
mbed_official | 573:ad23fe03a082 | 456 | } |
mbed_official | 573:ad23fe03a082 | 457 | else if(VoltageRange == FLASH_VOLTAGE_RANGE_3) |
mbed_official | 573:ad23fe03a082 | 458 | { |
mbed_official | 573:ad23fe03a082 | 459 | tmp_psize = FLASH_PSIZE_WORD; |
mbed_official | 573:ad23fe03a082 | 460 | } |
mbed_official | 573:ad23fe03a082 | 461 | else |
mbed_official | 573:ad23fe03a082 | 462 | { |
mbed_official | 573:ad23fe03a082 | 463 | tmp_psize = FLASH_PSIZE_DOUBLE_WORD; |
mbed_official | 573:ad23fe03a082 | 464 | } |
mbed_official | 573:ad23fe03a082 | 465 | |
mbed_official | 573:ad23fe03a082 | 466 | /* If the previous operation is completed, proceed to erase the sector */ |
mbed_official | 573:ad23fe03a082 | 467 | FLASH->CR &= CR_PSIZE_MASK; |
mbed_official | 573:ad23fe03a082 | 468 | FLASH->CR |= tmp_psize; |
mbed_official | 573:ad23fe03a082 | 469 | FLASH->CR &= SECTOR_MASK; |
mbed_official | 573:ad23fe03a082 | 470 | FLASH->CR |= FLASH_CR_SER | (Sector << POSITION_VAL(FLASH_CR_SNB)); |
mbed_official | 573:ad23fe03a082 | 471 | FLASH->CR |= FLASH_CR_STRT; |
mbed_official | 573:ad23fe03a082 | 472 | |
mbed_official | 573:ad23fe03a082 | 473 | /* Data synchronous Barrier (DSB) Just after the write operation |
mbed_official | 573:ad23fe03a082 | 474 | This will force the CPU to respect the sequence of instruction (no optimization).*/ |
mbed_official | 573:ad23fe03a082 | 475 | __DSB(); |
mbed_official | 573:ad23fe03a082 | 476 | } |
mbed_official | 573:ad23fe03a082 | 477 | |
mbed_official | 573:ad23fe03a082 | 478 | /** |
mbed_official | 573:ad23fe03a082 | 479 | * @brief Enable the write protection of the desired bank1 or bank 2 sectors |
mbed_official | 573:ad23fe03a082 | 480 | * |
mbed_official | 573:ad23fe03a082 | 481 | * @note When the memory read protection level is selected (RDP level = 1), |
mbed_official | 573:ad23fe03a082 | 482 | * it is not possible to program or erase the flash sector i if CortexM4 |
mbed_official | 573:ad23fe03a082 | 483 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
mbed_official | 573:ad23fe03a082 | 484 | * @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1). |
mbed_official | 573:ad23fe03a082 | 485 | * |
mbed_official | 573:ad23fe03a082 | 486 | * @param WRPSector: specifies the sector(s) to be write protected. |
mbed_official | 573:ad23fe03a082 | 487 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 488 | * @arg WRPSector: A value between OB_WRP_SECTOR_0 and OB_WRP_SECTOR_7 |
mbed_official | 573:ad23fe03a082 | 489 | * @arg OB_WRP_SECTOR_All |
mbed_official | 573:ad23fe03a082 | 490 | * |
mbed_official | 573:ad23fe03a082 | 491 | * @retval HAL FLASH State |
mbed_official | 573:ad23fe03a082 | 492 | */ |
mbed_official | 573:ad23fe03a082 | 493 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector) |
mbed_official | 573:ad23fe03a082 | 494 | { |
mbed_official | 573:ad23fe03a082 | 495 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 573:ad23fe03a082 | 496 | |
mbed_official | 573:ad23fe03a082 | 497 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 498 | assert_param(IS_OB_WRP_SECTOR(WRPSector)); |
mbed_official | 573:ad23fe03a082 | 499 | |
mbed_official | 573:ad23fe03a082 | 500 | /* Wait for last operation to be completed */ |
mbed_official | 573:ad23fe03a082 | 501 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 573:ad23fe03a082 | 502 | |
mbed_official | 573:ad23fe03a082 | 503 | if(status == HAL_OK) |
mbed_official | 573:ad23fe03a082 | 504 | { |
mbed_official | 573:ad23fe03a082 | 505 | /*Write protection enabled on sectors */ |
mbed_official | 573:ad23fe03a082 | 506 | FLASH->OPTCR &= (~WRPSector); |
mbed_official | 573:ad23fe03a082 | 507 | } |
mbed_official | 573:ad23fe03a082 | 508 | |
mbed_official | 573:ad23fe03a082 | 509 | return status; |
mbed_official | 573:ad23fe03a082 | 510 | } |
mbed_official | 573:ad23fe03a082 | 511 | |
mbed_official | 573:ad23fe03a082 | 512 | /** |
mbed_official | 573:ad23fe03a082 | 513 | * @brief Disable the write protection of the desired bank1 or bank 2 sectors |
mbed_official | 573:ad23fe03a082 | 514 | * |
mbed_official | 573:ad23fe03a082 | 515 | * @note When the memory read protection level is selected (RDP level = 1), |
mbed_official | 573:ad23fe03a082 | 516 | * it is not possible to program or erase the flash sector i if CortexM4 |
mbed_official | 573:ad23fe03a082 | 517 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
mbed_official | 573:ad23fe03a082 | 518 | * |
mbed_official | 573:ad23fe03a082 | 519 | * @param WRPSector: specifies the sector(s) to be write protected. |
mbed_official | 573:ad23fe03a082 | 520 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 521 | * @arg WRPSector: A value between OB_WRP_SECTOR_0 and OB_WRP_SECTOR_7 |
mbed_official | 573:ad23fe03a082 | 522 | * @arg OB_WRP_Sector_All |
mbed_official | 573:ad23fe03a082 | 523 | * |
mbed_official | 573:ad23fe03a082 | 524 | * |
mbed_official | 573:ad23fe03a082 | 525 | * @retval HAL Status |
mbed_official | 573:ad23fe03a082 | 526 | */ |
mbed_official | 573:ad23fe03a082 | 527 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector) |
mbed_official | 573:ad23fe03a082 | 528 | { |
mbed_official | 573:ad23fe03a082 | 529 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 573:ad23fe03a082 | 530 | |
mbed_official | 573:ad23fe03a082 | 531 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 532 | assert_param(IS_OB_WRP_SECTOR(WRPSector)); |
mbed_official | 573:ad23fe03a082 | 533 | |
mbed_official | 573:ad23fe03a082 | 534 | /* Wait for last operation to be completed */ |
mbed_official | 573:ad23fe03a082 | 535 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 573:ad23fe03a082 | 536 | |
mbed_official | 573:ad23fe03a082 | 537 | if(status == HAL_OK) |
mbed_official | 573:ad23fe03a082 | 538 | { |
mbed_official | 573:ad23fe03a082 | 539 | /* Write protection disabled on sectors */ |
mbed_official | 573:ad23fe03a082 | 540 | FLASH->OPTCR |= (WRPSector); |
mbed_official | 573:ad23fe03a082 | 541 | } |
mbed_official | 573:ad23fe03a082 | 542 | |
mbed_official | 573:ad23fe03a082 | 543 | return status; |
mbed_official | 573:ad23fe03a082 | 544 | } |
mbed_official | 573:ad23fe03a082 | 545 | |
mbed_official | 573:ad23fe03a082 | 546 | |
mbed_official | 573:ad23fe03a082 | 547 | |
mbed_official | 573:ad23fe03a082 | 548 | |
mbed_official | 573:ad23fe03a082 | 549 | /** |
mbed_official | 573:ad23fe03a082 | 550 | * @brief Set the read protection level. |
mbed_official | 573:ad23fe03a082 | 551 | * @param Level: specifies the read protection level. |
mbed_official | 573:ad23fe03a082 | 552 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 553 | * @arg OB_RDP_LEVEL_0: No protection |
mbed_official | 573:ad23fe03a082 | 554 | * @arg OB_RDP_LEVEL_1: Read protection of the memory |
mbed_official | 573:ad23fe03a082 | 555 | * @arg OB_RDP_LEVEL_2: Full chip protection |
mbed_official | 573:ad23fe03a082 | 556 | * |
mbed_official | 573:ad23fe03a082 | 557 | * @note WARNING: When enabling OB_RDP level 2 it's no more possible to go back to level 1 or 0 |
mbed_official | 573:ad23fe03a082 | 558 | * |
mbed_official | 573:ad23fe03a082 | 559 | * @retval HAL Status |
mbed_official | 573:ad23fe03a082 | 560 | */ |
mbed_official | 573:ad23fe03a082 | 561 | static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint32_t Level) |
mbed_official | 573:ad23fe03a082 | 562 | { |
mbed_official | 573:ad23fe03a082 | 563 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 573:ad23fe03a082 | 564 | |
mbed_official | 573:ad23fe03a082 | 565 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 566 | assert_param(IS_OB_RDP_LEVEL(Level)); |
mbed_official | 573:ad23fe03a082 | 567 | |
mbed_official | 573:ad23fe03a082 | 568 | /* Wait for last operation to be completed */ |
mbed_official | 573:ad23fe03a082 | 569 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 573:ad23fe03a082 | 570 | |
mbed_official | 573:ad23fe03a082 | 571 | if(status == HAL_OK) |
mbed_official | 573:ad23fe03a082 | 572 | { |
mbed_official | 573:ad23fe03a082 | 573 | MODIFY_REG(FLASH->OPTCR, FLASH_OPTCR_RDP, Level); |
mbed_official | 573:ad23fe03a082 | 574 | } |
mbed_official | 573:ad23fe03a082 | 575 | |
mbed_official | 573:ad23fe03a082 | 576 | return status; |
mbed_official | 573:ad23fe03a082 | 577 | } |
mbed_official | 573:ad23fe03a082 | 578 | |
mbed_official | 573:ad23fe03a082 | 579 | /** |
mbed_official | 573:ad23fe03a082 | 580 | * @brief Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY. |
mbed_official | 573:ad23fe03a082 | 581 | * @param Wwdg: Selects the IWDG mode |
mbed_official | 573:ad23fe03a082 | 582 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 583 | * @arg OB_WWDG_SW: Software WWDG selected |
mbed_official | 573:ad23fe03a082 | 584 | * @arg OB_WWDG_HW: Hardware WWDG selected |
mbed_official | 573:ad23fe03a082 | 585 | * @param Iwdg: Selects the WWDG mode |
mbed_official | 573:ad23fe03a082 | 586 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 587 | * @arg OB_IWDG_SW: Software IWDG selected |
mbed_official | 573:ad23fe03a082 | 588 | * @arg OB_IWDG_HW: Hardware IWDG selected |
mbed_official | 573:ad23fe03a082 | 589 | * @param Stop: Reset event when entering STOP mode. |
mbed_official | 573:ad23fe03a082 | 590 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 591 | * @arg OB_STOP_NO_RST: No reset generated when entering in STOP |
mbed_official | 573:ad23fe03a082 | 592 | * @arg OB_STOP_RST: Reset generated when entering in STOP |
mbed_official | 573:ad23fe03a082 | 593 | * @param Stdby: Reset event when entering Standby mode. |
mbed_official | 573:ad23fe03a082 | 594 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 595 | * @arg OB_STDBY_NO_RST: No reset generated when entering in STANDBY |
mbed_official | 573:ad23fe03a082 | 596 | * @arg OB_STDBY_RST: Reset generated when entering in STANDBY |
mbed_official | 573:ad23fe03a082 | 597 | * @param Iwdgstop: Independent watchdog counter freeze in Stop mode. |
mbed_official | 573:ad23fe03a082 | 598 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 599 | * @arg OB_IWDG_STOP_FREEZE: Freeze IWDG counter in STOP |
mbed_official | 573:ad23fe03a082 | 600 | * @arg OB_IWDG_STOP_ACTIVE: IWDG counter active in STOP |
mbed_official | 573:ad23fe03a082 | 601 | * @param Iwdgstdby: Independent watchdog counter freeze in standby mode. |
mbed_official | 573:ad23fe03a082 | 602 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 603 | * @arg OB_IWDG_STDBY_FREEZE: Freeze IWDG counter in STANDBY |
mbed_official | 573:ad23fe03a082 | 604 | * @arg OB_IWDG_STDBY_ACTIVE: IWDG counter active in STANDBY |
mbed_official | 573:ad23fe03a082 | 605 | * @retval HAL Status |
mbed_official | 573:ad23fe03a082 | 606 | */ |
mbed_official | 573:ad23fe03a082 | 607 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint32_t Wwdg, uint32_t Iwdg, uint32_t Stop, uint32_t Stdby, uint32_t Iwdgstop, uint32_t Iwdgstdby ) |
mbed_official | 573:ad23fe03a082 | 608 | { |
mbed_official | 573:ad23fe03a082 | 609 | uint32_t useroptionmask = 0x00; |
mbed_official | 573:ad23fe03a082 | 610 | uint32_t useroptionvalue = 0x00; |
mbed_official | 573:ad23fe03a082 | 611 | |
mbed_official | 573:ad23fe03a082 | 612 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 573:ad23fe03a082 | 613 | |
mbed_official | 573:ad23fe03a082 | 614 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 615 | assert_param(IS_OB_WWDG_SOURCE(Wwdg)); |
mbed_official | 573:ad23fe03a082 | 616 | assert_param(IS_OB_IWDG_SOURCE(Iwdg)); |
mbed_official | 573:ad23fe03a082 | 617 | assert_param(IS_OB_STOP_SOURCE(Stop)); |
mbed_official | 573:ad23fe03a082 | 618 | assert_param(IS_OB_STDBY_SOURCE(Stdby)); |
mbed_official | 573:ad23fe03a082 | 619 | assert_param(IS_OB_IWDG_STOP_FREEZE(Iwdgstop)); |
mbed_official | 573:ad23fe03a082 | 620 | assert_param(IS_OB_IWDG_STDBY_FREEZE(Iwdgstdby)); |
mbed_official | 573:ad23fe03a082 | 621 | |
mbed_official | 573:ad23fe03a082 | 622 | /* Wait for last operation to be completed */ |
mbed_official | 573:ad23fe03a082 | 623 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 573:ad23fe03a082 | 624 | |
mbed_official | 573:ad23fe03a082 | 625 | if(status == HAL_OK) |
mbed_official | 573:ad23fe03a082 | 626 | { |
mbed_official | 573:ad23fe03a082 | 627 | useroptionmask = (FLASH_OPTCR_WWDG_SW | FLASH_OPTCR_IWDG_SW | FLASH_OPTCR_nRST_STOP | \ |
mbed_official | 573:ad23fe03a082 | 628 | FLASH_OPTCR_nRST_STDBY | FLASH_OPTCR_IWDG_STOP | FLASH_OPTCR_IWDG_STDBY); |
mbed_official | 573:ad23fe03a082 | 629 | |
mbed_official | 573:ad23fe03a082 | 630 | useroptionvalue = (Iwdg | Wwdg | Stop | Stdby | Iwdgstop | Iwdgstdby); |
mbed_official | 573:ad23fe03a082 | 631 | |
mbed_official | 573:ad23fe03a082 | 632 | /* Update User Option Byte */ |
mbed_official | 573:ad23fe03a082 | 633 | MODIFY_REG(FLASH->OPTCR, useroptionmask, useroptionvalue); |
mbed_official | 573:ad23fe03a082 | 634 | } |
mbed_official | 573:ad23fe03a082 | 635 | |
mbed_official | 573:ad23fe03a082 | 636 | return status; |
mbed_official | 573:ad23fe03a082 | 637 | |
mbed_official | 573:ad23fe03a082 | 638 | } |
mbed_official | 573:ad23fe03a082 | 639 | |
mbed_official | 573:ad23fe03a082 | 640 | /** |
mbed_official | 573:ad23fe03a082 | 641 | * @brief Set the BOR Level. |
mbed_official | 573:ad23fe03a082 | 642 | * @param Level: specifies the Option Bytes BOR Reset Level. |
mbed_official | 573:ad23fe03a082 | 643 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 644 | * @arg OB_BOR_LEVEL3: Supply voltage ranges from 2.7 to 3.6 V |
mbed_official | 573:ad23fe03a082 | 645 | * @arg OB_BOR_LEVEL2: Supply voltage ranges from 2.4 to 2.7 V |
mbed_official | 573:ad23fe03a082 | 646 | * @arg OB_BOR_LEVEL1: Supply voltage ranges from 2.1 to 2.4 V |
mbed_official | 573:ad23fe03a082 | 647 | * @arg OB_BOR_OFF: Supply voltage ranges from 1.62 to 2.1 V |
mbed_official | 573:ad23fe03a082 | 648 | * @retval HAL Status |
mbed_official | 573:ad23fe03a082 | 649 | */ |
mbed_official | 573:ad23fe03a082 | 650 | static HAL_StatusTypeDef FLASH_OB_BOR_LevelConfig(uint8_t Level) |
mbed_official | 573:ad23fe03a082 | 651 | { |
mbed_official | 573:ad23fe03a082 | 652 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 653 | assert_param(IS_OB_BOR_LEVEL(Level)); |
mbed_official | 573:ad23fe03a082 | 654 | |
mbed_official | 573:ad23fe03a082 | 655 | /* Set the BOR Level */ |
mbed_official | 573:ad23fe03a082 | 656 | MODIFY_REG(FLASH->OPTCR, FLASH_OPTCR_BOR_LEV, Level); |
mbed_official | 573:ad23fe03a082 | 657 | |
mbed_official | 573:ad23fe03a082 | 658 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 659 | |
mbed_official | 573:ad23fe03a082 | 660 | } |
mbed_official | 573:ad23fe03a082 | 661 | |
mbed_official | 573:ad23fe03a082 | 662 | /** |
mbed_official | 573:ad23fe03a082 | 663 | * @brief Configure Boot base address. |
mbed_official | 573:ad23fe03a082 | 664 | * |
mbed_official | 573:ad23fe03a082 | 665 | * @param BootOption : specifies Boot base address depending from Boot pin = 0 or pin = 1 |
mbed_official | 573:ad23fe03a082 | 666 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 667 | * @arg OPTIONBYTE_BOOTADDR_0 : Boot address based when Boot pin = 0 |
mbed_official | 573:ad23fe03a082 | 668 | * @arg OPTIONBYTE_BOOTADDR_1 : Boot address based when Boot pin = 1 |
mbed_official | 573:ad23fe03a082 | 669 | * @param Address: specifies Boot base address |
mbed_official | 573:ad23fe03a082 | 670 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 671 | * @arg OB_BOOTADDR_ITCM_RAM : Boot from ITCM RAM (0x00000000) |
mbed_official | 573:ad23fe03a082 | 672 | * @arg OB_BOOTADDR_SYSTEM : Boot from System memory bootloader (0x00100000) |
mbed_official | 573:ad23fe03a082 | 673 | * @arg OB_BOOTADDR_ITCM_FLASH : Boot from Flash on ITCM interface (0x00200000) |
mbed_official | 573:ad23fe03a082 | 674 | * @arg OB_BOOTADDR_AXIM_FLASH : Boot from Flash on AXIM interface (0x08000000) |
mbed_official | 573:ad23fe03a082 | 675 | * @arg OB_BOOTADDR_DTCM_RAM : Boot from DTCM RAM (0x20000000) |
mbed_official | 573:ad23fe03a082 | 676 | * @arg OB_BOOTADDR_SRAM1 : Boot from SRAM1 (0x20010000) |
mbed_official | 573:ad23fe03a082 | 677 | * @arg OB_BOOTADDR_SRAM2 : Boot from SRAM2 (0x2004C000) |
mbed_official | 573:ad23fe03a082 | 678 | * |
mbed_official | 573:ad23fe03a082 | 679 | * @retval HAL Status |
mbed_official | 573:ad23fe03a082 | 680 | */ |
mbed_official | 573:ad23fe03a082 | 681 | static HAL_StatusTypeDef FLASH_OB_BootAddressConfig(uint32_t BootOption, uint32_t Address) |
mbed_official | 573:ad23fe03a082 | 682 | { |
mbed_official | 573:ad23fe03a082 | 683 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 573:ad23fe03a082 | 684 | |
mbed_official | 573:ad23fe03a082 | 685 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 686 | assert_param(IS_OB_BOOT_ADDRESS(Address)); |
mbed_official | 573:ad23fe03a082 | 687 | |
mbed_official | 573:ad23fe03a082 | 688 | /* Wait for last operation to be completed */ |
mbed_official | 573:ad23fe03a082 | 689 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 573:ad23fe03a082 | 690 | |
mbed_official | 573:ad23fe03a082 | 691 | if(status == HAL_OK) |
mbed_official | 573:ad23fe03a082 | 692 | { |
mbed_official | 573:ad23fe03a082 | 693 | if(BootOption == OPTIONBYTE_BOOTADDR_0) |
mbed_official | 573:ad23fe03a082 | 694 | { |
mbed_official | 573:ad23fe03a082 | 695 | MODIFY_REG(FLASH->OPTCR1, FLASH_OPTCR1_BOOT_ADD0, Address); |
mbed_official | 573:ad23fe03a082 | 696 | } |
mbed_official | 573:ad23fe03a082 | 697 | else |
mbed_official | 573:ad23fe03a082 | 698 | { |
mbed_official | 573:ad23fe03a082 | 699 | MODIFY_REG(FLASH->OPTCR1, FLASH_OPTCR1_BOOT_ADD1, (Address << 16)); |
mbed_official | 573:ad23fe03a082 | 700 | } |
mbed_official | 573:ad23fe03a082 | 701 | } |
mbed_official | 573:ad23fe03a082 | 702 | |
mbed_official | 573:ad23fe03a082 | 703 | return status; |
mbed_official | 573:ad23fe03a082 | 704 | } |
mbed_official | 573:ad23fe03a082 | 705 | |
mbed_official | 573:ad23fe03a082 | 706 | /** |
mbed_official | 573:ad23fe03a082 | 707 | * @brief Return the FLASH User Option Byte value. |
mbed_official | 573:ad23fe03a082 | 708 | * @retval uint32_t FLASH User Option Bytes values: IWDG_SW(Bit0), RST_STOP(Bit1) |
mbed_official | 573:ad23fe03a082 | 709 | * and RST_STDBY(Bit2). |
mbed_official | 573:ad23fe03a082 | 710 | */ |
mbed_official | 573:ad23fe03a082 | 711 | static uint32_t FLASH_OB_GetUser(void) |
mbed_official | 573:ad23fe03a082 | 712 | { |
mbed_official | 573:ad23fe03a082 | 713 | /* Return the User Option Byte */ |
mbed_official | 573:ad23fe03a082 | 714 | return ((uint32_t)(FLASH->OPTCR & 0xC00000F0)); |
mbed_official | 573:ad23fe03a082 | 715 | } |
mbed_official | 573:ad23fe03a082 | 716 | |
mbed_official | 573:ad23fe03a082 | 717 | /** |
mbed_official | 573:ad23fe03a082 | 718 | * @brief Return the FLASH Write Protection Option Bytes value. |
mbed_official | 573:ad23fe03a082 | 719 | * @retval uint32_t FLASH Write Protection Option Bytes value |
mbed_official | 573:ad23fe03a082 | 720 | */ |
mbed_official | 573:ad23fe03a082 | 721 | static uint32_t FLASH_OB_GetWRP(void) |
mbed_official | 573:ad23fe03a082 | 722 | { |
mbed_official | 573:ad23fe03a082 | 723 | /* Return the FLASH write protection Register value */ |
mbed_official | 573:ad23fe03a082 | 724 | return ((uint32_t)(FLASH->OPTCR & 0x00FF0000)); |
mbed_official | 573:ad23fe03a082 | 725 | } |
mbed_official | 573:ad23fe03a082 | 726 | |
mbed_official | 573:ad23fe03a082 | 727 | /** |
mbed_official | 573:ad23fe03a082 | 728 | * @brief Returns the FLASH Read Protection level. |
mbed_official | 573:ad23fe03a082 | 729 | * @retval FlagStatus FLASH ReadOut Protection Status: |
mbed_official | 610:813dcc80987e | 730 | * This parameter can be one of the following values: |
mbed_official | 610:813dcc80987e | 731 | * @arg OB_RDP_LEVEL_0: No protection |
mbed_official | 610:813dcc80987e | 732 | * @arg OB_RDP_LEVEL_1: Read protection of the memory |
mbed_official | 610:813dcc80987e | 733 | * @arg OB_RDP_LEVEL_2: Full chip protection |
mbed_official | 573:ad23fe03a082 | 734 | */ |
mbed_official | 610:813dcc80987e | 735 | static uint8_t FLASH_OB_GetRDP(void) |
mbed_official | 573:ad23fe03a082 | 736 | { |
mbed_official | 610:813dcc80987e | 737 | uint8_t readstatus = OB_RDP_LEVEL_0; |
mbed_official | 610:813dcc80987e | 738 | |
mbed_official | 610:813dcc80987e | 739 | if (((FLASH->OPTCR & FLASH_OPTCR_RDP) >> 8) == OB_RDP_LEVEL_0) |
mbed_official | 610:813dcc80987e | 740 | { |
mbed_official | 610:813dcc80987e | 741 | readstatus = OB_RDP_LEVEL_0; |
mbed_official | 610:813dcc80987e | 742 | } |
mbed_official | 610:813dcc80987e | 743 | else if (((FLASH->OPTCR & FLASH_OPTCR_RDP) >> 8) == OB_RDP_LEVEL_2) |
mbed_official | 573:ad23fe03a082 | 744 | { |
mbed_official | 610:813dcc80987e | 745 | readstatus = OB_RDP_LEVEL_2; |
mbed_official | 573:ad23fe03a082 | 746 | } |
mbed_official | 610:813dcc80987e | 747 | else |
mbed_official | 610:813dcc80987e | 748 | { |
mbed_official | 610:813dcc80987e | 749 | readstatus = OB_RDP_LEVEL_1; |
mbed_official | 610:813dcc80987e | 750 | } |
mbed_official | 610:813dcc80987e | 751 | |
mbed_official | 573:ad23fe03a082 | 752 | return readstatus; |
mbed_official | 573:ad23fe03a082 | 753 | } |
mbed_official | 573:ad23fe03a082 | 754 | |
mbed_official | 573:ad23fe03a082 | 755 | /** |
mbed_official | 573:ad23fe03a082 | 756 | * @brief Returns the FLASH BOR level. |
mbed_official | 573:ad23fe03a082 | 757 | * @retval uint32_t The FLASH BOR level: |
mbed_official | 573:ad23fe03a082 | 758 | * - OB_BOR_LEVEL3: Supply voltage ranges from 2.7 to 3.6 V |
mbed_official | 573:ad23fe03a082 | 759 | * - OB_BOR_LEVEL2: Supply voltage ranges from 2.4 to 2.7 V |
mbed_official | 573:ad23fe03a082 | 760 | * - OB_BOR_LEVEL1: Supply voltage ranges from 2.1 to 2.4 V |
mbed_official | 573:ad23fe03a082 | 761 | * - OB_BOR_OFF : Supply voltage ranges from 1.62 to 2.1 V |
mbed_official | 573:ad23fe03a082 | 762 | */ |
mbed_official | 573:ad23fe03a082 | 763 | static uint32_t FLASH_OB_GetBOR(void) |
mbed_official | 573:ad23fe03a082 | 764 | { |
mbed_official | 573:ad23fe03a082 | 765 | /* Return the FLASH BOR level */ |
mbed_official | 573:ad23fe03a082 | 766 | return ((uint32_t)(FLASH->OPTCR & 0x0C)); |
mbed_official | 573:ad23fe03a082 | 767 | } |
mbed_official | 573:ad23fe03a082 | 768 | |
mbed_official | 573:ad23fe03a082 | 769 | /** |
mbed_official | 573:ad23fe03a082 | 770 | * @brief Configure Boot base address. |
mbed_official | 573:ad23fe03a082 | 771 | * |
mbed_official | 573:ad23fe03a082 | 772 | * @param BootOption : specifies Boot base address depending from Boot pin = 0 or pin = 1 |
mbed_official | 573:ad23fe03a082 | 773 | * This parameter can be one of the following values: |
mbed_official | 573:ad23fe03a082 | 774 | * @arg OPTIONBYTE_BOOTADDR_0 : Boot address based when Boot pin = 0 |
mbed_official | 573:ad23fe03a082 | 775 | * @arg OPTIONBYTE_BOOTADDR_1 : Boot address based when Boot pin = 1 |
mbed_official | 573:ad23fe03a082 | 776 | * |
mbed_official | 573:ad23fe03a082 | 777 | * @retval uint32_t Boot Base Address: |
mbed_official | 573:ad23fe03a082 | 778 | * - OB_BOOTADDR_ITCM_RAM : Boot from ITCM RAM (0x00000000) |
mbed_official | 573:ad23fe03a082 | 779 | * - OB_BOOTADDR_SYSTEM : Boot from System memory bootloader (0x00100000) |
mbed_official | 573:ad23fe03a082 | 780 | * - OB_BOOTADDR_ITCM_FLASH : Boot from Flash on ITCM interface (0x00200000) |
mbed_official | 573:ad23fe03a082 | 781 | * - OB_BOOTADDR_AXIM_FLASH : Boot from Flash on AXIM interface (0x08000000) |
mbed_official | 573:ad23fe03a082 | 782 | * - OB_BOOTADDR_DTCM_RAM : Boot from DTCM RAM (0x20000000) |
mbed_official | 573:ad23fe03a082 | 783 | * - OB_BOOTADDR_SRAM1 : Boot from SRAM1 (0x20010000) |
mbed_official | 573:ad23fe03a082 | 784 | * - OB_BOOTADDR_SRAM2 : Boot from SRAM2 (0x2004C000) |
mbed_official | 573:ad23fe03a082 | 785 | */ |
mbed_official | 573:ad23fe03a082 | 786 | static uint32_t FLASH_OB_GetBootAddress(uint32_t BootOption) |
mbed_official | 573:ad23fe03a082 | 787 | { |
mbed_official | 573:ad23fe03a082 | 788 | uint32_t Address = 0; |
mbed_official | 573:ad23fe03a082 | 789 | |
mbed_official | 573:ad23fe03a082 | 790 | /* Return the Boot base Address */ |
mbed_official | 573:ad23fe03a082 | 791 | if(BootOption == OPTIONBYTE_BOOTADDR_0) |
mbed_official | 573:ad23fe03a082 | 792 | { |
mbed_official | 573:ad23fe03a082 | 793 | Address = FLASH->OPTCR1 & FLASH_OPTCR1_BOOT_ADD0; |
mbed_official | 573:ad23fe03a082 | 794 | } |
mbed_official | 573:ad23fe03a082 | 795 | else |
mbed_official | 573:ad23fe03a082 | 796 | { |
mbed_official | 573:ad23fe03a082 | 797 | Address = ((FLASH->OPTCR1 & FLASH_OPTCR1_BOOT_ADD1) >> 16); |
mbed_official | 573:ad23fe03a082 | 798 | } |
mbed_official | 573:ad23fe03a082 | 799 | |
mbed_official | 573:ad23fe03a082 | 800 | return Address; |
mbed_official | 573:ad23fe03a082 | 801 | } |
mbed_official | 573:ad23fe03a082 | 802 | |
mbed_official | 573:ad23fe03a082 | 803 | /** |
mbed_official | 573:ad23fe03a082 | 804 | * @} |
mbed_official | 573:ad23fe03a082 | 805 | */ |
mbed_official | 573:ad23fe03a082 | 806 | |
mbed_official | 573:ad23fe03a082 | 807 | #endif /* HAL_FLASH_MODULE_ENABLED */ |
mbed_official | 573:ad23fe03a082 | 808 | |
mbed_official | 573:ad23fe03a082 | 809 | /** |
mbed_official | 573:ad23fe03a082 | 810 | * @} |
mbed_official | 573:ad23fe03a082 | 811 | */ |
mbed_official | 573:ad23fe03a082 | 812 | |
mbed_official | 573:ad23fe03a082 | 813 | /** |
mbed_official | 573:ad23fe03a082 | 814 | * @} |
mbed_official | 573:ad23fe03a082 | 815 | */ |
mbed_official | 573:ad23fe03a082 | 816 | |
mbed_official | 573:ad23fe03a082 | 817 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |