STM32L4xx_HAL_Driver  1.14.0
FLASHEx Private Functions

Functions

void FLASH_PageErase (uint32_t Page, uint32_t Banks)
 Erase the specified FLASH memory page. More...
 
void FLASH_FlushCaches (void)
 Flush the instruction and data caches. More...
 
static void FLASH_MassErase (uint32_t Banks)
 Mass erase of FLASH memory. More...
 
static HAL_StatusTypeDef FLASH_OB_WRPConfig (uint32_t WRPArea, uint32_t WRPStartOffset, uint32_t WRDPEndOffset)
 Configure the write protection of the desired pages. More...
 
static HAL_StatusTypeDef FLASH_OB_RDPConfig (uint32_t RDPLevel)
 Set the read protection level. More...
 
static HAL_StatusTypeDef FLASH_OB_UserConfig (uint32_t UserType, uint32_t UserConfig)
 Program the FLASH User Option Byte. More...
 
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. More...
 
static void FLASH_OB_GetWRP (uint32_t WRPArea, uint32_t *WRPStartOffset, uint32_t *WRDPEndOffset)
 Return the FLASH Write Protection Option Bytes value. More...
 
static uint32_t FLASH_OB_GetRDP (void)
 Return the FLASH Read Protection level. More...
 
static uint32_t FLASH_OB_GetUser (void)
 Return the FLASH User Option Byte value. More...
 
static void FLASH_OB_GetPCROP (uint32_t *PCROPConfig, uint32_t *PCROPStartAddr, uint32_t *PCROPEndAddr)
 Return the FLASH Write Protection Option Bytes value. More...
 

Detailed Description

Function Documentation

◆ FLASH_FlushCaches()

void FLASH_FlushCaches ( void  )

Flush the instruction and data caches.

Return values
None

Definition at line 597 of file stm32l4xx_hal_flash_ex.c.

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 }
FLASH_CacheTypeDef
FLASH Cache structure definition.
FLASH_ProcessTypeDef pFlash
Variable used for Program/Erase sectors under interruption.
__IO FLASH_CacheTypeDef CacheToReactivate

◆ FLASH_MassErase()

static void FLASH_MassErase ( uint32_t  Banks)
static

Mass erase of FLASH memory.

Parameters
BanksBanks to be erased This parameter can be one of the following values:
  • FLASH_BANK_1: Bank1 to be erased
  • FLASH_BANK_2: Bank2 to be erased
  • FLASH_BANK_BOTH: Bank1 and Bank2 to be erased
Return values
None

Definition at line 509 of file stm32l4xx_hal_flash_ex.c.

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 }
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ FLASH_OB_GetPCROP()

static void FLASH_OB_GetPCROP ( uint32_t *  PCROPConfig,
uint32_t *  PCROPStartAddr,
uint32_t *  PCROPEndAddr 
)
static

Return the FLASH Write Protection Option Bytes value.

Parameters
PCROPConfig[inout]: specifies the configuration (Bank to be configured and PCROP_RDP option). This parameter must be a combination of FLASH_BANK_1 or FLASH_BANK_2 with OB_PCROP_RDP_NOT_ERASE or OB_PCROP_RDP_ERASE
PCROPStartAddr[out]: specifies the address where to copied the start address of the Proprietary code readout protection
PCROPEndAddr[out]: specifies the address where to copied the end address of the Proprietary code readout protection
Return values
None

Definition at line 1207 of file stm32l4xx_hal_flash_ex.c.

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 }

◆ FLASH_OB_GetRDP()

static uint32_t FLASH_OB_GetRDP ( void  )
static

Return the FLASH Read Protection level.

Return values
FLASHReadOut Protection Status: 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 1158 of file stm32l4xx_hal_flash_ex.c.

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 }

◆ 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: For STM32L47x/STM32L48x devices : BOR_LEV(Bit8-10), nRST_STOP(Bit12), nRST_STDBY(Bit13), nRST_SHDW(Bit14), IWDG_SW(Bit16), IWDG_STOP(Bit17), IWDG_STDBY(Bit18), WWDG_SW(Bit19), BFB2(Bit20), DUALBANK(Bit21), nBOOT1(Bit23), SRAM2_PE(Bit24) and SRAM2_RST(Bit25). For STM32L43x/STM32L44x devices : BOR_LEV(Bit8-10), nRST_STOP(Bit12), nRST_STDBY(Bit13), nRST_SHDW(Bit14), IWDG_SW(Bit16), IWDG_STOP(Bit17), IWDG_STDBY(Bit18), WWDG_SW(Bit19), nBOOT1(Bit23), SRAM2_PE(Bit24), SRAM2_RST(Bit25), nSWBOOT0(Bit26) and nBOOT0(Bit27).

Definition at line 1184 of file stm32l4xx_hal_flash_ex.c.

1185 {
1186  uint32_t user_config = READ_REG(FLASH->OPTR);
1187  CLEAR_BIT(user_config, FLASH_OPTR_RDP);
1188 
1189  return user_config;
1190 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)

◆ FLASH_OB_GetWRP()

static void FLASH_OB_GetWRP ( uint32_t  WRPArea,
uint32_t *  WRPStartOffset,
uint32_t *  WRDPEndOffset 
)
static

Return the FLASH Write Protection Option Bytes value.

Parameters
[in]WRPAreaspecifies the area to be returned. This parameter can be one of the following values:
  • OB_WRPAREA_BANK1_AREAA: Flash Bank 1 Area A
  • OB_WRPAREA_BANK1_AREAB: Flash Bank 1 Area B
  • OB_WRPAREA_BANK2_AREAA: Flash Bank 2 Area A (don't apply to STM32L43x/STM32L44x devices)
  • OB_WRPAREA_BANK2_AREAB: Flash Bank 2 Area B (don't apply to STM32L43x/STM32L44x devices)
[out]WRPStartOffsetspecifies the address where to copied the start page of the write protected area
[out]WRDPEndOffsetspecifies the address where to copied the end page of the write protected area
Return values
None

Definition at line 1117 of file stm32l4xx_hal_flash_ex.c.

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 }

◆ FLASH_OB_PCROPConfig()

static HAL_StatusTypeDef FLASH_OB_PCROPConfig ( uint32_t  PCROPConfig,
uint32_t  PCROPStartAddr,
uint32_t  PCROPEndAddr 
)
static

Configure the Proprietary code readout protection of the desired addresses.

Note
To configure the PCROP options, the option lock bit OPTLOCK must be cleared with the call of the HAL_FLASH_OB_Unlock() function.
To validate the PCROP options, the option bytes must be reloaded through the call of the HAL_FLASH_OB_Launch() function.
Parameters
PCROPConfigspecifies the configuration (Bank to be configured and PCROP_RDP option). This parameter must be a combination of FLASH_BANK_1 or FLASH_BANK_2 with OB_PCROP_RDP_NOT_ERASE or OB_PCROP_RDP_ERASE
PCROPStartAddrspecifies the start address of the Proprietary code readout protection This parameter can be an address between begin and end of the bank
PCROPEndAddrspecifies the end address of the Proprietary code readout protection This parameter can be an address between PCROPStartAddr and end of the bank
Return values
HALStatus

Definition at line 989 of file stm32l4xx_hal_flash_ex.c.

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 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
Wait for a FLASH operation to complete.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ FLASH_OB_RDPConfig()

static HAL_StatusTypeDef FLASH_OB_RDPConfig ( uint32_t  RDPLevel)
static

Set the read protection level.

Note
To configure the RDP level, the option lock bit OPTLOCK must be cleared with the call of the HAL_FLASH_OB_Unlock() function.
To validate the RDP level, the option bytes must be reloaded through the call of the HAL_FLASH_OB_Launch() function.
!!! Warning : When enabling OB_RDP level 2 it's no more possible to go back to level 1 or 0 !!!
Parameters
RDPLevelspecifies the read protection level. This parameter 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
Return values
HALstatus

Definition at line 727 of file stm32l4xx_hal_flash_ex.c.

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 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
Wait for a FLASH operation to complete.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ FLASH_OB_UserConfig()

static HAL_StatusTypeDef FLASH_OB_UserConfig ( uint32_t  UserType,
uint32_t  UserConfig 
)
static

Program the FLASH User Option Byte.

Note
To configure the user option bytes, the option lock bit OPTLOCK must be cleared with the call of the HAL_FLASH_OB_Unlock() function.
To validate the user option bytes, the option bytes must be reloaded through the call of the HAL_FLASH_OB_Launch() function.
Parameters
UserTypeThe FLASH User Option Bytes to be modified
UserConfigThe FLASH User Option Bytes values: BOR_LEV(Bit8-10), nRST_STOP(Bit12), nRST_STDBY(Bit13), IWDG_SW(Bit16), IWDG_STOP(Bit17), IWDG_STDBY(Bit18), WWDG_SW(Bit19), BFB2(Bit20), DUALBANK(Bit21), nBOOT1(Bit23), SRAM2_PE(Bit24) and SRAM2_RST(Bit25).
Return values
HALstatus

Definition at line 771 of file stm32l4xx_hal_flash_ex.c.

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 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
Wait for a FLASH operation to complete.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ FLASH_OB_WRPConfig()

static HAL_StatusTypeDef FLASH_OB_WRPConfig ( uint32_t  WRPArea,
uint32_t  WRPStartOffset,
uint32_t  WRDPEndOffset 
)
static

Configure the write protection of the desired pages.

Note
When the memory read protection level is selected (RDP level = 1), it is not possible to program or erase Flash memory if the CPU debug features are connected (JTAG or single wire) or boot code is being executed from RAM or System flash, even if WRP is not activated.
To configure the WRP options, the option lock bit OPTLOCK must be cleared with the call of the HAL_FLASH_OB_Unlock() function.
To validate the WRP options, the option bytes must be reloaded through the call of the HAL_FLASH_OB_Launch() function.
Parameters
WRPAreaspecifies the area to be configured. This parameter can be one of the following values:
  • OB_WRPAREA_BANK1_AREAA: Flash Bank 1 Area A
  • OB_WRPAREA_BANK1_AREAB: Flash Bank 1 Area B
  • OB_WRPAREA_BANK2_AREAA: Flash Bank 2 Area A (don't apply for STM32L43x/STM32L44x devices)
  • OB_WRPAREA_BANK2_AREAB: Flash Bank 2 Area B (don't apply for STM32L43x/STM32L44x devices)
WRPStartOffsetspecifies the start page of the write protected area This parameter can be page number between 0 and (max number of pages in the bank - 1)
WRDPEndOffsetspecifies the end page of the write protected area This parameter can be page number between WRPStartOffset and (max number of pages in the bank - 1)
Return values
HALStatus

Definition at line 652 of file stm32l4xx_hal_flash_ex.c.

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 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
Wait for a FLASH operation to complete.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ FLASH_PageErase()

void FLASH_PageErase ( uint32_t  Page,
uint32_t  Banks 
)

Erase the specified FLASH memory page.

Parameters
PageFLASH page to erase This parameter must be a value between 0 and (max number of pages in the bank - 1)
BanksBank(s) where the page will be erased This parameter can be one of the following values:
  • FLASH_BANK_1: Page in bank 1 to be erased
  • FLASH_BANK_2: Page in bank 2 to be erased
Return values
None

Definition at line 555 of file stm32l4xx_hal_flash_ex.c.

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 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))