STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_flash_ex.c
Go to the documentation of this file.
1 
62 /* Includes ------------------------------------------------------------------*/
63 #include "stm32l4xx_hal.h"
64 
74 #ifdef HAL_FLASH_MODULE_ENABLED
75 
76 /* Private typedef -----------------------------------------------------------*/
77 /* Private define ------------------------------------------------------------*/
78 /* Private macro -------------------------------------------------------------*/
79 /* Private variables ---------------------------------------------------------*/
80 /* Private function prototypes -----------------------------------------------*/
84 static void FLASH_MassErase(uint32_t Banks);
85 static HAL_StatusTypeDef FLASH_OB_WRPConfig(uint32_t WRPArea, uint32_t WRPStartOffset, uint32_t WRDPEndOffset);
86 static HAL_StatusTypeDef FLASH_OB_RDPConfig(uint32_t RDPLevel);
87 static HAL_StatusTypeDef FLASH_OB_UserConfig(uint32_t UserType, uint32_t UserConfig);
88 static HAL_StatusTypeDef FLASH_OB_PCROPConfig(uint32_t PCROPConfig, uint32_t PCROPStartAddr, uint32_t PCROPEndAddr);
89 static void FLASH_OB_GetWRP(uint32_t WRPArea, uint32_t * WRPStartOffset, uint32_t * WRDPEndOffset);
90 static uint32_t FLASH_OB_GetRDP(void);
91 static uint32_t FLASH_OB_GetUser(void);
92 static void FLASH_OB_GetPCROP(uint32_t * PCROPConfig, uint32_t * PCROPStartAddr, uint32_t * PCROPEndAddr);
97 /* Exported functions -------------------------------------------------------*/
127 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)
128 {
129  HAL_StatusTypeDef status;
130  uint32_t page_index;
131 
132  /* Process Locked */
133  __HAL_LOCK(&pFlash);
134 
135  /* Check the parameters */
136  assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
137 
138  /* Wait for last operation to be completed */
139  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
140 
141  if (status == HAL_OK)
142  {
143  pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
144 
145  /* Deactivate the cache if they are activated to avoid data misbehavior */
146  if(READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) != 0U)
147  {
148  /* Disable instruction cache */
149  __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
150 
151  if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U)
152  {
153  /* Disable data cache */
154  __HAL_FLASH_DATA_CACHE_DISABLE();
156  }
157  else
158  {
160  }
161  }
162  else if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U)
163  {
164  /* Disable data cache */
165  __HAL_FLASH_DATA_CACHE_DISABLE();
167  }
168  else
169  {
171  }
172 
173  if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
174  {
175  /* Mass erase to be done */
176  FLASH_MassErase(pEraseInit->Banks);
177 
178  /* Wait for last operation to be completed */
179  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
180 
181 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
182  defined (STM32L496xx) || defined (STM32L4A6xx) || \
183  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
184  /* If the erase operation is completed, disable the MER1 and MER2 Bits */
185  CLEAR_BIT(FLASH->CR, (FLASH_CR_MER1 | FLASH_CR_MER2));
186 #else
187  /* If the erase operation is completed, disable the MER1 Bit */
188  CLEAR_BIT(FLASH->CR, (FLASH_CR_MER1));
189 #endif
190  }
191  else
192  {
193  /*Initialization of PageError variable*/
194  *PageError = 0xFFFFFFFFU;
195 
196  for(page_index = pEraseInit->Page; page_index < (pEraseInit->Page + pEraseInit->NbPages); page_index++)
197  {
198  FLASH_PageErase(page_index, pEraseInit->Banks);
199 
200  /* Wait for last operation to be completed */
201  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
202 
203  /* If the erase operation is completed, disable the PER Bit */
204  CLEAR_BIT(FLASH->CR, (FLASH_CR_PER | FLASH_CR_PNB));
205 
206  if (status != HAL_OK)
207  {
208  /* In case of error, stop erase procedure and return the faulty address */
209  *PageError = page_index;
210  break;
211  }
212  }
213  }
214 
215  /* Flush the caches to be sure of the data consistency */
217  }
218 
219  /* Process Unlocked */
221 
222  return status;
223 }
224 
232 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
233 {
234  HAL_StatusTypeDef status = HAL_OK;
235 
236  /* Process Locked */
237  __HAL_LOCK(&pFlash);
238 
239  /* Check the parameters */
240  assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
241 
242  pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
243 
244  /* Deactivate the cache if they are activated to avoid data misbehavior */
245  if(READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) != 0U)
246  {
247  /* Disable instruction cache */
248  __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
249 
250  if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U)
251  {
252  /* Disable data cache */
253  __HAL_FLASH_DATA_CACHE_DISABLE();
255  }
256  else
257  {
259  }
260  }
261  else if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U)
262  {
263  /* Disable data cache */
264  __HAL_FLASH_DATA_CACHE_DISABLE();
266  }
267  else
268  {
270  }
271 
272  /* Enable End of Operation and Error interrupts */
273  __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_OPERR);
274 
275  pFlash.Bank = pEraseInit->Banks;
276 
277  if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
278  {
279  /* Mass erase to be done */
281  FLASH_MassErase(pEraseInit->Banks);
282  }
283  else
284  {
285  /* Erase by page to be done */
287  pFlash.NbPagesToErase = pEraseInit->NbPages;
288  pFlash.Page = pEraseInit->Page;
289 
290  /*Erase 1st page and wait for IT */
291  FLASH_PageErase(pEraseInit->Page, pEraseInit->Banks);
292  }
293 
294  return status;
295 }
296 
305 {
306  HAL_StatusTypeDef status = HAL_OK;
307 
308  /* Process Locked */
309  __HAL_LOCK(&pFlash);
310 
311  /* Check the parameters */
312  assert_param(IS_OPTIONBYTE(pOBInit->OptionType));
313 
314  pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
315 
316  /* Write protection configuration */
317  if((pOBInit->OptionType & OPTIONBYTE_WRP) != 0U)
318  {
319  /* Configure of Write protection on the selected area */
320  if(FLASH_OB_WRPConfig(pOBInit->WRPArea, pOBInit->WRPStartOffset, pOBInit->WRPEndOffset) != HAL_OK)
321  {
322  status = HAL_ERROR;
323  }
324 
325  }
326 
327  /* Read protection configuration */
328  if((pOBInit->OptionType & OPTIONBYTE_RDP) != 0U)
329  {
330  /* Configure the Read protection level */
331  if(FLASH_OB_RDPConfig(pOBInit->RDPLevel) != HAL_OK)
332  {
333  status = HAL_ERROR;
334  }
335  }
336 
337  /* User Configuration */
338  if((pOBInit->OptionType & OPTIONBYTE_USER) != 0U)
339  {
340  /* Configure the user option bytes */
341  if(FLASH_OB_UserConfig(pOBInit->USERType, pOBInit->USERConfig) != HAL_OK)
342  {
343  status = HAL_ERROR;
344  }
345  }
346 
347  /* PCROP Configuration */
348  if((pOBInit->OptionType & OPTIONBYTE_PCROP) != 0U)
349  {
350  if (pOBInit->PCROPStartAddr != pOBInit->PCROPEndAddr)
351  {
352  /* Configure the Proprietary code readout protection */
353  if(FLASH_OB_PCROPConfig(pOBInit->PCROPConfig, pOBInit->PCROPStartAddr, pOBInit->PCROPEndAddr) != HAL_OK)
354  {
355  status = HAL_ERROR;
356  }
357  }
358  }
359 
360  /* Process Unlocked */
362 
363  return status;
364 }
365 
376 {
377  pOBInit->OptionType = (OPTIONBYTE_RDP | OPTIONBYTE_USER);
378 
379 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
380  defined (STM32L496xx) || defined (STM32L4A6xx) || \
381  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
382  if((pOBInit->WRPArea == OB_WRPAREA_BANK1_AREAA) || (pOBInit->WRPArea == OB_WRPAREA_BANK1_AREAB) ||
383  (pOBInit->WRPArea == OB_WRPAREA_BANK2_AREAA) || (pOBInit->WRPArea == OB_WRPAREA_BANK2_AREAB))
384 #else
385  if((pOBInit->WRPArea == OB_WRPAREA_BANK1_AREAA) || (pOBInit->WRPArea == OB_WRPAREA_BANK1_AREAB))
386 #endif
387  {
388  pOBInit->OptionType |= OPTIONBYTE_WRP;
389  /* Get write protection on the selected area */
390  FLASH_OB_GetWRP(pOBInit->WRPArea, &(pOBInit->WRPStartOffset), &(pOBInit->WRPEndOffset));
391  }
392 
393  /* Get Read protection level */
394  pOBInit->RDPLevel = FLASH_OB_GetRDP();
395 
396  /* Get the user option bytes */
397  pOBInit->USERConfig = FLASH_OB_GetUser();
398 
399 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
400  defined (STM32L496xx) || defined (STM32L4A6xx) || \
401  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
402  if((pOBInit->PCROPConfig == FLASH_BANK_1) || (pOBInit->PCROPConfig == FLASH_BANK_2))
403 #else
404  if(pOBInit->PCROPConfig == FLASH_BANK_1)
405 #endif
406  {
407  pOBInit->OptionType |= OPTIONBYTE_PCROP;
408  /* Get the Proprietary code readout protection */
409  FLASH_OB_GetPCROP(&(pOBInit->PCROPConfig), &(pOBInit->PCROPStartAddr), &(pOBInit->PCROPEndAddr));
410  }
411 }
412 
417 #if defined (FLASH_CFGR_LVEN)
418 
446 HAL_StatusTypeDef HAL_FLASHEx_ConfigLVEPin(uint32_t ConfigLVE)
447 {
448  HAL_StatusTypeDef status;
449 
450  /* Process Locked */
451  __HAL_LOCK(&pFlash);
452 
453  /* Check the parameters */
454  assert_param(IS_FLASH_LVE_PIN(ConfigLVE));
455 
456  /* Wait for last operation to be completed */
457  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
458 
459  if (status == HAL_OK)
460  {
461  /* Check that the voltage scaling is range 2 */
462  if (HAL_PWREx_GetVoltageRange() == PWR_REGULATOR_VOLTAGE_SCALE2)
463  {
464  /* Configure the LVEN bit */
465  MODIFY_REG(FLASH->CFGR, FLASH_CFGR_LVEN, ConfigLVE);
466 
467  /* Check that the bit has been correctly configured */
468  if (READ_BIT(FLASH->CFGR, FLASH_CFGR_LVEN) != ConfigLVE)
469  {
470  status = HAL_ERROR;
471  }
472  }
473  else
474  {
475  /* Not allow to force Flash LVE pin if not in voltage range 2 */
476  status = HAL_ERROR;
477  }
478  }
479 
480  /* Process Unlocked */
482 
483  return status;
484 }
485 
489 #endif /* FLASH_CFGR_LVEN */
490 
495 /* Private functions ---------------------------------------------------------*/
496 
509 static void FLASH_MassErase(uint32_t Banks)
510 {
511 #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
512  if (READ_BIT(FLASH->OPTR, FLASH_OPTR_DBANK) != 0U)
513 #endif
514  {
515  /* Check the parameters */
516  assert_param(IS_FLASH_BANK(Banks));
517 
518  /* Set the Mass Erase Bit for the bank 1 if requested */
519  if((Banks & FLASH_BANK_1) != 0U)
520  {
521  SET_BIT(FLASH->CR, FLASH_CR_MER1);
522  }
523 
524 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
525  defined (STM32L496xx) || defined (STM32L4A6xx) || \
526  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
527  /* Set the Mass Erase Bit for the bank 2 if requested */
528  if((Banks & FLASH_BANK_2) != 0U)
529  {
530  SET_BIT(FLASH->CR, FLASH_CR_MER2);
531  }
532 #endif
533  }
534 #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
535  else
536  {
537  SET_BIT(FLASH->CR, (FLASH_CR_MER1 | FLASH_CR_MER2));
538  }
539 #endif
540 
541  /* Proceed to erase all sectors */
542  SET_BIT(FLASH->CR, FLASH_CR_STRT);
543 }
544 
555 void FLASH_PageErase(uint32_t Page, uint32_t Banks)
556 {
557  /* Check the parameters */
558  assert_param(IS_FLASH_PAGE(Page));
559 
560 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
561  defined (STM32L496xx) || defined (STM32L4A6xx) || \
562  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
563 #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
564  if(READ_BIT(FLASH->OPTR, FLASH_OPTR_DBANK) == 0U)
565  {
566  CLEAR_BIT(FLASH->CR, FLASH_CR_BKER);
567  }
568  else
569 #endif
570  {
571  assert_param(IS_FLASH_BANK_EXCLUSIVE(Banks));
572 
573  if((Banks & FLASH_BANK_1) != 0U)
574  {
575  CLEAR_BIT(FLASH->CR, FLASH_CR_BKER);
576  }
577  else
578  {
579  SET_BIT(FLASH->CR, FLASH_CR_BKER);
580  }
581  }
582 #else
583  /* Prevent unused argument(s) compilation warning */
584  UNUSED(Banks);
585 #endif
586 
587  /* Proceed to erase the page */
588  MODIFY_REG(FLASH->CR, FLASH_CR_PNB, ((Page & 0xFFU) << FLASH_CR_PNB_Pos));
589  SET_BIT(FLASH->CR, FLASH_CR_PER);
590  SET_BIT(FLASH->CR, FLASH_CR_STRT);
591 }
592 
598 {
600 
601  /* Flush instruction cache */
602  if((cache == FLASH_CACHE_ICACHE_ENABLED) ||
604  {
605  /* Reset instruction cache */
606  __HAL_FLASH_INSTRUCTION_CACHE_RESET();
607  /* Enable instruction cache */
608  __HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
609  }
610 
611  /* Flush data cache */
612  if((cache == FLASH_CACHE_DCACHE_ENABLED) ||
614  {
615  /* Reset data cache */
616  __HAL_FLASH_DATA_CACHE_RESET();
617  /* Enable data cache */
618  __HAL_FLASH_DATA_CACHE_ENABLE();
619  }
620 
621  /* Reset internal variable */
623 }
624 
652 static HAL_StatusTypeDef FLASH_OB_WRPConfig(uint32_t WRPArea, uint32_t WRPStartOffset, uint32_t WRDPEndOffset)
653 {
654  HAL_StatusTypeDef status;
655 
656  /* Check the parameters */
657  assert_param(IS_OB_WRPAREA(WRPArea));
658  assert_param(IS_FLASH_PAGE(WRPStartOffset));
659  assert_param(IS_FLASH_PAGE(WRDPEndOffset));
660 
661  /* Wait for last operation to be completed */
662  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
663 
664  if(status == HAL_OK)
665  {
666  /* Configure the write protected area */
667  if(WRPArea == OB_WRPAREA_BANK1_AREAA)
668  {
669  MODIFY_REG(FLASH->WRP1AR, (FLASH_WRP1AR_WRP1A_STRT | FLASH_WRP1AR_WRP1A_END),
670  (WRPStartOffset | (WRDPEndOffset << 16)));
671  }
672  else if(WRPArea == OB_WRPAREA_BANK1_AREAB)
673  {
674  MODIFY_REG(FLASH->WRP1BR, (FLASH_WRP1BR_WRP1B_STRT | FLASH_WRP1BR_WRP1B_END),
675  (WRPStartOffset | (WRDPEndOffset << 16)));
676  }
677 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
678  defined (STM32L496xx) || defined (STM32L4A6xx) || \
679  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
680  else if(WRPArea == OB_WRPAREA_BANK2_AREAA)
681  {
682  MODIFY_REG(FLASH->WRP2AR, (FLASH_WRP2AR_WRP2A_STRT | FLASH_WRP2AR_WRP2A_END),
683  (WRPStartOffset | (WRDPEndOffset << 16)));
684  }
685  else if(WRPArea == OB_WRPAREA_BANK2_AREAB)
686  {
687  MODIFY_REG(FLASH->WRP2BR, (FLASH_WRP2BR_WRP2B_STRT | FLASH_WRP2BR_WRP2B_END),
688  (WRPStartOffset | (WRDPEndOffset << 16)));
689  }
690 #endif
691  else
692  {
693  /* Nothing to do */
694  }
695 
696  /* Set OPTSTRT Bit */
697  SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
698 
699  /* Wait for last operation to be completed */
700  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
701 
702  /* If the option byte program operation is completed, disable the OPTSTRT Bit */
703  CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
704  }
705 
706  return status;
707 }
708 
727 static HAL_StatusTypeDef FLASH_OB_RDPConfig(uint32_t RDPLevel)
728 {
729  HAL_StatusTypeDef status;
730 
731  /* Check the parameters */
732  assert_param(IS_OB_RDP_LEVEL(RDPLevel));
733 
734  /* Wait for last operation to be completed */
735  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
736 
737  if(status == HAL_OK)
738  {
739  /* Configure the RDP level in the option bytes register */
740  MODIFY_REG(FLASH->OPTR, FLASH_OPTR_RDP, RDPLevel);
741 
742  /* Set OPTSTRT Bit */
743  SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
744 
745  /* Wait for last operation to be completed */
746  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
747 
748  /* If the option byte program operation is completed, disable the OPTSTRT Bit */
749  CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
750  }
751 
752  return status;
753 }
754 
771 static HAL_StatusTypeDef FLASH_OB_UserConfig(uint32_t UserType, uint32_t UserConfig)
772 {
773  uint32_t optr_reg_val = 0;
774  uint32_t optr_reg_mask = 0;
775  HAL_StatusTypeDef status;
776 
777  /* Check the parameters */
778  assert_param(IS_OB_USER_TYPE(UserType));
779 
780  /* Wait for last operation to be completed */
781  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
782 
783  if(status == HAL_OK)
784  {
785  if((UserType & OB_USER_BOR_LEV) != 0U)
786  {
787  /* BOR level option byte should be modified */
788  assert_param(IS_OB_USER_BOR_LEVEL(UserConfig & FLASH_OPTR_BOR_LEV));
789 
790  /* Set value and mask for BOR level option byte */
791  optr_reg_val |= (UserConfig & FLASH_OPTR_BOR_LEV);
792  optr_reg_mask |= FLASH_OPTR_BOR_LEV;
793  }
794 
795  if((UserType & OB_USER_nRST_STOP) != 0U)
796  {
797  /* nRST_STOP option byte should be modified */
798  assert_param(IS_OB_USER_STOP(UserConfig & FLASH_OPTR_nRST_STOP));
799 
800  /* Set value and mask for nRST_STOP option byte */
801  optr_reg_val |= (UserConfig & FLASH_OPTR_nRST_STOP);
802  optr_reg_mask |= FLASH_OPTR_nRST_STOP;
803  }
804 
805  if((UserType & OB_USER_nRST_STDBY) != 0U)
806  {
807  /* nRST_STDBY option byte should be modified */
808  assert_param(IS_OB_USER_STANDBY(UserConfig & FLASH_OPTR_nRST_STDBY));
809 
810  /* Set value and mask for nRST_STDBY option byte */
811  optr_reg_val |= (UserConfig & FLASH_OPTR_nRST_STDBY);
812  optr_reg_mask |= FLASH_OPTR_nRST_STDBY;
813  }
814 
815  if((UserType & OB_USER_nRST_SHDW) != 0U)
816  {
817  /* nRST_SHDW option byte should be modified */
818  assert_param(IS_OB_USER_SHUTDOWN(UserConfig & FLASH_OPTR_nRST_SHDW));
819 
820  /* Set value and mask for nRST_SHDW option byte */
821  optr_reg_val |= (UserConfig & FLASH_OPTR_nRST_SHDW);
822  optr_reg_mask |= FLASH_OPTR_nRST_SHDW;
823  }
824 
825  if((UserType & OB_USER_IWDG_SW) != 0U)
826  {
827  /* IWDG_SW option byte should be modified */
828  assert_param(IS_OB_USER_IWDG(UserConfig & FLASH_OPTR_IWDG_SW));
829 
830  /* Set value and mask for IWDG_SW option byte */
831  optr_reg_val |= (UserConfig & FLASH_OPTR_IWDG_SW);
832  optr_reg_mask |= FLASH_OPTR_IWDG_SW;
833  }
834 
835  if((UserType & OB_USER_IWDG_STOP) != 0U)
836  {
837  /* IWDG_STOP option byte should be modified */
838  assert_param(IS_OB_USER_IWDG_STOP(UserConfig & FLASH_OPTR_IWDG_STOP));
839 
840  /* Set value and mask for IWDG_STOP option byte */
841  optr_reg_val |= (UserConfig & FLASH_OPTR_IWDG_STOP);
842  optr_reg_mask |= FLASH_OPTR_IWDG_STOP;
843  }
844 
845  if((UserType & OB_USER_IWDG_STDBY) != 0U)
846  {
847  /* IWDG_STDBY option byte should be modified */
848  assert_param(IS_OB_USER_IWDG_STDBY(UserConfig & FLASH_OPTR_IWDG_STDBY));
849 
850  /* Set value and mask for IWDG_STDBY option byte */
851  optr_reg_val |= (UserConfig & FLASH_OPTR_IWDG_STDBY);
852  optr_reg_mask |= FLASH_OPTR_IWDG_STDBY;
853  }
854 
855  if((UserType & OB_USER_WWDG_SW) != 0U)
856  {
857  /* WWDG_SW option byte should be modified */
858  assert_param(IS_OB_USER_WWDG(UserConfig & FLASH_OPTR_WWDG_SW));
859 
860  /* Set value and mask for WWDG_SW option byte */
861  optr_reg_val |= (UserConfig & FLASH_OPTR_WWDG_SW);
862  optr_reg_mask |= FLASH_OPTR_WWDG_SW;
863  }
864 
865 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
866  defined (STM32L496xx) || defined (STM32L4A6xx) || \
867  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
868  if((UserType & OB_USER_BFB2) != 0U)
869  {
870  /* BFB2 option byte should be modified */
871  assert_param(IS_OB_USER_BFB2(UserConfig & FLASH_OPTR_BFB2));
872 
873  /* Set value and mask for BFB2 option byte */
874  optr_reg_val |= (UserConfig & FLASH_OPTR_BFB2);
875  optr_reg_mask |= FLASH_OPTR_BFB2;
876  }
877 
878  if((UserType & OB_USER_DUALBANK) != 0U)
879  {
880 #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
881  /* DUALBANK option byte should be modified */
882  assert_param(IS_OB_USER_DUALBANK(UserConfig & FLASH_OPTR_DB1M));
883 
884  /* Set value and mask for DUALBANK option byte */
885  optr_reg_val |= (UserConfig & FLASH_OPTR_DB1M);
886  optr_reg_mask |= FLASH_OPTR_DB1M;
887 #else
888  /* DUALBANK option byte should be modified */
889  assert_param(IS_OB_USER_DUALBANK(UserConfig & FLASH_OPTR_DUALBANK));
890 
891  /* Set value and mask for DUALBANK option byte */
892  optr_reg_val |= (UserConfig & FLASH_OPTR_DUALBANK);
893  optr_reg_mask |= FLASH_OPTR_DUALBANK;
894 #endif
895  }
896 #endif
897 
898  if((UserType & OB_USER_nBOOT1) != 0U)
899  {
900  /* nBOOT1 option byte should be modified */
901  assert_param(IS_OB_USER_BOOT1(UserConfig & FLASH_OPTR_nBOOT1));
902 
903  /* Set value and mask for nBOOT1 option byte */
904  optr_reg_val |= (UserConfig & FLASH_OPTR_nBOOT1);
905  optr_reg_mask |= FLASH_OPTR_nBOOT1;
906  }
907 
908  if((UserType & OB_USER_SRAM2_PE) != 0U)
909  {
910  /* SRAM2_PE option byte should be modified */
911  assert_param(IS_OB_USER_SRAM2_PARITY(UserConfig & FLASH_OPTR_SRAM2_PE));
912 
913  /* Set value and mask for SRAM2_PE option byte */
914  optr_reg_val |= (UserConfig & FLASH_OPTR_SRAM2_PE);
915  optr_reg_mask |= FLASH_OPTR_SRAM2_PE;
916  }
917 
918  if((UserType & OB_USER_SRAM2_RST) != 0U)
919  {
920  /* SRAM2_RST option byte should be modified */
921  assert_param(IS_OB_USER_SRAM2_RST(UserConfig & FLASH_OPTR_SRAM2_RST));
922 
923  /* Set value and mask for SRAM2_RST option byte */
924  optr_reg_val |= (UserConfig & FLASH_OPTR_SRAM2_RST);
925  optr_reg_mask |= FLASH_OPTR_SRAM2_RST;
926  }
927 
928 #if defined (STM32L412xx) || defined (STM32L422xx) || defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || \
929  defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || \
930  defined (STM32L496xx) || defined (STM32L4A6xx) || \
931  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
932  if((UserType & OB_USER_nSWBOOT0) != 0U)
933  {
934  /* nSWBOOT0 option byte should be modified */
935  assert_param(IS_OB_USER_SWBOOT0(UserConfig & FLASH_OPTR_nSWBOOT0));
936 
937  /* Set value and mask for nSWBOOT0 option byte */
938  optr_reg_val |= (UserConfig & FLASH_OPTR_nSWBOOT0);
939  optr_reg_mask |= FLASH_OPTR_nSWBOOT0;
940  }
941 
942  if((UserType & OB_USER_nBOOT0) != 0U)
943  {
944  /* nBOOT0 option byte should be modified */
945  assert_param(IS_OB_USER_BOOT0(UserConfig & FLASH_OPTR_nBOOT0));
946 
947  /* Set value and mask for nBOOT0 option byte */
948  optr_reg_val |= (UserConfig & FLASH_OPTR_nBOOT0);
949  optr_reg_mask |= FLASH_OPTR_nBOOT0;
950  }
951 #endif
952 
953  /* Configure the option bytes register */
954  MODIFY_REG(FLASH->OPTR, optr_reg_mask, optr_reg_val);
955 
956  /* Set OPTSTRT Bit */
957  SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
958 
959  /* Wait for last operation to be completed */
960  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
961 
962  /* If the option byte program operation is completed, disable the OPTSTRT Bit */
963  CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
964  }
965 
966  return status;
967 }
968 
989 static HAL_StatusTypeDef FLASH_OB_PCROPConfig(uint32_t PCROPConfig, uint32_t PCROPStartAddr, uint32_t PCROPEndAddr)
990 {
991  HAL_StatusTypeDef status;
992  uint32_t reg_value;
993  uint32_t bank1_addr;
994 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
995  defined (STM32L496xx) || defined (STM32L4A6xx) || \
996  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
997  uint32_t bank2_addr;
998 #endif
999 
1000  /* Check the parameters */
1001  assert_param(IS_FLASH_BANK_EXCLUSIVE(PCROPConfig & FLASH_BANK_BOTH));
1002  assert_param(IS_OB_PCROP_RDP(PCROPConfig & FLASH_PCROP1ER_PCROP_RDP));
1003  assert_param(IS_FLASH_MAIN_MEM_ADDRESS(PCROPStartAddr));
1004  assert_param(IS_FLASH_MAIN_MEM_ADDRESS(PCROPEndAddr));
1005 
1006  /* Wait for last operation to be completed */
1007  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
1008 
1009  if(status == HAL_OK)
1010  {
1011 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
1012  defined (STM32L496xx) || defined (STM32L4A6xx) || \
1013  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
1014  /* Get the information about the bank swapping */
1015  if (READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_FB_MODE) == 0U)
1016  {
1017  bank1_addr = FLASH_BASE;
1018  bank2_addr = FLASH_BASE + FLASH_BANK_SIZE;
1019  }
1020  else
1021  {
1022  bank1_addr = FLASH_BASE + FLASH_BANK_SIZE;
1023  bank2_addr = FLASH_BASE;
1024  }
1025 #else
1026  bank1_addr = FLASH_BASE;
1027 #endif
1028 
1029 #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
1030  if (READ_BIT(FLASH->OPTR, FLASH_OPTR_DBANK) == 0U)
1031  {
1032  /* Configure the Proprietary code readout protection */
1033  if((PCROPConfig & FLASH_BANK_BOTH) == FLASH_BANK_1)
1034  {
1035  reg_value = ((PCROPStartAddr - FLASH_BASE) >> 4);
1036  MODIFY_REG(FLASH->PCROP1SR, FLASH_PCROP1SR_PCROP1_STRT, reg_value);
1037 
1038  reg_value = ((PCROPEndAddr - FLASH_BASE) >> 4);
1039  MODIFY_REG(FLASH->PCROP1ER, FLASH_PCROP1ER_PCROP1_END, reg_value);
1040  }
1041  else if((PCROPConfig & FLASH_BANK_BOTH) == FLASH_BANK_2)
1042  {
1043  reg_value = ((PCROPStartAddr - FLASH_BASE) >> 4);
1044  MODIFY_REG(FLASH->PCROP2SR, FLASH_PCROP2SR_PCROP2_STRT, reg_value);
1045 
1046  reg_value = ((PCROPEndAddr - FLASH_BASE) >> 4);
1047  MODIFY_REG(FLASH->PCROP2ER, FLASH_PCROP2ER_PCROP2_END, reg_value);
1048  }
1049  else
1050  {
1051  /* Nothing to do */
1052  }
1053  }
1054  else
1055 #endif
1056  {
1057  /* Configure the Proprietary code readout protection */
1058  if((PCROPConfig & FLASH_BANK_BOTH) == FLASH_BANK_1)
1059  {
1060  reg_value = ((PCROPStartAddr - bank1_addr) >> 3);
1061  MODIFY_REG(FLASH->PCROP1SR, FLASH_PCROP1SR_PCROP1_STRT, reg_value);
1062 
1063  reg_value = ((PCROPEndAddr - bank1_addr) >> 3);
1064  MODIFY_REG(FLASH->PCROP1ER, FLASH_PCROP1ER_PCROP1_END, reg_value);
1065  }
1066 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
1067  defined (STM32L496xx) || defined (STM32L4A6xx) || \
1068  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
1069  else if((PCROPConfig & FLASH_BANK_BOTH) == FLASH_BANK_2)
1070  {
1071  reg_value = ((PCROPStartAddr - bank2_addr) >> 3);
1072  MODIFY_REG(FLASH->PCROP2SR, FLASH_PCROP2SR_PCROP2_STRT, reg_value);
1073 
1074  reg_value = ((PCROPEndAddr - bank2_addr) >> 3);
1075  MODIFY_REG(FLASH->PCROP2ER, FLASH_PCROP2ER_PCROP2_END, reg_value);
1076  }
1077 #endif
1078  else
1079  {
1080  /* Nothing to do */
1081  }
1082  }
1083 
1084  MODIFY_REG(FLASH->PCROP1ER, FLASH_PCROP1ER_PCROP_RDP, (PCROPConfig & FLASH_PCROP1ER_PCROP_RDP));
1085 
1086  /* Set OPTSTRT Bit */
1087  SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
1088 
1089  /* Wait for last operation to be completed */
1090  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
1091 
1092  /* If the option byte program operation is completed, disable the OPTSTRT Bit */
1093  CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
1094  }
1095 
1096  return status;
1097 }
1098 
1117 static void FLASH_OB_GetWRP(uint32_t WRPArea, uint32_t * WRPStartOffset, uint32_t * WRDPEndOffset)
1118 {
1119  /* Get the configuration of the write protected area */
1120  if(WRPArea == OB_WRPAREA_BANK1_AREAA)
1121  {
1122  *WRPStartOffset = READ_BIT(FLASH->WRP1AR, FLASH_WRP1AR_WRP1A_STRT);
1123  *WRDPEndOffset = (READ_BIT(FLASH->WRP1AR, FLASH_WRP1AR_WRP1A_END) >> 16);
1124  }
1125  else if(WRPArea == OB_WRPAREA_BANK1_AREAB)
1126  {
1127  *WRPStartOffset = READ_BIT(FLASH->WRP1BR, FLASH_WRP1BR_WRP1B_STRT);
1128  *WRDPEndOffset = (READ_BIT(FLASH->WRP1BR, FLASH_WRP1BR_WRP1B_END) >> 16);
1129  }
1130 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
1131  defined (STM32L496xx) || defined (STM32L4A6xx) || \
1132  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
1133  else if(WRPArea == OB_WRPAREA_BANK2_AREAA)
1134  {
1135  *WRPStartOffset = READ_BIT(FLASH->WRP2AR, FLASH_WRP2AR_WRP2A_STRT);
1136  *WRDPEndOffset = (READ_BIT(FLASH->WRP2AR, FLASH_WRP2AR_WRP2A_END) >> 16);
1137  }
1138  else if(WRPArea == OB_WRPAREA_BANK2_AREAB)
1139  {
1140  *WRPStartOffset = READ_BIT(FLASH->WRP2BR, FLASH_WRP2BR_WRP2B_STRT);
1141  *WRDPEndOffset = (READ_BIT(FLASH->WRP2BR, FLASH_WRP2BR_WRP2B_END) >> 16);
1142  }
1143 #endif
1144  else
1145  {
1146  /* Nothing to do */
1147  }
1148 }
1149 
1158 static uint32_t FLASH_OB_GetRDP(void)
1159 {
1160  uint32_t rdp_level = READ_BIT(FLASH->OPTR, FLASH_OPTR_RDP);
1161 
1162  if ((rdp_level != OB_RDP_LEVEL_0) && (rdp_level != OB_RDP_LEVEL_2))
1163  {
1164  return (OB_RDP_LEVEL_1);
1165  }
1166  else
1167  {
1168  return (READ_BIT(FLASH->OPTR, FLASH_OPTR_RDP));
1169  }
1170 }
1171 
1184 static uint32_t FLASH_OB_GetUser(void)
1185 {
1186  uint32_t user_config = READ_REG(FLASH->OPTR);
1187  CLEAR_BIT(user_config, FLASH_OPTR_RDP);
1188 
1189  return user_config;
1190 }
1191 
1207 static void FLASH_OB_GetPCROP(uint32_t * PCROPConfig, uint32_t * PCROPStartAddr, uint32_t * PCROPEndAddr)
1208 {
1209  uint32_t reg_value;
1210  uint32_t bank1_addr;
1211 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
1212  defined (STM32L496xx) || defined (STM32L4A6xx) || \
1213  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
1214  uint32_t bank2_addr;
1215 #endif
1216 
1217 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
1218  defined (STM32L496xx) || defined (STM32L4A6xx) || \
1219  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
1220  /* Get the information about the bank swapping */
1221  if (READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_FB_MODE) == 0U)
1222  {
1223  bank1_addr = FLASH_BASE;
1224  bank2_addr = FLASH_BASE + FLASH_BANK_SIZE;
1225  }
1226  else
1227  {
1228  bank1_addr = FLASH_BASE + FLASH_BANK_SIZE;
1229  bank2_addr = FLASH_BASE;
1230  }
1231 #else
1232  bank1_addr = FLASH_BASE;
1233 #endif
1234 
1235 #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
1236  if (READ_BIT(FLASH->OPTR, FLASH_OPTR_DBANK) == 0U)
1237  {
1238  if(((*PCROPConfig) & FLASH_BANK_BOTH) == FLASH_BANK_1)
1239  {
1240  reg_value = (READ_REG(FLASH->PCROP1SR) & FLASH_PCROP1SR_PCROP1_STRT);
1241  *PCROPStartAddr = (reg_value << 4) + FLASH_BASE;
1242 
1243  reg_value = (READ_REG(FLASH->PCROP1ER) & FLASH_PCROP1ER_PCROP1_END);
1244  *PCROPEndAddr = (reg_value << 4) + FLASH_BASE + 0xFU;
1245  }
1246  else if(((*PCROPConfig) & FLASH_BANK_BOTH) == FLASH_BANK_2)
1247  {
1248  reg_value = (READ_REG(FLASH->PCROP2SR) & FLASH_PCROP2SR_PCROP2_STRT);
1249  *PCROPStartAddr = (reg_value << 4) + FLASH_BASE;
1250 
1251  reg_value = (READ_REG(FLASH->PCROP2ER) & FLASH_PCROP2ER_PCROP2_END);
1252  *PCROPEndAddr = (reg_value << 4) + FLASH_BASE + 0xFU;;
1253  }
1254  else
1255  {
1256  /* Nothing to do */
1257  }
1258  }
1259  else
1260 #endif
1261  {
1262  if(((*PCROPConfig) & FLASH_BANK_BOTH) == FLASH_BANK_1)
1263  {
1264  reg_value = (READ_REG(FLASH->PCROP1SR) & FLASH_PCROP1SR_PCROP1_STRT);
1265  *PCROPStartAddr = (reg_value << 3) + bank1_addr;
1266 
1267  reg_value = (READ_REG(FLASH->PCROP1ER) & FLASH_PCROP1ER_PCROP1_END);
1268  *PCROPEndAddr = (reg_value << 3) + bank1_addr + 0x7U;
1269  }
1270 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
1271  defined (STM32L496xx) || defined (STM32L4A6xx) || \
1272  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
1273  else if(((*PCROPConfig) & FLASH_BANK_BOTH) == FLASH_BANK_2)
1274  {
1275  reg_value = (READ_REG(FLASH->PCROP2SR) & FLASH_PCROP2SR_PCROP2_STRT);
1276  *PCROPStartAddr = (reg_value << 3) + bank2_addr;
1277 
1278  reg_value = (READ_REG(FLASH->PCROP2ER) & FLASH_PCROP2ER_PCROP2_END);
1279  *PCROPEndAddr = (reg_value << 3) + bank2_addr + 0x7U;
1280  }
1281 #endif
1282  else
1283  {
1284  /* Nothing to do */
1285  }
1286  }
1287 
1288  *PCROPConfig |= (READ_REG(FLASH->PCROP1ER) & FLASH_PCROP1ER_PCROP_RDP);
1289 }
1298 #endif /* HAL_FLASH_MODULE_ENABLED */
1299 
1308 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_FLASHEx_ConfigLVEPin(uint32_t ConfigLVE)
Configuration of the LVE pin of the Flash (managed by power controller or forced to low in order to u...
__IO FLASH_ProcedureTypeDef ProcedureOnGoing
static uint32_t FLASH_OB_GetRDP(void)
Return the FLASH Read Protection level.
This file contains all the functions prototypes for the HAL module driver.
void FLASH_PageErase(uint32_t Page, uint32_t Banks)
Erase the specified FLASH memory page.
FLASH_CacheTypeDef
FLASH Cache structure definition.
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint32_t UserType, uint32_t UserConfig)
Program the FLASH User Option Byte.
static void FLASH_OB_GetWRP(uint32_t WRPArea, uint32_t *WRPStartOffset, uint32_t *WRDPEndOffset)
Return the FLASH Write Protection Option Bytes value.
__HAL_UNLOCK(hrtc)
static HAL_StatusTypeDef FLASH_OB_WRPConfig(uint32_t WRPArea, uint32_t WRPStartOffset, uint32_t WRDPEndOffset)
Configure the write protection of the desired pages.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void FLASH_FlushCaches(void)
Flush the instruction and data caches.
__HAL_LOCK(hrtc)
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
Get the Option bytes configuration.
return HAL_OK
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
Wait for a FLASH operation to complete.
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)
Perform a mass erase or erase the specified FLASH memory pages.
FLASH_ProcessTypeDef pFlash
Variable used for Program/Erase sectors under interruption.
FLASH Option Bytes Program structure definition.
static uint32_t FLASH_OB_GetUser(void)
Return the FLASH User Option Byte value.
static HAL_StatusTypeDef FLASH_OB_PCROPConfig(uint32_t PCROPConfig, uint32_t PCROPStartAddr, uint32_t PCROPEndAddr)
Configure the Proprietary code readout protection of the desired addresses.
uint32_t HAL_PWREx_GetVoltageRange(void)
Return Voltage Scaling Range.
static HAL_StatusTypeDef FLASH_OB_RDPConfig(uint32_t RDPLevel)
Set the read protection level.
__IO FLASH_CacheTypeDef CacheToReactivate
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
Perform a mass erase or erase the specified FLASH memory pages with interrupt enabled.
static void FLASH_OB_GetPCROP(uint32_t *PCROPConfig, uint32_t *PCROPStartAddr, uint32_t *PCROPEndAddr)
Return the FLASH Write Protection Option Bytes value.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
static void FLASH_MassErase(uint32_t Banks)
Mass erase of FLASH memory.
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
Program Option bytes.