当前位置: 首页>>代码示例>>C++>>正文


C++ HAL_FLASH_Unlock函数代码示例

本文整理汇总了C++中HAL_FLASH_Unlock函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_FLASH_Unlock函数的具体用法?C++ HAL_FLASH_Unlock怎么用?C++ HAL_FLASH_Unlock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了HAL_FLASH_Unlock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: flash_erase

void flash_erase(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32) {
    // check there is something to write
    if (num_word32 == 0) {
        return;
    }

    // unlock
    HAL_FLASH_Unlock();

    // Clear pending flags (if any)
    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
                           FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);

    // erase the sector(s)
    FLASH_EraseInitTypeDef EraseInitStruct;
    EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
    EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V
    EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL);
    EraseInitStruct.NbSectors = flash_get_sector_info(flash_dest + 4 * num_word32 - 1, NULL, NULL) - EraseInitStruct.Sector + 1;
    uint32_t SectorError = 0;
    if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
        // error occurred during sector erase
        HAL_FLASH_Lock(); // lock the flash
        return;
    }
}
开发者ID:ashtons,项目名称:micropython,代码行数:26,代码来源:flash.c

示例2: FLASH_If_WriteProtectionConfig

/**
  * @brief  Configure the write protection status of user flash area.
  * @param  modifier DISABLE or ENABLE the protection
  * @retval HAL_StatusTypeDef HAL_OK if change is applied.
  */
HAL_StatusTypeDef FLASH_If_WriteProtectionConfig(uint32_t modifier)
{
  uint32_t ProtectedSECTOR = 0xFFF;
  FLASH_OBProgramInitTypeDef config_new, config_old;
  HAL_StatusTypeDef result = HAL_OK;
  
  /* Get pages write protection status ****************************************/
  HAL_FLASHEx_OBGetConfig(&config_old);

  /* The parameter says whether we turn the protection on or off */
  config_new.WRPState = modifier;

  /* We want to modify only the Write protection */
  config_new.OptionType = OPTIONBYTE_WRP;
  
  /* No read protection, keep BOR and reset settings */
  config_new.RDPLevel = OB_RDP_LEVEL_0;
  config_new.USERConfig = config_old.USERConfig;  
  /* Get pages already write protected ****************************************/
  ProtectedSECTOR = config_old.WRPSector | FLASH_SECTOR_TO_BE_PROTECTED;

  /* Unlock the Flash to enable the flash control register access *************/ 
  HAL_FLASH_Unlock();

  /* Unlock the Options Bytes *************************************************/
  HAL_FLASH_OB_Unlock();
  
  config_new.WRPSector    = ProtectedSECTOR;
  result = HAL_FLASHEx_OBProgram(&config_new);
  
  return result;
}
开发者ID:MrZANE42,项目名称:verisure1512,代码行数:37,代码来源:flash_if.c

示例3: writeEEPROM

// FIXME: HAL for now this will only work for F4/F7 as flash layout is different
void writeEEPROM(void)
{
    // Generate compile time error if the config does not fit in the reserved area of flash.
    BUILD_BUG_ON(sizeof(master_t) > FLASH_TO_RESERVE_FOR_CONFIG);

    HAL_StatusTypeDef status;
    uint32_t wordOffset;
    int8_t attemptsRemaining = 3;

    suspendRxSignal();

    // prepare checksum/version constants
    masterConfig.version = EEPROM_CONF_VERSION;
    masterConfig.size = sizeof(master_t);
    masterConfig.magic_be = 0xBE;
    masterConfig.magic_ef = 0xEF;
    masterConfig.chk = 0; // erase checksum before recalculating
    masterConfig.chk = calculateChecksum((const uint8_t *) &masterConfig, sizeof(master_t));

    // write it
    /* Unlock the Flash to enable the flash control register access *************/
    HAL_FLASH_Unlock();
    while (attemptsRemaining--)
    {
        /* Fill EraseInit structure*/
        FLASH_EraseInitTypeDef EraseInitStruct = {0};
        EraseInitStruct.TypeErase     = FLASH_TYPEERASE_SECTORS;
        EraseInitStruct.VoltageRange  = FLASH_VOLTAGE_RANGE_3; // 2.7-3.6V
        EraseInitStruct.Sector        = (FLASH_SECTOR_TOTAL-1);
        EraseInitStruct.NbSectors     = 1;
        uint32_t SECTORError;
        status = HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError);
        if (status != HAL_OK)
        {
            continue;
        }
        else
        {
            for (wordOffset = 0; wordOffset < sizeof(master_t); wordOffset += 4)
            {
                status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, CONFIG_START_FLASH_ADDRESS + wordOffset, *(uint32_t *) ((char *) &masterConfig + wordOffset));
                if(status != HAL_OK)
                {
                    break;
                }
            }
        }
        if (status == HAL_OK) {
            break;
        }
    }
    HAL_FLASH_Lock();

    // Flash write failed - just die now
    if (status != HAL_OK || !isEEPROMContentValid()) {
        failureMode(FAILURE_FLASH_WRITE_FAILED);
    }

    resumeRxSignal();
}
开发者ID:tianbin4279,项目名称:betaflight,代码行数:61,代码来源:config_eeprom.c

示例4: FLASH_If_Erase

/**
  * @brief  This function does an erase of all user flash area
  * @param  start: start of user flash area
  * @retval FLASHIF_OK : user flash area successfully erased
  *         FLASHIF_ERASEKO : error occurred
  */
uint32_t FLASH_If_Erase(uint32_t start)
{
  uint32_t NbrOfPages = 0;
  uint32_t PageError = 0;
  FLASH_EraseInitTypeDef pEraseInit;
  HAL_StatusTypeDef status = HAL_OK;

  /* Unlock the Flash to enable the flash control register access *************/ 
  HAL_FLASH_Unlock();

  /* Get the sector where start the user flash area */
  NbrOfPages = (USER_FLASH_END_ADDRESS - start)/FLASH_PAGE_SIZE;

  pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
  pEraseInit.PageAddress = start;
  pEraseInit.NbPages = NbrOfPages;
  status = HAL_FLASHEx_Erase(&pEraseInit, &PageError);

  /* Lock the Flash to disable the flash control register access (recommended
     to protect the FLASH memory against possible unwanted operation) *********/
  HAL_FLASH_Lock();

  if (status != HAL_OK)
  {
    /* Error occurred while page erase */
    return FLASHIF_ERASEKO;
  }

  return FLASHIF_OK;
}
开发者ID:NjordCZ,项目名称:stm32cubef0,代码行数:36,代码来源:flash_if.c

示例5: stm32f3_flash_erase_block

/**
 * @brief Erase flash block
 * @note Block is the same thing as page in terms of stm32 lib:
 * it's minimal erasable chunk of flash memory
 *
 * @param dev
 * @param block
 *
 * @return Error code
 */
static int stm32f3_flash_erase_block(struct flash_dev *dev, uint32_t block) {
	int err;
	uint32_t page_err;
	FLASH_EraseInitTypeDef erase_struct;

	if (!stm32f3_flash_check_block(dev, block)) {
		return -EINVAL;
	}

	HAL_FLASH_Unlock();

	erase_struct = (FLASH_EraseInitTypeDef) {
		.TypeErase = TYPEERASE_PAGES,
		.PageAddress = dev->start + block * STM32F3_FLASH_PAGE_SIZE,
		.NbPages = 1,
	};

	err = HAL_FLASHEx_Erase(&erase_struct, &page_err);
	/* TODO check errcode */
	/* Lock to prevent unwanted operations with flash memory */
	HAL_FLASH_Lock();

	return err;
}


static int stm32f3_flash_read(struct flash_dev *dev, uint32_t base, void* data, size_t len) {
	size_t rlen = min(len, dev->end - dev->start + base);

	/* read can be unaligned */

	memcpy(data, (void *) dev->start + base, rlen);

	return rlen;
}
开发者ID:AleksandraButrova,项目名称:embox,代码行数:45,代码来源:stm32f3_flash.c

示例6: ResetSSIDPasswordInMemory

/**
  * @brief  Erase Access Point parameters from FLASH
  * @param  None
  * @retval System_Status_t (MODULE_SUCCESS/MODULE_ERROR)
  */
System_Status_t ResetSSIDPasswordInMemory(void)
{
  /* Reset Calibration Values in FLASH */
  System_Status_t status = MODULE_ERROR;

  /* Erase First Flash sector */
  FLASH_EraseInitTypeDef EraseInitStruct;
  uint32_t SectorError = 0;

  EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
  EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3;
  EraseInitStruct.Sector = BLUEMSYS_FLASH_SECTOR;
  EraseInitStruct.NbSectors = 1;

  /* Unlock the Flash to enable the flash control register access *************/
  HAL_FLASH_Unlock();

  if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK){
    /* Error occurred while sector erase.
      User can add here some code to deal with this error.
      SectorError will contain the faulty sector and then to know the code error on this sector,
      user can call function 'HAL_FLASH_GetError()'
      FLASH_ErrorTypeDef errorcode = HAL_FLASH_GetError(); */
      printf("\n\rError while erasing FLASH memory");
  } else {
      status = MODULE_SUCCESS;
  }
  /* Lock the Flash to disable the flash control register access (recommended
  to protect the FLASH memory against possible unwanted operation) *********/
  HAL_FLASH_Lock();

  return status;
}
开发者ID:nguyendinhthi,项目名称:nguyendinh,代码行数:38,代码来源:wifi_support.c

示例7: ErasePage

void ErasePage(uint32_t pageAddress)
{
  FLASH_EraseInitTypeDef EraseInitStruct;
  uint32_t FirstPage = 0, NbOfPages = 0, BankNumber = 0, PAGEError = 0;

  /* Unlock the Flash to enable the flash control register access */
  HAL_FLASH_Unlock();

  /* Clear OPTVERR bit set on virgin samples */
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);

  /* Get the 1st page to erase */
  FirstPage = GetPage(pageAddress);
  /* Get the number of pages to erase from 1st page */
  NbOfPages = 1;
  /* Get the bank */
  BankNumber = GetBank(pageAddress);
  /* Fill EraseInit structure*/
  EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
  EraseInitStruct.Banks       = BankNumber;
  EraseInitStruct.Page        = FirstPage;
  EraseInitStruct.NbPages     = NbOfPages;

  HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError);

  HAL_FLASH_Lock();
}
开发者ID:meisteg,项目名称:muc-loader,代码行数:27,代码来源:stm32l4xx_flash.c

示例8: stm32f3_flash_program

/**
 * @brief Write data to flash memory
 *
 * @param dev
 * @param base
 * @param data
 * @param len
 *
 * @return Negative error code
 */
static int stm32f3_flash_program(struct flash_dev *dev, uint32_t base, const void* data, size_t len) {
	int err = 0;
	int offset;

	if (!stm32f3_flash_check_align(base, len)
			|| ((uintptr_t) data & 0x1) != 0) {
		return -EINVAL;
	}

	if (!stm32f3_flash_check_range(dev, base, len)) {
		return -EFBIG;
	}

	HAL_FLASH_Unlock();

	/* Write data halfword by halfword */
	for (offset = 0; offset < len; offset += 2) {
		if (HAL_OK != HAL_FLASH_Program(TYPEPROGRAM_HALFWORD,
					dev->start + base + offset,
					*((uint32_t*) data + offset)))
			return -1; /* TODO: set appropriate code */
	}

	/* Lock to prevent unwanted operations with flash memory */
	HAL_FLASH_Lock();

	return err;
}
开发者ID:AleksandraButrova,项目名称:embox,代码行数:38,代码来源:stm32f3_flash.c

示例9: flash_write

void flash_write(const uint32_t *src, uint32_t dst, uint32_t size)
{
    // Unlock flash
    HAL_FLASH_Unlock();

    #if defined(MCU_SERIES_H7)
    // Program the flash 32 bytes at a time.
    for (int i=0; i<size/32; i++) {
        if (HAL_FLASH_Program(TYPEPROGRAM_WORD, dst, (uint64_t)(uint32_t) src) != HAL_OK) {
            // error occurred during flash write
            HAL_FLASH_Lock(); // lock the flash
            __fatal_error();
        }
        src += 8;
        dst += 32;
    }
    #else
    // Program the flash 4 bytes at a time.
    for (int i=0; i<size/4; i++) {
        if (HAL_FLASH_Program(TYPEPROGRAM_WORD, dst, *src) != HAL_OK) {
            // error occurred during flash write
            HAL_FLASH_Lock(); // lock the flash
            __fatal_error();
        }
        src += 1;
        dst += 4;
    }
    #endif

    // lock the flash
    HAL_FLASH_Lock();
}
开发者ID:openmv,项目名称:openmv,代码行数:32,代码来源:flash.c

示例10: main

/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F103xB HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 64 MHz */
  SystemClock_Config();

  /* Unlock the Flash Program Erase controller */
  HAL_FLASH_Unlock();

  /* EEPROM Init */
  EE_Init();

/* --- Store successively many values of the three variables in the EEPROM ---*/
  /* Store 0x1000 values of Variable1 in EEPROM */
  for (VarValue = 1; VarValue <= 0x1000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[0], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);


  /* Store 0x2000 values of Variable2 in EEPROM */
  for (VarValue = 1; VarValue <= 0x2000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[1], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
  EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);


  /* Store 0x3000 values of Variable3 in EEPROM */
  for (VarValue = 1; VarValue <= 0x3000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[2], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
  EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);
  EE_ReadVariable(VirtAddVarTab[2], &VarDataTab[2]);

  while (1)
  {
  };
}
开发者ID:NjordCZ,项目名称:STM32Cube_FW_F1,代码行数:65,代码来源:main.c

示例11: flash_erase

void flash_erase(uint32_t sector)
{
    uint32_t SectorError = 0;

    // unlock
    HAL_FLASH_Unlock();

    // Clear pending flags (if any)
    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
                           FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);

    // erase the sector(s)
    FLASH_EraseInitTypeDef EraseInitStruct;
    EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
    EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V
    EraseInitStruct.Sector = sector;
    EraseInitStruct.NbSectors = 1;

    if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
        // error occurred during sector erase
        HAL_FLASH_Lock(); // lock the flash
        __fatal_error();
    }

    HAL_FLASH_Lock(); // lock the flash
}
开发者ID:michaelchi08,项目名称:openmv,代码行数:26,代码来源:flash.c

示例12: FLASH_If_GetWriteProtectionStatus

/**
  * @brief  Returns the write protection status of application flash area.
  * @param  None
  * @retval If a sector in application area is write-protected returned value is a combinaison
            of the possible values : FLASHIF_PROTECTION_WRPENABLED, FLASHIF_PROTECTION_PCROPENABLED, ...
  *         If no sector is write-protected FLASHIF_PROTECTION_NONE is returned.
  */
uint32_t FLASH_If_GetWriteProtectionStatus(void)
{
  uint32_t ProtectedPAGE = FLASHIF_PROTECTION_NONE;
  FLASH_OBProgramInitTypeDef OptionsBytesStruct;

  /* Unlock the Flash to enable the flash control register access *************/
  HAL_FLASH_Unlock();

  /* Check if there are write protected sectors inside the user flash area ****/
  HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);

  /* Lock the Flash to disable the flash control register access (recommended
     to protect the FLASH memory against possible unwanted operation) *********/
  HAL_FLASH_Lock();

  /* Get pages already write protected ****************************************/
  ProtectedPAGE = ~(OptionsBytesStruct.WRPPage) & FLASH_PAGE_TO_BE_PROTECTED;

  /* Check if desired pages are already write protected ***********************/
  if(ProtectedPAGE != 0)
  {
    /* Some sectors inside the user flash area are write protected */
    return FLASHIF_PROTECTION_WRPENABLED;
  }
  else
  { 
    /* No write protected sectors inside the user flash area */
    return FLASHIF_PROTECTION_NONE;
  }
}
开发者ID:NjordCZ,项目名称:stm32cubef0,代码行数:37,代码来源:flash_if.c

示例13: FLASH_If_Write

/**
  * @brief  This function writes a data buffer in flash (data are 32-bit aligned).
  * @note   After writing data buffer, the flash content is checked.
  * @param  destination: start address for target location
  * @param  p_source: pointer on buffer with data to write
  * @param  length: length of data buffer (unit is 32-bit word)
  * @retval uint32_t 0: Data successfully written to Flash memory
  *         1: Error occurred while writing data in Flash memory
  *         2: Written Data in flash memory is different from expected one
  */
uint32_t FLASH_If_Write(uint32_t destination, uint32_t *p_source, uint32_t length)
{
  uint32_t i = 0;

  /* Unlock the Flash to enable the flash control register access *************/
  HAL_FLASH_Unlock();

  for (i = 0; (i < length) && (destination <= (USER_FLASH_END_ADDRESS-4)); i++)
  {
    /* Device voltage range supposed to be [2.7V to 3.6V], the operation will
       be done by word */ 
    if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, destination, *(uint32_t*)(p_source+i)) == HAL_OK)      
    {
     /* Check the written value */
      if (*(uint32_t*)destination != *(uint32_t*)(p_source+i))
      {
        /* Flash content doesn't match SRAM content */
        return(FLASHIF_WRITINGCTRL_ERROR);
      }
      /* Increment FLASH destination address */
      destination += 4;
    }
    else
    {
      /* Error occurred while writing data in Flash memory */
      return (FLASHIF_WRITING_ERROR);
    }
  }

  /* Lock the Flash to disable the flash control register access (recommended
     to protect the FLASH memory against possible unwanted operation) *********/
  HAL_FLASH_Lock();

  return (FLASHIF_OK);
}
开发者ID:NjordCZ,项目名称:stm32cubef0,代码行数:45,代码来源:flash_if.c

示例14: FLASH_If_Init

/**
  * @brief  Unlocks Flash for write access
  * @param  None
  * @retval None
  */
void FLASH_If_Init(void)
{
  HAL_FLASH_Unlock(); 

  /* Clear pending flags (if any) */  
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | 
                         FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR);
}
开发者ID:MrZANE42,项目名称:verisure1512,代码行数:13,代码来源:flash_if.c

示例15: program_tftf_header

/**
 * @brief Writes the contents fo the TFTF header to the TFTF_PARTITION
 */
int program_tftf_header(uint8_t *data, uint32_t size)
{
  HAL_FLASH_Unlock();
  program_flash_data((uint32_t)(PARTITION_TFTF_START), size, data);
  HAL_FLASH_Lock();

  return 0;
}
开发者ID:meisteg,项目名称:muc-loader,代码行数:11,代码来源:stm32l4xx_flash.c


注:本文中的HAL_FLASH_Unlock函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。