Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
stm32f1xx_hal_flash_ex.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f1xx_hal_flash_ex.c 00004 * @author MCD Application Team 00005 * @version V1.0.4 00006 * @date 29-April-2016 00007 * @brief Extended FLASH HAL module driver. 00008 * 00009 * This file provides firmware functions to manage the following 00010 * functionalities of the FLASH peripheral: 00011 * + Extended Initialization/de-initialization functions 00012 * + Extended I/O operation functions 00013 * + Extended Peripheral Control functions 00014 * 00015 @verbatim 00016 ============================================================================== 00017 ##### Flash peripheral extended features ##### 00018 ============================================================================== 00019 00020 ##### How to use this driver ##### 00021 ============================================================================== 00022 [..] This driver provides functions to configure and program the FLASH memory 00023 of all STM32F1xxx devices. It includes 00024 00025 (++) Set/Reset the write protection 00026 (++) Program the user Option Bytes 00027 (++) Get the Read protection Level 00028 00029 @endverbatim 00030 ****************************************************************************** 00031 * @attention 00032 * 00033 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00034 * 00035 * Redistribution and use in source and binary forms, with or without modification, 00036 * are permitted provided that the following conditions are met: 00037 * 1. Redistributions of source code must retain the above copyright notice, 00038 * this list of conditions and the following disclaimer. 00039 * 2. Redistributions in binary form must reproduce the above copyright notice, 00040 * this list of conditions and the following disclaimer in the documentation 00041 * and/or other materials provided with the distribution. 00042 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00043 * may be used to endorse or promote products derived from this software 00044 * without specific prior written permission. 00045 * 00046 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00047 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00048 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00049 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00050 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00051 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00052 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00053 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00054 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00055 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00056 * 00057 ****************************************************************************** 00058 */ 00059 00060 /* Includes ------------------------------------------------------------------*/ 00061 #include "stm32f1xx_hal.h" 00062 00063 /** @addtogroup STM32F1xx_HAL_Driver 00064 * @{ 00065 */ 00066 #ifdef HAL_FLASH_MODULE_ENABLED 00067 00068 /** @addtogroup FLASH 00069 * @{ 00070 */ 00071 /** @addtogroup FLASH_Private_Variables 00072 * @{ 00073 */ 00074 /* Variables used for Erase pages under interruption*/ 00075 extern FLASH_ProcessTypeDef pFlash; 00076 /** 00077 * @} 00078 */ 00079 00080 /** 00081 * @} 00082 */ 00083 00084 /** @defgroup FLASHEx FLASHEx 00085 * @brief FLASH HAL Extension module driver 00086 * @{ 00087 */ 00088 00089 /* Private typedef -----------------------------------------------------------*/ 00090 /* Private define ------------------------------------------------------------*/ 00091 /** @defgroup FLASHEx_Private_Constants FLASHEx Private Constants 00092 * @{ 00093 */ 00094 #define FLASH_POSITION_IWDGSW_BIT (uint32_t)POSITION_VAL(FLASH_OBR_IWDG_SW) 00095 #define FLASH_POSITION_OB_USERDATA0_BIT (uint32_t)POSITION_VAL(FLASH_OBR_DATA0) 00096 #define FLASH_POSITION_OB_USERDATA1_BIT (uint32_t)POSITION_VAL(FLASH_OBR_DATA1) 00097 /** 00098 * @} 00099 */ 00100 00101 /* Private macro -------------------------------------------------------------*/ 00102 /** @defgroup FLASHEx_Private_Macros FLASHEx Private Macros 00103 * @{ 00104 */ 00105 /** 00106 * @} 00107 */ 00108 00109 /* Private variables ---------------------------------------------------------*/ 00110 /* Private function prototypes -----------------------------------------------*/ 00111 /** @defgroup FLASHEx_Private_Functions FLASHEx Private Functions 00112 * @{ 00113 */ 00114 /* Erase operations */ 00115 static void FLASH_MassErase(uint32_t Banks); 00116 00117 /* Option bytes control */ 00118 static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage); 00119 static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage); 00120 static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel); 00121 static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig); 00122 static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data); 00123 static uint32_t FLASH_OB_GetWRP(void); 00124 static uint32_t FLASH_OB_GetRDP(void); 00125 static uint8_t FLASH_OB_GetUser(void); 00126 00127 /** 00128 * @} 00129 */ 00130 00131 /* Exported functions ---------------------------------------------------------*/ 00132 /** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions 00133 * @{ 00134 */ 00135 00136 /** @defgroup FLASHEx_Exported_Functions_Group1 FLASHEx Memory Erasing functions 00137 * @brief FLASH Memory Erasing functions 00138 * 00139 @verbatim 00140 ============================================================================== 00141 ##### FLASH Erasing Programming functions ##### 00142 ============================================================================== 00143 00144 [..] The FLASH Memory Erasing functions, includes the following functions: 00145 (+) @ref HAL_FLASHEx_Erase: return only when erase has been done 00146 (+) @ref HAL_FLASHEx_Erase_IT: end of erase is done when @ref HAL_FLASH_EndOfOperationCallback 00147 is called with parameter 0xFFFFFFFF 00148 00149 [..] Any operation of erase should follow these steps: 00150 (#) Call the @ref HAL_FLASH_Unlock() function to enable the flash control register and 00151 program memory access. 00152 (#) Call the desired function to erase page. 00153 (#) Call the @ref HAL_FLASH_Lock() to disable the flash program memory access 00154 (recommended to protect the FLASH memory against possible unwanted operation). 00155 00156 @endverbatim 00157 * @{ 00158 */ 00159 00160 00161 /** 00162 * @brief Perform a mass erase or erase the specified FLASH memory pages 00163 * @note To correctly run this function, the @ref HAL_FLASH_Unlock() function 00164 * must be called before. 00165 * Call the @ref HAL_FLASH_Lock() to disable the flash memory access 00166 * (recommended to protect the FLASH memory against possible unwanted operation) 00167 * @param[in] pEraseInit pointer to an FLASH_EraseInitTypeDef structure that 00168 * contains the configuration information for the erasing. 00169 * 00170 * @param[out] PageError pointer to variable that 00171 * contains the configuration information on faulty page in case of error 00172 * (0xFFFFFFFF means that all the pages have been correctly erased) 00173 * 00174 * @retval HAL_StatusTypeDef HAL Status 00175 */ 00176 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError) 00177 { 00178 HAL_StatusTypeDef status = HAL_ERROR; 00179 uint32_t address = 0; 00180 00181 /* Process Locked */ 00182 __HAL_LOCK(&pFlash); 00183 00184 /* Check the parameters */ 00185 assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); 00186 00187 if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) 00188 { 00189 #if defined(FLASH_BANK2_END) 00190 if (pEraseInit->Banks == FLASH_BANK_BOTH) 00191 { 00192 /* Mass Erase requested for Bank1 and Bank2 */ 00193 /* Wait for last operation to be completed */ 00194 if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && \ 00195 (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)) 00196 { 00197 /*Mass erase to be done*/ 00198 FLASH_MassErase(FLASH_BANK_BOTH); 00199 00200 /* Wait for last operation to be completed */ 00201 if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && \ 00202 (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)) 00203 { 00204 status = HAL_OK; 00205 } 00206 00207 /* If the erase operation is completed, disable the MER Bit */ 00208 CLEAR_BIT(FLASH->CR, FLASH_CR_MER); 00209 CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER); 00210 } 00211 } 00212 else if (pEraseInit->Banks == FLASH_BANK_2) 00213 { 00214 /* Mass Erase requested for Bank2 */ 00215 /* Wait for last operation to be completed */ 00216 if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) 00217 { 00218 /*Mass erase to be done*/ 00219 FLASH_MassErase(FLASH_BANK_2); 00220 00221 /* Wait for last operation to be completed */ 00222 status = FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE); 00223 00224 /* If the erase operation is completed, disable the MER Bit */ 00225 CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER); 00226 } 00227 } 00228 else 00229 #endif /* FLASH_BANK2_END */ 00230 { 00231 /* Mass Erase requested for Bank1 */ 00232 /* Wait for last operation to be completed */ 00233 if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) 00234 { 00235 /*Mass erase to be done*/ 00236 FLASH_MassErase(FLASH_BANK_1); 00237 00238 /* Wait for last operation to be completed */ 00239 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00240 00241 /* If the erase operation is completed, disable the MER Bit */ 00242 CLEAR_BIT(FLASH->CR, FLASH_CR_MER); 00243 } 00244 } 00245 } 00246 else 00247 { 00248 /* Page Erase is requested */ 00249 /* Check the parameters */ 00250 assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress)); 00251 assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages)); 00252 00253 #if defined(FLASH_BANK2_END) 00254 /* Page Erase requested on address located on bank2 */ 00255 if(pEraseInit->PageAddress > FLASH_BANK1_END) 00256 { 00257 /* Wait for last operation to be completed */ 00258 if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) 00259 { 00260 /*Initialization of PageError variable*/ 00261 *PageError = 0xFFFFFFFF; 00262 00263 /* Erase by page by page to be done*/ 00264 for(address = pEraseInit->PageAddress; 00265 address < (pEraseInit->PageAddress + (pEraseInit->NbPages)*FLASH_PAGE_SIZE); 00266 address += FLASH_PAGE_SIZE) 00267 { 00268 FLASH_PageErase(address); 00269 00270 /* Wait for last operation to be completed */ 00271 status = FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE); 00272 00273 /* If the erase operation is completed, disable the PER Bit */ 00274 CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER); 00275 00276 if (status != HAL_OK) 00277 { 00278 /* In case of error, stop erase procedure and return the faulty address */ 00279 *PageError = address; 00280 break; 00281 } 00282 } 00283 } 00284 } 00285 else 00286 #endif /* FLASH_BANK2_END */ 00287 { 00288 /* Page Erase requested on address located on bank1 */ 00289 /* Wait for last operation to be completed */ 00290 if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) 00291 { 00292 /*Initialization of PageError variable*/ 00293 *PageError = 0xFFFFFFFF; 00294 00295 /* Erase page by page to be done*/ 00296 for(address = pEraseInit->PageAddress; 00297 address < ((pEraseInit->NbPages * FLASH_PAGE_SIZE) + pEraseInit->PageAddress); 00298 address += FLASH_PAGE_SIZE) 00299 { 00300 FLASH_PageErase(address); 00301 00302 /* Wait for last operation to be completed */ 00303 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00304 00305 /* If the erase operation is completed, disable the PER Bit */ 00306 CLEAR_BIT(FLASH->CR, FLASH_CR_PER); 00307 00308 if (status != HAL_OK) 00309 { 00310 /* In case of error, stop erase procedure and return the faulty address */ 00311 *PageError = address; 00312 break; 00313 } 00314 } 00315 } 00316 } 00317 } 00318 00319 /* Process Unlocked */ 00320 __HAL_UNLOCK(&pFlash); 00321 00322 return status; 00323 } 00324 00325 /** 00326 * @brief Perform a mass erase or erase the specified FLASH memory pages with interrupt enabled 00327 * @note To correctly run this function, the @ref HAL_FLASH_Unlock() function 00328 * must be called before. 00329 * Call the @ref HAL_FLASH_Lock() to disable the flash memory access 00330 * (recommended to protect the FLASH memory against possible unwanted operation) 00331 * @param pEraseInit pointer to an FLASH_EraseInitTypeDef structure that 00332 * contains the configuration information for the erasing. 00333 * 00334 * @retval HAL_StatusTypeDef HAL Status 00335 */ 00336 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) 00337 { 00338 HAL_StatusTypeDef status = HAL_OK; 00339 00340 /* Process Locked */ 00341 __HAL_LOCK(&pFlash); 00342 00343 /* If procedure already ongoing, reject the next one */ 00344 if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) 00345 { 00346 return HAL_ERROR; 00347 } 00348 00349 /* Check the parameters */ 00350 assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); 00351 00352 /* Enable End of FLASH Operation and Error source interrupts */ 00353 __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR); 00354 00355 #if defined(FLASH_BANK2_END) 00356 /* Enable End of FLASH Operation and Error source interrupts */ 00357 __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2); 00358 00359 #endif 00360 if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) 00361 { 00362 /*Mass erase to be done*/ 00363 pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE; 00364 FLASH_MassErase(pEraseInit->Banks); 00365 } 00366 else 00367 { 00368 /* Erase by page to be done*/ 00369 00370 /* Check the parameters */ 00371 assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress)); 00372 assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages)); 00373 00374 pFlash.ProcedureOnGoing = FLASH_PROC_PAGEERASE; 00375 pFlash.DataRemaining = pEraseInit->NbPages; 00376 pFlash.Address = pEraseInit->PageAddress; 00377 00378 /*Erase 1st page and wait for IT*/ 00379 FLASH_PageErase(pEraseInit->PageAddress); 00380 } 00381 00382 return status; 00383 } 00384 00385 /** 00386 * @} 00387 */ 00388 00389 /** @defgroup FLASHEx_Exported_Functions_Group2 Option Bytes Programming functions 00390 * @brief Option Bytes Programming functions 00391 * 00392 @verbatim 00393 ============================================================================== 00394 ##### Option Bytes Programming functions ##### 00395 ============================================================================== 00396 [..] 00397 This subsection provides a set of functions allowing to control the FLASH 00398 option bytes operations. 00399 00400 @endverbatim 00401 * @{ 00402 */ 00403 00404 /** 00405 * @brief Erases the FLASH option bytes. 00406 * @note This functions erases all option bytes except the Read protection (RDP). 00407 * The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface 00408 * The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes 00409 * The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes 00410 * (system reset will occur) 00411 * @retval HAL status 00412 */ 00413 00414 HAL_StatusTypeDef HAL_FLASHEx_OBErase(void) 00415 { 00416 uint8_t rdptmp = OB_RDP_LEVEL_0; 00417 HAL_StatusTypeDef status = HAL_ERROR; 00418 00419 /* Get the actual read protection Option Byte value */ 00420 rdptmp = FLASH_OB_GetRDP(); 00421 00422 /* Wait for last operation to be completed */ 00423 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00424 00425 if(status == HAL_OK) 00426 { 00427 /* Clean the error context */ 00428 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; 00429 00430 /* If the previous operation is completed, proceed to erase the option bytes */ 00431 SET_BIT(FLASH->CR, FLASH_CR_OPTER); 00432 SET_BIT(FLASH->CR, FLASH_CR_STRT); 00433 00434 /* Wait for last operation to be completed */ 00435 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00436 00437 /* If the erase operation is completed, disable the OPTER Bit */ 00438 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER); 00439 00440 if(status == HAL_OK) 00441 { 00442 /* Restore the last read protection Option Byte value */ 00443 status = FLASH_OB_RDP_LevelConfig(rdptmp); 00444 } 00445 } 00446 00447 /* Return the erase status */ 00448 return status; 00449 } 00450 00451 /** 00452 * @brief Program option bytes 00453 * @note The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface 00454 * The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes 00455 * The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes 00456 * (system reset will occur) 00457 * 00458 * @param pOBInit pointer to an FLASH_OBInitStruct structure that 00459 * contains the configuration information for the programming. 00460 * 00461 * @retval HAL_StatusTypeDef HAL Status 00462 */ 00463 HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) 00464 { 00465 HAL_StatusTypeDef status = HAL_ERROR; 00466 00467 /* Process Locked */ 00468 __HAL_LOCK(&pFlash); 00469 00470 /* Check the parameters */ 00471 assert_param(IS_OPTIONBYTE(pOBInit->OptionType)); 00472 00473 /* Write protection configuration */ 00474 if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP) 00475 { 00476 assert_param(IS_WRPSTATE(pOBInit->WRPState)); 00477 if (pOBInit->WRPState == OB_WRPSTATE_ENABLE) 00478 { 00479 /* Enable of Write protection on the selected page */ 00480 status = FLASH_OB_EnableWRP(pOBInit->WRPPage); 00481 } 00482 else 00483 { 00484 /* Disable of Write protection on the selected page */ 00485 status = FLASH_OB_DisableWRP(pOBInit->WRPPage); 00486 } 00487 if (status != HAL_OK) 00488 { 00489 /* Process Unlocked */ 00490 __HAL_UNLOCK(&pFlash); 00491 return status; 00492 } 00493 } 00494 00495 /* Read protection configuration */ 00496 if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) 00497 { 00498 status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel); 00499 if (status != HAL_OK) 00500 { 00501 /* Process Unlocked */ 00502 __HAL_UNLOCK(&pFlash); 00503 return status; 00504 } 00505 } 00506 00507 /* USER configuration */ 00508 if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) 00509 { 00510 status = FLASH_OB_UserConfig(pOBInit->USERConfig); 00511 if (status != HAL_OK) 00512 { 00513 /* Process Unlocked */ 00514 __HAL_UNLOCK(&pFlash); 00515 return status; 00516 } 00517 } 00518 00519 /* DATA configuration*/ 00520 if((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA) 00521 { 00522 status = FLASH_OB_ProgramData(pOBInit->DATAAddress, pOBInit->DATAData); 00523 if (status != HAL_OK) 00524 { 00525 /* Process Unlocked */ 00526 __HAL_UNLOCK(&pFlash); 00527 return status; 00528 } 00529 } 00530 00531 /* Process Unlocked */ 00532 __HAL_UNLOCK(&pFlash); 00533 00534 return status; 00535 } 00536 00537 /** 00538 * @brief Get the Option byte configuration 00539 * @param pOBInit pointer to an FLASH_OBInitStruct structure that 00540 * contains the configuration information for the programming. 00541 * 00542 * @retval None 00543 */ 00544 void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) 00545 { 00546 pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER; 00547 00548 /*Get WRP*/ 00549 pOBInit->WRPPage = FLASH_OB_GetWRP(); 00550 00551 /*Get RDP Level*/ 00552 pOBInit->RDPLevel = FLASH_OB_GetRDP(); 00553 00554 /*Get USER*/ 00555 pOBInit->USERConfig = FLASH_OB_GetUser(); 00556 } 00557 00558 /** 00559 * @brief Get the Option byte user data 00560 * @param DATAAdress Address of the option byte DATA 00561 * This parameter can be one of the following values: 00562 * @arg @ref OB_DATA_ADDRESS_DATA0 00563 * @arg @ref OB_DATA_ADDRESS_DATA1 00564 * @retval Value programmed in USER data 00565 */ 00566 uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress) 00567 { 00568 uint32_t value = 0; 00569 00570 if (DATAAdress == OB_DATA_ADDRESS_DATA0) 00571 { 00572 /* Get value programmed in OB USER Data0 */ 00573 value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA0) >> FLASH_POSITION_OB_USERDATA0_BIT; 00574 } 00575 else 00576 { 00577 /* Get value programmed in OB USER Data1 */ 00578 value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA1) >> FLASH_POSITION_OB_USERDATA1_BIT; 00579 } 00580 00581 return value; 00582 } 00583 00584 /** 00585 * @} 00586 */ 00587 00588 /** 00589 * @} 00590 */ 00591 00592 /** @addtogroup FLASHEx_Private_Functions 00593 * @{ 00594 */ 00595 00596 /** 00597 * @brief Full erase of FLASH memory Bank 00598 * @param Banks Banks to be erased 00599 * This parameter can be one of the following values: 00600 * @arg @ref FLASH_BANK_1 Bank1 to be erased 00601 @if STM32F101xG 00602 * @arg @ref FLASH_BANK_2 Bank2 to be erased 00603 * @arg @ref FLASH_BANK_BOTH Bank1 and Bank2 to be erased 00604 @endif 00605 @if STM32F103xG 00606 * @arg @ref FLASH_BANK_2 Bank2 to be erased 00607 * @arg @ref FLASH_BANK_BOTH Bank1 and Bank2 to be erased 00608 @endif 00609 * 00610 * @retval None 00611 */ 00612 static void FLASH_MassErase(uint32_t Banks) 00613 { 00614 /* Check the parameters */ 00615 assert_param(IS_FLASH_BANK(Banks)); 00616 00617 /* Clean the error context */ 00618 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; 00619 00620 #if defined(FLASH_BANK2_END) 00621 if(Banks == FLASH_BANK_BOTH) 00622 { 00623 /* bank1 & bank2 will be erased*/ 00624 SET_BIT(FLASH->CR, FLASH_CR_MER); 00625 SET_BIT(FLASH->CR2, FLASH_CR2_MER); 00626 SET_BIT(FLASH->CR, FLASH_CR_STRT); 00627 SET_BIT(FLASH->CR2, FLASH_CR2_STRT); 00628 } 00629 else if(Banks == FLASH_BANK_2) 00630 { 00631 /*Only bank2 will be erased*/ 00632 SET_BIT(FLASH->CR2, FLASH_CR2_MER); 00633 SET_BIT(FLASH->CR2, FLASH_CR2_STRT); 00634 } 00635 else 00636 { 00637 #endif /* FLASH_BANK2_END */ 00638 /* Only bank1 will be erased*/ 00639 SET_BIT(FLASH->CR, FLASH_CR_MER); 00640 SET_BIT(FLASH->CR, FLASH_CR_STRT); 00641 #if defined(FLASH_BANK2_END) 00642 } 00643 #endif /* FLASH_BANK2_END */ 00644 } 00645 00646 /** 00647 * @brief Enable the write protection of the desired pages 00648 * @note An option byte erase is done automatically in this function. 00649 * @note When the memory read protection level is selected (RDP level = 1), 00650 * it is not possible to program or erase the flash page i if 00651 * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 00652 * 00653 * @param WriteProtectPage specifies the page(s) to be write protected. 00654 * The value of this parameter depend on device used within the same series 00655 * @retval HAL status 00656 */ 00657 static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage) 00658 { 00659 HAL_StatusTypeDef status = HAL_OK; 00660 uint16_t WRP0_Data = 0xFFFF; 00661 #if defined(FLASH_WRP1_WRP1) 00662 uint16_t WRP1_Data = 0xFFFF; 00663 #endif /* FLASH_WRP1_WRP1 */ 00664 #if defined(FLASH_WRP2_WRP2) 00665 uint16_t WRP2_Data = 0xFFFF; 00666 #endif /* FLASH_WRP2_WRP2 */ 00667 #if defined(FLASH_WRP3_WRP3) 00668 uint16_t WRP3_Data = 0xFFFF; 00669 #endif /* FLASH_WRP3_WRP3 */ 00670 00671 /* Check the parameters */ 00672 assert_param(IS_OB_WRP(WriteProtectPage)); 00673 00674 /* Get current write protected pages and the new pages to be protected ******/ 00675 WriteProtectPage = (uint32_t)(~((~FLASH_OB_GetWRP()) | WriteProtectPage)); 00676 00677 #if defined(OB_WRP_PAGES0TO15MASK) 00678 WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK); 00679 #elif defined(OB_WRP_PAGES0TO31MASK) 00680 WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO31MASK); 00681 #endif /* OB_WRP_PAGES0TO31MASK */ 00682 00683 #if defined(OB_WRP_PAGES16TO31MASK) 00684 WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8); 00685 #elif defined(OB_WRP_PAGES32TO63MASK) 00686 WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO63MASK) >> 8); 00687 #endif /* OB_WRP_PAGES32TO63MASK */ 00688 00689 #if defined(OB_WRP_PAGES64TO95MASK) 00690 WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES64TO95MASK) >> 16); 00691 #endif /* OB_WRP_PAGES64TO95MASK */ 00692 #if defined(OB_WRP_PAGES32TO47MASK) 00693 WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16); 00694 #endif /* OB_WRP_PAGES32TO47MASK */ 00695 00696 #if defined(OB_WRP_PAGES96TO127MASK) 00697 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES96TO127MASK) >> 24); 00698 #elif defined(OB_WRP_PAGES48TO255MASK) 00699 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO255MASK) >> 24); 00700 #elif defined(OB_WRP_PAGES48TO511MASK) 00701 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO511MASK) >> 24); 00702 #elif defined(OB_WRP_PAGES48TO127MASK) 00703 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24); 00704 #endif /* OB_WRP_PAGES96TO127MASK */ 00705 00706 /* Wait for last operation to be completed */ 00707 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00708 00709 if(status == HAL_OK) 00710 { 00711 /* Clean the error context */ 00712 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; 00713 00714 /* To be able to write again option byte, need to perform a option byte erase */ 00715 status = HAL_FLASHEx_OBErase(); 00716 if (status == HAL_OK) 00717 { 00718 /* Enable write protection */ 00719 SET_BIT(FLASH->CR, FLASH_CR_OPTPG); 00720 00721 #if defined(FLASH_WRP0_WRP0) 00722 if(WRP0_Data != 0xFF) 00723 { 00724 OB->WRP0 &= WRP0_Data; 00725 00726 /* Wait for last operation to be completed */ 00727 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00728 } 00729 #endif /* FLASH_WRP0_WRP0 */ 00730 00731 #if defined(FLASH_WRP1_WRP1) 00732 if((status == HAL_OK) && (WRP1_Data != 0xFF)) 00733 { 00734 OB->WRP1 &= WRP1_Data; 00735 00736 /* Wait for last operation to be completed */ 00737 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00738 } 00739 #endif /* FLASH_WRP1_WRP1 */ 00740 00741 #if defined(FLASH_WRP2_WRP2) 00742 if((status == HAL_OK) && (WRP2_Data != 0xFF)) 00743 { 00744 OB->WRP2 &= WRP2_Data; 00745 00746 /* Wait for last operation to be completed */ 00747 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00748 } 00749 #endif /* FLASH_WRP2_WRP2 */ 00750 00751 #if defined(FLASH_WRP3_WRP3) 00752 if((status == HAL_OK) && (WRP3_Data != 0xFF)) 00753 { 00754 OB->WRP3 &= WRP3_Data; 00755 00756 /* Wait for last operation to be completed */ 00757 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00758 } 00759 #endif /* FLASH_WRP3_WRP3 */ 00760 00761 /* if the program operation is completed, disable the OPTPG Bit */ 00762 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); 00763 } 00764 } 00765 00766 return status; 00767 } 00768 00769 /** 00770 * @brief Disable the write protection of the desired pages 00771 * @note An option byte erase is done automatically in this function. 00772 * @note When the memory read protection level is selected (RDP level = 1), 00773 * it is not possible to program or erase the flash page i if 00774 * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 00775 * 00776 * @param WriteProtectPage specifies the page(s) to be write unprotected. 00777 * The value of this parameter depend on device used within the same series 00778 * @retval HAL status 00779 */ 00780 static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage) 00781 { 00782 HAL_StatusTypeDef status = HAL_OK; 00783 uint16_t WRP0_Data = 0xFFFF; 00784 #if defined(FLASH_WRP1_WRP1) 00785 uint16_t WRP1_Data = 0xFFFF; 00786 #endif /* FLASH_WRP1_WRP1 */ 00787 #if defined(FLASH_WRP2_WRP2) 00788 uint16_t WRP2_Data = 0xFFFF; 00789 #endif /* FLASH_WRP2_WRP2 */ 00790 #if defined(FLASH_WRP3_WRP3) 00791 uint16_t WRP3_Data = 0xFFFF; 00792 #endif /* FLASH_WRP3_WRP3 */ 00793 00794 /* Check the parameters */ 00795 assert_param(IS_OB_WRP(WriteProtectPage)); 00796 00797 /* Get current write protected pages and the new pages to be unprotected ******/ 00798 WriteProtectPage = (FLASH_OB_GetWRP() | WriteProtectPage); 00799 00800 #if defined(OB_WRP_PAGES0TO15MASK) 00801 WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK); 00802 #elif defined(OB_WRP_PAGES0TO31MASK) 00803 WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO31MASK); 00804 #endif /* OB_WRP_PAGES0TO31MASK */ 00805 00806 #if defined(OB_WRP_PAGES16TO31MASK) 00807 WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8); 00808 #elif defined(OB_WRP_PAGES32TO63MASK) 00809 WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO63MASK) >> 8); 00810 #endif /* OB_WRP_PAGES32TO63MASK */ 00811 00812 #if defined(OB_WRP_PAGES64TO95MASK) 00813 WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES64TO95MASK) >> 16); 00814 #endif /* OB_WRP_PAGES64TO95MASK */ 00815 #if defined(OB_WRP_PAGES32TO47MASK) 00816 WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16); 00817 #endif /* OB_WRP_PAGES32TO47MASK */ 00818 00819 #if defined(OB_WRP_PAGES96TO127MASK) 00820 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES96TO127MASK) >> 24); 00821 #elif defined(OB_WRP_PAGES48TO255MASK) 00822 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO255MASK) >> 24); 00823 #elif defined(OB_WRP_PAGES48TO511MASK) 00824 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO511MASK) >> 24); 00825 #elif defined(OB_WRP_PAGES48TO127MASK) 00826 WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24); 00827 #endif /* OB_WRP_PAGES96TO127MASK */ 00828 00829 00830 /* Wait for last operation to be completed */ 00831 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00832 00833 if(status == HAL_OK) 00834 { 00835 /* Clean the error context */ 00836 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; 00837 00838 /* To be able to write again option byte, need to perform a option byte erase */ 00839 status = HAL_FLASHEx_OBErase(); 00840 if (status == HAL_OK) 00841 { 00842 SET_BIT(FLASH->CR, FLASH_CR_OPTPG); 00843 00844 #if defined(FLASH_WRP0_WRP0) 00845 if(WRP0_Data != 0xFF) 00846 { 00847 OB->WRP0 |= WRP0_Data; 00848 00849 /* Wait for last operation to be completed */ 00850 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00851 } 00852 #endif /* FLASH_WRP0_WRP0 */ 00853 00854 #if defined(FLASH_WRP1_WRP1) 00855 if((status == HAL_OK) && (WRP1_Data != 0xFF)) 00856 { 00857 OB->WRP1 |= WRP1_Data; 00858 00859 /* Wait for last operation to be completed */ 00860 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00861 } 00862 #endif /* FLASH_WRP1_WRP1 */ 00863 00864 #if defined(FLASH_WRP2_WRP2) 00865 if((status == HAL_OK) && (WRP2_Data != 0xFF)) 00866 { 00867 OB->WRP2 |= WRP2_Data; 00868 00869 /* Wait for last operation to be completed */ 00870 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00871 } 00872 #endif /* FLASH_WRP2_WRP2 */ 00873 00874 #if defined(FLASH_WRP3_WRP3) 00875 if((status == HAL_OK) && (WRP3_Data != 0xFF)) 00876 { 00877 OB->WRP3 |= WRP3_Data; 00878 00879 /* Wait for last operation to be completed */ 00880 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00881 } 00882 #endif /* FLASH_WRP3_WRP3 */ 00883 00884 /* if the program operation is completed, disable the OPTPG Bit */ 00885 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); 00886 } 00887 } 00888 return status; 00889 } 00890 00891 /** 00892 * @brief Set the read protection level. 00893 * @param ReadProtectLevel specifies the read protection level. 00894 * This parameter can be one of the following values: 00895 * @arg @ref OB_RDP_LEVEL_0 No protection 00896 * @arg @ref OB_RDP_LEVEL_1 Read protection of the memory 00897 * @retval HAL status 00898 */ 00899 static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel) 00900 { 00901 HAL_StatusTypeDef status = HAL_OK; 00902 00903 /* Check the parameters */ 00904 assert_param(IS_OB_RDP_LEVEL(ReadProtectLevel)); 00905 00906 /* Wait for last operation to be completed */ 00907 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00908 00909 if(status == HAL_OK) 00910 { 00911 /* Clean the error context */ 00912 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; 00913 00914 /* If the previous operation is completed, proceed to erase the option bytes */ 00915 SET_BIT(FLASH->CR, FLASH_CR_OPTER); 00916 SET_BIT(FLASH->CR, FLASH_CR_STRT); 00917 00918 /* Wait for last operation to be completed */ 00919 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00920 00921 /* If the erase operation is completed, disable the OPTER Bit */ 00922 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER); 00923 00924 if(status == HAL_OK) 00925 { 00926 /* Enable the Option Bytes Programming operation */ 00927 SET_BIT(FLASH->CR, FLASH_CR_OPTPG); 00928 00929 WRITE_REG(OB->RDP, ReadProtectLevel); 00930 00931 /* Wait for last operation to be completed */ 00932 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00933 00934 /* if the program operation is completed, disable the OPTPG Bit */ 00935 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); 00936 } 00937 } 00938 00939 return status; 00940 } 00941 00942 /** 00943 * @brief Program the FLASH User Option Byte. 00944 * @note Programming of the OB should be performed only after an erase (otherwise PGERR occurs) 00945 * @param UserConfig The FLASH User Option Bytes values FLASH_OBR_IWDG_SW(Bit2), 00946 * FLASH_OBR_nRST_STOP(Bit3),FLASH_OBR_nRST_STDBY(Bit4). 00947 * And BFBF2(Bit5) for STM32F101xG and STM32F103xG . 00948 * @retval HAL status 00949 */ 00950 static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig) 00951 { 00952 HAL_StatusTypeDef status = HAL_OK; 00953 00954 /* Check the parameters */ 00955 assert_param(IS_OB_IWDG_SOURCE((UserConfig&OB_IWDG_SW))); 00956 assert_param(IS_OB_STOP_SOURCE((UserConfig&OB_STOP_NO_RST))); 00957 assert_param(IS_OB_STDBY_SOURCE((UserConfig&OB_STDBY_NO_RST))); 00958 #if defined(FLASH_BANK2_END) 00959 assert_param(IS_OB_BOOT1((UserConfig&OB_BOOT1_SET))); 00960 #endif /* FLASH_BANK2_END */ 00961 00962 /* Wait for last operation to be completed */ 00963 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00964 00965 if(status == HAL_OK) 00966 { 00967 /* Clean the error context */ 00968 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; 00969 00970 /* Enable the Option Bytes Programming operation */ 00971 SET_BIT(FLASH->CR, FLASH_CR_OPTPG); 00972 00973 #if defined(FLASH_BANK2_END) 00974 OB->USER = (UserConfig | 0xF0); 00975 #else 00976 OB->USER = (UserConfig | 0x88); 00977 #endif /* FLASH_BANK2_END */ 00978 00979 /* Wait for last operation to be completed */ 00980 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 00981 00982 /* if the program operation is completed, disable the OPTPG Bit */ 00983 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); 00984 } 00985 00986 return status; 00987 } 00988 00989 /** 00990 * @brief Programs a half word at a specified Option Byte Data address. 00991 * @note The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface 00992 * The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes 00993 * The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes 00994 * (system reset will occur) 00995 * Programming of the OB should be performed only after an erase (otherwise PGERR occurs) 00996 * @param Address specifies the address to be programmed. 00997 * This parameter can be 0x1FFFF804 or 0x1FFFF806. 00998 * @param Data specifies the data to be programmed. 00999 * @retval HAL status 01000 */ 01001 static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data) 01002 { 01003 HAL_StatusTypeDef status = HAL_ERROR; 01004 01005 /* Check the parameters */ 01006 assert_param(IS_OB_DATA_ADDRESS(Address)); 01007 01008 /* Wait for last operation to be completed */ 01009 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 01010 01011 if(status == HAL_OK) 01012 { 01013 /* Clean the error context */ 01014 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; 01015 01016 /* Enables the Option Bytes Programming operation */ 01017 SET_BIT(FLASH->CR, FLASH_CR_OPTPG); 01018 *(__IO uint16_t*)Address = Data; 01019 01020 /* Wait for last operation to be completed */ 01021 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 01022 01023 /* If the program operation is completed, disable the OPTPG Bit */ 01024 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); 01025 } 01026 /* Return the Option Byte Data Program Status */ 01027 return status; 01028 } 01029 01030 /** 01031 * @brief Return the FLASH Write Protection Option Bytes value. 01032 * @retval The FLASH Write Protection Option Bytes value 01033 */ 01034 static uint32_t FLASH_OB_GetWRP(void) 01035 { 01036 /* Return the FLASH write protection Register value */ 01037 return (uint32_t)(READ_REG(FLASH->WRPR)); 01038 } 01039 01040 /** 01041 * @brief Returns the FLASH Read Protection level. 01042 * @retval FLASH ReadOut Protection Status: 01043 * This parameter can be one of the following values: 01044 * @arg @ref OB_RDP_LEVEL_0 No protection 01045 * @arg @ref OB_RDP_LEVEL_1 Read protection of the memory 01046 */ 01047 static uint32_t FLASH_OB_GetRDP(void) 01048 { 01049 uint32_t readstatus = OB_RDP_LEVEL_0; 01050 uint32_t tmp_reg = 0; 01051 01052 /* Read RDP level bits */ 01053 tmp_reg = READ_BIT(FLASH->OBR, FLASH_OBR_RDPRT); 01054 01055 if (tmp_reg == FLASH_OBR_RDPRT) 01056 { 01057 readstatus = OB_RDP_LEVEL_1; 01058 } 01059 else 01060 { 01061 readstatus = OB_RDP_LEVEL_0; 01062 } 01063 01064 return readstatus; 01065 } 01066 01067 /** 01068 * @brief Return the FLASH User Option Byte value. 01069 * @retval The FLASH User Option Bytes values: FLASH_OBR_IWDG_SW(Bit2), 01070 * FLASH_OBR_nRST_STOP(Bit3),FLASH_OBR_nRST_STDBY(Bit4). 01071 * And FLASH_OBR_BFB2(Bit5) for STM32F101xG and STM32F103xG . 01072 */ 01073 static uint8_t FLASH_OB_GetUser(void) 01074 { 01075 /* Return the User Option Byte */ 01076 return (uint8_t)((READ_REG(FLASH->OBR) & FLASH_OBR_USER) >> FLASH_POSITION_IWDGSW_BIT); 01077 } 01078 01079 /** 01080 * @} 01081 */ 01082 01083 /** 01084 * @} 01085 */ 01086 01087 /** @addtogroup FLASH 01088 * @{ 01089 */ 01090 01091 /** @addtogroup FLASH_Private_Functions 01092 * @{ 01093 */ 01094 01095 /** 01096 * @brief Erase the specified FLASH memory page 01097 * @param PageAddress FLASH page to erase 01098 * The value of this parameter depend on device used within the same series 01099 * 01100 * @retval None 01101 */ 01102 void FLASH_PageErase(uint32_t PageAddress) 01103 { 01104 /* Clean the error context */ 01105 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; 01106 01107 #if defined(FLASH_BANK2_END) 01108 if(PageAddress > FLASH_BANK1_END) 01109 { 01110 /* Proceed to erase the page */ 01111 SET_BIT(FLASH->CR2, FLASH_CR2_PER); 01112 WRITE_REG(FLASH->AR2, PageAddress); 01113 SET_BIT(FLASH->CR2, FLASH_CR2_STRT); 01114 } 01115 else 01116 { 01117 #endif /* FLASH_BANK2_END */ 01118 /* Proceed to erase the page */ 01119 SET_BIT(FLASH->CR, FLASH_CR_PER); 01120 WRITE_REG(FLASH->AR, PageAddress); 01121 SET_BIT(FLASH->CR, FLASH_CR_STRT); 01122 #if defined(FLASH_BANK2_END) 01123 } 01124 #endif /* FLASH_BANK2_END */ 01125 } 01126 01127 /** 01128 * @} 01129 */ 01130 01131 /** 01132 * @} 01133 */ 01134 01135 #endif /* HAL_FLASH_MODULE_ENABLED */ 01136 /** 01137 * @} 01138 */ 01139 01140 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 15:37:23 by
1.7.2