STM32L4xx_HAL_Driver  1.14.0

Functions

HAL_StatusTypeDef FLASH_WaitForLastOperation (uint32_t Timeout)
 Wait for a FLASH operation to complete. More...
 
static void FLASH_Program_DoubleWord (uint32_t Address, uint64_t Data)
 Program double-word (64-bit) at a specified address. More...
 
static void FLASH_Program_Fast (uint32_t Address, uint32_t DataAddress)
 Fast program a row double-word (64-bit) at a specified address. More...
 

Detailed Description

Function Documentation

◆ FLASH_Program_DoubleWord()

static void FLASH_Program_DoubleWord ( uint32_t  Address,
uint64_t  Data 
)
static

Program double-word (64-bit) at a specified address.

Parameters
Addressspecifies the address to be programmed.
Dataspecifies the data to be programmed.
Return values
None

Definition at line 700 of file stm32l4xx_hal_flash.c.

701 {
702  /* Check the parameters */
703  assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
704 
705  /* Set PG bit */
706  SET_BIT(FLASH->CR, FLASH_CR_PG);
707 
708  /* Program first word */
709  *(__IO uint32_t*)Address = (uint32_t)Data;
710 
711  /* Barrier to ensure programming is performed in 2 steps, in right order
712  (independently of compiler optimization behavior) */
713  __ISB();
714 
715  /* Program second word */
716  *(__IO uint32_t*)(Address+4U) = (uint32_t)(Data >> 32);
717 }
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ FLASH_Program_Fast()

static void FLASH_Program_Fast ( uint32_t  Address,
uint32_t  DataAddress 
)
static

Fast program a row double-word (64-bit) at a specified address.

Parameters
Addressspecifies the address to be programmed.
DataAddressspecifies the address where the data are stored.
Return values
None

Definition at line 725 of file stm32l4xx_hal_flash.c.

726 {
727  uint32_t primask_bit;
728  uint8_t row_index = (2*FLASH_NB_DOUBLE_WORDS_IN_ROW);
729  __IO uint32_t *dest_addr = (__IO uint32_t*)Address;
730  __IO uint32_t *src_addr = (__IO uint32_t*)DataAddress;
731 
732  /* Check the parameters */
733  assert_param(IS_FLASH_MAIN_MEM_ADDRESS(Address));
734 
735  /* Set FSTPG bit */
736  SET_BIT(FLASH->CR, FLASH_CR_FSTPG);
737 
738  /* Disable interrupts to avoid any interruption during the loop */
739  primask_bit = __get_PRIMASK();
740  __disable_irq();
741 
742  /* Program the double word of the row */
743  do
744  {
745  *dest_addr = *src_addr;
746  dest_addr++;
747  src_addr++;
748  row_index--;
749  } while (row_index != 0U);
750 
751  /* Re-enable the interrupts */
752  __set_PRIMASK(primask_bit);
753 }
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ FLASH_WaitForLastOperation()

HAL_StatusTypeDef FLASH_WaitForLastOperation ( uint32_t  Timeout)

Wait for a FLASH operation to complete.

Parameters
Timeoutmaximum flash operation timeout
Return values
HAL_StatusTypeDefHAL Status

Definition at line 649 of file stm32l4xx_hal_flash.c.

650 {
651  /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
652  Even if the FLASH operation fails, the BUSY flag will be reset and an error
653  flag will be set */
654 
655  uint32_t tickstart = HAL_GetTick();
656  uint32_t error;
657 
658  while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY))
659  {
660  if(Timeout != HAL_MAX_DELAY)
661  {
662  if((HAL_GetTick() - tickstart) >= Timeout)
663  {
664  return HAL_TIMEOUT;
665  }
666  }
667  }
668 
669  error = (FLASH->SR & FLASH_FLAG_SR_ERRORS);
670  error |= (FLASH->ECCR & FLASH_FLAG_ECCD);
671 
672  if(error != 0u)
673  {
674  /*Save the error code*/
675  pFlash.ErrorCode |= error;
676 
677  /* Clear error programming flags */
678  __HAL_FLASH_CLEAR_FLAG(error);
679 
680  return HAL_ERROR;
681  }
682 
683  /* Check FLASH End of Operation flag */
684  if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
685  {
686  /* Clear FLASH End of Operation pending bit */
687  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
688  }
689 
690  /* If there is an error flag set */
691  return HAL_OK;
692 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
return HAL_OK
FLASH_ProcessTypeDef pFlash
Variable used for Program/Erase sectors under interruption.