mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32L4/stm32l4xx_hal_flash_ex.c@637:ed69428d4850, 2015-12-22 (annotated)
- Committer:
- jaerts
- Date:
- Tue Dec 22 13:22:16 2015 +0000
- Revision:
- 637:ed69428d4850
- Parent:
- 610:813dcc80987e
Add very shady LPC1768 CAN Filter implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 610:813dcc80987e | 1 | /** |
mbed_official | 610:813dcc80987e | 2 | ****************************************************************************** |
mbed_official | 610:813dcc80987e | 3 | * @file stm32l4xx_hal_flash_ex.c |
mbed_official | 610:813dcc80987e | 4 | * @author MCD Application Team |
mbed_official | 610:813dcc80987e | 5 | * @version V1.0.0 |
mbed_official | 610:813dcc80987e | 6 | * @date 26-June-2015 |
mbed_official | 610:813dcc80987e | 7 | * @brief Extended FLASH HAL module driver. |
mbed_official | 610:813dcc80987e | 8 | * This file provides firmware functions to manage the following |
mbed_official | 610:813dcc80987e | 9 | * functionalities of the FLASH extended peripheral: |
mbed_official | 610:813dcc80987e | 10 | * + Extended programming operations functions |
mbed_official | 610:813dcc80987e | 11 | * |
mbed_official | 610:813dcc80987e | 12 | @verbatim |
mbed_official | 610:813dcc80987e | 13 | ============================================================================== |
mbed_official | 610:813dcc80987e | 14 | ##### Flash Extended features ##### |
mbed_official | 610:813dcc80987e | 15 | ============================================================================== |
mbed_official | 610:813dcc80987e | 16 | |
mbed_official | 610:813dcc80987e | 17 | [..] Comparing to other previous devices, the FLASH interface for STM32L4xx |
mbed_official | 610:813dcc80987e | 18 | devices contains the following additional features |
mbed_official | 610:813dcc80987e | 19 | |
mbed_official | 610:813dcc80987e | 20 | (+) Capacity up to 2 Mbyte with dual bank architecture supporting read-while-write |
mbed_official | 610:813dcc80987e | 21 | capability (RWW) |
mbed_official | 610:813dcc80987e | 22 | (+) Dual bank memory organization |
mbed_official | 610:813dcc80987e | 23 | (+) PCROP protection for all banks |
mbed_official | 610:813dcc80987e | 24 | |
mbed_official | 610:813dcc80987e | 25 | ##### How to use this driver ##### |
mbed_official | 610:813dcc80987e | 26 | ============================================================================== |
mbed_official | 610:813dcc80987e | 27 | [..] This driver provides functions to configure and program the FLASH memory |
mbed_official | 610:813dcc80987e | 28 | of all STM32L4xx devices. It includes |
mbed_official | 610:813dcc80987e | 29 | (#) Flash Memory Erase functions: |
mbed_official | 610:813dcc80987e | 30 | (++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and |
mbed_official | 610:813dcc80987e | 31 | HAL_FLASH_Lock() functions |
mbed_official | 610:813dcc80987e | 32 | (++) Erase function: Erase page, erase all sectors |
mbed_official | 610:813dcc80987e | 33 | (++) There are two modes of erase : |
mbed_official | 610:813dcc80987e | 34 | (+++) Polling Mode using HAL_FLASHEx_Erase() |
mbed_official | 610:813dcc80987e | 35 | (+++) Interrupt Mode using HAL_FLASHEx_Erase_IT() |
mbed_official | 610:813dcc80987e | 36 | |
mbed_official | 610:813dcc80987e | 37 | (#) Option Bytes Programming function: Use HAL_FLASHEx_OBProgram() to : |
mbed_official | 610:813dcc80987e | 38 | (++) Set/Reset the write protection |
mbed_official | 610:813dcc80987e | 39 | (++) Set the Read protection Level |
mbed_official | 610:813dcc80987e | 40 | (++) Program the user Option Bytes |
mbed_official | 610:813dcc80987e | 41 | (++) Configure the PCROP protection |
mbed_official | 610:813dcc80987e | 42 | |
mbed_official | 610:813dcc80987e | 43 | (#) Get Option Bytes Configuration function: Use HAL_FLASHEx_OBGetConfig() to : |
mbed_official | 610:813dcc80987e | 44 | (++) Get the value of a write protection area |
mbed_official | 610:813dcc80987e | 45 | (++) Know if the read protection is activated |
mbed_official | 610:813dcc80987e | 46 | (++) Get the value of the user Option Bytes |
mbed_official | 610:813dcc80987e | 47 | (++) Get the value of a PCROP area |
mbed_official | 610:813dcc80987e | 48 | |
mbed_official | 610:813dcc80987e | 49 | @endverbatim |
mbed_official | 610:813dcc80987e | 50 | ****************************************************************************** |
mbed_official | 610:813dcc80987e | 51 | * @attention |
mbed_official | 610:813dcc80987e | 52 | * |
mbed_official | 610:813dcc80987e | 53 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
mbed_official | 610:813dcc80987e | 54 | * |
mbed_official | 610:813dcc80987e | 55 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 610:813dcc80987e | 56 | * are permitted provided that the following conditions are met: |
mbed_official | 610:813dcc80987e | 57 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 610:813dcc80987e | 58 | * this list of conditions and the following disclaimer. |
mbed_official | 610:813dcc80987e | 59 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 610:813dcc80987e | 60 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 610:813dcc80987e | 61 | * and/or other materials provided with the distribution. |
mbed_official | 610:813dcc80987e | 62 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 610:813dcc80987e | 63 | * may be used to endorse or promote products derived from this software |
mbed_official | 610:813dcc80987e | 64 | * without specific prior written permission. |
mbed_official | 610:813dcc80987e | 65 | * |
mbed_official | 610:813dcc80987e | 66 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 610:813dcc80987e | 67 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 610:813dcc80987e | 68 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 610:813dcc80987e | 69 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 610:813dcc80987e | 70 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 610:813dcc80987e | 71 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 610:813dcc80987e | 72 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 610:813dcc80987e | 73 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 610:813dcc80987e | 74 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 610:813dcc80987e | 75 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 610:813dcc80987e | 76 | * |
mbed_official | 610:813dcc80987e | 77 | ****************************************************************************** |
mbed_official | 610:813dcc80987e | 78 | */ |
mbed_official | 610:813dcc80987e | 79 | |
mbed_official | 610:813dcc80987e | 80 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 81 | #include "stm32l4xx_hal.h" |
mbed_official | 610:813dcc80987e | 82 | |
mbed_official | 610:813dcc80987e | 83 | /** @addtogroup STM32L4xx_HAL_Driver |
mbed_official | 610:813dcc80987e | 84 | * @{ |
mbed_official | 610:813dcc80987e | 85 | */ |
mbed_official | 610:813dcc80987e | 86 | |
mbed_official | 610:813dcc80987e | 87 | /** @defgroup FLASHEx FLASHEx |
mbed_official | 610:813dcc80987e | 88 | * @brief FALSH Extended HAL module driver |
mbed_official | 610:813dcc80987e | 89 | * @{ |
mbed_official | 610:813dcc80987e | 90 | */ |
mbed_official | 610:813dcc80987e | 91 | |
mbed_official | 610:813dcc80987e | 92 | #ifdef HAL_FLASH_MODULE_ENABLED |
mbed_official | 610:813dcc80987e | 93 | |
mbed_official | 610:813dcc80987e | 94 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 95 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 96 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 97 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 98 | /** @defgroup FLASHEx_Private_Variables FLASHEx Private Variables |
mbed_official | 610:813dcc80987e | 99 | * @{ |
mbed_official | 610:813dcc80987e | 100 | */ |
mbed_official | 610:813dcc80987e | 101 | extern FLASH_ProcessTypeDef pFlash; |
mbed_official | 610:813dcc80987e | 102 | /** |
mbed_official | 610:813dcc80987e | 103 | * @} |
mbed_official | 610:813dcc80987e | 104 | */ |
mbed_official | 610:813dcc80987e | 105 | |
mbed_official | 610:813dcc80987e | 106 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 107 | /** @defgroup FLASHEx_Private_Functions FLASHEx Private Functions |
mbed_official | 610:813dcc80987e | 108 | * @{ |
mbed_official | 610:813dcc80987e | 109 | */ |
mbed_official | 610:813dcc80987e | 110 | extern HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); |
mbed_official | 610:813dcc80987e | 111 | void FLASH_PageErase(uint32_t Page, uint32_t Banks); |
mbed_official | 610:813dcc80987e | 112 | static void FLASH_MassErase(uint32_t Banks); |
mbed_official | 610:813dcc80987e | 113 | void FLASH_FlushCaches(void); |
mbed_official | 610:813dcc80987e | 114 | static HAL_StatusTypeDef FLASH_OB_WRPConfig(uint32_t WRPArea, uint32_t WRPStartOffset, uint32_t WRDPEndOffset); |
mbed_official | 610:813dcc80987e | 115 | static HAL_StatusTypeDef FLASH_OB_RDPConfig(uint32_t RDPLevel); |
mbed_official | 610:813dcc80987e | 116 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint32_t UserType, uint32_t UserConfig); |
mbed_official | 610:813dcc80987e | 117 | static HAL_StatusTypeDef FLASH_OB_PCROPConfig(uint32_t PCROPConfig, uint32_t PCROPStartAddr, uint32_t PCROPEndAddr); |
mbed_official | 610:813dcc80987e | 118 | static void FLASH_OB_GetWRP(uint32_t WRPArea, uint32_t * WRPStartOffset, uint32_t * WRDPEndOffset); |
mbed_official | 610:813dcc80987e | 119 | static uint32_t FLASH_OB_GetRDP(void); |
mbed_official | 610:813dcc80987e | 120 | static uint32_t FLASH_OB_GetUser(void); |
mbed_official | 610:813dcc80987e | 121 | static void FLASH_OB_GetPCROP(uint32_t * PCROPConfig, uint32_t * PCROPStartAddr, uint32_t * PCROPEndAddr); |
mbed_official | 610:813dcc80987e | 122 | /** |
mbed_official | 610:813dcc80987e | 123 | * @} |
mbed_official | 610:813dcc80987e | 124 | */ |
mbed_official | 610:813dcc80987e | 125 | |
mbed_official | 610:813dcc80987e | 126 | /* Exported functions -------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 127 | /** @defgroup FLASHEx_Exported_Functions FLASH Extended Exported Functions |
mbed_official | 610:813dcc80987e | 128 | * @{ |
mbed_official | 610:813dcc80987e | 129 | */ |
mbed_official | 610:813dcc80987e | 130 | |
mbed_official | 610:813dcc80987e | 131 | /** @defgroup FLASHEx_Exported_Functions_Group1 Extended IO operation functions |
mbed_official | 610:813dcc80987e | 132 | * @brief Extended IO operation functions |
mbed_official | 610:813dcc80987e | 133 | * |
mbed_official | 610:813dcc80987e | 134 | @verbatim |
mbed_official | 610:813dcc80987e | 135 | =============================================================================== |
mbed_official | 610:813dcc80987e | 136 | ##### Extended programming operation functions ##### |
mbed_official | 610:813dcc80987e | 137 | =============================================================================== |
mbed_official | 610:813dcc80987e | 138 | [..] |
mbed_official | 610:813dcc80987e | 139 | This subsection provides a set of functions allowing to manage the Extended FLASH |
mbed_official | 610:813dcc80987e | 140 | programming operations Operations. |
mbed_official | 610:813dcc80987e | 141 | |
mbed_official | 610:813dcc80987e | 142 | @endverbatim |
mbed_official | 610:813dcc80987e | 143 | * @{ |
mbed_official | 610:813dcc80987e | 144 | */ |
mbed_official | 610:813dcc80987e | 145 | /** |
mbed_official | 610:813dcc80987e | 146 | * @brief Perform a mass erase or erase the specified FLASH memory pages. |
mbed_official | 610:813dcc80987e | 147 | * @param[in] pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
mbed_official | 610:813dcc80987e | 148 | * contains the configuration information for the erasing. |
mbed_official | 610:813dcc80987e | 149 | * |
mbed_official | 610:813dcc80987e | 150 | * @param[out] PageError : pointer to variable that contains the configuration |
mbed_official | 610:813dcc80987e | 151 | * information on faulty page in case of error (0xFFFFFFFF means that all |
mbed_official | 610:813dcc80987e | 152 | * the pages have been correctly erased) |
mbed_official | 610:813dcc80987e | 153 | * |
mbed_official | 610:813dcc80987e | 154 | * @retval HAL Status |
mbed_official | 610:813dcc80987e | 155 | */ |
mbed_official | 610:813dcc80987e | 156 | HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError) |
mbed_official | 610:813dcc80987e | 157 | { |
mbed_official | 610:813dcc80987e | 158 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 610:813dcc80987e | 159 | uint32_t page_index = 0; |
mbed_official | 610:813dcc80987e | 160 | |
mbed_official | 610:813dcc80987e | 161 | /* Process Locked */ |
mbed_official | 610:813dcc80987e | 162 | __HAL_LOCK(&pFlash); |
mbed_official | 610:813dcc80987e | 163 | |
mbed_official | 610:813dcc80987e | 164 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 165 | assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
mbed_official | 610:813dcc80987e | 166 | |
mbed_official | 610:813dcc80987e | 167 | /* Wait for last operation to be completed */ |
mbed_official | 610:813dcc80987e | 168 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 610:813dcc80987e | 169 | |
mbed_official | 610:813dcc80987e | 170 | if (status == HAL_OK) |
mbed_official | 610:813dcc80987e | 171 | { |
mbed_official | 610:813dcc80987e | 172 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 610:813dcc80987e | 173 | |
mbed_official | 610:813dcc80987e | 174 | if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) |
mbed_official | 610:813dcc80987e | 175 | { |
mbed_official | 610:813dcc80987e | 176 | /* Mass erase to be done */ |
mbed_official | 610:813dcc80987e | 177 | FLASH_MassErase(pEraseInit->Banks); |
mbed_official | 610:813dcc80987e | 178 | |
mbed_official | 610:813dcc80987e | 179 | /* Wait for last operation to be completed */ |
mbed_official | 610:813dcc80987e | 180 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 610:813dcc80987e | 181 | |
mbed_official | 610:813dcc80987e | 182 | /* If the erase operation is completed, disable the MER1 and MER2 Bits */ |
mbed_official | 610:813dcc80987e | 183 | CLEAR_BIT(FLASH->CR, (FLASH_CR_MER1 | FLASH_CR_MER2)); |
mbed_official | 610:813dcc80987e | 184 | } |
mbed_official | 610:813dcc80987e | 185 | else |
mbed_official | 610:813dcc80987e | 186 | { |
mbed_official | 610:813dcc80987e | 187 | /*Initialization of PageError variable*/ |
mbed_official | 610:813dcc80987e | 188 | *PageError = 0xFFFFFFFF; |
mbed_official | 610:813dcc80987e | 189 | |
mbed_official | 610:813dcc80987e | 190 | for(page_index = pEraseInit->Page; page_index < (pEraseInit->Page + pEraseInit->NbPages); page_index++) |
mbed_official | 610:813dcc80987e | 191 | { |
mbed_official | 610:813dcc80987e | 192 | FLASH_PageErase(page_index, pEraseInit->Banks); |
mbed_official | 610:813dcc80987e | 193 | |
mbed_official | 610:813dcc80987e | 194 | /* Wait for last operation to be completed */ |
mbed_official | 610:813dcc80987e | 195 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 610:813dcc80987e | 196 | |
mbed_official | 610:813dcc80987e | 197 | /* If the erase operation is completed, disable the PER Bit */ |
mbed_official | 610:813dcc80987e | 198 | CLEAR_BIT(FLASH->CR, (FLASH_CR_PER | FLASH_CR_PNB)); |
mbed_official | 610:813dcc80987e | 199 | |
mbed_official | 610:813dcc80987e | 200 | if (status != HAL_OK) |
mbed_official | 610:813dcc80987e | 201 | { |
mbed_official | 610:813dcc80987e | 202 | /* In case of error, stop erase procedure and return the faulty address */ |
mbed_official | 610:813dcc80987e | 203 | *PageError = page_index; |
mbed_official | 610:813dcc80987e | 204 | break; |
mbed_official | 610:813dcc80987e | 205 | } |
mbed_official | 610:813dcc80987e | 206 | } |
mbed_official | 610:813dcc80987e | 207 | } |
mbed_official | 610:813dcc80987e | 208 | |
mbed_official | 610:813dcc80987e | 209 | /* Flush the caches to be sure of the data consistency */ |
mbed_official | 610:813dcc80987e | 210 | FLASH_FlushCaches(); |
mbed_official | 610:813dcc80987e | 211 | } |
mbed_official | 610:813dcc80987e | 212 | |
mbed_official | 610:813dcc80987e | 213 | /* Process Unlocked */ |
mbed_official | 610:813dcc80987e | 214 | __HAL_UNLOCK(&pFlash); |
mbed_official | 610:813dcc80987e | 215 | |
mbed_official | 610:813dcc80987e | 216 | return status; |
mbed_official | 610:813dcc80987e | 217 | } |
mbed_official | 610:813dcc80987e | 218 | |
mbed_official | 610:813dcc80987e | 219 | /** |
mbed_official | 610:813dcc80987e | 220 | * @brief Perform a mass erase or erase the specified FLASH memory pages with interrupt enabled. |
mbed_official | 610:813dcc80987e | 221 | * @param pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
mbed_official | 610:813dcc80987e | 222 | * contains the configuration information for the erasing. |
mbed_official | 610:813dcc80987e | 223 | * |
mbed_official | 610:813dcc80987e | 224 | * @retval HAL Status |
mbed_official | 610:813dcc80987e | 225 | */ |
mbed_official | 610:813dcc80987e | 226 | HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) |
mbed_official | 610:813dcc80987e | 227 | { |
mbed_official | 610:813dcc80987e | 228 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 610:813dcc80987e | 229 | |
mbed_official | 610:813dcc80987e | 230 | /* Process Locked */ |
mbed_official | 610:813dcc80987e | 231 | __HAL_LOCK(&pFlash); |
mbed_official | 610:813dcc80987e | 232 | |
mbed_official | 610:813dcc80987e | 233 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 234 | assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
mbed_official | 610:813dcc80987e | 235 | |
mbed_official | 610:813dcc80987e | 236 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 610:813dcc80987e | 237 | |
mbed_official | 610:813dcc80987e | 238 | /* Enable End of Operation and Error interrupts */ |
mbed_official | 610:813dcc80987e | 239 | __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_OPERR); |
mbed_official | 610:813dcc80987e | 240 | |
mbed_official | 610:813dcc80987e | 241 | pFlash.Bank = pEraseInit->Banks; |
mbed_official | 610:813dcc80987e | 242 | |
mbed_official | 610:813dcc80987e | 243 | if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) |
mbed_official | 610:813dcc80987e | 244 | { |
mbed_official | 610:813dcc80987e | 245 | /* Mass erase to be done */ |
mbed_official | 610:813dcc80987e | 246 | pFlash.ProcedureOnGoing = FLASH_PROC_MASS_ERASE; |
mbed_official | 610:813dcc80987e | 247 | FLASH_MassErase(pEraseInit->Banks); |
mbed_official | 610:813dcc80987e | 248 | } |
mbed_official | 610:813dcc80987e | 249 | else |
mbed_official | 610:813dcc80987e | 250 | { |
mbed_official | 610:813dcc80987e | 251 | /* Erase by page to be done */ |
mbed_official | 610:813dcc80987e | 252 | pFlash.ProcedureOnGoing = FLASH_PROC_PAGE_ERASE; |
mbed_official | 610:813dcc80987e | 253 | pFlash.NbPagesToErase = pEraseInit->NbPages; |
mbed_official | 610:813dcc80987e | 254 | pFlash.Page = pEraseInit->Page; |
mbed_official | 610:813dcc80987e | 255 | |
mbed_official | 610:813dcc80987e | 256 | /*Erase 1st page and wait for IT */ |
mbed_official | 610:813dcc80987e | 257 | FLASH_PageErase(pEraseInit->Page, pEraseInit->Banks); |
mbed_official | 610:813dcc80987e | 258 | } |
mbed_official | 610:813dcc80987e | 259 | |
mbed_official | 610:813dcc80987e | 260 | return status; |
mbed_official | 610:813dcc80987e | 261 | } |
mbed_official | 610:813dcc80987e | 262 | |
mbed_official | 610:813dcc80987e | 263 | /** |
mbed_official | 610:813dcc80987e | 264 | * @brief Program Option bytes. |
mbed_official | 610:813dcc80987e | 265 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that |
mbed_official | 610:813dcc80987e | 266 | * contains the configuration information for the programming. |
mbed_official | 610:813dcc80987e | 267 | * |
mbed_official | 610:813dcc80987e | 268 | * @retval HAL Status |
mbed_official | 610:813dcc80987e | 269 | */ |
mbed_official | 610:813dcc80987e | 270 | HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) |
mbed_official | 610:813dcc80987e | 271 | { |
mbed_official | 610:813dcc80987e | 272 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 610:813dcc80987e | 273 | |
mbed_official | 610:813dcc80987e | 274 | /* Process Locked */ |
mbed_official | 610:813dcc80987e | 275 | __HAL_LOCK(&pFlash); |
mbed_official | 610:813dcc80987e | 276 | |
mbed_official | 610:813dcc80987e | 277 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 278 | assert_param(IS_OPTIONBYTE(pOBInit->OptionType)); |
mbed_official | 610:813dcc80987e | 279 | |
mbed_official | 610:813dcc80987e | 280 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 610:813dcc80987e | 281 | |
mbed_official | 610:813dcc80987e | 282 | /* Write protection configuration */ |
mbed_official | 610:813dcc80987e | 283 | if((pOBInit->OptionType & OPTIONBYTE_WRP) != RESET) |
mbed_official | 610:813dcc80987e | 284 | { |
mbed_official | 610:813dcc80987e | 285 | /* Configure of Write protection on the selected area */ |
mbed_official | 610:813dcc80987e | 286 | status = FLASH_OB_WRPConfig(pOBInit->WRPArea, pOBInit->WRPStartOffset, pOBInit->WRPEndOffset); |
mbed_official | 610:813dcc80987e | 287 | } |
mbed_official | 610:813dcc80987e | 288 | |
mbed_official | 610:813dcc80987e | 289 | /* Read protection configuration */ |
mbed_official | 610:813dcc80987e | 290 | if((pOBInit->OptionType & OPTIONBYTE_RDP) != RESET) |
mbed_official | 610:813dcc80987e | 291 | { |
mbed_official | 610:813dcc80987e | 292 | /* Configure the Read protection level */ |
mbed_official | 610:813dcc80987e | 293 | status = FLASH_OB_RDPConfig(pOBInit->RDPLevel); |
mbed_official | 610:813dcc80987e | 294 | } |
mbed_official | 610:813dcc80987e | 295 | |
mbed_official | 610:813dcc80987e | 296 | /* User Configuration */ |
mbed_official | 610:813dcc80987e | 297 | if((pOBInit->OptionType & OPTIONBYTE_USER) != RESET) |
mbed_official | 610:813dcc80987e | 298 | { |
mbed_official | 610:813dcc80987e | 299 | /* Configure the user option bytes */ |
mbed_official | 610:813dcc80987e | 300 | status = FLASH_OB_UserConfig(pOBInit->USERType, pOBInit->USERConfig); |
mbed_official | 610:813dcc80987e | 301 | } |
mbed_official | 610:813dcc80987e | 302 | |
mbed_official | 610:813dcc80987e | 303 | /* PCROP Configuration */ |
mbed_official | 610:813dcc80987e | 304 | if((pOBInit->OptionType & OPTIONBYTE_PCROP) != RESET) |
mbed_official | 610:813dcc80987e | 305 | { |
mbed_official | 610:813dcc80987e | 306 | /* Configure the Proprietary code readout protection */ |
mbed_official | 610:813dcc80987e | 307 | status = FLASH_OB_PCROPConfig(pOBInit->PCROPConfig, pOBInit->PCROPStartAddr, pOBInit->PCROPEndAddr); |
mbed_official | 610:813dcc80987e | 308 | } |
mbed_official | 610:813dcc80987e | 309 | |
mbed_official | 610:813dcc80987e | 310 | /* Process Unlocked */ |
mbed_official | 610:813dcc80987e | 311 | __HAL_UNLOCK(&pFlash); |
mbed_official | 610:813dcc80987e | 312 | |
mbed_official | 610:813dcc80987e | 313 | return status; |
mbed_official | 610:813dcc80987e | 314 | } |
mbed_official | 610:813dcc80987e | 315 | |
mbed_official | 610:813dcc80987e | 316 | /** |
mbed_official | 610:813dcc80987e | 317 | * @brief Get the Option bytes configuration. |
mbed_official | 610:813dcc80987e | 318 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that contains the |
mbed_official | 610:813dcc80987e | 319 | * configuration information. The fields pOBInit->WRPArea and |
mbed_official | 610:813dcc80987e | 320 | * pOBInit->PCROPConfig should indicate which area is requested |
mbed_official | 610:813dcc80987e | 321 | * for the WRP and PCROP |
mbed_official | 610:813dcc80987e | 322 | * |
mbed_official | 610:813dcc80987e | 323 | * @retval None |
mbed_official | 610:813dcc80987e | 324 | */ |
mbed_official | 610:813dcc80987e | 325 | void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) |
mbed_official | 610:813dcc80987e | 326 | { |
mbed_official | 610:813dcc80987e | 327 | pOBInit->OptionType = (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_PCROP); |
mbed_official | 610:813dcc80987e | 328 | |
mbed_official | 610:813dcc80987e | 329 | /* Get write protection on the selected area */ |
mbed_official | 610:813dcc80987e | 330 | FLASH_OB_GetWRP(pOBInit->WRPArea, &(pOBInit->WRPStartOffset), &(pOBInit->WRPEndOffset)); |
mbed_official | 610:813dcc80987e | 331 | |
mbed_official | 610:813dcc80987e | 332 | /* Get Read protection level */ |
mbed_official | 610:813dcc80987e | 333 | pOBInit->RDPLevel = FLASH_OB_GetRDP(); |
mbed_official | 610:813dcc80987e | 334 | |
mbed_official | 610:813dcc80987e | 335 | /* Get the user option bytes */ |
mbed_official | 610:813dcc80987e | 336 | pOBInit->USERConfig = FLASH_OB_GetUser(); |
mbed_official | 610:813dcc80987e | 337 | |
mbed_official | 610:813dcc80987e | 338 | /* Get the Proprietary code readout protection */ |
mbed_official | 610:813dcc80987e | 339 | FLASH_OB_GetPCROP(&(pOBInit->PCROPConfig), &(pOBInit->PCROPStartAddr), &(pOBInit->PCROPEndAddr)); |
mbed_official | 610:813dcc80987e | 340 | |
mbed_official | 610:813dcc80987e | 341 | } |
mbed_official | 610:813dcc80987e | 342 | |
mbed_official | 610:813dcc80987e | 343 | /** |
mbed_official | 610:813dcc80987e | 344 | * @} |
mbed_official | 610:813dcc80987e | 345 | */ |
mbed_official | 610:813dcc80987e | 346 | |
mbed_official | 610:813dcc80987e | 347 | /** |
mbed_official | 610:813dcc80987e | 348 | * @} |
mbed_official | 610:813dcc80987e | 349 | */ |
mbed_official | 610:813dcc80987e | 350 | |
mbed_official | 610:813dcc80987e | 351 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 352 | |
mbed_official | 610:813dcc80987e | 353 | /** @addtogroup FLASHEx_Private_Functions |
mbed_official | 610:813dcc80987e | 354 | * @{ |
mbed_official | 610:813dcc80987e | 355 | */ |
mbed_official | 610:813dcc80987e | 356 | /** |
mbed_official | 610:813dcc80987e | 357 | * @brief Mass erase of FLASH memory. |
mbed_official | 610:813dcc80987e | 358 | * @param Banks: Banks to be erased |
mbed_official | 610:813dcc80987e | 359 | * This parameter can be one of the following values: |
mbed_official | 610:813dcc80987e | 360 | * @arg FLASH_BANK_1: Bank1 to be erased |
mbed_official | 610:813dcc80987e | 361 | * @arg FLASH_BANK_2: Bank2 to be erased |
mbed_official | 610:813dcc80987e | 362 | * @arg FLASH_BANK_BOTH: Bank1 and Bank2 to be erased |
mbed_official | 610:813dcc80987e | 363 | * @retval None |
mbed_official | 610:813dcc80987e | 364 | */ |
mbed_official | 610:813dcc80987e | 365 | static void FLASH_MassErase(uint32_t Banks) |
mbed_official | 610:813dcc80987e | 366 | { |
mbed_official | 610:813dcc80987e | 367 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 368 | assert_param(IS_FLASH_BANK(Banks)); |
mbed_official | 610:813dcc80987e | 369 | |
mbed_official | 610:813dcc80987e | 370 | /* Set the Mass Erase Bit for the bank 1 if requested */ |
mbed_official | 610:813dcc80987e | 371 | if((Banks & FLASH_BANK_1) != RESET) |
mbed_official | 610:813dcc80987e | 372 | { |
mbed_official | 610:813dcc80987e | 373 | SET_BIT(FLASH->CR, FLASH_CR_MER1); |
mbed_official | 610:813dcc80987e | 374 | } |
mbed_official | 610:813dcc80987e | 375 | |
mbed_official | 610:813dcc80987e | 376 | /* Set the Mass Erase Bit for the bank 2 if requested */ |
mbed_official | 610:813dcc80987e | 377 | if((Banks & FLASH_BANK_2) != RESET) |
mbed_official | 610:813dcc80987e | 378 | { |
mbed_official | 610:813dcc80987e | 379 | SET_BIT(FLASH->CR, FLASH_CR_MER2); |
mbed_official | 610:813dcc80987e | 380 | } |
mbed_official | 610:813dcc80987e | 381 | |
mbed_official | 610:813dcc80987e | 382 | /* Proceed to erase all sectors */ |
mbed_official | 610:813dcc80987e | 383 | SET_BIT(FLASH->CR, FLASH_CR_STRT); |
mbed_official | 610:813dcc80987e | 384 | } |
mbed_official | 610:813dcc80987e | 385 | |
mbed_official | 610:813dcc80987e | 386 | /** |
mbed_official | 610:813dcc80987e | 387 | * @brief Erase the specified FLASH memory page. |
mbed_official | 610:813dcc80987e | 388 | * @param Page: FLASH page to erase |
mbed_official | 610:813dcc80987e | 389 | * This parameter must be a value between 0 and (max number of pages in the bank - 1) |
mbed_official | 610:813dcc80987e | 390 | * @param Banks: Bank(s) where the page will be erased |
mbed_official | 610:813dcc80987e | 391 | * This parameter can be one or a combination of the following values: |
mbed_official | 610:813dcc80987e | 392 | * @arg FLASH_BANK_1: Page in bank 1 to be erased |
mbed_official | 610:813dcc80987e | 393 | * @arg FLASH_BANK_2: Page in bank 2 to be erased |
mbed_official | 610:813dcc80987e | 394 | * @retval None |
mbed_official | 610:813dcc80987e | 395 | */ |
mbed_official | 610:813dcc80987e | 396 | void FLASH_PageErase(uint32_t Page, uint32_t Banks) |
mbed_official | 610:813dcc80987e | 397 | { |
mbed_official | 610:813dcc80987e | 398 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 399 | assert_param(IS_FLASH_PAGE(Page)); |
mbed_official | 610:813dcc80987e | 400 | assert_param(IS_FLASH_BANK_EXCLUSIVE(Banks)); |
mbed_official | 610:813dcc80987e | 401 | |
mbed_official | 610:813dcc80987e | 402 | if((Banks & FLASH_BANK_1) != RESET) |
mbed_official | 610:813dcc80987e | 403 | { |
mbed_official | 610:813dcc80987e | 404 | CLEAR_BIT(FLASH->CR, FLASH_CR_BKER); |
mbed_official | 610:813dcc80987e | 405 | } |
mbed_official | 610:813dcc80987e | 406 | else |
mbed_official | 610:813dcc80987e | 407 | { |
mbed_official | 610:813dcc80987e | 408 | SET_BIT(FLASH->CR, FLASH_CR_BKER); |
mbed_official | 610:813dcc80987e | 409 | } |
mbed_official | 610:813dcc80987e | 410 | |
mbed_official | 610:813dcc80987e | 411 | /* Proceed to erase the page */ |
mbed_official | 610:813dcc80987e | 412 | MODIFY_REG(FLASH->CR, FLASH_CR_PNB, (Page << 3)); |
mbed_official | 610:813dcc80987e | 413 | SET_BIT(FLASH->CR, FLASH_CR_PER); |
mbed_official | 610:813dcc80987e | 414 | SET_BIT(FLASH->CR, FLASH_CR_STRT); |
mbed_official | 610:813dcc80987e | 415 | } |
mbed_official | 610:813dcc80987e | 416 | |
mbed_official | 610:813dcc80987e | 417 | /** |
mbed_official | 610:813dcc80987e | 418 | * @brief Flush the instruction and data caches. |
mbed_official | 610:813dcc80987e | 419 | * @retval None |
mbed_official | 610:813dcc80987e | 420 | */ |
mbed_official | 610:813dcc80987e | 421 | void FLASH_FlushCaches(void) |
mbed_official | 610:813dcc80987e | 422 | { |
mbed_official | 610:813dcc80987e | 423 | /* Flush instruction cache */ |
mbed_official | 610:813dcc80987e | 424 | if(READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) != RESET) |
mbed_official | 610:813dcc80987e | 425 | { |
mbed_official | 610:813dcc80987e | 426 | /* Disable instruction cache */ |
mbed_official | 610:813dcc80987e | 427 | __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); |
mbed_official | 610:813dcc80987e | 428 | /* Reset instruction cache */ |
mbed_official | 610:813dcc80987e | 429 | __HAL_FLASH_INSTRUCTION_CACHE_RESET(); |
mbed_official | 610:813dcc80987e | 430 | /* Enable instruction cache */ |
mbed_official | 610:813dcc80987e | 431 | __HAL_FLASH_INSTRUCTION_CACHE_ENABLE(); |
mbed_official | 610:813dcc80987e | 432 | } |
mbed_official | 610:813dcc80987e | 433 | |
mbed_official | 610:813dcc80987e | 434 | /* Flush data cache */ |
mbed_official | 610:813dcc80987e | 435 | if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != RESET) |
mbed_official | 610:813dcc80987e | 436 | { |
mbed_official | 610:813dcc80987e | 437 | /* Disable data cache */ |
mbed_official | 610:813dcc80987e | 438 | __HAL_FLASH_DATA_CACHE_DISABLE(); |
mbed_official | 610:813dcc80987e | 439 | /* Reset data cache */ |
mbed_official | 610:813dcc80987e | 440 | __HAL_FLASH_DATA_CACHE_RESET(); |
mbed_official | 610:813dcc80987e | 441 | /* Enable data cache */ |
mbed_official | 610:813dcc80987e | 442 | __HAL_FLASH_DATA_CACHE_ENABLE(); |
mbed_official | 610:813dcc80987e | 443 | } |
mbed_official | 610:813dcc80987e | 444 | } |
mbed_official | 610:813dcc80987e | 445 | |
mbed_official | 610:813dcc80987e | 446 | /** |
mbed_official | 610:813dcc80987e | 447 | * @brief Configure the write protection of the desired pages. |
mbed_official | 610:813dcc80987e | 448 | * |
mbed_official | 610:813dcc80987e | 449 | * @note When the memory read protection level is selected (RDP level = 1), |
mbed_official | 610:813dcc80987e | 450 | * it is not possible to program or erase Flash memory if the CPU debug |
mbed_official | 610:813dcc80987e | 451 | * features are connected (JTAG or single wire) or boot code is being |
mbed_official | 610:813dcc80987e | 452 | * executed from RAM or System flash, even if WRP is not activated. |
mbed_official | 610:813dcc80987e | 453 | * @note To configure the WRP options, the option lock bit OPTLOCK must be |
mbed_official | 610:813dcc80987e | 454 | * cleared with the call of the HAL_FLASH_OB_Unlock() function. |
mbed_official | 610:813dcc80987e | 455 | * @note To validate the WRP options, the option bytes must be reloaded |
mbed_official | 610:813dcc80987e | 456 | * through the call of the HAL_FLASH_OB_Launch() function. |
mbed_official | 610:813dcc80987e | 457 | * |
mbed_official | 610:813dcc80987e | 458 | * @param WRPArea: specifies the area to be configured. |
mbed_official | 610:813dcc80987e | 459 | * This parameter can be one of the following values: |
mbed_official | 610:813dcc80987e | 460 | * @arg OB_WRPAREA_BANK1_AREAA: Flash Bank 1 Area A |
mbed_official | 610:813dcc80987e | 461 | * @arg OB_WRPAREA_BANK1_AREAB: Flash Bank 1 Area B |
mbed_official | 610:813dcc80987e | 462 | * @arg OB_WRPAREA_BANK2_AREAA: Flash Bank 2 Area A |
mbed_official | 610:813dcc80987e | 463 | * @arg OB_WRPAREA_BANK2_AREAB: Flash Bank 2 Area B |
mbed_official | 610:813dcc80987e | 464 | * |
mbed_official | 610:813dcc80987e | 465 | * @param WRPStartOffset: specifies the start page of the write protected area |
mbed_official | 610:813dcc80987e | 466 | * This parameter can be page number between 0 and (max number of pages in the bank - 1) |
mbed_official | 610:813dcc80987e | 467 | * |
mbed_official | 610:813dcc80987e | 468 | * @param WRDPEndOffset: specifies the end page of the write protected area |
mbed_official | 610:813dcc80987e | 469 | * This parameter can be page number between WRPStartOffset and (max number of pages in the bank - 1) |
mbed_official | 610:813dcc80987e | 470 | * |
mbed_official | 610:813dcc80987e | 471 | * @retval HAL Status |
mbed_official | 610:813dcc80987e | 472 | */ |
mbed_official | 610:813dcc80987e | 473 | static HAL_StatusTypeDef FLASH_OB_WRPConfig(uint32_t WRPArea, uint32_t WRPStartOffset, uint32_t WRDPEndOffset) |
mbed_official | 610:813dcc80987e | 474 | { |
mbed_official | 610:813dcc80987e | 475 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 610:813dcc80987e | 476 | |
mbed_official | 610:813dcc80987e | 477 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 478 | assert_param(IS_OB_WRPAREA(WRPArea)); |
mbed_official | 610:813dcc80987e | 479 | assert_param(IS_FLASH_PAGE(WRPStartOffset)); |
mbed_official | 610:813dcc80987e | 480 | assert_param(IS_FLASH_PAGE(WRDPEndOffset)); |
mbed_official | 610:813dcc80987e | 481 | |
mbed_official | 610:813dcc80987e | 482 | /* Wait for last operation to be completed */ |
mbed_official | 610:813dcc80987e | 483 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 610:813dcc80987e | 484 | |
mbed_official | 610:813dcc80987e | 485 | if(status == HAL_OK) |
mbed_official | 610:813dcc80987e | 486 | { |
mbed_official | 610:813dcc80987e | 487 | /* Configure the write protected area */ |
mbed_official | 610:813dcc80987e | 488 | if(WRPArea == OB_WRPAREA_BANK1_AREAA) |
mbed_official | 610:813dcc80987e | 489 | { |
mbed_official | 610:813dcc80987e | 490 | MODIFY_REG(FLASH->WRP1AR, (FLASH_WRP1AR_WRP1A_STRT | FLASH_WRP1AR_WRP1A_END), |
mbed_official | 610:813dcc80987e | 491 | (WRPStartOffset | (WRDPEndOffset << 16))); |
mbed_official | 610:813dcc80987e | 492 | } |
mbed_official | 610:813dcc80987e | 493 | else if(WRPArea == OB_WRPAREA_BANK1_AREAB) |
mbed_official | 610:813dcc80987e | 494 | { |
mbed_official | 610:813dcc80987e | 495 | MODIFY_REG(FLASH->WRP1BR, (FLASH_WRP1BR_WRP1B_STRT | FLASH_WRP1BR_WRP1B_END), |
mbed_official | 610:813dcc80987e | 496 | (WRPStartOffset | (WRDPEndOffset << 16))); |
mbed_official | 610:813dcc80987e | 497 | } |
mbed_official | 610:813dcc80987e | 498 | else if(WRPArea == OB_WRPAREA_BANK2_AREAA) |
mbed_official | 610:813dcc80987e | 499 | { |
mbed_official | 610:813dcc80987e | 500 | MODIFY_REG(FLASH->WRP2AR, (FLASH_WRP2AR_WRP2A_STRT | FLASH_WRP2AR_WRP2A_END), |
mbed_official | 610:813dcc80987e | 501 | (WRPStartOffset | (WRDPEndOffset << 16))); |
mbed_official | 610:813dcc80987e | 502 | } |
mbed_official | 610:813dcc80987e | 503 | else if(WRPArea == OB_WRPAREA_BANK2_AREAB) |
mbed_official | 610:813dcc80987e | 504 | { |
mbed_official | 610:813dcc80987e | 505 | MODIFY_REG(FLASH->WRP2BR, (FLASH_WRP2BR_WRP2B_STRT | FLASH_WRP2BR_WRP2B_END), |
mbed_official | 610:813dcc80987e | 506 | (WRPStartOffset | (WRDPEndOffset << 16))); |
mbed_official | 610:813dcc80987e | 507 | } |
mbed_official | 610:813dcc80987e | 508 | |
mbed_official | 610:813dcc80987e | 509 | /* Set OPTSTRT Bit */ |
mbed_official | 610:813dcc80987e | 510 | SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT); |
mbed_official | 610:813dcc80987e | 511 | |
mbed_official | 610:813dcc80987e | 512 | /* Wait for last operation to be completed */ |
mbed_official | 610:813dcc80987e | 513 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 610:813dcc80987e | 514 | |
mbed_official | 610:813dcc80987e | 515 | /* If the option byte program operation is completed, disable the OPTSTRT Bit */ |
mbed_official | 610:813dcc80987e | 516 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT); |
mbed_official | 610:813dcc80987e | 517 | } |
mbed_official | 610:813dcc80987e | 518 | |
mbed_official | 610:813dcc80987e | 519 | return status; |
mbed_official | 610:813dcc80987e | 520 | } |
mbed_official | 610:813dcc80987e | 521 | |
mbed_official | 610:813dcc80987e | 522 | /** |
mbed_official | 610:813dcc80987e | 523 | * @brief Set the read protection level. |
mbed_official | 610:813dcc80987e | 524 | * |
mbed_official | 610:813dcc80987e | 525 | * @note To configure the RDP level, the option lock bit OPTLOCK must be |
mbed_official | 610:813dcc80987e | 526 | * cleared with the call of the HAL_FLASH_OB_Unlock() function. |
mbed_official | 610:813dcc80987e | 527 | * @note To validate the RDP level, the option bytes must be reloaded |
mbed_official | 610:813dcc80987e | 528 | * through the call of the HAL_FLASH_OB_Launch() function. |
mbed_official | 610:813dcc80987e | 529 | * @note !!! Warning : When enabling OB_RDP level 2 it's no more possible |
mbed_official | 610:813dcc80987e | 530 | * to go back to level 1 or 0 !!! |
mbed_official | 610:813dcc80987e | 531 | * |
mbed_official | 610:813dcc80987e | 532 | * @param RDPLevel: specifies the read protection level. |
mbed_official | 610:813dcc80987e | 533 | * This parameter can be one of the following values: |
mbed_official | 610:813dcc80987e | 534 | * @arg OB_RDP_LEVEL_0: No protection |
mbed_official | 610:813dcc80987e | 535 | * @arg OB_RDP_LEVEL_1: Read protection of the memory |
mbed_official | 610:813dcc80987e | 536 | * @arg OB_RDP_LEVEL_2: Full chip protection |
mbed_official | 610:813dcc80987e | 537 | * |
mbed_official | 610:813dcc80987e | 538 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 539 | */ |
mbed_official | 610:813dcc80987e | 540 | static HAL_StatusTypeDef FLASH_OB_RDPConfig(uint32_t RDPLevel) |
mbed_official | 610:813dcc80987e | 541 | { |
mbed_official | 610:813dcc80987e | 542 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 610:813dcc80987e | 543 | |
mbed_official | 610:813dcc80987e | 544 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 545 | assert_param(IS_OB_RDP_LEVEL(RDPLevel)); |
mbed_official | 610:813dcc80987e | 546 | |
mbed_official | 610:813dcc80987e | 547 | /* Wait for last operation to be completed */ |
mbed_official | 610:813dcc80987e | 548 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 610:813dcc80987e | 549 | |
mbed_official | 610:813dcc80987e | 550 | if(status == HAL_OK) |
mbed_official | 610:813dcc80987e | 551 | { |
mbed_official | 610:813dcc80987e | 552 | /* Configure the RDP level in the option bytes register */ |
mbed_official | 610:813dcc80987e | 553 | MODIFY_REG(FLASH->OPTR, FLASH_OPTR_RDP, RDPLevel); |
mbed_official | 610:813dcc80987e | 554 | |
mbed_official | 610:813dcc80987e | 555 | /* Set OPTSTRT Bit */ |
mbed_official | 610:813dcc80987e | 556 | SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT); |
mbed_official | 610:813dcc80987e | 557 | |
mbed_official | 610:813dcc80987e | 558 | /* Wait for last operation to be completed */ |
mbed_official | 610:813dcc80987e | 559 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 610:813dcc80987e | 560 | |
mbed_official | 610:813dcc80987e | 561 | /* If the option byte program operation is completed, disable the OPTSTRT Bit */ |
mbed_official | 610:813dcc80987e | 562 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT); |
mbed_official | 610:813dcc80987e | 563 | } |
mbed_official | 610:813dcc80987e | 564 | |
mbed_official | 610:813dcc80987e | 565 | return status; |
mbed_official | 610:813dcc80987e | 566 | } |
mbed_official | 610:813dcc80987e | 567 | |
mbed_official | 610:813dcc80987e | 568 | /** |
mbed_official | 610:813dcc80987e | 569 | * @brief Program the FLASH User Option Byte. |
mbed_official | 610:813dcc80987e | 570 | * |
mbed_official | 610:813dcc80987e | 571 | * @note To configure the user option bytes, the option lock bit OPTLOCK must |
mbed_official | 610:813dcc80987e | 572 | * be cleared with the call of the HAL_FLASH_OB_Unlock() function. |
mbed_official | 610:813dcc80987e | 573 | * @note To validate the user option bytes, the option bytes must be reloaded |
mbed_official | 610:813dcc80987e | 574 | * through the call of the HAL_FLASH_OB_Launch() function. |
mbed_official | 610:813dcc80987e | 575 | * |
mbed_official | 610:813dcc80987e | 576 | * @param UserType: The FLASH User Option Bytes to be modified |
mbed_official | 610:813dcc80987e | 577 | * @param UserConfig: The FLASH User Option Bytes values: |
mbed_official | 610:813dcc80987e | 578 | * BOR_LEV(Bit8-10), nRST_STOP(Bit12), nRST_STDBY(Bit13), IWDG_SW(Bit16), |
mbed_official | 610:813dcc80987e | 579 | * IWDG_STOP(Bit17), IWDG_STDBY(Bit18), WWDG_SW(Bit19), BFB2(Bit20), |
mbed_official | 610:813dcc80987e | 580 | * DUALBANK(Bit21), nBOOT1(Bit23), SRAM2_PE(Bit24) and SRAM2_RST(Bit25). |
mbed_official | 610:813dcc80987e | 581 | * |
mbed_official | 610:813dcc80987e | 582 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 583 | */ |
mbed_official | 610:813dcc80987e | 584 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint32_t UserType, uint32_t UserConfig) |
mbed_official | 610:813dcc80987e | 585 | { |
mbed_official | 610:813dcc80987e | 586 | uint32_t optr_reg_val = 0; |
mbed_official | 610:813dcc80987e | 587 | uint32_t optr_reg_mask = 0; |
mbed_official | 610:813dcc80987e | 588 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 610:813dcc80987e | 589 | |
mbed_official | 610:813dcc80987e | 590 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 591 | assert_param(IS_OB_USER_TYPE(UserType)); |
mbed_official | 610:813dcc80987e | 592 | |
mbed_official | 610:813dcc80987e | 593 | /* Wait for last operation to be completed */ |
mbed_official | 610:813dcc80987e | 594 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 610:813dcc80987e | 595 | |
mbed_official | 610:813dcc80987e | 596 | if(status == HAL_OK) |
mbed_official | 610:813dcc80987e | 597 | { |
mbed_official | 610:813dcc80987e | 598 | if((UserType & OB_USER_BOR_LEV) != RESET) |
mbed_official | 610:813dcc80987e | 599 | { |
mbed_official | 610:813dcc80987e | 600 | /* BOR level option byte should be modified */ |
mbed_official | 610:813dcc80987e | 601 | assert_param(IS_OB_USER_BOR_LEVEL(UserConfig & FLASH_OPTR_BOR_LEV)); |
mbed_official | 610:813dcc80987e | 602 | |
mbed_official | 610:813dcc80987e | 603 | /* Set value and mask for BOR level option byte */ |
mbed_official | 610:813dcc80987e | 604 | optr_reg_val |= (UserConfig & FLASH_OPTR_BOR_LEV); |
mbed_official | 610:813dcc80987e | 605 | optr_reg_mask |= FLASH_OPTR_BOR_LEV; |
mbed_official | 610:813dcc80987e | 606 | } |
mbed_official | 610:813dcc80987e | 607 | |
mbed_official | 610:813dcc80987e | 608 | if((UserType & OB_USER_nRST_STOP) != RESET) |
mbed_official | 610:813dcc80987e | 609 | { |
mbed_official | 610:813dcc80987e | 610 | /* nRST_STOP option byte should be modified */ |
mbed_official | 610:813dcc80987e | 611 | assert_param(IS_OB_USER_STOP(UserConfig & FLASH_OPTR_nRST_STOP)); |
mbed_official | 610:813dcc80987e | 612 | |
mbed_official | 610:813dcc80987e | 613 | /* Set value and mask for nRST_STOP option byte */ |
mbed_official | 610:813dcc80987e | 614 | optr_reg_val |= (UserConfig & FLASH_OPTR_nRST_STOP); |
mbed_official | 610:813dcc80987e | 615 | optr_reg_mask |= FLASH_OPTR_nRST_STOP; |
mbed_official | 610:813dcc80987e | 616 | } |
mbed_official | 610:813dcc80987e | 617 | |
mbed_official | 610:813dcc80987e | 618 | if((UserType & OB_USER_nRST_STDBY) != RESET) |
mbed_official | 610:813dcc80987e | 619 | { |
mbed_official | 610:813dcc80987e | 620 | /* nRST_STDBY option byte should be modified */ |
mbed_official | 610:813dcc80987e | 621 | assert_param(IS_OB_USER_STANDBY(UserConfig & FLASH_OPTR_nRST_STDBY)); |
mbed_official | 610:813dcc80987e | 622 | |
mbed_official | 610:813dcc80987e | 623 | /* Set value and mask for nRST_STDBY option byte */ |
mbed_official | 610:813dcc80987e | 624 | optr_reg_val |= (UserConfig & FLASH_OPTR_nRST_STDBY); |
mbed_official | 610:813dcc80987e | 625 | optr_reg_mask |= FLASH_OPTR_nRST_STDBY; |
mbed_official | 610:813dcc80987e | 626 | } |
mbed_official | 610:813dcc80987e | 627 | |
mbed_official | 610:813dcc80987e | 628 | if((UserType & OB_USER_IWDG_SW) != RESET) |
mbed_official | 610:813dcc80987e | 629 | { |
mbed_official | 610:813dcc80987e | 630 | /* IWDG_SW option byte should be modified */ |
mbed_official | 610:813dcc80987e | 631 | assert_param(IS_OB_USER_IWDG(UserConfig & FLASH_OPTR_IWDG_SW)); |
mbed_official | 610:813dcc80987e | 632 | |
mbed_official | 610:813dcc80987e | 633 | /* Set value and mask for IWDG_SW option byte */ |
mbed_official | 610:813dcc80987e | 634 | optr_reg_val |= (UserConfig & FLASH_OPTR_IWDG_SW); |
mbed_official | 610:813dcc80987e | 635 | optr_reg_mask |= FLASH_OPTR_IWDG_SW; |
mbed_official | 610:813dcc80987e | 636 | } |
mbed_official | 610:813dcc80987e | 637 | |
mbed_official | 610:813dcc80987e | 638 | if((UserType & OB_USER_IWDG_STOP) != RESET) |
mbed_official | 610:813dcc80987e | 639 | { |
mbed_official | 610:813dcc80987e | 640 | /* IWDG_STOP option byte should be modified */ |
mbed_official | 610:813dcc80987e | 641 | assert_param(IS_OB_USER_IWDG_STOP(UserConfig & FLASH_OPTR_IWDG_STOP)); |
mbed_official | 610:813dcc80987e | 642 | |
mbed_official | 610:813dcc80987e | 643 | /* Set value and mask for IWDG_STOP option byte */ |
mbed_official | 610:813dcc80987e | 644 | optr_reg_val |= (UserConfig & FLASH_OPTR_IWDG_STOP); |
mbed_official | 610:813dcc80987e | 645 | optr_reg_mask |= FLASH_OPTR_IWDG_STOP; |
mbed_official | 610:813dcc80987e | 646 | } |
mbed_official | 610:813dcc80987e | 647 | |
mbed_official | 610:813dcc80987e | 648 | if((UserType & OB_USER_IWDG_STDBY) != RESET) |
mbed_official | 610:813dcc80987e | 649 | { |
mbed_official | 610:813dcc80987e | 650 | /* IWDG_STDBY option byte should be modified */ |
mbed_official | 610:813dcc80987e | 651 | assert_param(IS_OB_USER_IWDG_STDBY(UserConfig & FLASH_OPTR_IWDG_STDBY)); |
mbed_official | 610:813dcc80987e | 652 | |
mbed_official | 610:813dcc80987e | 653 | /* Set value and mask for IWDG_STDBY option byte */ |
mbed_official | 610:813dcc80987e | 654 | optr_reg_val |= (UserConfig & FLASH_OPTR_IWDG_STDBY); |
mbed_official | 610:813dcc80987e | 655 | optr_reg_mask |= FLASH_OPTR_IWDG_STDBY; |
mbed_official | 610:813dcc80987e | 656 | } |
mbed_official | 610:813dcc80987e | 657 | |
mbed_official | 610:813dcc80987e | 658 | if((UserType & OB_USER_WWDG_SW) != RESET) |
mbed_official | 610:813dcc80987e | 659 | { |
mbed_official | 610:813dcc80987e | 660 | /* WWDG_SW option byte should be modified */ |
mbed_official | 610:813dcc80987e | 661 | assert_param(IS_OB_USER_WWDG(UserConfig & FLASH_OPTR_WWDG_SW)); |
mbed_official | 610:813dcc80987e | 662 | |
mbed_official | 610:813dcc80987e | 663 | /* Set value and mask for WWDG_SW option byte */ |
mbed_official | 610:813dcc80987e | 664 | optr_reg_val |= (UserConfig & FLASH_OPTR_WWDG_SW); |
mbed_official | 610:813dcc80987e | 665 | optr_reg_mask |= FLASH_OPTR_WWDG_SW; |
mbed_official | 610:813dcc80987e | 666 | } |
mbed_official | 610:813dcc80987e | 667 | |
mbed_official | 610:813dcc80987e | 668 | if((UserType & OB_USER_BFB2) != RESET) |
mbed_official | 610:813dcc80987e | 669 | { |
mbed_official | 610:813dcc80987e | 670 | /* BFB2 option byte should be modified */ |
mbed_official | 610:813dcc80987e | 671 | assert_param(IS_OB_USER_BFB2(UserConfig & FLASH_OPTR_BFB2)); |
mbed_official | 610:813dcc80987e | 672 | |
mbed_official | 610:813dcc80987e | 673 | /* Set value and mask for BFB2 option byte */ |
mbed_official | 610:813dcc80987e | 674 | optr_reg_val |= (UserConfig & FLASH_OPTR_BFB2); |
mbed_official | 610:813dcc80987e | 675 | optr_reg_mask |= FLASH_OPTR_BFB2; |
mbed_official | 610:813dcc80987e | 676 | } |
mbed_official | 610:813dcc80987e | 677 | |
mbed_official | 610:813dcc80987e | 678 | if((UserType & OB_USER_DUALBANK) != RESET) |
mbed_official | 610:813dcc80987e | 679 | { |
mbed_official | 610:813dcc80987e | 680 | /* DUALBANK option byte should be modified */ |
mbed_official | 610:813dcc80987e | 681 | assert_param(IS_OB_USER_DUALBANK(UserConfig & FLASH_OPTR_DUALBANK)); |
mbed_official | 610:813dcc80987e | 682 | |
mbed_official | 610:813dcc80987e | 683 | /* Set value and mask for DUALBANK option byte */ |
mbed_official | 610:813dcc80987e | 684 | optr_reg_val |= (UserConfig & FLASH_OPTR_DUALBANK); |
mbed_official | 610:813dcc80987e | 685 | optr_reg_mask |= FLASH_OPTR_DUALBANK; |
mbed_official | 610:813dcc80987e | 686 | } |
mbed_official | 610:813dcc80987e | 687 | |
mbed_official | 610:813dcc80987e | 688 | if((UserType & OB_USER_nBOOT1) != RESET) |
mbed_official | 610:813dcc80987e | 689 | { |
mbed_official | 610:813dcc80987e | 690 | /* nBOOT1 option byte should be modified */ |
mbed_official | 610:813dcc80987e | 691 | assert_param(IS_OB_USER_BOOT1(UserConfig & FLASH_OPTR_nBOOT1)); |
mbed_official | 610:813dcc80987e | 692 | |
mbed_official | 610:813dcc80987e | 693 | /* Set value and mask for nBOOT1 option byte */ |
mbed_official | 610:813dcc80987e | 694 | optr_reg_val |= (UserConfig & FLASH_OPTR_nBOOT1); |
mbed_official | 610:813dcc80987e | 695 | optr_reg_mask |= FLASH_OPTR_nBOOT1; |
mbed_official | 610:813dcc80987e | 696 | } |
mbed_official | 610:813dcc80987e | 697 | |
mbed_official | 610:813dcc80987e | 698 | if((UserType & OB_USER_SRAM2_PE) != RESET) |
mbed_official | 610:813dcc80987e | 699 | { |
mbed_official | 610:813dcc80987e | 700 | /* SRAM2_PE option byte should be modified */ |
mbed_official | 610:813dcc80987e | 701 | assert_param(IS_OB_USER_SRAM2_PARITY(UserConfig & FLASH_OPTR_SRAM2_PE)); |
mbed_official | 610:813dcc80987e | 702 | |
mbed_official | 610:813dcc80987e | 703 | /* Set value and mask for SRAM2_PE option byte */ |
mbed_official | 610:813dcc80987e | 704 | optr_reg_val |= (UserConfig & FLASH_OPTR_SRAM2_PE); |
mbed_official | 610:813dcc80987e | 705 | optr_reg_mask |= FLASH_OPTR_SRAM2_PE; |
mbed_official | 610:813dcc80987e | 706 | } |
mbed_official | 610:813dcc80987e | 707 | |
mbed_official | 610:813dcc80987e | 708 | if((UserType & OB_USER_SRAM2_RST) != RESET) |
mbed_official | 610:813dcc80987e | 709 | { |
mbed_official | 610:813dcc80987e | 710 | /* SRAM2_RST option byte should be modified */ |
mbed_official | 610:813dcc80987e | 711 | assert_param(IS_OB_USER_SRAM2_RST(UserConfig & FLASH_OPTR_SRAM2_RST)); |
mbed_official | 610:813dcc80987e | 712 | |
mbed_official | 610:813dcc80987e | 713 | /* Set value and mask for SRAM2_RST option byte */ |
mbed_official | 610:813dcc80987e | 714 | optr_reg_val |= (UserConfig & FLASH_OPTR_SRAM2_RST); |
mbed_official | 610:813dcc80987e | 715 | optr_reg_mask |= FLASH_OPTR_SRAM2_RST; |
mbed_official | 610:813dcc80987e | 716 | } |
mbed_official | 610:813dcc80987e | 717 | |
mbed_official | 610:813dcc80987e | 718 | /* Configure the option bytes register */ |
mbed_official | 610:813dcc80987e | 719 | MODIFY_REG(FLASH->OPTR, optr_reg_mask, optr_reg_val); |
mbed_official | 610:813dcc80987e | 720 | |
mbed_official | 610:813dcc80987e | 721 | /* Set OPTSTRT Bit */ |
mbed_official | 610:813dcc80987e | 722 | SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT); |
mbed_official | 610:813dcc80987e | 723 | |
mbed_official | 610:813dcc80987e | 724 | /* Wait for last operation to be completed */ |
mbed_official | 610:813dcc80987e | 725 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 610:813dcc80987e | 726 | |
mbed_official | 610:813dcc80987e | 727 | /* If the option byte program operation is completed, disable the OPTSTRT Bit */ |
mbed_official | 610:813dcc80987e | 728 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT); |
mbed_official | 610:813dcc80987e | 729 | } |
mbed_official | 610:813dcc80987e | 730 | |
mbed_official | 610:813dcc80987e | 731 | return status; |
mbed_official | 610:813dcc80987e | 732 | } |
mbed_official | 610:813dcc80987e | 733 | |
mbed_official | 610:813dcc80987e | 734 | /** |
mbed_official | 610:813dcc80987e | 735 | * @brief Configure the Proprietary code readout protection of the desired addresses. |
mbed_official | 610:813dcc80987e | 736 | * |
mbed_official | 610:813dcc80987e | 737 | * @note To configure the PCROP options, the option lock bit OPTLOCK must be |
mbed_official | 610:813dcc80987e | 738 | * cleared with the call of the HAL_FLASH_OB_Unlock() function. |
mbed_official | 610:813dcc80987e | 739 | * @note To validate the PCROP options, the option bytes must be reloaded |
mbed_official | 610:813dcc80987e | 740 | * through the call of the HAL_FLASH_OB_Launch() function. |
mbed_official | 610:813dcc80987e | 741 | * |
mbed_official | 610:813dcc80987e | 742 | * @param PCROPConfig: specifies the configuration (Bank to be configured and PCROP_RDP option). |
mbed_official | 610:813dcc80987e | 743 | * This parameter must be a combination of FLASH_BANK_1 or FLASH_BANK_2 |
mbed_official | 610:813dcc80987e | 744 | * with OB_PCROP_RDP_NOT_ERASE or OB_PCROP_RDP_ERASE |
mbed_official | 610:813dcc80987e | 745 | * |
mbed_official | 610:813dcc80987e | 746 | * @param PCROPStartAddr: specifies the start address of the Proprietary code readout protection |
mbed_official | 610:813dcc80987e | 747 | * This parameter can be an address between begin and end of the bank |
mbed_official | 610:813dcc80987e | 748 | * |
mbed_official | 610:813dcc80987e | 749 | * @param PCROPEndAddr: specifies the end address of the Proprietary code readout protection |
mbed_official | 610:813dcc80987e | 750 | * This parameter can be an address between PCROPStartAddr and end of the bank |
mbed_official | 610:813dcc80987e | 751 | * |
mbed_official | 610:813dcc80987e | 752 | * @retval HAL Status |
mbed_official | 610:813dcc80987e | 753 | */ |
mbed_official | 610:813dcc80987e | 754 | static HAL_StatusTypeDef FLASH_OB_PCROPConfig(uint32_t PCROPConfig, uint32_t PCROPStartAddr, uint32_t PCROPEndAddr) |
mbed_official | 610:813dcc80987e | 755 | { |
mbed_official | 610:813dcc80987e | 756 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 610:813dcc80987e | 757 | uint32_t reg_value = 0; |
mbed_official | 610:813dcc80987e | 758 | uint32_t bank1_addr, bank2_addr; |
mbed_official | 610:813dcc80987e | 759 | |
mbed_official | 610:813dcc80987e | 760 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 761 | assert_param(IS_FLASH_BANK_EXCLUSIVE(PCROPConfig & FLASH_BANK_BOTH)); |
mbed_official | 610:813dcc80987e | 762 | assert_param(IS_OB_PCROP_RDP(PCROPConfig & FLASH_PCROP1ER_PCROP_RDP)); |
mbed_official | 610:813dcc80987e | 763 | assert_param(IS_FLASH_MAIN_MEM_ADDRESS(PCROPStartAddr)); |
mbed_official | 610:813dcc80987e | 764 | assert_param(IS_FLASH_MAIN_MEM_ADDRESS(PCROPEndAddr)); |
mbed_official | 610:813dcc80987e | 765 | |
mbed_official | 610:813dcc80987e | 766 | /* Wait for last operation to be completed */ |
mbed_official | 610:813dcc80987e | 767 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 610:813dcc80987e | 768 | |
mbed_official | 610:813dcc80987e | 769 | if(status == HAL_OK) |
mbed_official | 610:813dcc80987e | 770 | { |
mbed_official | 610:813dcc80987e | 771 | /* Get the information about the bank swapping */ |
mbed_official | 610:813dcc80987e | 772 | if (READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_FB_MODE) == 0) |
mbed_official | 610:813dcc80987e | 773 | { |
mbed_official | 610:813dcc80987e | 774 | bank1_addr = FLASH_BASE; |
mbed_official | 610:813dcc80987e | 775 | bank2_addr = FLASH_BASE + FLASH_BANK_SIZE; |
mbed_official | 610:813dcc80987e | 776 | } |
mbed_official | 610:813dcc80987e | 777 | else |
mbed_official | 610:813dcc80987e | 778 | { |
mbed_official | 610:813dcc80987e | 779 | bank1_addr = FLASH_BASE + FLASH_BANK_SIZE; |
mbed_official | 610:813dcc80987e | 780 | bank2_addr = FLASH_BASE; |
mbed_official | 610:813dcc80987e | 781 | } |
mbed_official | 610:813dcc80987e | 782 | |
mbed_official | 610:813dcc80987e | 783 | /* Configure the Proprietary code readout protection */ |
mbed_official | 610:813dcc80987e | 784 | if((PCROPConfig & FLASH_BANK_BOTH) == FLASH_BANK_1) |
mbed_official | 610:813dcc80987e | 785 | { |
mbed_official | 610:813dcc80987e | 786 | reg_value = ((PCROPStartAddr - bank1_addr) >> 3); |
mbed_official | 610:813dcc80987e | 787 | MODIFY_REG(FLASH->PCROP1SR, FLASH_PCROP1SR_PCROP1_STRT, reg_value); |
mbed_official | 610:813dcc80987e | 788 | |
mbed_official | 610:813dcc80987e | 789 | reg_value = ((PCROPEndAddr - bank1_addr) >> 3); |
mbed_official | 610:813dcc80987e | 790 | MODIFY_REG(FLASH->PCROP1ER, FLASH_PCROP1ER_PCROP1_END, reg_value); |
mbed_official | 610:813dcc80987e | 791 | } |
mbed_official | 610:813dcc80987e | 792 | else if((PCROPConfig & FLASH_BANK_BOTH) == FLASH_BANK_2) |
mbed_official | 610:813dcc80987e | 793 | { |
mbed_official | 610:813dcc80987e | 794 | reg_value = ((PCROPStartAddr - bank2_addr) >> 3); |
mbed_official | 610:813dcc80987e | 795 | MODIFY_REG(FLASH->PCROP2SR, FLASH_PCROP2SR_PCROP2_STRT, reg_value); |
mbed_official | 610:813dcc80987e | 796 | |
mbed_official | 610:813dcc80987e | 797 | reg_value = ((PCROPEndAddr - bank2_addr) >> 3); |
mbed_official | 610:813dcc80987e | 798 | MODIFY_REG(FLASH->PCROP2ER, FLASH_PCROP2ER_PCROP2_END, reg_value); |
mbed_official | 610:813dcc80987e | 799 | } |
mbed_official | 610:813dcc80987e | 800 | |
mbed_official | 610:813dcc80987e | 801 | MODIFY_REG(FLASH->PCROP1ER, FLASH_PCROP1ER_PCROP_RDP, (PCROPConfig & FLASH_PCROP1ER_PCROP_RDP)); |
mbed_official | 610:813dcc80987e | 802 | |
mbed_official | 610:813dcc80987e | 803 | /* Set OPTSTRT Bit */ |
mbed_official | 610:813dcc80987e | 804 | SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT); |
mbed_official | 610:813dcc80987e | 805 | |
mbed_official | 610:813dcc80987e | 806 | /* Wait for last operation to be completed */ |
mbed_official | 610:813dcc80987e | 807 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 610:813dcc80987e | 808 | |
mbed_official | 610:813dcc80987e | 809 | /* If the option byte program operation is completed, disable the OPTSTRT Bit */ |
mbed_official | 610:813dcc80987e | 810 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT); |
mbed_official | 610:813dcc80987e | 811 | } |
mbed_official | 610:813dcc80987e | 812 | |
mbed_official | 610:813dcc80987e | 813 | return status; |
mbed_official | 610:813dcc80987e | 814 | } |
mbed_official | 610:813dcc80987e | 815 | |
mbed_official | 610:813dcc80987e | 816 | /** |
mbed_official | 610:813dcc80987e | 817 | * @brief Return the FLASH Write Protection Option Bytes value. |
mbed_official | 610:813dcc80987e | 818 | * |
mbed_official | 610:813dcc80987e | 819 | * @param[in] WRPArea: specifies the area to be returned. |
mbed_official | 610:813dcc80987e | 820 | * This parameter can be one of the following values: |
mbed_official | 610:813dcc80987e | 821 | * @arg OB_WRPAREA_BANK1_AREAA: Flash Bank 1 Area A |
mbed_official | 610:813dcc80987e | 822 | * @arg OB_WRPAREA_BANK1_AREAB: Flash Bank 1 Area B |
mbed_official | 610:813dcc80987e | 823 | * @arg OB_WRPAREA_BANK2_AREAA: Flash Bank 2 Area A |
mbed_official | 610:813dcc80987e | 824 | * @arg OB_WRPAREA_BANK2_AREAB: Flash Bank 2 Area B |
mbed_official | 610:813dcc80987e | 825 | * |
mbed_official | 610:813dcc80987e | 826 | * @param[out] WRPStartOffset: specifies the address where to copied the start page |
mbed_official | 610:813dcc80987e | 827 | * of the write protected area |
mbed_official | 610:813dcc80987e | 828 | * |
mbed_official | 610:813dcc80987e | 829 | * @param[out] WRDPEndOffset: specifies the address where to copied the end page of |
mbed_official | 610:813dcc80987e | 830 | * the write protected area |
mbed_official | 610:813dcc80987e | 831 | * |
mbed_official | 610:813dcc80987e | 832 | * @retval None |
mbed_official | 610:813dcc80987e | 833 | */ |
mbed_official | 610:813dcc80987e | 834 | static void FLASH_OB_GetWRP(uint32_t WRPArea, uint32_t * WRPStartOffset, uint32_t * WRDPEndOffset) |
mbed_official | 610:813dcc80987e | 835 | { |
mbed_official | 610:813dcc80987e | 836 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 837 | assert_param(IS_OB_WRPAREA(WRPArea)); |
mbed_official | 610:813dcc80987e | 838 | |
mbed_official | 610:813dcc80987e | 839 | /* Get the configuration of the write protected area */ |
mbed_official | 610:813dcc80987e | 840 | if(WRPArea == OB_WRPAREA_BANK1_AREAA) |
mbed_official | 610:813dcc80987e | 841 | { |
mbed_official | 610:813dcc80987e | 842 | *WRPStartOffset = READ_BIT(FLASH->WRP1AR, FLASH_WRP1AR_WRP1A_STRT); |
mbed_official | 610:813dcc80987e | 843 | *WRDPEndOffset = (READ_BIT(FLASH->WRP1AR, FLASH_WRP1AR_WRP1A_END) >> 16); |
mbed_official | 610:813dcc80987e | 844 | } |
mbed_official | 610:813dcc80987e | 845 | else if(WRPArea == OB_WRPAREA_BANK1_AREAB) |
mbed_official | 610:813dcc80987e | 846 | { |
mbed_official | 610:813dcc80987e | 847 | *WRPStartOffset = READ_BIT(FLASH->WRP1BR, FLASH_WRP1BR_WRP1B_STRT); |
mbed_official | 610:813dcc80987e | 848 | *WRDPEndOffset = (READ_BIT(FLASH->WRP1BR, FLASH_WRP1BR_WRP1B_END) >> 16); |
mbed_official | 610:813dcc80987e | 849 | } |
mbed_official | 610:813dcc80987e | 850 | else if(WRPArea == OB_WRPAREA_BANK2_AREAA) |
mbed_official | 610:813dcc80987e | 851 | { |
mbed_official | 610:813dcc80987e | 852 | *WRPStartOffset = READ_BIT(FLASH->WRP2AR, FLASH_WRP2AR_WRP2A_STRT); |
mbed_official | 610:813dcc80987e | 853 | *WRDPEndOffset = (READ_BIT(FLASH->WRP2AR, FLASH_WRP2AR_WRP2A_END) >> 16); |
mbed_official | 610:813dcc80987e | 854 | } |
mbed_official | 610:813dcc80987e | 855 | else if(WRPArea == OB_WRPAREA_BANK2_AREAB) |
mbed_official | 610:813dcc80987e | 856 | { |
mbed_official | 610:813dcc80987e | 857 | *WRPStartOffset = READ_BIT(FLASH->WRP2BR, FLASH_WRP2BR_WRP2B_STRT); |
mbed_official | 610:813dcc80987e | 858 | *WRDPEndOffset = (READ_BIT(FLASH->WRP2BR, FLASH_WRP2BR_WRP2B_END) >> 16); |
mbed_official | 610:813dcc80987e | 859 | } |
mbed_official | 610:813dcc80987e | 860 | } |
mbed_official | 610:813dcc80987e | 861 | |
mbed_official | 610:813dcc80987e | 862 | /** |
mbed_official | 610:813dcc80987e | 863 | * @brief Return the FLASH Read Protection level. |
mbed_official | 610:813dcc80987e | 864 | * @retval FLASH ReadOut Protection Status: |
mbed_official | 610:813dcc80987e | 865 | * This return value can be one of the following values: |
mbed_official | 610:813dcc80987e | 866 | * @arg OB_RDP_LEVEL_0: No protection |
mbed_official | 610:813dcc80987e | 867 | * @arg OB_RDP_LEVEL_1: Read protection of the memory |
mbed_official | 610:813dcc80987e | 868 | * @arg OB_RDP_LEVEL_2: Full chip protection |
mbed_official | 610:813dcc80987e | 869 | */ |
mbed_official | 610:813dcc80987e | 870 | static uint32_t FLASH_OB_GetRDP(void) |
mbed_official | 610:813dcc80987e | 871 | { |
mbed_official | 610:813dcc80987e | 872 | if ((READ_BIT(FLASH->OPTR, FLASH_OPTR_RDP) != OB_RDP_LEVEL_0) && |
mbed_official | 610:813dcc80987e | 873 | (READ_BIT(FLASH->OPTR, FLASH_OPTR_RDP) != OB_RDP_LEVEL_2)) |
mbed_official | 610:813dcc80987e | 874 | { |
mbed_official | 610:813dcc80987e | 875 | return (OB_RDP_LEVEL_1); |
mbed_official | 610:813dcc80987e | 876 | } |
mbed_official | 610:813dcc80987e | 877 | else |
mbed_official | 610:813dcc80987e | 878 | { |
mbed_official | 610:813dcc80987e | 879 | return (READ_BIT(FLASH->OPTR, FLASH_OPTR_RDP)); |
mbed_official | 610:813dcc80987e | 880 | } |
mbed_official | 610:813dcc80987e | 881 | } |
mbed_official | 610:813dcc80987e | 882 | |
mbed_official | 610:813dcc80987e | 883 | /** |
mbed_official | 610:813dcc80987e | 884 | * @brief Return the FLASH User Option Byte value. |
mbed_official | 610:813dcc80987e | 885 | * @retval The FLASH User Option Bytes values: |
mbed_official | 610:813dcc80987e | 886 | * BOR_LEV(Bit8-10), nRST_STOP(Bit12), nRST_STDBY(Bit13), IWDG_SW(Bit16), |
mbed_official | 610:813dcc80987e | 887 | * IWDG_STOP(Bit17), IWDG_STDBY(Bit18), WWDG_SW(Bit19), BFB2(Bit20), |
mbed_official | 610:813dcc80987e | 888 | * DUALBANK(Bit21), nBOOT1(Bit23), SRAM2_PE(Bit24) and SRAM2_RST(Bit25). |
mbed_official | 610:813dcc80987e | 889 | */ |
mbed_official | 610:813dcc80987e | 890 | static uint32_t FLASH_OB_GetUser(void) |
mbed_official | 610:813dcc80987e | 891 | { |
mbed_official | 610:813dcc80987e | 892 | uint32_t user_config = READ_REG(FLASH->OPTR); |
mbed_official | 610:813dcc80987e | 893 | CLEAR_BIT(user_config, FLASH_OPTR_RDP); |
mbed_official | 610:813dcc80987e | 894 | |
mbed_official | 610:813dcc80987e | 895 | return user_config; |
mbed_official | 610:813dcc80987e | 896 | } |
mbed_official | 610:813dcc80987e | 897 | |
mbed_official | 610:813dcc80987e | 898 | /** |
mbed_official | 610:813dcc80987e | 899 | * @brief Return the FLASH Write Protection Option Bytes value. |
mbed_official | 610:813dcc80987e | 900 | * |
mbed_official | 610:813dcc80987e | 901 | * @param PCROPConfig [inout]: specifies the configuration (Bank to be configured and PCROP_RDP option). |
mbed_official | 610:813dcc80987e | 902 | * This parameter must be a combination of FLASH_BANK_1 or FLASH_BANK_2 |
mbed_official | 610:813dcc80987e | 903 | * with OB_PCROP_RDP_NOT_ERASE or OB_PCROP_RDP_ERASE |
mbed_official | 610:813dcc80987e | 904 | * |
mbed_official | 610:813dcc80987e | 905 | * @param PCROPStartAddr [out]: specifies the address where to copied the start address |
mbed_official | 610:813dcc80987e | 906 | * of the Proprietary code readout protection |
mbed_official | 610:813dcc80987e | 907 | * |
mbed_official | 610:813dcc80987e | 908 | * @param PCROPEndAddr [out]: specifies the address where to copied the end address of |
mbed_official | 610:813dcc80987e | 909 | * the Proprietary code readout protection |
mbed_official | 610:813dcc80987e | 910 | * |
mbed_official | 610:813dcc80987e | 911 | * @retval None |
mbed_official | 610:813dcc80987e | 912 | */ |
mbed_official | 610:813dcc80987e | 913 | static void FLASH_OB_GetPCROP(uint32_t * PCROPConfig, uint32_t * PCROPStartAddr, uint32_t * PCROPEndAddr) |
mbed_official | 610:813dcc80987e | 914 | { |
mbed_official | 610:813dcc80987e | 915 | uint32_t reg_value = 0; |
mbed_official | 610:813dcc80987e | 916 | uint32_t bank1_addr, bank2_addr; |
mbed_official | 610:813dcc80987e | 917 | |
mbed_official | 610:813dcc80987e | 918 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 919 | assert_param(IS_FLASH_BANK_EXCLUSIVE((*PCROPConfig) & FLASH_BANK_BOTH)); |
mbed_official | 610:813dcc80987e | 920 | |
mbed_official | 610:813dcc80987e | 921 | /* Get the information about the bank swapping */ |
mbed_official | 610:813dcc80987e | 922 | if (READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_FB_MODE) == 0) |
mbed_official | 610:813dcc80987e | 923 | { |
mbed_official | 610:813dcc80987e | 924 | bank1_addr = FLASH_BASE; |
mbed_official | 610:813dcc80987e | 925 | bank2_addr = FLASH_BASE + FLASH_BANK_SIZE; |
mbed_official | 610:813dcc80987e | 926 | } |
mbed_official | 610:813dcc80987e | 927 | else |
mbed_official | 610:813dcc80987e | 928 | { |
mbed_official | 610:813dcc80987e | 929 | bank1_addr = FLASH_BASE + FLASH_BANK_SIZE; |
mbed_official | 610:813dcc80987e | 930 | bank2_addr = FLASH_BASE; |
mbed_official | 610:813dcc80987e | 931 | } |
mbed_official | 610:813dcc80987e | 932 | |
mbed_official | 610:813dcc80987e | 933 | if(((*PCROPConfig) & FLASH_BANK_BOTH) == FLASH_BANK_1) |
mbed_official | 610:813dcc80987e | 934 | { |
mbed_official | 610:813dcc80987e | 935 | reg_value = (READ_REG(FLASH->PCROP1SR) & FLASH_PCROP1SR_PCROP1_STRT); |
mbed_official | 610:813dcc80987e | 936 | *PCROPStartAddr = (reg_value << 3) + bank1_addr; |
mbed_official | 610:813dcc80987e | 937 | |
mbed_official | 610:813dcc80987e | 938 | reg_value = (READ_REG(FLASH->PCROP1ER) & FLASH_PCROP1ER_PCROP1_END); |
mbed_official | 610:813dcc80987e | 939 | *PCROPEndAddr = (reg_value << 3) + bank1_addr; |
mbed_official | 610:813dcc80987e | 940 | } |
mbed_official | 610:813dcc80987e | 941 | else if(((*PCROPConfig) & FLASH_BANK_BOTH) == FLASH_BANK_2) |
mbed_official | 610:813dcc80987e | 942 | { |
mbed_official | 610:813dcc80987e | 943 | reg_value = (READ_REG(FLASH->PCROP2SR) & FLASH_PCROP2SR_PCROP2_STRT); |
mbed_official | 610:813dcc80987e | 944 | *PCROPStartAddr = (reg_value << 3) + bank2_addr; |
mbed_official | 610:813dcc80987e | 945 | |
mbed_official | 610:813dcc80987e | 946 | reg_value = (READ_REG(FLASH->PCROP2ER) & FLASH_PCROP2ER_PCROP2_END); |
mbed_official | 610:813dcc80987e | 947 | *PCROPEndAddr = (reg_value << 3) + bank2_addr; |
mbed_official | 610:813dcc80987e | 948 | } |
mbed_official | 610:813dcc80987e | 949 | |
mbed_official | 610:813dcc80987e | 950 | *PCROPConfig |= (READ_REG(FLASH->PCROP1ER) & FLASH_PCROP1ER_PCROP_RDP); |
mbed_official | 610:813dcc80987e | 951 | } |
mbed_official | 610:813dcc80987e | 952 | /** |
mbed_official | 610:813dcc80987e | 953 | * @} |
mbed_official | 610:813dcc80987e | 954 | */ |
mbed_official | 610:813dcc80987e | 955 | |
mbed_official | 610:813dcc80987e | 956 | /** |
mbed_official | 610:813dcc80987e | 957 | * @} |
mbed_official | 610:813dcc80987e | 958 | */ |
mbed_official | 610:813dcc80987e | 959 | |
mbed_official | 610:813dcc80987e | 960 | #endif /* HAL_FLASH_MODULE_ENABLED */ |
mbed_official | 610:813dcc80987e | 961 | |
mbed_official | 610:813dcc80987e | 962 | /** |
mbed_official | 610:813dcc80987e | 963 | * @} |
mbed_official | 610:813dcc80987e | 964 | */ |
mbed_official | 610:813dcc80987e | 965 | |
mbed_official | 610:813dcc80987e | 966 | /** |
mbed_official | 610:813dcc80987e | 967 | * @} |
mbed_official | 610:813dcc80987e | 968 | */ |
mbed_official | 610:813dcc80987e | 969 | |
mbed_official | 610:813dcc80987e | 970 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |