STM32L4xx_HAL_Driver  1.14.0
Extended IO operation functions

Extended IO operation functions. More...

Functions

HAL_StatusTypeDef HAL_FLASHEx_Erase (FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)
 Perform a mass erase or erase the specified FLASH memory pages. More...
 
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT (FLASH_EraseInitTypeDef *pEraseInit)
 Perform a mass erase or erase the specified FLASH memory pages 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 bytes configuration. More...
 

Detailed Description

Extended IO operation functions.

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

Function Documentation

◆ HAL_FLASHEx_Erase()

HAL_StatusTypeDef HAL_FLASHEx_Erase ( FLASH_EraseInitTypeDef *  pEraseInit,
uint32_t *  PageError 
)

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

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

Definition at line 127 of file stm32l4xx_hal_flash_ex.c.

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 }
void FLASH_PageErase(uint32_t Page, uint32_t Banks)
Erase the specified FLASH memory page.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void FLASH_FlushCaches(void)
Flush the instruction and data caches.
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
Wait for a FLASH operation to complete.
FLASH_ProcessTypeDef pFlash
Variable used for Program/Erase sectors under interruption.
__IO FLASH_CacheTypeDef CacheToReactivate
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
static void FLASH_MassErase(uint32_t Banks)
Mass erase of FLASH memory.

◆ HAL_FLASHEx_Erase_IT()

HAL_StatusTypeDef HAL_FLASHEx_Erase_IT ( FLASH_EraseInitTypeDef *  pEraseInit)

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

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

Definition at line 232 of file stm32l4xx_hal_flash_ex.c.

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 }
__IO FLASH_ProcedureTypeDef ProcedureOnGoing
void FLASH_PageErase(uint32_t Page, uint32_t Banks)
Erase the specified FLASH memory page.
__HAL_LOCK(hrtc)
return HAL_OK
FLASH_ProcessTypeDef pFlash
Variable used for Program/Erase sectors under interruption.
__IO FLASH_CacheTypeDef CacheToReactivate
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
static void FLASH_MassErase(uint32_t Banks)
Mass erase of FLASH memory.

◆ HAL_FLASHEx_OBGetConfig()

void HAL_FLASHEx_OBGetConfig ( FLASH_OBProgramInitTypeDef pOBInit)

Get the Option bytes configuration.

Parameters
pOBInitpointer to an FLASH_OBInitStruct structure that contains the configuration information.
Note
The fields pOBInit->WRPArea and pOBInit->PCROPConfig should indicate which area is requested for the WRP and PCROP, else no information will be returned
Return values
None

Definition at line 375 of file stm32l4xx_hal_flash_ex.c.

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 }
static uint32_t FLASH_OB_GetRDP(void)
Return the FLASH Read Protection level.
static void FLASH_OB_GetWRP(uint32_t WRPArea, uint32_t *WRPStartOffset, uint32_t *WRDPEndOffset)
Return the FLASH Write Protection Option Bytes value.
static uint32_t FLASH_OB_GetUser(void)
Return the FLASH User Option Byte value.
static void FLASH_OB_GetPCROP(uint32_t *PCROPConfig, uint32_t *PCROPStartAddr, uint32_t *PCROPEndAddr)
Return the FLASH Write Protection Option Bytes value.

◆ 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

Definition at line 304 of file stm32l4xx_hal_flash_ex.c.

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 }
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint32_t UserType, uint32_t UserConfig)
Program the FLASH User Option Byte.
__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.
__HAL_LOCK(hrtc)
return HAL_OK
FLASH_ProcessTypeDef pFlash
Variable used for Program/Erase sectors under interruption.
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.
static HAL_StatusTypeDef FLASH_OB_RDPConfig(uint32_t RDPLevel)
Set the read protection level.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))