STM32L4xx_HAL_Driver  1.14.0

Programming operation functions. More...

Functions

HAL_StatusTypeDef HAL_FLASH_Program (uint32_t TypeProgram, uint32_t Address, uint64_t Data)
 Program double word or fast program of a row at a specified address. More...
 
HAL_StatusTypeDef HAL_FLASH_Program_IT (uint32_t TypeProgram, uint32_t Address, uint64_t Data)
 Program double word or fast program of a row at a specified address with interrupt enabled. More...
 
void HAL_FLASH_IRQHandler (void)
 Handle FLASH interrupt request. More...
 
void HAL_FLASH_EndOfOperationCallback (uint32_t ReturnValue)
 FLASH end of operation interrupt callback. More...
 
void HAL_FLASH_OperationErrorCallback (uint32_t ReturnValue)
 FLASH operation error interrupt callback. More...
 

Detailed Description

Programming operation functions.

 ===============================================================================
                  ##### Programming operation functions #####
 ===============================================================================
    [..]
    This subsection provides a set of functions allowing to manage the FLASH
    program operations.

Function Documentation

◆ HAL_FLASH_EndOfOperationCallback()

__weak void HAL_FLASH_EndOfOperationCallback ( uint32_t  ReturnValue)

FLASH end of operation interrupt callback.

Parameters
ReturnValueThe value saved in this parameter depends on the ongoing procedure Mass Erase: Bank number which has been requested to erase Page Erase: Page which has been erased (if 0xFFFFFFFF, it means that all the selected pages have been erased) Program: Address which was selected for data program
Return values
None

Definition at line 456 of file stm32l4xx_hal_flash.c.

457 {
458  /* Prevent unused argument(s) compilation warning */
459  UNUSED(ReturnValue);
460 
461  /* NOTE : This function should not be modified, when the callback is needed,
462  the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
463  */
464 }

◆ HAL_FLASH_IRQHandler()

void HAL_FLASH_IRQHandler ( void  )

Handle FLASH interrupt request.

Return values
None

Definition at line 313 of file stm32l4xx_hal_flash.c.

314 {
315  uint32_t tmp_page;
316  uint32_t error;
317  FLASH_ProcedureTypeDef procedure;
318 
319  /* If the operation is completed, disable the PG, PNB, MER1, MER2 and PER Bit */
320  CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_MER1 | FLASH_CR_PER | FLASH_CR_PNB));
321 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
322  defined (STM32L496xx) || defined (STM32L4A6xx) || \
323  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
324  CLEAR_BIT(FLASH->CR, FLASH_CR_MER2);
325 #endif
326 
327  /* Disable the FSTPG Bit only if it is the last row programmed */
329  {
330  CLEAR_BIT(FLASH->CR, FLASH_CR_FSTPG);
331  }
332 
333  /* Check FLASH operation error flags */
334  error = (FLASH->SR & FLASH_FLAG_SR_ERRORS);
335  error |= (FLASH->ECCR & FLASH_FLAG_ECCC);
336 
337  if (error !=0U)
338  {
339  /*Save the error code*/
340  pFlash.ErrorCode |= error;
341 
342  /* Clear error programming flags */
343  __HAL_FLASH_CLEAR_FLAG(error);
344 
345  /* Flush the caches to be sure of the data consistency */
347 
348  /* FLASH error interrupt user callback */
349  procedure = pFlash.ProcedureOnGoing;
350  if(procedure == FLASH_PROC_PAGE_ERASE)
351  {
353  }
354  else if(procedure == FLASH_PROC_MASS_ERASE)
355  {
357  }
358  else if((procedure == FLASH_PROC_PROGRAM) ||
359  (procedure == FLASH_PROC_PROGRAM_LAST))
360  {
362  }
363  else
364  {
366  }
367 
368  /*Stop the procedure ongoing*/
370  }
371 
372  /* Check FLASH End of Operation flag */
373  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP) != 0U)
374  {
375  /* Clear FLASH End of Operation pending bit */
376  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
377 
379  {
380  /* Nb of pages to erased can be decreased */
382 
383  /* Check if there are still pages to erase*/
384  if(pFlash.NbPagesToErase != 0U)
385  {
386  /* Indicate user which page has been erased*/
388 
389  /* Increment page number */
390  pFlash.Page++;
391  tmp_page = pFlash.Page;
392  FLASH_PageErase(tmp_page, pFlash.Bank);
393  }
394  else
395  {
396  /* No more pages to Erase */
397  /* Reset Address and stop Erase pages procedure */
398  pFlash.Page = 0xFFFFFFFFU;
400 
401  /* Flush the caches to be sure of the data consistency */
403 
404  /* FLASH EOP interrupt user callback */
406  }
407  }
408  else
409  {
410  /* Flush the caches to be sure of the data consistency */
412 
413  procedure = pFlash.ProcedureOnGoing;
414  if(procedure == FLASH_PROC_MASS_ERASE)
415  {
416  /* MassErase ended. Return the selected bank */
417  /* FLASH EOP interrupt user callback */
419  }
420  else if((procedure == FLASH_PROC_PROGRAM) ||
421  (procedure == FLASH_PROC_PROGRAM_LAST))
422  {
423  /* Program ended. Return the selected address */
424  /* FLASH EOP interrupt user callback */
426  }
427  else
428  {
429  /* Nothing to do */
430  }
431 
432  /*Clear the procedure ongoing*/
434  }
435  }
436 
438  {
439  /* Disable End of Operation and Error interrupts */
440  __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP | FLASH_IT_OPERR);
441 
442  /* Process Unlocked */
444  }
445 }
void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
FLASH operation error interrupt callback.
__IO FLASH_ProcedureTypeDef ProcedureOnGoing
void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
FLASH end of operation interrupt callback.
void FLASH_PageErase(uint32_t Page, uint32_t Banks)
Erase the specified FLASH memory page.
__HAL_UNLOCK(hrtc)
FLASH_ProcedureTypeDef
FLASH Procedure structure definition.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void FLASH_FlushCaches(void)
Flush the instruction and data caches.
FLASH_ProcessTypeDef pFlash
Variable used for Program/Erase sectors under interruption.

◆ HAL_FLASH_OperationErrorCallback()

__weak void HAL_FLASH_OperationErrorCallback ( uint32_t  ReturnValue)

FLASH operation error interrupt callback.

Parameters
ReturnValueThe value saved in this parameter depends on the ongoing procedure Mass Erase: Bank number which has been requested to erase Page Erase: Page number which returned an error Program: Address which was selected for data program
Return values
None

Definition at line 474 of file stm32l4xx_hal_flash.c.

475 {
476  /* Prevent unused argument(s) compilation warning */
477  UNUSED(ReturnValue);
478 
479  /* NOTE : This function should not be modified, when the callback is needed,
480  the HAL_FLASH_OperationErrorCallback could be implemented in the user file
481  */
482 }

◆ HAL_FLASH_Program()

HAL_StatusTypeDef HAL_FLASH_Program ( uint32_t  TypeProgram,
uint32_t  Address,
uint64_t  Data 
)

Program double word or fast program of a row at a specified address.

Parameters
TypeProgramIndicate the way to program at a specified address. This parameter can be a value of FLASH Program Type
Addressspecifies the address to be programmed.
Dataspecifies the data to be programmed This parameter is the data for the double word program and the address where are stored the data for the row fast program
Return values
HAL_StatusTypeDefHAL Status

Definition at line 171 of file stm32l4xx_hal_flash.c.

172 {
173  HAL_StatusTypeDef status;
174  uint32_t prog_bit = 0;
175 
176  /* Process Locked */
177  __HAL_LOCK(&pFlash);
178 
179  /* Check the parameters */
180  assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
181 
182  /* Wait for last operation to be completed */
183  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
184 
185  if(status == HAL_OK)
186  {
187  pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
188 
189  /* Deactivate the data cache if they are activated to avoid data misbehavior */
190  if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U)
191  {
192  /* Disable data cache */
193  __HAL_FLASH_DATA_CACHE_DISABLE();
195  }
196  else
197  {
199  }
200 
201  if(TypeProgram == FLASH_TYPEPROGRAM_DOUBLEWORD)
202  {
203  /* Program double-word (64-bit) at a specified address */
204  FLASH_Program_DoubleWord(Address, Data);
205  prog_bit = FLASH_CR_PG;
206  }
207  else if((TypeProgram == FLASH_TYPEPROGRAM_FAST) || (TypeProgram == FLASH_TYPEPROGRAM_FAST_AND_LAST))
208  {
209  /* Fast program a 32 row double-word (64-bit) at a specified address */
210  FLASH_Program_Fast(Address, (uint32_t)Data);
211 
212  /* If it is the last row, the bit will be cleared at the end of the operation */
213  if(TypeProgram == FLASH_TYPEPROGRAM_FAST_AND_LAST)
214  {
215  prog_bit = FLASH_CR_FSTPG;
216  }
217  }
218  else
219  {
220  /* Nothing to do */
221  }
222 
223  /* Wait for last operation to be completed */
224  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
225 
226  /* If the program operation is completed, disable the PG or FSTPG Bit */
227  if (prog_bit != 0U)
228  {
229  CLEAR_BIT(FLASH->CR, prog_bit);
230  }
231 
232  /* Flush the caches to be sure of the data consistency */
234  }
235 
236  /* Process Unlocked */
238 
239  return status;
240 }
static void FLASH_Program_Fast(uint32_t Address, uint32_t DataAddress)
Fast program a row double-word (64-bit) at a specified address.
__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
static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data)
Program double-word (64-bit) at a specified address.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_FLASH_Program_IT()

HAL_StatusTypeDef HAL_FLASH_Program_IT ( uint32_t  TypeProgram,
uint32_t  Address,
uint64_t  Data 
)

Program double word or fast program of a row at a specified address with interrupt enabled.

Parameters
TypeProgramIndicate the way to program at a specified address. This parameter can be a value of FLASH Program Type
Addressspecifies the address to be programmed.
Dataspecifies the data to be programmed This parameter is the data for the double word program and the address where are stored the data for the row fast program
Return values
HALStatus

Definition at line 253 of file stm32l4xx_hal_flash.c.

254 {
255  HAL_StatusTypeDef status = HAL_OK;
256 
257  /* Check the parameters */
258  assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
259 
260  /* Process Locked */
261  __HAL_LOCK(&pFlash);
262 
263  pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
264 
265  /* Deactivate the data cache if they are activated to avoid data misbehavior */
266  if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U)
267  {
268  /* Disable data cache */
269  __HAL_FLASH_DATA_CACHE_DISABLE();
271  }
272  else
273  {
275  }
276 
277  /* Set internal variables used by the IRQ handler */
278  if(TypeProgram == FLASH_TYPEPROGRAM_FAST_AND_LAST)
279  {
281  }
282  else
283  {
285  }
286  pFlash.Address = Address;
287 
288  /* Enable End of Operation and Error interrupts */
289  __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_OPERR);
290 
291  if(TypeProgram == FLASH_TYPEPROGRAM_DOUBLEWORD)
292  {
293  /* Program double-word (64-bit) at a specified address */
294  FLASH_Program_DoubleWord(Address, Data);
295  }
296  else if((TypeProgram == FLASH_TYPEPROGRAM_FAST) || (TypeProgram == FLASH_TYPEPROGRAM_FAST_AND_LAST))
297  {
298  /* Fast program a 32 row double-word (64-bit) at a specified address */
299  FLASH_Program_Fast(Address, (uint32_t)Data);
300  }
301  else
302  {
303  /* Nothing to do */
304  }
305 
306  return status;
307 }
__IO FLASH_ProcedureTypeDef ProcedureOnGoing
static void FLASH_Program_Fast(uint32_t Address, uint32_t DataAddress)
Fast program a row double-word (64-bit) at a specified address.
__HAL_LOCK(hrtc)
return HAL_OK
FLASH_ProcessTypeDef pFlash
Variable used for Program/Erase sectors under interruption.
__IO FLASH_CacheTypeDef CacheToReactivate
static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data)
Program double-word (64-bit) at a specified address.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))