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