rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
stm32h7xx_hal_flash_ex.c File Reference

Detailed Description

Extended FLASH HAL module driver. This file provides firmware functions to manage the following functionalities of the FLASH extension peripheral:

Author
MCD Application Team
  • Extended programming operations functions
==============================================================================
                  ##### Flash Extension features #####
 ==============================================================================

 [..] Comparing to other previous devices, the FLASH interface for STM32H7xx
      devices contains the following additional features

      (+) Capacity up to 2 Mbyte with dual bank architecture supporting read-while-write
          capability (RWW)
      (+) Dual bank memory organization
      (+) PCROP protection for all banks
      (+) Global readout protection (RDP)
      (+) Write protection
      (+) Secure access only protection
      (+) Bank / register swapping
      (+) Cyclic Redundancy Check (CRC)

                       ##### How to use this driver #####
==============================================================================
 [..] This driver provides functions to configure and program the FLASH memory
      of all STM32H7xx devices. It includes
     (#) FLASH Memory Erase functions:
          (++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and
               HAL_FLASH_Lock() functions
          (++) Erase function: Sector erase, bank erase and dual-bank mass erase
          (++) There are two modes of erase :
            (+++) Polling Mode using HAL_FLASHEx_Erase()
            (+++) Interrupt Mode using HAL_FLASHEx_Erase_IT()

     (#) Option Bytes Programming functions: Use HAL_FLASHEx_OBProgram() to:
       (++) Set/Reset the write protection per bank
       (++) Set the Read protection Level
       (++) Set the BOR level
       (++) Program the user Option Bytes
       (++) PCROP protection configuration and control per bank
       (++) Secure area configuration and control per bank
       (++) Core Boot address configuration
       (++) TCM / AXI shared RAM configuration
       (++) CPU Frequency Boost configuration

     (#) FLASH Memory Lock and unlock per Bank: HAL_FLASHEx_Lock_Bank1(), HAL_FLASHEx_Unlock_Bank1(),
         HAL_FLASHEx_Lock_Bank2() and HAL_FLASHEx_Unlock_Bank2() functions

     (#) FLASH CRC computation function: Use HAL_FLASHEx_ComputeCRC() to:
         (++) Enable CRC feature
         (++) Program the desired burst size
         (++) Define the user Flash Area on which the CRC has be computed
         (++) Perform the CRC computation
         (++) Disable CRC feature
Attention

© COPYRIGHT(c) 2017 STMicroelectronics. All rights reserved.

This software component is licensed by ST under BSD 3-Clause license, the "License"; You may not use this file except in compliance with the License. You may obtain a copy of the License at: opensource.org/licenses/BSD-3-Clause

Definition in file stm32h7xx_hal_flash_ex.c.

Functions

static void FLASH_MassErase (uint32_t VoltageRange, uint32_t Banks)
 Mass erase of FLASH memory.
 
static void FLASH_OB_EnableWRP (uint32_t WRPSector, uint32_t Banks)
 Enable the write protection of the desired bank1 or bank 2 sectors.
 
static void FLASH_OB_DisableWRP (uint32_t WRPSector, uint32_t Banks)
 Disable the write protection of the desired bank1 or bank 2 sectors.
 
static void FLASH_OB_GetWRP (uint32_t *WRPState, uint32_t *WRPSector, uint32_t Bank)
 Get the write protection of the given bank 1 or bank 2 sectors.
 
static void FLASH_OB_RDPConfig (uint32_t RDPLevel)
 Set the read protection level.
 
static uint32_t FLASH_OB_GetRDP (void)
 Get the read protection level.
 
static void FLASH_OB_PCROPConfig (uint32_t PCROPConfig, uint32_t PCROPStartAddr, uint32_t PCROPEndAddr, uint32_t Banks)
 Configure the Proprietary code readout protection of the desired addresses.
 
static void FLASH_OB_GetPCROP (uint32_t *PCROPConfig, uint32_t *PCROPStartAddr, uint32_t *PCROPEndAddr, uint32_t Bank)
 Get the Proprietary code readout protection configuration on a given Bank.
 
static void FLASH_OB_BOR_LevelConfig (uint32_t Level)
 Set the BOR Level.
 
static uint32_t FLASH_OB_GetBOR (void)
 Get the BOR Level.
 
static void FLASH_OB_UserConfig (uint32_t UserType, uint32_t UserConfig)
 Program the FLASH User Option Byte.
 
static uint32_t FLASH_OB_GetUser (void)
 Return the FLASH User Option Byte value.
 
static void FLASH_OB_BootAddConfig (uint32_t BootOption, uint32_t BootAddress0, uint32_t BootAddress1)
 Set Boot address.
 
static void FLASH_OB_GetBootAdd (uint32_t *BootAddress0, uint32_t *BootAddress1)
 Get Boot address.
 
static void FLASH_OB_SecureAreaConfig (uint32_t SecureAreaConfig, uint32_t SecureAreaStartAddr, uint32_t SecureAreaEndAddr, uint32_t Banks)
 Set secure area configuration.
 
static void FLASH_OB_GetSecureArea (uint32_t *SecureAreaConfig, uint32_t *SecureAreaStartAddr, uint32_t *SecureAreaEndAddr, uint32_t Bank)
 Get secure area configuration.
 
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.
 
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_OB_CM4BootAddConfig (uint32_t BootOption, uint32_t BootAddress0, uint32_t BootAddress1)
 Set CM4 Boot address.
 
static void FLASH_OB_GetCM4BootAdd (uint32_t *BootAddress0, uint32_t *BootAddress1)
 Get CM4 Boot address.
 
static void FLASH_OB_OTP_LockConfig (uint32_t OTP_Block)
 Configure the OTP Block Lock.
 
static uint32_t FLASH_OB_OTP_GetLock (void)
 Get the OTP Block Lock.
 
static void FLASH_OB_SharedRAM_Config (uint32_t SharedRamConfig)
 Configure the TCM / AXI Shared RAM.
 
static uint32_t FLASH_OB_SharedRAM_GetConfig (void)
 Get the TCM / AXI Shared RAM configurtion.
 
static void FLASH_OB_CPUFreq_BoostConfig (uint32_t FreqBoost)
 Configure the CPU Frequency Boost.
 
static uint32_t FLASH_OB_CPUFreq_GetBoost (void)
 Get the CPU Frequency Boost state.
 
HAL_StatusTypeDef HAL_FLASHEx_Erase (FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError)
 Perform a mass erase or erase the specified FLASH memory sectors.
 
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT (FLASH_EraseInitTypeDef *pEraseInit)
 Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled.
 
HAL_StatusTypeDef HAL_FLASHEx_OBProgram (FLASH_OBProgramInitTypeDef *pOBInit)
 Program option bytes.
 
void HAL_FLASHEx_OBGetConfig (FLASH_OBProgramInitTypeDef *pOBInit)
 Get the Option byte configuration.
 
HAL_StatusTypeDef HAL_FLASHEx_Unlock_Bank1 (void)
 Unlock the FLASH Bank1 control registers access.
 
HAL_StatusTypeDef HAL_FLASHEx_Lock_Bank1 (void)
 Locks the FLASH Bank1 control registers access.
 
HAL_StatusTypeDef HAL_FLASHEx_Unlock_Bank2 (void)
 Unlock the FLASH Bank2 control registers access.
 
HAL_StatusTypeDef HAL_FLASHEx_Lock_Bank2 (void)
 Locks the FLASH Bank2 control registers access.
 
HAL_StatusTypeDef HAL_FLASHEx_ComputeCRC (FLASH_CRCInitTypeDef *pCRCInit, uint32_t *CRC_Result)
 
void FLASH_Erase_Sector (uint32_t Sector, uint32_t Banks, uint32_t VoltageRange)
 Erase the specified FLASH memory sector.
 

Function Documentation

◆ FLASH_OB_DisableWRP()

static void FLASH_OB_DisableWRP ( uint32_t  WRPSector,
uint32_t  Banks 
)
static

Disable the write protection of the desired bank1 or bank 2 sectors.

Parameters
WRPSectorspecifies the sector(s) to disable write protection. This parameter can be one of the following values:
  • WRPSector: A combination of FLASH_OB_WRP_SECTOR_0 to FLASH_OB_WRP_SECTOR_7 or FLASH_OB_WRP_SECTOR_All
Banksthe specific bank to apply WRP sectors This parameter can be one of the following values:
  • FLASH_BANK_1: disable WRP on specified bank1 sectors
  • FLASH_BANK_2: disable WRP on specified bank2 sectors
  • FLASH_BANK_BOTH: disable WRP on both bank1 and bank2 specified sectors
Return values
HALFLASH State

Definition at line 1025 of file stm32h7xx_hal_flash_ex.c.

1026{
1027 /* Check the parameters */
1028 assert_param(IS_OB_WRP_SECTOR(WRPSector));
1029 assert_param(IS_FLASH_BANK(Banks));
1030
1031 if((Banks & FLASH_BANK_1) == FLASH_BANK_1)
1032 {
1033 /* Disable Write Protection for bank 1 */
1034 FLASH->WPSN_PRG1 |= (WRPSector & FLASH_WPSN_WRPSN);
1035 }
1036
1037#if defined (DUAL_BANK)
1038 if((Banks & FLASH_BANK_2) == FLASH_BANK_2)
1039 {
1040 /* Disable Write Protection for bank 2 */
1041 FLASH->WPSN_PRG2 |= (WRPSector & FLASH_WPSN_WRPSN);
1042 }
1043#endif /* DUAL_BANK */
1044}

◆ FLASH_OB_EnableWRP()

static void FLASH_OB_EnableWRP ( uint32_t  WRPSector,
uint32_t  Banks 
)
static

Enable the write protection of the desired bank1 or bank 2 sectors.

Parameters
WRPSectorspecifies the sector(s) to be write protected. This parameter can be one of the following values:
  • WRPSector: A combination of OB_WRP_SECTOR_0 to OB_WRP_SECTOR_7 or OB_WRP_SECTOR_All
Banksthe specific bank to apply WRP sectors This parameter can be one of the following values:
  • FLASH_BANK_1: enable WRP on specified bank1 sectors
  • FLASH_BANK_2: enable WRP on specified bank2 sectors
  • FLASH_BANK_BOTH: enable WRP on both bank1 and bank2 specified sectors
Return values
HALFLASH State

Definition at line 990 of file stm32h7xx_hal_flash_ex.c.

991{
992 /* Check the parameters */
993 assert_param(IS_OB_WRP_SECTOR(WRPSector));
994 assert_param(IS_FLASH_BANK(Banks));
995
996 if((Banks & FLASH_BANK_1) == FLASH_BANK_1)
997 {
998 /* Enable Write Protection for bank 1 */
999 FLASH->WPSN_PRG1 &= (~(WRPSector & FLASH_WPSN_WRPSN));
1000 }
1001
1002#if defined (DUAL_BANK)
1003 if((Banks & FLASH_BANK_2) == FLASH_BANK_2)
1004 {
1005 /* Enable Write Protection for bank 2 */
1006 FLASH->WPSN_PRG2 &= (~(WRPSector & FLASH_WPSN_WRPSN));
1007 }
1008#endif /* DUAL_BANK */
1009}

◆ FLASH_OB_GetBOR()

static uint32_t FLASH_OB_GetBOR ( void  )
static

Get the BOR Level.

Return values
TheOption Bytes BOR Reset Level. This parameter can be one of the following values:
  • OB_BOR_LEVEL0: Reset level threshold is set to 1.6V
  • OB_BOR_LEVEL1: Reset level threshold is set to 2.1V
  • OB_BOR_LEVEL2: Reset level threshold is set to 2.4V
  • OB_BOR_LEVEL3: Reset level threshold is set to 2.7V

Definition at line 1507 of file stm32h7xx_hal_flash_ex.c.

1508{
1509 return (FLASH->OPTSR_CUR & FLASH_OPTSR_BOR_LEV);
1510}

◆ FLASH_OB_GetRDP()

static uint32_t FLASH_OB_GetRDP ( void  )
static

Get the read protection level.

Return values
RDPLevelspecifies the read protection level. This return value can be one of the following values:
  • OB_RDP_LEVEL_0: No protection
  • OB_RDP_LEVEL_1: Read protection of the memory
  • OB_RDP_LEVEL_2: Full chip protection

Definition at line 1127 of file stm32h7xx_hal_flash_ex.c.

1128{
1129 uint32_t rdp_level = READ_BIT(FLASH->OPTSR_CUR, FLASH_OPTSR_RDP);
1130
1131 if ((rdp_level != OB_RDP_LEVEL_0) && (rdp_level != OB_RDP_LEVEL_2))
1132 {
1133 return (OB_RDP_LEVEL_1);
1134 }
1135 else
1136 {
1137 return rdp_level;
1138 }
1139}

◆ FLASH_OB_GetUser()

static uint32_t FLASH_OB_GetUser ( void  )
static

Return the FLASH User Option Byte value.

Return values
TheFLASH User Option Bytes values IWDG1_SW(Bit4), IWDG2_SW(Bit 5), nRST_STOP_D1(Bit 6), nRST_STDY_D1(Bit 7), FZ_IWDG_STOP(Bit 17), FZ_IWDG_SDBY(Bit 18), ST_RAM_SIZE(Bit[19:20]), SECURITY(Bit 21), BCM4(Bit 22), BCM7(Bit 23), nRST_STOP_D2(Bit 24), nRST_STDY_D2(Bit 25), IO_HSLV (Bit 29) and SWAP_BANK_OPT(Bit 31).

Return the FLASH User Option Byte value.

Return values
TheFLASH User Option Bytes values IWDG_SW(Bit4), nRST_STOP_D1(Bit 6), nRST_STDY_D1(Bit 7), FZ_IWDG_STOP(Bit 17), FZ_IWDG_SDBY(Bit 18), ST_RAM_SIZE(Bit[19:20]), SECURITY(Bit 21), IO_HSLV (Bit 29) and SWAP_BANK_OPT(Bit 31).

Definition at line 1371 of file stm32h7xx_hal_flash_ex.c.

1372{
1373 uint32_t userConfig = READ_REG(FLASH->OPTSR_CUR);
1374 userConfig &= (~(FLASH_OPTSR_BOR_LEV | FLASH_OPTSR_RDP));
1375
1376 return userConfig;
1377}

Go to the source code of this file.