Initial commit
mbed-dev-master/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_flash_ex.c@0:bb348c97df44, 2020-09-16 (annotated)
- Committer:
- lypinator
- Date:
- Wed Sep 16 01:11:49 2020 +0000
- Revision:
- 0:bb348c97df44
Added PWM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lypinator | 0:bb348c97df44 | 1 | /** |
lypinator | 0:bb348c97df44 | 2 | ****************************************************************************** |
lypinator | 0:bb348c97df44 | 3 | * @file stm32f4xx_hal_flash_ex.c |
lypinator | 0:bb348c97df44 | 4 | * @author MCD Application Team |
lypinator | 0:bb348c97df44 | 5 | * @brief Extended FLASH HAL module driver. |
lypinator | 0:bb348c97df44 | 6 | * This file provides firmware functions to manage the following |
lypinator | 0:bb348c97df44 | 7 | * functionalities of the FLASH extension peripheral: |
lypinator | 0:bb348c97df44 | 8 | * + Extended programming operations functions |
lypinator | 0:bb348c97df44 | 9 | * |
lypinator | 0:bb348c97df44 | 10 | @verbatim |
lypinator | 0:bb348c97df44 | 11 | ============================================================================== |
lypinator | 0:bb348c97df44 | 12 | ##### Flash Extension features ##### |
lypinator | 0:bb348c97df44 | 13 | ============================================================================== |
lypinator | 0:bb348c97df44 | 14 | |
lypinator | 0:bb348c97df44 | 15 | [..] Comparing to other previous devices, the FLASH interface for STM32F427xx/437xx and |
lypinator | 0:bb348c97df44 | 16 | STM32F429xx/439xx devices contains the following additional features |
lypinator | 0:bb348c97df44 | 17 | |
lypinator | 0:bb348c97df44 | 18 | (+) Capacity up to 2 Mbyte with dual bank architecture supporting read-while-write |
lypinator | 0:bb348c97df44 | 19 | capability (RWW) |
lypinator | 0:bb348c97df44 | 20 | (+) Dual bank memory organization |
lypinator | 0:bb348c97df44 | 21 | (+) PCROP protection for all banks |
lypinator | 0:bb348c97df44 | 22 | |
lypinator | 0:bb348c97df44 | 23 | ##### How to use this driver ##### |
lypinator | 0:bb348c97df44 | 24 | ============================================================================== |
lypinator | 0:bb348c97df44 | 25 | [..] This driver provides functions to configure and program the FLASH memory |
lypinator | 0:bb348c97df44 | 26 | of all STM32F427xx/437xx, STM32F429xx/439xx, STM32F469xx/479xx and STM32F446xx |
lypinator | 0:bb348c97df44 | 27 | devices. It includes |
lypinator | 0:bb348c97df44 | 28 | (#) FLASH Memory Erase functions: |
lypinator | 0:bb348c97df44 | 29 | (++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and |
lypinator | 0:bb348c97df44 | 30 | HAL_FLASH_Lock() functions |
lypinator | 0:bb348c97df44 | 31 | (++) Erase function: Erase sector, erase all sectors |
lypinator | 0:bb348c97df44 | 32 | (++) There are two modes of erase : |
lypinator | 0:bb348c97df44 | 33 | (+++) Polling Mode using HAL_FLASHEx_Erase() |
lypinator | 0:bb348c97df44 | 34 | (+++) Interrupt Mode using HAL_FLASHEx_Erase_IT() |
lypinator | 0:bb348c97df44 | 35 | |
lypinator | 0:bb348c97df44 | 36 | (#) Option Bytes Programming functions: Use HAL_FLASHEx_OBProgram() to : |
lypinator | 0:bb348c97df44 | 37 | (++) Set/Reset the write protection |
lypinator | 0:bb348c97df44 | 38 | (++) Set the Read protection Level |
lypinator | 0:bb348c97df44 | 39 | (++) Set the BOR level |
lypinator | 0:bb348c97df44 | 40 | (++) Program the user Option Bytes |
lypinator | 0:bb348c97df44 | 41 | (#) Advanced Option Bytes Programming functions: Use HAL_FLASHEx_AdvOBProgram() to : |
lypinator | 0:bb348c97df44 | 42 | (++) Extended space (bank 2) erase function |
lypinator | 0:bb348c97df44 | 43 | (++) Full FLASH space (2 Mo) erase (bank 1 and bank 2) |
lypinator | 0:bb348c97df44 | 44 | (++) Dual Boot activation |
lypinator | 0:bb348c97df44 | 45 | (++) Write protection configuration for bank 2 |
lypinator | 0:bb348c97df44 | 46 | (++) PCROP protection configuration and control for both banks |
lypinator | 0:bb348c97df44 | 47 | |
lypinator | 0:bb348c97df44 | 48 | @endverbatim |
lypinator | 0:bb348c97df44 | 49 | ****************************************************************************** |
lypinator | 0:bb348c97df44 | 50 | * @attention |
lypinator | 0:bb348c97df44 | 51 | * |
lypinator | 0:bb348c97df44 | 52 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
lypinator | 0:bb348c97df44 | 53 | * |
lypinator | 0:bb348c97df44 | 54 | * Redistribution and use in source and binary forms, with or without modification, |
lypinator | 0:bb348c97df44 | 55 | * are permitted provided that the following conditions are met: |
lypinator | 0:bb348c97df44 | 56 | * 1. Redistributions of source code must retain the above copyright notice, |
lypinator | 0:bb348c97df44 | 57 | * this list of conditions and the following disclaimer. |
lypinator | 0:bb348c97df44 | 58 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
lypinator | 0:bb348c97df44 | 59 | * this list of conditions and the following disclaimer in the documentation |
lypinator | 0:bb348c97df44 | 60 | * and/or other materials provided with the distribution. |
lypinator | 0:bb348c97df44 | 61 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
lypinator | 0:bb348c97df44 | 62 | * may be used to endorse or promote products derived from this software |
lypinator | 0:bb348c97df44 | 63 | * without specific prior written permission. |
lypinator | 0:bb348c97df44 | 64 | * |
lypinator | 0:bb348c97df44 | 65 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
lypinator | 0:bb348c97df44 | 66 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
lypinator | 0:bb348c97df44 | 67 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
lypinator | 0:bb348c97df44 | 68 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
lypinator | 0:bb348c97df44 | 69 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
lypinator | 0:bb348c97df44 | 70 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
lypinator | 0:bb348c97df44 | 71 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
lypinator | 0:bb348c97df44 | 72 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
lypinator | 0:bb348c97df44 | 73 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
lypinator | 0:bb348c97df44 | 74 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
lypinator | 0:bb348c97df44 | 75 | * |
lypinator | 0:bb348c97df44 | 76 | ****************************************************************************** |
lypinator | 0:bb348c97df44 | 77 | */ |
lypinator | 0:bb348c97df44 | 78 | |
lypinator | 0:bb348c97df44 | 79 | /* Includes ------------------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 80 | #include "stm32f4xx_hal.h" |
lypinator | 0:bb348c97df44 | 81 | |
lypinator | 0:bb348c97df44 | 82 | /** @addtogroup STM32F4xx_HAL_Driver |
lypinator | 0:bb348c97df44 | 83 | * @{ |
lypinator | 0:bb348c97df44 | 84 | */ |
lypinator | 0:bb348c97df44 | 85 | |
lypinator | 0:bb348c97df44 | 86 | /** @defgroup FLASHEx FLASHEx |
lypinator | 0:bb348c97df44 | 87 | * @brief FLASH HAL Extension module driver |
lypinator | 0:bb348c97df44 | 88 | * @{ |
lypinator | 0:bb348c97df44 | 89 | */ |
lypinator | 0:bb348c97df44 | 90 | |
lypinator | 0:bb348c97df44 | 91 | #ifdef HAL_FLASH_MODULE_ENABLED |
lypinator | 0:bb348c97df44 | 92 | |
lypinator | 0:bb348c97df44 | 93 | /* Private typedef -----------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 94 | /* Private define ------------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 95 | /** @addtogroup FLASHEx_Private_Constants |
lypinator | 0:bb348c97df44 | 96 | * @{ |
lypinator | 0:bb348c97df44 | 97 | */ |
lypinator | 0:bb348c97df44 | 98 | #define FLASH_TIMEOUT_VALUE 50000U /* 50 s */ |
lypinator | 0:bb348c97df44 | 99 | /** |
lypinator | 0:bb348c97df44 | 100 | * @} |
lypinator | 0:bb348c97df44 | 101 | */ |
lypinator | 0:bb348c97df44 | 102 | |
lypinator | 0:bb348c97df44 | 103 | /* Private macro -------------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 104 | /* Private variables ---------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 105 | /** @addtogroup FLASHEx_Private_Variables |
lypinator | 0:bb348c97df44 | 106 | * @{ |
lypinator | 0:bb348c97df44 | 107 | */ |
lypinator | 0:bb348c97df44 | 108 | extern FLASH_ProcessTypeDef pFlash; |
lypinator | 0:bb348c97df44 | 109 | /** |
lypinator | 0:bb348c97df44 | 110 | * @} |
lypinator | 0:bb348c97df44 | 111 | */ |
lypinator | 0:bb348c97df44 | 112 | |
lypinator | 0:bb348c97df44 | 113 | /* Private function prototypes -----------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 114 | /** @addtogroup FLASHEx_Private_Functions |
lypinator | 0:bb348c97df44 | 115 | * @{ |
lypinator | 0:bb348c97df44 | 116 | */ |
lypinator | 0:bb348c97df44 | 117 | /* Option bytes control */ |
lypinator | 0:bb348c97df44 | 118 | static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks); |
lypinator | 0:bb348c97df44 | 119 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks); |
lypinator | 0:bb348c97df44 | 120 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks); |
lypinator | 0:bb348c97df44 | 121 | static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t Level); |
lypinator | 0:bb348c97df44 | 122 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t Iwdg, uint8_t Stop, uint8_t Stdby); |
lypinator | 0:bb348c97df44 | 123 | static HAL_StatusTypeDef FLASH_OB_BOR_LevelConfig(uint8_t Level); |
lypinator | 0:bb348c97df44 | 124 | static uint8_t FLASH_OB_GetUser(void); |
lypinator | 0:bb348c97df44 | 125 | static uint16_t FLASH_OB_GetWRP(void); |
lypinator | 0:bb348c97df44 | 126 | static uint8_t FLASH_OB_GetRDP(void); |
lypinator | 0:bb348c97df44 | 127 | static uint8_t FLASH_OB_GetBOR(void); |
lypinator | 0:bb348c97df44 | 128 | |
lypinator | 0:bb348c97df44 | 129 | #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) ||\ |
lypinator | 0:bb348c97df44 | 130 | defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) ||\ |
lypinator | 0:bb348c97df44 | 131 | defined(STM32F423xx) |
lypinator | 0:bb348c97df44 | 132 | static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t Sector); |
lypinator | 0:bb348c97df44 | 133 | static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t Sector); |
lypinator | 0:bb348c97df44 | 134 | #endif /* STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx |
lypinator | 0:bb348c97df44 | 135 | STM32F413xx || STM32F423xx */ |
lypinator | 0:bb348c97df44 | 136 | |
lypinator | 0:bb348c97df44 | 137 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) || defined(STM32F469xx) || defined(STM32F479xx) |
lypinator | 0:bb348c97df44 | 138 | static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks); |
lypinator | 0:bb348c97df44 | 139 | static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks); |
lypinator | 0:bb348c97df44 | 140 | static HAL_StatusTypeDef FLASH_OB_BootConfig(uint8_t BootConfig); |
lypinator | 0:bb348c97df44 | 141 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ |
lypinator | 0:bb348c97df44 | 142 | |
lypinator | 0:bb348c97df44 | 143 | extern HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); |
lypinator | 0:bb348c97df44 | 144 | /** |
lypinator | 0:bb348c97df44 | 145 | * @} |
lypinator | 0:bb348c97df44 | 146 | */ |
lypinator | 0:bb348c97df44 | 147 | |
lypinator | 0:bb348c97df44 | 148 | /* Exported functions --------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 149 | /** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions |
lypinator | 0:bb348c97df44 | 150 | * @{ |
lypinator | 0:bb348c97df44 | 151 | */ |
lypinator | 0:bb348c97df44 | 152 | |
lypinator | 0:bb348c97df44 | 153 | /** @defgroup FLASHEx_Exported_Functions_Group1 Extended IO operation functions |
lypinator | 0:bb348c97df44 | 154 | * @brief Extended IO operation functions |
lypinator | 0:bb348c97df44 | 155 | * |
lypinator | 0:bb348c97df44 | 156 | @verbatim |
lypinator | 0:bb348c97df44 | 157 | =============================================================================== |
lypinator | 0:bb348c97df44 | 158 | ##### Extended programming operation functions ##### |
lypinator | 0:bb348c97df44 | 159 | =============================================================================== |
lypinator | 0:bb348c97df44 | 160 | [..] |
lypinator | 0:bb348c97df44 | 161 | This subsection provides a set of functions allowing to manage the Extension FLASH |
lypinator | 0:bb348c97df44 | 162 | programming operations. |
lypinator | 0:bb348c97df44 | 163 | |
lypinator | 0:bb348c97df44 | 164 | @endverbatim |
lypinator | 0:bb348c97df44 | 165 | * @{ |
lypinator | 0:bb348c97df44 | 166 | */ |
lypinator | 0:bb348c97df44 | 167 | /** |
lypinator | 0:bb348c97df44 | 168 | * @brief Perform a mass erase or erase the specified FLASH memory sectors |
lypinator | 0:bb348c97df44 | 169 | * @param[in] pEraseInit pointer to an FLASH_EraseInitTypeDef structure that |
lypinator | 0:bb348c97df44 | 170 | * contains the configuration information for the erasing. |
lypinator | 0:bb348c97df44 | 171 | * |
lypinator | 0:bb348c97df44 | 172 | * @param[out] SectorError pointer to variable that |
lypinator | 0:bb348c97df44 | 173 | * contains the configuration information on faulty sector in case of error |
lypinator | 0:bb348c97df44 | 174 | * (0xFFFFFFFFU means that all the sectors have been correctly erased) |
lypinator | 0:bb348c97df44 | 175 | * |
lypinator | 0:bb348c97df44 | 176 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 177 | */ |
lypinator | 0:bb348c97df44 | 178 | HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError) |
lypinator | 0:bb348c97df44 | 179 | { |
lypinator | 0:bb348c97df44 | 180 | HAL_StatusTypeDef status = HAL_ERROR; |
lypinator | 0:bb348c97df44 | 181 | uint32_t index = 0U; |
lypinator | 0:bb348c97df44 | 182 | |
lypinator | 0:bb348c97df44 | 183 | /* Process Locked */ |
lypinator | 0:bb348c97df44 | 184 | __HAL_LOCK(&pFlash); |
lypinator | 0:bb348c97df44 | 185 | |
lypinator | 0:bb348c97df44 | 186 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 187 | assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
lypinator | 0:bb348c97df44 | 188 | |
lypinator | 0:bb348c97df44 | 189 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 190 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 191 | |
lypinator | 0:bb348c97df44 | 192 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 193 | { |
lypinator | 0:bb348c97df44 | 194 | /*Initialization of SectorError variable*/ |
lypinator | 0:bb348c97df44 | 195 | *SectorError = 0xFFFFFFFFU; |
lypinator | 0:bb348c97df44 | 196 | |
lypinator | 0:bb348c97df44 | 197 | if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) |
lypinator | 0:bb348c97df44 | 198 | { |
lypinator | 0:bb348c97df44 | 199 | /*Mass erase to be done*/ |
lypinator | 0:bb348c97df44 | 200 | FLASH_MassErase((uint8_t) pEraseInit->VoltageRange, pEraseInit->Banks); |
lypinator | 0:bb348c97df44 | 201 | |
lypinator | 0:bb348c97df44 | 202 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 203 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 204 | |
lypinator | 0:bb348c97df44 | 205 | /* if the erase operation is completed, disable the MER Bit */ |
lypinator | 0:bb348c97df44 | 206 | FLASH->CR &= (~FLASH_MER_BIT); |
lypinator | 0:bb348c97df44 | 207 | } |
lypinator | 0:bb348c97df44 | 208 | else |
lypinator | 0:bb348c97df44 | 209 | { |
lypinator | 0:bb348c97df44 | 210 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 211 | assert_param(IS_FLASH_NBSECTORS(pEraseInit->NbSectors + pEraseInit->Sector)); |
lypinator | 0:bb348c97df44 | 212 | |
lypinator | 0:bb348c97df44 | 213 | /* Erase by sector by sector to be done*/ |
lypinator | 0:bb348c97df44 | 214 | for(index = pEraseInit->Sector; index < (pEraseInit->NbSectors + pEraseInit->Sector); index++) |
lypinator | 0:bb348c97df44 | 215 | { |
lypinator | 0:bb348c97df44 | 216 | FLASH_Erase_Sector(index, (uint8_t) pEraseInit->VoltageRange); |
lypinator | 0:bb348c97df44 | 217 | |
lypinator | 0:bb348c97df44 | 218 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 219 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 220 | |
lypinator | 0:bb348c97df44 | 221 | /* If the erase operation is completed, disable the SER and SNB Bits */ |
lypinator | 0:bb348c97df44 | 222 | CLEAR_BIT(FLASH->CR, (FLASH_CR_SER | FLASH_CR_SNB)); |
lypinator | 0:bb348c97df44 | 223 | |
lypinator | 0:bb348c97df44 | 224 | if(status != HAL_OK) |
lypinator | 0:bb348c97df44 | 225 | { |
lypinator | 0:bb348c97df44 | 226 | /* In case of error, stop erase procedure and return the faulty sector*/ |
lypinator | 0:bb348c97df44 | 227 | *SectorError = index; |
lypinator | 0:bb348c97df44 | 228 | break; |
lypinator | 0:bb348c97df44 | 229 | } |
lypinator | 0:bb348c97df44 | 230 | } |
lypinator | 0:bb348c97df44 | 231 | } |
lypinator | 0:bb348c97df44 | 232 | /* Flush the caches to be sure of the data consistency */ |
lypinator | 0:bb348c97df44 | 233 | FLASH_FlushCaches(); |
lypinator | 0:bb348c97df44 | 234 | } |
lypinator | 0:bb348c97df44 | 235 | |
lypinator | 0:bb348c97df44 | 236 | /* Process Unlocked */ |
lypinator | 0:bb348c97df44 | 237 | __HAL_UNLOCK(&pFlash); |
lypinator | 0:bb348c97df44 | 238 | |
lypinator | 0:bb348c97df44 | 239 | return status; |
lypinator | 0:bb348c97df44 | 240 | } |
lypinator | 0:bb348c97df44 | 241 | |
lypinator | 0:bb348c97df44 | 242 | /** |
lypinator | 0:bb348c97df44 | 243 | * @brief Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled |
lypinator | 0:bb348c97df44 | 244 | * @param pEraseInit pointer to an FLASH_EraseInitTypeDef structure that |
lypinator | 0:bb348c97df44 | 245 | * contains the configuration information for the erasing. |
lypinator | 0:bb348c97df44 | 246 | * |
lypinator | 0:bb348c97df44 | 247 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 248 | */ |
lypinator | 0:bb348c97df44 | 249 | HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) |
lypinator | 0:bb348c97df44 | 250 | { |
lypinator | 0:bb348c97df44 | 251 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 252 | |
lypinator | 0:bb348c97df44 | 253 | /* Process Locked */ |
lypinator | 0:bb348c97df44 | 254 | __HAL_LOCK(&pFlash); |
lypinator | 0:bb348c97df44 | 255 | |
lypinator | 0:bb348c97df44 | 256 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 257 | assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
lypinator | 0:bb348c97df44 | 258 | |
lypinator | 0:bb348c97df44 | 259 | /* Enable End of FLASH Operation interrupt */ |
lypinator | 0:bb348c97df44 | 260 | __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP); |
lypinator | 0:bb348c97df44 | 261 | |
lypinator | 0:bb348c97df44 | 262 | /* Enable Error source interrupt */ |
lypinator | 0:bb348c97df44 | 263 | __HAL_FLASH_ENABLE_IT(FLASH_IT_ERR); |
lypinator | 0:bb348c97df44 | 264 | |
lypinator | 0:bb348c97df44 | 265 | /* Clear pending flags (if any) */ |
lypinator | 0:bb348c97df44 | 266 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |\ |
lypinator | 0:bb348c97df44 | 267 | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_PGSERR); |
lypinator | 0:bb348c97df44 | 268 | |
lypinator | 0:bb348c97df44 | 269 | if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) |
lypinator | 0:bb348c97df44 | 270 | { |
lypinator | 0:bb348c97df44 | 271 | /*Mass erase to be done*/ |
lypinator | 0:bb348c97df44 | 272 | pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE; |
lypinator | 0:bb348c97df44 | 273 | pFlash.Bank = pEraseInit->Banks; |
lypinator | 0:bb348c97df44 | 274 | FLASH_MassErase((uint8_t) pEraseInit->VoltageRange, pEraseInit->Banks); |
lypinator | 0:bb348c97df44 | 275 | } |
lypinator | 0:bb348c97df44 | 276 | else |
lypinator | 0:bb348c97df44 | 277 | { |
lypinator | 0:bb348c97df44 | 278 | /* Erase by sector to be done*/ |
lypinator | 0:bb348c97df44 | 279 | |
lypinator | 0:bb348c97df44 | 280 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 281 | assert_param(IS_FLASH_NBSECTORS(pEraseInit->NbSectors + pEraseInit->Sector)); |
lypinator | 0:bb348c97df44 | 282 | |
lypinator | 0:bb348c97df44 | 283 | pFlash.ProcedureOnGoing = FLASH_PROC_SECTERASE; |
lypinator | 0:bb348c97df44 | 284 | pFlash.NbSectorsToErase = pEraseInit->NbSectors; |
lypinator | 0:bb348c97df44 | 285 | pFlash.Sector = pEraseInit->Sector; |
lypinator | 0:bb348c97df44 | 286 | pFlash.VoltageForErase = (uint8_t)pEraseInit->VoltageRange; |
lypinator | 0:bb348c97df44 | 287 | |
lypinator | 0:bb348c97df44 | 288 | /*Erase 1st sector and wait for IT*/ |
lypinator | 0:bb348c97df44 | 289 | FLASH_Erase_Sector(pEraseInit->Sector, pEraseInit->VoltageRange); |
lypinator | 0:bb348c97df44 | 290 | } |
lypinator | 0:bb348c97df44 | 291 | |
lypinator | 0:bb348c97df44 | 292 | return status; |
lypinator | 0:bb348c97df44 | 293 | } |
lypinator | 0:bb348c97df44 | 294 | |
lypinator | 0:bb348c97df44 | 295 | /** |
lypinator | 0:bb348c97df44 | 296 | * @brief Program option bytes |
lypinator | 0:bb348c97df44 | 297 | * @param pOBInit pointer to an FLASH_OBInitStruct structure that |
lypinator | 0:bb348c97df44 | 298 | * contains the configuration information for the programming. |
lypinator | 0:bb348c97df44 | 299 | * |
lypinator | 0:bb348c97df44 | 300 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 301 | */ |
lypinator | 0:bb348c97df44 | 302 | HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) |
lypinator | 0:bb348c97df44 | 303 | { |
lypinator | 0:bb348c97df44 | 304 | HAL_StatusTypeDef status = HAL_ERROR; |
lypinator | 0:bb348c97df44 | 305 | |
lypinator | 0:bb348c97df44 | 306 | /* Process Locked */ |
lypinator | 0:bb348c97df44 | 307 | __HAL_LOCK(&pFlash); |
lypinator | 0:bb348c97df44 | 308 | |
lypinator | 0:bb348c97df44 | 309 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 310 | assert_param(IS_OPTIONBYTE(pOBInit->OptionType)); |
lypinator | 0:bb348c97df44 | 311 | |
lypinator | 0:bb348c97df44 | 312 | /*Write protection configuration*/ |
lypinator | 0:bb348c97df44 | 313 | if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP) |
lypinator | 0:bb348c97df44 | 314 | { |
lypinator | 0:bb348c97df44 | 315 | assert_param(IS_WRPSTATE(pOBInit->WRPState)); |
lypinator | 0:bb348c97df44 | 316 | if(pOBInit->WRPState == OB_WRPSTATE_ENABLE) |
lypinator | 0:bb348c97df44 | 317 | { |
lypinator | 0:bb348c97df44 | 318 | /*Enable of Write protection on the selected Sector*/ |
lypinator | 0:bb348c97df44 | 319 | status = FLASH_OB_EnableWRP(pOBInit->WRPSector, pOBInit->Banks); |
lypinator | 0:bb348c97df44 | 320 | } |
lypinator | 0:bb348c97df44 | 321 | else |
lypinator | 0:bb348c97df44 | 322 | { |
lypinator | 0:bb348c97df44 | 323 | /*Disable of Write protection on the selected Sector*/ |
lypinator | 0:bb348c97df44 | 324 | status = FLASH_OB_DisableWRP(pOBInit->WRPSector, pOBInit->Banks); |
lypinator | 0:bb348c97df44 | 325 | } |
lypinator | 0:bb348c97df44 | 326 | } |
lypinator | 0:bb348c97df44 | 327 | |
lypinator | 0:bb348c97df44 | 328 | /*Read protection configuration*/ |
lypinator | 0:bb348c97df44 | 329 | if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) |
lypinator | 0:bb348c97df44 | 330 | { |
lypinator | 0:bb348c97df44 | 331 | status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel); |
lypinator | 0:bb348c97df44 | 332 | } |
lypinator | 0:bb348c97df44 | 333 | |
lypinator | 0:bb348c97df44 | 334 | /*USER configuration*/ |
lypinator | 0:bb348c97df44 | 335 | if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) |
lypinator | 0:bb348c97df44 | 336 | { |
lypinator | 0:bb348c97df44 | 337 | status = FLASH_OB_UserConfig(pOBInit->USERConfig&OB_IWDG_SW, |
lypinator | 0:bb348c97df44 | 338 | pOBInit->USERConfig&OB_STOP_NO_RST, |
lypinator | 0:bb348c97df44 | 339 | pOBInit->USERConfig&OB_STDBY_NO_RST); |
lypinator | 0:bb348c97df44 | 340 | } |
lypinator | 0:bb348c97df44 | 341 | |
lypinator | 0:bb348c97df44 | 342 | /*BOR Level configuration*/ |
lypinator | 0:bb348c97df44 | 343 | if((pOBInit->OptionType & OPTIONBYTE_BOR) == OPTIONBYTE_BOR) |
lypinator | 0:bb348c97df44 | 344 | { |
lypinator | 0:bb348c97df44 | 345 | status = FLASH_OB_BOR_LevelConfig(pOBInit->BORLevel); |
lypinator | 0:bb348c97df44 | 346 | } |
lypinator | 0:bb348c97df44 | 347 | |
lypinator | 0:bb348c97df44 | 348 | /* Process Unlocked */ |
lypinator | 0:bb348c97df44 | 349 | __HAL_UNLOCK(&pFlash); |
lypinator | 0:bb348c97df44 | 350 | |
lypinator | 0:bb348c97df44 | 351 | return status; |
lypinator | 0:bb348c97df44 | 352 | } |
lypinator | 0:bb348c97df44 | 353 | |
lypinator | 0:bb348c97df44 | 354 | /** |
lypinator | 0:bb348c97df44 | 355 | * @brief Get the Option byte configuration |
lypinator | 0:bb348c97df44 | 356 | * @param pOBInit pointer to an FLASH_OBInitStruct structure that |
lypinator | 0:bb348c97df44 | 357 | * contains the configuration information for the programming. |
lypinator | 0:bb348c97df44 | 358 | * |
lypinator | 0:bb348c97df44 | 359 | * @retval None |
lypinator | 0:bb348c97df44 | 360 | */ |
lypinator | 0:bb348c97df44 | 361 | void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) |
lypinator | 0:bb348c97df44 | 362 | { |
lypinator | 0:bb348c97df44 | 363 | pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_BOR; |
lypinator | 0:bb348c97df44 | 364 | |
lypinator | 0:bb348c97df44 | 365 | /*Get WRP*/ |
lypinator | 0:bb348c97df44 | 366 | pOBInit->WRPSector = (uint32_t)FLASH_OB_GetWRP(); |
lypinator | 0:bb348c97df44 | 367 | |
lypinator | 0:bb348c97df44 | 368 | /*Get RDP Level*/ |
lypinator | 0:bb348c97df44 | 369 | pOBInit->RDPLevel = (uint32_t)FLASH_OB_GetRDP(); |
lypinator | 0:bb348c97df44 | 370 | |
lypinator | 0:bb348c97df44 | 371 | /*Get USER*/ |
lypinator | 0:bb348c97df44 | 372 | pOBInit->USERConfig = (uint8_t)FLASH_OB_GetUser(); |
lypinator | 0:bb348c97df44 | 373 | |
lypinator | 0:bb348c97df44 | 374 | /*Get BOR Level*/ |
lypinator | 0:bb348c97df44 | 375 | pOBInit->BORLevel = (uint32_t)FLASH_OB_GetBOR(); |
lypinator | 0:bb348c97df44 | 376 | } |
lypinator | 0:bb348c97df44 | 377 | |
lypinator | 0:bb348c97df44 | 378 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\ |
lypinator | 0:bb348c97df44 | 379 | defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) ||\ |
lypinator | 0:bb348c97df44 | 380 | defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F469xx) ||\ |
lypinator | 0:bb348c97df44 | 381 | defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\ |
lypinator | 0:bb348c97df44 | 382 | defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) |
lypinator | 0:bb348c97df44 | 383 | /** |
lypinator | 0:bb348c97df44 | 384 | * @brief Program option bytes |
lypinator | 0:bb348c97df44 | 385 | * @param pAdvOBInit pointer to an FLASH_AdvOBProgramInitTypeDef structure that |
lypinator | 0:bb348c97df44 | 386 | * contains the configuration information for the programming. |
lypinator | 0:bb348c97df44 | 387 | * |
lypinator | 0:bb348c97df44 | 388 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 389 | */ |
lypinator | 0:bb348c97df44 | 390 | HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram (FLASH_AdvOBProgramInitTypeDef *pAdvOBInit) |
lypinator | 0:bb348c97df44 | 391 | { |
lypinator | 0:bb348c97df44 | 392 | HAL_StatusTypeDef status = HAL_ERROR; |
lypinator | 0:bb348c97df44 | 393 | |
lypinator | 0:bb348c97df44 | 394 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 395 | assert_param(IS_OBEX(pAdvOBInit->OptionType)); |
lypinator | 0:bb348c97df44 | 396 | |
lypinator | 0:bb348c97df44 | 397 | /*Program PCROP option byte*/ |
lypinator | 0:bb348c97df44 | 398 | if(((pAdvOBInit->OptionType) & OPTIONBYTE_PCROP) == OPTIONBYTE_PCROP) |
lypinator | 0:bb348c97df44 | 399 | { |
lypinator | 0:bb348c97df44 | 400 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 401 | assert_param(IS_PCROPSTATE(pAdvOBInit->PCROPState)); |
lypinator | 0:bb348c97df44 | 402 | if((pAdvOBInit->PCROPState) == OB_PCROP_STATE_ENABLE) |
lypinator | 0:bb348c97df44 | 403 | { |
lypinator | 0:bb348c97df44 | 404 | /*Enable of Write protection on the selected Sector*/ |
lypinator | 0:bb348c97df44 | 405 | #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\ |
lypinator | 0:bb348c97df44 | 406 | defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\ |
lypinator | 0:bb348c97df44 | 407 | defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) |
lypinator | 0:bb348c97df44 | 408 | status = FLASH_OB_EnablePCROP(pAdvOBInit->Sectors); |
lypinator | 0:bb348c97df44 | 409 | #else /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx || STM32F469xx || STM32F479xx */ |
lypinator | 0:bb348c97df44 | 410 | status = FLASH_OB_EnablePCROP(pAdvOBInit->SectorsBank1, pAdvOBInit->SectorsBank2, pAdvOBInit->Banks); |
lypinator | 0:bb348c97df44 | 411 | #endif /* STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx || |
lypinator | 0:bb348c97df44 | 412 | STM32F413xx || STM32F423xx */ |
lypinator | 0:bb348c97df44 | 413 | } |
lypinator | 0:bb348c97df44 | 414 | else |
lypinator | 0:bb348c97df44 | 415 | { |
lypinator | 0:bb348c97df44 | 416 | /*Disable of Write protection on the selected Sector*/ |
lypinator | 0:bb348c97df44 | 417 | #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\ |
lypinator | 0:bb348c97df44 | 418 | defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\ |
lypinator | 0:bb348c97df44 | 419 | defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) |
lypinator | 0:bb348c97df44 | 420 | status = FLASH_OB_DisablePCROP(pAdvOBInit->Sectors); |
lypinator | 0:bb348c97df44 | 421 | #else /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx || STM32F469xx || STM32F479xx */ |
lypinator | 0:bb348c97df44 | 422 | status = FLASH_OB_DisablePCROP(pAdvOBInit->SectorsBank1, pAdvOBInit->SectorsBank2, pAdvOBInit->Banks); |
lypinator | 0:bb348c97df44 | 423 | #endif /* STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx || |
lypinator | 0:bb348c97df44 | 424 | STM32F413xx || STM32F423xx */ |
lypinator | 0:bb348c97df44 | 425 | } |
lypinator | 0:bb348c97df44 | 426 | } |
lypinator | 0:bb348c97df44 | 427 | |
lypinator | 0:bb348c97df44 | 428 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F469xx) || defined(STM32F479xx) |
lypinator | 0:bb348c97df44 | 429 | /*Program BOOT config option byte*/ |
lypinator | 0:bb348c97df44 | 430 | if(((pAdvOBInit->OptionType) & OPTIONBYTE_BOOTCONFIG) == OPTIONBYTE_BOOTCONFIG) |
lypinator | 0:bb348c97df44 | 431 | { |
lypinator | 0:bb348c97df44 | 432 | status = FLASH_OB_BootConfig(pAdvOBInit->BootConfig); |
lypinator | 0:bb348c97df44 | 433 | } |
lypinator | 0:bb348c97df44 | 434 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ |
lypinator | 0:bb348c97df44 | 435 | |
lypinator | 0:bb348c97df44 | 436 | return status; |
lypinator | 0:bb348c97df44 | 437 | } |
lypinator | 0:bb348c97df44 | 438 | |
lypinator | 0:bb348c97df44 | 439 | /** |
lypinator | 0:bb348c97df44 | 440 | * @brief Get the OBEX byte configuration |
lypinator | 0:bb348c97df44 | 441 | * @param pAdvOBInit pointer to an FLASH_AdvOBProgramInitTypeDef structure that |
lypinator | 0:bb348c97df44 | 442 | * contains the configuration information for the programming. |
lypinator | 0:bb348c97df44 | 443 | * |
lypinator | 0:bb348c97df44 | 444 | * @retval None |
lypinator | 0:bb348c97df44 | 445 | */ |
lypinator | 0:bb348c97df44 | 446 | void HAL_FLASHEx_AdvOBGetConfig(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit) |
lypinator | 0:bb348c97df44 | 447 | { |
lypinator | 0:bb348c97df44 | 448 | #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\ |
lypinator | 0:bb348c97df44 | 449 | defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\ |
lypinator | 0:bb348c97df44 | 450 | defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) |
lypinator | 0:bb348c97df44 | 451 | /*Get Sector*/ |
lypinator | 0:bb348c97df44 | 452 | pAdvOBInit->Sectors = (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS)); |
lypinator | 0:bb348c97df44 | 453 | #else /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx || STM32F469xx || STM32F479xx */ |
lypinator | 0:bb348c97df44 | 454 | /*Get Sector for Bank1*/ |
lypinator | 0:bb348c97df44 | 455 | pAdvOBInit->SectorsBank1 = (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS)); |
lypinator | 0:bb348c97df44 | 456 | |
lypinator | 0:bb348c97df44 | 457 | /*Get Sector for Bank2*/ |
lypinator | 0:bb348c97df44 | 458 | pAdvOBInit->SectorsBank2 = (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS)); |
lypinator | 0:bb348c97df44 | 459 | |
lypinator | 0:bb348c97df44 | 460 | /*Get Boot config OB*/ |
lypinator | 0:bb348c97df44 | 461 | pAdvOBInit->BootConfig = *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS; |
lypinator | 0:bb348c97df44 | 462 | #endif /* STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx || |
lypinator | 0:bb348c97df44 | 463 | STM32F413xx || STM32F423xx */ |
lypinator | 0:bb348c97df44 | 464 | } |
lypinator | 0:bb348c97df44 | 465 | |
lypinator | 0:bb348c97df44 | 466 | /** |
lypinator | 0:bb348c97df44 | 467 | * @brief Select the Protection Mode |
lypinator | 0:bb348c97df44 | 468 | * |
lypinator | 0:bb348c97df44 | 469 | * @note After PCROP activated Option Byte modification NOT POSSIBLE! excepted |
lypinator | 0:bb348c97df44 | 470 | * Global Read Out Protection modification (from level1 to level0) |
lypinator | 0:bb348c97df44 | 471 | * @note Once SPRMOD bit is active unprotection of a protected sector is not possible |
lypinator | 0:bb348c97df44 | 472 | * @note Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag |
lypinator | 0:bb348c97df44 | 473 | * @note This function can be used only for STM32F42xxx/STM32F43xxx/STM32F401xx/STM32F411xx/STM32F446xx/ |
lypinator | 0:bb348c97df44 | 474 | * STM32F469xx/STM32F479xx/STM32F412xx/STM32F413xx devices. |
lypinator | 0:bb348c97df44 | 475 | * |
lypinator | 0:bb348c97df44 | 476 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 477 | */ |
lypinator | 0:bb348c97df44 | 478 | HAL_StatusTypeDef HAL_FLASHEx_OB_SelectPCROP(void) |
lypinator | 0:bb348c97df44 | 479 | { |
lypinator | 0:bb348c97df44 | 480 | uint8_t optiontmp = 0xFF; |
lypinator | 0:bb348c97df44 | 481 | |
lypinator | 0:bb348c97df44 | 482 | /* Mask SPRMOD bit */ |
lypinator | 0:bb348c97df44 | 483 | optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE3_ADDRESS) & (uint8_t)0x7F); |
lypinator | 0:bb348c97df44 | 484 | |
lypinator | 0:bb348c97df44 | 485 | /* Update Option Byte */ |
lypinator | 0:bb348c97df44 | 486 | *(__IO uint8_t *)OPTCR_BYTE3_ADDRESS = (uint8_t)(OB_PCROP_SELECTED | optiontmp); |
lypinator | 0:bb348c97df44 | 487 | |
lypinator | 0:bb348c97df44 | 488 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 489 | } |
lypinator | 0:bb348c97df44 | 490 | |
lypinator | 0:bb348c97df44 | 491 | /** |
lypinator | 0:bb348c97df44 | 492 | * @brief Deselect the Protection Mode |
lypinator | 0:bb348c97df44 | 493 | * |
lypinator | 0:bb348c97df44 | 494 | * @note After PCROP activated Option Byte modification NOT POSSIBLE! excepted |
lypinator | 0:bb348c97df44 | 495 | * Global Read Out Protection modification (from level1 to level0) |
lypinator | 0:bb348c97df44 | 496 | * @note Once SPRMOD bit is active unprotection of a protected sector is not possible |
lypinator | 0:bb348c97df44 | 497 | * @note Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag |
lypinator | 0:bb348c97df44 | 498 | * @note This function can be used only for STM32F42xxx/STM32F43xxx/STM32F401xx/STM32F411xx/STM32F446xx/ |
lypinator | 0:bb348c97df44 | 499 | * STM32F469xx/STM32F479xx/STM32F412xx/STM32F413xx devices. |
lypinator | 0:bb348c97df44 | 500 | * |
lypinator | 0:bb348c97df44 | 501 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 502 | */ |
lypinator | 0:bb348c97df44 | 503 | HAL_StatusTypeDef HAL_FLASHEx_OB_DeSelectPCROP(void) |
lypinator | 0:bb348c97df44 | 504 | { |
lypinator | 0:bb348c97df44 | 505 | uint8_t optiontmp = 0xFF; |
lypinator | 0:bb348c97df44 | 506 | |
lypinator | 0:bb348c97df44 | 507 | /* Mask SPRMOD bit */ |
lypinator | 0:bb348c97df44 | 508 | optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE3_ADDRESS) & (uint8_t)0x7F); |
lypinator | 0:bb348c97df44 | 509 | |
lypinator | 0:bb348c97df44 | 510 | /* Update Option Byte */ |
lypinator | 0:bb348c97df44 | 511 | *(__IO uint8_t *)OPTCR_BYTE3_ADDRESS = (uint8_t)(OB_PCROP_DESELECTED | optiontmp); |
lypinator | 0:bb348c97df44 | 512 | |
lypinator | 0:bb348c97df44 | 513 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 514 | } |
lypinator | 0:bb348c97df44 | 515 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F401xC || STM32F401xE || STM32F410xx ||\ |
lypinator | 0:bb348c97df44 | 516 | STM32F411xE || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx || |
lypinator | 0:bb348c97df44 | 517 | STM32F413xx || STM32F423xx */ |
lypinator | 0:bb348c97df44 | 518 | |
lypinator | 0:bb348c97df44 | 519 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) || defined(STM32F469xx) || defined(STM32F479xx) |
lypinator | 0:bb348c97df44 | 520 | /** |
lypinator | 0:bb348c97df44 | 521 | * @brief Returns the FLASH Write Protection Option Bytes value for Bank 2 |
lypinator | 0:bb348c97df44 | 522 | * @note This function can be used only for STM32F42xxx/STM32F43xxx/STM32F469xx/STM32F479xx devices. |
lypinator | 0:bb348c97df44 | 523 | * @retval The FLASH Write Protection Option Bytes value |
lypinator | 0:bb348c97df44 | 524 | */ |
lypinator | 0:bb348c97df44 | 525 | uint16_t HAL_FLASHEx_OB_GetBank2WRP(void) |
lypinator | 0:bb348c97df44 | 526 | { |
lypinator | 0:bb348c97df44 | 527 | /* Return the FLASH write protection Register value */ |
lypinator | 0:bb348c97df44 | 528 | return (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS)); |
lypinator | 0:bb348c97df44 | 529 | } |
lypinator | 0:bb348c97df44 | 530 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ |
lypinator | 0:bb348c97df44 | 531 | |
lypinator | 0:bb348c97df44 | 532 | /** |
lypinator | 0:bb348c97df44 | 533 | * @} |
lypinator | 0:bb348c97df44 | 534 | */ |
lypinator | 0:bb348c97df44 | 535 | |
lypinator | 0:bb348c97df44 | 536 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F469xx) || defined(STM32F479xx) |
lypinator | 0:bb348c97df44 | 537 | /** |
lypinator | 0:bb348c97df44 | 538 | * @brief Full erase of FLASH memory sectors |
lypinator | 0:bb348c97df44 | 539 | * @param VoltageRange The device voltage range which defines the erase parallelism. |
lypinator | 0:bb348c97df44 | 540 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 541 | * @arg FLASH_VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V, |
lypinator | 0:bb348c97df44 | 542 | * the operation will be done by byte (8-bit) |
lypinator | 0:bb348c97df44 | 543 | * @arg FLASH_VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V, |
lypinator | 0:bb348c97df44 | 544 | * the operation will be done by half word (16-bit) |
lypinator | 0:bb348c97df44 | 545 | * @arg FLASH_VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V, |
lypinator | 0:bb348c97df44 | 546 | * the operation will be done by word (32-bit) |
lypinator | 0:bb348c97df44 | 547 | * @arg FLASH_VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp, |
lypinator | 0:bb348c97df44 | 548 | * the operation will be done by double word (64-bit) |
lypinator | 0:bb348c97df44 | 549 | * |
lypinator | 0:bb348c97df44 | 550 | * @param Banks Banks to be erased |
lypinator | 0:bb348c97df44 | 551 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 552 | * @arg FLASH_BANK_1: Bank1 to be erased |
lypinator | 0:bb348c97df44 | 553 | * @arg FLASH_BANK_2: Bank2 to be erased |
lypinator | 0:bb348c97df44 | 554 | * @arg FLASH_BANK_BOTH: Bank1 and Bank2 to be erased |
lypinator | 0:bb348c97df44 | 555 | * |
lypinator | 0:bb348c97df44 | 556 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 557 | */ |
lypinator | 0:bb348c97df44 | 558 | static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks) |
lypinator | 0:bb348c97df44 | 559 | { |
lypinator | 0:bb348c97df44 | 560 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 561 | assert_param(IS_VOLTAGERANGE(VoltageRange)); |
lypinator | 0:bb348c97df44 | 562 | assert_param(IS_FLASH_BANK(Banks)); |
lypinator | 0:bb348c97df44 | 563 | |
lypinator | 0:bb348c97df44 | 564 | /* if the previous operation is completed, proceed to erase all sectors */ |
lypinator | 0:bb348c97df44 | 565 | CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE); |
lypinator | 0:bb348c97df44 | 566 | |
lypinator | 0:bb348c97df44 | 567 | if(Banks == FLASH_BANK_BOTH) |
lypinator | 0:bb348c97df44 | 568 | { |
lypinator | 0:bb348c97df44 | 569 | /* bank1 & bank2 will be erased*/ |
lypinator | 0:bb348c97df44 | 570 | FLASH->CR |= FLASH_MER_BIT; |
lypinator | 0:bb348c97df44 | 571 | } |
lypinator | 0:bb348c97df44 | 572 | else if(Banks == FLASH_BANK_1) |
lypinator | 0:bb348c97df44 | 573 | { |
lypinator | 0:bb348c97df44 | 574 | /*Only bank1 will be erased*/ |
lypinator | 0:bb348c97df44 | 575 | FLASH->CR |= FLASH_CR_MER1; |
lypinator | 0:bb348c97df44 | 576 | } |
lypinator | 0:bb348c97df44 | 577 | else |
lypinator | 0:bb348c97df44 | 578 | { |
lypinator | 0:bb348c97df44 | 579 | /*Only bank2 will be erased*/ |
lypinator | 0:bb348c97df44 | 580 | FLASH->CR |= FLASH_CR_MER2; |
lypinator | 0:bb348c97df44 | 581 | } |
lypinator | 0:bb348c97df44 | 582 | FLASH->CR |= FLASH_CR_STRT | ((uint32_t)VoltageRange <<8U); |
lypinator | 0:bb348c97df44 | 583 | } |
lypinator | 0:bb348c97df44 | 584 | |
lypinator | 0:bb348c97df44 | 585 | /** |
lypinator | 0:bb348c97df44 | 586 | * @brief Erase the specified FLASH memory sector |
lypinator | 0:bb348c97df44 | 587 | * @param Sector FLASH sector to erase |
lypinator | 0:bb348c97df44 | 588 | * The value of this parameter depend on device used within the same series |
lypinator | 0:bb348c97df44 | 589 | * @param VoltageRange The device voltage range which defines the erase parallelism. |
lypinator | 0:bb348c97df44 | 590 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 591 | * @arg FLASH_VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V, |
lypinator | 0:bb348c97df44 | 592 | * the operation will be done by byte (8-bit) |
lypinator | 0:bb348c97df44 | 593 | * @arg FLASH_VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V, |
lypinator | 0:bb348c97df44 | 594 | * the operation will be done by half word (16-bit) |
lypinator | 0:bb348c97df44 | 595 | * @arg FLASH_VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V, |
lypinator | 0:bb348c97df44 | 596 | * the operation will be done by word (32-bit) |
lypinator | 0:bb348c97df44 | 597 | * @arg FLASH_VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp, |
lypinator | 0:bb348c97df44 | 598 | * the operation will be done by double word (64-bit) |
lypinator | 0:bb348c97df44 | 599 | * |
lypinator | 0:bb348c97df44 | 600 | * @retval None |
lypinator | 0:bb348c97df44 | 601 | */ |
lypinator | 0:bb348c97df44 | 602 | void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange) |
lypinator | 0:bb348c97df44 | 603 | { |
lypinator | 0:bb348c97df44 | 604 | uint32_t tmp_psize = 0U; |
lypinator | 0:bb348c97df44 | 605 | |
lypinator | 0:bb348c97df44 | 606 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 607 | assert_param(IS_FLASH_SECTOR(Sector)); |
lypinator | 0:bb348c97df44 | 608 | assert_param(IS_VOLTAGERANGE(VoltageRange)); |
lypinator | 0:bb348c97df44 | 609 | |
lypinator | 0:bb348c97df44 | 610 | if(VoltageRange == FLASH_VOLTAGE_RANGE_1) |
lypinator | 0:bb348c97df44 | 611 | { |
lypinator | 0:bb348c97df44 | 612 | tmp_psize = FLASH_PSIZE_BYTE; |
lypinator | 0:bb348c97df44 | 613 | } |
lypinator | 0:bb348c97df44 | 614 | else if(VoltageRange == FLASH_VOLTAGE_RANGE_2) |
lypinator | 0:bb348c97df44 | 615 | { |
lypinator | 0:bb348c97df44 | 616 | tmp_psize = FLASH_PSIZE_HALF_WORD; |
lypinator | 0:bb348c97df44 | 617 | } |
lypinator | 0:bb348c97df44 | 618 | else if(VoltageRange == FLASH_VOLTAGE_RANGE_3) |
lypinator | 0:bb348c97df44 | 619 | { |
lypinator | 0:bb348c97df44 | 620 | tmp_psize = FLASH_PSIZE_WORD; |
lypinator | 0:bb348c97df44 | 621 | } |
lypinator | 0:bb348c97df44 | 622 | else |
lypinator | 0:bb348c97df44 | 623 | { |
lypinator | 0:bb348c97df44 | 624 | tmp_psize = FLASH_PSIZE_DOUBLE_WORD; |
lypinator | 0:bb348c97df44 | 625 | } |
lypinator | 0:bb348c97df44 | 626 | |
lypinator | 0:bb348c97df44 | 627 | /* Need to add offset of 4 when sector higher than FLASH_SECTOR_11 */ |
lypinator | 0:bb348c97df44 | 628 | if(Sector > FLASH_SECTOR_11) |
lypinator | 0:bb348c97df44 | 629 | { |
lypinator | 0:bb348c97df44 | 630 | Sector += 4U; |
lypinator | 0:bb348c97df44 | 631 | } |
lypinator | 0:bb348c97df44 | 632 | /* If the previous operation is completed, proceed to erase the sector */ |
lypinator | 0:bb348c97df44 | 633 | CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE); |
lypinator | 0:bb348c97df44 | 634 | FLASH->CR |= tmp_psize; |
lypinator | 0:bb348c97df44 | 635 | CLEAR_BIT(FLASH->CR, FLASH_CR_SNB); |
lypinator | 0:bb348c97df44 | 636 | FLASH->CR |= FLASH_CR_SER | (Sector << FLASH_CR_SNB_Pos); |
lypinator | 0:bb348c97df44 | 637 | FLASH->CR |= FLASH_CR_STRT; |
lypinator | 0:bb348c97df44 | 638 | } |
lypinator | 0:bb348c97df44 | 639 | |
lypinator | 0:bb348c97df44 | 640 | /** |
lypinator | 0:bb348c97df44 | 641 | * @brief Enable the write protection of the desired bank1 or bank 2 sectors |
lypinator | 0:bb348c97df44 | 642 | * |
lypinator | 0:bb348c97df44 | 643 | * @note When the memory read protection level is selected (RDP level = 1), |
lypinator | 0:bb348c97df44 | 644 | * it is not possible to program or erase the flash sector i if CortexM4 |
lypinator | 0:bb348c97df44 | 645 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
lypinator | 0:bb348c97df44 | 646 | * @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1). |
lypinator | 0:bb348c97df44 | 647 | * |
lypinator | 0:bb348c97df44 | 648 | * @param WRPSector specifies the sector(s) to be write protected. |
lypinator | 0:bb348c97df44 | 649 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 650 | * @arg WRPSector: A value between OB_WRP_SECTOR_0 and OB_WRP_SECTOR_23 |
lypinator | 0:bb348c97df44 | 651 | * @arg OB_WRP_SECTOR_All |
lypinator | 0:bb348c97df44 | 652 | * @note BANK2 starts from OB_WRP_SECTOR_12 |
lypinator | 0:bb348c97df44 | 653 | * |
lypinator | 0:bb348c97df44 | 654 | * @param Banks Enable write protection on all the sectors for the specific bank |
lypinator | 0:bb348c97df44 | 655 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 656 | * @arg FLASH_BANK_1: WRP on all sectors of bank1 |
lypinator | 0:bb348c97df44 | 657 | * @arg FLASH_BANK_2: WRP on all sectors of bank2 |
lypinator | 0:bb348c97df44 | 658 | * @arg FLASH_BANK_BOTH: WRP on all sectors of bank1 & bank2 |
lypinator | 0:bb348c97df44 | 659 | * |
lypinator | 0:bb348c97df44 | 660 | * @retval HAL FLASH State |
lypinator | 0:bb348c97df44 | 661 | */ |
lypinator | 0:bb348c97df44 | 662 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks) |
lypinator | 0:bb348c97df44 | 663 | { |
lypinator | 0:bb348c97df44 | 664 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 665 | |
lypinator | 0:bb348c97df44 | 666 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 667 | assert_param(IS_OB_WRP_SECTOR(WRPSector)); |
lypinator | 0:bb348c97df44 | 668 | assert_param(IS_FLASH_BANK(Banks)); |
lypinator | 0:bb348c97df44 | 669 | |
lypinator | 0:bb348c97df44 | 670 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 671 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 672 | |
lypinator | 0:bb348c97df44 | 673 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 674 | { |
lypinator | 0:bb348c97df44 | 675 | if(((WRPSector == OB_WRP_SECTOR_All) && ((Banks == FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH))) || |
lypinator | 0:bb348c97df44 | 676 | (WRPSector < OB_WRP_SECTOR_12)) |
lypinator | 0:bb348c97df44 | 677 | { |
lypinator | 0:bb348c97df44 | 678 | if(WRPSector == OB_WRP_SECTOR_All) |
lypinator | 0:bb348c97df44 | 679 | { |
lypinator | 0:bb348c97df44 | 680 | /*Write protection on all sector of BANK1*/ |
lypinator | 0:bb348c97df44 | 681 | *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~(WRPSector>>12)); |
lypinator | 0:bb348c97df44 | 682 | } |
lypinator | 0:bb348c97df44 | 683 | else |
lypinator | 0:bb348c97df44 | 684 | { |
lypinator | 0:bb348c97df44 | 685 | /*Write protection done on sectors of BANK1*/ |
lypinator | 0:bb348c97df44 | 686 | *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~WRPSector); |
lypinator | 0:bb348c97df44 | 687 | } |
lypinator | 0:bb348c97df44 | 688 | } |
lypinator | 0:bb348c97df44 | 689 | else |
lypinator | 0:bb348c97df44 | 690 | { |
lypinator | 0:bb348c97df44 | 691 | /*Write protection done on sectors of BANK2*/ |
lypinator | 0:bb348c97df44 | 692 | *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~(WRPSector>>12)); |
lypinator | 0:bb348c97df44 | 693 | } |
lypinator | 0:bb348c97df44 | 694 | |
lypinator | 0:bb348c97df44 | 695 | /*Write protection on all sector of BANK2*/ |
lypinator | 0:bb348c97df44 | 696 | if((WRPSector == OB_WRP_SECTOR_All) && (Banks == FLASH_BANK_BOTH)) |
lypinator | 0:bb348c97df44 | 697 | { |
lypinator | 0:bb348c97df44 | 698 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 699 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 700 | |
lypinator | 0:bb348c97df44 | 701 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 702 | { |
lypinator | 0:bb348c97df44 | 703 | *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~(WRPSector>>12)); |
lypinator | 0:bb348c97df44 | 704 | } |
lypinator | 0:bb348c97df44 | 705 | } |
lypinator | 0:bb348c97df44 | 706 | |
lypinator | 0:bb348c97df44 | 707 | } |
lypinator | 0:bb348c97df44 | 708 | return status; |
lypinator | 0:bb348c97df44 | 709 | } |
lypinator | 0:bb348c97df44 | 710 | |
lypinator | 0:bb348c97df44 | 711 | /** |
lypinator | 0:bb348c97df44 | 712 | * @brief Disable the write protection of the desired bank1 or bank 2 sectors |
lypinator | 0:bb348c97df44 | 713 | * |
lypinator | 0:bb348c97df44 | 714 | * @note When the memory read protection level is selected (RDP level = 1), |
lypinator | 0:bb348c97df44 | 715 | * it is not possible to program or erase the flash sector i if CortexM4 |
lypinator | 0:bb348c97df44 | 716 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
lypinator | 0:bb348c97df44 | 717 | * @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1). |
lypinator | 0:bb348c97df44 | 718 | * |
lypinator | 0:bb348c97df44 | 719 | * @param WRPSector specifies the sector(s) to be write protected. |
lypinator | 0:bb348c97df44 | 720 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 721 | * @arg WRPSector: A value between OB_WRP_SECTOR_0 and OB_WRP_SECTOR_23 |
lypinator | 0:bb348c97df44 | 722 | * @arg OB_WRP_Sector_All |
lypinator | 0:bb348c97df44 | 723 | * @note BANK2 starts from OB_WRP_SECTOR_12 |
lypinator | 0:bb348c97df44 | 724 | * |
lypinator | 0:bb348c97df44 | 725 | * @param Banks Disable write protection on all the sectors for the specific bank |
lypinator | 0:bb348c97df44 | 726 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 727 | * @arg FLASH_BANK_1: Bank1 to be erased |
lypinator | 0:bb348c97df44 | 728 | * @arg FLASH_BANK_2: Bank2 to be erased |
lypinator | 0:bb348c97df44 | 729 | * @arg FLASH_BANK_BOTH: Bank1 and Bank2 to be erased |
lypinator | 0:bb348c97df44 | 730 | * |
lypinator | 0:bb348c97df44 | 731 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 732 | */ |
lypinator | 0:bb348c97df44 | 733 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks) |
lypinator | 0:bb348c97df44 | 734 | { |
lypinator | 0:bb348c97df44 | 735 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 736 | |
lypinator | 0:bb348c97df44 | 737 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 738 | assert_param(IS_OB_WRP_SECTOR(WRPSector)); |
lypinator | 0:bb348c97df44 | 739 | assert_param(IS_FLASH_BANK(Banks)); |
lypinator | 0:bb348c97df44 | 740 | |
lypinator | 0:bb348c97df44 | 741 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 742 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 743 | |
lypinator | 0:bb348c97df44 | 744 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 745 | { |
lypinator | 0:bb348c97df44 | 746 | if(((WRPSector == OB_WRP_SECTOR_All) && ((Banks == FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH))) || |
lypinator | 0:bb348c97df44 | 747 | (WRPSector < OB_WRP_SECTOR_12)) |
lypinator | 0:bb348c97df44 | 748 | { |
lypinator | 0:bb348c97df44 | 749 | if(WRPSector == OB_WRP_SECTOR_All) |
lypinator | 0:bb348c97df44 | 750 | { |
lypinator | 0:bb348c97df44 | 751 | /*Write protection on all sector of BANK1*/ |
lypinator | 0:bb348c97df44 | 752 | *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)(WRPSector>>12); |
lypinator | 0:bb348c97df44 | 753 | } |
lypinator | 0:bb348c97df44 | 754 | else |
lypinator | 0:bb348c97df44 | 755 | { |
lypinator | 0:bb348c97df44 | 756 | /*Write protection done on sectors of BANK1*/ |
lypinator | 0:bb348c97df44 | 757 | *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)WRPSector; |
lypinator | 0:bb348c97df44 | 758 | } |
lypinator | 0:bb348c97df44 | 759 | } |
lypinator | 0:bb348c97df44 | 760 | else |
lypinator | 0:bb348c97df44 | 761 | { |
lypinator | 0:bb348c97df44 | 762 | /*Write protection done on sectors of BANK2*/ |
lypinator | 0:bb348c97df44 | 763 | *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)(WRPSector>>12); |
lypinator | 0:bb348c97df44 | 764 | } |
lypinator | 0:bb348c97df44 | 765 | |
lypinator | 0:bb348c97df44 | 766 | /*Write protection on all sector of BANK2*/ |
lypinator | 0:bb348c97df44 | 767 | if((WRPSector == OB_WRP_SECTOR_All) && (Banks == FLASH_BANK_BOTH)) |
lypinator | 0:bb348c97df44 | 768 | { |
lypinator | 0:bb348c97df44 | 769 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 770 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 771 | |
lypinator | 0:bb348c97df44 | 772 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 773 | { |
lypinator | 0:bb348c97df44 | 774 | *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)(WRPSector>>12); |
lypinator | 0:bb348c97df44 | 775 | } |
lypinator | 0:bb348c97df44 | 776 | } |
lypinator | 0:bb348c97df44 | 777 | |
lypinator | 0:bb348c97df44 | 778 | } |
lypinator | 0:bb348c97df44 | 779 | |
lypinator | 0:bb348c97df44 | 780 | return status; |
lypinator | 0:bb348c97df44 | 781 | } |
lypinator | 0:bb348c97df44 | 782 | |
lypinator | 0:bb348c97df44 | 783 | /** |
lypinator | 0:bb348c97df44 | 784 | * @brief Configure the Dual Bank Boot. |
lypinator | 0:bb348c97df44 | 785 | * |
lypinator | 0:bb348c97df44 | 786 | * @note This function can be used only for STM32F42xxx/43xxx devices. |
lypinator | 0:bb348c97df44 | 787 | * |
lypinator | 0:bb348c97df44 | 788 | * @param BootConfig specifies the Dual Bank Boot Option byte. |
lypinator | 0:bb348c97df44 | 789 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 790 | * @arg OB_Dual_BootEnabled: Dual Bank Boot Enable |
lypinator | 0:bb348c97df44 | 791 | * @arg OB_Dual_BootDisabled: Dual Bank Boot Disabled |
lypinator | 0:bb348c97df44 | 792 | * @retval None |
lypinator | 0:bb348c97df44 | 793 | */ |
lypinator | 0:bb348c97df44 | 794 | static HAL_StatusTypeDef FLASH_OB_BootConfig(uint8_t BootConfig) |
lypinator | 0:bb348c97df44 | 795 | { |
lypinator | 0:bb348c97df44 | 796 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 797 | |
lypinator | 0:bb348c97df44 | 798 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 799 | assert_param(IS_OB_BOOT(BootConfig)); |
lypinator | 0:bb348c97df44 | 800 | |
lypinator | 0:bb348c97df44 | 801 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 802 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 803 | |
lypinator | 0:bb348c97df44 | 804 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 805 | { |
lypinator | 0:bb348c97df44 | 806 | /* Set Dual Bank Boot */ |
lypinator | 0:bb348c97df44 | 807 | *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS &= (~FLASH_OPTCR_BFB2); |
lypinator | 0:bb348c97df44 | 808 | *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS |= BootConfig; |
lypinator | 0:bb348c97df44 | 809 | } |
lypinator | 0:bb348c97df44 | 810 | |
lypinator | 0:bb348c97df44 | 811 | return status; |
lypinator | 0:bb348c97df44 | 812 | } |
lypinator | 0:bb348c97df44 | 813 | |
lypinator | 0:bb348c97df44 | 814 | /** |
lypinator | 0:bb348c97df44 | 815 | * @brief Enable the read/write protection (PCROP) of the desired |
lypinator | 0:bb348c97df44 | 816 | * sectors of Bank 1 and/or Bank 2. |
lypinator | 0:bb348c97df44 | 817 | * @note This function can be used only for STM32F42xxx/43xxx devices. |
lypinator | 0:bb348c97df44 | 818 | * @param SectorBank1 Specifies the sector(s) to be read/write protected or unprotected for bank1. |
lypinator | 0:bb348c97df44 | 819 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 820 | * @arg OB_PCROP: A value between OB_PCROP_SECTOR_0 and OB_PCROP_SECTOR_11 |
lypinator | 0:bb348c97df44 | 821 | * @arg OB_PCROP_SECTOR__All |
lypinator | 0:bb348c97df44 | 822 | * @param SectorBank2 Specifies the sector(s) to be read/write protected or unprotected for bank2. |
lypinator | 0:bb348c97df44 | 823 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 824 | * @arg OB_PCROP: A value between OB_PCROP_SECTOR_12 and OB_PCROP_SECTOR_23 |
lypinator | 0:bb348c97df44 | 825 | * @arg OB_PCROP_SECTOR__All |
lypinator | 0:bb348c97df44 | 826 | * @param Banks Enable PCROP protection on all the sectors for the specific bank |
lypinator | 0:bb348c97df44 | 827 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 828 | * @arg FLASH_BANK_1: WRP on all sectors of bank1 |
lypinator | 0:bb348c97df44 | 829 | * @arg FLASH_BANK_2: WRP on all sectors of bank2 |
lypinator | 0:bb348c97df44 | 830 | * @arg FLASH_BANK_BOTH: WRP on all sectors of bank1 & bank2 |
lypinator | 0:bb348c97df44 | 831 | * |
lypinator | 0:bb348c97df44 | 832 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 833 | */ |
lypinator | 0:bb348c97df44 | 834 | static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks) |
lypinator | 0:bb348c97df44 | 835 | { |
lypinator | 0:bb348c97df44 | 836 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 837 | |
lypinator | 0:bb348c97df44 | 838 | assert_param(IS_FLASH_BANK(Banks)); |
lypinator | 0:bb348c97df44 | 839 | |
lypinator | 0:bb348c97df44 | 840 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 841 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 842 | |
lypinator | 0:bb348c97df44 | 843 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 844 | { |
lypinator | 0:bb348c97df44 | 845 | if((Banks == FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH)) |
lypinator | 0:bb348c97df44 | 846 | { |
lypinator | 0:bb348c97df44 | 847 | assert_param(IS_OB_PCROP(SectorBank1)); |
lypinator | 0:bb348c97df44 | 848 | /*Write protection done on sectors of BANK1*/ |
lypinator | 0:bb348c97df44 | 849 | *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)SectorBank1; |
lypinator | 0:bb348c97df44 | 850 | } |
lypinator | 0:bb348c97df44 | 851 | else |
lypinator | 0:bb348c97df44 | 852 | { |
lypinator | 0:bb348c97df44 | 853 | assert_param(IS_OB_PCROP(SectorBank2)); |
lypinator | 0:bb348c97df44 | 854 | /*Write protection done on sectors of BANK2*/ |
lypinator | 0:bb348c97df44 | 855 | *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)SectorBank2; |
lypinator | 0:bb348c97df44 | 856 | } |
lypinator | 0:bb348c97df44 | 857 | |
lypinator | 0:bb348c97df44 | 858 | /*Write protection on all sector of BANK2*/ |
lypinator | 0:bb348c97df44 | 859 | if(Banks == FLASH_BANK_BOTH) |
lypinator | 0:bb348c97df44 | 860 | { |
lypinator | 0:bb348c97df44 | 861 | assert_param(IS_OB_PCROP(SectorBank2)); |
lypinator | 0:bb348c97df44 | 862 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 863 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 864 | |
lypinator | 0:bb348c97df44 | 865 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 866 | { |
lypinator | 0:bb348c97df44 | 867 | /*Write protection done on sectors of BANK2*/ |
lypinator | 0:bb348c97df44 | 868 | *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)SectorBank2; |
lypinator | 0:bb348c97df44 | 869 | } |
lypinator | 0:bb348c97df44 | 870 | } |
lypinator | 0:bb348c97df44 | 871 | |
lypinator | 0:bb348c97df44 | 872 | } |
lypinator | 0:bb348c97df44 | 873 | |
lypinator | 0:bb348c97df44 | 874 | return status; |
lypinator | 0:bb348c97df44 | 875 | } |
lypinator | 0:bb348c97df44 | 876 | |
lypinator | 0:bb348c97df44 | 877 | |
lypinator | 0:bb348c97df44 | 878 | /** |
lypinator | 0:bb348c97df44 | 879 | * @brief Disable the read/write protection (PCROP) of the desired |
lypinator | 0:bb348c97df44 | 880 | * sectors of Bank 1 and/or Bank 2. |
lypinator | 0:bb348c97df44 | 881 | * @note This function can be used only for STM32F42xxx/43xxx devices. |
lypinator | 0:bb348c97df44 | 882 | * @param SectorBank1 specifies the sector(s) to be read/write protected or unprotected for bank1. |
lypinator | 0:bb348c97df44 | 883 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 884 | * @arg OB_PCROP: A value between OB_PCROP_SECTOR_0 and OB_PCROP_SECTOR_11 |
lypinator | 0:bb348c97df44 | 885 | * @arg OB_PCROP_SECTOR__All |
lypinator | 0:bb348c97df44 | 886 | * @param SectorBank2 Specifies the sector(s) to be read/write protected or unprotected for bank2. |
lypinator | 0:bb348c97df44 | 887 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 888 | * @arg OB_PCROP: A value between OB_PCROP_SECTOR_12 and OB_PCROP_SECTOR_23 |
lypinator | 0:bb348c97df44 | 889 | * @arg OB_PCROP_SECTOR__All |
lypinator | 0:bb348c97df44 | 890 | * @param Banks Disable PCROP protection on all the sectors for the specific bank |
lypinator | 0:bb348c97df44 | 891 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 892 | * @arg FLASH_BANK_1: WRP on all sectors of bank1 |
lypinator | 0:bb348c97df44 | 893 | * @arg FLASH_BANK_2: WRP on all sectors of bank2 |
lypinator | 0:bb348c97df44 | 894 | * @arg FLASH_BANK_BOTH: WRP on all sectors of bank1 & bank2 |
lypinator | 0:bb348c97df44 | 895 | * |
lypinator | 0:bb348c97df44 | 896 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 897 | */ |
lypinator | 0:bb348c97df44 | 898 | static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks) |
lypinator | 0:bb348c97df44 | 899 | { |
lypinator | 0:bb348c97df44 | 900 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 901 | |
lypinator | 0:bb348c97df44 | 902 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 903 | assert_param(IS_FLASH_BANK(Banks)); |
lypinator | 0:bb348c97df44 | 904 | |
lypinator | 0:bb348c97df44 | 905 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 906 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 907 | |
lypinator | 0:bb348c97df44 | 908 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 909 | { |
lypinator | 0:bb348c97df44 | 910 | if((Banks == FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH)) |
lypinator | 0:bb348c97df44 | 911 | { |
lypinator | 0:bb348c97df44 | 912 | assert_param(IS_OB_PCROP(SectorBank1)); |
lypinator | 0:bb348c97df44 | 913 | /*Write protection done on sectors of BANK1*/ |
lypinator | 0:bb348c97df44 | 914 | *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~SectorBank1); |
lypinator | 0:bb348c97df44 | 915 | } |
lypinator | 0:bb348c97df44 | 916 | else |
lypinator | 0:bb348c97df44 | 917 | { |
lypinator | 0:bb348c97df44 | 918 | /*Write protection done on sectors of BANK2*/ |
lypinator | 0:bb348c97df44 | 919 | assert_param(IS_OB_PCROP(SectorBank2)); |
lypinator | 0:bb348c97df44 | 920 | *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~SectorBank2); |
lypinator | 0:bb348c97df44 | 921 | } |
lypinator | 0:bb348c97df44 | 922 | |
lypinator | 0:bb348c97df44 | 923 | /*Write protection on all sector of BANK2*/ |
lypinator | 0:bb348c97df44 | 924 | if(Banks == FLASH_BANK_BOTH) |
lypinator | 0:bb348c97df44 | 925 | { |
lypinator | 0:bb348c97df44 | 926 | assert_param(IS_OB_PCROP(SectorBank2)); |
lypinator | 0:bb348c97df44 | 927 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 928 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 929 | |
lypinator | 0:bb348c97df44 | 930 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 931 | { |
lypinator | 0:bb348c97df44 | 932 | /*Write protection done on sectors of BANK2*/ |
lypinator | 0:bb348c97df44 | 933 | *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~SectorBank2); |
lypinator | 0:bb348c97df44 | 934 | } |
lypinator | 0:bb348c97df44 | 935 | } |
lypinator | 0:bb348c97df44 | 936 | |
lypinator | 0:bb348c97df44 | 937 | } |
lypinator | 0:bb348c97df44 | 938 | |
lypinator | 0:bb348c97df44 | 939 | return status; |
lypinator | 0:bb348c97df44 | 940 | |
lypinator | 0:bb348c97df44 | 941 | } |
lypinator | 0:bb348c97df44 | 942 | |
lypinator | 0:bb348c97df44 | 943 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ |
lypinator | 0:bb348c97df44 | 944 | |
lypinator | 0:bb348c97df44 | 945 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\ |
lypinator | 0:bb348c97df44 | 946 | defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) ||\ |
lypinator | 0:bb348c97df44 | 947 | defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ |
lypinator | 0:bb348c97df44 | 948 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) ||\ |
lypinator | 0:bb348c97df44 | 949 | defined(STM32F423xx) |
lypinator | 0:bb348c97df44 | 950 | /** |
lypinator | 0:bb348c97df44 | 951 | * @brief Mass erase of FLASH memory |
lypinator | 0:bb348c97df44 | 952 | * @param VoltageRange The device voltage range which defines the erase parallelism. |
lypinator | 0:bb348c97df44 | 953 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 954 | * @arg FLASH_VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V, |
lypinator | 0:bb348c97df44 | 955 | * the operation will be done by byte (8-bit) |
lypinator | 0:bb348c97df44 | 956 | * @arg FLASH_VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V, |
lypinator | 0:bb348c97df44 | 957 | * the operation will be done by half word (16-bit) |
lypinator | 0:bb348c97df44 | 958 | * @arg FLASH_VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V, |
lypinator | 0:bb348c97df44 | 959 | * the operation will be done by word (32-bit) |
lypinator | 0:bb348c97df44 | 960 | * @arg FLASH_VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp, |
lypinator | 0:bb348c97df44 | 961 | * the operation will be done by double word (64-bit) |
lypinator | 0:bb348c97df44 | 962 | * |
lypinator | 0:bb348c97df44 | 963 | * @param Banks Banks to be erased |
lypinator | 0:bb348c97df44 | 964 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 965 | * @arg FLASH_BANK_1: Bank1 to be erased |
lypinator | 0:bb348c97df44 | 966 | * |
lypinator | 0:bb348c97df44 | 967 | * @retval None |
lypinator | 0:bb348c97df44 | 968 | */ |
lypinator | 0:bb348c97df44 | 969 | static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks) |
lypinator | 0:bb348c97df44 | 970 | { |
lypinator | 0:bb348c97df44 | 971 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 972 | assert_param(IS_VOLTAGERANGE(VoltageRange)); |
lypinator | 0:bb348c97df44 | 973 | assert_param(IS_FLASH_BANK(Banks)); |
lypinator | 0:bb348c97df44 | 974 | |
lypinator | 0:bb348c97df44 | 975 | /* If the previous operation is completed, proceed to erase all sectors */ |
lypinator | 0:bb348c97df44 | 976 | CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE); |
lypinator | 0:bb348c97df44 | 977 | FLASH->CR |= FLASH_CR_MER; |
lypinator | 0:bb348c97df44 | 978 | FLASH->CR |= FLASH_CR_STRT | ((uint32_t)VoltageRange <<8U); |
lypinator | 0:bb348c97df44 | 979 | } |
lypinator | 0:bb348c97df44 | 980 | |
lypinator | 0:bb348c97df44 | 981 | /** |
lypinator | 0:bb348c97df44 | 982 | * @brief Erase the specified FLASH memory sector |
lypinator | 0:bb348c97df44 | 983 | * @param Sector FLASH sector to erase |
lypinator | 0:bb348c97df44 | 984 | * The value of this parameter depend on device used within the same series |
lypinator | 0:bb348c97df44 | 985 | * @param VoltageRange The device voltage range which defines the erase parallelism. |
lypinator | 0:bb348c97df44 | 986 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 987 | * @arg FLASH_VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V, |
lypinator | 0:bb348c97df44 | 988 | * the operation will be done by byte (8-bit) |
lypinator | 0:bb348c97df44 | 989 | * @arg FLASH_VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V, |
lypinator | 0:bb348c97df44 | 990 | * the operation will be done by half word (16-bit) |
lypinator | 0:bb348c97df44 | 991 | * @arg FLASH_VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V, |
lypinator | 0:bb348c97df44 | 992 | * the operation will be done by word (32-bit) |
lypinator | 0:bb348c97df44 | 993 | * @arg FLASH_VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp, |
lypinator | 0:bb348c97df44 | 994 | * the operation will be done by double word (64-bit) |
lypinator | 0:bb348c97df44 | 995 | * |
lypinator | 0:bb348c97df44 | 996 | * @retval None |
lypinator | 0:bb348c97df44 | 997 | */ |
lypinator | 0:bb348c97df44 | 998 | void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange) |
lypinator | 0:bb348c97df44 | 999 | { |
lypinator | 0:bb348c97df44 | 1000 | uint32_t tmp_psize = 0U; |
lypinator | 0:bb348c97df44 | 1001 | |
lypinator | 0:bb348c97df44 | 1002 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 1003 | assert_param(IS_FLASH_SECTOR(Sector)); |
lypinator | 0:bb348c97df44 | 1004 | assert_param(IS_VOLTAGERANGE(VoltageRange)); |
lypinator | 0:bb348c97df44 | 1005 | |
lypinator | 0:bb348c97df44 | 1006 | if(VoltageRange == FLASH_VOLTAGE_RANGE_1) |
lypinator | 0:bb348c97df44 | 1007 | { |
lypinator | 0:bb348c97df44 | 1008 | tmp_psize = FLASH_PSIZE_BYTE; |
lypinator | 0:bb348c97df44 | 1009 | } |
lypinator | 0:bb348c97df44 | 1010 | else if(VoltageRange == FLASH_VOLTAGE_RANGE_2) |
lypinator | 0:bb348c97df44 | 1011 | { |
lypinator | 0:bb348c97df44 | 1012 | tmp_psize = FLASH_PSIZE_HALF_WORD; |
lypinator | 0:bb348c97df44 | 1013 | } |
lypinator | 0:bb348c97df44 | 1014 | else if(VoltageRange == FLASH_VOLTAGE_RANGE_3) |
lypinator | 0:bb348c97df44 | 1015 | { |
lypinator | 0:bb348c97df44 | 1016 | tmp_psize = FLASH_PSIZE_WORD; |
lypinator | 0:bb348c97df44 | 1017 | } |
lypinator | 0:bb348c97df44 | 1018 | else |
lypinator | 0:bb348c97df44 | 1019 | { |
lypinator | 0:bb348c97df44 | 1020 | tmp_psize = FLASH_PSIZE_DOUBLE_WORD; |
lypinator | 0:bb348c97df44 | 1021 | } |
lypinator | 0:bb348c97df44 | 1022 | |
lypinator | 0:bb348c97df44 | 1023 | /* If the previous operation is completed, proceed to erase the sector */ |
lypinator | 0:bb348c97df44 | 1024 | CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE); |
lypinator | 0:bb348c97df44 | 1025 | FLASH->CR |= tmp_psize; |
lypinator | 0:bb348c97df44 | 1026 | CLEAR_BIT(FLASH->CR, FLASH_CR_SNB); |
lypinator | 0:bb348c97df44 | 1027 | FLASH->CR |= FLASH_CR_SER | (Sector << FLASH_CR_SNB_Pos); |
lypinator | 0:bb348c97df44 | 1028 | FLASH->CR |= FLASH_CR_STRT; |
lypinator | 0:bb348c97df44 | 1029 | } |
lypinator | 0:bb348c97df44 | 1030 | |
lypinator | 0:bb348c97df44 | 1031 | /** |
lypinator | 0:bb348c97df44 | 1032 | * @brief Enable the write protection of the desired bank 1 sectors |
lypinator | 0:bb348c97df44 | 1033 | * |
lypinator | 0:bb348c97df44 | 1034 | * @note When the memory read protection level is selected (RDP level = 1), |
lypinator | 0:bb348c97df44 | 1035 | * it is not possible to program or erase the flash sector i if CortexM4 |
lypinator | 0:bb348c97df44 | 1036 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
lypinator | 0:bb348c97df44 | 1037 | * @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1). |
lypinator | 0:bb348c97df44 | 1038 | * |
lypinator | 0:bb348c97df44 | 1039 | * @param WRPSector specifies the sector(s) to be write protected. |
lypinator | 0:bb348c97df44 | 1040 | * The value of this parameter depend on device used within the same series |
lypinator | 0:bb348c97df44 | 1041 | * |
lypinator | 0:bb348c97df44 | 1042 | * @param Banks Enable write protection on all the sectors for the specific bank |
lypinator | 0:bb348c97df44 | 1043 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 1044 | * @arg FLASH_BANK_1: WRP on all sectors of bank1 |
lypinator | 0:bb348c97df44 | 1045 | * |
lypinator | 0:bb348c97df44 | 1046 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 1047 | */ |
lypinator | 0:bb348c97df44 | 1048 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks) |
lypinator | 0:bb348c97df44 | 1049 | { |
lypinator | 0:bb348c97df44 | 1050 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 1051 | |
lypinator | 0:bb348c97df44 | 1052 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 1053 | assert_param(IS_OB_WRP_SECTOR(WRPSector)); |
lypinator | 0:bb348c97df44 | 1054 | assert_param(IS_FLASH_BANK(Banks)); |
lypinator | 0:bb348c97df44 | 1055 | |
lypinator | 0:bb348c97df44 | 1056 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 1057 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 1058 | |
lypinator | 0:bb348c97df44 | 1059 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 1060 | { |
lypinator | 0:bb348c97df44 | 1061 | *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~WRPSector); |
lypinator | 0:bb348c97df44 | 1062 | } |
lypinator | 0:bb348c97df44 | 1063 | |
lypinator | 0:bb348c97df44 | 1064 | return status; |
lypinator | 0:bb348c97df44 | 1065 | } |
lypinator | 0:bb348c97df44 | 1066 | |
lypinator | 0:bb348c97df44 | 1067 | /** |
lypinator | 0:bb348c97df44 | 1068 | * @brief Disable the write protection of the desired bank 1 sectors |
lypinator | 0:bb348c97df44 | 1069 | * |
lypinator | 0:bb348c97df44 | 1070 | * @note When the memory read protection level is selected (RDP level = 1), |
lypinator | 0:bb348c97df44 | 1071 | * it is not possible to program or erase the flash sector i if CortexM4 |
lypinator | 0:bb348c97df44 | 1072 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
lypinator | 0:bb348c97df44 | 1073 | * @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1). |
lypinator | 0:bb348c97df44 | 1074 | * |
lypinator | 0:bb348c97df44 | 1075 | * @param WRPSector specifies the sector(s) to be write protected. |
lypinator | 0:bb348c97df44 | 1076 | * The value of this parameter depend on device used within the same series |
lypinator | 0:bb348c97df44 | 1077 | * |
lypinator | 0:bb348c97df44 | 1078 | * @param Banks Enable write protection on all the sectors for the specific bank |
lypinator | 0:bb348c97df44 | 1079 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 1080 | * @arg FLASH_BANK_1: WRP on all sectors of bank1 |
lypinator | 0:bb348c97df44 | 1081 | * |
lypinator | 0:bb348c97df44 | 1082 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 1083 | */ |
lypinator | 0:bb348c97df44 | 1084 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks) |
lypinator | 0:bb348c97df44 | 1085 | { |
lypinator | 0:bb348c97df44 | 1086 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 1087 | |
lypinator | 0:bb348c97df44 | 1088 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 1089 | assert_param(IS_OB_WRP_SECTOR(WRPSector)); |
lypinator | 0:bb348c97df44 | 1090 | assert_param(IS_FLASH_BANK(Banks)); |
lypinator | 0:bb348c97df44 | 1091 | |
lypinator | 0:bb348c97df44 | 1092 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 1093 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 1094 | |
lypinator | 0:bb348c97df44 | 1095 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 1096 | { |
lypinator | 0:bb348c97df44 | 1097 | *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)WRPSector; |
lypinator | 0:bb348c97df44 | 1098 | } |
lypinator | 0:bb348c97df44 | 1099 | |
lypinator | 0:bb348c97df44 | 1100 | return status; |
lypinator | 0:bb348c97df44 | 1101 | } |
lypinator | 0:bb348c97df44 | 1102 | #endif /* STM32F40xxx || STM32F41xxx || STM32F401xx || STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx |
lypinator | 0:bb348c97df44 | 1103 | STM32F413xx || STM32F423xx */ |
lypinator | 0:bb348c97df44 | 1104 | |
lypinator | 0:bb348c97df44 | 1105 | #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\ |
lypinator | 0:bb348c97df44 | 1106 | defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\ |
lypinator | 0:bb348c97df44 | 1107 | defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) |
lypinator | 0:bb348c97df44 | 1108 | /** |
lypinator | 0:bb348c97df44 | 1109 | * @brief Enable the read/write protection (PCROP) of the desired sectors. |
lypinator | 0:bb348c97df44 | 1110 | * @note This function can be used only for STM32F401xx devices. |
lypinator | 0:bb348c97df44 | 1111 | * @param Sector specifies the sector(s) to be read/write protected or unprotected. |
lypinator | 0:bb348c97df44 | 1112 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 1113 | * @arg OB_PCROP: A value between OB_PCROP_Sector0 and OB_PCROP_Sector5 |
lypinator | 0:bb348c97df44 | 1114 | * @arg OB_PCROP_Sector_All |
lypinator | 0:bb348c97df44 | 1115 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 1116 | */ |
lypinator | 0:bb348c97df44 | 1117 | static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t Sector) |
lypinator | 0:bb348c97df44 | 1118 | { |
lypinator | 0:bb348c97df44 | 1119 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 1120 | |
lypinator | 0:bb348c97df44 | 1121 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 1122 | assert_param(IS_OB_PCROP(Sector)); |
lypinator | 0:bb348c97df44 | 1123 | |
lypinator | 0:bb348c97df44 | 1124 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 1125 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 1126 | |
lypinator | 0:bb348c97df44 | 1127 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 1128 | { |
lypinator | 0:bb348c97df44 | 1129 | *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)Sector; |
lypinator | 0:bb348c97df44 | 1130 | } |
lypinator | 0:bb348c97df44 | 1131 | |
lypinator | 0:bb348c97df44 | 1132 | return status; |
lypinator | 0:bb348c97df44 | 1133 | } |
lypinator | 0:bb348c97df44 | 1134 | |
lypinator | 0:bb348c97df44 | 1135 | |
lypinator | 0:bb348c97df44 | 1136 | /** |
lypinator | 0:bb348c97df44 | 1137 | * @brief Disable the read/write protection (PCROP) of the desired sectors. |
lypinator | 0:bb348c97df44 | 1138 | * @note This function can be used only for STM32F401xx devices. |
lypinator | 0:bb348c97df44 | 1139 | * @param Sector specifies the sector(s) to be read/write protected or unprotected. |
lypinator | 0:bb348c97df44 | 1140 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 1141 | * @arg OB_PCROP: A value between OB_PCROP_Sector0 and OB_PCROP_Sector5 |
lypinator | 0:bb348c97df44 | 1142 | * @arg OB_PCROP_Sector_All |
lypinator | 0:bb348c97df44 | 1143 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 1144 | */ |
lypinator | 0:bb348c97df44 | 1145 | static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t Sector) |
lypinator | 0:bb348c97df44 | 1146 | { |
lypinator | 0:bb348c97df44 | 1147 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 1148 | |
lypinator | 0:bb348c97df44 | 1149 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 1150 | assert_param(IS_OB_PCROP(Sector)); |
lypinator | 0:bb348c97df44 | 1151 | |
lypinator | 0:bb348c97df44 | 1152 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 1153 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 1154 | |
lypinator | 0:bb348c97df44 | 1155 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 1156 | { |
lypinator | 0:bb348c97df44 | 1157 | *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~Sector); |
lypinator | 0:bb348c97df44 | 1158 | } |
lypinator | 0:bb348c97df44 | 1159 | |
lypinator | 0:bb348c97df44 | 1160 | return status; |
lypinator | 0:bb348c97df44 | 1161 | |
lypinator | 0:bb348c97df44 | 1162 | } |
lypinator | 0:bb348c97df44 | 1163 | #endif /* STM32F401xC || STM32F401xE || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx |
lypinator | 0:bb348c97df44 | 1164 | STM32F413xx || STM32F423xx */ |
lypinator | 0:bb348c97df44 | 1165 | |
lypinator | 0:bb348c97df44 | 1166 | /** |
lypinator | 0:bb348c97df44 | 1167 | * @brief Set the read protection level. |
lypinator | 0:bb348c97df44 | 1168 | * @param Level specifies the read protection level. |
lypinator | 0:bb348c97df44 | 1169 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 1170 | * @arg OB_RDP_LEVEL_0: No protection |
lypinator | 0:bb348c97df44 | 1171 | * @arg OB_RDP_LEVEL_1: Read protection of the memory |
lypinator | 0:bb348c97df44 | 1172 | * @arg OB_RDP_LEVEL_2: Full chip protection |
lypinator | 0:bb348c97df44 | 1173 | * |
lypinator | 0:bb348c97df44 | 1174 | * @note WARNING: When enabling OB_RDP level 2 it's no more possible to go back to level 1 or 0 |
lypinator | 0:bb348c97df44 | 1175 | * |
lypinator | 0:bb348c97df44 | 1176 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 1177 | */ |
lypinator | 0:bb348c97df44 | 1178 | static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t Level) |
lypinator | 0:bb348c97df44 | 1179 | { |
lypinator | 0:bb348c97df44 | 1180 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 1181 | |
lypinator | 0:bb348c97df44 | 1182 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 1183 | assert_param(IS_OB_RDP_LEVEL(Level)); |
lypinator | 0:bb348c97df44 | 1184 | |
lypinator | 0:bb348c97df44 | 1185 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 1186 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 1187 | |
lypinator | 0:bb348c97df44 | 1188 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 1189 | { |
lypinator | 0:bb348c97df44 | 1190 | *(__IO uint8_t*)OPTCR_BYTE1_ADDRESS = Level; |
lypinator | 0:bb348c97df44 | 1191 | } |
lypinator | 0:bb348c97df44 | 1192 | |
lypinator | 0:bb348c97df44 | 1193 | return status; |
lypinator | 0:bb348c97df44 | 1194 | } |
lypinator | 0:bb348c97df44 | 1195 | |
lypinator | 0:bb348c97df44 | 1196 | /** |
lypinator | 0:bb348c97df44 | 1197 | * @brief Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY. |
lypinator | 0:bb348c97df44 | 1198 | * @param Iwdg Selects the IWDG mode |
lypinator | 0:bb348c97df44 | 1199 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 1200 | * @arg OB_IWDG_SW: Software IWDG selected |
lypinator | 0:bb348c97df44 | 1201 | * @arg OB_IWDG_HW: Hardware IWDG selected |
lypinator | 0:bb348c97df44 | 1202 | * @param Stop Reset event when entering STOP mode. |
lypinator | 0:bb348c97df44 | 1203 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 1204 | * @arg OB_STOP_NO_RST: No reset generated when entering in STOP |
lypinator | 0:bb348c97df44 | 1205 | * @arg OB_STOP_RST: Reset generated when entering in STOP |
lypinator | 0:bb348c97df44 | 1206 | * @param Stdby Reset event when entering Standby mode. |
lypinator | 0:bb348c97df44 | 1207 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 1208 | * @arg OB_STDBY_NO_RST: No reset generated when entering in STANDBY |
lypinator | 0:bb348c97df44 | 1209 | * @arg OB_STDBY_RST: Reset generated when entering in STANDBY |
lypinator | 0:bb348c97df44 | 1210 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 1211 | */ |
lypinator | 0:bb348c97df44 | 1212 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t Iwdg, uint8_t Stop, uint8_t Stdby) |
lypinator | 0:bb348c97df44 | 1213 | { |
lypinator | 0:bb348c97df44 | 1214 | uint8_t optiontmp = 0xFF; |
lypinator | 0:bb348c97df44 | 1215 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 1216 | |
lypinator | 0:bb348c97df44 | 1217 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 1218 | assert_param(IS_OB_IWDG_SOURCE(Iwdg)); |
lypinator | 0:bb348c97df44 | 1219 | assert_param(IS_OB_STOP_SOURCE(Stop)); |
lypinator | 0:bb348c97df44 | 1220 | assert_param(IS_OB_STDBY_SOURCE(Stdby)); |
lypinator | 0:bb348c97df44 | 1221 | |
lypinator | 0:bb348c97df44 | 1222 | /* Wait for last operation to be completed */ |
lypinator | 0:bb348c97df44 | 1223 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
lypinator | 0:bb348c97df44 | 1224 | |
lypinator | 0:bb348c97df44 | 1225 | if(status == HAL_OK) |
lypinator | 0:bb348c97df44 | 1226 | { |
lypinator | 0:bb348c97df44 | 1227 | /* Mask OPTLOCK, OPTSTRT, BOR_LEV and BFB2 bits */ |
lypinator | 0:bb348c97df44 | 1228 | optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE0_ADDRESS) & (uint8_t)0x1F); |
lypinator | 0:bb348c97df44 | 1229 | |
lypinator | 0:bb348c97df44 | 1230 | /* Update User Option Byte */ |
lypinator | 0:bb348c97df44 | 1231 | *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS = Iwdg | (uint8_t)(Stdby | (uint8_t)(Stop | ((uint8_t)optiontmp))); |
lypinator | 0:bb348c97df44 | 1232 | } |
lypinator | 0:bb348c97df44 | 1233 | |
lypinator | 0:bb348c97df44 | 1234 | return status; |
lypinator | 0:bb348c97df44 | 1235 | } |
lypinator | 0:bb348c97df44 | 1236 | |
lypinator | 0:bb348c97df44 | 1237 | /** |
lypinator | 0:bb348c97df44 | 1238 | * @brief Set the BOR Level. |
lypinator | 0:bb348c97df44 | 1239 | * @param Level specifies the Option Bytes BOR Reset Level. |
lypinator | 0:bb348c97df44 | 1240 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 1241 | * @arg OB_BOR_LEVEL3: Supply voltage ranges from 2.7 to 3.6 V |
lypinator | 0:bb348c97df44 | 1242 | * @arg OB_BOR_LEVEL2: Supply voltage ranges from 2.4 to 2.7 V |
lypinator | 0:bb348c97df44 | 1243 | * @arg OB_BOR_LEVEL1: Supply voltage ranges from 2.1 to 2.4 V |
lypinator | 0:bb348c97df44 | 1244 | * @arg OB_BOR_OFF: Supply voltage ranges from 1.62 to 2.1 V |
lypinator | 0:bb348c97df44 | 1245 | * @retval HAL Status |
lypinator | 0:bb348c97df44 | 1246 | */ |
lypinator | 0:bb348c97df44 | 1247 | static HAL_StatusTypeDef FLASH_OB_BOR_LevelConfig(uint8_t Level) |
lypinator | 0:bb348c97df44 | 1248 | { |
lypinator | 0:bb348c97df44 | 1249 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 1250 | assert_param(IS_OB_BOR_LEVEL(Level)); |
lypinator | 0:bb348c97df44 | 1251 | |
lypinator | 0:bb348c97df44 | 1252 | /* Set the BOR Level */ |
lypinator | 0:bb348c97df44 | 1253 | *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS &= (~FLASH_OPTCR_BOR_LEV); |
lypinator | 0:bb348c97df44 | 1254 | *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS |= Level; |
lypinator | 0:bb348c97df44 | 1255 | |
lypinator | 0:bb348c97df44 | 1256 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 1257 | |
lypinator | 0:bb348c97df44 | 1258 | } |
lypinator | 0:bb348c97df44 | 1259 | |
lypinator | 0:bb348c97df44 | 1260 | /** |
lypinator | 0:bb348c97df44 | 1261 | * @brief Return the FLASH User Option Byte value. |
lypinator | 0:bb348c97df44 | 1262 | * @retval uint8_t FLASH User Option Bytes values: IWDG_SW(Bit0), RST_STOP(Bit1) |
lypinator | 0:bb348c97df44 | 1263 | * and RST_STDBY(Bit2). |
lypinator | 0:bb348c97df44 | 1264 | */ |
lypinator | 0:bb348c97df44 | 1265 | static uint8_t FLASH_OB_GetUser(void) |
lypinator | 0:bb348c97df44 | 1266 | { |
lypinator | 0:bb348c97df44 | 1267 | /* Return the User Option Byte */ |
lypinator | 0:bb348c97df44 | 1268 | return ((uint8_t)(FLASH->OPTCR & 0xE0)); |
lypinator | 0:bb348c97df44 | 1269 | } |
lypinator | 0:bb348c97df44 | 1270 | |
lypinator | 0:bb348c97df44 | 1271 | /** |
lypinator | 0:bb348c97df44 | 1272 | * @brief Return the FLASH Write Protection Option Bytes value. |
lypinator | 0:bb348c97df44 | 1273 | * @retval uint16_t FLASH Write Protection Option Bytes value |
lypinator | 0:bb348c97df44 | 1274 | */ |
lypinator | 0:bb348c97df44 | 1275 | static uint16_t FLASH_OB_GetWRP(void) |
lypinator | 0:bb348c97df44 | 1276 | { |
lypinator | 0:bb348c97df44 | 1277 | /* Return the FLASH write protection Register value */ |
lypinator | 0:bb348c97df44 | 1278 | return (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS)); |
lypinator | 0:bb348c97df44 | 1279 | } |
lypinator | 0:bb348c97df44 | 1280 | |
lypinator | 0:bb348c97df44 | 1281 | /** |
lypinator | 0:bb348c97df44 | 1282 | * @brief Returns the FLASH Read Protection level. |
lypinator | 0:bb348c97df44 | 1283 | * @retval FLASH ReadOut Protection Status: |
lypinator | 0:bb348c97df44 | 1284 | * This parameter can be one of the following values: |
lypinator | 0:bb348c97df44 | 1285 | * @arg OB_RDP_LEVEL_0: No protection |
lypinator | 0:bb348c97df44 | 1286 | * @arg OB_RDP_LEVEL_1: Read protection of the memory |
lypinator | 0:bb348c97df44 | 1287 | * @arg OB_RDP_LEVEL_2: Full chip protection |
lypinator | 0:bb348c97df44 | 1288 | */ |
lypinator | 0:bb348c97df44 | 1289 | static uint8_t FLASH_OB_GetRDP(void) |
lypinator | 0:bb348c97df44 | 1290 | { |
lypinator | 0:bb348c97df44 | 1291 | uint8_t readstatus = OB_RDP_LEVEL_0; |
lypinator | 0:bb348c97df44 | 1292 | |
lypinator | 0:bb348c97df44 | 1293 | if((*(__IO uint8_t*)(OPTCR_BYTE1_ADDRESS) == (uint8_t)OB_RDP_LEVEL_2)) |
lypinator | 0:bb348c97df44 | 1294 | { |
lypinator | 0:bb348c97df44 | 1295 | readstatus = OB_RDP_LEVEL_2; |
lypinator | 0:bb348c97df44 | 1296 | } |
lypinator | 0:bb348c97df44 | 1297 | else if((*(__IO uint8_t*)(OPTCR_BYTE1_ADDRESS) == (uint8_t)OB_RDP_LEVEL_1)) |
lypinator | 0:bb348c97df44 | 1298 | { |
lypinator | 0:bb348c97df44 | 1299 | readstatus = OB_RDP_LEVEL_1; |
lypinator | 0:bb348c97df44 | 1300 | } |
lypinator | 0:bb348c97df44 | 1301 | else |
lypinator | 0:bb348c97df44 | 1302 | { |
lypinator | 0:bb348c97df44 | 1303 | readstatus = OB_RDP_LEVEL_0; |
lypinator | 0:bb348c97df44 | 1304 | } |
lypinator | 0:bb348c97df44 | 1305 | |
lypinator | 0:bb348c97df44 | 1306 | return readstatus; |
lypinator | 0:bb348c97df44 | 1307 | } |
lypinator | 0:bb348c97df44 | 1308 | |
lypinator | 0:bb348c97df44 | 1309 | /** |
lypinator | 0:bb348c97df44 | 1310 | * @brief Returns the FLASH BOR level. |
lypinator | 0:bb348c97df44 | 1311 | * @retval uint8_t The FLASH BOR level: |
lypinator | 0:bb348c97df44 | 1312 | * - OB_BOR_LEVEL3: Supply voltage ranges from 2.7 to 3.6 V |
lypinator | 0:bb348c97df44 | 1313 | * - OB_BOR_LEVEL2: Supply voltage ranges from 2.4 to 2.7 V |
lypinator | 0:bb348c97df44 | 1314 | * - OB_BOR_LEVEL1: Supply voltage ranges from 2.1 to 2.4 V |
lypinator | 0:bb348c97df44 | 1315 | * - OB_BOR_OFF : Supply voltage ranges from 1.62 to 2.1 V |
lypinator | 0:bb348c97df44 | 1316 | */ |
lypinator | 0:bb348c97df44 | 1317 | static uint8_t FLASH_OB_GetBOR(void) |
lypinator | 0:bb348c97df44 | 1318 | { |
lypinator | 0:bb348c97df44 | 1319 | /* Return the FLASH BOR level */ |
lypinator | 0:bb348c97df44 | 1320 | return (uint8_t)(*(__IO uint8_t *)(OPTCR_BYTE0_ADDRESS) & (uint8_t)0x0C); |
lypinator | 0:bb348c97df44 | 1321 | } |
lypinator | 0:bb348c97df44 | 1322 | |
lypinator | 0:bb348c97df44 | 1323 | /** |
lypinator | 0:bb348c97df44 | 1324 | * @brief Flush the instruction and data caches |
lypinator | 0:bb348c97df44 | 1325 | * @retval None |
lypinator | 0:bb348c97df44 | 1326 | */ |
lypinator | 0:bb348c97df44 | 1327 | void FLASH_FlushCaches(void) |
lypinator | 0:bb348c97df44 | 1328 | { |
lypinator | 0:bb348c97df44 | 1329 | /* Flush instruction cache */ |
lypinator | 0:bb348c97df44 | 1330 | if(READ_BIT(FLASH->ACR, FLASH_ACR_ICEN)!= RESET) |
lypinator | 0:bb348c97df44 | 1331 | { |
lypinator | 0:bb348c97df44 | 1332 | /* Disable instruction cache */ |
lypinator | 0:bb348c97df44 | 1333 | __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); |
lypinator | 0:bb348c97df44 | 1334 | /* Reset instruction cache */ |
lypinator | 0:bb348c97df44 | 1335 | __HAL_FLASH_INSTRUCTION_CACHE_RESET(); |
lypinator | 0:bb348c97df44 | 1336 | /* Enable instruction cache */ |
lypinator | 0:bb348c97df44 | 1337 | __HAL_FLASH_INSTRUCTION_CACHE_ENABLE(); |
lypinator | 0:bb348c97df44 | 1338 | } |
lypinator | 0:bb348c97df44 | 1339 | |
lypinator | 0:bb348c97df44 | 1340 | /* Flush data cache */ |
lypinator | 0:bb348c97df44 | 1341 | if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != RESET) |
lypinator | 0:bb348c97df44 | 1342 | { |
lypinator | 0:bb348c97df44 | 1343 | /* Disable data cache */ |
lypinator | 0:bb348c97df44 | 1344 | __HAL_FLASH_DATA_CACHE_DISABLE(); |
lypinator | 0:bb348c97df44 | 1345 | /* Reset data cache */ |
lypinator | 0:bb348c97df44 | 1346 | __HAL_FLASH_DATA_CACHE_RESET(); |
lypinator | 0:bb348c97df44 | 1347 | /* Enable data cache */ |
lypinator | 0:bb348c97df44 | 1348 | __HAL_FLASH_DATA_CACHE_ENABLE(); |
lypinator | 0:bb348c97df44 | 1349 | } |
lypinator | 0:bb348c97df44 | 1350 | } |
lypinator | 0:bb348c97df44 | 1351 | |
lypinator | 0:bb348c97df44 | 1352 | /** |
lypinator | 0:bb348c97df44 | 1353 | * @} |
lypinator | 0:bb348c97df44 | 1354 | */ |
lypinator | 0:bb348c97df44 | 1355 | |
lypinator | 0:bb348c97df44 | 1356 | #endif /* HAL_FLASH_MODULE_ENABLED */ |
lypinator | 0:bb348c97df44 | 1357 | |
lypinator | 0:bb348c97df44 | 1358 | /** |
lypinator | 0:bb348c97df44 | 1359 | * @} |
lypinator | 0:bb348c97df44 | 1360 | */ |
lypinator | 0:bb348c97df44 | 1361 | |
lypinator | 0:bb348c97df44 | 1362 | /** |
lypinator | 0:bb348c97df44 | 1363 | * @} |
lypinator | 0:bb348c97df44 | 1364 | */ |
lypinator | 0:bb348c97df44 | 1365 | |
lypinator | 0:bb348c97df44 | 1366 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |