stm32f1xx_hal_flash_ex.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_flash_ex.c
  4. * @author MCD Application Team
  5. * @brief Extended FLASH HAL module driver.
  6. *
  7. * This file provides firmware functions to manage the following
  8. * functionalities of the FLASH peripheral:
  9. * + Extended Initialization/de-initialization functions
  10. * + Extended I/O operation functions
  11. * + Extended Peripheral Control functions
  12. *
  13. @verbatim
  14. ==============================================================================
  15. ##### Flash peripheral extended features #####
  16. ==============================================================================
  17. ##### How to use this driver #####
  18. ==============================================================================
  19. [..] This driver provides functions to configure and program the FLASH memory
  20. of all STM32F1xxx devices. It includes
  21. (++) Set/Reset the write protection
  22. (++) Program the user Option Bytes
  23. (++) Get the Read protection Level
  24. @endverbatim
  25. ******************************************************************************
  26. * @attention
  27. *
  28. * Copyright (c) 2016 STMicroelectronics.
  29. * All rights reserved.
  30. *
  31. * This software is licensed under terms that can be found in the LICENSE file in
  32. * the root directory of this software component.
  33. * If no LICENSE file comes with this software, it is provided AS-IS.
  34. ******************************************************************************
  35. */
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "stm32f1xx_hal.h"
  38. /** @addtogroup STM32F1xx_HAL_Driver
  39. * @{
  40. */
  41. #ifdef HAL_FLASH_MODULE_ENABLED
  42. /** @addtogroup FLASH
  43. * @{
  44. */
  45. /** @addtogroup FLASH_Private_Variables
  46. * @{
  47. */
  48. /* Variables used for Erase pages under interruption*/
  49. extern FLASH_ProcessTypeDef pFlash;
  50. /**
  51. * @}
  52. */
  53. /**
  54. * @}
  55. */
  56. /** @defgroup FLASHEx FLASHEx
  57. * @brief FLASH HAL Extension module driver
  58. * @{
  59. */
  60. /* Private typedef -----------------------------------------------------------*/
  61. /* Private define ------------------------------------------------------------*/
  62. /** @defgroup FLASHEx_Private_Constants FLASHEx Private Constants
  63. * @{
  64. */
  65. #define FLASH_POSITION_IWDGSW_BIT FLASH_OBR_IWDG_SW_Pos
  66. #define FLASH_POSITION_OB_USERDATA0_BIT FLASH_OBR_DATA0_Pos
  67. #define FLASH_POSITION_OB_USERDATA1_BIT FLASH_OBR_DATA1_Pos
  68. /**
  69. * @}
  70. */
  71. /* Private macro -------------------------------------------------------------*/
  72. /** @defgroup FLASHEx_Private_Macros FLASHEx Private Macros
  73. * @{
  74. */
  75. /**
  76. * @}
  77. */
  78. /* Private variables ---------------------------------------------------------*/
  79. /* Private function prototypes -----------------------------------------------*/
  80. /** @defgroup FLASHEx_Private_Functions FLASHEx Private Functions
  81. * @{
  82. */
  83. /* Erase operations */
  84. static void FLASH_MassErase(uint32_t Banks);
  85. void FLASH_PageErase(uint32_t PageAddress);
  86. /* Option bytes control */
  87. static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage);
  88. static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage);
  89. static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel);
  90. static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig);
  91. static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data);
  92. static uint32_t FLASH_OB_GetWRP(void);
  93. static uint32_t FLASH_OB_GetRDP(void);
  94. static uint8_t FLASH_OB_GetUser(void);
  95. /**
  96. * @}
  97. */
  98. /* Exported functions ---------------------------------------------------------*/
  99. /** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions
  100. * @{
  101. */
  102. /** @defgroup FLASHEx_Exported_Functions_Group1 FLASHEx Memory Erasing functions
  103. * @brief FLASH Memory Erasing functions
  104. *
  105. @verbatim
  106. ==============================================================================
  107. ##### FLASH Erasing Programming functions #####
  108. ==============================================================================
  109. [..] The FLASH Memory Erasing functions, includes the following functions:
  110. (+) HAL_FLASHEx_Erase: return only when erase has been done
  111. (+) HAL_FLASHEx_Erase_IT: end of erase is done when HAL_FLASH_EndOfOperationCallback
  112. is called with parameter 0xFFFFFFFF
  113. [..] Any operation of erase should follow these steps:
  114. (#) Call the HAL_FLASH_Unlock() function to enable the flash control register and
  115. program memory access.
  116. (#) Call the desired function to erase page.
  117. (#) Call the HAL_FLASH_Lock() to disable the flash program memory access
  118. (recommended to protect the FLASH memory against possible unwanted operation).
  119. @endverbatim
  120. * @{
  121. */
  122. /**
  123. * @brief Perform a mass erase or erase the specified FLASH memory pages
  124. * @note To correctly run this function, the @ref HAL_FLASH_Unlock() function
  125. * must be called before.
  126. * Call the @ref HAL_FLASH_Lock() to disable the flash memory access
  127. * (recommended to protect the FLASH memory against possible unwanted operation)
  128. * @param[in] pEraseInit pointer to an FLASH_EraseInitTypeDef structure that
  129. * contains the configuration information for the erasing.
  130. *
  131. * @param[out] PageError pointer to variable that
  132. * contains the configuration information on faulty page in case of error
  133. * (0xFFFFFFFF means that all the pages have been correctly erased)
  134. *
  135. * @retval HAL_StatusTypeDef HAL Status
  136. */
  137. HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)
  138. {
  139. HAL_StatusTypeDef status = HAL_ERROR;
  140. uint32_t address = 0U;
  141. /* Process Locked */
  142. __HAL_LOCK(&pFlash);
  143. /* Check the parameters */
  144. assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
  145. if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
  146. {
  147. #if defined(FLASH_BANK2_END)
  148. if (pEraseInit->Banks == FLASH_BANK_BOTH)
  149. {
  150. /* Mass Erase requested for Bank1 and Bank2 */
  151. /* Wait for last operation to be completed */
  152. if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && \
  153. (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK))
  154. {
  155. /*Mass erase to be done*/
  156. FLASH_MassErase(FLASH_BANK_BOTH);
  157. /* Wait for last operation to be completed */
  158. if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && \
  159. (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK))
  160. {
  161. status = HAL_OK;
  162. }
  163. /* If the erase operation is completed, disable the MER Bit */
  164. CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
  165. CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
  166. }
  167. }
  168. else if (pEraseInit->Banks == FLASH_BANK_2)
  169. {
  170. /* Mass Erase requested for Bank2 */
  171. /* Wait for last operation to be completed */
  172. if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
  173. {
  174. /*Mass erase to be done*/
  175. FLASH_MassErase(FLASH_BANK_2);
  176. /* Wait for last operation to be completed */
  177. status = FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE);
  178. /* If the erase operation is completed, disable the MER Bit */
  179. CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
  180. }
  181. }
  182. else
  183. #endif /* FLASH_BANK2_END */
  184. {
  185. /* Mass Erase requested for Bank1 */
  186. /* Wait for last operation to be completed */
  187. if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
  188. {
  189. /*Mass erase to be done*/
  190. FLASH_MassErase(FLASH_BANK_1);
  191. /* Wait for last operation to be completed */
  192. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  193. /* If the erase operation is completed, disable the MER Bit */
  194. CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
  195. }
  196. }
  197. }
  198. else
  199. {
  200. /* Page Erase is requested */
  201. /* Check the parameters */
  202. assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress));
  203. assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages));
  204. #if defined(FLASH_BANK2_END)
  205. /* Page Erase requested on address located on bank2 */
  206. if(pEraseInit->PageAddress > FLASH_BANK1_END)
  207. {
  208. /* Wait for last operation to be completed */
  209. if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
  210. {
  211. /*Initialization of PageError variable*/
  212. *PageError = 0xFFFFFFFFU;
  213. /* Erase by page by page to be done*/
  214. for(address = pEraseInit->PageAddress;
  215. address < (pEraseInit->PageAddress + (pEraseInit->NbPages)*FLASH_PAGE_SIZE);
  216. address += FLASH_PAGE_SIZE)
  217. {
  218. FLASH_PageErase(address);
  219. /* Wait for last operation to be completed */
  220. status = FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE);
  221. /* If the erase operation is completed, disable the PER Bit */
  222. CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER);
  223. if (status != HAL_OK)
  224. {
  225. /* In case of error, stop erase procedure and return the faulty address */
  226. *PageError = address;
  227. break;
  228. }
  229. }
  230. }
  231. }
  232. else
  233. #endif /* FLASH_BANK2_END */
  234. {
  235. /* Page Erase requested on address located on bank1 */
  236. /* Wait for last operation to be completed */
  237. if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
  238. {
  239. /*Initialization of PageError variable*/
  240. *PageError = 0xFFFFFFFFU;
  241. /* Erase page by page to be done*/
  242. for(address = pEraseInit->PageAddress;
  243. address < ((pEraseInit->NbPages * FLASH_PAGE_SIZE) + pEraseInit->PageAddress);
  244. address += FLASH_PAGE_SIZE)
  245. {
  246. FLASH_PageErase(address);
  247. /* Wait for last operation to be completed */
  248. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  249. /* If the erase operation is completed, disable the PER Bit */
  250. CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
  251. if (status != HAL_OK)
  252. {
  253. /* In case of error, stop erase procedure and return the faulty address */
  254. *PageError = address;
  255. break;
  256. }
  257. }
  258. }
  259. }
  260. }
  261. /* Process Unlocked */
  262. __HAL_UNLOCK(&pFlash);
  263. return status;
  264. }
  265. /**
  266. * @brief Perform a mass erase or erase the specified FLASH memory pages with interrupt enabled
  267. * @note To correctly run this function, the @ref HAL_FLASH_Unlock() function
  268. * must be called before.
  269. * Call the @ref HAL_FLASH_Lock() to disable the flash memory access
  270. * (recommended to protect the FLASH memory against possible unwanted operation)
  271. * @param pEraseInit pointer to an FLASH_EraseInitTypeDef structure that
  272. * contains the configuration information for the erasing.
  273. *
  274. * @retval HAL_StatusTypeDef HAL Status
  275. */
  276. HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
  277. {
  278. HAL_StatusTypeDef status = HAL_OK;
  279. /* Process Locked */
  280. __HAL_LOCK(&pFlash);
  281. /* If procedure already ongoing, reject the next one */
  282. if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
  283. {
  284. return HAL_ERROR;
  285. }
  286. /* Check the parameters */
  287. assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
  288. /* Enable End of FLASH Operation and Error source interrupts */
  289. __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR);
  290. #if defined(FLASH_BANK2_END)
  291. /* Enable End of FLASH Operation and Error source interrupts */
  292. __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
  293. #endif
  294. if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
  295. {
  296. /*Mass erase to be done*/
  297. pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE;
  298. FLASH_MassErase(pEraseInit->Banks);
  299. }
  300. else
  301. {
  302. /* Erase by page to be done*/
  303. /* Check the parameters */
  304. assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress));
  305. assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages));
  306. pFlash.ProcedureOnGoing = FLASH_PROC_PAGEERASE;
  307. pFlash.DataRemaining = pEraseInit->NbPages;
  308. pFlash.Address = pEraseInit->PageAddress;
  309. /*Erase 1st page and wait for IT*/
  310. FLASH_PageErase(pEraseInit->PageAddress);
  311. }
  312. return status;
  313. }
  314. /**
  315. * @}
  316. */
  317. /** @defgroup FLASHEx_Exported_Functions_Group2 Option Bytes Programming functions
  318. * @brief Option Bytes Programming functions
  319. *
  320. @verbatim
  321. ==============================================================================
  322. ##### Option Bytes Programming functions #####
  323. ==============================================================================
  324. [..]
  325. This subsection provides a set of functions allowing to control the FLASH
  326. option bytes operations.
  327. @endverbatim
  328. * @{
  329. */
  330. /**
  331. * @brief Erases the FLASH option bytes.
  332. * @note This functions erases all option bytes except the Read protection (RDP).
  333. * The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
  334. * The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes
  335. * The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes
  336. * (system reset will occur)
  337. * @retval HAL status
  338. */
  339. HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
  340. {
  341. uint8_t rdptmp = OB_RDP_LEVEL_0;
  342. HAL_StatusTypeDef status = HAL_ERROR;
  343. /* Get the actual read protection Option Byte value */
  344. rdptmp = FLASH_OB_GetRDP();
  345. /* Wait for last operation to be completed */
  346. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  347. if(status == HAL_OK)
  348. {
  349. /* Clean the error context */
  350. pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
  351. /* If the previous operation is completed, proceed to erase the option bytes */
  352. SET_BIT(FLASH->CR, FLASH_CR_OPTER);
  353. SET_BIT(FLASH->CR, FLASH_CR_STRT);
  354. /* Wait for last operation to be completed */
  355. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  356. /* If the erase operation is completed, disable the OPTER Bit */
  357. CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);
  358. if(status == HAL_OK)
  359. {
  360. /* Restore the last read protection Option Byte value */
  361. status = FLASH_OB_RDP_LevelConfig(rdptmp);
  362. }
  363. }
  364. /* Return the erase status */
  365. return status;
  366. }
  367. /**
  368. * @brief Program option bytes
  369. * @note The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
  370. * The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes
  371. * The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes
  372. * (system reset will occur)
  373. *
  374. * @param pOBInit pointer to an FLASH_OBInitStruct structure that
  375. * contains the configuration information for the programming.
  376. *
  377. * @retval HAL_StatusTypeDef HAL Status
  378. */
  379. HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
  380. {
  381. HAL_StatusTypeDef status = HAL_ERROR;
  382. /* Process Locked */
  383. __HAL_LOCK(&pFlash);
  384. /* Check the parameters */
  385. assert_param(IS_OPTIONBYTE(pOBInit->OptionType));
  386. /* Write protection configuration */
  387. if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP)
  388. {
  389. assert_param(IS_WRPSTATE(pOBInit->WRPState));
  390. if (pOBInit->WRPState == OB_WRPSTATE_ENABLE)
  391. {
  392. /* Enable of Write protection on the selected page */
  393. status = FLASH_OB_EnableWRP(pOBInit->WRPPage);
  394. }
  395. else
  396. {
  397. /* Disable of Write protection on the selected page */
  398. status = FLASH_OB_DisableWRP(pOBInit->WRPPage);
  399. }
  400. if (status != HAL_OK)
  401. {
  402. /* Process Unlocked */
  403. __HAL_UNLOCK(&pFlash);
  404. return status;
  405. }
  406. }
  407. /* Read protection configuration */
  408. if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP)
  409. {
  410. status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel);
  411. if (status != HAL_OK)
  412. {
  413. /* Process Unlocked */
  414. __HAL_UNLOCK(&pFlash);
  415. return status;
  416. }
  417. }
  418. /* USER configuration */
  419. if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER)
  420. {
  421. status = FLASH_OB_UserConfig(pOBInit->USERConfig);
  422. if (status != HAL_OK)
  423. {
  424. /* Process Unlocked */
  425. __HAL_UNLOCK(&pFlash);
  426. return status;
  427. }
  428. }
  429. /* DATA configuration*/
  430. if((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA)
  431. {
  432. status = FLASH_OB_ProgramData(pOBInit->DATAAddress, pOBInit->DATAData);
  433. if (status != HAL_OK)
  434. {
  435. /* Process Unlocked */
  436. __HAL_UNLOCK(&pFlash);
  437. return status;
  438. }
  439. }
  440. /* Process Unlocked */
  441. __HAL_UNLOCK(&pFlash);
  442. return status;
  443. }
  444. /**
  445. * @brief Get the Option byte configuration
  446. * @param pOBInit pointer to an FLASH_OBInitStruct structure that
  447. * contains the configuration information for the programming.
  448. *
  449. * @retval None
  450. */
  451. void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
  452. {
  453. pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER;
  454. /*Get WRP*/
  455. pOBInit->WRPPage = FLASH_OB_GetWRP();
  456. /*Get RDP Level*/
  457. pOBInit->RDPLevel = FLASH_OB_GetRDP();
  458. /*Get USER*/
  459. pOBInit->USERConfig = FLASH_OB_GetUser();
  460. }
  461. /**
  462. * @brief Get the Option byte user data
  463. * @param DATAAdress Address of the option byte DATA
  464. * This parameter can be one of the following values:
  465. * @arg @ref OB_DATA_ADDRESS_DATA0
  466. * @arg @ref OB_DATA_ADDRESS_DATA1
  467. * @retval Value programmed in USER data
  468. */
  469. uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress)
  470. {
  471. uint32_t value = 0;
  472. if (DATAAdress == OB_DATA_ADDRESS_DATA0)
  473. {
  474. /* Get value programmed in OB USER Data0 */
  475. value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA0) >> FLASH_POSITION_OB_USERDATA0_BIT;
  476. }
  477. else
  478. {
  479. /* Get value programmed in OB USER Data1 */
  480. value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA1) >> FLASH_POSITION_OB_USERDATA1_BIT;
  481. }
  482. return value;
  483. }
  484. /**
  485. * @}
  486. */
  487. /**
  488. * @}
  489. */
  490. /** @addtogroup FLASHEx_Private_Functions
  491. * @{
  492. */
  493. /**
  494. * @brief Full erase of FLASH memory Bank
  495. * @param Banks Banks to be erased
  496. * This parameter can be one of the following values:
  497. * @arg @ref FLASH_BANK_1 Bank1 to be erased
  498. @if STM32F101xG
  499. * @arg @ref FLASH_BANK_2 Bank2 to be erased
  500. * @arg @ref FLASH_BANK_BOTH Bank1 and Bank2 to be erased
  501. @endif
  502. @if STM32F103xG
  503. * @arg @ref FLASH_BANK_2 Bank2 to be erased
  504. * @arg @ref FLASH_BANK_BOTH Bank1 and Bank2 to be erased
  505. @endif
  506. *
  507. * @retval None
  508. */
  509. static void FLASH_MassErase(uint32_t Banks)
  510. {
  511. /* Check the parameters */
  512. assert_param(IS_FLASH_BANK(Banks));
  513. /* Clean the error context */
  514. pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
  515. #if defined(FLASH_BANK2_END)
  516. if(Banks == FLASH_BANK_BOTH)
  517. {
  518. /* bank1 & bank2 will be erased*/
  519. SET_BIT(FLASH->CR, FLASH_CR_MER);
  520. SET_BIT(FLASH->CR2, FLASH_CR2_MER);
  521. SET_BIT(FLASH->CR, FLASH_CR_STRT);
  522. SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
  523. }
  524. else if(Banks == FLASH_BANK_2)
  525. {
  526. /*Only bank2 will be erased*/
  527. SET_BIT(FLASH->CR2, FLASH_CR2_MER);
  528. SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
  529. }
  530. else
  531. {
  532. #endif /* FLASH_BANK2_END */
  533. #if !defined(FLASH_BANK2_END)
  534. /* Prevent unused argument(s) compilation warning */
  535. UNUSED(Banks);
  536. #endif /* FLASH_BANK2_END */
  537. /* Only bank1 will be erased*/
  538. SET_BIT(FLASH->CR, FLASH_CR_MER);
  539. SET_BIT(FLASH->CR, FLASH_CR_STRT);
  540. #if defined(FLASH_BANK2_END)
  541. }
  542. #endif /* FLASH_BANK2_END */
  543. }
  544. /**
  545. * @brief Enable the write protection of the desired pages
  546. * @note An option byte erase is done automatically in this function.
  547. * @note When the memory read protection level is selected (RDP level = 1),
  548. * it is not possible to program or erase the flash page i if
  549. * debug features are connected or boot code is executed in RAM, even if nWRPi = 1
  550. *
  551. * @param WriteProtectPage specifies the page(s) to be write protected.
  552. * The value of this parameter depend on device used within the same series
  553. * @retval HAL status
  554. */
  555. static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
  556. {
  557. HAL_StatusTypeDef status = HAL_OK;
  558. uint16_t WRP0_Data = 0xFFFF;
  559. #if defined(FLASH_WRP1_WRP1)
  560. uint16_t WRP1_Data = 0xFFFF;
  561. #endif /* FLASH_WRP1_WRP1 */
  562. #if defined(FLASH_WRP2_WRP2)
  563. uint16_t WRP2_Data = 0xFFFF;
  564. #endif /* FLASH_WRP2_WRP2 */
  565. #if defined(FLASH_WRP3_WRP3)
  566. uint16_t WRP3_Data = 0xFFFF;
  567. #endif /* FLASH_WRP3_WRP3 */
  568. /* Check the parameters */
  569. assert_param(IS_OB_WRP(WriteProtectPage));
  570. /* Get current write protected pages and the new pages to be protected ******/
  571. WriteProtectPage = (uint32_t)(~((~FLASH_OB_GetWRP()) | WriteProtectPage));
  572. #if defined(OB_WRP_PAGES0TO15MASK)
  573. WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK);
  574. #elif defined(OB_WRP_PAGES0TO31MASK)
  575. WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO31MASK);
  576. #endif /* OB_WRP_PAGES0TO31MASK */
  577. #if defined(OB_WRP_PAGES16TO31MASK)
  578. WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8U);
  579. #elif defined(OB_WRP_PAGES32TO63MASK)
  580. WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO63MASK) >> 8U);
  581. #endif /* OB_WRP_PAGES32TO63MASK */
  582. #if defined(OB_WRP_PAGES64TO95MASK)
  583. WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES64TO95MASK) >> 16U);
  584. #endif /* OB_WRP_PAGES64TO95MASK */
  585. #if defined(OB_WRP_PAGES32TO47MASK)
  586. WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16U);
  587. #endif /* OB_WRP_PAGES32TO47MASK */
  588. #if defined(OB_WRP_PAGES96TO127MASK)
  589. WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES96TO127MASK) >> 24U);
  590. #elif defined(OB_WRP_PAGES48TO255MASK)
  591. WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO255MASK) >> 24U);
  592. #elif defined(OB_WRP_PAGES48TO511MASK)
  593. WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO511MASK) >> 24U);
  594. #elif defined(OB_WRP_PAGES48TO127MASK)
  595. WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24U);
  596. #endif /* OB_WRP_PAGES96TO127MASK */
  597. /* Wait for last operation to be completed */
  598. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  599. if(status == HAL_OK)
  600. {
  601. /* Clean the error context */
  602. pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
  603. /* To be able to write again option byte, need to perform a option byte erase */
  604. status = HAL_FLASHEx_OBErase();
  605. if (status == HAL_OK)
  606. {
  607. /* Enable write protection */
  608. SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
  609. #if defined(FLASH_WRP0_WRP0)
  610. if(WRP0_Data != 0xFFU)
  611. {
  612. OB->WRP0 &= WRP0_Data;
  613. /* Wait for last operation to be completed */
  614. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  615. }
  616. #endif /* FLASH_WRP0_WRP0 */
  617. #if defined(FLASH_WRP1_WRP1)
  618. if((status == HAL_OK) && (WRP1_Data != 0xFFU))
  619. {
  620. OB->WRP1 &= WRP1_Data;
  621. /* Wait for last operation to be completed */
  622. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  623. }
  624. #endif /* FLASH_WRP1_WRP1 */
  625. #if defined(FLASH_WRP2_WRP2)
  626. if((status == HAL_OK) && (WRP2_Data != 0xFFU))
  627. {
  628. OB->WRP2 &= WRP2_Data;
  629. /* Wait for last operation to be completed */
  630. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  631. }
  632. #endif /* FLASH_WRP2_WRP2 */
  633. #if defined(FLASH_WRP3_WRP3)
  634. if((status == HAL_OK) && (WRP3_Data != 0xFFU))
  635. {
  636. OB->WRP3 &= WRP3_Data;
  637. /* Wait for last operation to be completed */
  638. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  639. }
  640. #endif /* FLASH_WRP3_WRP3 */
  641. /* if the program operation is completed, disable the OPTPG Bit */
  642. CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
  643. }
  644. }
  645. return status;
  646. }
  647. /**
  648. * @brief Disable the write protection of the desired pages
  649. * @note An option byte erase is done automatically in this function.
  650. * @note When the memory read protection level is selected (RDP level = 1),
  651. * it is not possible to program or erase the flash page i if
  652. * debug features are connected or boot code is executed in RAM, even if nWRPi = 1
  653. *
  654. * @param WriteProtectPage specifies the page(s) to be write unprotected.
  655. * The value of this parameter depend on device used within the same series
  656. * @retval HAL status
  657. */
  658. static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
  659. {
  660. HAL_StatusTypeDef status = HAL_OK;
  661. uint16_t WRP0_Data = 0xFFFF;
  662. #if defined(FLASH_WRP1_WRP1)
  663. uint16_t WRP1_Data = 0xFFFF;
  664. #endif /* FLASH_WRP1_WRP1 */
  665. #if defined(FLASH_WRP2_WRP2)
  666. uint16_t WRP2_Data = 0xFFFF;
  667. #endif /* FLASH_WRP2_WRP2 */
  668. #if defined(FLASH_WRP3_WRP3)
  669. uint16_t WRP3_Data = 0xFFFF;
  670. #endif /* FLASH_WRP3_WRP3 */
  671. /* Check the parameters */
  672. assert_param(IS_OB_WRP(WriteProtectPage));
  673. /* Get current write protected pages and the new pages to be unprotected ******/
  674. WriteProtectPage = (FLASH_OB_GetWRP() | WriteProtectPage);
  675. #if defined(OB_WRP_PAGES0TO15MASK)
  676. WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK);
  677. #elif defined(OB_WRP_PAGES0TO31MASK)
  678. WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO31MASK);
  679. #endif /* OB_WRP_PAGES0TO31MASK */
  680. #if defined(OB_WRP_PAGES16TO31MASK)
  681. WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8U);
  682. #elif defined(OB_WRP_PAGES32TO63MASK)
  683. WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO63MASK) >> 8U);
  684. #endif /* OB_WRP_PAGES32TO63MASK */
  685. #if defined(OB_WRP_PAGES64TO95MASK)
  686. WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES64TO95MASK) >> 16U);
  687. #endif /* OB_WRP_PAGES64TO95MASK */
  688. #if defined(OB_WRP_PAGES32TO47MASK)
  689. WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16U);
  690. #endif /* OB_WRP_PAGES32TO47MASK */
  691. #if defined(OB_WRP_PAGES96TO127MASK)
  692. WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES96TO127MASK) >> 24U);
  693. #elif defined(OB_WRP_PAGES48TO255MASK)
  694. WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO255MASK) >> 24U);
  695. #elif defined(OB_WRP_PAGES48TO511MASK)
  696. WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO511MASK) >> 24U);
  697. #elif defined(OB_WRP_PAGES48TO127MASK)
  698. WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24U);
  699. #endif /* OB_WRP_PAGES96TO127MASK */
  700. /* Wait for last operation to be completed */
  701. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  702. if(status == HAL_OK)
  703. {
  704. /* Clean the error context */
  705. pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
  706. /* To be able to write again option byte, need to perform a option byte erase */
  707. status = HAL_FLASHEx_OBErase();
  708. if (status == HAL_OK)
  709. {
  710. SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
  711. #if defined(FLASH_WRP0_WRP0)
  712. if(WRP0_Data != 0xFFU)
  713. {
  714. OB->WRP0 |= WRP0_Data;
  715. /* Wait for last operation to be completed */
  716. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  717. }
  718. #endif /* FLASH_WRP0_WRP0 */
  719. #if defined(FLASH_WRP1_WRP1)
  720. if((status == HAL_OK) && (WRP1_Data != 0xFFU))
  721. {
  722. OB->WRP1 |= WRP1_Data;
  723. /* Wait for last operation to be completed */
  724. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  725. }
  726. #endif /* FLASH_WRP1_WRP1 */
  727. #if defined(FLASH_WRP2_WRP2)
  728. if((status == HAL_OK) && (WRP2_Data != 0xFFU))
  729. {
  730. OB->WRP2 |= WRP2_Data;
  731. /* Wait for last operation to be completed */
  732. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  733. }
  734. #endif /* FLASH_WRP2_WRP2 */
  735. #if defined(FLASH_WRP3_WRP3)
  736. if((status == HAL_OK) && (WRP3_Data != 0xFFU))
  737. {
  738. OB->WRP3 |= WRP3_Data;
  739. /* Wait for last operation to be completed */
  740. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  741. }
  742. #endif /* FLASH_WRP3_WRP3 */
  743. /* if the program operation is completed, disable the OPTPG Bit */
  744. CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
  745. }
  746. }
  747. return status;
  748. }
  749. /**
  750. * @brief Set the read protection level.
  751. * @param ReadProtectLevel specifies the read protection level.
  752. * This parameter can be one of the following values:
  753. * @arg @ref OB_RDP_LEVEL_0 No protection
  754. * @arg @ref OB_RDP_LEVEL_1 Read protection of the memory
  755. * @retval HAL status
  756. */
  757. static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
  758. {
  759. HAL_StatusTypeDef status = HAL_OK;
  760. /* Check the parameters */
  761. assert_param(IS_OB_RDP_LEVEL(ReadProtectLevel));
  762. /* Wait for last operation to be completed */
  763. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  764. if(status == HAL_OK)
  765. {
  766. /* Clean the error context */
  767. pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
  768. /* If the previous operation is completed, proceed to erase the option bytes */
  769. SET_BIT(FLASH->CR, FLASH_CR_OPTER);
  770. SET_BIT(FLASH->CR, FLASH_CR_STRT);
  771. /* Wait for last operation to be completed */
  772. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  773. /* If the erase operation is completed, disable the OPTER Bit */
  774. CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);
  775. if(status == HAL_OK)
  776. {
  777. /* Enable the Option Bytes Programming operation */
  778. SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
  779. WRITE_REG(OB->RDP, ReadProtectLevel);
  780. /* Wait for last operation to be completed */
  781. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  782. /* if the program operation is completed, disable the OPTPG Bit */
  783. CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
  784. }
  785. }
  786. return status;
  787. }
  788. /**
  789. * @brief Program the FLASH User Option Byte.
  790. * @note Programming of the OB should be performed only after an erase (otherwise PGERR occurs)
  791. * @param UserConfig The FLASH User Option Bytes values FLASH_OBR_IWDG_SW(Bit2),
  792. * FLASH_OBR_nRST_STOP(Bit3),FLASH_OBR_nRST_STDBY(Bit4).
  793. * And BFBF2(Bit5) for STM32F101xG and STM32F103xG .
  794. * @retval HAL status
  795. */
  796. static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig)
  797. {
  798. HAL_StatusTypeDef status = HAL_OK;
  799. /* Check the parameters */
  800. assert_param(IS_OB_IWDG_SOURCE((UserConfig&OB_IWDG_SW)));
  801. assert_param(IS_OB_STOP_SOURCE((UserConfig&OB_STOP_NO_RST)));
  802. assert_param(IS_OB_STDBY_SOURCE((UserConfig&OB_STDBY_NO_RST)));
  803. #if defined(FLASH_BANK2_END)
  804. assert_param(IS_OB_BOOT1((UserConfig&OB_BOOT1_SET)));
  805. #endif /* FLASH_BANK2_END */
  806. /* Wait for last operation to be completed */
  807. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  808. if(status == HAL_OK)
  809. {
  810. /* Clean the error context */
  811. pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
  812. /* Enable the Option Bytes Programming operation */
  813. SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
  814. #if defined(FLASH_BANK2_END)
  815. OB->USER = (UserConfig | 0xF0U);
  816. #else
  817. OB->USER = (UserConfig | 0x88U);
  818. #endif /* FLASH_BANK2_END */
  819. /* Wait for last operation to be completed */
  820. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  821. /* if the program operation is completed, disable the OPTPG Bit */
  822. CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
  823. }
  824. return status;
  825. }
  826. /**
  827. * @brief Programs a half word at a specified Option Byte Data address.
  828. * @note The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
  829. * The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes
  830. * The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes
  831. * (system reset will occur)
  832. * Programming of the OB should be performed only after an erase (otherwise PGERR occurs)
  833. * @param Address specifies the address to be programmed.
  834. * This parameter can be 0x1FFFF804 or 0x1FFFF806.
  835. * @param Data specifies the data to be programmed.
  836. * @retval HAL status
  837. */
  838. static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data)
  839. {
  840. HAL_StatusTypeDef status = HAL_ERROR;
  841. /* Check the parameters */
  842. assert_param(IS_OB_DATA_ADDRESS(Address));
  843. /* Wait for last operation to be completed */
  844. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  845. if(status == HAL_OK)
  846. {
  847. /* Clean the error context */
  848. pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
  849. /* Enables the Option Bytes Programming operation */
  850. SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
  851. *(__IO uint16_t*)Address = Data;
  852. /* Wait for last operation to be completed */
  853. status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
  854. /* If the program operation is completed, disable the OPTPG Bit */
  855. CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
  856. }
  857. /* Return the Option Byte Data Program Status */
  858. return status;
  859. }
  860. /**
  861. * @brief Return the FLASH Write Protection Option Bytes value.
  862. * @retval The FLASH Write Protection Option Bytes value
  863. */
  864. static uint32_t FLASH_OB_GetWRP(void)
  865. {
  866. /* Return the FLASH write protection Register value */
  867. return (uint32_t)(READ_REG(FLASH->WRPR));
  868. }
  869. /**
  870. * @brief Returns the FLASH Read Protection level.
  871. * @retval FLASH RDP level
  872. * This parameter can be one of the following values:
  873. * @arg @ref OB_RDP_LEVEL_0 No protection
  874. * @arg @ref OB_RDP_LEVEL_1 Read protection of the memory
  875. */
  876. static uint32_t FLASH_OB_GetRDP(void)
  877. {
  878. uint32_t readstatus = OB_RDP_LEVEL_0;
  879. uint32_t tmp_reg = 0U;
  880. /* Read RDP level bits */
  881. tmp_reg = READ_BIT(FLASH->OBR, FLASH_OBR_RDPRT);
  882. if (tmp_reg == FLASH_OBR_RDPRT)
  883. {
  884. readstatus = OB_RDP_LEVEL_1;
  885. }
  886. else
  887. {
  888. readstatus = OB_RDP_LEVEL_0;
  889. }
  890. return readstatus;
  891. }
  892. /**
  893. * @brief Return the FLASH User Option Byte value.
  894. * @retval The FLASH User Option Bytes values: FLASH_OBR_IWDG_SW(Bit2),
  895. * FLASH_OBR_nRST_STOP(Bit3),FLASH_OBR_nRST_STDBY(Bit4).
  896. * And FLASH_OBR_BFB2(Bit5) for STM32F101xG and STM32F103xG .
  897. */
  898. static uint8_t FLASH_OB_GetUser(void)
  899. {
  900. /* Return the User Option Byte */
  901. return (uint8_t)((READ_REG(FLASH->OBR) & FLASH_OBR_USER) >> FLASH_POSITION_IWDGSW_BIT);
  902. }
  903. /**
  904. * @}
  905. */
  906. /**
  907. * @}
  908. */
  909. /** @addtogroup FLASH
  910. * @{
  911. */
  912. /** @addtogroup FLASH_Private_Functions
  913. * @{
  914. */
  915. /**
  916. * @brief Erase the specified FLASH memory page
  917. * @param PageAddress FLASH page to erase
  918. * The value of this parameter depend on device used within the same series
  919. *
  920. * @retval None
  921. */
  922. void FLASH_PageErase(uint32_t PageAddress)
  923. {
  924. /* Clean the error context */
  925. pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
  926. #if defined(FLASH_BANK2_END)
  927. if(PageAddress > FLASH_BANK1_END)
  928. {
  929. /* Proceed to erase the page */
  930. SET_BIT(FLASH->CR2, FLASH_CR2_PER);
  931. WRITE_REG(FLASH->AR2, PageAddress);
  932. SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
  933. }
  934. else
  935. {
  936. #endif /* FLASH_BANK2_END */
  937. /* Proceed to erase the page */
  938. SET_BIT(FLASH->CR, FLASH_CR_PER);
  939. WRITE_REG(FLASH->AR, PageAddress);
  940. SET_BIT(FLASH->CR, FLASH_CR_STRT);
  941. #if defined(FLASH_BANK2_END)
  942. }
  943. #endif /* FLASH_BANK2_END */
  944. }
  945. /**
  946. * @}
  947. */
  948. /**
  949. * @}
  950. */
  951. #endif /* HAL_FLASH_MODULE_ENABLED */
  952. /**
  953. * @}
  954. */