rusEFI
The most advanced open source ECU
Functions

Extended IO operation functions. More...

Collaboration diagram for Extended IO operation functions:

Functions

HAL_StatusTypeDef HAL_FLASHEx_Erase (FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError)
 Perform a mass erase or erase the specified FLASH memory sectors. More...
 
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT (FLASH_EraseInitTypeDef *pEraseInit)
 Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled. More...
 
HAL_StatusTypeDef HAL_FLASHEx_OBProgram (FLASH_OBProgramInitTypeDef *pOBInit)
 Program option bytes. More...
 
void HAL_FLASHEx_OBGetConfig (FLASH_OBProgramInitTypeDef *pOBInit)
 Get the Option byte configuration. More...
 
HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram (FLASH_AdvOBProgramInitTypeDef *pAdvOBInit)
 Program option bytes. More...
 
void HAL_FLASHEx_AdvOBGetConfig (FLASH_AdvOBProgramInitTypeDef *pAdvOBInit)
 Get the OBEX byte configuration. More...
 
HAL_StatusTypeDef HAL_FLASHEx_OB_SelectPCROP (void)
 Select the Protection Mode. More...
 
HAL_StatusTypeDef HAL_FLASHEx_OB_DeSelectPCROP (void)
 Deselect the Protection Mode. More...
 
uint16_t HAL_FLASHEx_OB_GetBank2WRP (void)
 Returns the FLASH Write Protection Option Bytes value for Bank 2. More...
 
HAL_StatusTypeDef HAL_FLASHEx_Unlock_Bank1 (void)
 Unlock the FLASH Bank1 control registers access. More...
 
HAL_StatusTypeDef HAL_FLASHEx_Lock_Bank1 (void)
 Locks the FLASH Bank1 control registers access. More...
 
HAL_StatusTypeDef HAL_FLASHEx_Unlock_Bank2 (void)
 Unlock the FLASH Bank2 control registers access. More...
 
HAL_StatusTypeDef HAL_FLASHEx_Lock_Bank2 (void)
 Locks the FLASH Bank2 control registers access. More...
 
HAL_StatusTypeDef HAL_FLASHEx_ComputeCRC (FLASH_CRCInitTypeDef *pCRCInit, uint32_t *CRC_Result)
 
void FLASH_FlushCaches (void)
 Flush the instruction and data caches. More...
 

Detailed Description

Extended IO operation functions.

 ===============================================================================
                ##### Extended programming operation functions #####
 ===============================================================================  
    [..]
    This subsection provides a set of functions allowing to manage the Extension FLASH 
    programming operations.


 ===============================================================================
                ##### Extended programming operation functions #####
 ===============================================================================  
    [..]
    This subsection provides a set of functions allowing to manage the Extension FLASH 
    programming operations Operations.


 ===============================================================================
                ##### Extended programming operation functions #####
 ===============================================================================
    [..]
    This subsection provides a set of functions allowing to manage the Extension FLASH
    programming operations Operations.

Function Documentation

◆ FLASH_FlushCaches()

void FLASH_FlushCaches ( void  )

Flush the instruction and data caches.

Return values
None

Definition at line 370 of file stm32f4xx_hal_flash_ex.c.

371 {
372  /* Flush instruction cache */
373  if(READ_BIT(FLASH->ACR, FLASH_ACR_ICEN))
374  {
375  /* Disable instruction cache */
376  __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
377  /* Reset instruction cache */
378  __HAL_FLASH_INSTRUCTION_CACHE_RESET();
379  /* Enable instruction cache */
380  __HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
381  }
382 
383  /* Flush data cache */
384  if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN))
385  {
386  /* Disable data cache */
387  __HAL_FLASH_DATA_CACHE_DISABLE();
388  /* Reset data cache */
389  __HAL_FLASH_DATA_CACHE_RESET();
390  /* Enable data cache */
391  __HAL_FLASH_DATA_CACHE_ENABLE();
392  }
393 }

Referenced by HAL_FLASH_IRQHandler(), and HAL_FLASHEx_Erase().

Here is the caller graph for this function:

◆ HAL_FLASHEx_AdvOBGetConfig()

void HAL_FLASHEx_AdvOBGetConfig ( FLASH_AdvOBProgramInitTypeDef pAdvOBInit)

Get the OBEX byte configuration.

Parameters
pAdvOBInitpointer to an FLASH_AdvOBProgramInitTypeDef structure that contains the configuration information for the programming.
Return values
None

Definition at line 482 of file stm32f4xx_hal_flash_ex.c.

483 {
484 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\
485  defined(STM32F411xE) || defined(STM32F446xx)
486  /*Get Sector*/
487  pAdvOBInit->Sectors = (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS));
488 #else /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx || STM32F469xx || STM32F479xx */
489  /*Get Sector for Bank1*/
490  pAdvOBInit->SectorsBank1 = (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS));
491 
492  /*Get Sector for Bank2*/
493  pAdvOBInit->SectorsBank2 = (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS));
494 
495  /*Get Boot config OB*/
496  pAdvOBInit->BootConfig = *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS;
497 #endif /* STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE || STM32F446xx */
498 }

◆ HAL_FLASHEx_AdvOBProgram()

HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram ( FLASH_AdvOBProgramInitTypeDef pAdvOBInit)

Program option bytes.

Parameters
pAdvOBInitpointer to an FLASH_AdvOBProgramInitTypeDef structure that contains the configuration information for the programming.
Return values
HALStatus

Definition at line 430 of file stm32f4xx_hal_flash_ex.c.

431 {
432  HAL_StatusTypeDef status = HAL_ERROR;
433 
434  /* Check the parameters */
435  assert_param(IS_OBEX(pAdvOBInit->OptionType));
436 
437  /*Program PCROP option byte*/
438  if(((pAdvOBInit->OptionType) & OPTIONBYTE_PCROP) == OPTIONBYTE_PCROP)
439  {
440  /* Check the parameters */
441  assert_param(IS_PCROPSTATE(pAdvOBInit->PCROPState));
442  if((pAdvOBInit->PCROPState) == OB_PCROP_STATE_ENABLE)
443  {
444  /*Enable of Write protection on the selected Sector*/
445 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\
446  defined(STM32F411xE) || defined(STM32F446xx)
447  status = FLASH_OB_EnablePCROP(pAdvOBInit->Sectors);
448 #else /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx || STM32F469xx || STM32F479xx */
449  status = FLASH_OB_EnablePCROP(pAdvOBInit->SectorsBank1, pAdvOBInit->SectorsBank2, pAdvOBInit->Banks);
450 #endif /* STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE || STM32F446xx */
451  }
452  else
453  {
454  /*Disable of Write protection on the selected Sector*/
455 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\
456  defined(STM32F411xE) || defined(STM32F446xx)
457  status = FLASH_OB_DisablePCROP(pAdvOBInit->Sectors);
458 #else /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx || STM32F469xx || STM32F479xx */
459  status = FLASH_OB_DisablePCROP(pAdvOBInit->SectorsBank1, pAdvOBInit->SectorsBank2, pAdvOBInit->Banks);
460 #endif /* STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE || STM32F446xx */
461  }
462  }
463 
464 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F469xx) || defined(STM32F479xx)
465  /*Program BOOT config option byte*/
466  if(((pAdvOBInit->OptionType) & OPTIONBYTE_BOOTCONFIG) == OPTIONBYTE_BOOTCONFIG)
467  {
468  status = FLASH_OB_BootConfig(pAdvOBInit->BootConfig);
469  }
470 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */
471 
472  return status;
473 }
static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t Sector)
Enable the read/write protection (PCROP) of the desired sectors.
static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t Sector)
Disable the read/write protection (PCROP) of the desired sectors.
static HAL_StatusTypeDef FLASH_OB_BootConfig(uint8_t BootConfig)
Configure the Dual Bank Boot.
Here is the call graph for this function:

◆ HAL_FLASHEx_ComputeCRC()

HAL_StatusTypeDef HAL_FLASHEx_ComputeCRC ( FLASH_CRCInitTypeDef pCRCInit,
uint32_t *  CRC_Result 
)

Definition at line 708 of file stm32h7xx_hal_flash_ex.c.

709 {
710  HAL_StatusTypeDef status;
711  uint32_t sector_index;
712 
713  /* Check the parameters */
714  assert_param(IS_FLASH_BANK_EXCLUSIVE(pCRCInit->Bank));
715  assert_param(IS_FLASH_TYPECRC(pCRCInit->TypeCRC));
716 
717  /* Wait for OB change operation to be completed */
718  status = FLASH_OB_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
719 
720  if (status == HAL_OK)
721  {
722  if (pCRCInit->Bank == FLASH_BANK_1)
723  {
724  /* Enable CRC feature */
725  FLASH->CR1 |= FLASH_CR_CRC_EN;
726 
727  /* Clear CRC flags in Status Register: CRC end of calculation and CRC read error */
728  FLASH->CCR1 |= (FLASH_CCR_CLR_CRCEND | FLASH_CCR_CLR_CRCRDERR);
729 
730  /* Clear current CRC result, program burst size and define memory area on which CRC has to be computed */
731  FLASH->CRCCR1 |= FLASH_CRCCR_CLEAN_CRC | pCRCInit->BurstSize | pCRCInit->TypeCRC;
732 
733  if (pCRCInit->TypeCRC == FLASH_CRC_SECTORS)
734  {
735  /* Clear sectors list */
736  FLASH->CRCCR1 |= FLASH_CRCCR_CLEAN_SECT;
737 
738  /* Select CRC sectors */
739  for(sector_index = pCRCInit->Sector; sector_index < (pCRCInit->NbSectors + pCRCInit->Sector); sector_index++)
740  {
741  FLASH_CRC_AddSector(sector_index, FLASH_BANK_1);
742  }
743  }
744  else if (pCRCInit->TypeCRC == FLASH_CRC_BANK)
745  {
746  /* Enable Bank 1 CRC select bit */
747  FLASH->CRCCR1 |= FLASH_CRCCR_ALL_BANK;
748  }
749  else
750  {
751  /* Select CRC start and end addresses */
752  FLASH_CRC_SelectAddress(pCRCInit->CRCStartAddr, pCRCInit->CRCEndAddr, FLASH_BANK_1);
753  }
754 
755  /* Start the CRC calculation */
756  FLASH->CRCCR1 |= FLASH_CRCCR_START_CRC;
757 
758  /* Wait on CRC busy flag */
759  status = FLASH_CRC_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1);
760 
761  /* Return CRC result */
762  (*CRC_Result) = FLASH->CRCDATA;
763 
764  /* Disable CRC feature */
765  FLASH->CR1 &= (~FLASH_CR_CRC_EN);
766 
767  /* Clear CRC flags */
768  __HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_CRCEND_BANK1 | FLASH_FLAG_CRCRDERR_BANK1);
769  }
770 #if defined (DUAL_BANK)
771  else
772  {
773  /* Enable CRC feature */
774  FLASH->CR2 |= FLASH_CR_CRC_EN;
775 
776  /* Clear CRC flags in Status Register: CRC end of calculation and CRC read error */
777  FLASH->CCR2 |= (FLASH_CCR_CLR_CRCEND | FLASH_CCR_CLR_CRCRDERR);
778 
779  /* Clear current CRC result, program burst size and define memory area on which CRC has to be computed */
780  FLASH->CRCCR2 |= FLASH_CRCCR_CLEAN_CRC | pCRCInit->BurstSize | pCRCInit->TypeCRC;
781 
782  if (pCRCInit->TypeCRC == FLASH_CRC_SECTORS)
783  {
784  /* Clear sectors list */
785  FLASH->CRCCR2 |= FLASH_CRCCR_CLEAN_SECT;
786 
787  /* Add CRC sectors */
788  for(sector_index = pCRCInit->Sector; sector_index < (pCRCInit->NbSectors + pCRCInit->Sector); sector_index++)
789  {
790  FLASH_CRC_AddSector(sector_index, FLASH_BANK_2);
791  }
792  }
793  else if (pCRCInit->TypeCRC == FLASH_CRC_BANK)
794  {
795  /* Enable Bank 2 CRC select bit */
796  FLASH->CRCCR2 |= FLASH_CRCCR_ALL_BANK;
797  }
798  else
799  {
800  /* Select CRC start and end addresses */
801  FLASH_CRC_SelectAddress(pCRCInit->CRCStartAddr, pCRCInit->CRCEndAddr, FLASH_BANK_2);
802  }
803 
804  /* Start the CRC calculation */
805  FLASH->CRCCR2 |= FLASH_CRCCR_START_CRC;
806 
807  /* Wait on CRC busy flag */
808  status = FLASH_CRC_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_2);
809 
810  /* Return CRC result */
811  (*CRC_Result) = FLASH->CRCDATA;
812 
813  /* Disable CRC feature */
814  FLASH->CR2 &= (~FLASH_CR_CRC_EN);
815 
816  /* Clear CRC flags */
817  __HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_CRCEND_BANK2 | FLASH_FLAG_CRCRDERR_BANK2);
818  }
819 #endif /* DUAL_BANK */
820  }
821 
822  return status;
823 }
HAL_StatusTypeDef FLASH_CRC_WaitForLastOperation(uint32_t Timeout, uint32_t Bank)
Wait for a FLASH CRC computation to complete.
HAL_StatusTypeDef FLASH_OB_WaitForLastOperation(uint32_t Timeout)
Wait for a FLASH Option Bytes change operation to complete.
static void FLASH_CRC_SelectAddress(uint32_t CRCStartAddr, uint32_t CRCEndAddr, uint32_t Bank)
Select CRC start and end memory addresses on which the CRC will be calculated.
static void FLASH_CRC_AddSector(uint32_t Sector, uint32_t Bank)
Add a CRC sector to the list of sectors on which the CRC will be calculated.
Here is the call graph for this function:

◆ HAL_FLASHEx_Erase()

HAL_StatusTypeDef HAL_FLASHEx_Erase ( FLASH_EraseInitTypeDef *  pEraseInit,
uint32_t *  SectorError 
)

Perform a mass erase or erase the specified FLASH memory sectors.

Parameters
[in]pEraseInitpointer to an FLASH_EraseInitTypeDef structure that contains the configuration information for the erasing.
[out]SectorErrorpointer to variable that contains the configuration information on faulty sector in case of error (0xFFFFFFFF means that all the sectors have been correctly erased)
Return values
HALStatus
Parameters
[in]pEraseInitpointer to an FLASH_EraseInitTypeDef structure that contains the configuration information for the erasing.
[out]SectorErrorpointer to variable that contains the configuration information on faulty sector in case of error (0xFFFFFFFF means that all the sectors have been correctly erased)
Return values
HALStatus

Definition at line 190 of file stm32f4xx_hal_flash_ex.c.

191 {
192  HAL_StatusTypeDef status = HAL_ERROR;
193  uint32_t index = 0;
194 
195  /* Process Locked */
196  __HAL_LOCK(&pFlash);
197 
198  /* Check the parameters */
199  assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
200 
201  /* Wait for last operation to be completed */
202  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
203 
204  if(status == HAL_OK)
205  {
206  /*Initialization of SectorError variable*/
207  *SectorError = 0xFFFFFFFF;
208 
209  if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
210  {
211  /*Mass erase to be done*/
212  FLASH_MassErase((uint8_t) pEraseInit->VoltageRange, pEraseInit->Banks);
213 
214  /* Wait for last operation to be completed */
215  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
216 
217  /* if the erase operation is completed, disable the MER Bit */
218  FLASH->CR &= (~FLASH_MER_BIT);
219  }
220  else
221  {
222  /* Check the parameters */
223  assert_param(IS_FLASH_NBSECTORS(pEraseInit->NbSectors + pEraseInit->Sector));
224 
225  /* Erase by sector by sector to be done*/
226  for(index = pEraseInit->Sector; index < (pEraseInit->NbSectors + pEraseInit->Sector); index++)
227  {
228  FLASH_Erase_Sector(index, (uint8_t) pEraseInit->VoltageRange);
229 
230  /* Wait for last operation to be completed */
231  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
232 
233  /* If the erase operation is completed, disable the SER and SNB Bits */
234  CLEAR_BIT(FLASH->CR, (FLASH_CR_SER | FLASH_CR_SNB));
235 
236  if(status != HAL_OK)
237  {
238  /* In case of error, stop erase procedure and return the faulty sector*/
239  *SectorError = index;
240  break;
241  }
242  }
243  }
244  /* Flush the caches to be sure of the data consistency */
246  }
247 
248  /* Process Unlocked */
249  __HAL_UNLOCK(&pFlash);
250 
251  return status;
252 }
void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange)
Erase the specified FLASH memory sector.
void FLASH_FlushCaches(void)
Flush the instruction and data caches.
static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks)
Full erase of FLASH memory sectors.
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
Wait for a FLASH operation to complete.
FLASH_ProcessTypeDef pFlash
Here is the call graph for this function:

◆ HAL_FLASHEx_Erase_IT()

HAL_StatusTypeDef HAL_FLASHEx_Erase_IT ( FLASH_EraseInitTypeDef *  pEraseInit)

Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled.

Parameters
pEraseInitpointer to an FLASH_EraseInitTypeDef structure that contains the configuration information for the erasing.
Return values
HALStatus
Parameters
pEraseInitpointer to an FLASH_EraseInitTypeDef structure that contains the configuration information for the erasing.
Return values
HALStatus

Definition at line 261 of file stm32f4xx_hal_flash_ex.c.

262 {
263  HAL_StatusTypeDef status = HAL_OK;
264 
265  /* Process Locked */
266  __HAL_LOCK(&pFlash);
267 
268  /* Check the parameters */
269  assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
270 
271  /* Enable End of FLASH Operation interrupt */
272  __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP);
273 
274  /* Enable Error source interrupt */
275  __HAL_FLASH_ENABLE_IT(FLASH_IT_ERR);
276 
277  /* Clear pending flags (if any) */
278  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |\
279  FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_PGSERR);
280 
281  if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
282  {
283  /*Mass erase to be done*/
284  pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE;
285  pFlash.Bank = pEraseInit->Banks;
286  FLASH_MassErase((uint8_t) pEraseInit->VoltageRange, pEraseInit->Banks);
287  }
288  else
289  {
290  /* Erase by sector to be done*/
291 
292  /* Check the parameters */
293  assert_param(IS_FLASH_NBSECTORS(pEraseInit->NbSectors + pEraseInit->Sector));
294 
295  pFlash.ProcedureOnGoing = FLASH_PROC_SECTERASE;
296  pFlash.NbSectorsToErase = pEraseInit->NbSectors;
297  pFlash.Sector = pEraseInit->Sector;
298  pFlash.VoltageForErase = (uint8_t)pEraseInit->VoltageRange;
299 
300  /*Erase 1st sector and wait for IT*/
301  FLASH_Erase_Sector(pEraseInit->Sector, pEraseInit->VoltageRange);
302  }
303 
304  return status;
305 }
__IO uint32_t NbSectorsToErase
__IO FLASH_ProcedureTypeDef ProcedureOnGoing
Here is the call graph for this function:

◆ HAL_FLASHEx_Lock_Bank1()

HAL_StatusTypeDef HAL_FLASHEx_Lock_Bank1 ( void  )

Locks the FLASH Bank1 control registers access.

Return values
HALStatus

Definition at line 655 of file stm32h7xx_hal_flash_ex.c.

656 {
657  /* Set the LOCK Bit to lock the FLASH Bank1 Registers access */
658  SET_BIT(FLASH->CR1, FLASH_CR_LOCK);
659  return HAL_OK;
660 }

◆ HAL_FLASHEx_Lock_Bank2()

HAL_StatusTypeDef HAL_FLASHEx_Lock_Bank2 ( void  )

Locks the FLASH Bank2 control registers access.

Return values
HALStatus

Definition at line 689 of file stm32h7xx_hal_flash_ex.c.

690 {
691  /* Set the LOCK Bit to lock the FLASH Bank2 Registers access */
692  SET_BIT(FLASH->CR2, FLASH_CR_LOCK);
693  return HAL_OK;
694 }

◆ HAL_FLASHEx_OB_DeSelectPCROP()

HAL_StatusTypeDef HAL_FLASHEx_OB_DeSelectPCROP ( void  )

Deselect the Protection Mode.

Note
After PCROP activated Option Byte modification NOT POSSIBLE! excepted Global Read Out Protection modification (from level1 to level0)
Once SPRMOD bit is active unprotection of a protected sector is not possible
Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag
This function can be used only for STM32F42xxx/STM32F43xxx/STM32F401xx/STM32F411xx/STM32F446xx/ STM32F469xx/STM32F479xx devices.
Return values
HALStatus

Definition at line 537 of file stm32f4xx_hal_flash_ex.c.

538 {
539  uint8_t optiontmp = 0xFF;
540 
541  /* Mask SPRMOD bit */
542  optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE3_ADDRESS) & (uint8_t)0x7F);
543 
544  /* Update Option Byte */
545  *(__IO uint8_t *)OPTCR_BYTE3_ADDRESS = (uint8_t)(OB_PCROP_DESELECTED | optiontmp);
546 
547  return HAL_OK;
548 }

◆ HAL_FLASHEx_OB_GetBank2WRP()

uint16_t HAL_FLASHEx_OB_GetBank2WRP ( void  )

Returns the FLASH Write Protection Option Bytes value for Bank 2.

Note
This function can be used only for STM32F42xxx/STM32F43xxx/STM32F469xx/STM32F479xx devices.
Return values
TheFLASH Write Protection Option Bytes value

Definition at line 558 of file stm32f4xx_hal_flash_ex.c.

559 {
560  /* Return the FLASH write protection Register value */
561  return (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS));
562 }

◆ HAL_FLASHEx_OB_SelectPCROP()

HAL_StatusTypeDef HAL_FLASHEx_OB_SelectPCROP ( void  )

Select the Protection Mode.

Note
After PCROP activated Option Byte modification NOT POSSIBLE! excepted Global Read Out Protection modification (from level1 to level0)
Once SPRMOD bit is active unprotection of a protected sector is not possible
Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag
This function can be used only for STM32F42xxx/STM32F43xxx/STM32F401xx/STM32F411xx/STM32F446xx/ STM32F469xx/STM32F479xx devices.
Return values
HALStatus

Definition at line 512 of file stm32f4xx_hal_flash_ex.c.

513 {
514  uint8_t optiontmp = 0xFF;
515 
516  /* Mask SPRMOD bit */
517  optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE3_ADDRESS) & (uint8_t)0x7F);
518 
519  /* Update Option Byte */
520  *(__IO uint8_t *)OPTCR_BYTE3_ADDRESS = (uint8_t)(OB_PCROP_SELECTED | optiontmp);
521 
522  return HAL_OK;
523 }

◆ HAL_FLASHEx_OBGetConfig()

void HAL_FLASHEx_OBGetConfig ( FLASH_OBProgramInitTypeDef pOBInit)

Get the Option byte configuration.

Parameters
pOBInitpointer to an FLASH_OBInitStruct structure that contains the configuration information for the programming.
Return values
None
Parameters
pOBInitpointer to an FLASH_OBInitStruct structure that contains the configuration information for the programming.
Note
The parameter Banks of the pOBInit structure must be set exclusively to FLASH_BANK_1 or FLASH_BANK_2, as this parameter is use to get the given Bank WRP, PCROP and secured area configuration.
Return values
None

Definition at line 402 of file stm32f4xx_hal_flash_ex.c.

403 {
404  pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_BOR;
405 
406  /*Get WRP*/
407  pOBInit->WRPSector = (uint32_t)FLASH_OB_GetWRP();
408 
409  /*Get RDP Level*/
410  pOBInit->RDPLevel = (uint32_t)FLASH_OB_GetRDP();
411 
412  /*Get USER*/
413  pOBInit->USERConfig = (uint8_t)FLASH_OB_GetUser();
414 
415  /*Get BOR Level*/
416  pOBInit->BORLevel = (uint32_t)FLASH_OB_GetBOR();
417 }
static uint8_t FLASH_OB_GetBOR(void)
Returns the FLASH BOR level.
static uint16_t FLASH_OB_GetWRP(void)
Return the FLASH Write Protection Option Bytes value.
static uint8_t FLASH_OB_GetRDP(void)
Returns the FLASH Read Protection level.
static uint8_t FLASH_OB_GetUser(void)
Return the FLASH User Option Byte value.

Referenced by BOR_Get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HAL_FLASHEx_OBProgram()

HAL_StatusTypeDef HAL_FLASHEx_OBProgram ( FLASH_OBProgramInitTypeDef pOBInit)

Program option bytes.

Parameters
pOBInitpointer to an FLASH_OBInitStruct structure that contains the configuration information for the programming.
Return values
HALStatus
Parameters
pOBInitpointer to an FLASH_OBInitStruct structure that contains the configuration information for the programming.
Return values
HALStatus

Definition at line 314 of file stm32f4xx_hal_flash_ex.c.

315 {
316  HAL_StatusTypeDef status = HAL_ERROR;
317 
318  /* Process Locked */
319  __HAL_LOCK(&pFlash);
320 
321  /* Check the parameters */
322  assert_param(IS_OPTIONBYTE(pOBInit->OptionType));
323 
324  /*Write protection configuration*/
325  if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP)
326  {
327  assert_param(IS_WRPSTATE(pOBInit->WRPState));
328  if(pOBInit->WRPState == OB_WRPSTATE_ENABLE)
329  {
330  /*Enable of Write protection on the selected Sector*/
331  status = FLASH_OB_EnableWRP(pOBInit->WRPSector, pOBInit->Banks);
332  }
333  else
334  {
335  /*Disable of Write protection on the selected Sector*/
336  status = FLASH_OB_DisableWRP(pOBInit->WRPSector, pOBInit->Banks);
337  }
338  }
339 
340  /*Read protection configuration*/
341  if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP)
342  {
343  status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel);
344  }
345 
346  /*USER configuration*/
347  if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER)
348  {
349  status = FLASH_OB_UserConfig(pOBInit->USERConfig&OB_IWDG_SW,
350  pOBInit->USERConfig&OB_STOP_NO_RST,
351  pOBInit->USERConfig&OB_STDBY_NO_RST);
352  }
353 
354  /*BOR Level configuration*/
355  if((pOBInit->OptionType & OPTIONBYTE_BOR) == OPTIONBYTE_BOR)
356  {
357  status = FLASH_OB_BOR_LevelConfig(pOBInit->BORLevel);
358  }
359 
360  /* Process Unlocked */
361  __HAL_UNLOCK(&pFlash);
362 
363  return status;
364 }
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks)
Disable the write protection of the desired bank1 or bank 2 sectors.
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks)
Enable the write protection of the desired bank1 or bank 2 sectors.
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t Iwdg, uint8_t Stop, uint8_t Stdby)
Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t Level)
Set the read protection level.
static HAL_StatusTypeDef FLASH_OB_BOR_LevelConfig(uint8_t Level)
Set the BOR Level.

Referenced by BOR_Set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HAL_FLASHEx_Unlock_Bank1()

HAL_StatusTypeDef HAL_FLASHEx_Unlock_Bank1 ( void  )

Unlock the FLASH Bank1 control registers access.

Return values
HALStatus

Definition at line 633 of file stm32h7xx_hal_flash_ex.c.

634 {
635  if(READ_BIT(FLASH->CR1, FLASH_CR_LOCK) != 0U)
636  {
637  /* Authorize the FLASH Bank1 Registers access */
638  WRITE_REG(FLASH->KEYR1, FLASH_KEY1);
639  WRITE_REG(FLASH->KEYR1, FLASH_KEY2);
640 
641  /* Verify Flash Bank1 is unlocked */
642  if (READ_BIT(FLASH->CR1, FLASH_CR_LOCK) != 0U)
643  {
644  return HAL_ERROR;
645  }
646  }
647 
648  return HAL_OK;
649 }

◆ HAL_FLASHEx_Unlock_Bank2()

HAL_StatusTypeDef HAL_FLASHEx_Unlock_Bank2 ( void  )

Unlock the FLASH Bank2 control registers access.

Return values
HALStatus

Definition at line 667 of file stm32h7xx_hal_flash_ex.c.

668 {
669  if(READ_BIT(FLASH->CR2, FLASH_CR_LOCK) != 0U)
670  {
671  /* Authorize the FLASH Bank2 Registers access */
672  WRITE_REG(FLASH->KEYR2, FLASH_KEY1);
673  WRITE_REG(FLASH->KEYR2, FLASH_KEY2);
674 
675  /* Verify Flash Bank1 is unlocked */
676  if (READ_BIT(FLASH->CR2, FLASH_CR_LOCK) != 0U)
677  {
678  return HAL_ERROR;
679  }
680  }
681 
682  return HAL_OK;
683 }